Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SUIT / SUIT_ActionOperation.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "SUIT_ActionOperation.h"
23
24 #include "SUIT_Application.h"
25
26 #include <QtxAction.h>
27
28 /*!
29   Constructor.
30 */
31 SUIT_ActionOperation::SUIT_ActionOperation( SUIT_Application* app )
32 : SUIT_Operation( app ),
33 myAction( 0 )
34 {
35 }
36
37 /*!
38   Destructor.
39 */
40 SUIT_ActionOperation::~SUIT_ActionOperation()
41 {
42 }
43
44 /*!
45   Gets action.
46 */
47 QtxAction* SUIT_ActionOperation::action() const
48 {
49   return myAction;
50 }
51
52 /*!Set action.
53  * Create new instance of QtxAction and set.
54  */
55 void SUIT_ActionOperation::setAction( const QString& text, const QIcon& icon,
56                                                               const QString& menuText, QKeySequence accel,
57                                       QObject* parent, bool toggle )
58 {
59   setAction( new QtxAction( text, icon, menuText, accel, parent, toggle ) );
60 }
61
62 /*!Set action.
63  * Create new instance of QtxAction and set.
64  */
65 void SUIT_ActionOperation::setAction( const QString& text, const QString& menuText,
66                                                               QKeySequence accel, QObject* parent, bool toggle )
67 {
68   setAction( new QtxAction( text, menuText, accel, parent, toggle ) );
69 }
70
71 /*!Set action.
72  */
73 void SUIT_ActionOperation::setAction( QtxAction* a )
74 {
75   if ( myAction == a )
76     return;
77
78   delete myAction;
79   myAction = a;
80
81   myAction->setEnabled( application()->activeStudy() );
82   connect( myAction, SIGNAL( triggered() ), SLOT( start() ) );
83 }
84
85 /*! Add action to widget \a wid.
86  *\retval TRUE - successful, FALSE - not successful.
87  */
88 bool SUIT_ActionOperation::addTo( QWidget* wid )
89 {
90   if ( !action() )
91     return false;
92
93   wid->addAction( action() );
94   return true;
95 }
96
97 /*! Set status tip for action.
98 */
99 void SUIT_ActionOperation::setStatusTip( const QString& tip )
100 {
101   if ( action() )
102     action()->setStatusTip( tip );
103 }