]> SALOME platform Git repositories - modules/shaper.git/blob - src/SHAPERGUI/SHAPERGUI_NestedButton.cpp
Salome HOME
[GITHUB #2] problem in export dialog - difference in STEP vs BREP
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_NestedButton.cpp
1 // Copyright (C) 2014-2024  CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19
20 /*
21  * SHAPERGUI_NestedButton.cpp
22  *
23  *  Created on: Apr 13, 2015
24  *      Author: sbh
25  */
26
27 #include <SHAPERGUI_NestedButton.h>
28
29 #include <QAction>
30 #include <QFrame>
31 #include <QHBoxLayout>
32 #include <QToolButton>
33 #include <QToolBar>
34 #include <QEvent>
35
36 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(
37   QObject* theParent,
38   const QString& theID,
39   const QList<QAction*>& theNestedActions
40 )
41 : QtxAction(theParent, false /*isCheckable*/, theID),
42   myNestedActions(theNestedActions),
43   myAdditionalButtonsWidget(0),
44   myButtonFrame(0),
45   myThisButton(0)
46 { }
47
48 void SHAPERGUI_NestedButton::setEnabled(bool theOn)
49 {
50   QtxAction::setEnabled(theOn);
51   if (myThisButton)
52     myThisButton->setEnabled(theOn);
53 }
54
55 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
56 {
57   myAdditionalButtonsWidget->setVisible(isShow);
58   if (isShow) {
59     myButtonFrame->setFrameStyle(QFrame::WinPanel);
60     myButtonFrame->setFrameShadow(QFrame::Sunken);
61     myThisButton->setAutoRaise(false);
62   } else {
63     myButtonFrame->setFrameStyle(QFrame::NoFrame);
64     myButtonFrame->setFrameShadow(QFrame::Plain);
65     myThisButton->setAutoRaise(true);
66   }
67 }
68
69 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
70 {
71   // the action has widget only in tool bar, in menu bar, the default
72   // action presentation is shown
73   QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
74   if (!aToolBar)
75     return 0;
76
77   myButtonFrame = new QFrame(theParent);
78   QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
79   aBoxLay->setContentsMargins(2, 0, 0, 0);
80   aBoxLay->setSpacing(1);
81   QSizePolicy aSizePolicy;
82   aSizePolicy.setControlType(QSizePolicy::ToolButton);
83   myButtonFrame->setSizePolicy(aSizePolicy);
84
85   myThisButton = new QToolButton(myButtonFrame);
86   myThisButton->setDefaultAction(this);
87   myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
88   aBoxLay->addWidget(myThisButton, 1);
89
90   myAdditionalButtonsWidget = new QWidget(myButtonFrame);
91   QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
92   aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
93   aAdditionalBoxLay->setSpacing(1);
94   foreach (QAction* eachAct, myNestedActions) {
95     QToolButton* aButton = new QToolButton(myButtonFrame);
96     aButton->setDefaultAction(eachAct);
97     aButton->setAutoRaise(true);
98     aAdditionalBoxLay->addWidget(aButton);
99   }
100   myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
101   aBoxLay->addWidget(myAdditionalButtonsWidget);
102
103   myButtonFrame->setLayout(aBoxLay);
104
105   showAdditionalButtons(false);
106   connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
107   return myButtonFrame;
108 }
109
110 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
111 {
112   if (theEvent->type() == QEvent::ActionChanged) {
113     if (myThisButton) {
114       myThisButton->setEnabled(isEnabled());
115       return true;
116     }
117   }
118   return QtxAction::event(theEvent);
119 }