File indexing completed on 2024-05-12 03:48:21

0001 /*
0002     File                 : TextLabelPrivate.h
0003     Project              : LabPlot
0004     Description          : Private members of TextLabel
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2012-2021 Alexander Semke <alexander.semke@web.de>
0007     SPDX-FileCopyrightText: 2019-2022 Stefan Gerlach <stefan.gerlach@uni.kn>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef TEXTLABELPRIVATE_H
0012 #define TEXTLABELPRIVATE_H
0013 
0014 #include "src/backend/worksheet/TextLabel.h"
0015 #include "src/backend/worksheet/WorksheetElementPrivate.h"
0016 #include "tools/TeXRenderer.h"
0017 #include <QFutureWatcher>
0018 #include <QScreen>
0019 #include <QStaticText>
0020 
0021 #include <gsl/gsl_const_cgs.h>
0022 
0023 class QGraphicsSceneHoverEvent;
0024 class CartesianPlot;
0025 class CartesianCoordinateSystem;
0026 class ScaledTextItem;
0027 class TextLabel;
0028 class QStaticText;
0029 
0030 class TextLabelPrivate : public WorksheetElementPrivate {
0031 public:
0032     explicit TextLabelPrivate(TextLabel*);
0033 
0034     double zoomFactor{-1.0};
0035     int teXImageResolution{static_cast<int>(QApplication::primaryScreen()->physicalDotsPerInchX())};
0036     double teXImageScaleFactor{
0037         Worksheet::convertToSceneUnits(GSL_CONST_CGS_INCH / QApplication::primaryScreen()->physicalDotsPerInchX(), Worksheet::Unit::Centimeter)};
0038 
0039     TextLabel::TextWrapper textWrapper;
0040     QFont teXFont{QStringLiteral("Computer Modern"), 12}; // reasonable default font and size
0041     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
0042     QColor backgroundColor{Qt::transparent}; // same as fontColor
0043     QImage teXImage;
0044     QByteArray teXPdfData;
0045     QFutureWatcher<QByteArray> teXImageFutureWatcher;
0046     TeXRenderer::Result teXRenderResult;
0047 
0048     // see TextLabel::init() for type specific default settings
0049 
0050     TextLabel::BorderShape borderShape{TextLabel::BorderShape::NoBorder};
0051     QPen borderPen{Qt::black, Worksheet::convertToSceneUnits(1.0, Worksheet::Unit::Point), Qt::SolidLine};
0052     qreal borderOpacity{1.0};
0053 
0054     void retransform() override;
0055     void updateBoundingRect();
0056     void setZoomFactor(double);
0057     virtual void recalcShapeAndBoundingRect() override;
0058     void updatePosition();
0059     void updateText();
0060     void updateTeXImage();
0061     void updateBorder();
0062     QRectF size();
0063     QPointF findNearestGluePoint(QPointF scenePoint);
0064     TextLabel::GluePoint gluePointAt(int index);
0065 
0066     ScaledTextItem* m_textItem{nullptr};
0067 
0068     QPainterPath borderShapePath;
0069     QPainterPath labelShape;
0070 
0071     // reimplemented from QGraphicsItem
0072     QPainterPath shape() const override;
0073     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* = nullptr) override;
0074     TextLabel* const q{nullptr};
0075 
0076     // used in the InfoElement (Marker) to attach the line to the label
0077     QVector<TextLabel::GluePoint> m_gluePoints;
0078 };
0079 
0080 #endif