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>
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 |
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.
anonymous enum |
Enumerator | |
---|---|
Type |
Definition at line 62 of file vtextgraphicsitem.h.
|
explicit |
VTextGraphicsItem::VTextGraphicsItem constructor.
parent | pointer to the parent item |
Definition at line 121 of file vtextgraphicsitem.cpp.
References VPieceItem::m_inactiveZ, minH, minW, and setSize().
|
virtual |
|
private |
Definition at line 694 of file vtextgraphicsitem.cpp.
References cursorArrowCloseHand, VPieceItem::m_eMode, VPieceItem::mRotate, SetItemOverrideCursor(), and userMoveAndResize().
Referenced by mousePressEvent().
|
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().
int VTextGraphicsItem::getFontSize | ( | ) | const |
VTextGraphicsItem::getFontSize returns the currentextLiney used 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().
int VTextGraphicsItem::getTextLines | ( | ) | const |
VTextGraphicsItem::getTextLines returns the number of lines of text to show.
Definition at line 367 of file vtextgraphicsitem.cpp.
References VTextManager::GetSourceLinesCount(), and m_textMananger.
Referenced by PatternPieceTool::UpdateLabelItem().
|
protectedvirtual |
VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor.
event | pointer to the scene hover event |
Definition at line 657 of file vtextgraphicsitem.cpp.
|
protectedvirtual |
VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed.
event | pointer 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().
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.
rectBB | bounding box in question |
rotation | bounding box rotation in degrees |
xPos | horizontal translation needed to put the box inside parent item |
yPos | vertical translation needed to put the box inside parent item |
Definition at line 309 of file vtextgraphicsitem.cpp.
References anonymous_namespace{vtextgraphicsitem.cpp}::GetBoundingRect().
Referenced by correctLabel(), mouseMoveEvent(), and PatternPieceTool::UpdateLabelItem().
|
signal |
Referenced by mouseReleaseEvent(), and PatternPieceTool::PatternPieceTool().
|
signal |
Referenced by mouseReleaseEvent(), and PatternPieceTool::PatternPieceTool().
|
protectedvirtual |
VTextGraphicsItem::mouseMoveEvent handles mouse move events.
event | pointer to QGraphicsSceneMouseEvent object |
Definition at line 482 of file vtextgraphicsitem.cpp.
References VPieceItem::GetAngle(), isContained(), VPieceItem::IsMovable, VPieceItem::IsResizable, VPieceItem::IsRotatable, m_angle, VPieceItem::m_eMode, VPieceItem::m_moveType, VPieceItem::m_ptRotCenter, VPieceItem::m_rectBoundingBox, m_rotation, m_start, m_startPos, m_startSize, VPieceItem::mMove, VPieceItem::mResize, VPieceItem::mRotate, setSize(), textShrink(), Update(), and UpdateBox().
|
protectedvirtual |
VTextGraphicsItem::mousePressEvent handles left button mouse press events.
event | pointer to QGraphicsSceneMouseEvent object |
Definition at line 387 of file vtextgraphicsitem.cpp.
References ACTIVE_Z, VPieceItem::AllModifications, allUserModifications(), cursorArrowCloseHand, VPieceItem::GetAngle(), VPieceItem::IsMovable, VPieceItem::IsResizable, VPieceItem::IsRotatable, m_angle, VPieceItem::m_eMode, VPieceItem::m_moveType, VPieceItem::m_ptRotCenter, VPieceItem::m_rectBoundingBox, m_rotation, m_start, m_startPos, m_startSize, VPieceItem::mMove, VPieceItem::mRotate, VPieceItem::NotMovable, SetItemOverrideCursor(), Update(), userMoveAndResize(), and userRotateAndMove().
|
protectedvirtual |
VTextGraphicsItem::mouseReleaseEvent handles left button mouse release events.
event | pointer to QGraphicsSceneMouseEvent object |
Definition at line 579 of file vtextgraphicsitem.cpp.
References cursorArrowOpenHand, VTextManager::GetFont(), VPieceItem::IsMovable, VPieceItem::IsResizable, VPieceItem::IsRotatable, VPieceItem::itemMoved(), itemResized(), itemRotated(), VPieceItem::m_bReleased, VPieceItem::m_eMode, VPieceItem::m_moveType, VPieceItem::m_rectBoundingBox, m_start, m_textMananger, VPieceItem::mMove, VPieceItem::mResize, VPieceItem::mRotate, SetItemOverrideCursor(), Update(), and UpdateBox().
|
virtual |
VTextGraphicsItem::paint redraws the item content.
painter | pointer to the QPainter in use |
option | pointer to the object containing the actual label rectangle |
widget | not used |
Definition at line 153 of file vtextgraphicsitem.cpp.
References TextLine::bold, VPieceItem::boundingRect(), VTextManager::GetFont(), VTextManager::GetSourceLine(), VTextManager::GetSourceLinesCount(), VTextManager::GetSpacing(), TextLine::italic, TextLine::m_eAlign, VPieceItem::m_eMode, TextLine::m_iFontSize, VPieceItem::m_rectBoundingBox, m_rectResize, TextLine::m_text, m_textMananger, minH, minW, VPieceItem::mNormal, VPieceItem::mResize, VPieceItem::mRotate, qApp, ROTATE_ARC, ROTATE_RECT, and rotateCircle.
void VTextGraphicsItem::setFont | ( | const QFont & | font | ) |
VTextGraphicsItem::SetFont sets the item font.
font | font to be used in item |
Definition at line 141 of file vtextgraphicsitem.cpp.
References m_textMananger, and VTextManager::setFont().
Referenced by PatternPieceTool::PrepareLabelData().
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.
width | label width |
height | label 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().
|
signal |
Referenced by mouseMoveEvent().
|
inlinevirtual |
|
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().
|
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().
void VTextGraphicsItem::updateData | ( | const QString & | name, |
const VPieceLabelData & | data | ||
) |
VTextGraphicsItem::updateData Updates the detail label.
name | name of detail |
data | reference to VPatternPieceData |
Definition at line 347 of file vtextgraphicsitem.cpp.
References m_textMananger, and VTextManager::Update().
Referenced by PatternPieceTool::UpdatePatternLabel(), and PatternPieceTool::UpdatePieceLabel().
void VTextGraphicsItem::updateData | ( | VAbstractPattern * | doc | ) |
VTextGraphicsItem::updateData Updates the pattern label.
doc | pointer to the pattern object |
Definition at line 357 of file vtextgraphicsitem.cpp.
References m_textMananger, and VTextManager::Update().
|
private |
Definition at line 717 of file vtextgraphicsitem.cpp.
References cursorArrowCloseHand, VPieceItem::m_eMode, m_rectResize, VPieceItem::mMove, VPieceItem::mResize, and SetItemOverrideCursor().
Referenced by allUserModifications(), and mousePressEvent().
|
private |
Definition at line 707 of file vtextgraphicsitem.cpp.
References cursorArrowCloseHand, VPieceItem::m_eMode, VPieceItem::mMove, VPieceItem::mRotate, and SetItemOverrideCursor().
Referenced by mousePressEvent().
|
private |
Definition at line 93 of file vtextgraphicsitem.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 94 of file vtextgraphicsitem.h.
Referenced by hoverMoveEvent(), paint(), setSize(), and userMoveAndResize().
|
private |
Definition at line 92 of file vtextgraphicsitem.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 90 of file vtextgraphicsitem.h.
Referenced by mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().
|
private |
Definition at line 89 of file vtextgraphicsitem.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 91 of file vtextgraphicsitem.h.
Referenced by mouseMoveEvent(), and mousePressEvent().
|
private |
Definition at line 95 of file vtextgraphicsitem.h.
Referenced by correctLabel(), getFontSize(), getTextLines(), mouseReleaseEvent(), paint(), setFont(), and updateData().