1 // Copyright (C) 2014-2020 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
20 #include <ModuleBase_WidgetAction.h>
21 #include <ModuleBase_Tools.h>
22 #include <ModuleBase_IconFactory.h>
24 #include <Config_WidgetAPI.h>
27 #include <QHBoxLayout>
28 #include <QToolButton>
30 #define DEFAULT_TOOL_TIP_WIDTH 300
32 ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
33 const Config_WidgetAPI* theData)
34 : ModuleBase_ModelWidget(theParent, theData),
35 myActionID(attributeID())
37 setAttributeID(""); // To prevent errors. Action not stored as attribtue in feature.
38 QHBoxLayout* aControlLay = new QHBoxLayout(this);
39 ModuleBase_Tools::adjustMargins(aControlLay);
41 myButton = new QToolButton(this);
42 QString aText = translate(theData->widgetLabel());
43 QString aToolTip = ModuleBase_Tools::wrapTextByWords(translate(theData->widgetTooltip()),
45 DEFAULT_TOOL_TIP_WIDTH);
47 myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
48 aControlLay->addWidget(myButton);
50 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
51 if (!aLabelIcon.isEmpty())
52 myButton->setIcon(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
54 myButton->setText(aText);
55 myButton->setToolTip(aToolTip);
57 connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
60 ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
64 bool ModuleBase_WidgetAction::focusTo()
69 QList<QWidget*> ModuleBase_WidgetAction::getControls() const
71 QList<QWidget*> aList;
72 aList.append(myButton);
76 bool ModuleBase_WidgetAction::storeValueCustom()
81 bool ModuleBase_WidgetAction::restoreValueCustom()
86 void ModuleBase_WidgetAction::onActionClicked()
88 if (myFeature->customAction(myActionID))
89 updateObject(myFeature);