Salome HOME
Porting to Mandrake 10.1 and new products:
[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 #include "SALOMEGUI_OpenWith.h"
30
31 #include <qlabel.h>
32 #include <qcheckbox.h>
33 #include <qpushbutton.h>
34 #include <qlayout.h>
35 #include <qlistbox.h>
36 using namespace std;
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   connect( ListComponent, SIGNAL( doubleClicked( QListBoxItem* ) ), this, SLOT( onDoubleClickEvent( QListBoxItem* ) ));
96
97   updateButtonState();
98 }
99
100 /*  
101  *  Destroys the object and frees any allocated resources
102  */
103 SALOMEGUI_OpenWith::~SALOMEGUI_OpenWith()
104 {
105 }
106
107 /*
108    Inserts new component into component list
109 */
110 void SALOMEGUI_OpenWith::addComponent(const QString& aComp)
111 {
112   ListComponent->insertItem(aComp);
113 }
114
115 /*
116    Returns choosen component
117 */
118 QString SALOMEGUI_OpenWith::getComponent()
119 {
120   return ListComponent->currentText();
121 }
122
123 bool SALOMEGUI_OpenWith::getAlwaysFlag()
124 {
125   if ( AllwaysCheckBox )
126     return AllwaysCheckBox->isChecked();
127   return false;
128 }
129 void SALOMEGUI_OpenWith::onSelectionChanged()
130 {
131   updateButtonState();
132 }
133
134 void SALOMEGUI_OpenWith:: updateButtonState()
135 {
136   buttonOk->setEnabled( ListComponent->currentItem() >=0 && 
137                         ListComponent->currentItem() < ListComponent->count() ) ;
138 }
139
140 void SALOMEGUI_OpenWith::onDoubleClickEvent( QListBoxItem* item )
141 {
142   if ( item )
143     accept();
144 }