From 4e1742ded5f5a46b46e9dbadffef0345913f4ee5 Mon Sep 17 00:00:00 2001 From: dismine Date: Tue, 19 Aug 2014 14:16:00 +0300 Subject: [PATCH] Show cursor if item can move. --HG-- branch : develop --- src/app/share/resources/cursor.qrc | 2 + src/app/tools/drawTools/vabstractspline.cpp | 12 +++-- src/app/tools/drawTools/vabstractspline.h | 3 +- src/app/tools/drawTools/vtoolline.cpp | 6 +-- src/app/tools/drawTools/vtoolline.h | 2 +- src/app/tools/drawTools/vtoolpoint.cpp | 11 ++-- src/app/tools/drawTools/vtoolpoint.h | 2 +- src/app/tools/drawTools/vtoolsinglepoint.cpp | 52 +++++++++++++++++++ src/app/tools/drawTools/vtoolsinglepoint.h | 4 ++ src/app/tools/drawTools/vtoolspline.cpp | 11 +++- src/app/tools/drawTools/vtoolsplinepath.cpp | 10 +++- src/app/visualization/vcontrolpointspline.cpp | 42 +++++++++++++-- src/app/visualization/vcontrolpointspline.h | 4 +- .../visualization/vgraphicssimpletextitem.cpp | 45 ++++++++++++++-- .../visualization/vgraphicssimpletextitem.h | 4 +- src/app/xml/vdomdocument.cpp | 1 - 16 files changed, 181 insertions(+), 30 deletions(-) diff --git a/src/app/share/resources/cursor.qrc b/src/app/share/resources/cursor.qrc index d8f3a8ab2..85b2d21f1 100644 --- a/src/app/share/resources/cursor.qrc +++ b/src/app/share/resources/cursor.qrc @@ -19,5 +19,7 @@ cursor/splinepath_cut_point_cursor.png cursor/union_cursor.png cursor/arc_cut_cursor.png + cursor/cursor-arrow-closehand.png + cursor/cursor-arrow-openhand.png diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 6d0424355..dc1ec9bff 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -34,7 +34,7 @@ const QString VAbstractSpline::TagName = QStringLiteral("spline"); //--------------------------------------------------------------------------------------------------------------------- VAbstractSpline::VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem *parent) :VDrawTool(doc, data, id), QGraphicsPathItem(parent), controlPoints(QVector()), - sceneType(SceneObject::Unknown) + sceneType(SceneObject::Unknown), isHovered(false) { ignoreFullUpdate = true; } @@ -117,15 +117,17 @@ void VAbstractSpline::SetFactor(qreal factor) //--------------------------------------------------------------------------------------------------------------------- /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. + * @brief hoverEnterEvent handle hover enter events. + * @param event hover enter event. */ // cppcheck-suppress unusedFunction -void VAbstractSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VAbstractSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, Qt::SolidLine, Qt::RoundCap)); this->setPath(ToolPath(PathDirection::Show)); + isHovered = true; + QGraphicsPathItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -139,6 +141,8 @@ void VAbstractSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_UNUSED(event); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPath(ToolPath()); + isHovered = false; + QGraphicsPathItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index bc3f643be..2dfe1fa88 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -64,6 +64,7 @@ protected: */ QVector controlPoints; SceneObject sceneType; + bool isHovered; /** * @brief RefreshGeometry refresh item on scene. */ @@ -71,7 +72,7 @@ protected: virtual void ChangedActivDraw ( const QString &newName ); virtual void ShowTool(quint32 id, Qt::GlobalColor color, bool enable); virtual void SetFactor(qreal factor); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void keyReleaseEvent(QKeyEvent * event); diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index 8698e6630..035913be7 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -279,10 +279,10 @@ void VToolLine::RefreshDataInFile() //--------------------------------------------------------------------------------------------------------------------- /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. + * @brief hoverEnterEvent handle hover enter events. + * @param event hover enter event. */ -void VToolLine::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VToolLine::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor, LineStyle(typeLine))); diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 534507fb9..74ef14a59 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -58,7 +58,7 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); virtual void RefreshDataInFile(); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void RemoveReferens(); virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 032ab2a98..c58285bfd 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -185,18 +185,19 @@ void VToolPoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { emit ChoosedTool(id, SceneObject::Point); } - QGraphicsItem::mouseReleaseEvent(event); + QGraphicsEllipseItem::mouseReleaseEvent(event); } //--------------------------------------------------------------------------------------------------------------------- /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. + * @brief hoverEnterEvent handle hover enter events. + * @param event hover enter event. */ -void VToolPoint::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VToolPoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/factor)); + QGraphicsEllipseItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -314,5 +315,5 @@ void VToolPoint::keyReleaseEvent(QKeyEvent *event) default: break; } - QGraphicsItem::keyReleaseEvent ( event ); + QGraphicsEllipseItem::keyReleaseEvent ( event ); } diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index d20ceb60e..926b59cbf 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -65,7 +65,7 @@ protected: virtual void UpdateNamePosition(qreal mx, qreal my); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void RefreshPointGeometry(const VPointF &point); void RefreshLine(); diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index f9986fbb8..ca06a51ce 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -215,6 +215,54 @@ void VToolSinglePoint::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(p.y()))); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) +{ + VToolPoint::hoverEnterEvent(event); + +#ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) +{ + VToolPoint::hoverLeaveEvent(event); + + //Disable cursor-arrow-openhand +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + #ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); + #endif + } + VToolPoint::mousePressEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + //Disable cursor-arrow-closehand + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } + VToolPoint::mouseReleaseEvent(event); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setColorLabel change color for label and label line. @@ -233,6 +281,10 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) */ void VToolSinglePoint::contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ) { +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + quint32 ref = _referens; // store referens _referens = 1; // make available delete pattern piece if (doc->CountPP() > 1) diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 78b7b0ebd..c3b34f9d5 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -61,6 +61,10 @@ protected: virtual void decrementReferens(); virtual void DeleteTool(bool ask = true); virtual void SaveDialog(QDomElement &domElement); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); private: QString namePP; QString mPath; diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 4b4e312c0..efc043fb5 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -319,8 +319,15 @@ void VToolSpline::SaveDialog(QDomElement &domElement) */ void VToolSpline::RefreshGeometry() { - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - this->setPath(ToolPath()); + //this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); + if(isHovered) + { + this->setPath(ToolPath(PathDirection::Show)); + } + else + { + this->setPath(ToolPath()); + } const VSpline *spl = VAbstractTool::data.GeometricObject(id); QPointF splinePoint = VAbstractTool::data.GeometricObject(spl->GetP1().id())->toQPointF(); diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index c771df84d..e85c744ba 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -358,8 +358,14 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) */ void VToolSplinePath::RefreshGeometry() { - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); - this->setPath(ToolPath()); + if(isHovered) + { + this->setPath(ToolPath(PathDirection::Show)); + } + else + { + this->setPath(ToolPath()); + } const VSplinePath *splPath = VAbstractTool::data.GeometricObject(id); for (qint32 i = 1; i<=splPath->Count(); ++i) diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index 9a4297a7f..ba1644310 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -82,20 +82,28 @@ void VControlPointSpline::paint(QPainter *painter, const QStyleOptionGraphicsIte //--------------------------------------------------------------------------------------------------------------------- /** - * @brief hoverMoveEvent handle hover move events. + * @brief hoverEnterEvent handle hover enter events. * @param event hover move event. */ -void VControlPointSpline::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VControlPointSpline::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event); this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthMainLine()))); +#ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); +#endif + QGraphicsEllipseItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event); this->setPen(QPen(Qt::black, qApp->toPixel(qApp->widthHairLine()))); + //Disable cursor-arrow-openhand +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + QGraphicsEllipseItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -116,6 +124,32 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang return QGraphicsItem::itemChange(change, value); } +//--------------------------------------------------------------------------------------------------------------------- +void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + #ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); + #endif + } + QGraphicsEllipseItem::mousePressEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + //Disable cursor-arrow-closehand + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } + QGraphicsEllipseItem::mouseReleaseEvent(event); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshLine refresh line control point. diff --git a/src/app/visualization/vcontrolpointspline.h b/src/app/visualization/vcontrolpointspline.h index 20212c346..0ae115fc7 100644 --- a/src/app/visualization/vcontrolpointspline.h +++ b/src/app/visualization/vcontrolpointspline.h @@ -63,9 +63,11 @@ protected: /** @brief controlLine pointer to line control point. */ QGraphicsLineItem *controlLine; - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent * event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); private: Q_DISABLE_COPY(VControlPointSpline) /** @brief indexSpline index spline in list.. */ diff --git a/src/app/visualization/vgraphicssimpletextitem.cpp b/src/app/visualization/vgraphicssimpletextitem.cpp index e2c1c3e2c..9de68966f 100644 --- a/src/app/visualization/vgraphicssimpletextitem.cpp +++ b/src/app/visualization/vgraphicssimpletextitem.cpp @@ -97,13 +97,18 @@ QVariant VGraphicsSimpleTextItem::itemChange(GraphicsItemChange change, const QV //--------------------------------------------------------------------------------------------------------------------- /** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. + * @brief hoverEnterEvent handle hover enter events. + * @param event hover enter event. */ -void VGraphicsSimpleTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) +void VGraphicsSimpleTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { - Q_UNUSED(event); this->setBrush(Qt::green); + +#ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-openhand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); +#endif + QGraphicsSimpleTextItem::hoverEnterEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,6 +120,12 @@ void VGraphicsSimpleTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setBrush(Qt::black); + + //Disable cursor-arrow-openhand +#ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); +#endif + QGraphicsSimpleTextItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- @@ -126,3 +137,29 @@ void VGraphicsSimpleTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e { emit ShowContextMenu(event); } + +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + #ifndef QT_NO_CURSOR + QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); + QApplication::setOverrideCursor(QCursor(pixmap, 1, 1)); + #endif + } + QGraphicsSimpleTextItem::mousePressEvent(event); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + if (event->button() == Qt::LeftButton) + { + //Disable cursor-arrow-closehand + #ifndef QT_NO_CURSOR + QApplication::restoreOverrideCursor(); + #endif + } + QGraphicsSimpleTextItem::mouseReleaseEvent(event); +} diff --git a/src/app/visualization/vgraphicssimpletextitem.h b/src/app/visualization/vgraphicssimpletextitem.h index 699f9e436..b6622feda 100644 --- a/src/app/visualization/vgraphicssimpletextitem.h +++ b/src/app/visualization/vgraphicssimpletextitem.h @@ -57,9 +57,11 @@ signals: void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent *event ); + virtual void hoverEnterEvent ( QGraphicsSceneHoverEvent *event ); virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent *event ); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent *event ); + virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); + virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); private: /** @brief fontSize label font size. */ qint32 fontSize; diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index 7c86d7687..605d5aaca 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -227,7 +227,6 @@ bool VDomDocument::GetParametrBool(const QDomElement &domElement, const QString Q_ASSERT_X(name.isEmpty() == false, Q_FUNC_INFO, "name of parametr is empty"); Q_ASSERT_X(domElement.isNull() == false, Q_FUNC_INFO, "domElement is null"); - bool ok = false; QString parametr; bool val = true;