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