]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_PreferencesDlg.cxx
Salome HOME
748d42b54bbf60b000aa6ca35d5fcdb7f3feedaa
[modules/gui.git] / src / LightApp / LightApp_PreferencesDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File:      LightApp_PreferencesDlg.cxx
23 // Author:    Sergey TELKOV
24 //
25 #include "LightApp_PreferencesDlg.h"
26 #include "LightApp_Preferences.h"
27
28 #include "QtxResourceMgr.h"
29
30 #include <SUIT_MessageBox.h>
31
32 #include <QAbstractButton>
33 #include <QVBoxLayout>
34 #include <QFileDialog>
35
36 /*!
37   Constructor.
38 */
39 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
40 : QtxDialog( parent, true, true, OK | Close | Apply ),
41 myPrefs( prefs ), mySaved ( false )
42 {
43   setWindowTitle( tr( "CAPTION" ) );
44
45   QVBoxLayout* main = new QVBoxLayout( mainFrame() );
46   main->setMargin( 0 );
47   main->setSpacing( 5 );
48   main->addWidget( myPrefs );
49
50   setFocusProxy( myPrefs );
51   myPrefs->setFrameStyle( QFrame::Box | QFrame::Sunken );
52   myPrefs->show();
53
54   setButtonPosition( Right, Close );
55
56   setDialogFlags( AlignOnce );
57
58   connect( this, SIGNAL( dlgHelp() ),  this, SLOT( onHelp() ) );
59   connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
60
61   QAbstractButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
62   if ( defBtn )
63     connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
64   QAbstractButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
65   if( impBtn )
66     connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
67 }
68
69 /*!
70   Destructor.
71 */
72 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
73 {
74   if ( !myPrefs )
75     return;
76
77   mainFrame()->layout()->removeWidget( myPrefs );
78   myPrefs->setParent( 0 );
79   myPrefs->hide();
80   myPrefs = 0;
81 }
82
83 /*!Show/hide dialog.*/
84 void LightApp_PreferencesDlg::setVisible(bool visible)
85 {
86   if ( visible ) {
87     myPrefs->retrieve();
88     myPrefs->toBackup();
89   }
90
91   QtxDialog::setVisible(visible);
92 }
93
94 /*!Store preferences on accept.*/
95 void LightApp_PreferencesDlg::accept()
96 {
97   QtxDialog::accept();
98
99   myPrefs->store();
100   mySaved = true;
101 }
102
103 /*!Reject. Restore preferences from backup.*/
104 void LightApp_PreferencesDlg::reject()
105 {
106   QtxDialog::reject();
107
108   myPrefs->fromBackup();
109 }
110
111 /*!Do nothing.*/
112 void LightApp_PreferencesDlg::onHelp()
113 {
114 }
115
116 /*!Store preferences on apply.*/
117 void LightApp_PreferencesDlg::onApply()
118 {
119   myPrefs->store();
120
121   // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
122   // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
123   // ::preferencesChanged( const QString& sect, const QString& name ))
124   myPrefs->retrieve();
125   //
126
127   myPrefs->toBackup();
128   mySaved = true;
129 }
130
131 /*! Restore default preferences*/
132 void LightApp_PreferencesDlg::onDefault()
133 {
134   if( SUIT_MessageBox::Ok == SUIT_MessageBox::question( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ),
135                                                         SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
136                                                         SUIT_MessageBox::Ok ) )
137     {
138       if ( myPrefs && myPrefs->resourceMgr() )
139         {
140           QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode();
141           myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
142           myPrefs->retrieve();
143           myPrefs->resourceMgr()->setWorkingMode( prev );
144         }
145     }
146 }
147
148 /*! Import preferences from some file */
149 void LightApp_PreferencesDlg::onImportPref()
150 {
151   QtxResourceMgr* mgr = myPrefs->resourceMgr();
152   if( !mgr )
153     return;
154
155   QFileDialog dlg( this, tr("IMPORT_PREFERENCES"), ".", "*" );
156   dlg.setObjectName( "" );
157   //dlg.setShowHiddenFiles( true );
158   dlg.exec();
159
160   QStringList files = dlg.selectedFiles();
161   if ( files.isEmpty() )
162     return;
163
164   QString fname = files[0];
165   if( mgr->import( fname ) )
166   {
167     myPrefs->retrieve();
168     myPrefs->toBackup();
169   }
170 }