+
+void SHAPERGUI::onWhatIs(bool isToggled)
+{
+ if (sender() == myWhatIsAction) {
+ QAction* aViewAct = myInspectionPanel->toggleViewAction();
+ aViewAct->blockSignals(true);
+ aViewAct->setChecked(isToggled);
+ aViewAct->blockSignals(false);
+ myInspectionPanel->setVisible(isToggled);
+ }
+ else {
+ myWhatIsAction->blockSignals(true);
+ myWhatIsAction->setChecked(isToggled);
+ myWhatIsAction->blockSignals(false);
+ myInspectionPanel->setVisible(isToggled);
+ }
+}
+
+void SHAPERGUI::updateModuleVisibilityState()
+{
+ LightApp_Module::updateModuleVisibilityState();
+ onWhatIs(myIsInspectionVisible);
+}
+
+void SHAPERGUI::onEditToolbars()
+{
+ SHAPERGUI_ToolbarsDlg aDlg(this);
+ if (aDlg.exec() == QDialog::Accepted) {
+ if (aDlg.isReset())
+ resetToolbars();
+ else
+ updateToolbars(aDlg.result());
+ }
+}
+
+void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
+{
+ if (!myToolbars.contains(theToolName))
+ myToolbars[theToolName] = QList<int>();
+ myToolbars[theToolName].append(theCommandId);
+}
+
+int SHAPERGUI::getNextCommandId() const
+{
+ QtxActionMenuMgr* aMenuMgr = menuMgr();
+ QIntList aIds = aMenuMgr->idList();
+ int aId = aIds.count();
+ while (action(aId) || myActionsList.contains(aId))
+ aId++;
+ return aId;
+}
+
+void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
+{
+ // Store default toolbars
+ if (myDefaultToolbars.size() == 0)
+ myDefaultToolbars = myToolbars;
+
+ QtxActionToolMgr* aMgr = toolMgr();
+ QStringList aToolbars = theNewToolbars.keys();
+ QIntList aCommands, aOldCmd;
+ int aToolbarId;
+ QAction* aAction;
+ int aActionId;
+ foreach(QString aName, aToolbars) {
+ aCommands = theNewToolbars[aName];
+ // Find or create toolbar
+ if (aMgr->hasToolBar(aName)) {
+ aToolbarId = aMgr->find(aMgr->toolBar(aName));
+ aOldCmd = myToolbars[aName];
+ }
+ else {
+ aToolbarId = aMgr->createToolBar(aName);
+ }
+ int aPos = 0;
+ foreach(int aCmd, aCommands) {
+ // Find action
+ if (aCmd == -1)
+ aAction = separator();
+ else
+ aAction = action(aCmd);
+ aActionId = aMgr->actionId(aAction);
+ if (aActionId == -1) {
+ // Add new action
+ aMgr->insert(aAction, aToolbarId, aPos);
+ }
+ else {
+ // Change position of action
+ if (aMgr->index(aActionId, aToolbarId) != aPos) {
+ if (aMgr->containsAction(aActionId, aToolbarId))
+ aMgr->remove(aActionId, aToolbarId);
+ aMgr->insert(aActionId, aToolbarId, aPos);
+ }
+ }
+ aOldCmd.removeAll(aCmd);
+ aPos++;
+ }
+ // remove extra actions
+ foreach(int aCmd, aOldCmd) {
+ aAction = action(aCmd);
+ aActionId = aMgr->actionId(aAction);
+ aMgr->remove(aActionId, aToolbarId);
+ }
+ myToolbars.remove(aName);
+ }
+ // Remove extra toolbars
+ aToolbars = myToolbars.keys();
+ foreach(QString aName, aToolbars) {
+ aMgr->removeToolBar(aName);
+ }
+ // Set new toolbars structure
+ myToolbars = theNewToolbars;
+ myIsToolbarsModified = true;
+}
+
+void SHAPERGUI::saveToolbarsConfig()
+{
+ if (!myIsToolbarsModified)
+ return;
+ // Save toolbars config into map
+ QMap<QString, QStringList> aToolbarsConfig;
+ QtxActionToolMgr* aMgr = toolMgr();
+ QStringList aToolbars = myToolbars.keys();
+ QIntList aActionsIds;
+ foreach(QString aName, aToolbars) {
+ aActionsIds = myToolbars[aName];
+ QStringList aContent;
+ foreach(int aId, aActionsIds) {
+ if (aId == -1)
+ aContent.append("");
+ else
+ aContent.append(action(aId)->data().toString());
+ }
+ aToolbarsConfig[aName] = aContent;
+ }
+ // Store the config into resources
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ QStringList aNames = aToolbarsConfig.keys();
+ QStringList aValues;
+ foreach(QString aToolbar, aNames) {
+ aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(","));
+ }
+ // Remove obsolete parameters from resources
+ QStringList aOldParams = aResMgr->parameters(ToolbarsSection);
+ foreach(QString aName, aOldParams) {
+ if (!aToolbars.contains(aName))
+ aResMgr->remove(ToolbarsSection, aName);
+ }
+ // Store current list of free commands
+ QIntList aFreeCommands = getFreeCommands();
+ QStringList aFreeList;
+ foreach(int aId, aFreeCommands) {
+ aFreeList.append(action(aId)->data().toString());
+ }
+ if (aFreeList.size() > 0)
+ aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(","));
+
+ myIsToolbarsModified = false;
+}
+
+void SHAPERGUI::loadToolbarsConfig()
+{
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection);
+ if (aToolbarNames.size() == 0)
+ return;
+
+ // Create commands map
+ QMap<QString, int> aCommandsMap;
+ QString aCmdIdStr;
+ foreach(int aId, myActionsList) {
+ aCmdIdStr = action(aId)->data().toString();
+ aCommandsMap[aCmdIdStr] = aId;
+ }
+
+ // Create new toolbars structure
+ QMap<QString, QIntList> aToolbars;
+ QStringList aCommands;
+ QIntList aKnownCommands;
+ QList<QAction*> aActions;
+ foreach(QString aName, aToolbarNames) {
+ aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(",");
+ if (aName == FreeCommandsParam) {
+ // The value is a list of free commands
+ foreach(QString aCommand, aCommands) {
+ aKnownCommands.append(aCommandsMap[aCommand]);
+ }
+ }
+ else {
+ aToolbars[aName] = QIntList();
+ if (aCommands.size() > 0) {
+ foreach(QString aCommand, aCommands) {
+ if (aCommand.isEmpty())
+ aToolbars[aName].append(-1);
+ else if (aCommandsMap.contains(aCommand)) {
+ int aId = aCommandsMap[aCommand];
+ aToolbars[aName].append(aId);
+ aKnownCommands.append(aId);
+ }
+ }
+ }
+ }
+ }
+ // Find new and obsolete commands
+ QIntList aNewCommands = myActionsList;
+ foreach(int aId, myActionsList) {
+ if (aKnownCommands.contains(aId)) {
+ aKnownCommands.removeAll(aId);
+ aNewCommands.removeAll(aId);
+ }
+ }
+ if (aNewCommands.size() > 0) {
+ // Add new commands to toolbars structure
+ QStringList aKeys = myToolbars.keys();
+ foreach(int aNewId, aNewCommands) {
+ foreach(QString aName, aKeys) {
+ if (myToolbars[aName].contains(aNewId)) {
+ if (!aToolbars.contains(aName)) {
+ aToolbars[aName] = QIntList();
+ }
+ aToolbars[aName].append(aNewId);
+ }
+ }
+ }
+ }
+ if (aKnownCommands.size() > 0) {
+ // Remove obsolete commands from the toolbars structure
+ QStringList aKeys = aToolbars.keys();
+ foreach(int aOldId, aKnownCommands) {
+ foreach(QString aName, aKeys) {
+ if (aToolbars[aName].contains(aOldId)) {
+ aToolbars[aName].removeAll(aOldId);
+ if (aToolbars[aName].size() == 0)
+ aToolbars.remove(aName);
+ }
+ }
+ }
+ }
+ updateToolbars(aToolbars);
+ myIsToolbarsModified = false;
+}
+
+
+QIntList SHAPERGUI::getFreeCommands() const
+{
+ QIntList aFreeCommands;
+ QtxActionToolMgr* aMgr = toolMgr();
+ QAction* anAction;
+ int aId;
+ QMap<QString, QIntList>::const_iterator aIt;
+ QIntList aShaperActions = shaperActions();
+ foreach(int aCmd, aShaperActions) {
+ anAction = action(aCmd);
+ aId = aMgr->actionId(anAction);
+ if (!aMgr->containsAction(aId))
+ aFreeCommands.append(aCmd);
+ }
+ return aFreeCommands;
+}
+
+void SHAPERGUI::resetToolbars()
+{
+ if (!myDefaultToolbars.isEmpty())
+ updateToolbars(myDefaultToolbars);
+ myIsToolbarsModified = false;
+ SUIT_ResourceMgr* aResMgr = application()->resourceMgr();
+ aResMgr->remove(ToolbarsSection);
+}