Back to index

salome-gui  6.5.0
LightApp_PreferencesDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      LightApp_PreferencesDlg.cxx
00024 // Author:    Sergey TELKOV
00025 //
00026 #include "LightApp_PreferencesDlg.h"
00027 #include "LightApp_Preferences.h"
00028 
00029 #include "QtxResourceMgr.h"
00030 
00031 #include <SUIT_MessageBox.h>
00032 
00033 #include <QAbstractButton>
00034 #include <QVBoxLayout>
00035 #include <QFileDialog>
00036 
00040 LightApp_PreferencesDlg::LightApp_PreferencesDlg( LightApp_Preferences* prefs, QWidget* parent )
00041 : QtxDialog( parent, true, true, OK | Close | Apply ),
00042 myPrefs( prefs ), mySaved ( false )
00043 {
00044   setWindowTitle( tr( "CAPTION" ) );
00045 
00046   QVBoxLayout* main = new QVBoxLayout( mainFrame() );
00047   main->setMargin( 0 );
00048   main->setSpacing( 5 );
00049   main->addWidget( myPrefs );
00050 
00051   setFocusProxy( myPrefs );
00052   myPrefs->setFrameStyle( QFrame::Box | QFrame::Sunken );
00053   myPrefs->show();
00054 
00055   setButtonPosition( Right, Close );
00056 
00057   setDialogFlags( AlignOnce );
00058 
00059   connect( this, SIGNAL( dlgHelp() ),  this, SLOT( onHelp() ) );
00060   connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
00061 
00062   QAbstractButton* defBtn = userButton( insertButton( tr( "DEFAULT_BTN_TEXT" ) ) );
00063   if ( defBtn )
00064     connect( defBtn, SIGNAL( clicked() ), this, SLOT( onDefault() ) );
00065   QAbstractButton* impBtn = userButton( insertButton( tr( "IMPORT_BTN_TEXT" ) ) );
00066   if( impBtn )
00067     connect( impBtn, SIGNAL( clicked() ), this, SLOT( onImportPref() ) );
00068 }
00069 
00073 LightApp_PreferencesDlg::~LightApp_PreferencesDlg()
00074 {
00075   if ( !myPrefs )
00076     return;
00077 
00078   mainFrame()->layout()->removeWidget( myPrefs );
00079   myPrefs->setParent( 0 );
00080   myPrefs->hide();
00081   myPrefs = 0;
00082 }
00083 
00085 void LightApp_PreferencesDlg::setVisible(bool visible)
00086 {
00087   if ( visible ) {
00088     myPrefs->retrieve();
00089     myPrefs->toBackup();
00090   }
00091 
00092   QtxDialog::setVisible(visible);
00093 }
00094 
00096 void LightApp_PreferencesDlg::accept()
00097 {
00098   QtxDialog::accept();
00099 
00100   myPrefs->store();
00101   mySaved = true;
00102 }
00103 
00105 void LightApp_PreferencesDlg::reject()
00106 {
00107   QtxDialog::reject();
00108 
00109   myPrefs->fromBackup();
00110 }
00111 
00113 void LightApp_PreferencesDlg::onHelp()
00114 {
00115 }
00116 
00118 void LightApp_PreferencesDlg::onApply()
00119 {
00120   myPrefs->store();
00121 
00122   // Fix for Bug PAL11197: Restoring the corrected values from resource manager.
00123   // (Correcting in VisuGUI.cxx and SMESHGUI.cxx in methods
00124   // ::preferencesChanged( const QString& sect, const QString& name ))
00125   myPrefs->retrieve();
00126   //
00127 
00128   myPrefs->toBackup();
00129   mySaved = true;
00130 }
00131 
00133 void LightApp_PreferencesDlg::onDefault()
00134 {
00135   if( SUIT_MessageBox::Ok == SUIT_MessageBox::question( this, tr( "WARNING" ), tr( "DEFAULT_QUESTION" ),
00136                                                         SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
00137                                                         SUIT_MessageBox::Ok ) )
00138     {
00139       if ( myPrefs && myPrefs->resourceMgr() )
00140         {
00141           QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode();
00142           myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues );
00143           myPrefs->retrieve();
00144           myPrefs->resourceMgr()->setWorkingMode( prev );
00145         }
00146     }
00147 }
00148 
00150 void LightApp_PreferencesDlg::onImportPref()
00151 {
00152   QtxResourceMgr* mgr = myPrefs->resourceMgr();
00153   if( !mgr )
00154     return;
00155 
00156   QFileDialog dlg( this, tr("IMPORT_PREFERENCES"), ".", "*" );
00157   dlg.setObjectName( "" );
00158   //dlg.setShowHiddenFiles( true );
00159   dlg.exec();
00160 
00161   QStringList files = dlg.selectedFiles();
00162   if ( files.isEmpty() )
00163     return;
00164 
00165   QString fname = files[0];
00166   if( mgr->import( fname ) )
00167   {
00168     myPrefs->retrieve();
00169     myPrefs->toBackup();
00170   }
00171 }