Salome HOME
Issue #1692: Explicit send the Create message when external entity appears in the...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetAction.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_WidgetAction.cpp
4 // Created:     15 Apr 2016
5 // Author:      Natalia Ermolaeva
6
7 #include <ModuleBase_WidgetAction.h>
8 #include <ModuleBase_Tools.h>
9 #include <ModuleBase_IconFactory.h>
10
11 #include <Config_WidgetAPI.h>
12
13 #include <QWidget>
14 #include <QHBoxLayout>
15 #include <QToolButton>
16
17 #define DEFAULT_TOOL_TIP_WIDTH 300
18
19 ModuleBase_WidgetAction::ModuleBase_WidgetAction(QWidget* theParent,
20                                                  const Config_WidgetAPI* theData)
21 : ModuleBase_ModelWidget(theParent, theData)
22 {
23   QHBoxLayout* aControlLay = new QHBoxLayout(this);
24   ModuleBase_Tools::adjustMargins(aControlLay);
25
26   myActionID = attributeID();
27   setAttributeID("");
28
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);
33
34   myButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
35   aControlLay->addWidget(myButton);
36
37   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
38   if (!aLabelIcon.isEmpty())
39     myButton->setIcon(ModuleBase_IconFactory::loadPixmap(aLabelIcon));
40   else
41     myButton->setText(aText);
42   myButton->setToolTip(aToolTip);
43
44   connect(myButton, SIGNAL(clicked(bool)), this, SLOT(onActionClicked()));
45 }
46
47 ModuleBase_WidgetAction::~ModuleBase_WidgetAction()
48 {
49 }
50
51 bool ModuleBase_WidgetAction::focusTo()
52 {
53   return false;
54 }
55
56 QList<QWidget*> ModuleBase_WidgetAction::getControls() const
57 {
58   QList<QWidget*> aList;
59   aList.append(myButton);
60   return aList;
61 }
62
63 bool ModuleBase_WidgetAction::storeValueCustom()
64 {
65   return true;
66 }
67
68 bool ModuleBase_WidgetAction::restoreValueCustom()
69 {
70   return true;
71 }
72
73 void ModuleBase_WidgetAction::onActionClicked()
74 {
75   if (myFeature->customAction(myActionID))
76     updateObject(myFeature);
77 }