Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_ViewChoiceDlg.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEGUI_ViewChoiceDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #include "SALOMEGUI_ViewChoiceDlg.h"
30 #include "QAD_Config.h"
31 #include "QAD_StudyFrame.h"
32
33 #include <qcombobox.h>
34 #include <qgroupbox.h>
35 #include <qlabel.h>
36 #include <qpushbutton.h>
37 #include <qlayout.h>
38 #include <qvariant.h>
39 #include <qtooltip.h>
40 #include <qwhatsthis.h>
41 using namespace std;
42
43 /* 
44  *  Constructs a SALOMEGUI_ViewChoiceDlg which is a child of 'parent', with the 
45  *  name 'name' and widget flags set to 'f' 
46  *
47  *  The dialog will by default be modeless, unless you set 'modal' to
48  *  TRUE to construct a modal dialog.
49  */
50 SALOMEGUI_ViewChoiceDlg::SALOMEGUI_ViewChoiceDlg( QWidget* parent,  const char* name, bool modal, WFlags fl )
51     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
52 {
53     if ( !name )
54         setName( "SALOMEGUI_ViewChoiceDlg" );
55     setCaption( tr( "MEN_CHOICE" ) );
56     setSizeGripEnabled( true );
57
58     QGridLayout* theBaseLayout = new QGridLayout( this, 2, 1, 11, 6);
59
60     GroupBox1 = new QGroupBox(0, Qt::Vertical, tr("MEN_VIEW"), this);
61     theBaseLayout->addWidget(GroupBox1, 0, 0);
62
63     QHBoxLayout* aBoxLayout = new QHBoxLayout(GroupBox1->layout()); 
64
65     QHBoxLayout* aInternalLayout = new QHBoxLayout(6);
66
67     TextLabel1 = new QLabel(tr("MEN_VIEWER_TYPE"), GroupBox1);
68     aInternalLayout->addWidget(TextLabel1);
69
70     ComboBox1 = new QComboBox( false, GroupBox1);
71     ComboBox1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
72     ComboBox1->setMinimumWidth( 200 );
73     // OCC Viewer
74     ComboBox1->insertItem(tr("MEN_VIEWER_OCC"));
75     myViewers.append(VIEW_OCC);
76     if ( QAD_CONFIG->getSetting( "Viewer:DefaultViewer").toInt() == VIEW_OCC )
77       ComboBox1->setCurrentItem( ComboBox1->count()-1 );
78     // VTK Viewer
79     ComboBox1->insertItem(tr("MEN_VIEWER_VTK"));
80     myViewers.append(VIEW_VTK);
81     if ( QAD_CONFIG->getSetting( "Viewer:DefaultViewer").toInt() == VIEW_VTK )
82       ComboBox1->setCurrentItem( ComboBox1->count()-1 );
83     // SUPERVISOR Viewer
84 //    ComboBox1->insertItem(tr("MEN_VIEWER_GRAPH"));
85 //    myViewers.append(VIEW_GRAPHSUPERV);
86 //    if ( QAD_CONFIG->getSetting( "Viewer:DefaultViewer").toInt() == VIEW_GRAPHSUPERV )
87 //      ComboBox1->setCurrentItem( ComboBox1->count()-1 );
88     // Plot2d Viewer
89     ComboBox1->insertItem(tr("MEN_VIEWER_PLOT2D"));
90     myViewers.append(VIEW_PLOT2D);
91     if ( QAD_CONFIG->getSetting( "Viewer:DefaultViewer").toInt() == VIEW_PLOT2D )
92       ComboBox1->setCurrentItem( ComboBox1->count()-1 );
93     TextLabel1->setBuddy(ComboBox1);
94     aInternalLayout->addWidget(ComboBox1);
95
96     aBoxLayout->addLayout(aInternalLayout);
97     
98     QFrame* aButtonFrame = new QFrame( this );
99     theBaseLayout->addWidget(aButtonFrame, 1, 0);
100
101     QHBoxLayout* aButtLayout = new QHBoxLayout(aButtonFrame); 
102
103     buttonOk = new QPushButton(tr("BUT_OK"), aButtonFrame);
104     buttonOk->setAutoDefault(true);
105     buttonOk->setDefault(true);
106     aButtLayout->addWidget(buttonOk);
107
108     QSpacerItem* aSpacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding);
109     aButtLayout->addItem(aSpacer);
110
111     buttonCancel = new QPushButton(tr( "BUT_CANCEL" ),  aButtonFrame);
112     buttonCancel->setAutoDefault(true);
113     aButtLayout->addWidget(buttonCancel);
114
115     connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
116     connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
117 }
118
119 /*  
120  *  Destroys the object and frees any allocated resources
121  */
122 SALOMEGUI_ViewChoiceDlg::~SALOMEGUI_ViewChoiceDlg()
123 {
124     // no need to delete child widgets, Qt does it all for us
125 }
126
127 /*!
128   Gets user's choice
129 */
130 int SALOMEGUI_ViewChoiceDlg::getSelectedViewer()
131 {
132   return myViewers[ ComboBox1->currentItem() ];
133 }