Salome HOME
Accept/Abort buttons in salome
[modules/shaper.git] / src / NewGeom / NewGeom_NestedButton.cpp
1 /*
2  * NewGeom_NestedButton.cpp
3  *
4  *  Created on: Apr 13, 2015
5  *      Author: sbh
6  */
7
8 #include <NewGeom_NestedButton.h>
9
10 #include <QAction>
11 #include <QFrame>
12 #include <QHBoxLayout>
13 #include <QToolButton>
14
15 NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent,
16                                            const QList<QAction*>& theNestedActions)
17 : QWidgetAction(theParent),
18   myNestedActions(theNestedActions),
19   myAdditionalButtonsWidget(0),
20   myButtonFrame(0),
21   myThisButton(0)
22 {
23 }
24
25 NewGeom_NestedButton::~NewGeom_NestedButton()
26 {
27 }
28
29 void NewGeom_NestedButton::showAdditionalButtons(bool isShow)
30 {
31   myAdditionalButtonsWidget->setVisible(isShow);
32   if (isShow) {
33     myButtonFrame->setFrameStyle(QFrame::WinPanel);
34     myButtonFrame->setFrameShadow(QFrame::Sunken);
35     myThisButton->setAutoRaise(false);
36   } else {
37     myButtonFrame->setFrameStyle(QFrame::NoFrame);
38     myButtonFrame->setFrameShadow(QFrame::Plain);
39     myThisButton->setAutoRaise(true);
40   }
41 }
42
43 QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent)
44 {
45   myButtonFrame = new QFrame(theParent);
46   QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
47   aBoxLay->setContentsMargins(2, 0, 0, 0);
48   aBoxLay->setSpacing(1);
49
50   myThisButton = new QToolButton(myButtonFrame);
51   myThisButton->setDefaultAction(this);
52   myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
53   aBoxLay->addWidget(myThisButton, 1);
54
55   myAdditionalButtonsWidget = new QWidget(myButtonFrame);
56   QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
57   aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
58   aAdditionalBoxLay->setSpacing(1);
59   foreach (QAction* eachAct, myNestedActions) {
60     QToolButton* aButton = new QToolButton(myButtonFrame);
61     aButton->setDefaultAction(eachAct);
62     aButton->setAutoRaise(true);
63     aAdditionalBoxLay->addWidget(aButton);
64   }
65   myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
66   aBoxLay->addWidget(myAdditionalButtonsWidget);
67
68   myButtonFrame->setLayout(aBoxLay);
69
70   showAdditionalButtons(false);
71   connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
72   connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
73   return myButtonFrame;
74 }
75
76 void NewGeom_NestedButton::actionStateChanged()
77 {
78   if (isEnabled()) {
79     QString s = "true";
80   } else {
81     QString s = "false";
82   }
83   
84 }