From f2d5b00fd9960e20989f3dcb8bcf791e83bd89c8 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Tue, 2 Aug 2016 22:51:40 +0200 Subject: [PATCH 1/4] Detail bounding box is drawn when one of its items is in move, resize or rotate mode --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 10 ++++++++++ src/libs/vtools/tools/vtextgraphicsitem.h | 1 + src/libs/vtools/tools/vtooldetail.cpp | 16 ++++++++++++++++ src/libs/vtools/tools/vtooldetail.h | 2 ++ 4 files changed, 29 insertions(+) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index a5f4a3a81..252ffbb74 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -164,6 +164,16 @@ void VTextGraphicsItem::Reset() setZValue(TOP_Z); } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::IsIdle checks if the item is in normal mode. + * @return true, if item is in normal mode and false otherwise. + */ +bool VTextGraphicsItem::IsIdle() const +{ + return m_eMode == mNormal; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextGraphicsItem::AddLine adds a line of text to the label list. If necessary, it also resizes the diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index c601cc1e7..ef8dfe2b8 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -59,6 +59,7 @@ public: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void Reset(); + bool IsIdle() const; int GetFontSize() const; QRectF boundingRect() const; diff --git a/src/libs/vtools/tools/vtooldetail.cpp b/src/libs/vtools/tools/vtooldetail.cpp index 1d827e268..be8d58ea0 100644 --- a/src/libs/vtools/tools/vtooldetail.cpp +++ b/src/libs/vtools/tools/vtooldetail.cpp @@ -331,6 +331,22 @@ void VToolDetail::FullUpdateFromGuiOk(int result) dialog = nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VToolDetail::paint draws a bounding box around detail, if one of its text items is not idle. + */ +void VToolDetail::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + if (dataLabel->IsIdle() == false || patternInfo->IsIdle() == false) + { + painter->save(); + painter->setPen(QPen(Qt::black, 3, Qt::DashLine)); + painter->drawRect(boundingRect().adjusted(1, 1, -1, -1)); + painter->restore(); + } + VNoBrushScalePathItem::paint(painter, option, widget); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToFile add tag with informations about tool into file. diff --git a/src/libs/vtools/tools/vtooldetail.h b/src/libs/vtools/tools/vtooldetail.h index a91526e05..9c470e96c 100644 --- a/src/libs/vtools/tools/vtooldetail.h +++ b/src/libs/vtools/tools/vtooldetail.h @@ -96,6 +96,8 @@ public slots: virtual void ResetChildren(QGraphicsItem* pItem); virtual void UpdateAll(); protected: + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget) Q_DECL_OVERRIDE; virtual void AddToFile () Q_DECL_OVERRIDE; virtual void RefreshDataInFile() Q_DECL_OVERRIDE; virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ) Q_DECL_OVERRIDE; From a2ee1e24e6ad69656a9f1dc3c8468ae40296967e Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 3 Aug 2016 00:32:37 +0200 Subject: [PATCH 2/4] Fixed cursor handling over the label --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 43 ++++++++++++++++++++- src/libs/vtools/tools/vtextgraphicsitem.h | 3 ++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index 252ffbb74..d9f4884c5 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -35,6 +35,8 @@ #include #include +#include + #include "../vmisc/def.h" #include "vtextgraphicsitem.h" @@ -54,11 +56,12 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), - m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm() + m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm(), m_bResizeCursor(false) { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); SetSize(MIN_W, m_iMinH); setZValue(TOP_Z); + setAcceptHoverEvents(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -160,6 +163,7 @@ void VTextGraphicsItem::Reset() { m_eMode = mNormal; m_bReleased = false; + m_bResizeCursor = false; Update(); setZValue(TOP_Z); } @@ -365,6 +369,10 @@ void VTextGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *pME) SetOverrideCursor(cursorArrowCloseHand, 1, 1); } } + else + { + SetOverrideCursor(cursorArrowCloseHand, 1, 1); + } // raise the label and redraw it setZValue(TOP_Z + 1); UpdateBox(); @@ -446,7 +454,7 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) if (pME->button() == Qt::LeftButton) { // restore the cursor - if (m_eMode == mMove) + if (m_eMode == mMove || m_eMode == mRotate) { RestoreOverrideCursor(cursorArrowCloseHand); } @@ -498,6 +506,37 @@ void VTextGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* pME) } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::hoverMoveEvent checks if cursor has to be changed + * @param pHE pointer to the scene hover event + */ +void VTextGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent* pHE) +{ + if (m_eMode == mMove || m_eMode == mResize) + { + if (m_rectResize.contains(pHE->pos()) == true) + { + SetOverrideCursor(Qt::SizeFDiagCursor); + } + else + { + RestoreOverrideCursor(Qt::SizeFDiagCursor); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief VTextGraphicsItem::hoverLeaveEvent tries to restore normal mouse cursor + * @param pHE not used + */ +void VTextGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE) +{ + Q_UNUSED(pHE); + RestoreOverrideCursor(Qt::SizeFDiagCursor); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VTextGraphicsItem::UpdateBox redraws the label content diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index ef8dfe2b8..76c2c324d 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -76,6 +76,8 @@ protected: void mousePressEvent(QGraphicsSceneMouseEvent* pME); void mouseMoveEvent(QGraphicsSceneMouseEvent* pME); void mouseReleaseEvent(QGraphicsSceneMouseEvent* pME); + void hoverMoveEvent(QGraphicsSceneHoverEvent* pHE); + void hoverLeaveEvent(QGraphicsSceneHoverEvent* pHE); void UpdateBox(); void UpdateFont(); @@ -100,6 +102,7 @@ private: int m_iMinH; QRectF m_rectBoundingBox; VTextManager m_tm; + bool m_bResizeCursor; QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const; }; From 192bd7e7d538c3bd317b2dfdd059b273118f07c6 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 3 Aug 2016 00:39:02 +0200 Subject: [PATCH 3/4] Deleted unnecessary include --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index d9f4884c5..e3f13213d 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -35,8 +35,6 @@ #include #include -#include - #include "../vmisc/def.h" #include "vtextgraphicsitem.h" From f56614966b216110e92481f6ec6b17e8e69b9b79 Mon Sep 17 00:00:00 2001 From: BojanKverh Date: Wed, 3 Aug 2016 00:44:22 +0200 Subject: [PATCH 4/4] Deleted unnecessary class member --HG-- branch : feature --- src/libs/vtools/tools/vtextgraphicsitem.cpp | 3 +-- src/libs/vtools/tools/vtextgraphicsitem.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/vtools/tools/vtextgraphicsitem.cpp b/src/libs/vtools/tools/vtextgraphicsitem.cpp index e3f13213d..10f392748 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.cpp +++ b/src/libs/vtools/tools/vtextgraphicsitem.cpp @@ -54,7 +54,7 @@ VTextGraphicsItem::VTextGraphicsItem(QGraphicsItem* pParent) :QGraphicsObject(pParent), m_eMode(VTextGraphicsItem::mNormal), m_bReleased(false), m_ptStartPos(), m_ptStart(), m_ptRotCenter(), m_szStart(), m_dRotation(0), m_dAngle(0), - m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm(), m_bResizeCursor(false) + m_rectResize(), m_iMinH(MIN_H), m_rectBoundingBox(), m_tm() { m_rectBoundingBox.setTopLeft(QPointF(0, 0)); SetSize(MIN_W, m_iMinH); @@ -161,7 +161,6 @@ void VTextGraphicsItem::Reset() { m_eMode = mNormal; m_bReleased = false; - m_bResizeCursor = false; Update(); setZValue(TOP_Z); } diff --git a/src/libs/vtools/tools/vtextgraphicsitem.h b/src/libs/vtools/tools/vtextgraphicsitem.h index 76c2c324d..d8638eff6 100644 --- a/src/libs/vtools/tools/vtextgraphicsitem.h +++ b/src/libs/vtools/tools/vtextgraphicsitem.h @@ -102,7 +102,6 @@ private: int m_iMinH; QRectF m_rectBoundingBox; VTextManager m_tm; - bool m_bResizeCursor; QRectF GetBoundingRect(QRectF rectBB, qreal dRot) const; };