1 #include "XGUI_MenuGroupPanel.h"
2 #include "XGUI_Command.h"
7 #include <QResizeEvent>
12 XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent)
13 : QWidget(parent), myNewRow(0), myNewCol(0), myMaxRow(1)
15 myLayout = new QGridLayout(this);
16 myLayout->setSpacing(0);
17 myLayout->setMargin(0);
18 myLayout->setContentsMargins(0, 0, 0, 0);
21 void XGUI_MenuGroupPanel::addCommand(XGUI_Command* theAction)
23 myActions.append(theAction);
24 QWidget* aWdg = theAction->requestWidget(this);
25 myActionWidget.append(aWdg);
29 void XGUI_MenuGroupPanel::placeWidget(QWidget* theWgt)
31 if (myMaxRow == myNewRow) {
35 myLayout->addWidget(theWgt, myNewRow, myNewCol);
36 myLayout->setRowStretch(myNewRow, 0);
40 void XGUI_MenuGroupPanel::addWidget(QWidget* theWgt)
45 void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent)
47 QWidget::resizeEvent(theEvent);
48 if (myActions.size() == 0)
51 int aH = theEvent->size().height();
52 int aMaxRow = (int) floor(double(aH / MIN_BUTTON_HEIGHT));
53 if (aMaxRow == myMaxRow)
59 foreach(QWidget* eachWidget, myActionWidget) {
60 placeWidget(eachWidget);
62 myLayout->setRowStretch(myMaxRow + 1, 1);
65 XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle,
66 const QString& theTip, const QIcon& theIcon,
67 const QKeySequence& theKeys, bool isCheckable)
69 XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this, isCheckable);
70 aCommand->setToolTip(theTip);
71 if (!theKeys.isEmpty())
72 aCommand->setShortcut(theKeys);
79 XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
81 foreach (XGUI_Command* aCmd, myActions) {
82 if (aCmd->data().toString() == theId)