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