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)
23 QHBoxLayout* aControlLay = new QHBoxLayout(this);
24 ModuleBase_Tools::adjustMargins(aControlLay);
26 myActionID = attributeID();
29 myButton = new QToolButton(this);
30 QString aText = QString::fromStdString(theData->widgetLabel());
31 QString aToolTip = ModuleBase_Tools::wrapTextByWords(
32 QString::fromStdString(theData->widgetTooltip()), myButton, 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);