Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / VISUGUI / VisuGUI_CursorDlg.cxx
1 //  Copyright (C) 2007-2010  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
23 //  VISU VISUGUI : GUI of VISU component
24 //  File   : VisuGUI_CursorDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28 //
29 #include <string>
30 using namespace std;
31
32 #include "VisuGUI.h"
33 #include "VisuGUI_CursorDlg.h"
34
35 #include "SUIT_Session.h"
36 #include "SUIT_MessageBox.h"
37 #include "SUIT_ResourceMgr.h"
38
39 #include "LightApp_Application.h"
40
41 #include <SalomeApp_IntSpinBox.h>
42
43 #include <QLayout>
44 #include <QLabel>
45 #include <QPushButton>
46 #include <QGroupBox>
47 #include <QKeyEvent>
48
49 /*!
50   Constructor
51 */
52 VisuGUI_CursorDlg::VisuGUI_CursorDlg( QWidget* parent,  const char* name, bool modal )
53     : QDialog( parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint )//WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
54 {
55   setWindowTitle( name );
56   setModal( modal );
57   setSizeGripEnabled( TRUE );
58
59   QGridLayout* TopLayout = new QGridLayout( this );
60   TopLayout->setSpacing( 6 );
61   TopLayout->setMargin( 11 );
62
63   TopGroupBox = new QGroupBox( this );
64   //TopGroupBox->setColumnLayout(0, Qt::Vertical );
65   //TopGroupBox->layout()->setSpacing( 0 );
66   //TopGroupBox->layout()->setMargin( 0 );
67   QGridLayout* TopGroupBoxLayout = new QGridLayout( TopGroupBox );
68   TopGroupBoxLayout->setAlignment( Qt::AlignTop );
69   TopGroupBoxLayout->setSpacing( 6 );
70   TopGroupBoxLayout->setMargin( 11 );
71
72   Comment1 = new QLabel( tr( "TextLabel1" ), TopGroupBox );
73   Comment1->setAlignment( Qt::AlignCenter );
74   TopGroupBoxLayout->addWidget( Comment1, 0, 0 );
75
76   Comment2 = new QLabel(  tr( "TextLabel2" ), TopGroupBox );
77   Comment2->setAlignment( Qt::AlignCenter );
78   TopGroupBoxLayout->addWidget( Comment2, 1, 0 );
79
80   SpinBox1 = new SalomeApp_IntSpinBox( TopGroupBox );
81   SpinBox1->setAcceptNames( false );
82   SpinBox1->setMinimum( 0 );
83   SpinBox1->setMaximum(100 );
84   SpinBox1->setSingleStep( 1 );
85   SpinBox1->setValue( 100 );
86   SpinBox1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
87   SpinBox1->setMinimumSize( 70, 0 );
88   QHBoxLayout* SLayout = new QHBoxLayout;
89   SLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
90   SLayout->addWidget( SpinBox1 );
91   SLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
92   TopGroupBoxLayout->addLayout( SLayout, 2, 0 );
93
94   GroupButtons = new QGroupBox (this);
95   GroupButtons->setGeometry(QRect(10, 10, 281, 48));
96   //GroupButtons->setColumnLayout(0, Qt::Vertical);
97   //GroupButtons->layout()->setSpacing(0);
98   //GroupButtons->layout()->setMargin(0);
99   QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
100   GroupButtonsLayout->setAlignment(Qt::AlignTop);
101   GroupButtonsLayout->setSpacing(6);
102   GroupButtonsLayout->setMargin(11);
103
104   buttonOk = new QPushButton (tr("&OK"), GroupButtons);
105   buttonOk->setAutoDefault(TRUE);
106   buttonOk->setDefault(TRUE);
107   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
108
109   GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
110
111   buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
112   buttonCancel->setAutoDefault(TRUE);
113   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
114
115   buttonHelp = new QPushButton(tr("&Help") , GroupButtons);
116   buttonHelp->setAutoDefault(TRUE);
117   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
118
119   TopLayout->addWidget(TopGroupBox,  0, 0);
120   TopLayout->addWidget(GroupButtons, 1, 0);
121
122   // signals and slots connections
123   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
124   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
125   connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
126 }
127
128 /*!
129   Destructor
130 */
131 VisuGUI_CursorDlg::~VisuGUI_CursorDlg()
132 {
133 }
134
135 /*!
136   function : onHelp()
137   purpose  :
138 */
139 void VisuGUI_CursorDlg::onHelp()
140 {
141   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
142   if (app) {
143     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
144     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), helpFileName);
145   }
146   else {
147     QString platform;
148 #ifdef WIN32
149     platform = "winapplication";
150 #else
151     platform = "application";
152 #endif
153     SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
154                              QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
155                              arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).
156                              arg(helpFileName) );
157   }
158 }
159
160 /*!
161   function : keyPressEvent()
162   purpose  :
163 */
164 void VisuGUI_CursorDlg::keyPressEvent( QKeyEvent* e )
165 {
166   QDialog::keyPressEvent( e );
167   if ( e->isAccepted() )
168     return;
169
170   if ( e->key() == Qt::Key_F1 )
171     {
172       e->accept();
173       onHelp();
174     }
175 }