Fix for text items' buttons overflowing from frame

This was observed in some cases on low-resolution screens, at least on
Linux and Windows.

The previously hardcoded value for the width of the text items' titlebar
(consisting of the buttons for formatting text) was replaced by a
method calculating its width (which varies based on screen resolution).
preferencesAboutTextFull
Craig Watson 8 years ago
parent 334ef904f4
commit fe6b92513f
  1. 1
      src/board/UBBoardView.cpp
  2. 8
      src/domain/UBGraphicsTextItem.cpp
  3. 25
      src/domain/UBGraphicsTextItemDelegate.cpp
  4. 1
      src/domain/UBGraphicsTextItemDelegate.h

@ -1335,6 +1335,7 @@ void UBBoardView::mouseReleaseEvent (QMouseEvent *event)
textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
textItem->setSelected (true);
textItem->setTextWidth(0);
textItem->setFocus();
}
}

@ -306,8 +306,12 @@ QPainterPath UBGraphicsTextItem::shape() const
void UBGraphicsTextItem::setTextWidth(qreal width)
{
qreal strictMin = 155; // the size of the font customization panel
qreal newWidth = qMax(strictMin, width);
qreal titleBarWidth = 0;
UBGraphicsTextItemDelegate * del = dynamic_cast<UBGraphicsTextItemDelegate*>(Delegate());
if (del)
titleBarWidth = del->titleBarWidth();
qreal newWidth = qMax(titleBarWidth, width);
QGraphicsTextItem::setTextWidth(newWidth);
}

@ -204,6 +204,31 @@ void UBGraphicsTextItemDelegate::createControls()
}
/**
* @brief Calculate the width of the toolbar containing the text item-related buttons
* @return The space between the left-most and right-most buttons in pixels
*/
qreal UBGraphicsTextItemDelegate::titleBarWidth()
{
if (!mFontButton)
return 0;
// refresh the frame and buttons' positions
positionHandles();
qreal titleBarWidth(0);
qreal frameLeftCoordinate = mFontButton->pos().x();
qreal frameRightCoordinate = frameLeftCoordinate;
foreach(DelegateButton* button, mButtons) {
if (button->getSection() == Qt::TitleBarArea) {
frameLeftCoordinate = qMin(button->pos().x(), frameLeftCoordinate);
frameRightCoordinate = qMax(button->pos().x() + button->boundingRect().width(), frameRightCoordinate);
}
}
return frameRightCoordinate - frameLeftCoordinate;
}
void UBGraphicsTextItemDelegate::freeButtons()
{

@ -114,6 +114,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate
void scaleTextSize(qreal multiplyer);
virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
virtual void createControls();
qreal titleBarWidth();
public slots:
void contentsChanged();

Loading…
Cancel
Save