]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_PreferencesDlg.cxx
Salome HOME
af26451f77480b37987b1492a9bda51582ba82f1
[modules/gui.git] / src / LightApp / LightApp_PreferencesDlg.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 // File:      LightApp_PreferencesDlg.cxx
20 // Author:    Sergey TELKOV
21
22 #include "LightApp_PreferencesDlg.h"
23
24 #include "LightApp_Preferences.h"
25
26 #include "QtxResourceMgr.h"
27
28 #include <qbutton.h>
29 #include <qlayout.h>
30 #include <qmessagebox.h>
31 #include <qvbox.h>
32
33 /*!
34   Constructor.
35 */
36 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
37 : QtxDialog( parent, 0, true, false, OK | Close | Apply ),
38 myPrefs( prefs ), mySaved ( false )
39 {
40   setCaption( tr( "CAPTION" ) );
41
42   QVBoxLayout* main = new QVBoxLayout( mainFrame(), 5 );
43
44   QVBox* base = new QVBox( mainFrame() );
45   main->addWidget( base );
46
47   myPrefs->reparent( base, QPoint( 0, 0 ), true );
48
49   setFocusProxy( myPrefs );
50
51   setButtonPosition( Right, Close );
52
53   setDialogFlags( AlignOnce );
54
55   connect( this, SIGNAL( dlgHelp() ),  this, SLOT( onHelp() ) );
56   connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
57
58   QButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
59   if ( defBtn )
60     connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
61 }
62
63 /*!
64   Destructor.
65 */
66 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
67 {
68   if ( !myPrefs )
69     return;
70
71   myPrefs->reparent( 0, QPoint( 0, 0 ), false );
72   myPrefs = 0;
73 }
74
75 /*!Show dialog.*/
76 void LightApp_PreferencesDlg::show()
77 {
78   myPrefs->retrieve();
79   myPrefs->toBackup();
80
81   QtxDialog::show();
82 }
83
84 /*!Store preferences on accept.*/
85 void LightApp_PreferencesDlg::accept()
86 {
87   QtxDialog::accept();
88
89   myPrefs->store();
90   mySaved = true;
91 }
92
93 /*!Reject. Restore preferences from backup.*/
94 void LightApp_PreferencesDlg::reject()
95 {
96   QtxDialog::reject();
97
98   myPrefs->fromBackup();
99 }
100
101 /*!Do nothing.*/
102 void LightApp_PreferencesDlg::onHelp()
103 {
104 }
105
106 /*!Store preferences on apply.*/
107 void LightApp_PreferencesDlg::onApply()
108 {
109   myPrefs->store();
110   
111   // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
112   // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
113   // ::preferencesChanged( const QString& sect, const QString& name ))
114   myPrefs->retrieve();
115   //
116   
117   myPrefs->toBackup();
118   mySaved = true;
119 }
120
121 /*! Restore default preferences*/
122 void LightApp_PreferencesDlg::onDefault()
123 {
124   if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) )
125     {
126       if ( myPrefs && myPrefs->resourceMgr() )
127         {
128           bool prev = myPrefs->resourceMgr()->ignoreUserValues();
129           myPrefs->resourceMgr()->setIgnoreUserValues( true ); 
130           myPrefs->retrieve();
131           myPrefs->resourceMgr()->setIgnoreUserValues( prev );
132         }      
133     }
134 }