Seamly2D
Code documentation
vtextgraphicsitem.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vtextgraphicsitem.h
4  ** @author Bojan Kverh
5  ** @date June 16, 2016
6  **
7  ** @brief
8  ** @copyright
9  ** This source code is part of the Valentine project, a pattern making
10  ** program, whose allow create and modeling patterns of clothing.
11  ** Copyright (C) 2013-2015 Seamly2D project
12  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
13  **
14  ** Seamly2D is free software: you can redistribute it and/or modify
15  ** it under the terms of the GNU General Public License as published by
16  ** the Free Software Foundation, either version 3 of the License, or
17  ** (at your option) any later version.
18  **
19  ** Seamly2D is distributed in the hope that it will be useful,
20  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  ** GNU General Public License for more details.
23  **
24  ** You should have received a copy of the GNU General Public License
25  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #ifndef VTEXTGRAPHICSITEM_H
30 #define VTEXTGRAPHICSITEM_H
31 
32 #include <QFont>
33 #include <QGraphicsObject>
34 #include <QList>
35 #include <QMetaObject>
36 #include <QObject>
37 #include <QPointF>
38 #include <QRectF>
39 #include <QSizeF>
40 #include <QString>
41 #include <QtGlobal>
42 
43 #include "vpieceitem.h"
44 #include "../vlayout/vtextmanager.h"
45 
46 /**
47  * @brief The VTextGraphicsItem class. This class implements text graphics item,
48  * which can be dragged around, resized and rotated within the parent item. The text font
49  * size will be automatically updated, so that the entire text will fit into the item.
50  */
52 {
53  Q_OBJECT
54 public:
55  explicit VTextGraphicsItem(QGraphicsItem* pParent = nullptr);
56  virtual ~VTextGraphicsItem() Q_DECL_EQ_DEFAULT;
57 
58  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE;
59  virtual void Update() Q_DECL_OVERRIDE;
60 
61  virtual int type() const Q_DECL_OVERRIDE {return Type;}
62  enum { Type = UserType + static_cast<int>(Vis::TextGraphicsItem)};
63 
64  void setFont(const QFont &font);
65  int getFontSize() const;
66  void setSize(qreal width, qreal height);
67  bool isContained(QRectF rectBB, qreal rotation, qreal &xPos, qreal &yPos) const;
68  void updateData(const QString &name, const VPieceLabelData &data);
69  void updateData(VAbstractPattern *doc);
70  int getTextLines() const;
71 
72 protected:
73  virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
74  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
75  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
76  virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
77  virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
78 
79  void UpdateBox();
80  void correctLabel();
81 
82 signals:
83  void itemResized(qreal width, int fontSize);
84  void itemRotated(qreal angle);
85  void textShrink();
86 
87 private:
88  Q_DISABLE_COPY(VTextGraphicsItem)
89  QPointF m_startPos;
90  QPointF m_start;
91  QSizeF m_startSize;
92  double m_rotation;
93  double m_angle;
94  QRectF m_rectResize;
96 
97  void allUserModifications(const QPointF &pos);
98  void userRotateAndMove();
99  void userMoveAndResize(const QPointF &pos);
100 };
101 
102 #endif // VTEXTGRAPHICSITEM_H
The VPieceLabelData class holds some information about a single piece like letter,...
The VTextGraphicsItem class. This class implements text graphics item, which can be dragged around,...
void itemRotated(qreal angle)
void UpdateBox()
VTextGraphicsItem::UpdateBox redraws the label content.
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events.
virtual ~VTextGraphicsItem() Q_DECL_EQ_DEFAULT
void itemResized(qreal width, int fontSize)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mousePressEvent handles left button mouse press events.
void allUserModifications(const QPointF &pos)
int getFontSize() const
VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size.
int getTextLines() const
VTextGraphicsItem::getTextLines returns the number of lines of text to show.
void userMoveAndResize(const QPointF &pos)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
VTextGraphicsItem::paint redraws the item content.
void updateData(const QString &name, const VPieceLabelData &data)
VTextGraphicsItem::updateData Updates the detail label.
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed.
VTextGraphicsItem(QGraphicsItem *pParent=nullptr)
VTextGraphicsItem::VTextGraphicsItem constructor.
virtual int type() const Q_DECL_OVERRIDE
void correctLabel()
VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will just fit into the...
void setFont(const QFont &font)
VTextGraphicsItem::SetFont sets the item font.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
VTextGraphicsItem::mouseMoveEvent handles mouse move events.
VTextManager m_textMananger
void setSize(qreal width, qreal height)
VTextGraphicsItem::setSize Tries to set the label size to (width, height). If either of those is too ...
virtual void Update() Q_DECL_OVERRIDE
VTextGraphicsItem::Update sets the correct size and font size and redraws the label.
bool isContained(QRectF rectBB, qreal rotation, qreal &xPos, qreal &yPos) const
VTextGraphicsItem::isContained checks if the bounding box around rotated rectBB is contained in the p...
The VTextManager class this class is used to determine whether a collection of text lines can fit int...
Definition: vtextmanager.h:66
@ TextGraphicsItem