]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_MenuGroupPanel.cpp
Salome HOME
"GUI" stubs for testing of CMake building procedures, preliminary examples of GUI
[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
21 void XGUI_MenuGroupPanel::addCommand(XGUI_Command* theAction)
22 {
23     addWidget(theAction->requestWidget(this));
24 }
25
26 void XGUI_MenuGroupPanel::placeWidget(QWidget* theWgt)
27 {
28     if (myMaxRow == myNewRow) {
29         myNewRow = 0;
30         myNewCol++;
31     }
32     myLayout->addWidget(theWgt, myNewRow, myNewCol, Qt::AlignLeft);
33     myNewRow++;
34 }
35
36 void XGUI_MenuGroupPanel::addWidget(QWidget* theWgt)
37 {
38     placeWidget(theWgt);
39     myWidgets.append(theWgt);
40 }
41
42
43 void XGUI_MenuGroupPanel::resizeEvent(QResizeEvent* theEvent)
44 {
45     QWidget::resizeEvent(theEvent);
46     if (myWidgets.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     QListIterator<QWidget*> aIt(myWidgets);
56     myNewRow = 0;
57     myNewCol = 0;
58     while (aIt.hasNext()) {
59        placeWidget(aIt.next());
60     }
61 }