4 * Created on: Feb 2, 2015
8 #include <XGUI_HistoryMenu.h>
10 #include <ModelAPI_Session.h>
12 #include <QListWidget>
13 #include <QWidgetAction>
14 #include <QToolButton>
16 //! Extends given feature with previously created context menu.
17 //! \param theId - Id of the feature to add \a theMenu
18 //! \param theMenu - Enables or disables menu feature
19 XGUI_HistoryMenu::XGUI_HistoryMenu(QToolButton* theParent)
21 myHistoryList(new QListWidget(this))
23 theParent->setMenu(this);
24 theParent->setPopupMode(QToolButton::MenuButtonPopup);
26 QWidgetAction* aListAction = new QWidgetAction(this);
27 aListAction->setDefaultWidget(myHistoryList);
28 this->addAction(aListAction);
30 myHistoryList->setMouseTracking(true); // track mouse hover
31 myHistoryList->setSelectionMode(QAbstractItemView::ExtendedSelection);
32 connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)),
33 this, SLOT(setStackSelectedTo(QListWidgetItem *)));
34 connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)),
35 this, SLOT(onItemPressed(QListWidgetItem *)));
38 XGUI_HistoryMenu::~XGUI_HistoryMenu()
42 void XGUI_HistoryMenu::setHistory(const QList<QAction*>& theActions)
44 myHistoryList->clear();
45 foreach(QAction* anAct, theActions) {
46 QListWidgetItem* anItem = new QListWidgetItem(anAct->icon(),
54 void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
59 QListWidgetItem* eachItem = NULL;
61 for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
62 eachItem = myHistoryList->item(aRow);
63 myHistoryList->setItemSelected(eachItem, isSelect);
64 // Deselect items below hovered
65 if (eachItem == theItem) {
71 void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
73 int selectedSize = myHistoryList->row(theItem) + 1;
74 emit actionsSelected(selectedSize);
76 myHistoryList->clear();