Salome HOME
Issue #1309 Management of icons - icons are moved into corresponded plugins. The...
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // TEMPORARY COMMIT
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
12 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
13 {
14   initDefault();
15 }
16
17 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
18 {
19   initDefault();
20 }
21
22 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
23 {
24   initDefault();
25   icon = theIcon;
26   text = theText;
27 }
28
29 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
30 {
31 }
32
33 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
34 {
35   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
36   if (theAction->data().isValid()) {
37     id = theAction->data().toString();
38   }
39   checkable = theAction->isCheckable();
40   checked = theAction->isChecked();
41   enabled = theAction->isEnabled();
42   visible = theAction->isVisible();
43   icon = theAction->icon();
44   text = theAction->text();
45   iconText = theAction->iconText();
46   toolTip = theAction->toolTip();
47   // statusTip = theAction->statusTip();
48   // whatsThis = theAction->whatsThis();
49   shortcut = theAction->shortcut();
50   font = theAction->font();
51 }
52
53 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
54 {
55   id = QString::fromStdString(theMessage->id());
56   iconFile = QString::fromStdString(theMessage->icon());
57   if (!iconFile.isEmpty()) {
58     icon = ModuleBase_IconFactory::loadIcon(iconFile);
59   }
60   text = QString::fromStdString(theMessage->text());
61   toolTip = QString::fromStdString(theMessage->tooltip());
62   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
63   if (!aShortcutStr.isEmpty()) {
64     shortcut = QKeySequence(aShortcutStr);
65   }
66   // If feature requires PropertyPannel for input, it should be checkable
67   checkable = theMessage->isUseInput();
68 }
69
70 QAction* ModuleBase_ActionInfo::makeAction(QObject* theParent)
71 {
72   QAction* aResult = new QAction(icon, text, theParent);
73   aResult->setCheckable(checkable);
74   aResult->setChecked(checked);
75   aResult->setEnabled(enabled);
76   aResult->setVisible(visible);
77   aResult->setIconText(iconText);
78   aResult->setToolTip(toolTip);
79   // aResult->setStatusTip(statusTip);
80   // aResult->setWhatsThis(whatsThis);
81   aResult->setShortcut(shortcut);
82   aResult->setFont(font);
83   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
84   aResult->setData(id);
85   return aResult;
86 }
87
88 void ModuleBase_ActionInfo::initDefault()
89 {
90   id = QString();
91   checkable = false;
92   checked   = false;
93   enabled   = true;
94   visible   = true;
95   icon = QIcon();
96   text = QString();
97   iconText = QString();
98   iconFile = QString();
99   toolTip = QString();
100   // statusTip = QString();
101   // whatsThis = QString();
102   shortcut = QKeySequence();
103   font = QFont();
104 }