]> SALOME platform Git repositories - modules/shaper.git/blob - src/SHAPERGUI/SHAPERGUI_NestedButton.cpp
Salome HOME
Reverted some changes in salome build/run scripts.
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_NestedButton.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 /*
22  * SHAPERGUI_NestedButton.cpp
23  *
24  *  Created on: Apr 13, 2015
25  *      Author: sbh
26  */
27
28 #include <SHAPERGUI_NestedButton.h>
29
30 #include <QAction>
31 #include <QFrame>
32 #include <QHBoxLayout>
33 #include <QToolButton>
34 #include <QToolBar>
35 #include <QEvent>
36
37 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
38                                            const QList<QAction*>& theNestedActions)
39 : QWidgetAction(theParent),
40   myNestedActions(theNestedActions),
41   myAdditionalButtonsWidget(0),
42   myButtonFrame(0),
43   myThisButton(0)
44 {
45 }
46
47 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
48 {
49 }
50
51 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
52 {
53   myAdditionalButtonsWidget->setVisible(isShow);
54   if (isShow) {
55     myButtonFrame->setFrameStyle(QFrame::WinPanel);
56     myButtonFrame->setFrameShadow(QFrame::Sunken);
57     myThisButton->setAutoRaise(false);
58   } else {
59     myButtonFrame->setFrameStyle(QFrame::NoFrame);
60     myButtonFrame->setFrameShadow(QFrame::Plain);
61     myThisButton->setAutoRaise(true);
62   }
63 }
64
65 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
66 {
67   // the action has widget only in tool bar, in menu bar, the default
68   // action presentation is shown
69   QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
70   if (!aToolBar)
71     return 0;
72
73   myButtonFrame = new QFrame(theParent);
74   QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
75   aBoxLay->setContentsMargins(2, 0, 0, 0);
76   aBoxLay->setSpacing(1);
77   QSizePolicy aSizePolicy;
78   aSizePolicy.setControlType(QSizePolicy::ToolButton);
79   myButtonFrame->setSizePolicy(aSizePolicy);
80
81   myThisButton = new QToolButton(myButtonFrame);
82   myThisButton->setDefaultAction(this);
83   myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
84   aBoxLay->addWidget(myThisButton, 1);
85
86   myAdditionalButtonsWidget = new QWidget(myButtonFrame);
87   QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
88   aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
89   aAdditionalBoxLay->setSpacing(1);
90   foreach (QAction* eachAct, myNestedActions) {
91     QToolButton* aButton = new QToolButton(myButtonFrame);
92     aButton->setDefaultAction(eachAct);
93     aButton->setAutoRaise(true);
94     aAdditionalBoxLay->addWidget(aButton);
95   }
96   myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
97   aBoxLay->addWidget(myAdditionalButtonsWidget);
98
99   myButtonFrame->setLayout(aBoxLay);
100
101   showAdditionalButtons(false);
102   connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
103   connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
104   return myButtonFrame;
105 }
106
107 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
108 {
109   if (theEvent->type() == QEvent::ActionChanged) {
110     if (myThisButton) {
111       myThisButton->setEnabled(isEnabled());
112       return true;
113     }
114   }
115   return QWidgetAction::event(theEvent);
116 }
117
118
119 void SHAPERGUI_NestedButton::actionStateChanged()
120 {
121   if (isEnabled()) {
122     QString s = "true";
123   } else {
124     QString s = "false";
125   }
126
127 }