labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

TextLabel.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : TextLabel.h
3  Project : LabPlot
4  Description : Text label supporting reach text and latex formatting
5  --------------------------------------------------------------------
6  Copyright : (C) 2009 Tilman Benkert (thzs@gmx.net)
7  Copyright : (C) 2012-2014 Alexander Semke (alexander.semke@web.de)
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 
30 #ifndef TEXTLABEL_H
31 #define TEXTLABEL_H
32 
33 #include "backend/lib/macros.h"
34 #include "tools/TeXRenderer.h"
36 
37 #include <QPen>
38 #include <QTextEdit>
39 
40 class QBrush;
41 class QFont;
42 class TextLabelPrivate;
43 
44 class TextLabel : public WorksheetElement {
45  Q_OBJECT
46 
47 public:
51 
52  // The text is always in HMTL format
53  struct TextWrapper {
55  TextWrapper(const QString& t, bool b, bool html): teXUsed(b) {
56  if (b) {
57  text = t; // LaTeX does not support HTML, so assume t is a plain text string
58  return;
59  }
60  text = createHtml(t, html);
61  }
62  TextWrapper(const QString& t, bool html = false) {
63  text = createHtml(t, html);
64  }
65  QString createHtml(QString text, bool isHtml) {
66  if (isHtml)
67  return text;
68 
69  QTextEdit te(text);
70  return te.toHtml();
71  }
72 
73  QString text;
74  bool teXUsed{false};
75  };
76 
77  explicit TextLabel(const QString& name, Type type = Type::General);
78  ~TextLabel() override;
79 
80  Type type() const;
81  QIcon icon() const override;
82  QMenu* createContextMenu() override;
83  QGraphicsItem* graphicsItem() const override;
84  void setParentGraphicsItem(QGraphicsItem*);
85 
86  void save(QXmlStreamWriter*) const override;
87  bool load(XmlStreamReader*, bool preview) override;
88  void loadThemeConfig(const KConfig&) override;
89  void saveThemeConfig(const KConfig&) override;
90 
92  BASIC_D_ACCESSOR_DECL(QColor, fontColor, FontColor)
93  BASIC_D_ACCESSOR_DECL(QColor, backgroundColor, BackgroundColor)
94  CLASS_D_ACCESSOR_DECL(QFont, teXFont, TeXFont)
96  void setPosition(QPointF);
97  void setPositionInvalid(bool);
100  BASIC_D_ACCESSOR_DECL(qreal, rotationAngle, RotationAngle)
101 
103  CLASS_D_ACCESSOR_DECL(QPen, borderPen, BorderPen)
104  BASIC_D_ACCESSOR_DECL(qreal, borderOpacity, BorderOpacity)
105 
106  void setVisible(bool on) override;
107  bool isVisible() const override;
108  void setPrinting(bool) override;
109 
110  void retransform() override;
111  void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override;
112 
114 
115 private slots:
116  void updateTeXImage();
117 
118  //SLOTs for changes triggered via QActions in the context menu
119  void visibilityChanged();
120 
121 protected:
123  TextLabel(const QString& name, TextLabelPrivate* dd, Type type = Type::General);
124 
125 private:
126  Q_DECLARE_PRIVATE(TextLabel)
127  void init();
128 
130  QAction* visibilityAction{nullptr};
131 
132 signals:
134  void teXFontSizeChanged(const int);
135  void teXFontChanged(const QFont);
136  void fontColorChanged(const QColor);
137  void backgroundColorChanged(const QColor);
141  void rotationAngleChanged(qreal);
142  void visibleChanged(bool);
144  void borderPenChanged(QPen&);
145  void borderOpacityChanged(float);
146 
147  void teXImageUpdated(bool);
148  void changed();
149 };
150 
151 #endif
QString name() const
A label supporting rendering of html- and tex-formatted texts.
Definition: TextLabel.h:44
void init()
Definition: TextLabel.cpp:80
void changed()
QAction * visibilityAction
Definition: TextLabel.h:130
void loadThemeConfig(const KConfig &) override
Definition: TextLabel.cpp:1082
TextLabel(const QString &name, Type type=Type::General)
Definition: TextLabel.cpp:64
Type type() const
Definition: TextLabel.cpp:76
void saveThemeConfig(const KConfig &) override
Definition: TextLabel.cpp:1117
Type m_type
Definition: TextLabel.h:129
void verticalAlignmentChanged(WorksheetElement::VerticalAlignment)
void setParentGraphicsItem(QGraphicsItem *)
Definition: TextLabel.cpp:160
void setPositionInvalid(bool)
Definition: TextLabel.cpp:287
bool isVisible() const override
Return whether the element is (at least) partially visible.
Definition: TextLabel.cpp:343
void borderOpacityChanged(float)
void setVisible(bool on) override
Show/hide the element.
Definition: TextLabel.cpp:338
QMenu * createContextMenu() override
Return a new context menu.
Definition: TextLabel.cpp:204
void borderShapeChanged(TextLabel::BorderShape)
void textWrapperChanged(const TextLabel::TextWrapper &)
QIcon icon() const override
Definition: TextLabel.cpp:200
~TextLabel() override
void visibilityChanged()
Definition: TextLabel.cpp:361
BASIC_D_ACCESSOR_DECL(BorderShape, borderShape, BorderShape)
void teXImageUpdated(bool)
void rotationAngleChanged(qreal)
void visibleChanged(bool)
QGraphicsItem * graphicsItem() const override
Return the graphics item representing this element.
Definition: TextLabel.cpp:156
void backgroundColorChanged(const QColor)
bool load(XmlStreamReader *, bool preview) override
Load from XML.
Definition: TextLabel.cpp:978
void updateTeXImage()
Definition: TextLabel.cpp:353
void horizontalAlignmentChanged(WorksheetElement::HorizontalAlignment)
void handleResize(double horizontalRatio, double verticalRatio, bool pageResize) override
Definition: TextLabel.cpp:171
void borderPenChanged(QPen &)
void save(QXmlStreamWriter *) const override
Save as XML.
Definition: TextLabel.cpp:926
void teXFontChanged(const QFont)
void retransform() override
Tell the element to newly transform its graphics item into its coordinate system.
Definition: TextLabel.cpp:166
void positionChanged(const WorksheetElement::PositionWrapper &)
void fontColorChanged(const QColor)
void teXFontSizeChanged(const int)
TextLabelPrivate *const d_ptr
Definition: TextLabel.h:122
void setPosition(QPointF)
Definition: TextLabel.cpp:265
void setPrinting(bool) override
Switches the printing mode on/off.
Definition: TextLabel.cpp:348
Base class for all Worksheet children.
XML stream parser that supports errors as well as warnings. This class also adds line and column numb...
#define CLASS_D_ACCESSOR_DECL(type, method, Method)
Definition: macros.h:134
@ Text
Definition: OriginObj.h:45
TextWrapper(const QString &t, bool b, bool html)
Definition: TextLabel.h:55
QString createHtml(QString text, bool isHtml)
Definition: TextLabel.h:65
TextWrapper(const QString &t, bool html=false)
Definition: TextLabel.h:62