1 // Copyright (C) 2007-2013 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
23 // File: LightApp_PreferencesDlg.cxx
24 // Author: Sergey TELKOV
26 #include "LightApp_PreferencesDlg.h"
27 #include "LightApp_Preferences.h"
29 #include "QtxResourceMgr.h"
31 #include <SUIT_MessageBox.h>
33 #include <QAbstractButton>
34 #include <QVBoxLayout>
35 #include <QFileDialog>
40 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
41 : QtxDialog( parent, true, true, OK | Close | Apply ),
42 myPrefs( prefs ), mySaved ( false )
44 setWindowTitle( tr( "CAPTION" ) );
46 QVBoxLayout* main = new QVBoxLayout( mainFrame() );
48 main->setSpacing( 5 );
49 main->addWidget( myPrefs );
51 setFocusProxy( myPrefs );
52 myPrefs->setFrameStyle( QFrame::Box | QFrame::Sunken );
55 setButtonPosition( Right, Close );
57 setDialogFlags( AlignOnce );
59 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
60 connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
62 QAbstractButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
64 connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
65 QAbstractButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
67 connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
69 setMinimumSize( 800, 600 );
75 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
80 mainFrame()->layout()->removeWidget( myPrefs );
81 myPrefs->setParent( 0 );
86 /*!Show/hide dialog.*/
87 void LightApp_PreferencesDlg::setVisible(bool visible)
94 QtxDialog::setVisible(visible);
97 /*!Store preferences on accept.*/
98 void LightApp_PreferencesDlg::accept()
106 /*!Reject. Restore preferences from backup.*/
107 void LightApp_PreferencesDlg::reject()
111 myPrefs->fromBackup();
115 void LightApp_PreferencesDlg::onHelp()
119 /*!Store preferences on apply.*/
120 void LightApp_PreferencesDlg::onApply()
124 // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
125 // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
126 // ::preferencesChanged( const QString& sect, const QString& name ))
134 /*! Restore default preferences*/
135 void LightApp_PreferencesDlg::onDefault()
137 if( SUIT_MessageBox::Ok == SUIT_MessageBox::question( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ),
138 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
139 SUIT_MessageBox::Ok ) )
141 if ( myPrefs && myPrefs->resourceMgr() )
143 QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode();
144 myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
146 myPrefs->resourceMgr()->setWorkingMode( prev );
151 /*! Import preferences from some file */
152 void LightApp_PreferencesDlg::onImportPref()
154 QtxResourceMgr* mgr = myPrefs->resourceMgr();
158 QFileDialog dlg( this, tr("IMPORT_PREFERENCES"), ".", "*" );
159 dlg.setObjectName( "" );
160 //dlg.setShowHiddenFiles( true );
163 QStringList files = dlg.selectedFiles();
164 if ( files.isEmpty() )
167 QString fname = files[0];
168 if( mgr->import( fname ) )