Salome HOME
Rename NewGeom_* into SHAPERGUI_*
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_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 #include <QEvent>
15
16 NewGeom_NestedButton::NewGeom_NestedButton(QObject* theParent,
17                                            const QList<QAction*>& theNestedActions)
18 : QWidgetAction(theParent),
19   myNestedActions(theNestedActions),
20   myAdditionalButtonsWidget(0),
21   myButtonFrame(0),
22   myThisButton(0)
23 {
24 }
25
26 NewGeom_NestedButton::~NewGeom_NestedButton()
27 {
28 }
29
30 void NewGeom_NestedButton::showAdditionalButtons(bool isShow)
31 {
32   myAdditionalButtonsWidget->setVisible(isShow);
33   if (isShow) {
34     myButtonFrame->setFrameStyle(QFrame::WinPanel);
35     myButtonFrame->setFrameShadow(QFrame::Sunken);
36     myThisButton->setAutoRaise(false);
37   } else {
38     myButtonFrame->setFrameStyle(QFrame::NoFrame);
39     myButtonFrame->setFrameShadow(QFrame::Plain);
40     myThisButton->setAutoRaise(true);
41   }
42 }
43
44 QWidget * NewGeom_NestedButton::createWidget(QWidget * theParent)
45 {
46   myButtonFrame = new QFrame(theParent);
47   QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
48   aBoxLay->setContentsMargins(2, 0, 0, 0);
49   aBoxLay->setSpacing(1);
50   QSizePolicy aSizePolicy;
51   aSizePolicy.setControlType(QSizePolicy::ToolButton);
52   myButtonFrame->setSizePolicy(aSizePolicy);
53
54   myThisButton = new QToolButton(myButtonFrame);
55   myThisButton->setDefaultAction(this);
56   myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
57   aBoxLay->addWidget(myThisButton, 1);
58
59   myAdditionalButtonsWidget = new QWidget(myButtonFrame);
60   QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
61   aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
62   aAdditionalBoxLay->setSpacing(1);
63   foreach (QAction* eachAct, myNestedActions) {
64     QToolButton* aButton = new QToolButton(myButtonFrame);
65     aButton->setDefaultAction(eachAct);
66     aButton->setAutoRaise(true);
67     aAdditionalBoxLay->addWidget(aButton);
68   }
69   myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
70   aBoxLay->addWidget(myAdditionalButtonsWidget);
71
72   myButtonFrame->setLayout(aBoxLay);
73
74   showAdditionalButtons(false);
75   connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
76   connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
77   return myButtonFrame;
78 }
79
80 bool NewGeom_NestedButton::event(QEvent* theEvent)
81 {
82   if (theEvent->type() == QEvent::ActionChanged) {
83     if (myThisButton) {
84       myThisButton->setEnabled(isEnabled());
85       return true;
86     }
87   }
88   return QWidgetAction::event(theEvent);
89 }
90
91
92 void NewGeom_NestedButton::actionStateChanged()
93 {
94   if (isEnabled()) {
95     QString s = "true";
96   } else {
97     QString s = "false";
98   }
99   
100 }