Salome HOME
9b7b0c1d6fc85dfda167d7b1e8b983a32dacf7b5
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operations.cxx
1
2 #include <HYDROGUI_Module.h>
3 #include <HYDROGUI_Operations.h>
4 #include <CAM_Application.h>
5 #include <SUIT_ResourceMgr.h>
6 #include <SUIT_Desktop.h>
7 #include <QAction>
8
9 QAction* HYDROGUI_Module::CreateAction( const int theId, const QString& theSuffix, const QString& theImg,
10                                         const int theKey, const bool isToggle, const QString& theSlot )
11 {
12   QString aSlot = theSlot;
13   if( aSlot.isEmpty() )
14     aSlot = SLOT( onOperation() );
15   SUIT_ResourceMgr* aMgr = application()->resourceMgr();
16   std::string anImg = theImg.toStdString();
17   QPixmap aPixmap = theImg.isEmpty() ? QPixmap() : aMgr->loadPixmap( "HYDROGUI", tr( anImg.c_str() ) );
18   std::string aMenu    = ( "MEN_" + theSuffix ).toStdString();
19   std::string aDesktop = ( "DSK_" + theSuffix ).toStdString();
20   std::string aToolbar = ( "STB_" + theSuffix ).toStdString();
21   std::string aSlotStr = aSlot.toStdString();
22   return LightApp_Module::createAction( theId, tr( aMenu.c_str() ), aPixmap,
23     tr( aDesktop.c_str() ), tr( aToolbar.c_str() ),
24                 theKey, application()->desktop(), isToggle, this, aSlotStr.c_str() );
25 }
26
27 void HYDROGUI_Module::CreateActions()
28 {
29   CreateAction( ImportImageId, "IMPORT_IMAGE", "", Qt::CTRL + Qt::Key_I );
30 }
31
32 void HYDROGUI_Module::CreateMenus()
33 {
34   int aFileId = createMenu( tr( "MEN_DESK_FILE" ), -1, -1, 0 );
35
36   createMenu( separator(), aFileId, -1, 1, -1 );
37   createMenu( ImportImageId, aFileId, -1, -1 );
38 }
39
40 void HYDROGUI_Module::CreatePopups()
41 {
42 }
43
44 void HYDROGUI_Module::CreateToolbars()
45 {
46 }
47
48 void HYDROGUI_Module::onOperation()
49 {
50   const QAction* anAction = dynamic_cast<const QAction*>( sender() );
51   int anId = actionId( anAction );
52   if( anId >= 0 )
53     startOperation( anId );
54 }
55
56 LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const
57 {
58   LightApp_Operation* anOp = 0;
59   HYDROGUI_Module* aModule = const_cast<HYDROGUI_Module*>( this );
60   switch( theId )
61   {
62   case ImportImageId:
63     anOp = 0;
64     break;
65   }
66
67   if( !anOp )
68     anOp = LightApp_Module::createOperation( theId );
69
70   return anOp;
71 }