Main Page · Class Overview · Hierarchy · All Classes
item-text.h
1 /***************************************************************************
2 ** **
3 ** QCustomPlot, an easy to use, modern plotting widget for Qt **
4 ** Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer **
5 ** **
6 ** This program is free software: you can redistribute it and/or modify **
7 ** it under the terms of the GNU General Public License as published by **
8 ** the Free Software Foundation, either version 3 of the License, or **
9 ** (at your option) any later version. **
10 ** **
11 ** This program is distributed in the hope that it will be useful, **
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of **
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
14 ** GNU General Public License for more details. **
15 ** **
16 ** You should have received a copy of the GNU General Public License **
17 ** along with this program. If not, see http://www.gnu.org/licenses/. **
18 ** **
19 ****************************************************************************
20 ** Author: Emanuel Eichhammer **
21 ** Website/Contact: http://www.qcustomplot.com/ **
22 ** Date: 07.04.14 **
23 ** Version: 1.2.1 **
24 ****************************************************************************/
25 
26 #ifndef QCP_ITEM_TEXT_H
27 #define QCP_ITEM_TEXT_H
28 
29 #include "../global.h"
30 #include "../item.h"
31 
32 class QCPPainter;
33 class QCustomPlot;
34 
35 class QCP_LIB_DECL QCPItemText : public QCPAbstractItem
36 {
37  Q_OBJECT
39  Q_PROPERTY(QColor color READ color WRITE setColor)
40  Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
41  Q_PROPERTY(QPen pen READ pen WRITE setPen)
42  Q_PROPERTY(QPen selectedPen READ selectedPen WRITE setSelectedPen)
43  Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
44  Q_PROPERTY(QBrush selectedBrush READ selectedBrush WRITE setSelectedBrush)
45  Q_PROPERTY(QFont font READ font WRITE setFont)
46  Q_PROPERTY(QFont selectedFont READ selectedFont WRITE setSelectedFont)
47  Q_PROPERTY(QString text READ text WRITE setText)
48  Q_PROPERTY(Qt::Alignment positionAlignment READ positionAlignment WRITE setPositionAlignment)
49  Q_PROPERTY(Qt::Alignment textAlignment READ textAlignment WRITE setTextAlignment)
50  Q_PROPERTY(double rotation READ rotation WRITE setRotation)
51  Q_PROPERTY(QMargins padding READ padding WRITE setPadding)
53 public:
54  QCPItemText(QCustomPlot *parentPlot);
55  virtual ~QCPItemText();
56 
57  // getters:
58  QColor color() const { return mColor; }
59  QColor selectedColor() const { return mSelectedColor; }
60  QPen pen() const { return mPen; }
61  QPen selectedPen() const { return mSelectedPen; }
62  QBrush brush() const { return mBrush; }
63  QBrush selectedBrush() const { return mSelectedBrush; }
64  QFont font() const { return mFont; }
65  QFont selectedFont() const { return mSelectedFont; }
66  QString text() const { return mText; }
67  Qt::Alignment positionAlignment() const { return mPositionAlignment; }
68  Qt::Alignment textAlignment() const { return mTextAlignment; }
69  double rotation() const { return mRotation; }
70  QMargins padding() const { return mPadding; }
71 
72  // setters;
73  void setColor(const QColor &color);
74  void setSelectedColor(const QColor &color);
75  void setPen(const QPen &pen);
76  void setSelectedPen(const QPen &pen);
77  void setBrush(const QBrush &brush);
78  void setSelectedBrush(const QBrush &brush);
79  void setFont(const QFont &font);
80  void setSelectedFont(const QFont &font);
81  void setText(const QString &text);
82  void setPositionAlignment(Qt::Alignment alignment);
83  void setTextAlignment(Qt::Alignment alignment);
84  void setRotation(double degrees);
85  void setPadding(const QMargins &padding);
86 
87  // reimplemented virtual methods:
88  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details=0) const;
89 
90  QCPItemPosition * const position;
91  QCPItemAnchor * const topLeft;
92  QCPItemAnchor * const top;
93  QCPItemAnchor * const topRight;
94  QCPItemAnchor * const right;
95  QCPItemAnchor * const bottomRight;
96  QCPItemAnchor * const bottom;
97  QCPItemAnchor * const bottomLeft;
98  QCPItemAnchor * const left;
99 
100 protected:
101  enum AnchorIndex {aiTopLeft, aiTop, aiTopRight, aiRight, aiBottomRight, aiBottom, aiBottomLeft, aiLeft};
102 
103  // property members:
104  QColor mColor, mSelectedColor;
105  QPen mPen, mSelectedPen;
106  QBrush mBrush, mSelectedBrush;
107  QFont mFont, mSelectedFont;
108  QString mText;
109  Qt::Alignment mPositionAlignment;
110  Qt::Alignment mTextAlignment;
111  double mRotation;
112  QMargins mPadding;
113 
114  // reimplemented virtual methods:
115  virtual void draw(QCPPainter *painter);
116  virtual QPointF anchorPixelPoint(int anchorId) const;
117 
118  // non-virtual methods:
119  QPointF getTextDrawPoint(const QPointF &pos, const QRectF &rect, Qt::Alignment positionAlignment) const;
120  QFont mainFont() const;
121  QColor mainColor() const;
122  QPen mainPen() const;
123  QBrush mainBrush() const;
124 };
125 
126 #endif // QCP_ITEM_TEXT_H