1 #include "CAF_Application.h"
6 #include <SUIT_Desktop.h>
7 #include <SUIT_Session.h>
8 #include <SUIT_ViewModel.h>
9 #include <SUIT_Operation.h>
10 #include <SUIT_MessageBox.h>
11 #include <SUIT_ResourceMgr.h>
13 #include <QtxListAction.h>
17 #include <qpopupmenu.h>
18 #include <qstatusbar.h>
19 #include <qapplication.h>
21 #include <Resource_Manager.hxx>
23 #include <TColStd_SequenceOfExtendedString.hxx>
25 extern "C" CAF_EXPORT SUIT_Application* createApplication()
27 return new CAF_Application();
30 CAF_Application::CAF_Application()
35 CAF_Application::CAF_Application( const Handle(TDocStd_Application)& app )
41 CAF_Application::~CAF_Application()
45 QString CAF_Application::applicationName() const
47 return QString( "CAFApplication" );
50 Handle(TDocStd_Application) CAF_Application::stdApp() const
55 QString CAF_Application::getFileFilter() const
57 if ( stdApp().IsNull() )
60 TColStd_SequenceOfExtendedString formats;
61 stdApp()->Formats( formats );
64 QMap<QString, QStringList> wildCards;
65 Handle(Resource_Manager) resMgr = new Resource_Manager( stdApp()->ResourcesName() );
66 for ( int i = 1; i <= formats.Length(); i++ )
69 QString extResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".FileExtension" );
70 if ( resMgr->Find( (char*)extResStr.latin1() ) )
71 extension = QString( resMgr->Value( (char*)extResStr.latin1() ) );
74 QString descrResStr = CAF_Tools::toQString( formats.Value( i ) ) + QString( ".Description" );
75 if ( resMgr->Find( (char*)descrResStr.latin1() ) )
76 descr = QString( resMgr->Value( (char*)descrResStr.latin1() ) );
78 if ( !descr.isEmpty() && !extension.isEmpty() )
80 if ( !wildCards.contains( descr ) )
81 wildCards.insert( descr, QStringList() );
82 wildCards[descr].append( QString( "*.%1" ).arg( extension ) );
83 allWC.append( QString( "*.%1" ).arg( extension ) );
87 if ( wildCards.isEmpty() )
91 for ( QMap<QString, QStringList>::ConstIterator it = wildCards.begin(); it != wildCards.end(); ++it )
92 filters.append( QString( "%1 (%2)" ).arg( it.key() ).arg( it.data().join( "; " ) ) );
94 if ( wildCards.count() > 1 )
95 filters.prepend( QString( "%1 (%2)" ).arg( tr( "INF_ALL_DOCUMENTS_FILTER" ) ).arg( allWC.join( "; " ) ) );
97 if ( !filters.isEmpty() )
98 filters.append( tr( "INF_ALL_FILTER" ) );
100 return filters.join( ";;" );
103 void CAF_Application::createActions()
105 STD_Application::createActions();
107 SUIT_Desktop* desk = desktop();
108 SUIT_ResourceMgr* resMgr = resourceMgr();
110 QtxListAction* editUndo =
111 new QtxListAction( tr( "TOT_APP_EDIT_UNDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_UNDO" ) ),
112 tr( "MEN_APP_EDIT_UNDO" ), CTRL+Key_Z, desk );
113 registerAction( EditUndoId, editUndo );
115 QtxListAction* editRedo =
116 new QtxListAction( tr( "TOT_APP_EDIT_REDO" ), resMgr->loadPixmap( "CAF", tr( "ICON_APP_EDIT_REDO" ) ),
117 tr( "MEN_APP_EDIT_REDO" ), CTRL+Key_Y, desk );
118 registerAction( EditRedoId, editRedo );
120 editUndo->setComment( tr( "INF_APP_UNDOACTIONS" ) );
121 editRedo->setComment( tr( "INF_APP_REDOACTIONS" ) );
123 connect( editUndo, SIGNAL( activated( int ) ), this, SLOT( onUndo( int ) ) );
124 connect( editRedo, SIGNAL( activated( int ) ), this, SLOT( onRedo( int ) ) );
127 int editMenu = createMenu( tr( "MEN_DESK_EDIT" ), -1, -1, 10 );
129 createMenu( EditUndoId, editMenu, 0 );
130 createMenu( EditRedoId, editMenu, 0 );
131 createMenu( separator(), editMenu, -1, 0 );
133 int stdTBar = createTool( tr( "INF_DESK_TOOLBAR_STANDARD" ) );
135 createTool( separator(), stdTBar );
136 createTool( EditUndoId, stdTBar );
137 createTool( EditRedoId, stdTBar );
138 createTool( separator(), stdTBar );
142 Undo operation on the given document. [ virtual protected ]
144 bool CAF_Application::undo( CAF_Study* doc )
146 bool success = false;
149 if ( success = doc->undo() )
156 Redo operation on the given document. [ virtual protected ]
158 bool CAF_Application::redo(CAF_Study* doc)
160 bool success = false;
163 if ( success = doc->redo() )
170 Undo operation on the active document. [ virtual protected slot ]
172 bool CAF_Application::onUndo( int numActions )
175 while ( numActions > 0 )
177 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
180 if ( !undo( cafStudy ) )
188 updateCommandsStatus(); /* enable/disable undo/redo */
193 Redo operation on the active document. [ virtual protected slot ]
195 bool CAF_Application::onRedo( int numActions )
198 while ( numActions > 0 )
200 CAF_Study* cafStudy = dynamic_cast<CAF_Study*>( activeStudy() );
203 if ( !redo( cafStudy ) )
211 updateCommandsStatus(); /* enable/disable undo/redo */
216 Enables / disables the actions according to the application state. [ virtual protected ]
218 void CAF_Application::updateCommandsStatus()
220 STD_Application::updateCommandsStatus();
222 CAF_Study* cafStudy = 0;
223 if ( activeStudy() && activeStudy()->inherits( "CAF_Study" ) )
224 cafStudy = (CAF_Study*)activeStudy();
226 QAction* undo = action( EditUndoId );
227 if ( cafStudy && undo )
228 undo->setProperty( "names", cafStudy->undoNames() );
230 QAction* redo = action( EditRedoId );
231 if ( cafStudy && redo )
232 redo->setProperty( "names", cafStudy->redoNames() );
235 undo->setEnabled( cafStudy && cafStudy->canUndo() );
237 redo->setEnabled( cafStudy && cafStudy->canRedo() );
240 void CAF_Application::onHelpAbout()
242 SUIT_MessageBox::info1( desktop(), tr( "About" ), tr( "ABOUT_INFO" ), "&OK" );
245 SUIT_Study* CAF_Application::createNewStudy()
247 return new CAF_Study( this );
250 void CAF_Application::setStdApp( const Handle(TDocStd_Application)& app )