Salome HOME
Update just modified part tree in object browser
[modules/shaper.git] / src / XGUI / XGUI_MenuGroupPanel.cpp
1 #include "XGUI_MenuGroupPanel.h"
2 #include "XGUI_Command.h"
3
4 #include <QLayout>
5 #include <QPushButton>
6 #include <QAction>
7 #include <QResizeEvent>
8
9 #include <math.h>
10
11 XGUI_MenuGroupPanel::XGUI_MenuGroupPanel(QWidget *parent)
12     : QWidget(parent), myNewRow(0), myNewCol(0), myMaxRow(1)
13 {
14   myLayout = new QGridLayout(this);
15   myLayout->setSpacing(0);
16   myLayout->setMargin(0);
17   myLayout->setContentsMargins(0, 0, 0, 0);
18 }
19
20 void XGUI_MenuGroupPanel::addCommand(XGUI_Command* theAction)
21 {
22   myActions.append(theAction);
23   QWidget* aWdg = theAction->requestWidget(this);
24   myActionWidget.append(aWdg);
25   addWidget(aWdg);
26 }
27
28 void XGUI_MenuGroupPanel::placeWidget(QWidget* theWgt)
29 {
30   if (myMaxRow == myNewRow) {
31     myNewRow = 0;
32     myNewCol++;
33   }
34   myLayout->addWidget(theWgt, myNewRow, myNewCol, Qt::AlignLeft);
35   myNewRow++;
36 }
37
38 void XGUI_MenuGroupPanel::addWidget(QWidget* theWgt)
39 {
40   placeWidget(theWgt);
41 }
42
43 void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent)
44 {
45   QWidget::resizeEvent(theEvent);
46   if (myActions.size() == 0)
47     return;
48
49   int aH = theEvent->size().height();
50   int aMaxRow = (int) floor(double(aH / MIN_BUTTON_HEIGHT));
51   if (aMaxRow == myMaxRow)
52     return;
53
54   myMaxRow = aMaxRow;
55   myNewRow = 0;
56   myNewCol = 0;
57   foreach(QWidget* eachWidget, myActionWidget) {
58     placeWidget(eachWidget);
59   }
60 }
61
62 XGUI_Command* XGUI_MenuGroupPanel::addFeature(const QString& theId, const QString& theTitle,
63                                               const QString& theTip, const QIcon& theIcon,
64                                               const QKeySequence& theKeys)
65 {
66   XGUI_Command* aCommand = new XGUI_Command(theId, theIcon, theTitle, this);
67   aCommand->setToolTip(theTip);
68   if (!theKeys.isEmpty())
69     aCommand->setShortcut(theKeys);
70
71   addCommand(aCommand);
72   return aCommand;
73 }
74
75
76 XGUI_Command* XGUI_MenuGroupPanel::feature(const QString& theId) const
77 {
78   QList<XGUI_Command*>::const_iterator aIt;
79   for (aIt = myActions.constBegin(); aIt != myActions.constEnd(); ++aIt)
80     if ((*aIt)->id() == theId)
81       return (*aIt);
82   return 0;
83 }