1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File: LightApp_PreferencesDlg.cxx
20 // Author: Sergey TELKOV
22 #include "LightApp_PreferencesDlg.h"
23 #include "LightApp_Preferences.h"
25 #include "QtxResourceMgr.h"
29 #include <qmessagebox.h>
31 #include <qfiledialog.h>
36 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
37 : QtxDialog( parent, 0, true, true, OK | Close | Apply ),
38 myPrefs( prefs ), mySaved ( false )
40 setCaption( tr( "CAPTION" ) );
42 QVBoxLayout* main = new QVBoxLayout( mainFrame(), 5 );
44 QVBox* base = new QVBox( mainFrame() );
45 main->addWidget( base );
47 myPrefs->reparent( base, QPoint( 0, 0 ), true );
49 setFocusProxy( myPrefs );
51 setButtonPosition( Right, Close );
53 setDialogFlags( AlignOnce );
55 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
56 connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
58 QButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
60 connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
61 QButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
63 connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
69 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
74 myPrefs->reparent( 0, QPoint( 0, 0 ), false );
79 void LightApp_PreferencesDlg::show()
87 /*!Store preferences on accept.*/
88 void LightApp_PreferencesDlg::accept()
96 /*!Reject. Restore preferences from backup.*/
97 void LightApp_PreferencesDlg::reject()
101 myPrefs->fromBackup();
105 void LightApp_PreferencesDlg::onHelp()
109 /*!Store preferences on apply.*/
110 void LightApp_PreferencesDlg::onApply()
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 ))
124 /*! Restore default preferences*/
125 void LightApp_PreferencesDlg::onDefault()
127 if( QMessageBox::Ok == QMessageBox::information( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ), QMessageBox::Ok, QMessageBox::Cancel ) )
129 if ( myPrefs && myPrefs->resourceMgr() )
131 bool prev = myPrefs->resourceMgr()->ignoreUserValues();
132 myPrefs->resourceMgr()->setIgnoreUserValues( true );
134 myPrefs->resourceMgr()->setIgnoreUserValues( prev );
139 /*! Import preferences from some file */
140 void LightApp_PreferencesDlg::onImportPref()
142 QtxResourceMgr* mgr = myPrefs->resourceMgr();
146 QFileDialog dlg( ".", "*", this, "" );
147 dlg.setCaption( tr("IMPORT_PREFERENCES") );
148 dlg.setShowHiddenFiles( true );
150 QString fname = dlg.selectedFile();
151 if( fname.isEmpty() )
154 if( mgr->import( fname ) )