1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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_Session.h>
32 #include <SUIT_Application.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_FileDlg.h>
36 #include <QAbstractButton>
37 #include <QVBoxLayout>
38 #include <QFileDialog>
43 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
44 : QtxDialog( parent, true, true, OK | Close | Apply | Help ),
45 myPrefs( prefs ), mySaved ( false )
47 setWindowTitle( tr( "CAPTION" ) );
49 QVBoxLayout* main = new QVBoxLayout( mainFrame() );
51 main->setSpacing( 5 );
52 main->addWidget( myPrefs );
54 setFocusProxy( myPrefs );
55 myPrefs->setFrameStyle( QFrame::Box | QFrame::Sunken );
58 setButtonPosition( Right, Close );
60 setDialogFlags( AlignOnce );
62 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
63 connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
65 QAbstractButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
67 connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
68 QAbstractButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
70 connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
72 setMinimumSize( 800, 600 );
78 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
83 mainFrame()->layout()->removeWidget( myPrefs );
84 myPrefs->setParent( 0 );
89 /*!Show/hide dialog.*/
90 void LightApp_PreferencesDlg::setVisible(bool visible)
97 QtxDialog::setVisible(visible);
100 /*!Store preferences on accept.*/
101 void LightApp_PreferencesDlg::accept()
109 /*!Reject. Restore preferences from backup.*/
110 void LightApp_PreferencesDlg::reject()
114 myPrefs->fromBackup();
118 void LightApp_PreferencesDlg::onHelp()
120 SUIT_Application* app = SUIT_Session::session()->activeApplication();
122 app->onHelpContextModule( "GUI", "setting_preferences_page.html" );
125 /*!Store preferences on apply.*/
126 void LightApp_PreferencesDlg::onApply()
130 // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
131 // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
132 // ::preferencesChanged( const QString& sect, const QString& name ))
140 /*! Restore default preferences*/
141 void LightApp_PreferencesDlg::onDefault()
143 if( SUIT_MessageBox::Ok == SUIT_MessageBox::question( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ),
144 SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
145 SUIT_MessageBox::Ok ) )
147 if ( myPrefs && myPrefs->resourceMgr() )
149 QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode();
150 myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
152 myPrefs->resourceMgr()->setWorkingMode( prev );
157 /*! Import preferences from some file */
158 void LightApp_PreferencesDlg::onImportPref()
160 QtxResourceMgr* mgr = myPrefs->resourceMgr();
161 QStringList filtersList;
162 filtersList.append(tr("XML_FILES_FILTER"));
163 QString anInitialPath = "";
164 if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
165 anInitialPath = QDir::currentPath();
167 QString aName = SUIT_FileDlg::getFileName( this, anInitialPath, filtersList, tr("IMPORT_PREFERENCES"), true, true );
169 if( mgr->import( aName ) )