Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_ActionInfo.cpp
1 // Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * ModuleBase_ActionInfo.cpp
22  *
23  *  Created on: Feb 4, 2015
24  *      Author: sbh
25  */
26
27 #include <ModuleBase_ActionInfo.h>
28 #include <ModuleBase_IconFactory.h>
29 #include <ModuleBase_Tools.h>
30
31 ModuleBase_ActionInfo::ModuleBase_ActionInfo()
32 {
33   initDefault();
34 }
35
36 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QString &theText)
37 {
38   initDefault();
39 }
40
41 ModuleBase_ActionInfo::ModuleBase_ActionInfo(const QIcon & theIcon, const QString &theText)
42 {
43   initDefault();
44   icon = theIcon;
45   text = theText;
46 }
47
48 ModuleBase_ActionInfo::~ModuleBase_ActionInfo()
49 {
50 }
51
52 void ModuleBase_ActionInfo::initFrom(QAction* theAction)
53 {
54   // By convenience, QAction for a feature keeps feature's id as data (QVariant);
55   if (theAction->data().isValid()) {
56     id = theAction->data().toString();
57   }
58   checkable = theAction->isCheckable();
59   checked = theAction->isChecked();
60   enabled = theAction->isEnabled();
61   visible = theAction->isVisible();
62   icon = theAction->icon();
63   text = theAction->text();
64   iconText = theAction->iconText();
65   toolTip = theAction->toolTip();
66   // statusTip = theAction->statusTip();
67   // whatsThis = theAction->whatsThis();
68   shortcut = theAction->shortcut();
69   font = theAction->font();
70 }
71
72 void ModuleBase_ActionInfo::initFrom(std::shared_ptr<Config_FeatureMessage> theMessage)
73 {
74   id = QString::fromStdString(theMessage->id());
75   iconFile = QString::fromStdString(theMessage->icon());
76   if (!iconFile.isEmpty()) {
77     icon = ModuleBase_IconFactory::loadIcon(iconFile);
78   }
79   text = QString::fromUtf8(theMessage->text().c_str());
80   toolTip = QString::fromUtf8(theMessage->tooltip().c_str());
81   QString aShortcutStr = QString::fromStdString(theMessage->keysequence());
82   if (!aShortcutStr.isEmpty()) {
83     shortcut = QKeySequence(aShortcutStr);
84   }
85   // If feature requires PropertyPannel for input, it should be checkable
86   checkable = theMessage->isUseInput();
87   // If Feature requires modal Dialog box for input
88   modal = theMessage->isModal();
89 }
90
91 void ModuleBase_ActionInfo::initDefault()
92 {
93   id = QString();
94   checkable = false;
95   checked   = false;
96   enabled   = true;
97   visible   = true;
98   icon = QIcon();
99   text = QString();
100   iconText = QString();
101   iconFile = QString();
102   toolTip = QString();
103   // statusTip = QString();
104   // whatsThis = QString();
105   shortcut = QKeySequence();
106   font = QFont();
107 }