1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetAction.cpp
4 // Created: 15 Apr 2016
5 // Author: Natalia Ermolaeva
7 #include <ModuleBase_WidgetAction.h>
8 #include <ModuleBase_Tools.h>
9 #include <ModuleBase_IconFactory.h>
11 #include <Config_WidgetAPI.h>
14 #include <QHBoxLayout>
15 #include <QToolButton>
17 #define DEFAULT_TOOL_TIP_WIDTH 300
19 ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
20 const Config_WidgetAPI* theData)
21 : ModuleBase_ModelWidget(theParent, theData),
22 myActionID(attributeID())
24 setAttributeID(""); // To prevent errors. Action not stored as attribtue in feature.
25 QHBoxLayout* aControlLay = new QHBoxLayout(this);
26 ModuleBase_Tools::adjustMargins(aControlLay);
28 myButton = new QToolButton(this);
29 QString aText = translate(theData->widgetLabel());
30 QString aToolTip = ModuleBase_Tools::wrapTextByWords(translate(theData->widgetTooltip()),
32 DEFAULT_TOOL_TIP_WIDTH);
34 myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
35 aControlLay->addWidget(myButton);
37 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
38 if (!aLabelIcon.isEmpty())
39 myButton->setIcon(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
41 myButton->setText(aText);
42 myButton->setToolTip(aToolTip);
44 connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
47 ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
51 bool ModuleBase_WidgetAction::focusTo()
56 QList<QWidget*> ModuleBase_WidgetAction::getControls() const
58 QList<QWidget*> aList;
59 aList.append(myButton);
63 bool ModuleBase_WidgetAction::storeValueCustom()
68 bool ModuleBase_WidgetAction::restoreValueCustom()
73 void ModuleBase_WidgetAction::onActionClicked()
75 if (myFeature->customAction(myActionID))
76 updateObject(myFeature);