From e8094b2c51a1c0033489554f8015ac0d456a2d79 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 26 Oct 2018 18:34:57 +0300 Subject: [PATCH] Create dialog boxes --- src/SHAPERGUI/CMakeLists.txt | 3 + src/SHAPERGUI/SHAPERGUI.cpp | 66 ++++-- src/SHAPERGUI/SHAPERGUI.h | 13 +- src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp | 285 ++++++++++++++++++++++++ src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h | 96 ++++++++ 5 files changed, 447 insertions(+), 16 deletions(-) create mode 100644 src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp create mode 100644 src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h diff --git a/src/SHAPERGUI/CMakeLists.txt b/src/SHAPERGUI/CMakeLists.txt index ab6631181..1f7aa9f66 100644 --- a/src/SHAPERGUI/CMakeLists.txt +++ b/src/SHAPERGUI/CMakeLists.txt @@ -33,6 +33,7 @@ SET(PROJECT_HEADERS SHAPERGUI_OCCSelector.h SHAPERGUI_SalomeViewer.h SHAPERGUI_NestedButton.h + SHAPERGUI_ToolbarsMgr.h ) SET(PROJECT_MOC_HEADERS @@ -40,6 +41,7 @@ SET(PROJECT_MOC_HEADERS SHAPERGUI_DataModel.h SHAPERGUI_NestedButton.h SHAPERGUI_SalomeViewer.h + SHAPERGUI_ToolbarsMgr.h ) # sources / moc wrappings @@ -51,6 +53,7 @@ SET(PROJECT_SOURCES SHAPERGUI_OCCSelector.cpp SHAPERGUI_SalomeViewer.cpp SHAPERGUI_NestedButton.cpp + SHAPERGUI_ToolbarsMgr.cpp ) SET(PROJECT_RESOURCES diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index e7189ffd8..0959e9cac 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -21,7 +21,8 @@ #include "SHAPERGUI.h" #include "SHAPERGUI_DataModel.h" #include "SHAPERGUI_OCCSelector.h" -#include +#include "SHAPERGUI_NestedButton.h" +#include "SHAPERGUI_ToolbarsMgr.h" #include #include @@ -156,8 +157,8 @@ void SHAPERGUI::initialize(CAM_Application* theApp) int aMenu = createMenu(tr("Inspection"), -1, -1, 30); int aSubMenu = createMenu(tr("Information"), aMenu); - int aId = myActionsList.size(); - myActionsList.append("INSPECTION_CMD"); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); QString aTip = tr("Show inspection window"); myWhatIsAction = createAction(aId, aTip, QIcon(":pictures/whatis.png"), tr("What Is"), @@ -166,8 +167,19 @@ void SHAPERGUI::initialize(CAM_Application* theApp) myWhatIsAction->setData("INSPECTION_CMD"); createMenu(aId, aSubMenu, 0); - int aTool = createTool(tr("Inspection tool")); + QString aToolName = tr("Inspection tool"); + int aTool = createTool(aToolName); int aToolId = createTool(myWhatIsAction, aTool); + registerCommandToolbar(aToolName, aId); + + // Define Edit toolbars command + aId = getNextCommandId(); + myActionsList.append(aId); + aTip = tr("Edit toolbars of the module"); + QAction* aAction = createAction(aId, aTip, QIcon(), tr("Edit toolbars..."), + aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars())); + int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30); + int aEditItem = createMenu(aId, aEditMenu); } //****************************************************** @@ -535,8 +547,8 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBNam } aNb++; - int aId = myActionsList.size(); - myActionsList.append(theId); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); int aKeys = 0; for (int i = 0; i < theKeys.count(); i++) @@ -554,8 +566,11 @@ QAction* SHAPERGUI::addFeature(const QString& theWBName, const QString& theTBNam int aWBTool = createTool(theTBName, theTBName); int aToolId = createTool(aId, aWBTool); - if (isAddSeparator) + registerCommandToolbar(theTBName, aId); + if (isAddSeparator) { createTool(separator(), aWBTool); + registerCommandToolbar(theTBName, -1); + } return aAction; } @@ -569,7 +584,6 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, const ActionInfo& theInfo, const QList& theNestedActions) { - myActionsList.append(theInfo.id); SUIT_Desktop* aDesk = application()->desktop(); SHAPERGUI_NestedButton* anAction = new SHAPERGUI_NestedButton(aDesk, theNestedActions); anAction->setData(theInfo.id); @@ -585,11 +599,14 @@ QAction* SHAPERGUI::addFeatureOfNested(const QString& theWBName, int aWBMenu = createMenu(theWBName, -1, -1, 30); int aItemId = createMenu(anAction, aWBMenu); + myActionsList.append(aItemId); createMenu(separator(), aWBMenu); /// nested action is always separated of others int aWBTool = createTool(theWBName, theWBName); int aToolId = createTool(anAction, aWBTool); + registerCommandToolbar(theWBName, aItemId); createTool(separator(), aWBTool); /// nested action is always separated of others + registerCommandToolbar(theWBName, -1); return anAction; } @@ -603,8 +620,8 @@ QAction* SHAPERGUI::addDesktopCommand(const QString& theId, const QString& theTi { int aMenu = createMenu(tr(theMenuSourceText), -1, -1); - int aId = myActionsList.size(); - myActionsList.append(theId); + int aId = getNextCommandId(); + myActionsList.append(aId); SUIT_Desktop* aDesk = application()->desktop(); int aKeys = 0; for (int i = 0; i < theKeys.count(); i++) @@ -645,9 +662,9 @@ bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBa QList SHAPERGUI::commandList() const { QList aActions; - for (int i = 0; i < myActionsList.size(); i++) { - QAction* aCmd = action(i); - if (aCmd && myActionsList.contains(aCmd->data().toString())) + foreach (int aId, myActionsList) { + QAction* aCmd = action(aId); + if (aCmd) aActions.append(aCmd); } @@ -792,3 +809,26 @@ void SHAPERGUI::updateModuleVisibilityState() LightApp_Module::updateModuleVisibilityState(); onWhatIs(myIsInspectionVisible); } + +void SHAPERGUI::onEditToolbars() +{ + SHAPERGUI_ToolbarsDlg aDlg(this, myActionsList, myToolbars); + aDlg.exec(); +} + +void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId) +{ + if (!myToolbars.contains(theToolName)) + myToolbars[theToolName] = QList(); + myToolbars[theToolName].append(theCommandId); +} + +int SHAPERGUI::getNextCommandId() const +{ + QtxActionMenuMgr* aMenuMgr = menuMgr(); + QIntList aIds = aMenuMgr->idList(); + int aId = aIds.count(); + while (aIds.contains(aId)) + aId++; + return aId; +} diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index 1241ebc75..8c06ccf46 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -29,7 +29,7 @@ #include -#include +#include #include class XGUI_Workshop; @@ -207,13 +207,17 @@ Q_OBJECT private slots: void onWhatIs(bool isToggled); + void onEditToolbars(); + private: /// Create selector for OCC Viewer /// \param theMgr view manager SHAPERGUI_OCCSelector* createSelector(SUIT_ViewManager* theMgr); - /// List of registered actions - QStringList myActionsList; + void registerCommandToolbar(const QString& theToolName, int theCommandId); + + int getNextCommandId() const; + /// List of registered nested actions QStringList myNestedActionsList; @@ -249,6 +253,9 @@ private slots: bool myIsInspectionVisible; QDockWidget* myInspectionPanel; + /// List of registered actions + QIntList myActionsList; + QMap myToolbars; }; #endif diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp new file mode 100644 index 000000000..337871cdb --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp @@ -0,0 +1,285 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#include "SHAPERGUI_ToolbarsMgr.h" +#include "SHAPERGUI.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + + +class SHAPERGUI_CommandIdItem : public QListWidgetItem +{ +public: + SHAPERGUI_CommandIdItem(QListWidget* theParent, int theId, SHAPERGUI* theModule) + : QListWidgetItem(theParent), myId(theId), myModule(theModule) {} + + + virtual QVariant data(int theRole) const { + if (theRole == Qt::DisplayRole) { + if (myId == -1) + return "------"; + QAction* aAction = myModule->action(myId); + if (aAction) + return aAction->text(); + } + return QListWidgetItem::data(theRole); + } + + +private: + SHAPERGUI* myModule; + int myId; +}; + + +//************************************************************************************ +//************************************************************************************ +//************************************************************************************ +SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule, + const QIntList& theActionsList, + const QMap& theToolbars) + : QDialog(theModule->application()->desktop()), + myModule(theModule), + myActionsList(theActionsList), + myToolbars(theToolbars) +{ + setWindowTitle(tr("Toolbars")); + QVBoxLayout* aMailLayout = new QVBoxLayout(this); + + // Controls part of the dialog + QWidget* aControlsWgt = new QWidget(this); + QHBoxLayout* aContolsLay = new QHBoxLayout(aControlsWgt); + aContolsLay->setContentsMargins(0, 0, 0, 0); + aMailLayout->addWidget(aControlsWgt); + + // Right controls + QWidget* aListWgt = new QWidget(aControlsWgt); + QVBoxLayout* aListLayout = new QVBoxLayout(aListWgt); + aListLayout->setContentsMargins(0, 0, 0, 0); + aContolsLay->addWidget(aListWgt); + + aListLayout->addWidget(new QLabel(tr("Toolbars:"), aListWgt)); + + myToolbarsList = new QListWidget(aListWgt); + myToolbarsList->addItems(theToolbars.keys()); + aListLayout->addWidget(myToolbarsList); + + // Left controls + QWidget* aButtonsWgt = new QWidget(aControlsWgt); + QVBoxLayout* aBtnLayout = new QVBoxLayout(aButtonsWgt); + aBtnLayout->setContentsMargins(0, 0, 0, 0); + aContolsLay->addWidget(aButtonsWgt); + + QPushButton* aAddBtn = new QPushButton(tr("Add..."), aButtonsWgt); + connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd())); + aBtnLayout->addWidget(aAddBtn); + + QPushButton* aEditBtn = new QPushButton(tr("Edit..."), aButtonsWgt); + connect(aEditBtn, SIGNAL(clicked(bool)), SLOT(onEdit())); + aBtnLayout->addWidget(aEditBtn); + + QPushButton* aDeleteBtn = new QPushButton(tr("Delete"), aButtonsWgt); + connect(aDeleteBtn, SIGNAL(clicked(bool)), SLOT(onDelete())); + aBtnLayout->addWidget(aDeleteBtn); + aBtnLayout->addStretch(1); + + // Buttons part of the dialog + QDialogButtonBox* aButtons = + new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + aMailLayout->addWidget(aButtons); + connect(aButtons, SIGNAL(accepted()), SLOT(accept())); + connect(aButtons, SIGNAL(rejected()), SLOT(reject())); +} + +void SHAPERGUI_ToolbarsDlg::onAdd() +{ + QString aNewToolbar = + QInputDialog::getText(this, tr("Create toolbar"), tr("Name of a new toolbar")); + if (!(aNewToolbar.isNull() || aNewToolbar.isEmpty())) { + if (!myToolbars.contains(aNewToolbar)) { + myToolbars[aNewToolbar] = QIntList(); + updateToolbarsList(); + } + else { + QString aMsg = tr("A tool bar with name %1 already exists").arg(aNewToolbar); + QMessageBox::warning(this, tr("Create toolbar"), aMsg); + } + } +} + +void SHAPERGUI_ToolbarsDlg::onEdit() +{ + QList aSelected = myToolbarsList->selectedItems(); + if (aSelected.size() == 1) { + QString aToolbarName = aSelected.first()->text(); + QIntList aFreeItems = getFreeCommands(); + SHAPERGUI_ToolbarItemsDlg aDlg(this, myModule, + aToolbarName, aFreeItems, myToolbars[aToolbarName]); + aDlg.exec(); + } +} + +void SHAPERGUI_ToolbarsDlg::onDelete() +{ + QList aSelected = myToolbarsList->selectedItems(); + if (aSelected.size() == 1) { + QString aToolbarName = aSelected.first()->text(); + QString aMsg = tr("Toolbar %1 will be deleted. Continue?").arg(aToolbarName); + if (QMessageBox::question(this, tr("Delete toolbar"), aMsg) == QMessageBox::Yes) { + myToolbars.remove(aToolbarName); + updateToolbarsList(); + } + } +} + +void SHAPERGUI_ToolbarsDlg::updateToolbarsList() +{ + myToolbarsList->clear(); + myToolbarsList->addItems(myToolbars.keys()); +} + +QIntList SHAPERGUI_ToolbarsDlg::getFreeCommands() const +{ + QIntList aFreeCommands; + QMap::const_iterator aIt; + foreach(int aCmd, myActionsList) { + bool aIsFree = true; + for (aIt = myToolbars.cbegin(); aIt != myToolbars.cend(); aIt++) { + if (aIt.value().contains(aCmd)) { + aIsFree = false; + break; + } + } + if (aIsFree) + aFreeCommands.append(aCmd); + } + return aFreeCommands; +} + + +//************************************************************************************ +//************************************************************************************ +//************************************************************************************ +SHAPERGUI_ToolbarItemsDlg::SHAPERGUI_ToolbarItemsDlg(QWidget* theParent, + SHAPERGUI* theModule, + const QString& theToolbar, + const QIntList& theFreeItems, + const QIntList& theItemsList) + : QDialog(theParent), + myModule(theModule), + myFreeItems(theFreeItems), + myToolItems(theItemsList) +{ + setWindowTitle(tr("Edit toolbar items")); + + QVBoxLayout* aMailLayout = new QVBoxLayout(this); + + // Name of toolbar + QWidget* aNameWgt = new QWidget(this); + QHBoxLayout* aNameLay = new QHBoxLayout(aNameWgt); + aNameLay->setContentsMargins(0, 0, 0, 0); + aMailLayout->addWidget(aNameWgt); + + aNameLay->addWidget(new QLabel(tr("Toolbar name:"), aNameWgt)); + QLabel* aNameLbl = new QLabel(theToolbar, aNameWgt); + QFont aFont = aNameLbl->font(); + aFont.setBold(true); + aNameLbl->setFont(aFont); + aNameLay->addWidget(aNameLbl); + aNameLay->addStretch(1); + + // Lists widget + QWidget* aControlsWgt = new QWidget(this); + QHBoxLayout* aCtrlLayout = new QHBoxLayout(aControlsWgt); + aCtrlLayout->setContentsMargins(0, 0, 0, 0); + aMailLayout->addWidget(aControlsWgt); + + // Left list + QWidget* aCommandsWgt = new QWidget(aControlsWgt); + QVBoxLayout* aCommandsLay = new QVBoxLayout(aCommandsWgt); + aCommandsLay->setContentsMargins(0, 0, 0, 0); + aCtrlLayout->addWidget(aCommandsWgt); + + aCommandsLay->addWidget(new QLabel(tr("Out of toolbars:"), aCommandsWgt)); + myCommandsList = new QListWidget(aCommandsWgt); + foreach(int aId, myFreeItems) { + myCommandsList->addItem(new SHAPERGUI_CommandIdItem(myCommandsList, aId, myModule)); + } + myCommandsList->setMaximumWidth(150); + aCommandsLay->addWidget(myCommandsList); + + // Middle buttons + QWidget* aButtonsWgt = new QWidget(aControlsWgt); + QVBoxLayout* aBtnLayout = new QVBoxLayout(aButtonsWgt); + aBtnLayout->setContentsMargins(0, 0, 0, 0); + aCtrlLayout->addWidget(aButtonsWgt); + + aBtnLayout->addStretch(1); + QPushButton* aAddButton = new QPushButton("--->", aButtonsWgt); + connect(aAddButton, SIGNAL(clicked(bool)), SLOT(onAddItem())); + aBtnLayout->addWidget(aAddButton); + + aBtnLayout->addSpacing(20); + + QPushButton* aDelButton = new QPushButton("<---", aButtonsWgt); + connect(aDelButton, SIGNAL(clicked(bool)), SLOT(onDelItem())); + aBtnLayout->addWidget(aDelButton); + aBtnLayout->addStretch(1); + + // Right list + QWidget* aItemsWgt = new QWidget(aControlsWgt); + QVBoxLayout* aItemsLay = new QVBoxLayout(aItemsWgt); + aItemsLay->setContentsMargins(0, 0, 0, 0); + aCtrlLayout->addWidget(aItemsWgt); + + aItemsLay->addWidget(new QLabel(tr("In the toolbar:"), aItemsWgt)); + myItemsList = new QListWidget(aItemsWgt); + foreach(int aId, myToolItems) { + myItemsList->addItem(new SHAPERGUI_CommandIdItem(myItemsList, aId, myModule)); + } + myItemsList->setMaximumWidth(150); + aItemsLay->addWidget(myItemsList); + + // Buttons part of the dialog + QDialogButtonBox* aButtons = + new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); + aMailLayout->addWidget(aButtons); + connect(aButtons, SIGNAL(accepted()), SLOT(accept())); + connect(aButtons, SIGNAL(rejected()), SLOT(reject())); +} + +void SHAPERGUI_ToolbarItemsDlg::onAddItem() +{ + +} + +void SHAPERGUI_ToolbarItemsDlg::onDelItem() +{ + +} \ No newline at end of file diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h new file mode 100644 index 000000000..1da7e8a2e --- /dev/null +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h @@ -0,0 +1,96 @@ +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// + +#ifndef SHAPERGUI_ToolbarsMgr_H +#define SHAPERGUI_ToolbarsMgr_H + +#include "SHAPER_SHAPERGUI.h" + +#include + +#include +#include +#include +#include + +class QListWidget; +class SHAPERGUI; + + +class SHAPERGUI_ToolbarItemsDlg : public QDialog +{ + Q_OBJECT +public: + SHAPERGUI_ToolbarItemsDlg(QWidget* theParent, + SHAPERGUI* theModule, + const QString& theToolbar, + const QIntList& theFreeItems, + const QIntList& theItemsList); + +private slots: + void onAddItem(); + void onDelItem(); + +private: + SHAPERGUI* myModule; + QIntList myFreeItems; + QIntList myToolItems; + + QListWidget* myCommandsList; + QListWidget* myItemsList; +}; + + +/** +* \ingroup Salome +* A dialog box for toolbars management +*/ +class SHAPERGUI_ToolbarsDlg : public QDialog +{ + Q_OBJECT +public: + SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule, + const QIntList& theActionsList, + const QMap& theToolbars); + + QMap result() const { return myToolbars; } + +private slots: + void onAdd(); + + void onEdit(); + + void onDelete(); + +private: + void updateToolbarsList(); + + QIntList getFreeCommands() const; + +private: + SHAPERGUI* myModule; + QIntList myActionsList; + QMap myToolbars; + + QListWidget* myToolbarsList; +}; + + +#endif \ No newline at end of file -- 2.39.2