1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 * SHAPERGUI_NestedButton.cpp
23 * Created on: Apr 13, 2015
27 #include <SHAPERGUI_NestedButton.h>
31 #include <QHBoxLayout>
32 #include <QToolButton>
36 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
37 const QList<QAction*>& theNestedActions)
38 : QWidgetAction(theParent),
39 myNestedActions(theNestedActions),
40 myAdditionalButtonsWidget(0),
46 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
50 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
52 myAdditionalButtonsWidget->setVisible(isShow);
54 myButtonFrame->setFrameStyle(QFrame::WinPanel);
55 myButtonFrame->setFrameShadow(QFrame::Sunken);
56 myThisButton->setAutoRaise(false);
58 myButtonFrame->setFrameStyle(QFrame::NoFrame);
59 myButtonFrame->setFrameShadow(QFrame::Plain);
60 myThisButton->setAutoRaise(true);
64 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
66 // the action has widget only in tool bar, in menu bar, the default
67 // action presentation is shown
68 QToolBar* aToolBar = dynamic_cast<QToolBar*>(theParent);
72 myButtonFrame = new QFrame(theParent);
73 QHBoxLayout* aBoxLay = new QHBoxLayout(myButtonFrame);
74 aBoxLay->setContentsMargins(2, 0, 0, 0);
75 aBoxLay->setSpacing(1);
76 QSizePolicy aSizePolicy;
77 aSizePolicy.setControlType(QSizePolicy::ToolButton);
78 myButtonFrame->setSizePolicy(aSizePolicy);
80 myThisButton = new QToolButton(myButtonFrame);
81 myThisButton->setDefaultAction(this);
82 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
83 aBoxLay->addWidget(myThisButton, 1);
85 myAdditionalButtonsWidget = new QWidget(myButtonFrame);
86 QHBoxLayout* aAdditionalBoxLay = new QHBoxLayout(myAdditionalButtonsWidget);
87 aAdditionalBoxLay->setContentsMargins(0, 0, 0, 0);
88 aAdditionalBoxLay->setSpacing(1);
89 foreach (QAction* eachAct, myNestedActions) {
90 QToolButton* aButton = new QToolButton(myButtonFrame);
91 aButton->setDefaultAction(eachAct);
92 aButton->setAutoRaise(true);
93 aAdditionalBoxLay->addWidget(aButton);
95 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
96 aBoxLay->addWidget(myAdditionalButtonsWidget);
98 myButtonFrame->setLayout(aBoxLay);
100 showAdditionalButtons(false);
101 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
102 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
103 return myButtonFrame;
106 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
108 if (theEvent->type() == QEvent::ActionChanged) {
110 myThisButton->setEnabled(isEnabled());
114 return QWidgetAction::event(theEvent);
118 void SHAPERGUI_NestedButton::actionStateChanged()