From 5cd9804b0680fcf9c89c4265964679e36c015773 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 24 Jan 2020 12:30:06 +0300 Subject: [PATCH] Define user preferences for sketch operation cursor Signed-off-by: vsv --- src/Config/Config_Prop.h | 10 ++++- .../ConstructionPlugin_Plugin.cpp | 2 + src/ModuleBase/ModuleBase_Preferences.cpp | 36 ++++++++++++--- src/PartSet/PartSet_Module.cpp | 6 +-- src/PartSet/PartSet_SketcherMgr.cpp | 42 +++++++++--------- src/PartSet/PartSet_SketcherMgr.h | 2 +- src/PartSet/PartSet_Tools.cpp | 14 ++++++ src/PartSet/PartSet_Tools.h | 6 +++ src/XGUI/XGUI_pictures.qrc | 3 ++ src/XGUI/pictures/ArrowCursor.png | Bin 0 -> 359 bytes src/XGUI/pictures/CrossCursor.png | Bin 0 -> 259 bytes src/XGUI/pictures/HandCursor.png | Bin 0 -> 291 bytes 12 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 src/XGUI/pictures/ArrowCursor.png create mode 100644 src/XGUI/pictures/CrossCursor.png create mode 100644 src/XGUI/pictures/HandCursor.png diff --git a/src/Config/Config_Prop.h b/src/Config/Config_Prop.h index fe97e9675..050b5d6a6 100644 --- a/src/Config/Config_Prop.h +++ b/src/Config/Config_Prop.h @@ -60,7 +60,15 @@ class Config_Prop ShortcutTree, BiColor, Background, - Directory + Directory, + Cursor + }; + + enum CursorType + { + ArrowCursor, + CrossCursor, + HandCursor }; /** diff --git a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp index 637e37b4e..855ce055a 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Plugin.cpp @@ -62,6 +62,8 @@ ConstructionPlugin_Plugin::ConstructionPlugin_Plugin() Config_Prop::DblSpin, "0.04"); Config_PropManager::registerProp(SKETCH_TAB_NAME, "rotate_to_plane", "Rotate to plane when selected", Config_Prop::Boolean, "false"); + Config_PropManager::registerProp(SKETCH_TAB_NAME, "operation_cursor", + "Cursor for Sketch operation", Config_Prop::Cursor, "0"); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/ModuleBase/ModuleBase_Preferences.cpp b/src/ModuleBase/ModuleBase_Preferences.cpp index 68e275d21..4d5f2a1c5 100644 --- a/src/ModuleBase/ModuleBase_Preferences.cpp +++ b/src/ModuleBase/ModuleBase_Preferences.cpp @@ -176,18 +176,26 @@ void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int // Add item if (aProp->type() != Config_Prop::Disabled) { SUIT_PreferenceMgr::PrefItemType aPrefType = SUIT_PreferenceMgr::Auto; - if (aProp->type() == Config_Prop::Directory) { + switch (aProp->type()) { + case Config_Prop::Directory: aPrefType = SUIT_PreferenceMgr::File; - } else { + break; + case Config_Prop::Cursor: + aPrefType = SUIT_PreferenceMgr::Selector; + break; + default: aPrefType = (SUIT_PreferenceMgr::PrefItemType) aProp->type(); } + int anId = thePref->addPreference(QObject::tr(aProp->title().c_str()), aTab, aPrefType, QString::fromStdString(aProp->section()), QString::fromStdString(aProp->name())); - if(aProp->type() == Config_Prop::Directory) { + + switch (aProp->type()) { + case Config_Prop::Directory: thePref->setItemProperty("path_type", Qtx::PT_Directory, anId); - } - if (aPrefType == SUIT_PreferenceMgr::DblSpin) { + break; + case SUIT_PreferenceMgr::DblSpin: if (aProp->min() != "") { double aMin = QString(aProp->min().c_str()).toDouble(); thePref->setItemProperty("min", aMin, anId); @@ -196,8 +204,8 @@ void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int double aMax = QString(aProp->max().c_str()).toDouble(); thePref->setItemProperty("max", aMax, anId); } - } - if (aPrefType == SUIT_PreferenceMgr::IntSpin) { + break; + case SUIT_PreferenceMgr::IntSpin: if (aProp->min() != "") { int aMin = QString(aProp->min().c_str()).toInt(); thePref->setItemProperty("min", aMin, anId); @@ -206,6 +214,20 @@ void ModuleBase_Preferences::createCustomPage(ModuleBase_IPrefMgr* thePref, int int aMax = QString(aProp->max().c_str()).toInt(); thePref->setItemProperty("max", aMax, anId); } + break; + case Config_Prop::Cursor: + { + QList aIndicesList; + QList aIconsList; + aIndicesList << 0 << 1 << 2; + aIconsList << QPixmap(":pictures/ArrowCursor.png") << + QPixmap(":pictures/CrossCursor.png") << + QPixmap(":pictures/HandCursor.png"); + + thePref->setItemProperty("indexes", aIndicesList, anId); + thePref->setItemProperty("icons", aIconsList, anId); + } + break; } } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 5b5068971..feeda8b71 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -459,9 +459,9 @@ void PartSet_Module::updateSketcherOnStart(ModuleBase_Operation* theOperation) } // It is switched off because of // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow - //else if (sketchMgr()->isNestedSketchOperation(theOperation)) { - // mySketchMgr->startNestedSketch(theOperation); - //} + else if (sketchMgr()->isNestedSketchOperation(theOperation)) { + mySketchMgr->startNestedSketch(theOperation); + } } //****************************************************** diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index b230b6dd6..cb916284b 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -226,15 +226,15 @@ void PartSet_SketcherMgr::onEnterViewPort() // It is switched off because of // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow - // if (canChangeCursor(getCurrentOperation())) { - // QCursor* aCurrentCursor = QApplication::overrideCursor(); - // if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) { - // QApplication::setOverrideCursor(QCursor(Qt::CrossCursor)); + if (canChangeCursor(getCurrentOperation())) { + QCursor* aCurrentCursor = QApplication::overrideCursor(); + if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) { + QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor()); //#ifdef DEBUG_CURSOR // qDebug("onEnterViewPort() : Qt::CrossCursor"); //#endif - // } - // } + } + } if (!isNestedCreateOperation(getCurrentOperation(), activeSketch())) return; @@ -266,12 +266,12 @@ void PartSet_SketcherMgr::onLeaveViewPort() return; #endif -// if (canChangeCursor(getCurrentOperation())) { -// QApplication::restoreOverrideCursor(); + if (canChangeCursor(getCurrentOperation())) { + QApplication::restoreOverrideCursor(); //#ifdef DEBUG_CURSOR // qDebug("onLeaveViewPort() : None"); //#endif -// } + } if (!isNestedCreateOperation(getCurrentOperation(), activeSketch())) return; @@ -1217,30 +1217,30 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) workshop()->viewer()->set2dMode(false); } -//void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) -//{ -// if (canChangeCursor(theOperation) && myIsMouseOverWindow) { -// QCursor* aCurrentCursor = QApplication::overrideCursor(); -// if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) { -// QApplication::setOverrideCursor(QCursor(Qt::CrossCursor)); +void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) +{ + if (canChangeCursor(theOperation) && myIsMouseOverWindow) { + QCursor* aCurrentCursor = QApplication::overrideCursor(); + if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) { + QApplication::setOverrideCursor(PartSet_Tools::getOperationCursor()); //#ifdef DEBUG_CURSOR // qDebug("startNestedSketch() : Qt::CrossCursor"); //#endif -// } -// } -//} + } + } +} void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) { myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); // when sketch nested operation is stopped the cursor should be restored unconditionally - //if (canChangeCursor(theOperation)) { - //QApplication::restoreOverrideCursor(); + if (canChangeCursor(theOperation)) { + QApplication::restoreOverrideCursor(); #ifdef DEBUG_CURSOR qDebug("stopNestedSketch() : None"); #endif - //} + } /// improvement to deselect automatically all eventual selected objects, when // returning to the neutral point of the Sketcher bool isClearSelectionPossible = true; diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 20ee6e659..67640b018 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -219,7 +219,7 @@ public: /// Starts sketch operation, connects to the opeation property panel /// \param theOperation a committed operation - //void startNestedSketch(ModuleBase_Operation* theOperation); + void startNestedSketch(ModuleBase_Operation* theOperation); /// Stop sketch operation, disconnects from the opeation property panel /// \param theOperation a stopped operation diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index fbb50228f..83476b096 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -851,3 +851,17 @@ double PartSet_Tools::getDefaultTransparency() { return Config_PropManager::integer("Visualization", "shaper_default_transparency") / 100.; } + +QCursor PartSet_Tools::getOperationCursor() +{ + int aId = Config_PropManager::integer(SKETCH_TAB_NAME, "operation_cursor"); + switch (aId) { + case 0: + return QCursor(Qt::ArrowCursor); + case 1: + return QCursor(Qt::CrossCursor); + case 2: + return QCursor(Qt::PointingHandCursor); + } + return QCursor(); +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 7f1c236ab..250e82a19 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -317,6 +318,11 @@ public: * Returns default transparency value */ static double getDefaultTransparency(); + + /** + * Returns cursor according to (SKETCH_TAB_NAME, "operation_cursor") property value + */ + static QCursor getOperationCursor(); }; #endif diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 9b958d9e7..2178d9dda 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -92,5 +92,8 @@ pictures/normal-view.png pictures/move_to_end.png pictures/move_to_end_split.png + pictures/ArrowCursor.png + pictures/CrossCursor.png + pictures/HandCursor.png diff --git a/src/XGUI/pictures/ArrowCursor.png b/src/XGUI/pictures/ArrowCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..de53b1069e8265ba8bc488cf5b23b90502e7f15c GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0vp^q9Dw{1|(OCFP#RY7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f`2?+978Pp=T7$IJ7mD)D%^5}&2UbG^a0i# z{|lo!c{gzV3$yc@yRkN?GkNK`;-DIigPaGe-zVuTJbvP5R#{<4(nbT{%g(~mCwmp<@AuLls*h*xl=Ar%&q3Ok3Rb+SzoX_zEhr4{PXRl?>K)0!-2um)z4*}Q$iB} D4-=Eh literal 0 HcmV?d00001 diff --git a/src/XGUI/pictures/CrossCursor.png b/src/XGUI/pictures/CrossCursor.png new file mode 100644 index 0000000000000000000000000000000000000000..230d586be02e19a0454a0fbb69d98ece03cc17f9 GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}c0*}aI1_r*vAk26?e?NS%G}c0*}aI1_r*vAk26?e?lV|jm2|>3eIP5WO@PAPqJ>T$ClA_x*FWy;a4b`o8c-ZjN zr<^GF^0I2VJwd)Bv*^s;-zusmyHR{<3un*Ef?#+-Kyz$`mbkdw%1Y zv96)Mk$j}M#;uwqqE{za7pS*heRDAD(7i9xJNkRYr4RcrPtm{bQFW-LrTkQ#)uRub j%k3j32LGuzByewi$047keJ!m(KQMT@`njxgN@xNA86|NN literal 0 HcmV?d00001 -- 2.39.2