Salome HOME
Copyrights update
[modules/gui.git] / src / SUIT / SUIT_ActionOperation.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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.
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/
18 //
19 #include "SUIT_ActionOperation.h"
20
21 #include "SUIT_Application.h"
22
23 #include <QtxAction.h>
24
25 /*!
26   Constructor.
27 */
28 SUIT_ActionOperation::SUIT_ActionOperation( SUIT_Application* app )
29 : SUIT_Operation( app ),
30 myAction( 0 )
31 {
32 }
33
34 /*!
35   Destructor.
36 */
37 SUIT_ActionOperation::~SUIT_ActionOperation()
38 {
39 }
40
41 /*!
42   Gets action.
43 */
44 QtxAction* SUIT_ActionOperation::action() const
45 {
46   return myAction;
47 }
48
49 /*!Set action.
50  * Create new instance of QtxAction and set.
51  */
52 void SUIT_ActionOperation::setAction( const QString& text, const QIconSet& icon,
53                                       const QString& menuText, QKeySequence accel,
54                                       QObject* parent, const char* name, bool toggle )
55 {
56   setAction( new QtxAction( text, icon, menuText, accel, parent, name, toggle ) );
57 }
58
59 /*!Set action.
60  * Create new instance of QtxAction and set.
61  */
62 void SUIT_ActionOperation::setAction( const QString& text, const QString& menuText,
63                                       QKeySequence accel, QObject* parent, const char* name, bool toggle )
64 {
65   setAction( new QtxAction(text, menuText, accel, parent, name, toggle ) );
66 }
67
68 /*!Set action.
69  */
70 void SUIT_ActionOperation::setAction( QtxAction* a )
71 {
72   if ( myAction == a )
73     return;
74
75   delete myAction;
76   myAction = a;
77
78   myAction->setEnabled( application()->activeStudy() );
79   connect( myAction, SIGNAL( activated() ), SLOT( start() ) );
80 }
81
82 /*! Add action to widget \a wid.
83  *\retval TRUE - successful, FALSE - not successful.
84  */
85 bool SUIT_ActionOperation::addTo( QWidget* wid )
86 {
87   if ( !action() )
88     return false;
89
90   return action()->addTo( wid );
91 }
92
93 /*! Add action to widget \a wid.
94  *\retval TRUE - successful, FALSE - not successful.
95  */
96 bool SUIT_ActionOperation::addTo( QWidget* wid, int idx )
97 {
98   if ( !action() )
99     return false;
100
101   return action()->addTo( wid, idx );
102 }
103
104 /*! Set status tip for action.
105 */
106 void SUIT_ActionOperation::setStatusTip( const QString& tip )
107 {
108   if ( action() )
109     action()->setStatusTip( tip );
110 }