1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: LightApp_PreferencesDlg.cxx
23 // Author: Sergey TELKOV
25 #include "LightApp_PreferencesDlg.h"
26 #include "LightApp_Preferences.h"
28 #include "QtxResourceMgr.h"
30 #include <SUIT_MessageBox.h>
32 #include <QAbstractButton>
33 #include <QVBoxLayout>
34 #include <QFileDialog>
39 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
40 : QtxDialog( parent, true, true, OK | Close | Apply ),
41 myPrefs( prefs ), mySaved ( false )
43 setWindowTitle( tr( "CAPTION" ) );
45 QVBoxLayout* main = new QVBoxLayout( mainFrame() );
47 main->setSpacing( 5 );
48 main->addWidget( myPrefs );
50 setFocusProxy( myPrefs );
51 myPrefs->setFrameStyle( QFrame::Box | QFrame::Sunken );
54 setButtonPosition( Right, Close );
56 setDialogFlags( AlignOnce );
58 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
59 connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
61 QAbstractButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
63 connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
64 QAbstractButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
66 connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
72 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
77 mainFrame()->layout()->removeWidget( myPrefs );
78 myPrefs->setParent( 0 );
83 /*!Show/hide dialog.*/
84 void LightApp_PreferencesDlg::setVisible(bool visible)
91 QtxDialog::setVisible(visible);
94 /*!Store preferences on accept.*/
95 void LightApp_PreferencesDlg::accept()
103 /*!Reject. Restore preferences from backup.*/
104 void LightApp_PreferencesDlg::reject()
108 myPrefs->fromBackup();
112 void LightApp_PreferencesDlg::onHelp()
116 /*!Store preferences on apply.*/
117 void LightApp_PreferencesDlg::onApply()
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 ))
131 /*! Restore default preferences*/
132 void LightApp_PreferencesDlg::onDefault()
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 ) )
138 if ( myPrefs && myPrefs->resourceMgr() )
140 QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode();
141 myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
143 myPrefs->resourceMgr()->setWorkingMode( prev );
148 /*! Import preferences from some file */
149 void LightApp_PreferencesDlg::onImportPref()
151 QtxResourceMgr* mgr = myPrefs->resourceMgr();
155 QFileDialog dlg( this, tr("IMPORT_PREFERENCES"), ".", "*" );
156 dlg.setObjectName( "" );
157 //dlg.setShowHiddenFiles( true );
160 QStringList files = dlg.selectedFiles();
161 if ( files.isEmpty() )
164 QString fname = files[0];
165 if( mgr->import( fname ) )