#include <QAction>
#include <QTimer>
#include <QMenu>
+#include <QToolBar>
#define SALOME_PATCH_FOR_CTRL_WHEEL
createTool(separator(), aWBTool);
registerCommandToolbar(theTBName, -1);
}
-
return aAction;
}
createMenu(separator(), aMenu, -1, theMenuPosition);
}
+//******************************************************
bool SHAPERGUI::addActionInToolbar( QAction* theAction, const QString& theToolBarTitle )
{
if( !theAction )
void SHAPERGUI::onEditToolbars()
{
- SHAPERGUI_ToolbarsDlg aDlg(this, myActionsList, myToolbars);
- aDlg.exec();
+ SHAPERGUI_ToolbarsDlg aDlg(this);
+ if (aDlg.exec() == QDialog::Accepted) {
+ updateToolbars(aDlg.result());
+ }
}
void SHAPERGUI::registerCommandToolbar(const QString& theToolName, int theCommandId)
QtxActionMenuMgr* aMenuMgr = menuMgr();
QIntList aIds = aMenuMgr->idList();
int aId = aIds.count();
- while (aIds.contains(aId))
+ while (action(aId) || myActionsList.contains(aId))
aId++;
return aId;
}
+
+void SHAPERGUI::updateToolbars(const QMap<QString, QIntList>& theNewToolbars)
+{
+ 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();
+ QToolBar* aToolbar = 0;
+ QList<QAction*> aActionList;
+ foreach(QString aName, aToolbars) {
+ aMgr->removeToolBar(aName);
+ }
+ // Set new toolbars structure
+ myToolbars = theNewToolbars;
+}
#include <CAM_Application.h>
#include <SUIT_Desktop.h>
+#include <QtxActionToolMgr.h>
#include <QLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QInputDialog>
#include <QMessageBox>
+#include <QMouseEvent>
+#define SEPARATOR "------"
+#define LIST_WIDTH 180
+
class SHAPERGUI_CommandIdItem : public QListWidgetItem
{
public:
virtual QVariant data(int theRole) const {
- if (theRole == Qt::DisplayRole) {
- if (myId == -1)
- return "------";
- QAction* aAction = myModule->action(myId);
+ QAction* aAction = 0;
+ if (myId != -1)
+ aAction = myModule->action(myId);
+
+ switch (theRole) {
+ case Qt::DisplayRole:
if (aAction)
return aAction->text();
+ else
+ return SEPARATOR;
+ case Qt::DecorationRole:
+ if (aAction)
+ return aAction->icon();
+ else
+ return QIcon();
}
return QListWidgetItem::data(theRole);
}
+ int id() const { return myId; }
+
private:
SHAPERGUI* myModule;
int myId;
//************************************************************************************
//************************************************************************************
//************************************************************************************
-SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule,
- const QIntList& theActionsList,
- const QMap<QString, QIntList>& theToolbars)
+SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule)
: QDialog(theModule->application()->desktop()),
myModule(theModule),
- myActionsList(theActionsList),
- myToolbars(theToolbars)
+ myResult(theModule->shaperToolbars())
{
+ myFreeCommands = getModuleFreeCommands();
+
setWindowTitle(tr("Toolbars"));
QVBoxLayout* aMailLayout = new QVBoxLayout(this);
aListLayout->addWidget(new QLabel(tr("Toolbars:"), aListWgt));
myToolbarsList = new QListWidget(aListWgt);
- myToolbarsList->addItems(theToolbars.keys());
+ connect(myToolbarsList, SIGNAL(doubleClicked(const QModelIndex&)),
+ SLOT(onDoubleClick(const QModelIndex&)));
aListLayout->addWidget(myToolbarsList);
+ QWidget* aFreeItemsWgt = new QWidget(aListWgt);
+ QHBoxLayout* aFreeLayout = new QHBoxLayout(aFreeItemsWgt);
+ aFreeLayout->setContentsMargins(0, 0, 0, 0);
+ aListLayout->addWidget(aFreeItemsWgt);
+
+ aFreeLayout->addWidget(new QLabel(tr("Number of commands out of toolbars:"), aFreeItemsWgt));
+ myFreeNbLbl = new QLabel(aFreeItemsWgt);
+ aFreeLayout->addWidget(myFreeNbLbl);
+
// Left controls
QWidget* aButtonsWgt = new QWidget(aControlsWgt);
QVBoxLayout* aBtnLayout = new QVBoxLayout(aButtonsWgt);
aMailLayout->addWidget(aButtons);
connect(aButtons, SIGNAL(accepted()), SLOT(accept()));
connect(aButtons, SIGNAL(rejected()), SLOT(reject()));
+
+ updateToolbarsList();
+ updateNumber();
}
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();
+ if (!myResult.contains(aNewToolbar)) {
+ myResult[aNewToolbar] = QIntList();
updateToolbarsList();
}
else {
QList<QListWidgetItem*> aSelected = myToolbarsList->selectedItems();
if (aSelected.size() == 1) {
QString aToolbarName = aSelected.first()->text();
- QIntList aFreeItems = getFreeCommands();
+ int aPos = aToolbarName.lastIndexOf(" (");
+ aToolbarName = aToolbarName.left(aPos);
+
SHAPERGUI_ToolbarItemsDlg aDlg(this, myModule,
- aToolbarName, aFreeItems, myToolbars[aToolbarName]);
- aDlg.exec();
+ aToolbarName, myFreeCommands, myResult[aToolbarName]);
+ if (aDlg.exec() == QDialog::Accepted) {
+ myFreeCommands = aDlg.freeItems();
+ myResult[aToolbarName] = aDlg.toolbarItems();
+ updateNumber();
+ updateToolbarsList();
+ }
}
}
QList<QListWidgetItem*> aSelected = myToolbarsList->selectedItems();
if (aSelected.size() == 1) {
QString aToolbarName = aSelected.first()->text();
+ int aPos = aToolbarName.lastIndexOf(" (");
+ aToolbarName = aToolbarName.left(aPos);
+
QString aMsg = tr("Toolbar %1 will be deleted. Continue?").arg(aToolbarName);
if (QMessageBox::question(this, tr("Delete toolbar"), aMsg) == QMessageBox::Yes) {
- myToolbars.remove(aToolbarName);
+ myFreeCommands.append(myResult[aToolbarName]);
+ // remove separators from free items
+ myFreeCommands.removeAll(-1);
+ myResult.remove(aToolbarName);
updateToolbarsList();
+ updateNumber();
}
}
}
void SHAPERGUI_ToolbarsDlg::updateToolbarsList()
{
myToolbarsList->clear();
- myToolbarsList->addItems(myToolbars.keys());
+ QStringList aItems;
+ QMap<QString, QIntList>::const_iterator aIt;
+ for (aIt = myResult.cbegin(); aIt != myResult.cend(); aIt++) {
+ aItems.append(aIt.key() + tr(" (%1 items)").arg(aIt.value().size() - aIt.value().count(-1)));
+ }
+ myToolbarsList->addItems(aItems);
}
-QIntList SHAPERGUI_ToolbarsDlg::getFreeCommands() const
+QIntList SHAPERGUI_ToolbarsDlg::getModuleFreeCommands() const
{
QIntList aFreeCommands;
+ QtxActionToolMgr* aMgr = myModule->toolMgr();
+ QAction* anAction;
+ int aId;
QMap<QString, QIntList>::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)
+ QIntList aShaperActions = myModule->shaperActions();
+ foreach(int aCmd, aShaperActions) {
+ anAction = myModule->action(aCmd);
+ aId = aMgr->actionId(anAction);
+ if (!aMgr->containsAction(aId))
aFreeCommands.append(aCmd);
}
return aFreeCommands;
}
+void SHAPERGUI_ToolbarsDlg::onDoubleClick(const QModelIndex& theIdx)
+{
+ if (theIdx.isValid())
+ onEdit();
+}
+
+void SHAPERGUI_ToolbarsDlg::updateNumber()
+{
+ myFreeNbLbl->setText(QString::number(myFreeCommands.size()));
+}
+
//************************************************************************************
//************************************************************************************
//************************************************************************************
const QIntList& theFreeItems,
const QIntList& theItemsList)
: QDialog(theParent),
- myModule(theModule),
- myFreeItems(theFreeItems),
- myToolItems(theItemsList)
+ myModule(theModule)
{
setWindowTitle(tr("Edit toolbar items"));
aCommandsLay->addWidget(new QLabel(tr("Out of toolbars:"), aCommandsWgt));
myCommandsList = new QListWidget(aCommandsWgt);
- foreach(int aId, myFreeItems) {
+ myCommandsList->setSortingEnabled(false);
+
+ myCommandsList->addItem(new SHAPERGUI_CommandIdItem(myCommandsList, -1, myModule));
+ foreach(int aId, theFreeItems) {
myCommandsList->addItem(new SHAPERGUI_CommandIdItem(myCommandsList, aId, myModule));
}
- myCommandsList->setMaximumWidth(150);
+ myCommandsList->setMaximumWidth(LIST_WIDTH);
aCommandsLay->addWidget(myCommandsList);
// Middle buttons
aCtrlLayout->addWidget(aButtonsWgt);
aBtnLayout->addStretch(1);
- QPushButton* aAddButton = new QPushButton("--->", aButtonsWgt);
+ QPushButton* aAddButton = new QPushButton(QIcon(":pictures/arrow-right.png"), "", aButtonsWgt);
connect(aAddButton, SIGNAL(clicked(bool)), SLOT(onAddItem()));
aBtnLayout->addWidget(aAddButton);
aBtnLayout->addSpacing(20);
- QPushButton* aDelButton = new QPushButton("<---", aButtonsWgt);
+ QPushButton* aDelButton = new QPushButton(QIcon(":pictures/arrow-left.png"), "", aButtonsWgt);
connect(aDelButton, SIGNAL(clicked(bool)), SLOT(onDelItem()));
aBtnLayout->addWidget(aDelButton);
aBtnLayout->addStretch(1);
aItemsLay->addWidget(new QLabel(tr("In the toolbar:"), aItemsWgt));
myItemsList = new QListWidget(aItemsWgt);
- foreach(int aId, myToolItems) {
+ myItemsList->setSortingEnabled(false);
+ foreach(int aId, theItemsList) {
myItemsList->addItem(new SHAPERGUI_CommandIdItem(myItemsList, aId, myModule));
}
- myItemsList->setMaximumWidth(150);
+ myItemsList->setMaximumWidth(LIST_WIDTH);
+ myItemsList->viewport()->installEventFilter(this);
aItemsLay->addWidget(myItemsList);
+ // Buttons of right list
+ QWidget* aBtnWgt = new QWidget(aControlsWgt);
+ QVBoxLayout* aBtnLay = new QVBoxLayout(aBtnWgt);
+ aBtnLay->setContentsMargins(0, 0, 0, 0);
+ aCtrlLayout->addWidget(aBtnWgt);
+
+ aBtnLay->addStretch(1);
+ QPushButton* aUpButton = new QPushButton(QIcon(":pictures/arrow-up.png"), "", aBtnWgt);
+ connect(aUpButton, SIGNAL(clicked(bool)), SLOT(onUp()));
+ aBtnLay->addWidget(aUpButton);
+
+ aBtnLay->addSpacing(20);
+
+ QPushButton* aDownButton = new QPushButton(QIcon(":pictures/arrow-down.png"), "", aBtnWgt);
+ connect(aDownButton, SIGNAL(clicked(bool)), SLOT(onDown()));
+ aBtnLay->addWidget(aDownButton);
+ aBtnLay->addStretch(1);
+
// Buttons part of the dialog
QDialogButtonBox* aButtons =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
void SHAPERGUI_ToolbarItemsDlg::onAddItem()
{
-
+ QList<QListWidgetItem*> aCurrentList = myCommandsList->selectedItems();
+ if (aCurrentList.size() > 0) {
+ SHAPERGUI_CommandIdItem* aItem = dynamic_cast<SHAPERGUI_CommandIdItem*>(aCurrentList.first());
+ int aId = aItem->id();
+ if (aId != -1) {
+ myCommandsList->removeItemWidget(aItem);
+ delete aItem;
+ }
+ QModelIndex aIdx = myItemsList->currentIndex();
+ aItem = new SHAPERGUI_CommandIdItem(0, aId, myModule);
+ if (aIdx.isValid()) {
+ int aRow = aIdx.row();
+ myItemsList->insertItem(aRow, aItem);
+ }
+ else {
+ myItemsList->addItem(aItem);
+ }
+ }
}
void SHAPERGUI_ToolbarItemsDlg::onDelItem()
{
+ QList<QListWidgetItem*> aCurrentList = myItemsList->selectedItems();
+ if (aCurrentList.size() > 0) {
+ SHAPERGUI_CommandIdItem* aItem = dynamic_cast<SHAPERGUI_CommandIdItem*>(aCurrentList.first());
+ int aId = aItem->id();
+ myItemsList->removeItemWidget(aItem);
+ delete aItem;
+ if (aId != -1) {
+ aItem = new SHAPERGUI_CommandIdItem(myCommandsList, aId, myModule);
+ myCommandsList->addItem(aItem);
+ }
+ }
+}
+
+
+bool SHAPERGUI_ToolbarItemsDlg::eventFilter(QObject* theObj, QEvent* theEvent)
+{
+ if (theEvent->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent* aMouseEvent = (QMouseEvent*)theEvent;
+ QModelIndex aIdx = myItemsList->indexAt(aMouseEvent->pos());
+ if (!aIdx.isValid() || aMouseEvent->button() == Qt::RightButton) {
+ myItemsList->setCurrentIndex(QModelIndex());
+ }
+ }
+ return QDialog::eventFilter(theObj, theEvent);
+}
+
+void SHAPERGUI_ToolbarItemsDlg::onUp()
+{
+ QModelIndex aCurrentIdx = myItemsList->currentIndex();
+ if (aCurrentIdx.isValid()) {
+ int aRow = aCurrentIdx.row();
+ if (aRow > 0) {
+ QListWidgetItem* aItem = myItemsList->takeItem(aRow);
+ aRow--;
+ myItemsList->insertItem(aRow, aItem);
+ myItemsList->setCurrentRow(aRow);
+ }
+ }
+}
+
+void SHAPERGUI_ToolbarItemsDlg::onDown()
+{
+ QModelIndex aCurrentIdx = myItemsList->currentIndex();
+ if (aCurrentIdx.isValid()) {
+ int aNb = myItemsList->count();
+ int aRow = aCurrentIdx.row();
+ if (aRow < (aNb - 1)) {
+ QListWidgetItem* aItem = myItemsList->takeItem(aRow);
+ aRow++;
+ myItemsList->insertItem(aRow, aItem);
+ myItemsList->setCurrentRow(aRow);
+ }
+ }
+}
-}
\ No newline at end of file
+QIntList SHAPERGUI_ToolbarItemsDlg::freeItems() const
+{
+ return getItems(myCommandsList, 1);
+}
+
+QIntList SHAPERGUI_ToolbarItemsDlg::toolbarItems() const
+{
+ return getItems(myItemsList, 0);
+}
+
+QIntList SHAPERGUI_ToolbarItemsDlg::getItems(QListWidget* theWidget, int theStart) const
+{
+ QIntList aList;
+ SHAPERGUI_CommandIdItem* aItem = 0;
+ int aNb = theWidget->count();
+ for (int i = theStart; i < aNb; i++) {
+ aItem = (SHAPERGUI_CommandIdItem*)theWidget->item(i);
+ aList.append(aItem->id());
+ }
+ return aList;
+}
class QListWidget;
class SHAPERGUI;
+class QLabel;
-
+/**
+* \ingroup Salome
+* A dialog box for editing of toolbar items
+*/
class SHAPERGUI_ToolbarItemsDlg : public QDialog
{
Q_OBJECT
public:
+ /// Constructor
+ /// \param theParent a parent for the dialog
+ /// \param theModule a module with toolbars
+ /// \param theToolbar a name of the toolbar for editing
+ /// \param theFreeItems a list of commands out of toolbars
+ /// \param theItemsList a list of command in the toolbar
SHAPERGUI_ToolbarItemsDlg(QWidget* theParent,
SHAPERGUI* theModule,
const QString& theToolbar,
const QIntList& theFreeItems,
const QIntList& theItemsList);
+ /// Returns list of free commands
+ QIntList freeItems() const;
+
+ /// Returns list of commands in the toolbar
+ QIntList toolbarItems() const;
+
+protected:
+ /// An redifinition of a virtual function
+ /// \param theObj an object
+ /// \param theEvent an event
+ virtual bool eventFilter(QObject* theObj, QEvent* theEvent);
+
private slots:
+ /// A slot for button to add an item to toolbar commands
void onAddItem();
+
+ /// A slot for button to remove an item from toolbar commands
void onDelItem();
+ /// A slot to move a current item up in list of toolbar command
+ void onUp();
+
+ /// A slot to move a current item down in list of toolbar command
+ void onDown();
+
private:
+ QIntList getItems(QListWidget* theWidget, int theStart) const;
+
SHAPERGUI* myModule;
- QIntList myFreeItems;
- QIntList myToolItems;
QListWidget* myCommandsList;
QListWidget* myItemsList;
{
Q_OBJECT
public:
- SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule,
- const QIntList& theActionsList,
- const QMap<QString, QIntList>& theToolbars);
+ /// Constructor
+ /// \param theModule a SHAPER module
+ SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule);
- QMap<QString, QIntList> result() const { return myToolbars; }
+ /// Returns result of editing
+ QMap<QString, QIntList> result() const { return myResult; }
private slots:
+ /// A slot to add a new toolbar
void onAdd();
+ /// A slot to edit a current toolbar
void onEdit();
+ /// A slot to delete a current toolbar
void onDelete();
+ /// A slot called on double click on item in list
+ void onDoubleClick(const QModelIndex& theIdx);
+
private:
+ /// Update content of toolbars list
void updateToolbarsList();
- QIntList getFreeCommands() const;
+ /// Update number of free items
+ void updateNumber();
+
+ /// Returns free commands which are not in toolbars in the module
+ QIntList getModuleFreeCommands() const;
private:
SHAPERGUI* myModule;
- QIntList myActionsList;
- QMap<QString, QIntList> myToolbars;
+ QMap<QString, QIntList> myResult;
+ QIntList myFreeCommands;
+ QLabel* myFreeNbLbl;
QListWidget* myToolbarsList;
};