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>
17 //! Extends given feature with previously created context menu.
18 //! \param theId - Id of the feature to add \a theMenu
19 //! \param theMenu - Enables or disables menu feature
20 XGUI_HistoryMenu::XGUI_HistoryMenu(QAction* theParent)
24 theParent->setMenu(this);
27 connect(theParent, SIGNAL(destroyed()), this, SLOT(deleteLater()));
30 //! Extends given feature with previously created context menu.
31 //! \param theId - Id of the feature to add \a theMenu
32 //! \param theMenu - Enables or disables menu feature
33 XGUI_HistoryMenu::XGUI_HistoryMenu(QToolButton* theParent)
37 theParent->setMenu(this);
38 theParent->setPopupMode(QToolButton::MenuButtonPopup);
43 void XGUI_HistoryMenu::initMenu()
45 myHistoryList = new QListWidget(this);
46 QWidgetAction* aListAction = new QWidgetAction(this);
47 aListAction->setDefaultWidget(myHistoryList);
48 this->addAction(aListAction);
49 myHistoryList->setMouseTracking(true); // track mouse hover
50 myHistoryList->setSelectionMode(QAbstractItemView::ExtendedSelection);
51 connect(myHistoryList, SIGNAL(itemEntered(QListWidgetItem *)), this,
52 SLOT(setStackSelectedTo(QListWidgetItem *)));
53 connect(myHistoryList, SIGNAL(itemClicked(QListWidgetItem *)), this,
54 SLOT(onItemPressed(QListWidgetItem *)));
57 XGUI_HistoryMenu::~XGUI_HistoryMenu()
61 void XGUI_HistoryMenu::setHistory(const QList<ActionInfo>& theActions)
63 myHistoryList->clear();
64 foreach(ActionInfo anAct, theActions) {
65 QListWidgetItem* anItem = new QListWidgetItem(anAct.icon, anAct.text, myHistoryList);
70 void XGUI_HistoryMenu::setStackSelectedTo(QListWidgetItem * theItem)
75 QListWidgetItem* eachItem = NULL;
77 for(int aRow = 0; aRow < myHistoryList->count(); ++aRow) {
78 eachItem = myHistoryList->item(aRow);
79 myHistoryList->setItemSelected(eachItem, isSelect);
80 // Deselect items below hovered
81 if (eachItem == theItem) {
87 void XGUI_HistoryMenu::onItemPressed(QListWidgetItem * theItem)
89 int selectedSize = myHistoryList->row(theItem) + 1;
90 emit actionSelected(selectedSize);
92 myHistoryList->clear();