libkpl  5.0
A Library for Graphical Presentation of Data Sets and Functions
textitem.h
1/***************************************************************************
2 textitem.h - description
3 -------------------
4 begin : Wed Apr 18 2001
5 copyright : (C) 2017 by Werner Stille
6 email : kpl@werner-stille.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef TEXTITEM_H
19#define TEXTITEM_H
20
21#include <QGraphicsItem>
22#include <QTextDocument>
23#include "decoitem.h"
24
29class Q_DECL_EXPORT TextItem : public DecoItem, public QGraphicsItem
30{
31public:
33 enum Alignment {
34 AlignLeft = 1,
36 AlignRight
37 };
39 enum {Type = UserType + Text
41 };
54 TextItem(double x0 = 0, double y0 = 0, unsigned color = 0,
55 QGraphicsItem* parent = 0, const QString& text = "",
56 bool visible = true, Alignment alignment = AlignLeft,
57 double relSize = 1, double dir = 0);
64 TextItem(const KConfigGroup* plo, unsigned color = 0,
65 QGraphicsItem* parent = 0);
70 TextItem(const TextItem& a);
72 virtual ~TextItem();
74 inline Alignment alignment() const { return m_alignment; };
76 virtual QRectF boundingRect() const;
78 inline double dir() const { return m_dir; };
80 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
81 QWidget* widget = 0);
86 inline void setAlignment(Alignment alignment) { m_alignment = alignment; };
91 inline void setDir(double dir) { m_dir = dir; };
96 void setProperties(const QTransform& m);
98 void setSize();
103 inline void setText(const QString& text) { m_text = text; };
110 static void setText(QTextDocument& doc, const QString& text,
111 unsigned color = 0);
113 inline QString text() const { return m_text; };
115 virtual int type() const { return Type; };
117 void update();
122 void writePlo(KConfigGroup* plo) const;
123
124protected:
126 void init();
128 virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
131 Alignment m_alignment;
132 double m_dir;
133 QString m_text;
134 QTextDocument m_doc;
135};
136
137#endif
Decoration item class.
Definition: decoitem.h:36
Text item class.
Definition: textitem.h:30
virtual QRectF boundingRect() const
Calculates bounding rectangle.
static void setText(QTextDocument &doc, const QString &text, unsigned color=0)
Sets text.
void init()
Performs initialization.
void setText(const QString &text)
Sets text.
Definition: textitem.h:103
void writePlo(KConfigGroup *plo) const
Writes into plot file.
void setAlignment(Alignment alignment)
Sets alignment.
Definition: textitem.h:86
Alignment
Text alignment.
Definition: textitem.h:33
@ AlignCentered
Aligns at center.
Definition: textitem.h:35
virtual ~TextItem()
Destructor.
TextItem(const TextItem &a)
Copy constructor.
Alignment alignment() const
Returns horizontal alignment.
Definition: textitem.h:74
double dir() const
Returns rotation angle in deg.
Definition: textitem.h:78
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Updates position.
void setProperties()
Sets properties according to transformation matrix.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Paints item.
TextItem(double x0=0, double y0=0, unsigned color=0, QGraphicsItem *parent=0, const QString &text="", bool visible=true, Alignment alignment=AlignLeft, double relSize=1, double dir=0)
Constructor.
void setSize()
Sets size according to transformation matrix.
virtual int type() const
Returns specific QGraphicsItem type number.
Definition: textitem.h:115
void setProperties(const QTransform &m)
Sets properties according to transformation matrix.
void update()
Applies changes and forces redrawing.
void setDir(double dir)
Sets rotation angle.
Definition: textitem.h:91
QString text() const
Returns text.
Definition: textitem.h:113
TextItem(const KConfigGroup *plo, unsigned color=0, QGraphicsItem *parent=0)
Constructor.