Salome HOME
Copyrights update
[modules/gui.git] / src / STD / STD_CloseDlg.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #include "STD_CloseDlg.h"
20
21 #include <qlabel.h> 
22 #include <qlayout.h> 
23 #include <qpushbutton.h>
24 #include <qmessagebox.h>
25 #include <qhbuttongroup.h>
26
27 #ifndef WNT
28 using namespace std;
29 #endif
30
31 /*!
32  * \brief creates a Close dialog box
33  * \param parent a parent widget
34  * \param modal bool argument, if true the dialog box is a modal dialog box
35  * \param f style flags
36  */
37
38 STD_CloseDlg::STD_CloseDlg( QWidget* parent, bool modal, WFlags f )
39 : QDialog( parent, "", true,  WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
40 {
41   setSizeGripEnabled( true );
42   setCaption( tr( "CLOSE_DLG_CAPTION" ) );
43
44   QVBoxLayout* m_vbL = new QVBoxLayout( this );
45   m_vbL->setMargin( 11 );
46   m_vbL->setSpacing( 6 );
47
48   QLabel* m_lIcon = new QLabel( this, "m_lDescr" );
49   QPixmap pm = QMessageBox::standardIcon( QMessageBox::Warning );
50   m_lIcon->setPixmap( pm );
51   m_lIcon->setScaledContents( false );
52   m_lIcon->setAlignment( Qt::AlignCenter );
53
54   QLabel* m_lDescr = new QLabel (this, "m_lDescr");
55   m_lDescr->setText ( tr ("CLOSE_DLG_DESCRIPTION") );
56   m_lDescr->setAlignment( Qt::AlignCenter );
57   m_lDescr->setMinimumHeight( m_lDescr->sizeHint().height()*5 );
58   m_lDescr->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
59
60   QHBoxLayout* m_hl1 = new QHBoxLayout();
61   m_hl1->setMargin( 0 ); m_hl1->setSpacing( 6 );
62   m_hl1->addWidget( m_lIcon );
63   m_hl1->addWidget( m_lDescr );
64
65   m_pb1 = new QPushButton( tr ("CLOSE_DLG_SAVE_CLOSE"), this );
66   m_pb2 = new QPushButton( tr ("CLOSE_DLG_CLOSE"),      this );
67   m_pb3 = new QPushButton( tr ("CLOSE_DLG_UNLOAD"),     this );
68   m_pb4 = new QPushButton( tr ("BUT_CANCEL"), this );
69
70   QGridLayout* m_hl2 = new QGridLayout();
71   m_hl2->setMargin( 0 ); m_hl2->setSpacing( 6 );
72   m_hl2->addWidget( m_pb1, 0, 0 );
73   m_hl2->addWidget( m_pb2, 0, 1 );
74   m_hl2->addWidget( m_pb3, 0, 2 );
75   m_hl2->addColSpacing( 3, 10 );
76   m_hl2->setColStretch( 3, 5 );
77   m_hl2->addWidget( m_pb4, 0, 4 );
78   
79   m_vbL->addLayout( m_hl1 );
80   m_vbL->addLayout( m_hl2 );
81
82   connect( m_pb1, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
83   connect( m_pb2, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
84   connect( m_pb3, SIGNAL( clicked() ), this, SLOT( onButtonClicked() ) );
85   connect( m_pb4, SIGNAL( clicked() ), this, SLOT( reject() ) );
86 }
87
88 //================================================================================
89 /*!
90  * \brief reaction on clicked(pressed) button
91  */
92 //================================================================================
93
94 void STD_CloseDlg::onButtonClicked()
95 {
96   QPushButton* btn = ( QPushButton* )sender();
97   if ( btn == m_pb1 )
98     done( 1 );
99   if ( btn == m_pb2 )
100     done( 2 );
101   if ( btn == m_pb3 )
102     done( 3 );
103 }