Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_OpenWith.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_OpenWith.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "SALOMEGUI_OpenWith.h"
31
32 #include <qlabel.h>
33 #include <qcheckbox.h>
34 #include <qpushbutton.h>
35 #include <qlayout.h>
36 #include <qlistbox.h>
37
38 #define SPACING_SIZE             6
39 #define MARGIN_SIZE             11
40 #define MIN_LISTBOX_WIDTH      150
41 #define MIN_LISTBOX_HEIGHT     100
42
43 /* 
44  *  Constructs modal SALOMEGUI_OpenWith which is a child of 'parent', with the 
45  *  name 'name' 
46  */
47 SALOMEGUI_OpenWith::SALOMEGUI_OpenWith(QWidget* parent,  const char* name)
48     : QDialog( parent, name, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
49 {
50   if ( !name )
51     setName( "SALOMEGUI_OpenWith" );
52   setCaption( tr("OPEN_WITH_TLT") );
53   setSizeGripEnabled( TRUE );
54
55   QGridLayout* aTopLayout = new QGridLayout(this);
56   aTopLayout->setMargin(MARGIN_SIZE);
57   aTopLayout->setSpacing(SPACING_SIZE);
58   
59   AllwaysCheckBox = 0;
60 /*  
61   AllwaysCheckBox = new QCheckBox( this, "AllwaysCheckBox" );
62   AllwaysCheckBox->setText( tr( "MEN_COMPONENT_CHOICE1"  ) );
63 */  
64   QHBoxLayout* aBtnLayout = new QHBoxLayout;
65   aBtnLayout->setSpacing( SPACING_SIZE );
66   aBtnLayout->setMargin( 0 );
67
68   buttonOk = new QPushButton( this, "buttonOk" );
69   buttonOk->setText( tr( "BUT_OK"  ) );
70   buttonOk->setAutoDefault( true );
71   buttonOk->setDefault( true );
72   
73   buttonCancel = new QPushButton( this, "buttonCancel" );
74   buttonCancel->setText( tr( "BUT_CANCEL"  ) );
75   buttonCancel->setAutoDefault( true );
76   
77   aBtnLayout->addWidget( buttonOk );
78   aBtnLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ) );
79   aBtnLayout->addWidget( buttonCancel );
80
81   ListComponent = new QListBox( this, "ListComponent" );
82   ListComponent->setVScrollBarMode(QListBox::AlwaysOn);
83   ListComponent->setMinimumSize(MIN_LISTBOX_WIDTH, MIN_LISTBOX_HEIGHT);
84   ListComponent->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
85   ListComponent->setSelectionMode(QListBox::Single);
86   
87   aTopLayout->addWidget(ListComponent,   0, 0);
88 //  aTopLayout->addWidget(AllwaysCheckBox, 1, 0);
89   aTopLayout->addLayout(aBtnLayout,      1, 0);
90   
91   // signals and slots connections
92   connect( buttonOk,      SIGNAL( clicked() ),          this, SLOT( accept() ) );
93   connect( buttonCancel,  SIGNAL( clicked() ),          this, SLOT( reject() ) );
94   connect( ListComponent, SIGNAL( selectionChanged() ), this, SLOT( onSelectionChanged() ));
95
96   updateButtonState();
97 }
98
99 /*  
100  *  Destroys the object and frees any allocated resources
101  */
102 SALOMEGUI_OpenWith::~SALOMEGUI_OpenWith()
103 {
104 }
105
106 /*
107    Inserts new component into component list
108 */
109 void SALOMEGUI_OpenWith::addComponent(const QString& aComp)
110 {
111   ListComponent->insertItem(aComp);
112 }
113
114 /*
115    Returns choosen component
116 */
117 QString SALOMEGUI_OpenWith::getComponent()
118 {
119   return ListComponent->currentText();
120 }
121
122 bool SALOMEGUI_OpenWith::getAlwaysFlag()
123 {
124   if ( AllwaysCheckBox )
125     return AllwaysCheckBox->isChecked();
126   return false;
127 }
128 void SALOMEGUI_OpenWith::onSelectionChanged()
129 {
130   updateButtonState();
131 }
132
133 void SALOMEGUI_OpenWith:: updateButtonState()
134 {
135   buttonOk->setEnabled( ListComponent->currentItem() >=0 && 
136                         ListComponent->currentItem() < ListComponent->count() ) ;
137 }