Salome HOME
Update copyrights
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <ModuleBase_ActionInfo.h>
21 #include <ModuleBase_IconFactory.h>
22 #include <ModuleBase_Tools.h>
23
24 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
25 {
26   initDefault();
27 }
28
29 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
30 {
31   initDefault();
32 }
33
34 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
35 {
36   initDefault();
37   icon = theIcon;
38   text = theText;
39 }
40
41 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
42 {
43 }
44
45 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
46 {
47   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
48   if (theAction->data().isValid()) {
49     id = theAction->data().toString();
50   }
51   checkable = theAction->isCheckable();
52   checked = theAction->isChecked();
53   enabled = theAction->isEnabled();
54   visible = theAction->isVisible();
55   icon = theAction->icon();
56   text = theAction->text();
57   iconText = theAction->iconText();
58   toolTip = theAction->toolTip();
59   // statusTip = theAction->statusTip();
60   // whatsThis = theAction->whatsThis();
61   shortcut = theAction->shortcut();
62   font = theAction->font();
63 }
64
65 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
66 {
67   id = QString::fromStdString(theMessage->id());
68   iconFile = QString::fromStdString(theMessage->icon());
69   if (!iconFile.isEmpty()) {
70     icon = ModuleBase_IconFactory::loadIcon(iconFile);
71   }
72   text = QString::fromUtf8(theMessage->text().c_str());
73   toolTip = QString::fromUtf8(theMessage->tooltip().c_str());
74   toolBar = QString::fromStdString(theMessage->toolBarId());
75   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
76   if (!aShortcutStr.isEmpty()) {
77     shortcut = QKeySequence(aShortcutStr);
78   }
79   // If feature requires PropertyPannel for input, it should be checkable
80   checkable = theMessage->isUseInput();
81   // If Feature requires modal Dialog box for input
82   modal = theMessage->isModal();
83 }
84
85 void ModuleBase_ActionInfo::initDefault()
86 {
87   id = QString();
88   checkable = false;
89   checked   = false;
90   enabled   = true;
91   visible   = true;
92   icon = QIcon();
93   text = QString();
94   iconText = QString();
95   iconFile = QString();
96   toolTip = QString();
97   // statusTip = QString();
98   // whatsThis = QString();
99   shortcut = QKeySequence();
100   font = QFont();
101 }