Seamly2D
Code documentation
VTextGraphicsItem Class Reference

The VTextGraphicsItem class. This class implements text graphics item, which can be dragged around, resized and rotated within the parent item. The text font size will be automatically updated, so that the entire text will fit into the item. More...

#include <vtextgraphicsitem.h>

Inheritance diagram for VTextGraphicsItem:
Collaboration diagram for VTextGraphicsItem:

Public Types

enum  { Type = UserType + static_cast<int>(Vis::TextGraphicsItem) }
 
- Public Types inherited from VPieceItem
enum  MoveType {
  NotMovable = 0x0 , IsRotatable = 0x1 , IsResizable = 0x2 , IsMovable = 0x4 ,
  AllModifications = IsRotatable | IsResizable | IsMovable , Error = 0x8
}
 
enum  { Type = UserType + static_cast<int>(Vis::PieceItem) }
 

Signals

void itemResized (qreal width, int fontSize)
 
void itemRotated (qreal angle)
 
void textShrink ()
 
- Signals inherited from VPieceItem
void itemMoved (const QPointF &ptPos)
 

Public Member Functions

 VTextGraphicsItem (QGraphicsItem *pParent=nullptr)
 VTextGraphicsItem::VTextGraphicsItem constructor. More...
 
virtual ~VTextGraphicsItem () Q_DECL_EQ_DEFAULT
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) Q_DECL_OVERRIDE
 VTextGraphicsItem::paint redraws the item content. More...
 
virtual void Update () Q_DECL_OVERRIDE
 VTextGraphicsItem::Update sets the correct size and font size and redraws the label. More...
 
virtual int type () const Q_DECL_OVERRIDE
 
void setFont (const QFont &font)
 VTextGraphicsItem::SetFont sets the item font. More...
 
int getFontSize () const
 VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size. More...
 
void setSize (qreal width, qreal height)
 VTextGraphicsItem::setSize Tries to set the label size to (width, height). If either of those is too small, the labelsize does not change. More...
 
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 parent. If that is not the case, it calculates the amount of movement needed to put it inside the parent and write it into xPos, yPos. More...
 
void updateData (const QString &name, const VPieceLabelData &data)
 VTextGraphicsItem::updateData Updates the detail label. More...
 
void updateData (VAbstractPattern *doc)
 VTextGraphicsItem::updateData Updates the pattern label. More...
 
int getTextLines () const
 VTextGraphicsItem::getTextLines returns the number of lines of text to show. More...
 
- Public Member Functions inherited from VPieceItem
 VPieceItem (QGraphicsItem *pParent=nullptr)
 
virtual ~VPieceItem ()
 
virtual QRectF boundingRect () const Q_DECL_OVERRIDE
 boundingRect returns the item bounding box More...
 
void Reset ()
 Reset resets the item, putting the mode and z coordinate to normal and redraws it. More...
 
bool IsIdle () const
 IsIdle returns the idle flag. More...
 
VPieceItem::MoveTypes GetMoveType () const
 
void SetMoveType (const VPieceItem::MoveTypes &moveType)
 

Protected Member Functions

virtual void mousePressEvent (QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
 VTextGraphicsItem::mousePressEvent handles left button mouse press events. More...
 
virtual void mouseMoveEvent (QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
 VTextGraphicsItem::mouseMoveEvent handles mouse move events. More...
 
virtual void mouseReleaseEvent (QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE
 VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events. More...
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
 VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed. More...
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE
 VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor. More...
 
void UpdateBox ()
 VTextGraphicsItem::UpdateBox redraws the label content. More...
 
void correctLabel ()
 VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will just fit into the label bounding box. More...
 
- Protected Member Functions inherited from VPieceItem
virtual double GetAngle (const QPointF &pt) const
 GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis. More...
 

Private Member Functions

void allUserModifications (const QPointF &pos)
 
void userRotateAndMove ()
 
void userMoveAndResize (const QPointF &pos)
 

Private Attributes

QPointF m_startPos
 
QPointF m_start
 
QSizeF m_startSize
 
double m_rotation
 
double m_angle
 
QRectF m_rectResize
 
VTextManager m_textMananger
 

Additional Inherited Members

- Protected Types inherited from VPieceItem
enum  Mode { mNormal , mMove , mResize , mRotate }
 
- Protected Attributes inherited from VPieceItem
QRectF m_rectBoundingBox
 
Mode m_eMode
 
bool m_bReleased
 
QPointF m_ptRotCenter
 
VPieceItem::MoveTypes m_moveType
 
qreal m_inactiveZ
 

Detailed Description

The VTextGraphicsItem class. This class implements text graphics item, which can be dragged around, resized and rotated within the parent item. The text font size will be automatically updated, so that the entire text will fit into the item.

Definition at line 51 of file vtextgraphicsitem.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
Type 

Definition at line 62 of file vtextgraphicsitem.h.

Constructor & Destructor Documentation

◆ VTextGraphicsItem()

VTextGraphicsItem::VTextGraphicsItem ( QGraphicsItem *  parent = nullptr)
explicit

VTextGraphicsItem::VTextGraphicsItem constructor.

Parameters
parentpointer to the parent item

Definition at line 121 of file vtextgraphicsitem.cpp.

References VPieceItem::m_inactiveZ, minH, minW, and setSize().

◆ ~VTextGraphicsItem()

virtual VTextGraphicsItem::~VTextGraphicsItem ( )
virtual

Member Function Documentation

◆ allUserModifications()

void VTextGraphicsItem::allUserModifications ( const QPointF &  pos)
private

◆ correctLabel()

void VTextGraphicsItem::correctLabel ( )
protected

VTextGraphicsItem::UpdateFont sets the text font size, so that the entire text will just fit into the label bounding box.

Definition at line 677 of file vtextgraphicsitem.cpp.

References VTextManager::FitFontSize(), isContained(), VPieceItem::m_rectBoundingBox, m_textMananger, and UpdateBox().

Referenced by Update().

◆ getFontSize()

int VTextGraphicsItem::getFontSize ( ) const

VTextGraphicsItem::getFontSize returns the currentextLiney used text base font size.

Returns
current text base font size

Definition at line 377 of file vtextgraphicsitem.cpp.

References VTextManager::GetFont(), and m_textMananger.

Referenced by PatternPieceTool::savePieceRotation(), and PatternPieceTool::SaveRotationPattern().

◆ getTextLines()

int VTextGraphicsItem::getTextLines ( ) const

VTextGraphicsItem::getTextLines returns the number of lines of text to show.

Returns
number of lines of text

Definition at line 367 of file vtextgraphicsitem.cpp.

References VTextManager::GetSourceLinesCount(), and m_textMananger.

Referenced by PatternPieceTool::UpdateLabelItem().

◆ hoverLeaveEvent()

void VTextGraphicsItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor.

Parameters
eventpointer to the scene hover event

Definition at line 657 of file vtextgraphicsitem.cpp.

◆ hoverMoveEvent()

void VTextGraphicsItem::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed.

Parameters
eventpointer to the scene hover event

Definition at line 636 of file vtextgraphicsitem.cpp.

References cursorArrowOpenHand, VPieceItem::IsResizable, VPieceItem::m_eMode, VPieceItem::m_moveType, m_rectResize, VPieceItem::mResize, and SetItemOverrideCursor().

◆ isContained()

bool VTextGraphicsItem::isContained ( QRectF  rectBB,
qreal  rotation,
qreal &  xPos,
qreal &  yPos 
) const

VTextGraphicsItem::isContained checks if the bounding box around rotated rectBB is contained in the parent. If that is not the case, it calculates the amount of movement needed to put it inside the parent and write it into xPos, yPos.

Parameters
rectBBbounding box in question
rotationbounding box rotation in degrees
xPoshorizontal translation needed to put the box inside parent item
yPosvertical translation needed to put the box inside parent item
Returns
true, if rectBB is contained in parent item and false otherwise

Definition at line 309 of file vtextgraphicsitem.cpp.

References anonymous_namespace{vtextgraphicsitem.cpp}::GetBoundingRect().

Referenced by correctLabel(), mouseMoveEvent(), and PatternPieceTool::UpdateLabelItem().

◆ itemResized

void VTextGraphicsItem::itemResized ( qreal  width,
int  fontSize 
)
signal

◆ itemRotated

void VTextGraphicsItem::itemRotated ( qreal  angle)
signal

◆ mouseMoveEvent()

void VTextGraphicsItem::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

◆ mousePressEvent()

◆ mouseReleaseEvent()

◆ paint()

void VTextGraphicsItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
virtual

◆ setFont()

void VTextGraphicsItem::setFont ( const QFont &  font)

VTextGraphicsItem::SetFont sets the item font.

Parameters
fontfont to be used in item

Definition at line 141 of file vtextgraphicsitem.cpp.

References m_textMananger, and VTextManager::setFont().

Referenced by PatternPieceTool::PrepareLabelData().

◆ setSize()

void VTextGraphicsItem::setSize ( qreal  width,
qreal  height 
)

VTextGraphicsItem::setSize Tries to set the label size to (width, height). If either of those is too small, the labelsize does not change.

Parameters
widthlabel width
heightlabel height

Definition at line 250 of file vtextgraphicsitem.cpp.

References VPieceItem::boundingRect(), VPieceItem::m_rectBoundingBox, m_rectResize, minH, minW, and resizeSquare.

Referenced by mouseMoveEvent(), PatternPieceTool::PrepareLabelData(), and VTextGraphicsItem().

◆ textShrink

void VTextGraphicsItem::textShrink ( )
signal

Referenced by mouseMoveEvent().

◆ type()

virtual int VTextGraphicsItem::type ( ) const
inlinevirtual

Reimplemented from VPieceItem.

Definition at line 61 of file vtextgraphicsitem.h.

References Type.

◆ Update()

void VTextGraphicsItem::Update ( )
virtual

VTextGraphicsItem::Update sets the correct size and font size and redraws the label.

Implements VPieceItem.

Definition at line 292 of file vtextgraphicsitem.cpp.

References correctLabel().

Referenced by mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), and PatternPieceTool::UpdateLabelItem().

◆ UpdateBox()

void VTextGraphicsItem::UpdateBox ( )
protected

VTextGraphicsItem::UpdateBox redraws the label content.

Definition at line 667 of file vtextgraphicsitem.cpp.

References VPieceItem::m_rectBoundingBox.

Referenced by correctLabel(), mouseMoveEvent(), and mouseReleaseEvent().

◆ updateData() [1/2]

void VTextGraphicsItem::updateData ( const QString &  name,
const VPieceLabelData data 
)

VTextGraphicsItem::updateData Updates the detail label.

Parameters
namename of detail
datareference to VPatternPieceData

Definition at line 347 of file vtextgraphicsitem.cpp.

References m_textMananger, and VTextManager::Update().

Referenced by PatternPieceTool::UpdatePatternLabel(), and PatternPieceTool::UpdatePieceLabel().

◆ updateData() [2/2]

void VTextGraphicsItem::updateData ( VAbstractPattern doc)

VTextGraphicsItem::updateData Updates the pattern label.

Parameters
docpointer to the pattern object

Definition at line 357 of file vtextgraphicsitem.cpp.

References m_textMananger, and VTextManager::Update().

◆ userMoveAndResize()

void VTextGraphicsItem::userMoveAndResize ( const QPointF &  pos)
private

◆ userRotateAndMove()

void VTextGraphicsItem::userRotateAndMove ( )
private

Member Data Documentation

◆ m_angle

double VTextGraphicsItem::m_angle
private

Definition at line 93 of file vtextgraphicsitem.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

◆ m_rectResize

QRectF VTextGraphicsItem::m_rectResize
private

Definition at line 94 of file vtextgraphicsitem.h.

Referenced by hoverMoveEvent(), paint(), setSize(), and userMoveAndResize().

◆ m_rotation

double VTextGraphicsItem::m_rotation
private

Definition at line 92 of file vtextgraphicsitem.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

◆ m_start

QPointF VTextGraphicsItem::m_start
private

Definition at line 90 of file vtextgraphicsitem.h.

Referenced by mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().

◆ m_startPos

QPointF VTextGraphicsItem::m_startPos
private

Definition at line 89 of file vtextgraphicsitem.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

◆ m_startSize

QSizeF VTextGraphicsItem::m_startSize
private

Definition at line 91 of file vtextgraphicsitem.h.

Referenced by mouseMoveEvent(), and mousePressEvent().

◆ m_textMananger

VTextManager VTextGraphicsItem::m_textMananger
private

The documentation for this class was generated from the following files: