Vertically align RichResourceText painting in the centre with margins

This commit is contained in:
baldurk
2017-11-21 16:55:58 +00:00
parent 32a74e20e1
commit bb5ae999f5
+15
View File
@@ -227,6 +227,13 @@ void RichResourceTextPaint(QWidget *owner, QPainter *painter, QRect rect, QFont
linkedText->doc.setTextWidth(rect.width());
linkedText->doc.setDefaultFont(font);
// vertical align to the centre, if there's spare room.
int diff = rect.height() - linkedText->doc.size().height();
if(diff > 0)
painter->translate(0, diff / 2);
linkedText->doc.drawContents(painter);
if(mouseOver)
@@ -236,6 +243,8 @@ void RichResourceTextPaint(QWidget *owner, QPainter *painter, QRect rect, QFont
QAbstractTextDocumentLayout *layout = linkedText->doc.documentLayout();
QPoint p = mousePos - rect.topLeft();
if(diff > 0)
p -= QPoint(0, diff / 2);
int pos = layout->hitTest(p, Qt::FuzzyHit);
@@ -294,6 +303,12 @@ bool RichResourceTextMouseEvent(QWidget *owner, const QVariant &var, QRect rect,
QPoint p = event->pos() - rect.topLeft();
// vertical align to the centre, if there's spare room.
int diff = rect.height() - linkedText->doc.size().height();
if(diff > 0)
p -= QPoint(0, diff / 2);
int pos = layout->hitTest(p, Qt::FuzzyHit);
if(pos >= 0)