Salome HOME
bf1c5a1da6908332aa4be3a9cf4adf9922204e46
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2 /*
3  * ModuleBase_ActionInfo.cpp
4  *
5  *  Created on: Feb 4, 2015
6  *      Author: sbh
7  */
8
9 #include <ModuleBase_ActionInfo.h>
10 #include <ModuleBase_IconFactory.h>
11 #include <ModuleBase_Tools.h>
12
13 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
14 {
15   initDefault();
16 }
17
18 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
19 {
20   initDefault();
21 }
22
23 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
24 {
25   initDefault();
26   icon = theIcon;
27   text = theText;
28 }
29
30 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
31 {
32 }
33
34 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
35 {
36   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
37   if (theAction->data().isValid()) {
38     id = theAction->data().toString();
39   }
40   checkable = theAction->isCheckable();
41   checked = theAction->isChecked();
42   enabled = theAction->isEnabled();
43   visible = theAction->isVisible();
44   icon = theAction->icon();
45   text = theAction->text();
46   iconText = theAction->iconText();
47   toolTip = theAction->toolTip();
48   // statusTip = theAction->statusTip();
49   // whatsThis = theAction->whatsThis();
50   shortcut = theAction->shortcut();
51   font = theAction->font();
52 }
53
54 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
55 {
56   id = QString::fromStdString(theMessage->id());
57   iconFile = QString::fromStdString(theMessage->icon());
58   if (!iconFile.isEmpty()) {
59     icon = ModuleBase_IconFactory::loadIcon(iconFile);
60   }
61   text = ModuleBase_Tools::translate(theMessage->id(), theMessage->text());
62   toolTip = ModuleBase_Tools::translate(theMessage->id(), theMessage->tooltip());
63   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
64   if (!aShortcutStr.isEmpty()) {
65     shortcut = QKeySequence(aShortcutStr);
66   }
67   // If feature requires PropertyPannel for input, it should be checkable
68   checkable = theMessage->isUseInput();
69   // If Feature requires modal Dialog box for input
70   modal = theMessage->isModal();
71 }
72
73 void ModuleBase_ActionInfo::initDefault()
74 {
75   id = QString();
76   checkable = false;
77   checked   = false;
78   enabled   = true;
79   visible   = true;
80   icon = QIcon();
81   text = QString();
82   iconText = QString();
83   iconFile = QString();
84   toolTip = QString();
85   // statusTip = QString();
86   // whatsThis = QString();
87   shortcut = QKeySequence();
88   font = QFont();
89 }