Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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   text = theText;
33 }
34
35 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
36 {
37   initDefault();
38   icon = theIcon;
39   text = theText;
40 }
41
42 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
43 {
44 }
45
46 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
47 {
48   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
49   if (theAction->data().isValid()) {
50     id = theAction->data().toString();
51   }
52   checkable = theAction->isCheckable();
53   checked = theAction->isChecked();
54   enabled = theAction->isEnabled();
55   visible = theAction->isVisible();
56   icon = theAction->icon();
57   text = theAction->text();
58   iconText = theAction->iconText();
59   toolTip = theAction->toolTip();
60   // statusTip = theAction->statusTip();
61   // whatsThis = theAction->whatsThis();
62   shortcut = theAction->shortcut();
63   font = theAction->font();
64 }
65
66 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
67 {
68   id = QString::fromStdString(theMessage->id());
69   iconFile = QString::fromStdString(theMessage->icon());
70   if (!iconFile.isEmpty()) {
71     icon = ModuleBase_IconFactory::loadIcon(iconFile);
72   }
73   text = QString::fromUtf8(theMessage->text().c_str());
74   toolTip = QString::fromUtf8(theMessage->tooltip().c_str());
75   toolBar = QString::fromStdString(theMessage->toolBarId());
76   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
77   if (!aShortcutStr.isEmpty()) {
78     shortcut = QKeySequence(aShortcutStr);
79   }
80   // If feature requires PropertyPannel for input, it should be checkable
81   checkable = theMessage->isUseInput();
82   // If Feature requires modal Dialog box for input
83   modal = theMessage->isModal();
84 }
85
86 void ModuleBase_ActionInfo::initDefault()
87 {
88   id = QString();
89   checkable = false;
90   checked   = false;
91   enabled   = true;
92   visible   = true;
93   icon = QIcon();
94   text = QString();
95   iconText = QString();
96   iconFile = QString();
97   toolTip = QString();
98   // statusTip = QString();
99   // whatsThis = QString();
100   shortcut = QKeySequence();
101   font = QFont();
102 }