From b84bb1a16a76a5185dd6581e714a0b474d604a63 Mon Sep 17 00:00:00 2001 From: 0penBrain <48731257+0penBrain@users.noreply.github.com> Date: Thu, 13 May 2021 11:16:48 +0200 Subject: [PATCH] [Gui] UserEditMode : add menu and toolbar management --- src/Gui/CommandStd.cpp | 95 ++++++ src/Gui/Icons/EditModeColor.svg | 243 ++++++++++++++ src/Gui/Icons/EditModeCutting.svg | 496 ++++++++++++++++++++++++++++ src/Gui/Icons/EditModeDefault.svg | 396 ++++++++++++++++++++++ src/Gui/Icons/EditModeTransform.svg | 231 +++++++++++++ src/Gui/Icons/resource.qrc | 4 + src/Gui/Workbench.cpp | 4 +- 7 files changed, 1467 insertions(+), 2 deletions(-) create mode 100644 src/Gui/Icons/EditModeColor.svg create mode 100644 src/Gui/Icons/EditModeCutting.svg create mode 100644 src/Gui/Icons/EditModeDefault.svg create mode 100644 src/Gui/Icons/EditModeTransform.svg diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index e62df2d7e8..7ca792d1e9 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -29,6 +29,7 @@ # include # include # include +# include #endif #include @@ -63,6 +64,7 @@ using Base::Console; using Base::Sequencer; using namespace Gui; +namespace bp = boost::placeholders; //=========================================================================== @@ -813,6 +815,98 @@ void StdCmdUnitsCalculator::activated(int iMsg) dlg->show(); } +//=========================================================================== +// StdCmdUserEditMode +//=========================================================================== +class StdCmdUserEditMode : public Gui::Command +{ +public: + StdCmdUserEditMode(); + virtual ~StdCmdUserEditMode(){} + virtual void languageChange(); + virtual const char* className() const {return "StdCmdUserEditMode";} + void updateIcon(int mode); +protected: + virtual void activated(int iMsg); + virtual bool isActive(void); + virtual Gui::Action * createAction(void); +}; + +StdCmdUserEditMode::StdCmdUserEditMode() + : Command("Std_UserEditMode") +{ + sGroup = QT_TR_NOOP("Edit mode"); + sMenuText = QT_TR_NOOP("Edit mode"); + sToolTipText = QT_TR_NOOP("Defines behavior when editing an object from tree"); + sStatusTip = QT_TR_NOOP("Defines behavior when editing an object from tree"); + sWhatsThis = "Std_UserEditMode"; + sPixmap = "EditModeDefault"; + eType = ForEdit; + + this->getGuiApplication()->signalUserEditModeChanged.connect(boost::bind(&StdCmdUserEditMode::updateIcon, this, bp::_1)); +} + +Gui::Action * StdCmdUserEditMode::createAction(void) +{ + Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); + pcAction->setDropDownMenu(true); + applyCommandData(this->className(), pcAction); + + for (auto const &uem : Gui::Application::Instance->listUserEditModes()) { + QAction* act = pcAction->addAction(QString()); + act->setCheckable(true); + act->setIcon(BitmapFactory().iconFromTheme(qPrintable(QString::fromLatin1("EditMode")+QString::fromStdString(uem.second)))); + act->setObjectName(QString::fromLatin1("Std_EditMode")+QString::fromStdString(uem.second)); + act->setWhatsThis(QString::fromLatin1(getWhatsThis())); + + if (uem.first == 0) { + pcAction->setIcon(act->icon()); + act->setChecked(true); + } + } + + _pcAction = pcAction; + languageChange(); + return pcAction; +} + +void StdCmdUserEditMode::languageChange() +{ + Command::languageChange(); + + if (!_pcAction) + return; + Gui::ActionGroup* pcAction = qobject_cast(_pcAction); + QList a = pcAction->actions(); + + for (int i = 0 ; i < a.count() ; i++) { + auto modeName = Gui::Application::Instance->getUserEditModeName(i); + a[i]->setText(QCoreApplication::translate( + "EditMode", qPrintable(QString::fromStdString(modeName)))); + a[i]->setToolTip(QCoreApplication::translate( + "EditMode", qPrintable(QString::fromStdString(modeName)+QString::fromLatin1(" mode")))); + } +} + +void StdCmdUserEditMode::updateIcon(int mode) +{ + Gui::ActionGroup *actionGroup = dynamic_cast(_pcAction); + if (!actionGroup) + return; + + actionGroup->setCheckedAction(mode); +} + +void StdCmdUserEditMode::activated(int iMsg) +{ + Gui::Application::Instance->setUserEditMode(iMsg); +} + +bool StdCmdUserEditMode::isActive(void) +{ + return true; +} + namespace Gui { void CreateStdCommands(void) @@ -842,6 +936,7 @@ void CreateStdCommands(void) rcCmdMgr.addCommand(new StdCmdPythonWebsite()); rcCmdMgr.addCommand(new StdCmdTextDocument()); rcCmdMgr.addCommand(new StdCmdUnitsCalculator()); + rcCmdMgr.addCommand(new StdCmdUserEditMode()); //rcCmdMgr.addCommand(new StdCmdMeasurementSimple()); //rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp()); //rcCmdMgr.addCommand(new StdCmdDescription()); diff --git a/src/Gui/Icons/EditModeColor.svg b/src/Gui/Icons/EditModeColor.svg new file mode 100644 index 0000000000..07d832dc28 --- /dev/null +++ b/src/Gui/Icons/EditModeColor.svg @@ -0,0 +1,243 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/src/Gui/Icons/EditModeCutting.svg b/src/Gui/Icons/EditModeCutting.svg new file mode 100644 index 0000000000..fb051257b8 --- /dev/null +++ b/src/Gui/Icons/EditModeCutting.svg @@ -0,0 +1,496 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Edit Cut + + + Garrett Le Sage + + + + + edit + cut + clipboard + + + + + + Jakub Steiner + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/EditModeDefault.svg b/src/Gui/Icons/EditModeDefault.svg new file mode 100644 index 0000000000..a6183e8b0a --- /dev/null +++ b/src/Gui/Icons/EditModeDefault.svg @@ -0,0 +1,396 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + http://jimmac.musichall.cz + + Preferences System + + + preferences + settings + control panel + tweaks + system + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/EditModeTransform.svg b/src/Gui/Icons/EditModeTransform.svg new file mode 100644 index 0000000000..135ac9736e --- /dev/null +++ b/src/Gui/Icons/EditModeTransform.svg @@ -0,0 +1,231 @@ + + + Std_AxisCross + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Std_AxisCross + + + [bitacovir] + + + + + FreeCAD LGPL2+ + + + + + FreeCAD + + + 2020/12/20 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 9de6436fbb..0f0e132595 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -240,6 +240,10 @@ document-package.svg Std_Alignment.svg Std_DuplicateSelection.svg + EditModeDefault.svg + EditModeTransform.svg + EditModeCutting.svg + EditModeColor.svg diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 715d2623c8..bda11719ef 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -587,7 +587,7 @@ MenuItem* StdWorkbench::setupMenuBar() const << "Std_Refresh" << "Std_BoxSelection" << "Std_BoxElementSelection" << "Std_SelectAll" << "Std_Delete" << "Std_SendToPythonConsole" << "Separator" << "Std_Placement" << "Std_TransformManip" << "Std_Alignment" - << "Std_Edit" << "Separator" << "Std_DlgPreferences"; + << "Std_Edit" << "Separator" << "Std_UserEditMode" << "Separator" << "Std_DlgPreferences"; MenuItem* axoviews = new MenuItem; axoviews->setCommand("Axonometric"); @@ -712,7 +712,7 @@ ToolBarItem* StdWorkbench::setupToolBars() const file->setCommand("File"); *file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator" - << "Std_Refresh" << "Separator" << "Std_WhatsThis"; + << "Std_UserEditMode" << "Separator" << "Std_Refresh" << "Separator" << "Std_WhatsThis"; // Workbench switcher ToolBarItem* wb = new ToolBarItem( root );