]> SALOME platform Git repositories - modules/shaper.git/blob - src/SHAPERGUI/SHAPERGUI_NestedButton.cpp
Salome HOME
Remove extra files
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_NestedButton.cpp
1 /*
2  * SHAPERGUI_NestedButton.cpp
3  *
4  *  Created on: Apr 13, 2015
5  *      Author: sbh
6  */
7
8 #include <SHAPERGUI_NestedButton.h>
9
10 #include <QAction>
11 #include <QFrame>
12 #include <QHBoxLayout>
13 #include <QToolButton>
14 #include <QToolBar>
15 #include <QEvent>
16
17 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
18                                            const QList<QAction*>& theNestedActions)
19 : QWidgetAction(theParent),
20   myNestedActions(theNestedActions),
21   myAdditionalButtonsWidget(0),
22   myButtonFrame(0),
23   myThisButton(0)
24 {
25 }
26
27 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
28 {
29 }
30
31 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
32 {
33   myAdditionalButtonsWidget->setVisible(isShow);
34   if (isShow) {
35     myButtonFrame->setFrameStyle(QFrame::WinPanel);
36     myButtonFrame->setFrameShadow(QFrame::Sunken);
37     myThisButton->setAutoRaise(false);
38   } else {
39     myButtonFrame->setFrameStyle(QFrame::NoFrame);
40     myButtonFrame->setFrameShadow(QFrame::Plain);
41     myThisButton->setAutoRaise(true);
42   }
43 }
44
45 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
46 {
47   // the action has widget only in tool bar, in menu bar, the default
48   // action presentation is shown
49   QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
50   if (!aToolBar)
51     return 0;
52
53   myButtonFrame = new QFrame(theParent);
54   QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
55   aBoxLay->setContentsMargins(2, 0, 0, 0);
56   aBoxLay->setSpacing(1);
57   QSizePolicy aSizePolicy;
58   aSizePolicy.setControlType(QSizePolicy::ToolButton);
59   myButtonFrame->setSizePolicy(aSizePolicy);
60
61   myThisButton = new QToolButton(myButtonFrame);
62   myThisButton->setDefaultAction(this);
63   myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
64   aBoxLay->addWidget(myThisButton, 1);
65
66   myAdditionalButtonsWidget = new QWidget(myButtonFrame);
67   QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
68   aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
69   aAdditionalBoxLay->setSpacing(1);
70   foreach (QAction* eachAct, myNestedActions) {
71     QToolButton* aButton = new QToolButton(myButtonFrame);
72     aButton->setDefaultAction(eachAct);
73     aButton->setAutoRaise(true);
74     aAdditionalBoxLay->addWidget(aButton);
75   }
76   myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
77   aBoxLay->addWidget(myAdditionalButtonsWidget);
78
79   myButtonFrame->setLayout(aBoxLay);
80
81   showAdditionalButtons(false);
82   connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
83   connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
84   return myButtonFrame;
85 }
86
87 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
88 {
89   if (theEvent->type() == QEvent::ActionChanged) {
90     if (myThisButton) {
91       myThisButton->setEnabled(isEnabled());
92       return true;
93     }
94   }
95   return QWidgetAction::event(theEvent);
96 }
97
98
99 void SHAPERGUI_NestedButton::actionStateChanged()
100 {
101   if (isEnabled()) {
102     QString s = "true";
103   } else {
104     QString s = "false";
105   }
106   
107 }