1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 * SHAPERGUI_NestedButton.cpp
24 * Created on: Apr 13, 2015
28 #include <SHAPERGUI_NestedButton.h>
32 #include <QHBoxLayout>
33 #include <QToolButton>
37 SHAPERGUI_NestedButton::SHAPERGUI_NestedButton(QObject* theParent,
38 const QList<QAction*>& theNestedActions)
39 : QWidgetAction(theParent),
40 myNestedActions(theNestedActions),
41 myAdditionalButtonsWidget(0),
47 SHAPERGUI_NestedButton::~SHAPERGUI_NestedButton()
51 void SHAPERGUI_NestedButton::showAdditionalButtons(bool isShow)
53 myAdditionalButtonsWidget->setVisible(isShow);
55 myButtonFrame->setFrameStyle(QFrame::WinPanel);
56 myButtonFrame->setFrameShadow(QFrame::Sunken);
57 myThisButton->setAutoRaise(false);
59 myButtonFrame->setFrameStyle(QFrame::NoFrame);
60 myButtonFrame->setFrameShadow(QFrame::Plain);
61 myThisButton->setAutoRaise(true);
65 QWidget * SHAPERGUI_NestedButton::createWidget(QWidget * theParent)
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);
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);
81 myThisButton = new QToolButton(myButtonFrame);
82 myThisButton->setDefaultAction(this);
83 myThisButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
84 aBoxLay->addWidget(myThisButton, 1);
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);
96 myAdditionalButtonsWidget->setLayout(aAdditionalBoxLay);
97 aBoxLay->addWidget(myAdditionalButtonsWidget);
99 myButtonFrame->setLayout(aBoxLay);
101 showAdditionalButtons(false);
102 connect(this, SIGNAL(toggled(bool)), this, SLOT(showAdditionalButtons(bool)));
103 connect(this, SIGNAL(changed()), this, SLOT(actionStateChanged()));
104 return myButtonFrame;
107 bool SHAPERGUI_NestedButton::event(QEvent* theEvent)
109 if (theEvent->type() == QEvent::ActionChanged) {
111 myThisButton->setEnabled(isEnabled());
115 return QWidgetAction::event(theEvent);
119 void SHAPERGUI_NestedButton::actionStateChanged()