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<ActionInfo>& theActions)
44 myHistoryList->clear();
45 foreach(ActionInfo anAct, theActions) {
46 QListWidgetItem* anItem = new QListWidgetItem(anAct.icon, anAct.text, myHistoryList);
51 void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
56 QListWidgetItem* eachItem = NULL;
58 for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
59 eachItem = myHistoryList->item(aRow);
60 myHistoryList->setItemSelected(eachItem, isSelect);
61 // Deselect items below hovered
62 if (eachItem == theItem) {
68 void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
70 int selectedSize = myHistoryList->row(theItem) + 1;
71 emit actionsSelected(selectedSize);
73 myHistoryList->clear();