File indexing completed on 2024-05-19 15:02:12
0001 /*************************************************************************** 0002 File : TextLabelPrivate.h 0003 Project : LabPlot 0004 Description : Private members of TextLabel 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2012-2014 by Alexander Semke (alexander.semke@web.de) 0007 Copyright : (C) 2019 by Stefan Gerlach (stefan.gerlach@uni.kn) 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 0030 #ifndef TEXTLABELPRIVATE_H 0031 #define TEXTLABELPRIVATE_H 0032 0033 #include <QStaticText> 0034 #include <QFutureWatcher> 0035 #include <QGraphicsItem> 0036 #include <QDesktopWidget> 0037 0038 class QGraphicsSceneHoverEvent; 0039 0040 class TextLabelPrivate: public QGraphicsItem { 0041 public: 0042 explicit TextLabelPrivate(TextLabel*); 0043 0044 qreal rotationAngle{0.0}; 0045 //scaling: 0046 //we need to scale from the font size specified in points to scene units. 0047 //furhermore, we create the tex-image in a higher resolution then usual desktop resolution 0048 // -> take this into account 0049 double scaleFactor{Worksheet::convertToSceneUnits(1, Worksheet::Unit::Point)}; 0050 int teXImageResolution{QApplication::desktop()->physicalDpiX()}; 0051 //TODO: use constant for 2.54 0052 double teXImageScaleFactor{Worksheet::convertToSceneUnits(2.54/QApplication::desktop()->physicalDpiX(), Worksheet::Unit::Centimeter)}; 0053 0054 TextLabel::TextWrapper textWrapper; 0055 QFont teXFont{"Computer Modern", 42}; 0056 QColor fontColor{Qt::black}; // used only by the theme for unformatted text. The text font is in the HTML and so this variable is never set 0057 QColor backgroundColor{Qt::white}; // used only by the theme for unformatted text. The text font is in the HTML and so this variable is never set 0058 QImage teXImage; 0059 QFutureWatcher<QImage> teXImageFutureWatcher; 0060 bool teXRenderSuccessful{false}; 0061 0062 // see TextLabel::init() for type specific default settings 0063 // position in parent's coordinate system, the label gets aligned around this point 0064 WorksheetElement::PositionWrapper position{ 0065 QPoint(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Centimeter), Worksheet::convertToSceneUnits(1, Worksheet::Unit::Centimeter)), 0066 TextLabel::HorizontalPosition::Center, TextLabel::VerticalPosition::Center}; 0067 bool positionInvalid{false}; 0068 0069 WorksheetElement::HorizontalAlignment horizontalAlignment{WorksheetElement::HorizontalAlignment::Center}; 0070 WorksheetElement::VerticalAlignment verticalAlignment{WorksheetElement::VerticalAlignment::Center}; 0071 0072 TextLabel::BorderShape borderShape{TextLabel::BorderShape::NoBorder}; 0073 QPen borderPen{Qt::black, Worksheet::convertToSceneUnits(1.0, Worksheet::Unit::Point), Qt::SolidLine}; 0074 qreal borderOpacity{1.0}; 0075 0076 QString name() const; 0077 void retransform(); 0078 bool swapVisible(bool on); 0079 virtual void recalcShapeAndBoundingRect(); 0080 void updatePosition(); 0081 QPointF positionFromItemPosition(QPointF); 0082 void updateText(); 0083 void updateTeXImage(); 0084 void updateBorder(); 0085 QStaticText staticText; 0086 0087 bool suppressItemChangeEvent{false}; 0088 bool suppressRetransform{false}; 0089 bool m_printing{false}; 0090 bool m_hovered{false}; 0091 0092 QRectF boundingRectangle; //bounding rectangle of the text 0093 QRectF transformedBoundingRectangle; //bounding rectangle of transformed (rotated etc.) text 0094 QPainterPath borderShapePath; 0095 QPainterPath labelShape; 0096 0097 //reimplemented from QGraphicsItem 0098 QRectF boundingRect() const override; 0099 QPainterPath shape() const override; 0100 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override; 0101 QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; 0102 0103 TextLabel* const q; 0104 0105 private: 0106 void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override; 0107 void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override; 0108 void keyPressEvent(QKeyEvent*) override; 0109 void hoverEnterEvent(QGraphicsSceneHoverEvent*) override; 0110 void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override; 0111 }; 0112 0113 #endif