Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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 #include "LightApp_Preferences.h"
24
25 #include "QtxResourceMgr.h"
26
27 #include <qbutton.h>
28 #include <qlayout.h>
29 #include <qmessagebox.h>
30 #include <qvbox.h>
31 #include <qfiledialog.h>
32
33 /*!
34   Constructor.
35 */
36 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
37 : QtxDialog( parent, 0, true, true, 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   QButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
62   if( impBtn )
63     connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
64 }
65
66 /*!
67   Destructor.
68 */
69 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
70 {
71   if ( !myPrefs )
72     return;
73
74   myPrefs->reparent( 0, QPoint( 0, 0 ), false );
75   myPrefs = 0;
76 }
77
78 /*!Show dialog.*/
79 void LightApp_PreferencesDlg::show()
80 {
81   myPrefs->retrieve();
82   myPrefs->toBackup();
83
84   QtxDialog::show();
85 }
86
87 /*!Store preferences on accept.*/
88 void LightApp_PreferencesDlg::accept()
89 {
90   QtxDialog::accept();
91
92   myPrefs->store();
93   mySaved = true;
94 }
95
96 /*!Reject. Restore preferences from backup.*/
97 void LightApp_PreferencesDlg::reject()
98 {
99   QtxDialog::reject();
100
101   myPrefs->fromBackup();
102 }
103
104 /*!Do nothing.*/
105 void LightApp_PreferencesDlg::onHelp()
106 {
107 }
108
109 /*!Store preferences on apply.*/
110 void LightApp_PreferencesDlg::onApply()
111 {
112   myPrefs->store();
113   
114   // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
115   // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
116   // ::preferencesChanged( const QString& sect, const QString& name ))
117   myPrefs->retrieve();
118   //
119   
120   myPrefs->toBackup();
121   mySaved = true;
122 }
123
124 /*! Restore default preferences*/
125 void LightApp_PreferencesDlg::onDefault()
126 {
127   if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) )
128     {
129       if ( myPrefs && myPrefs->resourceMgr() )
130         {
131           bool prev = myPrefs->resourceMgr()->ignoreUserValues();
132           myPrefs->resourceMgr()->setIgnoreUserValues( true ); 
133           myPrefs->retrieve();
134           myPrefs->resourceMgr()->setIgnoreUserValues( prev );
135         }      
136     }
137 }
138
139 /*! Import preferences from some file */
140 void LightApp_PreferencesDlg::onImportPref()
141 {
142   QtxResourceMgr* mgr = myPrefs->resourceMgr();
143   if( !mgr )
144     return;
145
146   QFileDialog dlg( ".", "*", this, "", tr( "IMPORT_PREFERENCES" ) );
147   dlg.setShowHiddenFiles( true );
148   dlg.exec();
149   QString fname = dlg.selectedFile();
150   if( fname.isEmpty() )
151     return;
152
153   if( mgr->import( fname ) )
154   {
155     myPrefs->retrieve();
156     myPrefs->toBackup();
157   }
158 }