| 1014 | } |
| 1015 | |
| 1016 | void TextLabelPrivate::paint(QPainter* painter, const QStyleOptionGraphicsItem* /*option*/, QWidget*) { |
| 1017 | if (positionInvalid || textWrapper.text.isEmpty()) |
| 1018 | return; |
| 1019 | |
| 1020 | // draw the text |
| 1021 | painter->save(); |
| 1022 | switch (textWrapper.mode) { |
| 1023 | case TextLabel::Mode::LaTeX: { |
| 1024 | painter->setRenderHint(QPainter::SmoothPixmapTransform); |
| 1025 | if (m_boundingRectangle.width() != 0.0 && m_boundingRectangle.height() != 0.0) |
| 1026 | painter->drawImage(m_boundingRectangle, teXImage); |
| 1027 | break; |
| 1028 | } |
| 1029 | case TextLabel::Mode::Text: |
| 1030 | case TextLabel::Mode::Markdown: { |
| 1031 | // nothing to do here, the painting is done in the ScaledTextItem child |
| 1032 | break; |
| 1033 | } |
| 1034 | } |
| 1035 | painter->restore(); |
| 1036 | |
| 1037 | // Fill the complete path with the background color, for text mode only since for latex and markdown |
| 1038 | // a rectangular image is drawn which is not cropped to the boundaries of the selected shape (eclipse, etc.) |
| 1039 | if (textWrapper.mode == TextLabel::Mode::Text) |
| 1040 | painter->fillPath(labelShape, QBrush(backgroundColor)); |
| 1041 | |
| 1042 | // draw the border |
| 1043 | if (borderShape != TextLabel::BorderShape::NoBorder) { |
| 1044 | painter->save(); |
| 1045 | painter->setPen(borderLine->pen()); |
| 1046 | painter->setOpacity(borderLine->opacity()); |
| 1047 | painter->drawPath(borderShapePath); |
| 1048 | painter->restore(); |
| 1049 | } |
| 1050 | |
| 1051 | // TODO: move the handling of m_hovered and the logic below |
| 1052 | // to draw the selectiong/hover box to WorksheetElementPrivate |
| 1053 | // so there is no need to duplicate this code in Plot, Label, Image, etc. |
| 1054 | const bool selected = isSelected(); |
| 1055 | const bool hovered = (m_hovered && !selected); |
| 1056 | if ((hovered || selected) && !q->isPrinting()) { |
| 1057 | static double penWidth = 2.; |
| 1058 | if (hovered) |
| 1059 | painter->setPen(QPen(QApplication::palette().color(QPalette::Shadow), penWidth)); |
| 1060 | else |
| 1061 | painter->setPen(QPen(QApplication::palette().color(QPalette::Highlight), penWidth)); |
| 1062 | |
| 1063 | painter->drawPath(labelShape); |
| 1064 | } |
| 1065 | |
| 1066 | #if DEBUG_TEXTLABEL_BOUNDING_RECT |
| 1067 | painter->setPen(QColor(Qt::GlobalColor::red)); |
| 1068 | painter->drawRect(boundingRect()); |
| 1069 | |
| 1070 | painter->setPen(QColor(Qt::GlobalColor::darkGreen)); |
| 1071 | painter->drawRect(m_boundingRectangle.marginsAdded(QMarginsF(3, 3, 3, 3))); |
| 1072 | |
| 1073 | painter->setPen(QColor(Qt::GlobalColor::blue)); |