Seamly2D
Code documentation
vgraphicssimpletextitem.h
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vgraphicssimpletextitem.h
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date November 15, 2013
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #ifndef VGRAPHICSSIMPLETEXTITEM_H
53 #define VGRAPHICSSIMPLETEXTITEM_H
54 
55 #include <qcompilerdetection.h>
56 #include <QGraphicsItem>
57 #include <QGraphicsSimpleTextItem>
58 #include <QMetaObject>
59 #include <QObject>
60 #include <QPointF>
61 #include <QString>
62 #include <QVariant>
63 #include <QtGlobal>
64 #include <QColor>
65 
66 #include "../vmisc/def.h"
67 
68 /**
69  * @brief The VGraphicsSimpleTextItem class pointer label.
70  */
71 class VGraphicsSimpleTextItem : public QObject, public QGraphicsSimpleTextItem
72 {
73  Q_OBJECT
74 public:
75  explicit VGraphicsSimpleTextItem(QColor color, QGraphicsItem *parent = nullptr);
76  explicit VGraphicsSimpleTextItem( const QString &text, QColor textColor, QGraphicsItem *parent = nullptr );
77  virtual ~VGraphicsSimpleTextItem() =default;
78 
79  qint32 BaseFontSize()const;
80  virtual int type() const Q_DECL_OVERRIDE {return Type;}
81  enum { Type = UserType + static_cast<int>(Vis::GraphicsSimpleTextItem)};
82 
83  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
84  QWidget *widget = nullptr) Q_DECL_OVERRIDE;
85 
86  void setEnabled(bool enabled);
88  void setShowParentTooltip(bool show);
89 
90  QColor getTextBrushColor();
91  void setTextColor(const QColor &color);
92 
93  void setPosition(QPointF pos);
94 
95 signals:
96  /**
97  * @brief nameChangedPosition emit when label change position.
98  * @param pos new posotion.
99  */
100  void nameChangedPosition(const QPointF &pos);
101  /**
102  * @brief showContextMenu emit when need show tool context menu.
103  * @param event context menu event.
104  */
105  void showContextMenu(QGraphicsSceneContextMenuEvent *event);
106  void deleteTool();
107  void pointChosen();
108  void pointSelected(bool selected);
109 
110 protected:
111  virtual QVariant itemChange (GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE;
112  virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event ) Q_DECL_OVERRIDE;
113  virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event ) Q_DECL_OVERRIDE;
114  virtual void contextMenuEvent (QGraphicsSceneContextMenuEvent *event ) Q_DECL_OVERRIDE;
115  virtual void mousePressEvent(QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
116  virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent * event ) Q_DECL_OVERRIDE;
117  virtual void keyReleaseEvent (QKeyEvent * event ) Q_DECL_OVERRIDE;
118 
119 private:
120  /** @brief fontSize label font size. */
121  qint32 m_fontSize;
122  qreal m_scale;
123  QColor m_textColor;
127  QPointF m_pointNamePos{};
128 
129  void initItem();
130  void scalePointName(const qreal &scale);
131  void scalePosition();
132  void updateLeader();
133 };
134 
135 //---------------------------------------------------------------------------------------------------------------------
136 /**
137  * @brief FontSize return label font size.
138  * @return font size.
139  */
141 {
142  return m_fontSize;
143 }
144 
145 #endif // VGRAPHICSSIMPLETEXTITEM_H
The VGraphicsSimpleTextItem class pointer label.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void setTextColor(const QColor &color)
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE
itemChange handle item change.
virtual int type() const Q_DECL_OVERRIDE
void scalePointName(const qreal &scale)
scalePointName handle point name scaling to maintain same size when scene scale changes.
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverEnterEvent handle hover enter events.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
hoverLeaveEvent handle hover leave events.
qint32 m_fontSize
fontSize label font size.
void textSelectionType(const SelectionType &type)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
void showContextMenu(QGraphicsSceneContextMenuEvent *event)
showContextMenu emit when need show tool context menu.
qint32 BaseFontSize() const
FontSize return label font size.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=nullptr) Q_DECL_OVERRIDE
virtual void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE
VGraphicsSimpleTextItem(QColor color, QGraphicsItem *parent=nullptr)
VGraphicsSimpleTextItem default constructor.
virtual ~VGraphicsSimpleTextItem()=default
void nameChangedPosition(const QPointF &pos)
nameChangedPosition emit when label change position.
void pointSelected(bool selected)
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) Q_DECL_OVERRIDE
contextMenuEvent handle context menu events.
void scalePosition()
scalePosition handle point name position scaling to maintain same distance when scene scale changes.
@ GraphicsSimpleTextItem
SelectionType
Definition: def.h:108