#include <QListWidget>
#include <QWidgetAction>
#include <QToolButton>
+#include <QAction>
+
+//! Extends given feature with previously created context menu.
+//! \param theId - Id of the feature to add \a theMenu
+//! \param theMenu - Enables or disables menu feature
+XGUI_HistoryMenu::XGUI_HistoryMenu(QAction* theParent)
+ : QMenu(NULL),
+ myHistoryList(NULL)
+{
+ theParent->setMenu(this);
+ initMenu();
+
+ connect(theParent, SIGNAL(destroyed()), this, SLOT(deleteLater()));
+}
//! Extends given feature with previously created context menu.
//! \param theId - Id of the feature to add \a theMenu
//! \param theMenu - Enables or disables menu feature
XGUI_HistoryMenu::XGUI_HistoryMenu(QToolButton* theParent)
: QMenu(theParent),
- myHistoryList(new QListWidget(this))
+ myHistoryList(NULL)
{
theParent->setMenu(this);
theParent->setPopupMode(QToolButton::MenuButtonPopup);
+ initMenu();
+}
+
+void XGUI_HistoryMenu::initMenu()
+{
+ myHistoryList = new QListWidget(this);
QWidgetAction* aListAction = new QWidgetAction(this);
aListAction->setDefaultWidget(myHistoryList);
this->addAction(aListAction);
-
- myHistoryList->setMouseTracking(true); // track mouse hover
+ myHistoryList->setMouseTracking(true); // track mouse hover
myHistoryList->setSelectionMode(QAbstractItemView::ExtendedSelection);
- connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)),
- this, SLOT(setStackSelectedTo(QListWidgetItem *)));
- connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)),
- this, SLOT(onItemPressed(QListWidgetItem *)));
+ connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)), this,
+ SLOT(setStackSelectedTo(QListWidgetItem *)));
+ connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)), this,
+ SLOT(onItemPressed(QListWidgetItem *)));
}
XGUI_HistoryMenu::~XGUI_HistoryMenu()
void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
{
int selectedSize = myHistoryList->row(theItem) + 1;
- emit actionsSelected(selectedSize);
+ emit actionSelected(selectedSize);
hide();
myHistoryList->clear();
}
QIcon(":pictures/undo.png"),
QKeySequence::Undo, false, "MEN_DESK_EDIT");
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
+ addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
+
aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo,
false, "MEN_DESK_EDIT");
connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
+ addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
+
salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"), QKeySequence(),
aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
QIcon(":pictures/undo.png"), QKeySequence::Undo);
aCommand->connectTo(this, SLOT(onUndo()));
-
- QToolButton* aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
- XGUI_HistoryMenu* aUndoMenu = new XGUI_HistoryMenu(aToolBtn);
- connect(this, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
- aUndoMenu, SLOT(setHistory(const QList<ActionInfo>&)));
- connect(aUndoMenu, SIGNAL(actionsSelected(int)),
- this, SLOT(onUndo(int)));
+ QToolButton* aUndoButton = qobject_cast<QToolButton*>(aGroup->widget(aUndoId));
+ addHistoryMenu(aUndoButton,
+ SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
+ SLOT(onUndo(int)));
QString aRedoId = "REDO_CMD";
aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
QIcon(":pictures/redo.png"), QKeySequence::Redo);
aCommand->connectTo(this, SLOT(onRedo()));
-
- aToolBtn = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
- XGUI_HistoryMenu* aRedoMenu = new XGUI_HistoryMenu(aToolBtn);
- connect(this, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
- aRedoMenu, SLOT(setHistory(const QList<QAction*>&)));
- connect(aRedoMenu, SIGNAL(actionsSelected(int)),
- this, SLOT(onUndo(int)));
+ QToolButton* aRedoButton = qobject_cast<QToolButton*>(aGroup->widget(aRedoId));
+ addHistoryMenu(aRedoButton,
+ SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
+ SLOT(onRedo(int)));
aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
QIcon(":pictures/rebuild.png"), QKeySequence());
} else
myDisplayer->display(theObj, false);
}
+
+void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
+{
+ XGUI_HistoryMenu* aMenu = NULL;
+ if (isSalomeMode()) {
+ QAction* anAction = qobject_cast<QAction*>(theObject);
+ if (!anAction)
+ return;
+ aMenu = new XGUI_HistoryMenu(anAction);
+ } else {
+ QToolButton* aButton = qobject_cast<QToolButton*>(theObject);
+ aMenu = new XGUI_HistoryMenu(aButton);
+ }
+ connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
+ connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
+
+}