]> SALOME platform Git repositories - tools/yacsgen.git/blob - Examples/cppgui2/cppcomposGUI.cxx
Salome HOME
Copyright update 2022
[tools/yacsgen.git] / Examples / cppgui2 / cppcomposGUI.cxx
1 // Copyright (C) 2009-2022  EDF 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, or (at your option) any later version.
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/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "cppcomposGUI.h"
21 #include <SUIT_MessageBox.h>
22 #include <SUIT_ResourceMgr.h>
23 #include <SUIT_Desktop.h>
24 #include <SUIT_Study.h>
25 #include <SUIT_ViewWindow.h>
26 #include <SUIT_ViewManager.h>
27 #include <SalomeApp_Application.h>
28
29 #include <SALOMEconfig.h>
30
31 // QT Includes
32 #include <QInputDialog>
33 #include <QIcon>
34 #include <QLabel>
35
36 // Export the module
37 extern "C" {
38   CAM_Module* createModule()
39   {
40     return new cppcomposGUI();
41   }
42 }
43
44 // Constructor
45 cppcomposGUI::cppcomposGUI() :
46   LightApp_Module( "cppcompos" ) // default name
47 {
48 }
49
50 //static cppcompos_ORB::cppcompos_var engine;
51
52 // Module's initialization
53 void cppcomposGUI::initialize( CAM_Application* app )
54 {
55
56   LightApp_Module::initialize( app );
57
58   QWidget* aParent = application()->desktop();
59   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
60
61   // create actions
62   QPixmap aPixmap = aResourceMgr->loadPixmap( "cppcompos","exec.png" );
63   createAction( 901, "Banner", QIcon( aPixmap ), "Banner", "Banner", 0, aParent, false, this, SLOT( OnGetBanner() ) );
64   createAction( 902, "Designer", QIcon( aPixmap ), "Designer", "Designer", 0, aParent, false, this, SLOT( OnDesigner() ) );
65
66   // create menus
67   int aMenuId;
68   aMenuId = createMenu( "cppcompos", -1, -1, 30 );
69   createMenu( 901, aMenuId, 10 );
70
71   // create toolbars
72   int aToolId = createTool ( "cppcompos" );
73   createTool( 901, aToolId );
74   createTool( 902, aToolId );
75   
76   _myWidget = new QLabel("My module!", aParent);
77   _myViewManager = getApp()->createViewManager("cppcompos", _myWidget);
78   _myViewManager->getActiveView()->setClosable( false );
79   if(app->desktop() )
80      connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
81               this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
82     
83 }
84
85 // Get compatible dockable windows.
86 void cppcomposGUI::windows( QMap<int, int>& theMap ) const
87 {
88   theMap.clear();
89 //  theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
90 //  theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
91 }
92
93 // Module's activation
94 bool cppcomposGUI::activateModule( SUIT_Study* theStudy )
95 {
96   bool bOk = LightApp_Module::activateModule( theStudy );
97
98   if(bOk)
99   {
100     setMenuShown( true );
101     setToolShown( true );
102     _myViewManager->setShown(true);
103     _myWidget->setVisible(true);
104     _myViewManager->getActiveView()->setFocus();
105   }
106   return bOk;
107 }
108
109 // Module's deactivation
110 bool cppcomposGUI::deactivateModule( SUIT_Study* theStudy )
111 {
112   setMenuShown( false );
113   setToolShown( false );
114   _myWidget->setVisible(false);
115   _myViewManager->setShown(false);
116
117   return LightApp_Module::deactivateModule( theStudy );
118 }
119
120 void cppcomposGUI::onWindowActivated( SUIT_ViewWindow* svw)
121 {
122   if(_myViewManager->getActiveView()->getId() == svw->getId())
123     if (!getApp()->activeModule() ||
124         getApp()->activeModule()->moduleName() != "cppcompos")
125       getApp()->activateModule("cppcompos");
126 }
127
128 // Action slot
129 void cppcomposGUI::OnGetBanner()
130 {
131   // Dialog to get the Name
132   bool ok = false;
133   QString myName = QInputDialog::getText( getApp()->desktop(), "label", "name", QLineEdit::Normal, QString::null, &ok );
134
135   if ( ok && !myName.isEmpty()) 
136   {
137     QString banner = "Hello " + myName;
138     SUIT_MessageBox::information( getApp()->desktop(), "info", banner, "OK" );
139   }
140 }
141
142 // Action slot
143 void cppcomposGUI::OnDesigner()
144 {
145   QWidget* wid= new MyDemo(getApp()->desktop());
146   wid->show();
147 }
148
149 MyDemo::MyDemo(QWidget *parent)
150         :QDialog(parent)
151 {
152   ui.setupUi(this);
153 }