-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextcontent.cpp
43 lines (38 loc) · 1.34 KB
/
textcontent.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "textcontent.h"
#include <QDebug>
#include <QLabel>
TextContent::TextContent(QString text, Qt::Alignment alignmentFlags, QMarginsF margins, bool multiLine, QColor textColor, QFont font) : TableCellContent()
{
_text = text;
_font = font;
_margins = margins;
_textColor = textColor;
_textOption = QTextOption(alignmentFlags);
_multiLine = multiLine;
}
TextContent::TextContent(QString text, QTextOption textOption, QMarginsF margins, bool multiLine, QColor textColor, QFont font) : TableCellContent()
{
_text = text;
_font = font;
_margins = margins;
_textColor = textColor;
_textOption = textOption;
_multiLine = multiLine;
}
void TextContent::draw(QPainter *painter, QRectF rect)
{
QMarginsF realMargins(_margins.left() * rect.width(),
_margins.top() * rect.height(),
_margins.right() * rect.width(),
_margins.bottom() * rect.height());
QRectF finalRect = rect.marginsRemoved(realMargins);
if(!_multiLine){
_font.setPixelSize(finalRect.height());
} else {
QRectF boundingRect = painter->boundingRect(rect, Qt::TextWrapAnywhere, _text);
rect = boundingRect;
}
painter->setFont(_font);
painter->setBrush(QBrush(_textColor));
painter->drawText(finalRect, _text, _textOption);
}