From af53b570da0d68b8b5f187f6c03d783c13286b97 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 31 Oct 2008 15:20:25 +0000 Subject: [PATCH] Improve SALOME style handling --- src/LightApp/LightApp_Application.cxx | 115 +- src/LightApp/LightApp_Application.h | 6 +- src/LightApp/LightApp_PreferencesDlg.cxx | 6 +- src/Qtx/QtxFontEdit.cxx | 36 +- src/Qtx/QtxFontEdit.h | 4 + src/Qtx/QtxResourceMgr.cxx | 168 +-- src/Qtx/QtxResourceMgr.h | 16 +- src/SUITApp/SUITApp.cxx | 13 +- src/Style/Makefile.am | 17 +- src/Style/Style_Model.cxx | 1220 +++++++++++++--------- src/Style/Style_Model.h | 239 +++-- src/Style/Style_PrefDlg.cxx | 1001 ++++++++++++++++++ src/Style/Style_PrefDlg.h | 157 +++ src/Style/Style_ResourceMgr.cxx | 101 ++ src/Style/Style_ResourceMgr.h | 48 + src/Style/Style_Salome.cxx | 769 ++++++++------ src/Style/Style_Salome.h | 93 +- src/Style/Style_Tools.cxx | 180 +++- src/Style/Style_Tools.h | 43 +- 19 files changed, 3103 insertions(+), 1129 deletions(-) create mode 100644 src/Style/Style_PrefDlg.cxx create mode 100644 src/Style/Style_PrefDlg.h create mode 100644 src/Style/Style_ResourceMgr.cxx create mode 100644 src/Style/Style_ResourceMgr.h diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c31a8aac4..341a4527d 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -44,8 +44,8 @@ #include -#include #include +#include #include #include @@ -614,6 +614,13 @@ void LightApp_Application::createActions() createMenu( MRUId, fileMenu, 100, -1 ); createMenu( separator(), fileMenu, -1, 100, -1 ); + createAction( StyleId, tr( "TOT_THEME" ), QIcon(), tr( "MEN_DESK_THEME" ), tr( "PRP_THEME" ), + 0, desk, false, this, SLOT( onStylePreferences() ) ); + + int viewMenu = createMenu( tr( "MEN_DESK_VIEW" ), -1 ); + createMenu( separator(), viewMenu, -1, 20, -1 ); + createMenu( StyleId, viewMenu, 20, -1 ); + int modTBar = createTool( tr( "INF_TOOLBAR_MODULES" ) ); createTool( ModulesListId, modTBar ); } @@ -1778,11 +1785,6 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) int pythonConsoleGroup = pref->addPreference( tr( "PREF_GROUP_PY_CONSOLE" ), genTab ); pref->addPreference( tr( "PREF_FONT" ), pythonConsoleGroup, LightApp_Preferences::Font, "PyConsole", "font" ); - int SalomeStyleGroup = pref->addPreference( tr( "PREF_GROUP_STYLE" ), genTab ); - pref->addPreference( tr( "PREF_USE_SALOME_STYLE" ), SalomeStyleGroup, LightApp_Preferences::Bool, "Style", "use_salome_style" ); - if ( resourceMgr() ) - resourceMgr()->booleanValue( "Style", "use_salome_style", true ); - int viewTab = pref->addPreference( tr( "PREF_TAB_VIEWERS" ), salomeCat ); int occGroup = pref->addPreference( tr( "PREF_GROUP_OCCVIEWER" ), viewTab ); @@ -2034,66 +2036,6 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref ) pref->setItemProperty( "strings", aValuesList, mruLinkType ); pref->setItemProperty( "indexes", anIndicesList, mruLinkType ); - // theme values - Style_Model* aSModel = 0; - QStyle* style = qApp->style(); - if ( style ) { - Style_Salome* aSStyle = qobject_cast( style ); - if ( aSStyle ) - aSModel = aSStyle->getModel(); - } - if ( !aSModel ) - return; - - QString aSection = aSModel->sectionName(); - int themaTab = pref->addPreference( aSection, salomeCat ); - QtxResourceMgr* aResMgr = pref->resourceMgr(); - aSModel->initFromResource( aResMgr ); - - QList aTabLst = aSModel->getTabs(); - QList::iterator aTabIt = aTabLst.begin(), aTabEnd = aTabLst.end(); - QList aGrpLst, aPropLst; - QList::iterator anIt, anEnd, aPropIt, aPropEnd; - int aGrpId, aPropId, aPrefId; - int themaSubTab = pref->addPreference( "ThemeTabs", themaTab, - SUIT_PreferenceMgr::Tab ); - for ( ; aTabIt != aTabEnd; ++aTabIt ) { - QList aGrpLst = aSModel->getGroups( *aTabIt ); - int themaSubSubTab = pref->addPreference( aSModel->getTabTitle( *aTabIt ), themaSubTab, - SUIT_PreferenceMgr::Frame ); - for( anIt = aGrpLst.begin(), anEnd = aGrpLst.end(); anIt != anEnd; ++anIt ) { - aGrpId = *anIt; - int themaGroup = pref->addPreference( aSModel->getGroupTitle( aGrpId ), themaSubSubTab, SUIT_PreferenceMgr::GroupBox ); - pref->setItemProperty( "columns", aSModel->getGroupNbColumns( aGrpId ), themaGroup ); - aPropLst = aSModel->getGroupProps( aGrpId ); - for( aPropIt = aPropLst.begin(), aPropEnd = aPropLst.end(); aPropIt != aPropEnd; ++aPropIt ) { - aPropId = *aPropIt; - Style_Model::PropType aType = aSModel->getPropType( aPropId ); - LightApp_Preferences::PrefItemType aPType = LightApp_Preferences::Auto; - switch( aType ) { - case Style_Model::Bool: aPType = LightApp_Preferences::Bool; break; - case Style_Model::Color: aPType = LightApp_Preferences::Color; break; - case Style_Model::String: aPType = LightApp_Preferences::String; break; - case Style_Model::IntSpin: aPType = LightApp_Preferences::IntSpin; break; - case Style_Model::DblSpin: aPType = LightApp_Preferences::DblSpin; break; - case Style_Model::Selector: aPType = LightApp_Preferences::Selector; break; - case Style_Model::Font: aPType = LightApp_Preferences::Font; break; - default: break; - } - aPrefId = pref->addPreference( aSModel->getPropTitle( aPropId ), themaGroup, - aPType, aSection, aSModel->getPropName( aPropId ) ); - aSModel->getValueTo( aResMgr, aPropId, true );//set default values into resource - if ( aPType == LightApp_Preferences::Selector ) - { - aValuesList.clear(); - anIndicesList.clear(); - aSModel->getSelector( aPropId, aValuesList, anIndicesList ); - pref->setItemProperty( "strings", aValuesList, aPrefId ); - pref->setItemProperty( "indexes", anIndicesList, aPrefId ); - } - } - } - } pref->retrieve(); } @@ -2303,29 +2245,6 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString } #endif - Style_Salome* aSStyle = 0; - if ( QStyle* style = qApp->style() ) aSStyle = qobject_cast( style ); - - if( sec=="Style" ) - { - if( param=="use_salome_style" ) - { - if ( resMgr->booleanValue( "Style", "use_salome_style", true ) ) - { - if ( !aSStyle ) - { - aSStyle = new Style_Salome(); - aSStyle->getModel()->initFromResource( resMgr ); - qApp->setStyle( aSStyle ); - } - } - else if ( aSStyle ) - { - qApp->setStyle( new QWindowsStyle ); - } - } - } - if( sec=="MRU" ) { QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); @@ -2344,16 +2263,6 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString mru->setVisible( resMgr->booleanValue( "MRU", "show_mru", false ) ); // do not show MRU menu item by default } } - - if ( aSStyle ) { - Style_Model* aSModel = aSStyle->getModel(); - if ( sec==aSModel->sectionName() ) { - bool retrieve = aSModel->updateFromResource( resMgr, param ); - if ( retrieve && _prefs_ ) - _prefs_->retrieve(); - aSStyle->polish(qApp); - } - } } /*! @@ -2863,6 +2772,14 @@ void LightApp_Application::onMRUActivated( const QString& name ) onOpenDoc( name ); } +void LightApp_Application::onStylePreferences() +{ + Style_PrefDlg dlg( desktop() ); + dlg.exec(); + + resourceMgr()->setValue( "Style", "use_salome_style", Style_Salome::isActive() ); +} + /*! Connects just added view manager */ diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 305246b40..467de5ec5 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -77,7 +77,9 @@ public: enum { RenameId = CAM_Application::UserID, CloseId, CloseAllId, GroupAllId, PreferencesId, MRUId, ModulesListId, - NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, UserID }; + NewGLViewId, NewPlot2dId, NewOCCViewId, NewVTKViewId, NewQxGraphViewId, + StyleId, + UserID }; protected: enum { NewStudyId = 1, OpenStudyId }; @@ -203,6 +205,8 @@ protected slots: void onMRUActivated( const QString& ); + void onStylePreferences(); + private slots: void onSelection(); void onRefresh(); diff --git a/src/LightApp/LightApp_PreferencesDlg.cxx b/src/LightApp/LightApp_PreferencesDlg.cxx index add5dac14..1761f91a0 100644 --- a/src/LightApp/LightApp_PreferencesDlg.cxx +++ b/src/LightApp/LightApp_PreferencesDlg.cxx @@ -134,10 +134,10 @@ void LightApp_PreferencesDlg::onDefault() { if ( myPrefs && myPrefs->resourceMgr() ) { - bool prev = myPrefs->resourceMgr()->ignoreUserValues(); - myPrefs->resourceMgr()->setIgnoreUserValues( true ); + QtxResourceMgr::WorkingMode prev = myPrefs->resourceMgr()->workingMode(); + myPrefs->resourceMgr()->setWorkingMode( QtxResourceMgr::IgnoreUserValues ); myPrefs->retrieve(); - myPrefs->resourceMgr()->setIgnoreUserValues( prev ); + myPrefs->resourceMgr()->setWorkingMode( prev ); } } } diff --git a/src/Qtx/QtxFontEdit.cxx b/src/Qtx/QtxFontEdit.cxx index 30970d8f1..972284cdf 100644 --- a/src/Qtx/QtxFontEdit.cxx +++ b/src/Qtx/QtxFontEdit.cxx @@ -130,11 +130,25 @@ QFont QtxFontEdit::currentFont() const */ void QtxFontEdit::setCurrentFont( const QFont& fnt ) { + myFamily->blockSignals( true ); + mySize->blockSignals( true ); + myB->blockSignals( true ); + myI->blockSignals( true ); + myU->blockSignals( true ); + setFontFamily( fnt.family() ); setFontSize( fnt.pointSize() ); setFontScripting( ( fnt.bold() ? Bold : 0 ) | ( fnt.italic() ? Italic : 0 ) | ( fnt.underline() ? Underline : 0 ) ); + + myFamily->blockSignals( false ); + mySize->blockSignals( false ); + myB->blockSignals( false ); + myI->blockSignals( false ); + myU->blockSignals( false ); + + emit( changed( currentFont() ) ); } /*! @@ -234,6 +248,9 @@ void QtxFontEdit::updateState() */ void QtxFontEdit::onFontChanged( const QFont& /*f*/ ) { + bool blocked = mySize->signalsBlocked(); + mySize->blockSignals( true ); + int s = fontSize(); mySize->clear(); @@ -244,6 +261,16 @@ void QtxFontEdit::onFontChanged( const QFont& /*f*/ ) mySize->addItems( sizes ); setFontSize( s ); + + mySize->blockSignals( blocked ); + + if ( !myFamily->signalsBlocked() ) + emit( changed( currentFont() ) ); +} + +void QtxFontEdit::onPropertyChanged() +{ + emit( changed( currentFont() ) ); } /*! @@ -290,8 +317,13 @@ void QtxFontEdit::initialize() myFamily->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); - connect( myPreview, SIGNAL( clicked( bool ) ), this, SLOT( onPreview( bool ) ) ); - connect( myFamily, SIGNAL( currentFontChanged( const QFont& ) ), this, SLOT( onFontChanged( const QFont& ) ) ); + connect( myPreview, SIGNAL( clicked( bool ) ), this, SLOT( onPreview( bool ) ) ); + connect( myFamily, SIGNAL( currentFontChanged( const QFont& ) ), this, SLOT( onFontChanged( const QFont& ) ) ); + connect( mySize, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onPropertyChanged() ) ); + connect( mySize, SIGNAL( editTextChanged( QString ) ), this, SLOT( onPropertyChanged() ) ); + connect( myB, SIGNAL( toggled( bool ) ), this, SLOT( onPropertyChanged() ) ); + connect( myI, SIGNAL( toggled( bool ) ), this, SLOT( onPropertyChanged() ) ); + connect( myU, SIGNAL( toggled( bool ) ), this, SLOT( onPropertyChanged() ) ); updateState(); onFontChanged( currentFont() ); diff --git a/src/Qtx/QtxFontEdit.h b/src/Qtx/QtxFontEdit.h index b0ef25eef..897b10a47 100644 --- a/src/Qtx/QtxFontEdit.h +++ b/src/Qtx/QtxFontEdit.h @@ -67,9 +67,13 @@ public: int features() const; void setFeatures( const int ); +signals: + void changed( const QFont& ); + private slots: void onPreview( bool ); void onFontChanged( const QFont& ); + void onPropertyChanged(); private: void initialize(); diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 80812a2f1..de647ba3b 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1041,8 +1041,11 @@ bool QtxResourceMgr::Format::save( Resources* res ) resources environment variable has higher priority. Priority has the meaning when searching requested resources (application preference, pixmap file name, translation file, etc). - Loading of the user configuration file can be omitted by calling setIgnoreUserValues() - with \c true parameter. + + When retrieving preferences, it is sometimes helpful to ignore values coming from the + user preference file and take into account only global preferences. + To do this, use setWorkingMode() method passing QtxResourceMgr::IgnoreUserValues enumerator + as parameter. Resources manager operates with such terms like options, sections and parameters. Parametets are named application resources, for example, application preferences like @@ -1082,7 +1085,8 @@ QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTem myCheckExist( true ), myDefaultPix( 0 ), myIsPixmapCached( true ), - myIsIgnoreUserValues( false ) + myHasUserValues( true ), + myWorkingMode( AllowUserValues ) { QString envVar = !resVarTemplate.isEmpty() ? resVarTemplate : QString( "%1Resources" ); if ( envVar.contains( "%1" ) ) @@ -1172,18 +1176,19 @@ QStringList QtxResourceMgr::dirList() const Prepare the resources containers and load resources (if \a autoLoad is \c true). \param autoLoad if \c true (default) then all resources are loaded - \param loadUser if \c true (default) then user settings are also loaded */ -void QtxResourceMgr::initialize( const bool autoLoad, const bool loadUser ) const +void QtxResourceMgr::initialize( const bool autoLoad ) const { if ( !myResources.isEmpty() ) return; QtxResourceMgr* that = (QtxResourceMgr*)this; - if ( loadUser && !userFileName( appName() ).isEmpty() ) + if ( !userFileName( appName() ).isEmpty() ) that->myResources.append( new Resources( that, userFileName( appName() ) ) ); + that->myHasUserValues = myResources.count() > 0; + for ( QStringList::ConstIterator it = myDirList.begin(); it != myDirList.end(); ++it ) { QString path = Qtx::addSlash( *it ) + globalFileName( appName() ); @@ -1230,27 +1235,31 @@ void QtxResourceMgr::clear() } /*! - \brief Set "ignore user values" option value. - - If this option is \c true, then all resources loaded from user home directory are ignored. + \brief Get current working mode. - \param val new option value - \sa ignoreUserValues() + \return current working mode + \sa setWorkingMode(), value(), hasValue(), hasSection(), setValue() */ -void QtxResourceMgr::setIgnoreUserValues( const bool val ) +QtxResourceMgr::WorkingMode QtxResourceMgr::workingMode() const { - myIsIgnoreUserValues = val; + return myWorkingMode; } /*! - \brief Get "ignore user values" option value. + \brief Set resource manager's working mode. + + The resource manager can operate in the following working modes: + * AllowUserValues : methods values(), hasValue(), hasSection() take into account user values (default) + * IgnoreUserValues : methods values(), hasValue(), hasSection() do not take into account user values + + Note, that setValue() method always put the value to the user settings file. - \return "ignore user values" option value - \sa setIgnoreUserValues() + \param mode new working mode + \sa workingMode(), value(), hasValue(), hasSection(), setValue() */ -bool QtxResourceMgr::ignoreUserValues() const +void QtxResourceMgr::setWorkingMode( WorkingMode mode ) { - return myIsIgnoreUserValues; + myWorkingMode = mode; } /*! @@ -1493,7 +1502,7 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& v bool ok = false; ResList::ConstIterator it = myResources.begin(); - if ( ignoreUserValues() ) + if ( myHasUserValues && workingMode() == IgnoreUserValues ) ++it; for ( ; it != myResources.end() && !ok; ++it ) @@ -1702,7 +1711,12 @@ bool QtxResourceMgr::hasValue( const QString& sect, const QString& name ) const initialize(); bool ok = false; - for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + + ResList::ConstIterator it = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++it; + + for ( ; it != myResources.end() && !ok; ++it ) ok = (*it)->hasValue( sect, name ); return ok; @@ -1718,7 +1732,12 @@ bool QtxResourceMgr::hasSection( const QString& sect ) const initialize(); bool ok = false; - for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && !ok; ++it ) + + ResList::ConstIterator it = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++it; + + for ( ; it != myResources.end() && !ok; ++it ) ok = (*it)->hasSection( sect ); return ok; @@ -2062,6 +2081,9 @@ bool QtxResourceMgr::import( const QString& fname ) if ( !fmt ) return false; + if ( myResources.isEmpty() || !myHasUserValues ) + return false; + Resources* r = myResources[0]; if ( !r ) return false; @@ -2085,7 +2107,7 @@ bool QtxResourceMgr::save() if ( !fmt ) return false; - if ( myResources.isEmpty() ) + if ( myResources.isEmpty() || !myHasUserValues ) return true; return fmt->save( myResources[0] ); @@ -2100,18 +2122,19 @@ QStringList QtxResourceMgr::sections() const initialize(); QMap map; - for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end(); ++it ) + + ResList::ConstIterator it = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++it; + + for ( ; it != myResources.end(); ++it ) { QStringList lst = (*it)->sections(); for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr ) map.insert( *itr, 0 ); } - QStringList res; - for ( QMap::ConstIterator iter = map.begin(); iter != map.end(); ++iter ) - res.append( iter.key() ); - - return res; + return map.keys(); } /*! @@ -2130,20 +2153,24 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const #endif PMap pmap; - ResList::ConstIterator it = myResources.end(); - while ( it != myResources.begin() ) + Resources* ur = !myResources.isEmpty() && workingMode() == IgnoreUserValues ? myResources[0] : 0; + + QListIterator it( myResources ); + it.toBack(); + while ( it.hasPrevious() ) { - --it; - QStringList lst = (*it)->parameters( sec ); + Resources* r = it.previous(); + if ( r == ur ) break; + QStringList lst = r->parameters( sec ); for ( QStringList::ConstIterator itr = lst.begin(); itr != lst.end(); ++itr ) +#if defined(QTX_NO_INDEXED_MAP) + if ( !pmap.contains( *itr ) ) pmap.insert( *itr, 0 ); +#else pmap.insert( *itr, 0, false ); +#endif } - QStringList res; - for ( PMap::ConstIterator iter = pmap.begin(); iter != pmap.end(); ++iter ) - res.append( iter.key() ); - - return res; + return pmap.keys(); } /*! @@ -2163,7 +2190,12 @@ QStringList QtxResourceMgr::parameters( const QString& sec ) const QString QtxResourceMgr::path( const QString& sect, const QString& prefix, const QString& name ) const { QString res; - for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && res.isEmpty(); ++it ) + + ResList::ConstIterator it = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++it; + + for ( ; it != myResources.end() && res.isEmpty(); ++it ) res = (*it)->path( sect, prefix, name ); return res; } @@ -2276,39 +2308,18 @@ QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, initialize(); QPixmap pix; - for ( ResList::ConstIterator it = myResources.begin(); it != myResources.end() && pix.isNull(); ++it ) + + ResList::ConstIterator it = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++it; + + for ( ; it != myResources.end() && pix.isNull(); ++it ) pix = (*it)->loadPixmap( resSection(), prefix, name ); if ( pix.isNull() ) pix = defPix; return pix; } -/*! - \brief Load translation files according to the specified language. - - Names of the translation files are calculated according to the pattern specified - by the "translators" option (this option is read from the section "language" of resources files). - By default, "%P_msg_%L.qm" pattern is used. - Keywords \%A, \%P, \%L in the pattern are substituted by the application name, prefix and language name - correspondingly. - For example, for prefix "SUIT" an language "en", all translation files "SUIT_msg_en.qm" are searched and - loaded. - - If prefix is empty or null string, all translation files specified in the "resources" section of resources - files are loaded (actually, the section is retrieved from resSection() method). - If language is not specified, it is retrieved from the langSection() method, and if the latest is also empty, - by default "en" (English) language is used. - - \param pref parameter which defines translation context (for example, package name) - \param l language name - - \sa resSection(), langSection(), loadTranslators() -*/ -void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) -{ - loadLanguage( true, pref, l ); -} - /*! \brief Load translation files according to the specified language. @@ -2327,15 +2338,14 @@ void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) By default, settings from the user preferences file are also loaded (if user resource file is valid, see userFileName()). To avoid loading user settings, pass \c false as first parameter. - \param loadUser if \c true then user settings are also loaded \param pref parameter which defines translation context (for example, package name) \param l language name \sa resSection(), langSection(), loadTranslators() */ -void QtxResourceMgr::loadLanguage( const bool loadUser, const QString& pref, const QString& l ) +void QtxResourceMgr::loadLanguage( const QString& pref, const QString& l ) { - initialize( true, loadUser ); + initialize( true ); QMap substMap; substMap.insert( 'A', appName() ); @@ -2402,7 +2412,12 @@ void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& initialize(); ResList lst; - for ( ResList::Iterator iter = myResources.begin(); iter != myResources.end(); ++iter ) + + ResList::ConstIterator iter = myResources.begin(); + if ( myHasUserValues && workingMode() == IgnoreUserValues ) + ++iter; + + for ( ; iter != myResources.end(); ++iter ) lst.prepend( *iter ); QTranslator* trans = 0; @@ -2434,11 +2449,16 @@ void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name QTranslator* trans = 0; - ResList::ConstIterator it = myResources.end(); - while ( it != myResources.begin() ) + Resources* ur = !myResources.isEmpty() && workingMode() == IgnoreUserValues ? myResources[0] : 0; + + QListIterator it( myResources ); + it.toBack(); + while ( it.hasPrevious() ) { - --it; - trans = (*it)->loadTranslator( resSection(), prefix, name ); + Resources* r = it.previous(); + if ( r == ur ) break; + + trans = r->loadTranslator( resSection(), prefix, name ); if ( trans ) { if ( !myTranslator[prefix].contains( trans ) ) @@ -2524,7 +2544,7 @@ void QtxResourceMgr::setResource( const QString& sect, const QString& name, cons { initialize(); - if ( !myResources.isEmpty() ) + if ( !myResources.isEmpty() && myHasUserValues ) myResources.first()->setValue( sect, name, val ); } diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 550c14e30..78e8048fb 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -60,6 +60,12 @@ public: typedef IMap Section; //!< resource section #endif + //! Working mode; defines a way how resource manager handles user preferences + typedef enum { + AllowUserValues, //!< User values are processed by the resource manager + IgnoreUserValues //!< User values are ignored by the resource manager + } WorkingMode; + public: QtxResourceMgr( const QString&, const QString& = QString() ); virtual ~QtxResourceMgr(); @@ -75,8 +81,8 @@ public: void clear(); - void setIgnoreUserValues( const bool = true ); - bool ignoreUserValues() const; + WorkingMode workingMode() const; + void setWorkingMode( WorkingMode ); bool value( const QString&, const QString&, int& ) const; bool value( const QString&, const QString&, double& ) const; @@ -138,7 +144,6 @@ public: QPixmap loadPixmap( const QString&, const QString&, const bool ) const; QPixmap loadPixmap( const QString&, const QString&, const QPixmap& ) const; void loadLanguage( const QString& = QString(), const QString& = QString() ); - void loadLanguage( const bool, const QString& = QString(), const QString& = QString() ); void raiseTranslators( const QString& ); void removeTranslators( const QString& ); @@ -164,7 +169,7 @@ protected: virtual QString globalFileName( const QString& ) const; private: - void initialize( const bool = true, const bool = true ) const; + void initialize( const bool = true ) const; QString substMacro( const QString&, const QMap& ) const; private: @@ -185,7 +190,8 @@ private: QPixmap* myDefaultPix; //!< default icon bool myIsPixmapCached; //!< "cached pixmaps" flag - bool myIsIgnoreUserValues; //!< "ignore user values" flag + bool myHasUserValues; //!< \c true if user preferences has been read + WorkingMode myWorkingMode; //!< working mode friend class QtxResourceMgr::Format; }; diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index bbac91a30..c3caeef5b 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -29,7 +29,6 @@ #include #include #include -#include #include #include @@ -256,13 +255,10 @@ int main( int args, char* argv[] ) SUIT_Application* theApp = aSession->startApplication( argList.first() ); if ( theApp ) { - if ( resMgr && resMgr->booleanValue( "Style", "use_salome_style", true ) ) - { - Style_Salome* aStyle = new Style_Salome(); - aStyle->getModel()->initFromResource( theApp->resourceMgr() ); - app.setStyle( aStyle ); - } - + Style_Salome::initialize( theApp->resourceMgr() ); + if ( theApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) ) + Style_Salome::apply(); + if ( !noExceptHandling ) app.setHandler( aSession->handler() ); @@ -270,7 +266,6 @@ int main( int args, char* argv[] ) splash->finish( theApp->desktop() ); result = app.exec(); - delete splash; } delete aSession; } diff --git a/src/Style/Makefile.am b/src/Style/Makefile.am index 9c1ffedde..8243bb4b9 100644 --- a/src/Style/Makefile.am +++ b/src/Style/Makefile.am @@ -27,19 +27,24 @@ EXTRA_DIST += images # Libraries targets lib_LTLIBRARIES = libSalomeStyle.la -salomeinclude_HEADERS = \ - Style.h \ - Style_Tools.h \ - Style_Model.h \ +salomeinclude_HEADERS = \ + Style.h \ + Style_Tools.h \ + Style_Model.h \ + Style_PrefDlg.h \ + Style_ResourceMgr.h \ Style_Salome.h dist_libSalomeStyle_la_SOURCES = \ Style_Tools.cxx \ Style_Model.cxx \ + Style_PrefDlg.cxx \ + Style_ResourceMgr.cxx \ Style_Salome.cxx MOC_FILES = \ - Style_Salome_moc.cxx + Style_Salome_moc.cxx \ + Style_PrefDlg_moc.cxx QRC_FILES = \ qrc_Style.cxx @@ -51,3 +56,5 @@ libSalomeStyle_la_CPPFLAGS = $(QT_INCLUDES) \ libSalomeStyle_la_LDFLAGS = $(QT_MT_LIBS) \ ../Qtx/libqtx.la + +dist_salomeres_DATA = resources/SalomeStyle.xml diff --git a/src/Style/Style_Model.cxx b/src/Style/Style_Model.cxx index 64bfa241e..ae4a13d6e 100644 --- a/src/Style/Style_Model.cxx +++ b/src/Style/Style_Model.cxx @@ -1,588 +1,862 @@ // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D -// +// // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either +// License as published by the Free Software Foundation; either // version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : Style_Model.cxx -// Author : Natalia Ermolaeva, Open CASCADE S.A.S. +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) // #include "Style_Model.h" + #include -#include #include -#include +#include #include +#include -Style_Model::Style_Model() +/*! + \brief Mix two colors to get color with averaged red, green, blue and alpha-channel values + \internal + \param c1 first color + \param c2 second color + \return averaged color +*/ +static QColor mixColors( const QColor& c1, const QColor& c2 ) { - // grp_style group - fillValue( defined_style, "defined-style", "Style:", grp_style, Selector ); - myPStyles<<"Default"<<"Steel-blue"<<"Dark-green"; - // grp_colors group - fillValue( bg_clr, "bg-color", "Window", grp_color ); - fillValue( pal_base_clr, "base-color", "Base", grp_color ); - fillValue( header_clr, "header-color", "Header", grp_color ); - - fillValue( pal_text_clr, "text-color", "Text", grp_color ); - fillValue( pal_btext_clr, "text-button-color", "Text button", grp_color ); - fillValue( pal_wtext_clr, "text-window-color", "Text window", grp_color ); - - fillValue( slider_clr, "slider-color", "Slider", grp_color ); - fillValue( button_clr, "button-color", "Button", grp_color ); - fillValue( prbar_clr, "progress-bar-color", "Progress bar", grp_color ); - - fillValue( checked_clr, "checked-color", "Checked", grp_color ); - fillValue( pointer_clr, "pointer-color", "Pointer", grp_color ); - fillValue( tbl_grline_clr, "table-grid-color", "Table grid", grp_color ); - - fillValue( ttip_is_change, "ttip-is-change", "Change ToolTip", grp_color, Bool ); - fillValue( ttip_bg_clr, "ttip-bg-color", "Background", grp_color ); - fillValue( ttip_text_clr, "ttip-text-color", "Text color", grp_color ); - - fillValue( highlight_wdg, "is-highlight-widget", "Highlight widget", grp_color, Bool ); - fillValue( high_wdg_clr, "highlight-widget-color", "Widget center", grp_color ); - fillValue( high_brd_wdg_clr, "highligh-brd-widget-color", "Widget border", grp_color ); - - fillValue( auto_raising_wdg, "is-raising-widget", "Auto raising widget", grp_color, Bool ); - fillValue( pal_high_clr, "highlight-color", "Highlight", grp_color ); - fillValue( pal_high_text_clr, "highlight-text-color", "Highlight text", grp_color ); - // grp_col_values group - fillValue( fld_light_clr, "fld-light-color", "Field light", grp_col_values ); - fillValue( fld_dark_clr, "fld-dark-color", "Field dark", grp_col_values ); - fillValue( pal_light_clr, "light-color", "Light", grp_col_values ); - fillValue( pal_dark_clr, "dark-color", "Dark", grp_col_values ); - - fillValue( border_top_clr, "brd-top-color", "Border top", grp_col_values ); - fillValue( border_bot_clr, "brd-bottom-color", "Border bottom", grp_col_values ); - fillValue( border_tab_top_clr, "brd-tab-top-color", "Border widget top", grp_col_values ); - fillValue( border_tab_bot_clr, "brd-tab-bottom-color", "Border widget bottom", grp_col_values ); - - // lines group - fillValue( is_lines, "is-lines", "Draw lines", grp_lines, Bool ); - fillValue( lines_type, "lines-type", "Type", grp_lines, Selector ); - myLines<<"Horizontal"<<"Incline"; - fillValue( lines_clr, "lines-color", "Color", grp_lines, Color ); - fillValue( lines_transp, "lines-transp", "Transparency", grp_lines, DblSpin ); - - // grp_font group - fillValue( font_value, "app-font", "Font", grp_font, Font ); - // grp_values group - fillValue( edit_rad, "edit-rad", "Rounding of edit", grp_value, DblSpin ); - fillValue( btn_rad, "button-rad", "Rounding of button", grp_value, DblSpin ); - fillValue( frame_rad, "frame-rad", "Rounding of frame", grp_value, DblSpin ); - fillValue( slider_rad, "slider-rad", "Rounding of slider", grp_value, DblSpin ); - fillValue( hor_handle_delta, "hor-hadle-delta", "Hor spacinig of handle ", grp_value, DblSpin ); - fillValue( ver_handle_delta, "ver-handle-delta", "Ver spacing of handle", grp_value, DblSpin ); - fillValue( split_handle_len, "split-handle-len", "Length of splitter handle", grp_value, DblSpin ); - fillValue( slider_increase, "slider-increase", "Slider increase", grp_value, IntSpin ); - fillValue( all_antialized, "all-antialized", "All borders antialized", grp_value, Bool ); - - fillGroup( grp_style, tab_value, "Predefined style", 1 ); - fillGroup( grp_color, tab_color, "Colors", 3 ); - fillGroup( grp_col_values, tab_color, "ColorValues", 2 ); - fillGroup( grp_lines, tab_value, "Lines", 2 ); - fillGroup( grp_font, tab_value, "Font", 1 ); - fillGroup( grp_value, tab_value, "Values", 2 ); - - myTabs[tab_color] = QString( "Colors" ); - myTabs[tab_value] = QString( "Values" ); + return QColor( (c1.red() + c2.red() ) / 2, + (c1.green() + c2.green() ) / 2, + (c1.blue() + c2.blue() ) / 2, + (c1.alpha() + c2.alpha() ) / 2 ); } -Style_Model::~Style_Model() +/*! + \class Style_Model + \brief SALOME style model + + Style model class stores properties of the SALOME style, like palette colors, + widget roundings etc. It allows reading these properties from the resource file + and write them back to resource file. + + SALOME_Style class provides an access to the global style model (which is applied + to the application). To get access to the global SALOME style model, use static + Style_Model::model() function. + + \sa Style_Salome class +*/ + +/*! + \brief Application style data + \internal +*/ +Style_Model::AppData* Style_Model::myAppData = 0; + +/*! + \brief Constructor + + Create new SALOME style model with default properties. +*/ +Style_Model::Style_Model() + : myResourceMgr( 0 ) { + initDefaults(); // init from default values } -QString Style_Model::sectionName() +/*! + \brief Destructor +*/ +Style_Model::~Style_Model() { - return "Theme"; } -void Style_Model::reset() +/*! + \brief Initialize model from the current application style + + This function is useful when it is necessary to set/remove SALOME style + dynamically. Function fromApplication() saves current application properties + (style, palette, font) which can be later restored with the restore() function. + + The simplest way it can be done is using static functions of Style_Salome class: + Style_Salome::apply(), Style_Salome::restore() + + \param reset if \c true model is first restores default values of all properties + \sa restore(), fromResources() + \sa Style_Salome class +*/ +void Style_Model::fromApplication( bool reset ) { - ValuesMap::iterator anIt = myValues.begin(), anEnd = myValues.end(); - int anId; - for ( ; anIt != anEnd; ++anIt ) { - anId = anIt.key(); - myValues[anId].myValue = myValues[anId].myDefValue; + if ( reset ) initDefaults(); + + if ( !QApplication::instance() ) // application object is not created yet + return; + + if ( !myAppData ) { + // if not yes initialized from the application, + // store current application's style, palette, etc + myAppData = new AppData; + myAppData->myStyle = QApplication::style(); + myAppData->myPalette = QApplication::palette(); + myAppData->myFont = QApplication::font(); } -} -void Style_Model::setDefaults( QApplication* app ) -{ - setDefValue( defined_style, QVariant( 0 ) ); - - QPalette aPal = app->palette(); - setDefValue( bg_clr, QVariant( aPal.color( QPalette::Window ) ) ); - setDefValue( pal_base_clr, aPal.color ( QPalette::Base ) ); - setDefValue( header_clr, QVariant( aPal.color( QPalette::Button ) ) ); - setDefValue( pal_text_clr, aPal.color( QPalette::Text ) ); - setDefValue( pal_btext_clr, aPal.color( QPalette::ButtonText ) ); - setDefValue( pal_wtext_clr, aPal.color( QPalette::WindowText ) ); - - setDefValue( slider_clr, QVariant( aPal.color( QPalette::Button ) ) ); - setDefValue( button_clr, QVariant( aPal.color( QPalette::Button ) ) ); - setDefValue( prbar_clr, QVariant( aPal.color( QPalette::Highlight ) ) ); - - setDefValue( checked_clr, QVariant( aPal.color( QPalette::Base ) ) ); - setDefValue( pointer_clr, QVariant( QColor( Qt::black ) ) ); - setDefValue( tbl_grline_clr, QVariant( aPal.color( QPalette::Mid ) ) ); - - setDefValue( ttip_is_change, QVariant( false ) ); - setDefValue( ttip_bg_clr, myValues[bg_clr].myValue ); - setDefValue( ttip_text_clr, myValues[pal_text_clr].myValue ); - - setDefValue( highlight_wdg, QVariant( false ) ); - setDefValue( high_wdg_clr, myValues[button_clr].myValue ); - setDefValue( high_brd_wdg_clr, myValues[high_wdg_clr].myValue ); - - setDefValue( pal_high_clr, aPal.color( QPalette::Highlight ) ); - setDefValue( pal_high_text_clr, aPal.color( QPalette::HighlightedText ) ); - - setDefValue( fld_light_clr, QVariant( aPal.color( QPalette::Light ) ) ); - setDefValue( fld_dark_clr, QVariant( aPal.color( QPalette::Mid ).light( 125 ) ) ); - setDefValue( pal_light_clr, aPal.color( QPalette::Light ) ); - setDefValue( pal_dark_clr, aPal.color( QPalette::Dark ) ); - - QColor aDark = aPal.color( QPalette::Dark ); - setDefValue( border_top_clr, QVariant( aDark.light() ) ); - setDefValue( border_bot_clr, QVariant( aDark.dark() ) ); - setDefValue( border_tab_top_clr, QVariant( aDark.light().light().light() ) ); - setDefValue( border_tab_bot_clr, QVariant( aDark.dark().dark() ) ); - - setDefValue( is_lines, QVariant( false ) ); - setDefValue( lines_type, QVariant( 0 ) ); - setDefValue( lines_clr, QVariant( aPal.color( QPalette::Mid ) ) ); - - // not color settings - QFont aFont = app->font(); - setDefValue( font_value, QVariant( aFont ) ); - - setDefValue( slider_rad, QVariant( 0 ) ); - setDefValue( edit_rad, QVariant( 0 ) ); - setDefValue( btn_rad, QVariant( 0 ) ); - setDefValue( frame_rad, QVariant( 0 ) ); - setDefValue( slider_increase,QVariant( 2 ) ); - setDefValue( all_antialized, QVariant( false ) ); - setDefValue( highlight_wdg, QVariant( false ) ); - setDefValue( auto_raising_wdg, QVariant( false ) ); - setDefValue( hor_handle_delta, QVariant( 3 ) ); - setDefValue( ver_handle_delta, QVariant( 3 ) ); - setDefValue( split_handle_len, QVariant( 20 ) ); -} - -void Style_Model::initFromResource( QtxResourceMgr* theResMgr ) -{ - ValuesMap::iterator anIt = myValues.begin(), anEnd = myValues.end(); - for ( ; anIt != anEnd; ++anIt ) - setValueFrom( theResMgr, anIt.key() ); -} - -bool Style_Model::updateFromResource( QtxResourceMgr* theResMgr, const QString& thePropName ) -{ - bool retrieve = false; - if ( !theResMgr ) - return retrieve; - ValuesMap::iterator anIt = myValues.begin(), anEnd = myValues.end(); - int anId = -1; - for ( ; anIt != anEnd && anId == -1; ++anIt ) - if ( anIt.value().myName == thePropName ) - anId = anIt.key(); - if ( anId == -1 ) - return retrieve; - setValueFrom( theResMgr, anId ); - - if ( anId == defined_style ) { - setPredefinedStyle( getIntValue( defined_style ) ); - retrieve = true; - // update for resources all datas - for ( anIt = myValues.begin(); anIt != anEnd; ++anIt ) { - if ( anIt.key() != anId ) - getValueTo( theResMgr, anIt.key(), false ); + // initialize style properties from the application + + // font + myFont = myAppData->myFont; + // colors + for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) { + for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) { + myColors[ (QPalette::ColorGroup)i ][ (Style_Model::ColorRole)j ] = + myAppData->myPalette.color( (QPalette::ColorGroup)i, (QPalette::ColorRole)j ); } } - return retrieve; + + QColor dark = myAppData->myPalette.color( QPalette::Dark ); + setColor( BorderTop, dark.lighter() ); + setColor( BorderBottom, dark.darker() ); + setColor( TabBorderTop, dark.lighter().lighter() ); + setColor( TabBorderBottom, dark.darker().darker() ); + setColor( FieldLight, myAppData->myPalette.color( QPalette::Light ) ); + setColor( FieldDark, myAppData->myPalette.color( QPalette::Mid ).light( 125 ) ); + setColor( ProgressBar, myAppData->myPalette.color( QPalette::Highlight ) ); + setColor( Pointer, myAppData->myPalette.color( QPalette::WindowText ) ); + setColor( Checked, myAppData->myPalette.color( QPalette::Base ) ); + setColor( GridLine, myAppData->myPalette.color( QPalette::Mid ) ); + setColor( Header, myAppData->myPalette.color( QPalette::Button ) ); + setColor( Slider, myAppData->myPalette.color( QPalette::Button ) ); + setColor( HighlightWidget, myAppData->myPalette.color( QPalette::Button ) ); + setColor( HighlightBorder, myAppData->myPalette.color( QPalette::Button ) ); + setColor( Lines, myAppData->myPalette.color( QPalette::Mid ) ); } -void Style_Model::getValueTo( QtxResourceMgr* theResMgr, int theId, bool theIsDef ) +/*! + \brief Initialize model from the resources + + This function can be used to retrieve SALOME style properties from the resource file(s). + Note, that paremeters \a resMgr and \a resSection are stored by the model to be used + later with save() method. + + \param resMgr resources manager + \param resSection resources section name; if empty (default), "Theme" section is used instead + \sa fromApplication(), save(), update() +*/ +void Style_Model::fromResources( QtxResourceMgr* resMgr, const QString& resSection ) { - if ( !theResMgr ) + // init from application + fromApplication( true ); + + myResourceMgr = resMgr; + myResourceSection = resSection; + + // init from resource manager + if ( !resourceMgr() ) return; - QString aSection = sectionName(), - aPropName = getPropName( theId ); - switch( getPropType( theId ) ) { - case Bool: { - bool aValue; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aValue ) ) - theResMgr->setValue( aSection, aPropName, getBoolValue( theId, theIsDef ) ); - break; - } - case Color: { - QColor aColor; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aColor ) ) - theResMgr->setValue( aSection, aPropName, getColorValue( theId, theIsDef ) ); - break; - } - case String: { - QString aStr; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aStr ) ) - theResMgr->setValue( aSection, aPropName, getStringValue( theId, theIsDef ) ); - break; - } - case IntSpin: { - int aValue; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aValue ) ) - theResMgr->setValue( aSection, aPropName, getIntValue( theId, theIsDef ) ); - break; - } - case DblSpin: { - double aValue; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aValue ) ) - theResMgr->setValue( aSection, aPropName, getDblValue( theId, theIsDef ) ); - break; - } - case Selector: { - int aValue; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aValue ) ) - theResMgr->setValue( aSection, aPropName, getIntValue( theId, theIsDef ) ); - break; - } - case Font: { - QFont aFont; - if ( !theIsDef || !theResMgr->value( aSection, aPropName, aFont ) ) - theResMgr->setValue( aSection, aPropName, getFontValue( theId, theIsDef ) ); - break; - } - default: break; + + QString section = resourceSection(); + + // colors + // Button + readColorValue( Button, "button" ); + // Window text + readColorValue( WindowText, "window-text" ); + // Light + readColorValue( Light, "light" ); + // Dark + readColorValue( Dark, "dark" ); + // Mid + readColorValue( Mid, "mid" ); + // Text + readColorValue( Text, "text" ); + // BrightText + readColorValue( BrightText, "bright-text" ); + // ButtonText + readColorValue( ButtonText, "button-text" ); + // Base + readColorValue( Base, "base" ); + // Window + readColorValue( Window, "window" ); + // AlternateBase + readColorValue( AlternateBase, "alternate-base" ); + // Midlight + readColorValue( Midlight, "midlight" ); + // Shadow + readColorValue( Shadow, "shadow" ); + // Highlight + readColorValue( Highlight, "highlight" ); + // HighlightedText + readColorValue( HighlightedText, "highlight-text" ); + // Link + readColorValue( Link, "link" ); + // LinkVisited + readColorValue( LinkVisited, "link-visited" ); + // ToolTipBase + readColorValue( ToolTipBase, "tooltip-base" ); + // ToolTipText + readColorValue( ToolTipText, "tooltip-text" ); + // BorderTop + readColorValue( BorderTop, "border-top" ); + // BorderBottom + readColorValue( BorderBottom, "border-bottom" ); + // TabBorderTop + readColorValue( TabBorderTop, "tab-border-top" ); + // TabBorderBottom + readColorValue( TabBorderBottom, "tab-border-bottom" ); + // FieldLight + readColorValue( FieldLight, "field-light" ); + // FieldDark + readColorValue( FieldDark, "field-dark" ); + // ProgressBar + readColorValue( ProgressBar, "progress-bar" ); + // Pointer + readColorValue( Pointer, "pointer" ); + // Checked + readColorValue( Checked, "checked" ); + // GridLine + readColorValue( GridLine, "grid-line" ); + // Header + readColorValue( Header, "header" ); + // Slider + readColorValue( Slider, "slider" ); + // HighlightWidget + readColorValue( HighlightWidget, "highlight-widget" ); + // HighlightBorder + readColorValue( HighlightBorder, "highlight-border" ); + // Lines + readColorValue( Lines, "lines" ); + // auto-palette flag (internal) + if ( resourceMgr()->hasValue( section, "auto-palette" ) ) { + setAutoPalette( resourceMgr()->booleanValue( section, "auto-palette" ) ); + } + // lines type + if ( resourceMgr()->hasValue( section, "lines-type" ) ) { + int ltype = resourceMgr()->integerValue( section, "lines-type" ); + if ( ltype >= NoLines && ltype <= Inclined ) + setLinesType( (LineType)ltype ); + } + // lines transparency + if ( resourceMgr()->hasValue( section, "lines-transparency" ) ) { + int ltransp = resourceMgr()->integerValue( section, "lines-transparency" ); + if ( ltransp >= 0 && ltransp <= 100 ) + setLinesTransparency( ltransp ); + } + // application font + if ( resourceMgr()->hasValue( section, "application-font" ) ) { + setApplicationFont( resourceMgr()->fontValue( section, "application-font" ) ); + } + // widgets rounding + if ( resourceMgr()->hasValue( section, "button-rad" ) ) { + setWidgetRounding( ButtonRadius, resourceMgr()->doubleValue( section, "button-rad" ) ); + } + if ( resourceMgr()->hasValue( section, "edit-rad" ) ) { + setWidgetRounding( EditRadius, resourceMgr()->doubleValue( section, "edit-rad" ) ); + } + if ( resourceMgr()->hasValue( section, "frame-rad" ) ) { + setWidgetRounding( FrameRadius, resourceMgr()->doubleValue( section, "frame-rad" ) ); + } + if ( resourceMgr()->hasValue( section, "slider-rad" ) ) { + setWidgetRounding( SliderRadius, resourceMgr()->doubleValue( section, "slider-rad" ) ); + } + // widget effect + if ( resourceMgr()->hasValue( section, "widget-effect" ) ) { + int effect = resourceMgr()->integerValue( section, "widget-effect" ); + if ( effect >= NoEffect && effect <= AutoRaiseEffect ) + setWidgetEffect( (WidgetEffect)effect ); + } + else if ( resourceMgr()->hasValue( section, "is-highlight-widget" ) || + resourceMgr()->hasValue( section, "is-raising-widget" ) ) { + bool highlight = resourceMgr()->booleanValue( section, "is-highlight-widget", false ); + bool autoraise = resourceMgr()->booleanValue( section, "is-highlight-widget", false ); + if ( highlight ) + setWidgetEffect( HighlightEffect ); + else if ( autoraise ) + setWidgetEffect( AutoRaiseEffect ); + } + if ( resourceMgr()->hasValue( section, "all-antialized" ) ) { + setAntialiasing( resourceMgr()->booleanValue( section, "all-antialized" ) ); + } + // handles + if ( resourceMgr()->hasValue( section, "hor-hadle-delta" ) ) { + setHandleDelta( Qt::Horizontal, resourceMgr()->integerValue( section, "hor-hadle-delta" ) ); + } + if ( resourceMgr()->hasValue( section, "ver-hadle-delta" ) ) { + setHandleDelta( Qt::Vertical, resourceMgr()->integerValue( section, "vsr-hadle-delta" ) ); + } + if ( resourceMgr()->hasValue( section, "slider-size" ) ) { + setSliderSize( resourceMgr()->integerValue( section, "slider-size" ) ); + } + else if ( resourceMgr()->hasValue( section, "slider-increase" ) ) { + setSliderSize( resourceMgr()->integerValue( section, "slider-increase" ) ); + } + if ( resourceMgr()->hasValue( section, "split-handle-len" ) ) { + setSplitHandleLength( resourceMgr()->integerValue( section, "split-handle-len" ) ); } } -void Style_Model::setValueFrom( QtxResourceMgr* theResMgr, int theId ) +/*! + \brief Save SALOME stype properties to the resource file. + + If paremeters \a resMgr and \a resSection are not specified, default ones + (those passed to the fromResources() function) are used instead. + + \param resMgr resources manager + \param resSection resources section name + \sa fromResources(), update() +*/ +void Style_Model::save( QtxResourceMgr* resMgr, const QString& resSection ) { - if ( !theResMgr ) + if ( !resMgr ) + resMgr = resourceMgr(); + if ( !resMgr ) return; - QString aSection = sectionName(), - aPropName = getPropName( theId ); - QVariant aValue = myValues[theId].myDefValue; - switch( getPropType( theId ) ) { - case Bool: - aValue = theResMgr->booleanValue( aSection, aPropName, getBoolValue( theId, true ) ); - break; - case Color: - aValue = theResMgr->colorValue( aSection, aPropName, getColorValue( theId , true ) ); - break; - case String: - aValue = theResMgr->stringValue( aSection, aPropName, getStringValue( theId, true ) ); - break; - case IntSpin: - aValue = theResMgr->integerValue( aSection, aPropName, getIntValue( theId, true ) ); - break; - case DblSpin: - aValue = theResMgr->doubleValue( aSection, aPropName, getDblValue( theId, true ) ); - break; - case Selector: - aValue = theResMgr->integerValue( aSection, aPropName, getIntValue( theId, true ) ); - break; - case Font: - aValue = theResMgr->fontValue( aSection, aPropName, getFontValue( theId, true ) ); - break; - default: break; - } - myValues[theId].myValue = aValue; + + QString section = resSection.isEmpty() ? resourceSection() : resSection; + + // colors + // Button + writeColorValue( Button, "button", resMgr, section ); + // Window text + writeColorValue( WindowText, "window-text", resMgr, section ); + // Light + writeColorValue( Light, "light", resMgr, section ); + // Dark + writeColorValue( Dark, "dark", resMgr, section ); + // Mid + writeColorValue( Mid, "mid", resMgr, section ); + // Text + writeColorValue( Text, "text", resMgr, section ); + // BrightText + writeColorValue( BrightText, "bright-text", resMgr, section ); + // ButtonText + writeColorValue( ButtonText, "button-text", resMgr, section ); + // Base + writeColorValue( Base, "base", resMgr, section ); + // Window + writeColorValue( Window, "window", resMgr, section ); + // AlternateBase + writeColorValue( AlternateBase, "alternate-base", resMgr, section ); + // Midlight + writeColorValue( Midlight, "midlight", resMgr, section ); + // Shadow + writeColorValue( Shadow, "shadow", resMgr, section ); + // Highlight + writeColorValue( Highlight, "highlight", resMgr, section ); + // HighlightedText + writeColorValue( HighlightedText, "highlight-text", resMgr, section ); + // Link + writeColorValue( Link, "link", resMgr, section ); + // LinkVisited + writeColorValue( LinkVisited, "link-visited", resMgr, section ); + // ToolTipBase + writeColorValue( ToolTipBase, "tooltip-base", resMgr, section ); + // ToolTipText + writeColorValue( ToolTipText, "tooltip-text", resMgr, section ); + // BorderTop + writeColorValue( BorderTop, "border-top", resMgr, section ); + // BorderBottom + writeColorValue( BorderBottom, "border-bottom", resMgr, section ); + // TabBorderTop + writeColorValue( TabBorderTop, "tab-border-top", resMgr, section ); + // TabBorderBottom + writeColorValue( TabBorderBottom, "tab-border-bottom", resMgr, section ); + // FieldLight + writeColorValue( FieldLight, "field-light", resMgr, section ); + // FieldDark + writeColorValue( FieldDark, "field-dark", resMgr, section ); + // ProgressBar + writeColorValue( ProgressBar, "progress-bar", resMgr, section ); + // Pointer + writeColorValue( Pointer, "pointer", resMgr, section ); + // Checked + writeColorValue( Checked, "checked", resMgr, section ); + // GridLine + writeColorValue( GridLine, "grid-line", resMgr, section ); + // Header + writeColorValue( Header, "header", resMgr, section ); + // Slider + writeColorValue( Slider, "slider", resMgr, section ); + // HighlightWidget + writeColorValue( HighlightWidget, "highlight-widget", resMgr, section ); + // HighlightBorder + writeColorValue( HighlightBorder, "highlight-border", resMgr, section ); + // Lines + writeColorValue( Lines, "lines", resMgr, section ); + // auto-palette flag (internal) + resMgr->setValue( section, "auto-palette", isAutoPalette() ); + + // lines type + resMgr->setValue( section, "lines-type", (int)linesType() ); + // lines transparency + resMgr->setValue( section, "lines-transparency", linesTransparency() ); + // application font + resMgr->setValue( section, "application-font", applicationFont() ); + // widgets rounding + resMgr->setValue( section, "button-rad", widgetRounding( ButtonRadius ) ); + resMgr->setValue( section, "edit-rad", widgetRounding( EditRadius ) ); + resMgr->setValue( section, "frame-rad", widgetRounding( FrameRadius ) ); + resMgr->setValue( section, "slider-rad", widgetRounding( SliderRadius ) ); + resMgr->setValue( section, "all-antialized", antialiasing() ); + // widget effect + resMgr->setValue( section, "widget-effect", (int)widgetEffect() ); + // handles + resMgr->setValue( section, "hor-hadle-delta", handleDelta( Qt::Horizontal ) ); + resMgr->setValue( section, "vsr-hadle-delta", handleDelta( Qt::Vertical ) ); + resMgr->setValue( section, "slider-size", sliderSize() ); + resMgr->setValue( section, "split-handle-len", splitHandleLength() ); +} + +/*! + \brief Reload SALOME style properties from the resources file(s). + \sa fromResources(), save() +*/ +void Style_Model::update() +{ + fromResources( resourceMgr(), resourceSection() ); +} + +/*! + \brief Restore original style, palette and font to the application + + This function should be used in conjunction with fromApplication() method. + Sets initial style, color palette and font to the application. + If SALOME style model has not been initialized from the application, + this function does nothing. + + \sa fromApplication() +*/ +void Style_Model::restore() +{ + if ( !QApplication::instance() ) // application object is not created yet + return; + if ( !myAppData ) // not initialized from the application yet + return; + + QApplication::setStyle( myAppData->myStyle ); + QApplication::setPalette( myAppData->myPalette ); + QApplication::setFont( myAppData->myFont ); } -void Style_Model::setPredefinedStyle( int theType ) +/*! + \brief Get resource manager used by this SALOME style model. + + \return pointer to the resource manager passed previously to the fromResources() method + \sa initFromResources(), resourceSection() +*/ +QtxResourceMgr* Style_Model::resourceMgr() const +{ + return myResourceMgr; +} + +/*! + \brief Get resources section name + + If section name is empty, default "Theme" is returned + + \return resource section name passed previously to the fromResources() method + \sa initFromResources(), resourceMgr() +*/ +QString Style_Model::resourceSection() const +{ + return !myResourceSection.isEmpty() ? myResourceSection : "Theme"; +} + +/*! + \brief Get palette color value + \param role color role + \param cg color group + \return a color which should be used to draw the corresponding part of the application + \sa setColor() +*/ +QColor Style_Model::color( ColorRole role, QPalette::ColorGroup cg ) const +{ + QColor c = myColors[ cg ][ role ]; + if ( !c.isValid() ) c = myColors[ QPalette::Active ][ role ]; + return c; +} + +/*! + \brief Set palette color value + + If \a inactive and/or \a disabled colors are not specified, they are automatically + calculated from \a active color. + + \param role color role + \param active a color to be used with active color group (QPalette::Active) + \param inactive a color to be used with inactive color group (QPalette::Inactive) + \param disabled a color to be used with disabled color group (QPalette::Disabled) + \sa color() +*/ +void Style_Model::setColor( Style_Model::ColorRole role, const QColor& active, + const QColor& inactive, const QColor& disabled ) { - reset(); - switch ( theType ) { - case 0: { - setValue( slider_rad, QVariant( 3 ) ); - setValue( slider_increase, QVariant( 5 ) ); - setValue( auto_raising_wdg, QVariant( true ) ); + QColor ac = active, ic = inactive, dc = disabled; + + if ( !ic.isValid() ) { + ic = ac; + } + if ( !dc.isValid() ) { + switch ( role ) { + case WindowText: + case Text: + dc = color( Button ).darker(); break; - } - case 1: { - //light blue variant - setValue( bg_clr, QVariant( QColor( "lightsteelblue" ) ) ); - setValue( lines_type, QVariant( 0 ) ); - setValue( lines_clr, QVariant( QColor( "blue" ) ) ); - setValue( checked_clr, QVariant( QColor( "cornflowerblue" ) ) ); - setValue( header_clr, QVariant( QColor( "silver" ) ) ); - setValue( slider_clr, QVariant( QColor( "cornflowerblue" ) ) ); - setValue( button_clr, QVariant( QColor( "silver" ) ) ); - setValue( pointer_clr, QVariant( QColor( "midnightblue" ) ) ); - setValue( fld_light_clr, QVariant( QColor( "whitesmoke" ) ) ); - setValue( fld_dark_clr, QVariant( QColor( "grey" ).light( 145 ) ) ); - setValue( prbar_clr, QVariant( QColor ("cornflowerblue" ) ) ); - setValue( slider_rad, QVariant( 3 ) ); - setValue( edit_rad, QVariant( 6 ) ); - setValue( btn_rad, QVariant( 10 ) ); - setValue( frame_rad, QVariant( 10 ) ); - setValue( slider_increase, QVariant( 5 ) ); - setValue( all_antialized, QVariant( false ) ); // true - - setValue( highlight_wdg, QVariant( true ) ); - setValue( high_wdg_clr, QVariant("skyblue") ); - setValue( high_brd_wdg_clr, QVariant("cornflowerblue") ); - setValue( pal_base_clr, QVariant( QColor( "white" ) ) ); - //setValue( auto_raising_wdg, QVariant( true ) ); + case Base: + dc = color( Button ); break; - } - case 2: { - QColor aDarkGreen = QColor( "darkgreen" ).dark(195); - setValue( bg_clr, QVariant( QColor( "black" ) ) ); - setValue( lines_type, QVariant( 0 ) ); - setValue( checked_clr, QVariant( QColor( "black" ) ) ); - setValue( header_clr, QVariant( aDarkGreen ) ); - setValue( slider_clr, QVariant( QColor( "goldenrod" ) ) ); - setValue( button_clr, QVariant( aDarkGreen ) ); - - setValue( border_top_clr, QVariant( "goldenrod" ) ); - setValue( border_bot_clr, QVariant( "saddlebrown" ) ); - setValue( border_tab_top_clr, QVariant( "goldenrod" ) ); - setValue( border_tab_bot_clr, QVariant( "saddlebrown" ) ); - - setValue( pointer_clr, QVariant( QColor( "gold" ) ) ); - setValue( fld_light_clr, QVariant( QColor( "green" ) ) ); - setValue( fld_dark_clr, QVariant( aDarkGreen ) ); - setValue( prbar_clr, QVariant( QColor( "goldenrod" ) ) ); - setValue( tbl_grline_clr,QVariant( "saddlebrown" ) ); - setValue( ttip_is_change,QVariant( true ) ); - setValue( ttip_bg_clr, QVariant( "green" ) ); - - setValue( pal_text_clr, QVariant( QColor( "white" ) ) ); - setValue( pal_btext_clr, QVariant( QColor( "gold" ) ) ); - setValue( pal_wtext_clr, QVariant( QColor( "gold" ) ) ); - setValue( pal_base_clr, QVariant( QColor( "black" ) ) ); - setValue( pal_high_clr, QVariant( QColor( "gold" ) ) ); - setValue( pal_high_text_clr, QVariant( QColor( "goldenrod" ) ) ); - setValue( pal_light_clr, QVariant( QColor( "goldenrod" ) ) ); - setValue( pal_dark_clr, QVariant( QColor( "saddlebrown" ) ) ); - - setValue( slider_rad, QVariant( 3 ) ); - setValue( edit_rad, QVariant( 6 ) ); - setValue( frame_rad, QVariant( 10 ) ); - setValue( btn_rad, QVariant( 10 ) ); - setValue( slider_increase, QVariant( 6 ) ); - setValue( all_antialized, QVariant( false ) ); - - setValue( highlight_wdg, QVariant( true ) ); - setValue( high_wdg_clr, QVariant("green") ); - setValue( high_brd_wdg_clr, QVariant( aDarkGreen ) ); + case AlternateBase: + dc = mixColors( color( Base, QPalette::Inactive ), color( Button, QPalette::Inactive ) ); + break; + case Midlight: + dc = mixColors( color( Light, QPalette::Inactive ), color( Button, QPalette::Inactive ) ); break; - } default: - return; + dc = ac; + break; + } } + + setColor( role, QPalette::Active, ac ); + setColor( role, QPalette::Inactive, ic ); + setColor( role, QPalette::Disabled, dc ); } -double Style_Model::getDblValue( int theId, const bool theIsDef ) const +/*! + \brief Set palette color value + + If \a inactive and/or \a disabled colors are not specified, they are automatically + calculated from \a active color. + + \param role color role + \param cg color group + \param c color which should be used to draw the corresponding part of the application + \sa color() +*/ +void Style_Model::setColor( Style_Model::ColorRole role, QPalette::ColorGroup cg, const QColor& c ) { - double aRes = 0; - QVariant aValue; - if ( myValues.contains(theId) && myValues[theId].myType == DblSpin ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; - if ( aValue.canConvert( QVariant::Double ) ) - aRes = myValues[theId].myValue.toDouble(); - } - return aRes; + myColors[ cg ][ role ] = c; } -int Style_Model::getIntValue( int theId, const bool theIsDef ) const +/*! + \brief Returns 'auto-calculating color values' flag + \return 'auto-calculating color values' flag + \internal + \sa setAutoPalette() +*/ +bool Style_Model::isAutoPalette() const { - int aRes = 0; - QVariant aValue; - if ( myValues.contains(theId) && ( myValues[theId].myType == IntSpin - || myValues[theId].myType == Selector ) ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; - if ( aValue.canConvert( QVariant::Int ) ) - aRes = myValues[theId].myValue.toInt(); - } - return aRes; + return myAutoPalette; } -bool Style_Model::getBoolValue( int theId, const bool theIsDef ) const +/*! + \brief Set/clear 'auto-calculating color values' flag + \param on new value of 'auto-calculating color values' flag + \internal + \sa isAutoPalette() +*/ +void Style_Model::setAutoPalette( bool on ) { - bool aRes = false; - QVariant aValue; - if ( myValues.contains(theId) && myValues[theId].myType == Bool ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; - if ( aValue.canConvert( QVariant::Bool ) ) - aRes = myValues[theId].myValue.toBool(); - } - return aRes; + myAutoPalette = on; } -QColor Style_Model::getColorValue( int theId, const bool theIsDef ) const +/*! + \brief Get lines type + \return current lines type + \sa setLinesType(), linesTransparency() +*/ +Style_Model::LineType Style_Model::linesType() const { - QColor aColor = Qt::gray; - QVariant aValue; - if ( myValues.contains(theId) && myValues[theId].myType == Color ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; + return myLinesType; +} - if ( aValue.canConvert( QVariant::Color ) ) - aColor = myValues[theId].myValue.value(); - } - return aColor; +/*! + \brief Set lines type + \param lt new lines type + \sa linesType(), linesTransparency() +*/ +void Style_Model::setLinesType( LineType lt ) +{ + myLinesType = lt; } -QString Style_Model::getStringValue( int theId, const bool theIsDef ) const +/*! + \brief Get lines transparency value + \return current lines transparency + \sa setLinesTransparency(), linesType() +*/ +int Style_Model::linesTransparency() const { - QString aRes = false; - QVariant aValue; - if ( myValues.contains(theId) && myValues[theId].myType == String ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; - if ( aValue.canConvert( QVariant::String ) ) - aRes = myValues[theId].myValue.toString(); - } - return aRes; + return myLinesTransparency; } -QFont Style_Model::getFontValue( int theId, const bool theIsDef ) const +/*! + \brief Set lines transparency value + \param transparency new lines transparency + \sa linesTransparency(), linesType() +*/ +void Style_Model::setLinesTransparency( int transparency ) { - QFont aFont; - QVariant aValue; - if ( myValues.contains(theId) && myValues[theId].myType == Font ) { - if ( theIsDef ) - aValue = myValues[theId].myDefValue; - else - aValue = myValues[theId].myValue; - if ( aValue.canConvert( QVariant::Font ) ) - aFont = myValues[theId].myValue.value(); - } - return aFont; + myLinesTransparency = transparency; } -QList Style_Model::getTabs() const +/*! + \brief Get application font + \return current application font + \sa setApplicationFont() +*/ +QFont Style_Model::applicationFont() const { - return myTabs.keys(); + return myFont; } -QString Style_Model::getTabTitle( int theId ) const +/*! + \brief Set application font + \param font new application font + \sa applicationFont() +*/ +void Style_Model::setApplicationFont( const QFont& font ) { - return myTabs.contains( theId ) ? myTabs[theId] : ""; + myFont = font; } -QList Style_Model::getGroups( int theId ) const +/*! + \brief Get widget corners rounding radius value + \param wr widget type + \return current widget corners rounding + \sa setWidgetRounding(), antialiasing() +*/ +double Style_Model::widgetRounding( Style_Model::WidgetRounding wr ) const { - QList groups; - GroupMap::const_iterator anIt = myGroups.begin(), anEnd = myGroups.end(); - for ( ; anIt != anEnd; ++anIt ) - if ( anIt.value().myTabType == theId ) - groups.append( anIt.key() ); - return groups; + return myWidgetRounding[ wr ]; } -QString Style_Model::getGroupTitle( int theId ) const +/*! + \brief Set widget corners rounding radius value + \param wr widget type + \param value new widget corners rounding + \sa widgetRounding(), antialiasing() +*/ +void Style_Model::setWidgetRounding( WidgetRounding wr, double value ) { - return myGroups.contains( theId ) ? myGroups[theId].myTitle : ""; + myWidgetRounding[ wr ] = value; } -int Style_Model::getGroupNbColumns( int theId ) const +/*! + \brief Get anti-aliasing flag value + \return \c true if widgets borders should be antialiased + \sa setAntialiasing(), widgetRounding() +*/ +bool Style_Model::antialiasing() const { - return myGroups.contains( theId ) ? myGroups[theId].myNbColumns : 1; + return myAntiAliasing; } -QList Style_Model::getGroupProps( int theId ) const +/*! + \brief Set anti-aliasing flag value + \param value if \c true, widgets borders should be antialiased + \sa antialiasing(), widgetRounding() +*/ +void Style_Model::setAntialiasing( bool value ) { - QList values; - ValuesMap::const_iterator anIt = myValues.begin(), anEnd = myValues.end(); - for ( ; anIt != anEnd; ++anIt ) - if ( anIt.value().myGroupId == theId ) - values.append( anIt.key() ); - return values; + myAntiAliasing = value; } -QString Style_Model::getPropTitle( int theId ) const +/*! + \brief Get widget effect + \return current widget effect + \sa setWidgetEffect() +*/ +Style_Model::WidgetEffect Style_Model::widgetEffect() const { - return myValues.contains( theId ) ? myValues[theId].myTitle : ""; + return myWidgetEffect; } -Style_Model::PropType Style_Model::getPropType( int theId ) const +/*! + \brief Set widget effect + \param we new widget effect + \sa widgetEffect() +*/ +void Style_Model::setWidgetEffect( WidgetEffect we ) { - return myValues.contains( theId ) ? myValues[theId].myType : None; + myWidgetEffect = we; } -QString Style_Model::getPropName( int theId ) const +/*! + \brief Get handle spacing value + \param o handle spacing direction + \return current handle spacing value + \sa setHandleDelta() +*/ +int Style_Model::handleDelta( Qt::Orientation o ) const { - return myValues.contains( theId ) ? myValues[theId].myName : ""; + return myHandleDelta[ o ]; } -void Style_Model::getSelector( int theId, QStringList& theLst, QList& theIds ) const +/*! + \brief Set handle spacing value + \param o handle spacing direction + \param value new handle spacing value + \sa handleDelta() +*/ +void Style_Model::setHandleDelta( Qt::Orientation o, int value ) { - theLst.clear(); - theIds.clear(); - switch ( theId ) { - case defined_style: theLst = myPStyles; break; - case lines_type: theLst = myLines; break; - default: break; - } - QStringList::iterator anIt = theLst.begin(), anEnd = theLst.end(); - int i = 0; - for ( ; anIt != anEnd; ++anIt ) - theIds.append( QVariant( i++ ) ); + myHandleDelta[ o ] = value; } -void Style_Model::setDefValue( Properties theId, const QVariant& theValue ) +/*! + \brief Get splitter handle length + \return current splitter handle length + \sa setSplitHandleLength() +*/ +int Style_Model::splitHandleLength() const { - myValues[theId].myDefValue = theValue; - setValue( theId, theValue ); + return mySplitHandleLength; } -void Style_Model::setValue( Properties theId, const QVariant& theValue ) +/*! + \brief Set splitted handle length + \param value new splitter handle length + \sa splitHandleLength() +*/ +void Style_Model::setSplitHandleLength( int value ) { - myValues[theId].myValue = theValue; + mySplitHandleLength = value; } -void Style_Model::fillValue( Properties theId, const QString& theName, - const QString& theTitle, Groups theGroupId, PropType theType ) +/*! + \brief Get slider handle extra size + \return current slider handle extra size + \sa setSliderSize() +*/ +int Style_Model::sliderSize() const { - StyleValue aValue; - aValue.myName = theName; - aValue.myTitle = theTitle; - aValue.myGroupId = theGroupId; - aValue.myType = theType; - aValue.myValue = QVariant(); + return mySliderSize; +} - myValues[theId] = aValue; +/*! + \brief Set slider handle extra size + \param value new slider handle extra size + \sa sliderSize() +*/ +void Style_Model::setSliderSize( int value ) +{ + mySliderSize = value; } -void Style_Model::fillGroup( Groups theId, Tabs theTab, const QString& theTitle, int theNbCols ) +/*! + \brief Initialize model with the default values +*/ +void Style_Model::initDefaults() { - GroupValue aValue; - aValue.myTabType = theTab; - aValue.myTitle = theTitle; - aValue.myNbColumns = theNbCols; + // default application font + myFont.fromString( "Sans Serif,9,-1,5,50,0,0,0,0,0" ); + + // default palette colors + myAutoPalette = false; + QColor btn = QColor( "#e6e7e6" ); + QColor fg = QColor( "#000000" ); + QColor bg = QColor( "#ffffff" ); + setColor( Button, btn ); // = (230, 231, 230) + setColor( WindowText, fg ); // = ( 0, 0, 0) + setColor( Light, bg ); // = (255, 255, 255) + setColor( Dark, btn.darker() ); // = (115, 115, 115) // btn.darker( 130 ) = (177, 178, 177) + setColor( Mid, btn.darker( 150 ) ); // = (153, 154, 153) + setColor( Text, fg ); // = ( 0, 0, 0) + setColor( BrightText, bg ); // = (255, 255, 255) // fg = ( 0, 0, 0) + setColor( ButtonText, fg ); // = ( 0, 0, 0) + setColor( Base, bg ); // = (255, 255, 255) + setColor( Window, btn ); // = (230, 231, 230) + setColor( AlternateBase, mixColors( bg, btn ) ); // = (242, 243, 242) + setColor( Midlight, mixColors( bg, btn ) ); // = (242, 243, 242) + setColor( Shadow, fg ); // = ( 0, 0, 0) + setColor( Highlight, "#000080" ); // = ( 0, 0, 128) // ( 33, 68, 156 ) + setColor( HighlightedText, bg ); // = (255, 255, 255) + setColor( Link, "#0000ff" ); // = ( 0, 0, 255) + setColor( LinkVisited, "#ff00ff" ); // = (255, 0, 255) + setColor( ToolTipBase, "#ffffdc" ); // = (255, 255, 220) // ( 230, 231, 230 ) + setColor( ToolTipText, fg ); // = ( 0, 0, 0) + setColor( BorderTop, "#adadad" ); // = (173, 173, 173) // ( 255, 255, 255 ) + setColor( BorderBottom, "#393939" ); // = ( 57, 57, 57) // ( 88, 89, 88 ) + setColor( TabBorderTop, "#ffffff" ); // = (255, 255, 255) + setColor( TabBorderBottom, "#0e0e0e" ); // = ( 14, 14, 14) // ( 44, 44, 44 ) + setColor( FieldLight, "#ffffff" ); // = (255, 255, 255) + setColor( FieldDark, "#c0c1c0" ); // = (192, 193, 192) // ( 240, 241, 240 ) + setColor( ProgressBar, "#000080" ); // = ( 0, 0, 128) // ( 33, 68, 156 ) + setColor( Pointer, "#000000" ); // = ( 0, 0, 0) + setColor( Checked, "#ffffff" ); // = (255, 255, 255) + setColor( GridLine, "#999a99" ); // = (153, 154, 153) // ( 192, 192, 192 ) + setColor( Header, "#e6e7e6" ); // = (230, 231, 230) + setColor( Slider, "#e6e7e6" ); // = (230, 231, 230) + setColor( HighlightWidget, "#e6e7e6" ); // = (230, 231, 230) + setColor( HighlightBorder, "#e6e7e6" ); // = (230, 231, 230) + setColor( Lines, "#999a99" ); // = (153, 154, 153) // ( 192, 193, 192 ) + + // default values + myLinesType = NoLines; + myWidgetEffect = NoEffect; + myAntiAliasing = false; + myLinesTransparency = 0; + myWidgetRounding[ EditRadius ] = 0.0; + myWidgetRounding[ ButtonRadius ] = 0.0; + myWidgetRounding[ FrameRadius ] = 0.0; + myWidgetRounding[ SliderRadius ] = 0.0; + myHandleDelta[ Qt::Horizontal ] = 3; + myHandleDelta[ Qt::Vertical ] = 3; + mySplitHandleLength = 20; + mySliderSize = 2; +} - myGroups[theId] = aValue; +/*! + \brief Read palette color values from resources manager + \param role color role + \param prefix palette color value resource name prefix + \sa writeColorValue() +*/ +void Style_Model::readColorValue( ColorRole role, const QString& prefix ) +{ + if ( !resourceMgr() ) return; + + QString section = resourceSection(); + QString active = QString( "%1-color" ).arg( prefix ); + QString inactive = QString( "%1-color-inactive" ).arg( prefix ); + QString disabled = QString( "%1-color-disabled" ).arg( prefix ); + + if ( resourceMgr()->hasValue( section, active ) ) + setColor( role, resourceMgr()->colorValue( section, active ) ); + if ( resourceMgr()->hasValue( section, inactive ) ) + setColor( role, QPalette::Inactive, resourceMgr()->colorValue( section, inactive ) ); + if ( resourceMgr()->hasValue( section, disabled ) ) + setColor( role, QPalette::Disabled, resourceMgr()->colorValue( section, disabled ) ); } +/*! + \brief Write palette color values to resources manager + \param role color role + \param prefix palette color value resource name prefix + \param resMgr resource manager + \param resSection resource section name + \sa readColorValue() +*/ +void Style_Model::writeColorValue( ColorRole role, const QString& prefix, + QtxResourceMgr* resMgr, const QString& resSection ) const +{ + QString active = QString( "%1-color" ).arg( prefix ); + QString inactive = QString( "%1-color-inactive" ).arg( prefix ); + QString disabled = QString( "%1-color-disabled" ).arg( prefix ); + + resMgr->setValue( resSection, active, color( role, QPalette::Active ) ); + resMgr->setValue( resSection, inactive, color( role, QPalette::Inactive ) ); + resMgr->setValue( resSection, disabled, color( role, QPalette::Disabled ) ); +} diff --git a/src/Style/Style_Model.h b/src/Style/Style_Model.h index c85a709b6..c1d6c8d74 100644 --- a/src/Style/Style_Model.h +++ b/src/Style/Style_Model.h @@ -17,118 +17,171 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : Style_Model.h -// Author : Natalia Ermolaeva, Open CASCADE S.A.S. +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) // #ifndef STYLE_MODEL_H #define STYLE_MODEL_H -#include "Style.h" - #include #include -#include -#include +#include +#include +class QStyle; class QtxResourceMgr; -class QApplication; -class QColor; -class QFont; -class STYLE_SALOME_EXPORT Style_Model +// +// This class is private for Style package. +// Normally it should not be exported. +// +class Style_Model { public: + //! Color palette instance enumeration + typedef enum { + WindowText = QPalette::WindowText, //!< A general foreground color + Button = QPalette::Button, //!< The general button background color + Light = QPalette::Light, //!< Usually lighter than Button color + Midlight = QPalette::Midlight, //!< Usually between Button and Light + Dark = QPalette::Dark, //!< Usually darker than Button + Mid = QPalette::Mid, //!< Usualliy between Button and Dark + Text = QPalette::Text, //!< The foreground color used with Base + BrightText = QPalette::BrightText, //!< A text color that is very different from WindowText, and contrasts well with e.g. Dark + ButtonText = QPalette::ButtonText, //!< A foreground color used with the Button color + Base = QPalette::Base, //!< Used mostly as the background color for text entry widgets + Window = QPalette::Window, //!< A general background color + Shadow = QPalette::Shadow, //!< Usually a very dark palette color + Highlight = QPalette::Highlight, //!< A color to indicate a selected item or the current item + HighlightedText = QPalette::HighlightedText, //!< A text color that contrasts with Highlight + Link = QPalette::Link, //!< A text color used for unvisited hyperlinks + LinkVisited = QPalette::LinkVisited, //!< A text color used for already visited hyperlinks + AlternateBase = QPalette::AlternateBase, //!< Used as the alternate background color in views with alternating row colors + NoRole = QPalette::NoRole, //!< No role; this special role is often used to indicate that a role has not been assigned + ToolTipBase = QPalette::ToolTipBase, //!< Used as the background color for QToolTip and QWhatsThis + ToolTipText = QPalette::ToolTipText, //!< Used as the foreground color for QToolTip and QWhatsThis + NColorRoles = QPalette::NColorRoles, //!< Used to indicate last standard palette color + BorderTop = NColorRoles, //!< Used to draw top-left borders of the widgets + BorderBottom, //!< Used to draw bottom-right borders of the widgets + TabBorderTop, //!< Used to draw top-left borders of the tab panels + TabBorderBottom, //!< Used to draw bottom-right borders of the tab panels + FieldLight, //!< Light component of the text entry widgets + FieldDark, //!< Dark component of the text entry widgets + Slider, //!< Used to draw sliders + Lines, //!< Used to draw lines throughout all the widgets + HighlightWidget, //!< Used to draw widget background when widget is hovered + HighlightBorder, //!< Used to draw widget borders when widget is hovered + Header, //!< Used to draw header of tab panels + ProgressBar, //!< Main progress bar color + Pointer, //!< Used to draw different widgets indicators like spin box arrows etc + Checked, //!< Check box indicator color + GridLine, //!< Used to draw table widgets grid + LastColor //!< Points to the last color; no specific meaning + } ColorRole; + + //! Lines type + typedef enum { + NoLines, //!< Do not draw lines + Horizontal, //!< Draw horozontal lines + Inclined, //!< Draw inclined lines + } LineType; + + //!< Widget roundings + typedef enum { + ButtonRadius, //!< Buttons rounding + EditRadius, //!< Text entry widgets rounding + FrameRadius, //!< Frames rounding + SliderRadius, //!< Sliders rounding + } WidgetRounding; + + //! Widget effect + typedef enum { + NoEffect, //!< Do not use widget effects + HighlightEffect, //!< Highlight widget when it is hovered + AutoRaiseEffect //!< Raise widget when it is hovered + } WidgetEffect; + Style_Model(); virtual ~Style_Model(); - static QString sectionName(); - - typedef enum { tab_value, tab_color } Tabs; - typedef enum { grp_style, grp_color, grp_col_values, grp_lines, grp_font, grp_value } Groups; - typedef enum { None, Bool, Color, String, IntSpin, DblSpin, Selector, Font } PropType; - typedef enum { // grp_style - defined_style, - // grp colors - bg_clr, pal_base_clr, header_clr, - pal_text_clr, pal_btext_clr, pal_wtext_clr, - slider_clr, button_clr, prbar_clr, - checked_clr, pointer_clr, tbl_grline_clr, - ttip_is_change, ttip_bg_clr, ttip_text_clr, - highlight_wdg, high_wdg_clr, high_brd_wdg_clr, - auto_raising_wdg, pal_high_clr, pal_high_text_clr, - // grp_col_values - fld_light_clr, fld_dark_clr, pal_light_clr, pal_dark_clr, - border_top_clr, border_bot_clr, border_tab_top_clr, border_tab_bot_clr, - // grp_lines - is_lines, lines_type, lines_clr, lines_transp, - // grp_font - font_value, - // grp_values - edit_rad, btn_rad, frame_rad, slider_rad, - hor_handle_delta, ver_handle_delta, - split_handle_len, slider_increase, all_antialized } Properties; - - void reset(); - void setDefaults( QApplication* ); - void initFromResource( QtxResourceMgr* ); - bool updateFromResource( QtxResourceMgr*, const QString& ); - - void getValueTo( QtxResourceMgr*, int, bool ); - void setValueFrom( QtxResourceMgr*, int ); - - void setPredefinedStyle( int ); - - double getDblValue( int, const bool = false ) const; - int getIntValue( int, const bool = false ) const; - bool getBoolValue( int, const bool = false ) const; - QColor getColorValue( int, const bool = false ) const; - QString getStringValue( int, const bool = false ) const; - QFont getFontValue( int, const bool = false ) const; - - QList getTabs() const; - QString getTabTitle( int ) const; - QList getGroups( int ) const; - QString getGroupTitle( int ) const; - int getGroupNbColumns( int ) const; - QList getGroupProps( int ) const; - QString getPropTitle( int ) const; - PropType getPropType( int ) const; - QString getPropName( int ) const; - void getSelector( int, QStringList&, QList& ) const; + void fromApplication( bool = false ); + void fromResources( QtxResourceMgr*, const QString& = QString() ); -private: - void setDefValue( Properties, const QVariant& ); - void setValue( Properties, const QVariant& ); + void save( QtxResourceMgr* = 0, const QString& = QString() ); + void update(); + void restore(); + + QtxResourceMgr* resourceMgr() const; + QString resourceSection() const; + + + QColor color( ColorRole, QPalette::ColorGroup = QPalette::Active ) const; + void setColor( ColorRole, const QColor&, const QColor& = QColor(), const QColor& = QColor() ); + void setColor( ColorRole, QPalette::ColorGroup, const QColor& ); + + bool isAutoPalette() const; + void setAutoPalette( bool ); - void fillValue( Properties, const QString&, const QString&, - Groups, PropType = Color ); - void fillGroup( Groups, Tabs, const QString&, int ); + LineType linesType() const; + void setLinesType( LineType ); + + int linesTransparency() const; + void setLinesTransparency( int ); + + QFont applicationFont() const; + void setApplicationFont( const QFont& ); + + double widgetRounding( WidgetRounding ) const; + void setWidgetRounding( WidgetRounding, double ); + + bool antialiasing() const; + void setAntialiasing( bool ); + + WidgetEffect widgetEffect() const; + void setWidgetEffect( WidgetEffect ); + + int handleDelta( Qt::Orientation ) const; + void setHandleDelta( Qt::Orientation, int ); + + int splitHandleLength() const; + void setSplitHandleLength( int ); + + int sliderSize() const; + void setSliderSize( int ); + +private: + void initDefaults(); + void readColorValue( ColorRole, const QString& ); + void writeColorValue( ColorRole, const QString&, QtxResourceMgr*, const QString& ) const; private: - typedef struct { - QString myName; - QString myTitle; - Groups myGroupId; - PropType myType; - QVariant myValue; - QVariant myDefValue; - } StyleValue; - - typedef struct { - Tabs myTabType; - QString myTitle; - int myNbColumns; - } GroupValue; - - typedef QMap ValuesMap; - typedef QMap GroupMap; - typedef QMap StringMap; - ValuesMap myValues; - GroupMap myGroups; - StringMap myTabs; - - QStringList myPStyles; - QStringList myLines; + typedef QMap ColorMap; + typedef QMap ColorGroupMap; + typedef QMap RoundMap; + typedef QMap DeltaMap; + + QtxResourceMgr* myResourceMgr; + QString myResourceSection; + + ColorGroupMap myColors; + bool myAutoPalette; + RoundMap myWidgetRounding; + DeltaMap myHandleDelta; + QFont myFont; + LineType myLinesType; + WidgetEffect myWidgetEffect; + bool myAntiAliasing; + int myLinesTransparency; + int mySplitHandleLength; + int mySliderSize; + + struct AppData { + QStyle* myStyle; + QPalette myPalette; + QFont myFont; + }; + + static AppData* myAppData; }; #endif // STYLE_MODEL_H diff --git a/src/Style/Style_PrefDlg.cxx b/src/Style/Style_PrefDlg.cxx new file mode 100644 index 000000000..619d5b102 --- /dev/null +++ b/src/Style/Style_PrefDlg.cxx @@ -0,0 +1,1001 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Style_PrefDlg.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) +// + +#include "Style_PrefDlg.h" +#include "Style_ResourceMgr.h" +#include "Style_Model.h" +#include "Style_Salome.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const int MARGIN = 9; +static const int SPACING = 6; + +/*! + \class Style_PrefDlg::PaletteEditor + \brief SALOME style palette editor widget + \internal +*/ + +/*! + \brief Constructor + \param parent parent widget + \internal +*/ +Style_PrefDlg::PaletteEditor::PaletteEditor( QWidget* parent ) + : QFrame( parent ), myCurrentRow( 0 ), myCurrentColumn( -1 ) +{ + QGridLayout* l = new QGridLayout( this ); + l->setMargin( MARGIN ); l->setSpacing( SPACING ); + l->addWidget( myQuickButton = new QPushButton( tr( "Quick" ), this ), 0, 0 ); + l->addWidget( myAutoCheck = new QCheckBox( tr( "Auto" ), this ), 0, 1 ); + l->addWidget( myContainer = new QFrame( this ), 1, 0, 1, 2 ); + + l = new QGridLayout( myContainer ); + l->setMargin( 0 ); l->setSpacing( SPACING ); + + addColumn( tr( "Base colors" ) ); + for ( int i = (int)Style_Model::WindowText; i < (int)Style_Model::NColorRoles; i++ ) { + if ( i == Style_Model::NoRole ) continue; + addItem( i ); + } + + addColumn( tr( "Additional colors" ) ); + for ( int i = (int)Style_Model::BorderTop; i < (int)Style_Model::LastColor; i++ ) + addItem( i ); + + connect( myQuickButton, SIGNAL( clicked() ), this, SLOT( onQuick() ) ); + connect( myAutoCheck, SIGNAL( toggled( bool ) ), this, SLOT( onAuto() ) ); +} + +/*! + \brief Destructor + \internal +*/ +Style_PrefDlg::PaletteEditor::~PaletteEditor() +{ +} + +/*! + \brief Add new color properties column to the widget + \param title column title + \sa addItem() + \internal +*/ +void Style_PrefDlg::PaletteEditor::addColumn( const QString& title ) +{ + QGridLayout* l = qobject_cast( myContainer->layout() ); + myCurrentRow = 0; + myCurrentColumn++; + + if ( !title.isEmpty() ) { + QHBoxLayout* hbox = new QHBoxLayout; + hbox->setMargin( 0 ); hbox->setSpacing( SPACING ); + QWidget* ln = line(); + hbox->addWidget( ln ); + hbox->setStretchFactor( ln, 5 ); + QLabel* tlt = new QLabel( title, myContainer ); + tlt->setAlignment( Qt::AlignCenter ); + hbox->addWidget( tlt ); + ln = line(); + hbox->addWidget( ln ); + hbox->setStretchFactor( ln, 5 ); + l->addLayout( hbox, myCurrentRow++, myCurrentColumn*4, 1, 4 ); + } + + l->addWidget( myActiveLab = new QLabel( tr( "Active" ), myContainer ), myCurrentRow, myCurrentColumn*4+1 ); + l->addWidget( myInactiveLab = new QLabel( tr( "Inactive" ), myContainer ), myCurrentRow, myCurrentColumn*4+2 ); + l->addWidget( myDisabledLab = new QLabel( tr( "Disable" ), myContainer ), myCurrentRow, myCurrentColumn*4+3 ); + int w = 0; + w = qMax( w, myActiveLab->sizeHint().width() ); + w = qMax( w, myInactiveLab->sizeHint().width() ); + w = qMax( w, myDisabledLab->sizeHint().width() ); + myActiveLab->setMinimumWidth( w ); + myInactiveLab->setMinimumWidth( w ); + myDisabledLab->setMinimumWidth( w ); + + for( int i = 1; i < 4; i++ ) l->setColumnStretch( myCurrentColumn*4+i, 5 ); + + myCurrentRow++; +} + +/*! + \brief Add color item to the widget (to the current column) + \param id color palette identifier (Style_Model::ColorRole) + \sa addColumn(), items() + \internal +*/ +void Style_PrefDlg::PaletteEditor::addItem( int id ) +{ + if ( myButtons.contains( id ) ) + return; + + myButtons[ id ] = Btns(); + myButtons[ id ][ QPalette::Active ] = new QtxColorButton( myContainer ); + myButtons[ id ][ QPalette::Inactive ] = new QtxColorButton( myContainer ); + myButtons[ id ][ QPalette::Disabled ] = new QtxColorButton( myContainer ); + myButtons[ id ][ QPalette::Active ]->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myButtons[ id ][ QPalette::Inactive ]->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + myButtons[ id ][ QPalette::Disabled ]->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); + + QGridLayout* l = qobject_cast( myContainer->layout() ); + l->addWidget( new QLabel( idToName( id ), myContainer ), myCurrentRow, myCurrentColumn*4 ); + l->addWidget( myButtons[ id ][ QPalette::Active ], myCurrentRow, myCurrentColumn*4+1 ); + l->addWidget( myButtons[ id ][ QPalette::Inactive ], myCurrentRow, myCurrentColumn*4+2 ); + l->addWidget( myButtons[ id ][ QPalette::Disabled ], myCurrentRow, myCurrentColumn*4+3 ); + + connect( myButtons[ id ][ QPalette::Active ], SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); + connect( myButtons[ id ][ QPalette::Inactive ], SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); + connect( myButtons[ id ][ QPalette::Disabled ], SIGNAL( changed( QColor ) ), this, SIGNAL( changed() ) ); + + myCurrentRow++; +} + +/*! + \brief Get list of currently available color items + \return list of items identifiers (Style_Model::ColorRole) + \sa addColumn(), addItem() + \internal +*/ +QList Style_PrefDlg::PaletteEditor::items() const +{ + return myButtons.keys(); +} + +/*! + \brief Set color value to the item + \param id item identifier (Style_Model::ColorRole) + \param cg color group + \param c color value + \sa color() + \internal +*/ +void Style_PrefDlg::PaletteEditor::setColor( int id, QPalette::ColorGroup cg, const QColor& c ) +{ + if ( myButtons.contains( id ) ) { + myButtons[ id ][ cg ]->setColor( c ); + } +} + +/*! + \brief Set color value to the item + \param id item identifier (Style_Model::ColorRole) + \param active color to be used with active color group (QPalette::Active) + \param inactive color to be used with inactive color group (QPalette::Inactive) + \param disabled color to be used with disabled color group (QPalette::Disabled) + \sa color() + \internal +*/ +void Style_PrefDlg::PaletteEditor::setColor( int id, const QColor& active, + const QColor& inactive, const QColor& disabled ) +{ + setColor( id, QPalette::Active, active ); + setColor( id, QPalette::Inactive, inactive.isValid() ? inactive : active ); + setColor( id, QPalette::Disabled, disabled.isValid() ? disabled : active ); +} + +/*! + \brief Get color value assigned to the item + \param id item identifier (Style_Model::ColorRole) + \param cg color group + \return color value + \sa setColor() + \internal +*/ +QColor Style_PrefDlg::PaletteEditor::color( int id, QPalette::ColorGroup cg ) const +{ + QColor c; + if ( myButtons.contains( id ) ) { + c = myButtons[ id ][ cg ]->color(); + } + return c; +} + +/*! + \brief Get 'auto-palette' flag value + \return \c true if inactive/disabled palette colors should be calculated from active one + \sa setAuto() + \internal +*/ +bool Style_PrefDlg::PaletteEditor::isAuto() const +{ + return myAutoCheck->isChecked(); +} + +/*! + \brief Set/clear 'auto-palette' flag value + \param on if \c true, inactive/disabled palette colors should be calculated from active one + \sa isAuto() + \internal +*/ +void Style_PrefDlg::PaletteEditor::setAuto( bool on ) +{ + myAutoCheck->setChecked( on ); +} + +/*! + \brief Initialize all palette colors from color \a c + \param c button color value + \internal +*/ +void Style_PrefDlg::PaletteEditor::fromColor( const QColor& c ) +{ + const QPalette pal = QPalette( c ); + for ( int i = 0; i < (int)Style_Model::NColorRoles; i++ ) { + setColor( i, + pal.color( QPalette::Active, (QPalette::ColorRole)i ), + pal.color( QPalette::Inactive, (QPalette::ColorRole)i ), + pal.color( QPalette::Disabled, (QPalette::ColorRole)i ) ); + } + + // Header + setColor( Style_Model::Header, + pal.color( QPalette::Active, QPalette::Button ), + pal.color( QPalette::Inactive, QPalette::Button ), + pal.color( QPalette::Disabled, QPalette::Button ) ); + // Checked + setColor( Style_Model::Checked, + pal.color( QPalette::Active, QPalette::Base ), + pal.color( QPalette::Inactive, QPalette::Base ), + pal.color( QPalette::Disabled, QPalette::Base ) ); + // Lines + setColor( Style_Model::Lines, + pal.color( QPalette::Active, QPalette::Mid ), + pal.color( QPalette::Inactive, QPalette::Mid ), + pal.color( QPalette::Disabled, QPalette::Mid ) ); + // Slider + setColor( Style_Model::Slider, + pal.color( QPalette::Active, QPalette::Button ), + pal.color( QPalette::Inactive, QPalette::Button ), + pal.color( QPalette::Disabled, QPalette::Button ) ); + // ProgressBar + setColor( Style_Model::ProgressBar, + pal.color( QPalette::Active, QPalette::Highlight ), + pal.color( QPalette::Inactive, QPalette::Highlight ), + pal.color( QPalette::Disabled, QPalette::Highlight ) ); + // FieldLight + setColor( Style_Model::FieldLight, + pal.color( QPalette::Active, QPalette::Light ), + pal.color( QPalette::Inactive, QPalette::Light ), + pal.color( QPalette::Disabled, QPalette::Light ) ); + // FieldDark + setColor( Style_Model::FieldDark, + pal.color( QPalette::Active, QPalette::Mid ).light( 125 ), + pal.color( QPalette::Inactive, QPalette::Mid ).light( 125 ), + pal.color( QPalette::Disabled, QPalette::Mid ).light( 125 ) ); + // GridLine + setColor( Style_Model::GridLine, + pal.color( QPalette::Active, QPalette::Mid ), + pal.color( QPalette::Inactive, QPalette::Mid ), + pal.color( QPalette::Disabled, QPalette::Mid ) ); + // HighlightWidget + setColor( Style_Model::HighlightWidget, + pal.color( QPalette::Active, QPalette::Button ), + pal.color( QPalette::Inactive, QPalette::Button ), + pal.color( QPalette::Disabled, QPalette::Button ) ); + // HighlightWidget + setColor( Style_Model::HighlightBorder, + pal.color( QPalette::Active, QPalette::Button ).dark( 100 ), + pal.color( QPalette::Inactive, QPalette::Button ).dark( 100 ), + pal.color( QPalette::Disabled, QPalette::Button ).dark( 100 ) ); + // Pointer + setColor( Style_Model::Pointer, Qt::black, Qt::black, Qt::black ); + + QColor aDarkActive = pal.color( QPalette::Active, QPalette::Dark ); + QColor aDarkInactive = pal.color( QPalette::Inactive, QPalette::Dark ); + QColor aDarkDisabled = pal.color( QPalette::Disabled, QPalette::Dark ); + + // BorderTop + setColor( Style_Model::BorderTop, + aDarkActive.lighter(), + aDarkInactive.lighter(), + aDarkDisabled.lighter() ); + // BorderBottom + setColor( Style_Model::BorderBottom, + aDarkActive.darker(), + aDarkInactive.darker(), + aDarkDisabled.darker() ); + // TabBorderTop + setColor( Style_Model::TabBorderTop, + aDarkActive.light().light().light(), + aDarkInactive.light().light().light(), + aDarkDisabled.light().light().light() ); + // TabBorderBottom + setColor( Style_Model::TabBorderBottom, + aDarkActive.dark().dark().dark(), + aDarkInactive.dark().dark().dark(), + aDarkDisabled.dark().dark().dark() ); +} + +/*! + \brief Get title of the item + \param id item identifier (Style_Model::ColorRole) + \return item title + \internal +*/ +QString Style_PrefDlg::PaletteEditor::idToName( int id ) +{ + QString name; + switch ( id ) { + case Style_Model::WindowText: // 0 + name = tr( "Window text" ); break; + case Style_Model::Button: // 1 + name = tr( "Button" ); break; + case Style_Model::Light: // 2 + name = tr( "Light" ); break; + case Style_Model::Midlight: // 3 + name = tr( "Midlight" ); break; + case Style_Model::Dark: // 4 + name = tr( "Dark" ); break; + case Style_Model::Mid: // 5 + name = tr( "Mid" ); break; + case Style_Model::Text: // 6 + name = tr( "Text" ); break; + case Style_Model::BrightText: // 7 + name = tr( "Bright text" ); break; + case Style_Model::ButtonText: // 8 + name = tr( "Buttont text" ); break; + case Style_Model::Base: // 9 + name = tr( "Base" ); break; + case Style_Model::Window: // 10 + name = tr( "Window" ); break; + case Style_Model::Shadow: // 11 + name = tr( "Shadow" ); break; + case Style_Model::Highlight: // 12 + name = tr( "Highlight" ); break; + case Style_Model::HighlightedText: // 13 + name = tr( "Highlighted text" ); break; + case Style_Model::Link: // 14 + name = tr( "Link" ); break; + case Style_Model::LinkVisited: // 15 + name = tr( "Visited link" ); break; + case Style_Model::AlternateBase: // 16 + name = tr( "Alternate base" ); break; + case Style_Model::ToolTipBase: // 18 + name = tr( "Tooltip base" ); break; + case Style_Model::ToolTipText: // 19 + name = tr( "Tooltip text" ); break; + case Style_Model::BorderTop: + name = tr( "Border top" ); break; + case Style_Model::BorderBottom: + name = tr( "Border bottom" ); break; + case Style_Model::TabBorderTop: + name = tr( "Tab border top" ); break; + case Style_Model::TabBorderBottom: + name = tr( "Tab border bottom" ); break; + case Style_Model::FieldLight: + name = tr( "Field light" ); break; + case Style_Model::FieldDark: + name = tr( "Field dark" ); break; + case Style_Model::Slider: + name = tr( "Slider" ); break; + case Style_Model::Lines: + name = tr( "Lines" ); break; + case Style_Model::HighlightWidget: + name = tr( "Widget center" ); break; + case Style_Model::HighlightBorder: + name = tr( "Widget border" ); break; + case Style_Model::Header: + name = tr( "Header" ); break; + case Style_Model::ProgressBar: + name = tr( "Progress bar" ); break; + case Style_Model::Pointer: + name = tr( "Pointer" ); break; + case Style_Model::Checked: + name = tr( "Checked" ); break; + case Style_Model::GridLine: + name = tr( "Table grid" ); break; + default: + break; + } + return name; +} + +/*! + \brief Create horizontal line widget + \return new line widget + \internal +*/ +QWidget* Style_PrefDlg::PaletteEditor::line() +{ + QFrame* hline = new QFrame( myContainer ); + hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); + return hline; +} + +/*! + \brief Called when "Quick" button is clicked + \internal +*/ +void Style_PrefDlg::PaletteEditor::onQuick() +{ + static QColor lastColor = Qt::white; + QColor c = QColorDialog::getColor( lastColor, this ); + if ( c.isValid() ) { + fromColor( lastColor = c ); + emit( changed() ); + } +} + +/*! + \brief Called when "Auto" check box is clicked + \internal +*/ +void Style_PrefDlg::PaletteEditor::onAuto() +{ + foreach( Btns btn, myButtons ) { + btn[ QPalette::Inactive ]->setEnabled( !myAutoCheck->isChecked() ); + btn[ QPalette::Disabled ]->setEnabled( !myAutoCheck->isChecked() ); + } + emit( changed() ); +} + +/*! + \class Style_PrefDlg + \brief SALOME style prefences dialog box class. + + The dialog box lists all SALOME style themes available via the application and allows + user to create own schemas. +*/ + +/*! + \brief Constructor + \param parent parent widget +*/ +Style_PrefDlg::Style_PrefDlg( QWidget* parent ) + : QtxDialog( parent, true, true, OK | Close | Apply | Help ), + myResMgr( 0 ) +{ + // set title + setWindowTitle( tr( "SALOME style preferences" ) ); + + // create main layout + QVBoxLayout* main = new QVBoxLayout( mainFrame() ); + main->setMargin( 0 ); main->setSpacing( SPACING ); + + // create main widgets + myStyleCheck = new QCheckBox( tr( "Use SALOME Style" ), this ); + QFrame* fr = new QFrame( this ); + fr->setFrameStyle( QFrame::Box | QFrame::Sunken ); + + main->addWidget( myStyleCheck ); + main->addWidget( fr ); + + // create editor widgets + myStylesList = new QListWidget( fr ); + myStylesTab = new QTabWidget( fr ); + + QHBoxLayout* frLayout = new QHBoxLayout( fr ); + frLayout->setMargin( MARGIN ); frLayout->setSpacing( SPACING ); + frLayout->addWidget( myStylesList ); + frLayout->addWidget( myStylesTab ); + frLayout->setStretchFactor( myStylesList, 1 ); + frLayout->setStretchFactor( myStylesTab, 2 ); + + // ... + QWidget* w1 = new QWidget( myStylesTab ); + QVBoxLayout* vLayout = new QVBoxLayout( w1 ); + vLayout->setMargin( 0 ); vLayout->setSpacing( SPACING ); + + myPaletteEditor = new PaletteEditor( w1 ); + vLayout->addWidget( myPaletteEditor ); + vLayout->addStretch(); + + // ... + QWidget* w2 = new QWidget( myStylesTab ); + vLayout = new QVBoxLayout( w2 ); + vLayout->setMargin( MARGIN ); vLayout->setSpacing( SPACING ); + + QGroupBox* fontGroup = new QGroupBox( tr( "Font" ), w2 ); + myFontEdit = new QtxFontEdit( fontGroup ); + + QHBoxLayout* fontLayout = new QHBoxLayout( fontGroup ); + fontLayout->setMargin( MARGIN ); fontLayout->setSpacing( SPACING ); + fontLayout->addWidget( myFontEdit ); + + QGroupBox* linesGroup = new QGroupBox( tr( "Lines" ), w2 ); + QLabel* linesTypeLab = new QLabel( tr( "Type" ), linesGroup ); + myLinesCombo = new QComboBox( linesGroup ); + myLinesCombo->addItem( tr( "None" ), Style_Model::NoLines ); + myLinesCombo->addItem( tr( "Horizontal" ), Style_Model::Horizontal ); + myLinesCombo->addItem( tr( "Inclined" ), Style_Model::Inclined ); + QLabel* linesTranspLab = new QLabel( tr( "Transparency" ), linesGroup ); + myLinesTransparency = new QSlider( Qt::Horizontal, linesGroup ); + myLinesTransparency->setMinimum( 0 ); + myLinesTransparency->setMaximum( 100 ); + myLinesTransparency->setSingleStep( 1 ); + myLinesTransparency->setTracking( false ); + + QHBoxLayout* linesLayout = new QHBoxLayout( linesGroup ); + linesLayout->setMargin( MARGIN ); linesLayout->setSpacing( SPACING ); + linesLayout->addWidget( linesTypeLab ); + linesLayout->addWidget( myLinesCombo ); + linesLayout->addWidget( linesTranspLab ); + linesLayout->addWidget( myLinesTransparency ); + + QGroupBox* roundGroup = new QGroupBox( tr( "Widgets rounding" ), w2 ); + QLabel* roundButtonLab = new QLabel( tr( "Buttons" ), roundGroup ); + myButtonRound = new QtxDoubleSpinBox( roundGroup ); + QLabel* roundEditLab = new QLabel( tr( "Edit boxes" ), roundGroup ); + myEditRound = new QtxDoubleSpinBox( roundGroup ); + QLabel* roundFrameLab = new QLabel( tr( "Frames" ), roundGroup ); + myFrameRound = new QtxDoubleSpinBox( roundGroup ); + QLabel* roundSliderLab = new QLabel( tr( "Sliders" ), roundGroup ); + mySliderRound = new QtxDoubleSpinBox( roundGroup ); + myAntiAliasing = new QCheckBox( tr( "Anti-aliased borders" ), roundGroup ); + + QGridLayout* roundLayout = new QGridLayout( roundGroup ); + roundLayout->setMargin( MARGIN ); roundLayout->setSpacing( SPACING ); + roundLayout->addWidget( roundButtonLab, 0, 0 ); + roundLayout->addWidget( myButtonRound, 0, 1 ); + roundLayout->addWidget( roundEditLab, 0, 2 ); + roundLayout->addWidget( myEditRound, 0, 3 ); + roundLayout->addWidget( roundFrameLab, 1, 0 ); + roundLayout->addWidget( myFrameRound, 1, 1 ); + roundLayout->addWidget( roundSliderLab, 1, 2 ); + roundLayout->addWidget( mySliderRound, 1, 3 ); + roundLayout->addWidget( myAntiAliasing, 2, 0, 1, 4 ); + + QGroupBox* handleGroup = new QGroupBox( tr( "Handle" ), w2 ); + QLabel* horHandleLab = new QLabel( tr( "Horizontal spacing" ), handleGroup ); + myHorHandleDelta = new QSpinBox( handleGroup ); + QLabel* verHandleLab = new QLabel( tr( "Vertical spacing" ), handleGroup ); + myVerHandleDelta = new QSpinBox( handleGroup ); + QLabel* splitterLengthLab = new QLabel( tr( "Splitter handle size" ), handleGroup ); + mySplitterLength = new QSpinBox( handleGroup ); + QLabel* sliderLengthLab = new QLabel( tr( "Slider handle size" ), handleGroup ); + mySliderSize = new QSpinBox( handleGroup ); + + QGridLayout* handleLayout = new QGridLayout( handleGroup ); + handleLayout->setMargin( MARGIN ); handleLayout->setSpacing( SPACING ); + handleLayout->addWidget( horHandleLab, 0, 0 ); + handleLayout->addWidget( myHorHandleDelta, 0, 1 ); + handleLayout->addWidget( verHandleLab, 0, 2); + handleLayout->addWidget( myVerHandleDelta, 0, 3 ); + handleLayout->addWidget( splitterLengthLab, 1, 0 ); + handleLayout->addWidget( mySplitterLength, 1, 1 ); + handleLayout->addWidget( sliderLengthLab, 1, 2 ); + handleLayout->addWidget( mySliderSize, 1, 3 ); + + QGroupBox* effectGroup = new QGroupBox( tr( "Widget effect" ), w2 ); + myEffectNone = new QRadioButton( tr( "None" ), effectGroup ); + myEffectHighlight = new QRadioButton( tr( "Highlight widgets" ), effectGroup ); + myEffectAutoRaise = new QRadioButton( tr( "Auto raise widgets" ), effectGroup ); + QButtonGroup* aGroup = new QButtonGroup( w2 ); + aGroup->addButton( myEffectNone ); + aGroup->addButton( myEffectHighlight ); + aGroup->addButton( myEffectAutoRaise ); + myEffectNone->setChecked( true ); + myCurrentEffect = myEffectNone; + + QHBoxLayout* effectLayout = new QHBoxLayout( effectGroup ); + effectLayout->setMargin( MARGIN ); effectLayout->setSpacing( SPACING ); + effectLayout->addWidget( myEffectNone ); + effectLayout->addWidget( myEffectHighlight ); + effectLayout->addWidget( myEffectAutoRaise ); + + vLayout->addWidget( fontGroup ); + vLayout->addWidget( linesGroup ); + vLayout->addWidget( roundGroup ); + vLayout->addWidget( handleGroup ); + vLayout->addWidget( effectGroup ); + vLayout->addStretch(); + + // ... + myStylesTab->addTab( w1, tr( "Colors" ) ); + myStylesTab->addTab( w2, tr( "Properties" ) ); + + // initialize dialog box + setFocusProxy( fr ); + setButtonPosition( Right, Close ); + setDialogFlags( AlignOnce ); + myStylesList->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed ); + + QStringList globalStyles = resourceMgr()->styles( Style_ResourceMgr::Global ); + QStringList userStyles = resourceMgr()->styles( Style_ResourceMgr::User ); + + QListWidgetItem* item; + + // current style + item = new QListWidgetItem( tr( "[ Current ]" ) ); + item->setForeground( QColor( Qt::red ) ); + item->setData( TypeRole, QVariant( Current ) ); + myStylesList->addItem( item ); + // default style + item = new QListWidgetItem( tr( "[ Default ]" ) ); + item->setForeground( QColor( Qt::green ) ); + item->setData( TypeRole, QVariant( Default ) ); + myStylesList->addItem( item ); + // global styles + foreach ( QString sname, globalStyles ) { + item = new QListWidgetItem( sname ); + item->setForeground( QColor( Qt::blue ) ); + item->setData( TypeRole, QVariant( Global ) ); + item->setData( NameRole, QVariant( sname ) ); + myStylesList->addItem( item ); + } + // user styles + foreach ( QString sname, userStyles ) { + item = new QListWidgetItem( sname ); + item->setData( TypeRole, QVariant( User ) ); + item->setData( NameRole, QVariant( sname ) ); + item->setFlags( item->flags() | Qt::ItemIsEditable ); + myStylesList->addItem( item ); + } + + // connect widgets + connect( myStyleCheck, SIGNAL( toggled( bool ) ), fr, SLOT( setEnabled( bool ) ) ); + connect( myStylesList, SIGNAL( itemSelectionChanged() ), this, SLOT( onStyleChanged() ) ); + connect( myStylesList, SIGNAL( itemChanged( QListWidgetItem* ) ), this, SLOT( onItemChanged( QListWidgetItem* ) ) ); + connect( myLinesCombo, SIGNAL( activated( int ) ), this, SLOT( onLinesType() ) ); + connect( myPaletteEditor, SIGNAL( changed() ), this, SIGNAL( styleChanged() ) ); + connect( myFontEdit, SIGNAL( changed( QFont ) ), this, SIGNAL( styleChanged() ) ); + connect( myLinesTransparency, SIGNAL( valueChanged( int ) ), this, SIGNAL( styleChanged() ) ); + connect( myButtonRound, SIGNAL( valueChanged( double ) ), this, SIGNAL( styleChanged() ) ); + connect( myEditRound, SIGNAL( valueChanged( double ) ), this, SIGNAL( styleChanged() ) ); + connect( myFrameRound, SIGNAL( valueChanged( double ) ), this, SIGNAL( styleChanged() ) ); + connect( mySliderRound, SIGNAL( valueChanged( double ) ), this, SIGNAL( styleChanged() ) ); + connect( myAntiAliasing, SIGNAL( toggled( bool ) ), this, SIGNAL( styleChanged() ) ); + connect( myHorHandleDelta, SIGNAL( valueChanged( int ) ), this, SIGNAL( styleChanged() ) ); + connect( myVerHandleDelta, SIGNAL( valueChanged( int ) ), this, SIGNAL( styleChanged() ) ); + connect( mySplitterLength, SIGNAL( valueChanged( int ) ), this, SIGNAL( styleChanged() ) ); + connect( mySliderSize, SIGNAL( valueChanged( int ) ), this, SIGNAL( styleChanged() ) ); + connect( aGroup, SIGNAL( buttonClicked( QAbstractButton* ) ), + this, SLOT( onEffectChanged( QAbstractButton* ) ) ); + connect( this, SIGNAL( styleChanged() ), this, SLOT( onChanged() ) ); + + connect( this, SIGNAL( dlgApply() ), this, SLOT( onApply() ) ); + connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) ); + + myStylesList->setCurrentRow( 0 ); + + myStyleCheck->setChecked( Style_Salome::isActive() ); + fr->setEnabled( Style_Salome::isActive() ); +} + +/*! + \brief Destructor +*/ +Style_PrefDlg::~Style_PrefDlg() +{ +} + +/*! + \brief Called when "OK" button is clicked +*/ +void Style_PrefDlg::accept() +{ + onApply(); + QtxDialog::accept(); +} + +/*! + \brief Get SALOME themes resource manager + \return themes resource manager +*/ +Style_ResourceMgr* Style_PrefDlg::resourceMgr() +{ + if ( !myResMgr ) + myResMgr = new Style_ResourceMgr(); + return myResMgr; +} + +/*! + \brief Initialize dialog box fields from SALOME style model + \param model style model +*/ +void Style_PrefDlg::fromModel( Style_Model* model ) +{ + if ( !model ) return; + + // colors + for ( int i = (int)Style_Model::WindowText; i < (int)Style_Model::LastColor; i++ ) { + if ( i == Style_Model::NoRole ) continue; + myPaletteEditor->setColor( i, QPalette::Active, model->color( (Style_Model::ColorRole)i, QPalette::Active ) ); + myPaletteEditor->setColor( i, QPalette::Inactive, model->color( (Style_Model::ColorRole)i, QPalette::Inactive ) ); + myPaletteEditor->setColor( i, QPalette::Disabled, model->color( (Style_Model::ColorRole)i, QPalette::Disabled ) ); + } + myPaletteEditor->setAuto( model->isAutoPalette() ); + // font + myFontEdit->setCurrentFont( model->applicationFont() ); + // lines type + int idx = myLinesCombo->findData( QVariant( model->linesType() ) ); + if ( idx >= 0 ) myLinesCombo->setCurrentIndex( idx ); + // lines transparency + myLinesTransparency->setValue( model->linesTransparency() ); + // widgets rounding + myButtonRound->setValue( model->widgetRounding( Style_Model::ButtonRadius ) ); + myEditRound->setValue( model->widgetRounding( Style_Model::EditRadius ) ); + myFrameRound->setValue( model->widgetRounding( Style_Model::FrameRadius ) ); + mySliderRound->setValue( model->widgetRounding( Style_Model::SliderRadius ) ); + // widgets antialiasing + myAntiAliasing->setChecked( model->antialiasing() ); + // handle delta + myHorHandleDelta->setValue( model->handleDelta( Qt::Horizontal ) ); + myVerHandleDelta->setValue( model->handleDelta( Qt::Vertical ) ); + // splitter handle lentgh + mySplitterLength->setValue( model->splitHandleLength() ); + // slider size + mySliderSize->setValue( model->sliderSize() ); + // widgets effect + Style_Model::WidgetEffect we = model->widgetEffect(); + if ( we == Style_Model::HighlightEffect ) myEffectHighlight->setChecked( true ); + else if ( we == Style_Model::AutoRaiseEffect ) myEffectAutoRaise->setChecked( true ); + else myEffectNone->setChecked( true ); +} + +/*! + \brief Save values from dialog box fields to SALOME style model + \param model style model +*/ +void Style_PrefDlg::toModel( Style_Model* model ) const +{ + if ( !model ) return; + + // colors + // ... first set Button color 'cause it is used to calculate other ones + if ( myPaletteEditor->isAuto() ) + model->setColor( Style_Model::Button, + myPaletteEditor->color( Style_Model::Button, QPalette::Active ) ); + else + model->setColor( Style_Model::Button, + myPaletteEditor->color( Style_Model::Button, QPalette::Active ), + myPaletteEditor->color( Style_Model::Button, QPalette::Inactive ), + myPaletteEditor->color( Style_Model::Button, QPalette::Disabled )); + // ... then set all other colors + for ( int i = (int)Style_Model::WindowText; i < (int)Style_Model::LastColor; i++ ) { + if ( i == Style_Model::NoRole ) continue; // not supported + if ( i == Style_Model::Button ) continue; // already set + if ( myPaletteEditor->isAuto() ) + model->setColor( (Style_Model::ColorRole)i, + myPaletteEditor->color( i, QPalette::Active ) ); + else + model->setColor( (Style_Model::ColorRole)i, + myPaletteEditor->color( i, QPalette::Active ), + myPaletteEditor->color( i, QPalette::Inactive ), + myPaletteEditor->color( i, QPalette::Disabled )); + } + model->setAutoPalette( myPaletteEditor->isAuto() ); // internal + // font + model->setApplicationFont( myFontEdit->currentFont() ); + // lines type + model->setLinesType( (Style_Model::LineType)myLinesCombo->itemData( myLinesCombo->currentIndex() ).toInt() ); + // lines transparency + model->setLinesTransparency( myLinesTransparency->value() ); + // widgets rounding + model->setWidgetRounding( Style_Model::ButtonRadius, myButtonRound->value() ); + model->setWidgetRounding( Style_Model::EditRadius, myEditRound->value() ); + model->setWidgetRounding( Style_Model::FrameRadius, myFrameRound->value() ); + model->setWidgetRounding( Style_Model::SliderRadius, mySliderRound->value() ); + // widgets antialiasing + model->setAntialiasing( myAntiAliasing->isChecked() ); + // handle delta + model->setHandleDelta( Qt::Horizontal, myHorHandleDelta->value() ); + model->setHandleDelta( Qt::Vertical, myVerHandleDelta->value() ); + // splitter handle lentgh + model->setSplitHandleLength( mySplitterLength->value() ); + // slider size + model->setSliderSize( mySliderSize->value() ); + // widgets effect + if ( myEffectHighlight->isChecked() ) model->setWidgetEffect( Style_Model::HighlightEffect ); + else if ( myEffectAutoRaise->isChecked() ) model->setWidgetEffect( Style_Model::AutoRaiseEffect ); + else model->setWidgetEffect( Style_Model::NoEffect ); +} + +/*! + \brief Find unique name for the theme name + \param name theme name template + \param item if not 0, used to be ignored when browsing through items list + \param addSuffix if \c true, the integrer suffix is always added to the theme name (otherwise + suffix is added only if item name is not unique) + \return new unique theme name +*/ +QString Style_PrefDlg::findUniqueName( const QString& name, QListWidgetItem* item, bool addSuffix ) +{ + bool found = false; + int idx = 0; + for( int i = 2; i < myStylesList->count(); i++ ) { + if ( item == myStylesList->item( i ) ) continue; + QString iname = myStylesList->item( i )->text(); + if ( iname == name ) { + found = true; + } + else { + iname = iname.mid( name.length() ).trimmed(); + bool ok = false; + int nx = iname.toInt( &ok ); + if ( ok ) idx = qMax( idx, nx ); + } + } + return found || addSuffix ? QString( "%1 %2" ).arg( name ).arg( idx+1 ) : name; +} + +/*! + \brief Called when "Apply" button is pressed +*/ +void Style_PrefDlg::onApply() +{ + // save user schemas + resourceMgr()->save(); + // set selected schema as current + if ( myStylesList->currentRow() >= 0 ) { + Style_Model* model = Style_Salome::model(); + toModel( model ); + model->save(); + Style_Salome::update(); + if ( myStyleCheck->isChecked() ) + Style_Salome::apply(); + else + Style_Salome::restore(); + } +} + +/*! + \brief Called when "Help" button is pressed +*/ +void Style_PrefDlg::onHelp() +{ +} + +/*! + \brief Called when user selects any theme item in the themes list +*/ +void Style_PrefDlg::onStyleChanged() +{ + blockSignals( true ); + + QListWidgetItem* item = myStylesList->currentItem(); + int type = item->data( TypeRole ).toInt(); + + Style_Model* model = 0; + + switch ( type ) { + case Current: + // current style + model = Style_Salome::model(); + break; + case Default: + // default style + model = new Style_Model(); + break; + case Global: + case User: + // global style, user style + model = new Style_Model(); + model->fromResources( resourceMgr(), item->data( NameRole ).toString() ); + break; + default: + break; + } + + fromModel( model ); + if ( type != Current ) + delete model; + + onLinesType(); + + blockSignals( false ); +} + +/*! + \brief Called when lines type is changed +*/ +void Style_PrefDlg::onLinesType() +{ + myLinesTransparency->setEnabled( myLinesCombo->itemData( myLinesCombo->currentIndex() ) != Style_Model::NoLines ); + emit( styleChanged() ); +} + +/*! + \brief Called when any style parameter is changed by the user +*/ +void Style_PrefDlg::onChanged() +{ + QListWidgetItem* item = myStylesList->currentItem(); + int type = item->data( TypeRole ).toInt(); + + // for the current and user schemas do not perform any actions + if ( type == Current ) { + Style_Model model = *( Style_Salome::model() ); + toModel( &model ); + model.save(); + blockSignals( true ); + fromModel( &model ); + blockSignals( false ); + } + else if ( type == User ) { + Style_Model model; + toModel( &model ); + QString oldName = item->data( NameRole ).toString(), newName = item->text(); + if ( oldName == newName ) { + model.save( resourceMgr(), oldName ); + } + else { + resourceMgr()->remove( oldName ); + model.save( resourceMgr(), newName ); + item->setData( NameRole, newName ); + } + blockSignals( true ); + fromModel( &model ); + blockSignals( false ); + } + else { + // if user tries to change global (or default) schema, we create new user schema basing on selected one + QString newName = findUniqueName( tr( "Custom schema" ), 0, true ); + item = new QListWidgetItem( newName ); + item->setData( TypeRole, QVariant( User ) ); + item->setData( NameRole, QVariant( newName ) ); + item->setFlags( item->flags() | Qt::ItemIsEditable ); + myStylesList->addItem( item ); + + Style_Model model; + toModel( &model ); + model.save( resourceMgr(), newName ); + + myStylesList->setCurrentItem( item ); + } +} + +/*! + \brief Called when user theme is renamed by the user +*/ +void Style_PrefDlg::onItemChanged( QListWidgetItem* item ) +{ + QString newName = item->text(); + QString uniqueName = findUniqueName( newName, item ); + if ( uniqueName != newName ) { + myStylesList->blockSignals( true ); + item->setText( uniqueName ); + myStylesList->blockSignals( false ); + } +} + +/*! + \brief Called when widget effect is changed +*/ +void Style_PrefDlg::onEffectChanged( QAbstractButton* rb ) +{ + if ( rb != myCurrentEffect ) + emit( styleChanged() ); + myCurrentEffect = qobject_cast( rb ); +} diff --git a/src/Style/Style_PrefDlg.h b/src/Style/Style_PrefDlg.h new file mode 100644 index 000000000..73972665d --- /dev/null +++ b/src/Style/Style_PrefDlg.h @@ -0,0 +1,157 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Style_PrefDlg.h +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) +// + +#ifndef STYLE_PREFDLG_H +#define STYLE_PREFDLG_H + +#include "Style.h" + +#include +#include +#include + +class QCheckBox; +class QComboBox; +class QLabel; +class QListWidget; +class QListWidgetItem; +class QPushButton; +class QRadioButton; +class QSlider; +class QSpinBox; +class QTabWidget; +class QtxColorButton; +class QtxDoubleSpinBox; +class QtxFontEdit; +class Style_ResourceMgr; +class Style_Model; + +class STYLE_SALOME_EXPORT Style_PrefDlg : public QtxDialog +{ + Q_OBJECT + + class PaletteEditor; + enum { Current, Default, Global, User }; + enum { TypeRole = Qt::UserRole + 123, NameRole }; + +public: + Style_PrefDlg( QWidget* = 0 ); + ~Style_PrefDlg(); + + void accept(); + +private: + Style_ResourceMgr* resourceMgr(); + void fromModel( Style_Model* ); + void toModel( Style_Model* ) const; + + QString findUniqueName( const QString&, QListWidgetItem* = 0, bool = false ); + +signals: + void styleChanged(); + +private slots: + void onApply(); + void onHelp(); + + void onStyleChanged(); + void onLinesType(); + void onChanged(); + void onItemChanged( QListWidgetItem* ); + void onEffectChanged( QAbstractButton* ); + +private: + Style_ResourceMgr* myResMgr; + QCheckBox* myStyleCheck; + QListWidget* myStylesList; + QTabWidget* myStylesTab; + + PaletteEditor* myPaletteEditor; + QtxFontEdit* myFontEdit; + QComboBox* myLinesCombo; + QSlider* myLinesTransparency; + QtxDoubleSpinBox* myEditRound; + QtxDoubleSpinBox* myButtonRound; + QtxDoubleSpinBox* myFrameRound; + QtxDoubleSpinBox* mySliderRound; + QCheckBox* myAntiAliasing; + QSpinBox* myHorHandleDelta; + QSpinBox* myVerHandleDelta; + QSpinBox* mySplitterLength; + QSpinBox* mySliderSize; + QRadioButton* myEffectNone; + QRadioButton* myEffectHighlight; + QRadioButton* myEffectAutoRaise; + + QRadioButton* myCurrentEffect; +}; + +class Style_PrefDlg::PaletteEditor : public QFrame +{ + Q_OBJECT + +public: + PaletteEditor( QWidget* = 0 ); + ~PaletteEditor(); + + void addColumn( const QString& ); + void addItem( int ); + QList items() const; + + void setColor( int, QPalette::ColorGroup, const QColor& ); + void setColor( int, const QColor&, const QColor& = QColor(), const QColor& = QColor() ); + QColor color( int, QPalette::ColorGroup ) const; + + bool isAuto() const; + void setAuto( bool ); + + void fromColor( const QColor& ); + +private: + static QString idToName( int ); + QWidget* line(); + +private slots: + void onQuick(); + void onAuto(); + +signals: + void changed(); + +private: + typedef QMap Btns; + + QFrame* myContainer; + QPushButton* myQuickButton; + QCheckBox* myAutoCheck; + QLabel* myActiveLab; + QLabel* myInactiveLab; + QLabel* myDisabledLab; + + QMap myButtons; + int myCurrentRow; + int myCurrentColumn; + + friend class Style_PrefDlg; +}; + +#endif // STYLE_PREFDLG_H diff --git a/src/Style/Style_ResourceMgr.cxx b/src/Style/Style_ResourceMgr.cxx new file mode 100644 index 000000000..d1e692a31 --- /dev/null +++ b/src/Style/Style_ResourceMgr.cxx @@ -0,0 +1,101 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Style_ResourceMgr.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) +// + +#include "Style_ResourceMgr.h" + +/*! + \class Style_ResourceMgr + \brief SALOME style resources manager. + + This class is used to manage the SALOME style themes throughout the application + in the similar way as QtxResourceMgr does it with application preferences. + + Standard SALOME themes are stored in the global application settings files + (named as SalomeStyle.xml). User-defined themes are stored in user's home + directory - in the file .SalomeStylerc. + + The Style_ResourceMgr class is used by SALOME style preferences dialog box + (Style_PrefDlg class). +*/ + +/*! + \brief Constructor +*/ +Style_ResourceMgr::Style_ResourceMgr() + : QtxResourceMgr( "SalomeStyle", "%1Config" ) +{ + if ( dirList().isEmpty() && ::getenv( "GUI_ROOT_DIR" ) ) + setDirList( QStringList() << Qtx::addSlash( ::getenv( "GUI_ROOT_DIR" ) ) + "share/salome/resources/gui" ); + setCurrentFormat( "xml" ); +} + +/*! + \brief Destructor +*/ +Style_ResourceMgr::~Style_ResourceMgr() +{ +} + +/*! + \brief Get list of avaiable SALOME themes + \param type themes type + \param sort if \c true (default), returns a list of themes sorted by name + \return list of avaiable themes names +*/ +QStringList Style_ResourceMgr::styles( StyleType type, bool sort ) +{ + QStringList sl; + + WorkingMode m = workingMode(); + + switch ( type ) { + case Global: + setWorkingMode( IgnoreUserValues ); + sl = sections(); + break; + case User: + { + setWorkingMode( AllowUserValues ); + sl = sections(); + setWorkingMode( IgnoreUserValues ); + QMutableListIterator it( sl ); + while ( it.hasNext() ) { + QString s = it.next(); + if ( hasSection( s ) ) it.remove(); + } + } + break; + case All: + setWorkingMode( AllowUserValues ); + sl = sections(); + break; + default: + break; + } + + setWorkingMode( m ); + + if ( sort ) + qSort( sl ); + + return sl; +} diff --git a/src/Style/Style_ResourceMgr.h b/src/Style/Style_ResourceMgr.h new file mode 100644 index 000000000..29b34a542 --- /dev/null +++ b/src/Style/Style_ResourceMgr.h @@ -0,0 +1,48 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : Style_ResourceMgr.h +// Author : Vadim SANDLER, Open CASCADE S.A.S (vadim.sandler@opencascade.com) +// + +#ifndef STYLE_RESOURCEMGR_H +#define STYLE_RESOURCEMGR_H + +#include + +// +// This class is private for Style package. +// Normally it should not be exported. +// +class Style_ResourceMgr : public QtxResourceMgr +{ +public: + //! Style type + typedef enum { + Global, //!< Global styles + User, //!< User styles + All //!< All style + } StyleType; + + Style_ResourceMgr(); + ~Style_ResourceMgr(); + + QStringList styles( StyleType = All, bool = true ); +}; + +#endif // STYLE_RESOURCEMGR_H diff --git a/src/Style/Style_Salome.cxx b/src/Style/Style_Salome.cxx index 0755b5d6a..f2ab0aa41 100644 --- a/src/Style/Style_Salome.cxx +++ b/src/Style/Style_Salome.cxx @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -59,6 +58,7 @@ #include #include #include +#include #include @@ -165,56 +165,179 @@ static const char* const minimize_xpm[] = { /////////////////////////////////////////////////////////// // FOR debug purposes only!!! // -const int DEBUG_LEVEL = 0; +int DEBUG_LEVEL = 0; static bool checkDebugLevel( int level ) { - return DEBUG_LEVEL == level; + return DEBUG_LEVEL == level || DEBUG_LEVEL == -1; } // /////////////////////////////////////////////////////////// +Style_Model* Style_Salome::myModel = 0; + +/*! + \class Style_Salome + \brief SALOME style class. + + To set SALOME style to the application, use static function Style_Salome::apply(). + Static function restore() can be used then to restore initial application style. + + The usual way to use SALOME style is as following: + \code + Style_Salome::initialize( resourceMgr() ); // initialize SALOME style from resources + if ( needSalomeStyle ) Style_Salome::apply(); // set SALOME style to the application + \endcode + + Style_PrefDlg class can be then used to change style properties, select one of the + predefined style themes or even create user themes: + \code + Style_PrefDlg dlg( desktop() ); + dlg.exec(); + \endcode +*/ + +/*! + \brief Constructor + + Use Style_Salome::apply() static function to set SALOME style to the application. +*/ Style_Salome::Style_Salome() : QWindowsStyle() { - Q_INIT_RESOURCE(Style); + // initialize SALOME style resources + Q_INIT_RESOURCE( Style ); +} + +/*! + \brief Destructor +*/ +Style_Salome::~Style_Salome() +{ +} + + +/*! + \brief Initialize SALOME style. + + This method should be called at the very beginning of the application + which uses SALOME style. + The method initializes style properties from the current settings. - myModel = new Style_Model(); - myModel->setDefaults( qApp ); + If the parameter \a resMgr is not 0, the style is initialized from the + resources manager. - QPalette ttipPal = QToolTip::palette(); // from current system - myTTipWnd = ttipPal.color( QPalette::Window ); - myTTipText = ttipPal.color( QPalette::Text ); + The parameter \a section allows customizing of the resources file section + used to store style's properties. By default "Theme" section name is used. + + \param resMgr resources manager + \param section resources file section name + \sa apply(), restore() +*/ +void Style_Salome::initialize( QtxResourceMgr* resMgr, const QString& section ) +{ + model()->fromResources( resMgr, section ); } -Style_Salome::~Style_Salome() +/*! + \brief Set SALOME style to the application + \sa initialize(), restore() +*/ +void Style_Salome::apply() { + // application object is not created yet + if ( !QApplication::instance() ) + return; + + // update model (from the resources manager if needed) + model()->update(); + + // check if SALOME style is already set to the application + if ( !isActive() ) { + // set SALOME style + QApplication::style()->setParent( 0 ); // avoid deleting original application style + QApplication::setStyle( new Style_Salome() ); // set style + } + update(); // update style } -Style_Model* Style_Salome::getModel() const +/*! + \brief Restore original style to the application + \sa initialize(), apply() +*/ +void Style_Salome::restore() { - return myModel; + // application object is not created yet + if ( !QApplication::instance() ) + return; + // check if SALOME style is set to the application + if ( !isActive() ) + return; + // restore previous style + model()->restore(); } -void Style_Salome::updateSettings( QApplication* app ) +/*! + \brief Check if the SALOME style is currently set to application. + \return \c true if SALOME style is set to the applcation or \c false otherwise +*/ +bool Style_Salome::isActive() { - updatePaletteColors(); - QFont aFont = myModel->getFontValue( Style_Model::font_value ); - app->setFont( aFont ); - updateAllWidgets( app ); + return QApplication::instance() != 0 && qobject_cast( QApplication::style() ) != 0; +} + +/*! + \brief Update style from resources. +*/ +void Style_Salome::update() +{ + // application object is not created yet + if ( !QApplication::instance() ) + return; + // check if SALOME style is set to the application + if ( Style_Salome* style = qobject_cast( QApplication::style() ) ) + style->polish( qobject_cast( QApplication::instance() ) ); +} + +/*! + \brief Get style model + \return style model +*/ +Style_Model* Style_Salome::model() +{ + if ( !myModel ) + myModel = new Style_Model(); + return myModel; } +/*! + \brief Initialize the appearance of the application. + + Performs late initialization of the given application object. + + \param app application object +*/ void Style_Salome::polish ( QApplication* app ) { + QWindowsStyle::polish( app ); + if ( checkDebugLevel(1) ) { - QWindowsStyle::polish( app ); return; } - QWindowsStyle::polish( app ); - updateSettings( app ); + updatePaletteColors(); + app->setFont( model()->applicationFont() ); + updateAllWidgets( app ); } +/*! + \brief Initializes the appearance of the given widget. + + This function is called for every widget at some point after + it has been fully created but just before it is shown for the very first time. + + \param w widget object +*/ void Style_Salome::polish ( QWidget* w ) { if ( checkDebugLevel(2) ) { @@ -222,20 +345,29 @@ void Style_Salome::polish ( QWidget* w ) return; } - if ( !w ) - return; if ( w && hasHover() ) { - if ( qobject_cast(w) || qobject_cast(w) || - qobject_cast(w) || qobject_cast(w) || - qobject_cast(w) || qobject_cast(w) || - qobject_cast(w) || qobject_cast(w) || - qobject_cast(w) || qobject_cast(w) || - qobject_cast(w) || qobject_cast(w) ) + if ( qobject_cast(w) || qobject_cast(w) || + qobject_cast(w) || qobject_cast(w) || + qobject_cast(w) || qobject_cast(w) || + qobject_cast(w) || qobject_cast(w) || + qobject_cast(w) || qobject_cast(w) || + qobject_cast(w) || qobject_cast(w) ) w->setAttribute( Qt::WA_Hover ); } + QWindowsStyle::polish( w ); } +/*! + \brief Uninitialize the given widget's appearance. + + This function is the counterpart to polish(). + It is called for every polished widget whenever the style + is dynamically changed; the former style has to unpolish + its settings before the new style can polish them again. + + \param w widget object +*/ void Style_Salome::unpolish( QWidget* w ) { if ( checkDebugLevel(3) ) { @@ -252,9 +384,17 @@ void Style_Salome::unpolish( QWidget* w ) qobject_cast(w) || qobject_cast(w) ) w->setAttribute( Qt::WA_Hover, false ); } + QWindowsStyle::unpolish( w ); } +/*! + \brief Draws the given control using the provided painter \p with the style options specified by \a opt. + \param cc complex control type + \param opt style option + \param p painter + \param w widget +*/ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComplex* opt, QPainter* p, const QWidget* w ) const { @@ -270,17 +410,17 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver); QRect optr = opt->rect, arUp = subControlRect( cc, spin, SC_SpinBoxUp, w ); optr.setWidth( arUp.x()-optr.x()+1 ); - double aRad = getDblValue( Style_Model::edit_rad ); - bool antialized = getBoolValue( Style_Model::all_antialized ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + double aRad = model()->widgetRounding( Style_Model::EditRadius ); + bool antialized = model()->antialiasing(); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr if ( hover ) drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true); else Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left, - getColor( Style_Model::fld_light_clr ), - getColor( Style_Model::fld_dark_clr ), aBrdTopCol, - aBrdBotCol, antialized, false ); + model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr, + model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr, + aBrdTopCol, aBrdBotCol, antialized, false ); QRect aBtnRect = QRect( QPoint( arUp.x(), optr.y() ), QPoint( arUp.right(), optr.bottom() ) ); QColor aBtnCol = opt->palette.color( QPalette::Button ); bool aStateOn = opt->state & ( State_Sunken | State_On ); @@ -350,17 +490,17 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp optr.setY( ar.y() ); optr.setHeight( ar.height() ); optr.setWidth( ar.x()-optr.x()+1 ); - bool antialized = getBoolValue( Style_Model::all_antialized ); - double aRad = getDblValue( Style_Model::edit_rad ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + bool antialized = model()->antialiasing(); + double aRad = model()->widgetRounding( Style_Model::EditRadius ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr if ( hover ) drawHoverRect(p, optr, opt->palette.color( QPalette::Window ), aRad, Style_Tools::Left, true); else Style_Tools::shadowRect( p, optr, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::Left, - getColor( Style_Model::fld_light_clr ), - getColor( Style_Model::fld_dark_clr ), aBrdTopCol, - aBrdBotCol, antialized, false ); + model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr, + model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr, + aBrdTopCol, aBrdBotCol, antialized, false ); if (cmb->subControls & SC_ComboBoxArrow) { State flags = State_None; QColor aBtnCol = opt->palette.color( QPalette::Button ); @@ -405,7 +545,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp (slider->state & State_MouseOver) ) { QRect moderated = w->rect(); drawHoverRect(p, moderated, opt->palette.color( QPalette::Window ), - getDblValue( Style_Model::btn_rad ), Style_Tools::All, false); + model()->widgetRounding( Style_Model::ButtonRadius ), Style_Tools::All, false); } if ((slider->subControls & SC_SliderGroove) && groove.isValid()) { @@ -429,9 +569,9 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp bool horiz = slider->orientation == Qt::Horizontal; bool tickAbove = slider->tickPosition == QSlider::TicksAbove; bool tickBelow = slider->tickPosition == QSlider::TicksBelow; - QColor aBtnCol = getColor( Style_Model::slider_clr ), - aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBtnCol = model()->color( Style_Model::Slider ); // Style_Model::slider_clr + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr // rect was changed on +/-DELTA_SLIDER value for correct painting Antialised border of slider int aDelta = DELTA_SLIDER-1; QRect slRect = QRect(x+aDelta, y+aDelta, wi-aDelta, he-aDelta); @@ -459,7 +599,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp slRect.setRight( slRect.right()+aXAdd ); } } - Style_Tools::drawSlider( p, slRect, getDblValue( Style_Model::slider_rad ), type, + Style_Tools::drawSlider( p, slRect, model()->widgetRounding( Style_Model::SliderRadius ), type, aBtnCol.light( BUT_PERCENT_COL ), aBtnCol.dark( BUT_PERCENT_COL ), aBrdTopCol, aBrdBotCol ); QRect aHRect = handle; @@ -485,7 +625,7 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp QWindowsStyle::drawComplexControl( cc, opt, p, w ); return; } - int aMinDelta = (int)getDblValue( Style_Model::btn_rad ); + int aMinDelta = (int)model()->widgetRounding( Style_Model::ButtonRadius ); if ( !toolbutton->icon.isNull() ) aMinDelta = Style_Tools::getMinDelta( toolbutton->rect, toolbutton->iconSize, aMinDelta ); bool aStateOn = opt->state & ( State_Sunken | State_On ); @@ -493,12 +633,12 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp top = aBtnCol.light( BUT_PERCENT_COL ), bottom = aBtnCol.dark( BUT_PERCENT_COL ); bool isMenuBtn = toolbutton->features == QStyleOptionToolButton::Menu; - bool antialized = getBoolValue( Style_Model::all_antialized ); - bool isAutoRaising = getBoolValue( Style_Model::auto_raising_wdg ); - bool isHighWdg = getBoolValue( Style_Model::highlight_wdg ); + bool antialized = model()->antialiasing(); + bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect; + bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect; bool hover = hasHover() && (opt->state & State_Enabled) && ( opt->state & State_MouseOver ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr QRect aRect = button; int aType = isMenuBtn ? Style_Tools::Left : Style_Tools::All; if ( toolbutton->subControls & SC_ToolButton ) { @@ -575,13 +715,13 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp QRect checkBoxRect = subControlRect( cc, opt, SC_GroupBoxCheckBox, w); if (groupBox->subControls & QStyle::SC_GroupBoxFrame) { QRect aRect = subControlRect( cc, opt, SC_GroupBoxFrame, w); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); - Style_Tools::shadowRect( p, aRect, getDblValue( Style_Model::frame_rad ), 0., + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr + Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::FrameRadius ), 0., SHADOW, Style_Tools::All, - getColor( Style_Model::fld_light_clr ), - getColor( Style_Model::fld_dark_clr ), aBrdTopCol, - aBrdBotCol, false, false, false, false); + model()->color( Style_Model::FieldLight ), // Style_Model::fld_light_clr + model()->color( Style_Model::FieldDark ), // Style_Model::fld_dark_clr + aBrdTopCol, aBrdBotCol, false, false, false, false); } // Draw title if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) { @@ -622,6 +762,13 @@ void Style_Salome::drawComplexControl( ComplexControl cc, const QStyleOptionComp } } +/*! + \brief Draws the given element with the provided painter \p with the style options specified by \a opt. + \param ce control element type + \param opt style option + \param p painter + \param w widget +*/ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QPainter* p, const QWidget* w ) const { @@ -639,27 +786,27 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, drawControl(CE_PushButtonLabel, &subopt, p, w); if (btn->state & State_HasFocus) { QRect aRect = subElementRect( SE_PushButtonFocusRect, btn, w ); - Style_Tools::drawFocus( p, aRect, getDblValue(Style_Model:: btn_rad ), - Style_Tools::All, getColor( Style_Model::border_bot_clr ) ); + Style_Tools::drawFocus( p, aRect, model()->widgetRounding( Style_Model::ButtonRadius ), + Style_Tools::All, model()->color( Style_Model::BorderBottom ) ); } break; } case CE_PushButtonBevel: if ( qstyleoption_cast(opt) ) { - double aRad = getDblValue( Style_Model::btn_rad ); + double aRad = model()->widgetRounding( Style_Model::ButtonRadius ); bool aStateOn = opt->state & ( State_Sunken | State_On ); - bool isAutoRaising = getBoolValue( Style_Model::auto_raising_wdg ); - bool isHighWdg = getBoolValue( Style_Model::highlight_wdg ); + bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect; + bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect; bool enabled = opt->state & State_Enabled; bool hover = hasHover() && enabled && ( opt->state & State_MouseOver ); QColor aBtnCol = opt->palette.color( QPalette::Button ); QColor top = aBtnCol.light( BUT_PERCENT_COL ), bottom = aBtnCol.dark( BUT_PERCENT_COL ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr QRect r = opt->rect; - bool antialized = getBoolValue( Style_Model::all_antialized ); + bool antialized = model()->antialiasing(); if ( isAutoRaising && hover && !aStateOn ) Style_Tools::shadowRect( p, r, aRad, -1, SHADOW, Style_Tools::All, bottom, top, aBrdTopCol, aBrdBotCol, antialized, true, aStateOn ); @@ -706,8 +853,8 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, gr.setColorAt( 1.0, top ); p->fillRect( r, gr ); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr p->setPen( aBrdTopCol ); p->drawLine( r.x(), r.bottom(), r.x(), r.y() ); p->drawLine( r.x(), r.y(), r.right(), r.y() ); @@ -752,7 +899,7 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QWindowsStyle::drawControl( ce, opt, p, w ); QRect r = opt->rect; bool horiz = r.width() > r.height(); - int aLen = (int)getDblValue( Style_Model::split_handle_len ); + int aLen = model()->splitHandleLength(); if ( horiz ) r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height()); else @@ -772,18 +919,17 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, tab->position == QStyleOptionTab::OnlyOneTab; QColor aColor = opt->palette.color( QPalette::Window ), aDarkColor = aColor.dark( BUT_PERCENT_ON ); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver); - if ( isHover && !isSelected && !getBoolValue( Style_Model::auto_raising_wdg ) && - getBoolValue( Style_Model::highlight_wdg) ) { - aColor = getColor( Style_Model::high_wdg_clr ); - aDarkColor = getColor( Style_Model::high_brd_wdg_clr ); + if ( isHover && !isSelected && model()->widgetEffect() == Style_Model::HighlightEffect ) { + aColor = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr + aDarkColor = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr } Style_Tools::tabRect( p, tabRect, (int)tab->shape, - getDblValue( Style_Model::frame_rad ), + model()->widgetRounding( Style_Model::FrameRadius ), DELTA_H_TAB, aColor, aDarkColor, aBrdTopCol, aBrdBotCol, isSelected, isLast, isHover ); p->restore(); @@ -830,17 +976,16 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QColor aBtnCol = opt->palette.color( QPalette::Window ), top = aBtnCol.light( BUT_PERCENT_ON ), bottom = aBtnCol.dark( BUT_PERCENT_ON ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); - bool aHighWdg = hasHover() && !getBoolValue( Style_Model::auto_raising_wdg ) && - getBoolValue( Style_Model::highlight_wdg ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr + bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect; if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) && (opt->state & State_Selected) ) drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true); else { Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol, - getBoolValue( Style_Model::all_antialized ), true, aStateOn ); + model()->antialiasing(), true, aStateOn ); } } if (active && down) { @@ -859,11 +1004,11 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QColor aBgColor = opt->palette.color( QPalette::Window ), top = aBgColor.light( BUT_PERCENT_ON ), bottom = aBgColor.dark( BUT_PERCENT_ON ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); - Style_Tools::shadowRect( p, opt->rect, getDblValue( Style_Model::edit_rad ), -1, + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr + Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::EditRadius ), -1, SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol, - getBoolValue( Style_Model::all_antialized ), true ); + model()->antialiasing(), true ); break; } case CE_ProgressBarLabel: @@ -1003,9 +1148,9 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, int myHeight = pbBits.rect.height(); pbBits.state = State_None; QRect aRect; - QColor aColor = getColor( Style_Model::prbar_clr ), - top = aColor.light( BUT_PERCENT_COL ), - bottom = aColor.dark( BUT_PERCENT_COL ); + QColor aColor = model()->color( Style_Model::ProgressBar ); // Style_Model::prbar_clr + QColor top = aColor.light( BUT_PERCENT_COL ); + QColor bottom = aColor.dark( BUT_PERCENT_COL ); int aType; for (int i = 0; i <= nu; ++i) { aType = Style_Tools::None; @@ -1048,7 +1193,7 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, aTopClr = aColor.light(); aBotClr = aColor.dark(); } - Style_Tools::shadowRect( p, aRect, getDblValue( Style_Model::edit_rad ), -1, 0, + Style_Tools::shadowRect( p, aRect, model()->widgetRounding( Style_Model::EditRadius ), -1, 0, aType, top, bottom, aTopClr, aBotClr, false, true ); x += reverse ? -unit_width : unit_width; } @@ -1077,8 +1222,8 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, double aMargin = LINE_GR_MARGIN; QLinearGradient gr(x,y,menuitem->rect.right(),y); gr.setColorAt( 0.0, aBgColor ); - gr.setColorAt( aMargin/width, getColor( Style_Model::fld_light_clr ) ); - gr.setColorAt( 1.0, getColor( Style_Model::fld_light_clr ) ); + gr.setColorAt( aMargin/width, model()->color( Style_Model::FieldLight ) ); // Style_Model::fld_light_clr + gr.setColorAt( 1.0, model()->color( Style_Model::FieldLight ) ); QBrush fill; if ( act ) fill = menuitem->palette.brush( QPalette::Highlight ); @@ -1087,8 +1232,8 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, p->fillRect(menuitem->rect, fill); if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){ int yoff = y-1 + h / 2; - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr p->setPen( aBrdBotCol ); p->drawLine(x + 2, yoff, x + width - 4, yoff); p->setPen( aBrdTopCol ); @@ -1210,13 +1355,13 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, */ case CE_HeaderSection: { bool aStateOn = opt->state & State_On; - QColor aColor = getColor( Style_Model::header_clr ); + QColor aColor = model()->color( Style_Model::Header ); // Style_Model::header_clr QColor top = aColor.light( BUT_PERCENT_COL ), bottom = aColor.dark( BUT_PERCENT_COL ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol, - aBrdBotCol, getBoolValue( Style_Model::all_antialized ), true, aStateOn ); + aBrdBotCol, model()->antialiasing(), true, aStateOn ); break; } case CE_ComboBoxLabel: @@ -1233,7 +1378,7 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QRect alignRect = editRect; if ( cb->editable ) { int aHalfRect = (int)Style_Tools::getMaxRect( iconRect, - (int)getDblValue( Style_Model::edit_rad )/2 ); + (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); alignRect.setLeft( alignRect.left() + aHalfRect ); alignRect.setRight( alignRect.right() - aHalfRect ); } @@ -1262,8 +1407,8 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, QColor aBtnCol = opt->palette.color( QPalette::Button ); QColor top = aBtnCol.light( BUT_PERCENT_COL ), bottom = aBtnCol.dark( BUT_PERCENT_COL ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr Style_Tools::shadowRect( p, opt->rect, 0, -1, 0, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol, false, true, aStateOn, true ); PrimitiveElement arrow; @@ -1287,17 +1432,17 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, p->setRenderHint( QPainter::Antialiasing, true ); bool enabled = opt->state & State_Enabled; bool horiz = scrollbar->orientation == Qt::Horizontal; - double aRad = getDblValue( Style_Model::btn_rad ); + double aRad = model()->widgetRounding( Style_Model::ButtonRadius ); if ( hasHover() && enabled && (opt->state & State_MouseOver) ) drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, false); else { - QColor aColor = getColor( Style_Model::slider_clr ); + QColor aColor = model()->color( Style_Model::Slider ); // Style_Model::slider_clr if ( !enabled ) aColor = opt->palette.button().color(); QColor top = aColor.light( BUT_PERCENT_ON ), bottom = aColor.dark( BUT_PERCENT_ON ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr QRect r = opt->rect; QPainterPath path = Style_Tools::roundRect( r, aRad, Style_Tools::All ); @@ -1346,6 +1491,13 @@ void Style_Salome::drawControl( ControlElement ce, const QStyleOption* opt, } } +/*! + \brief Draws the given primitive element with the provided painter \p using the style options specified by \a opt. + \param pe primitive type + \param opt style option + \param p painter + \param w widget (optional) +*/ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, QPainter* p, const QWidget* w ) const { @@ -1362,8 +1514,8 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, QColor aBtnCol = opt->palette.color( QPalette::Window ), top = aBtnCol.light( BUT_PERCENT_ON ), bottom = aBtnCol.dark( BUT_PERCENT_ON ); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr Style_Tools::shadowRect( p, opt->rect, 0, 0., SHADOW, Style_Tools::All, top, bottom, aBrdTopCol, aBrdBotCol, false, false, false, false ); break; @@ -1374,19 +1526,18 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, ( w->inherits("QDockWidgetTitleButton") ) || ( w->inherits("QtxWorkstackAreaTitleButton") ) ) ) { bool aStateOn = opt->state & (State_Sunken | State_On); - bool aHighWdg = hasHover() && !getBoolValue( Style_Model::auto_raising_wdg ) && - getBoolValue( Style_Model::highlight_wdg ); + bool aHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect; if ( !aStateOn && aHighWdg && (opt->state & State_Enabled) && (opt->state & State_MouseOver) ) drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, true); else { QColor aBtnCol = opt->palette.color( QPalette::Window ); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr QColor top = aBtnCol.light( BUT_PERCENT_COL ), bottom = aBtnCol.dark( BUT_PERCENT_COL ); Style_Tools::shadowRect( p, opt->rect, 0.0, 0, SHADOW, Style_Tools::All, top, bottom, - aBrdTopCol, aBrdBotCol, getBoolValue( Style_Model::all_antialized ), true, aStateOn ); + aBrdTopCol, aBrdBotCol, model()->antialiasing(), true, aStateOn ); } break; } @@ -1397,13 +1548,13 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, case PE_FrameFocusRect: { if (w && qobject_cast((QWidget*)w)) { QTabBar* tabBar = qobject_cast((QWidget*)w); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver); Style_Tools::tabRect( p, opt->rect, (int)tabBar->shape(), - getDblValue( Style_Model::frame_rad ), DELTA_H_TAB, + model()->widgetRounding( Style_Model::FrameRadius ), DELTA_H_TAB, pal.color( QPalette::Window ), - getColor( Style_Model::border_bot_clr ), + model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr aBrdTopCol, aBrdBotCol, false, false, isHover, true ); } else { @@ -1422,7 +1573,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, QRect rect = opt->rect; QColor pen, brush; if ( opt->state & State_Enabled ) { - pen = getColor( Style_Model::pointer_clr ); + pen = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr brush = opt->palette.color( QPalette::Button ); if ( ( opt->state & State_Sunken ) && (opt->state & State_Enabled ) ) rect.moveTo( rect.x()+1, rect.y()+1 ); @@ -1438,7 +1589,8 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, } case PE_IndicatorCheckBox: { if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) ) - drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), getDblValue( Style_Model::edit_rad ), + drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), + model()->widgetRounding( Style_Model::EditRadius ), Style_Tools::All, false); QBrush fill; if (opt->state & State_NoChange) @@ -1447,7 +1599,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, fill = opt->palette.color( QPalette::Window ); else if (opt->state & State_Enabled) { if (!(opt->state & State_Off) ) - fill = QBrush( getColor( Style_Model::checked_clr ) ); + fill = QBrush( model()->color( Style_Model::Checked ) ); // Style_Model::checked_clr else fill = QBrush( opt->palette.color( QPalette::Base ) ); } @@ -1456,9 +1608,9 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, p->save(); doRestore = true; QColor color = fill.color(); - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); - if ( getBoolValue( Style_Model::all_antialized ) ) + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr + if ( model()->antialiasing() ) p->setRenderHint( QPainter::Antialiasing, true ); // make sure the indicator is square @@ -1473,7 +1625,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, Style_Tools::shadowCheck( p, ir, 2., Style_Tools::All, color, color.dark( BUT_PERCENT_ON ), aBrdTopCol, aBrdBotCol ); - if ( getBoolValue( Style_Model::all_antialized ) ) + if ( model()->antialiasing() ) p->setRenderHint( QPainter::Antialiasing, false ); if (opt->state & State_NoChange) p->setPen(opt->palette.dark().color()); @@ -1509,7 +1661,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, ++xx; --yy; } - QColor aColor = getColor( Style_Model::pointer_clr ); + QColor aColor = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr if ( !(opt->state & State_Enabled ) ) aColor = opt->palette.mid().color(); if ( opt->state & State_Selected && itemViewOpt && itemViewOpt->showDecorationSelected ) @@ -1525,7 +1677,8 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, } case PE_IndicatorRadioButton: { if ( hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver) ) - drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), getDblValue( Style_Model::btn_rad ), + drawHoverRect(p, w->rect(), opt->palette.color( QPalette::Window ), + model()->widgetRounding( Style_Model::ButtonRadius ), Style_Tools::All, false); #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint)) static const QPoint pts_border[] = { // border line @@ -1558,7 +1711,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, else { QColor fillColor = opt->palette.color( QPalette::Base ); if ( enabled && on ) - fillColor = getColor( Style_Model::checked_clr ); + fillColor = model()->color( Style_Model::Checked ); // Style_Model::checked_clr QLinearGradient gr( 3, 3, 8, 8 ); gr.setColorAt( 0.0, fillColor.dark( BUT_PERCENT_ON ) ); gr.setColorAt( 1.0, fillColor ); @@ -1568,21 +1721,20 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, p->drawPolygon(pts_border, PTSARRLEN(pts_border)); int aSize = PTSARRLEN(pts_border), aHalfSize = (int)aSize/2; - if ( getBoolValue( Style_Model::all_antialized ) ) + if ( model()->antialiasing() ) p->setRenderHint( QPainter::Antialiasing, true ); - p->setPen( getColor( Style_Model::border_top_clr ) ); + p->setPen( model()->color( Style_Model::BorderTop) ); // Style_Model::border_top_clr p->drawPolyline(pts_border, aHalfSize); - - p->setPen( getColor( Style_Model::border_bot_clr ) ); + p->setPen( model()->color( Style_Model::BorderBottom ) ); // Style_Model::border_bot_clr QPolygon aPolygon; for ( int i = aHalfSize; i < aSize; i++ ) aPolygon << pts_border[i]; p->drawPolyline( aPolygon ); - if ( getBoolValue( Style_Model::all_antialized ) ) + if ( model()->antialiasing() ) p->setRenderHint( QPainter::Antialiasing, false ); if (on) { - QColor aPointerCol = getColor( Style_Model::pointer_clr ); + QColor aPointerCol = model()->color( Style_Model::Pointer ); // Style_Model::pointer_clr if ( !enabled ) aPointerCol = opt->palette.mid().color(); p->setPen( Qt::NoPen ); @@ -1607,17 +1759,17 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, break; } if ( pe == PE_FrameLineEdit ) { - QColor aBrdTopCol = getColor( Style_Model::border_top_clr ), - aBrdBotCol = getColor( Style_Model::border_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::BorderTop ); // Style_Model::border_top_clr + QColor aBrdBotCol = model()->color( Style_Model::BorderBottom ); // Style_Model::border_bot_clr bool hover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver); - double aRad = getDblValue(Style_Model::edit_rad); + double aRad = model()->widgetRounding( Style_Model::EditRadius ); if ( hover ) drawHoverRect(p, opt->rect, opt->palette.color( QPalette::Window ), aRad, Style_Tools::All, true); else { Style_Tools::shadowRect( p, opt->rect, aRad, LINE_GR_MARGIN, SHADOW, Style_Tools::All, opt->palette.color( QPalette::Base ), // getColor( Style_Model::fld_light_clr ), - getColor( Style_Model::fld_dark_clr ), aBrdTopCol, aBrdBotCol, - getBoolValue( Style_Model::all_antialized ), false ); + model()->color( Style_Model::FieldDark ), aBrdTopCol, aBrdBotCol, + model()->antialiasing(), false ); } } else { @@ -1646,11 +1798,11 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, aRoundType = aRoundType | Style_Tools::BottomLeft; if ( aTabPos != QTabWidget::East ) aRoundType = aRoundType | Style_Tools::TopRight; - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); - Style_Tools::shadowRect( p, opt->rect, getDblValue( Style_Model::frame_rad ), + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr + Style_Tools::shadowRect( p, opt->rect, model()->widgetRounding( Style_Model::FrameRadius ), 0., SHADOW, aRoundType, - getColor( Style_Model::fld_light_clr ), + model()->color( Style_Model::FieldLight ), opt->palette.color( QPalette::Dark ), aBrdTopCol, aBrdBotCol, false, false, false, false ); break; @@ -1696,12 +1848,13 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, if ( tabBar ) isLast = tabBar->currentIndex() == tabBar->count() -1; QColor aColor = opt->palette.color( QPalette::Window ); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr bool isHover = hasHover() && (opt->state & State_Enabled) && (opt->state & State_MouseOver); QPainterPath aSelPath = Style_Tools::tabRect( p, aSelRect, (int)tbb->shape, - getDblValue( Style_Model::frame_rad ), DELTA_H_TAB, aColor, aColor, + model()->widgetRounding( Style_Model::FrameRadius ), + DELTA_H_TAB, aColor, aColor, aColor, aColor, isSelected, isLast, isHover, false, false ); if ( !aSelPath.isEmpty() ) aSelRect = aSelPath.controlPointRect().toRect(); @@ -1753,7 +1906,7 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, if ( hover ) drawHoverRect(p, r, opt->palette.color( QPalette::Window ), 0, Style_Tools::All, false); bool horiz = r.width() > r.height(); - int aLen = (int)getDblValue( Style_Model::split_handle_len ); + int aLen = model()->splitHandleLength(); if ( horiz ) r = QRect( r.x() +(int)((r.width()-aLen)/2), r.y(), aLen, r.height()); else @@ -1776,10 +1929,10 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, } QPalette aPal = aWdg->palette(); double aMarg = LINE_GR_MARGIN; - QColor base = getColor( Style_Model::pal_base_clr ), - light = base, - light_alt = base.dark(110),//AlternateBase color - dark = getColor( Style_Model::fld_dark_clr ); + QColor base = model()->color( Style_Model::Base ), // Style_Model::pal_base_clr + light = base, + light_alt = base.dark(110),//AlternateBase color + dark = model()->color( Style_Model::FieldDark ); // Style_Model::fld_dark_clr light.setAlpha( 0 ); // VSR commented: IPAL19262 QLinearGradient gr_h(r.x(), r.y(), r.right(), r.y()); gr_h.setColorAt( 0.0, dark ); @@ -1810,8 +1963,15 @@ void Style_Salome::drawPrimitive( PrimitiveElement pe, const QStyleOption* opt, } } +/*! + \brief Returns the value of the given pixel \a metric. + \param metric metric type + \param opt style option + \param w widget + \return metric value +*/ int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt, - const QWidget* w ) const + const QWidget* w ) const { if ( checkDebugLevel(7) ) { return QWindowsStyle::pixelMetric( metric, opt, w ); @@ -1820,7 +1980,7 @@ int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt, int aRes = QWindowsStyle::pixelMetric( metric, opt, w ); switch( metric ) { case PM_SliderLength: { - aRes += (int)(getIntValue( Style_Model::slider_increase )/2); + aRes += (int)((double)model()->sliderSize()/2); break; } case PM_DockWidgetFrameWidth: @@ -1841,6 +2001,15 @@ int Style_Salome::pixelMetric( PixelMetric metric, const QStyleOption* opt, return aRes; } +/*! + \brief Returns the size of the element described by the specified option \a opt + and type \a ct, based on the provided \a contentsSize. + \param ct contents type + \param opt style option + \param contentsSize contents size + \param w widget (optional) + \return size of the element +*/ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, const QSize& contentsSize, const QWidget* w ) const { @@ -1867,7 +2036,7 @@ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, } break; case CT_Slider: { - int aValue = getIntValue( Style_Model::slider_increase ); + int aValue = model()->sliderSize(); sz.setWidth( sz.width() + aValue ); sz.setHeight( sz.height() + aValue ); break; @@ -1876,7 +2045,7 @@ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, if (const QStyleOptionComboBox *cmb = qstyleoption_cast(opt)) { QRect res = QRect( 0, 0, sz.width(), sz.height() ); int aHalfRect = (int)Style_Tools::getMaxRect( res, - (int)getDblValue( Style_Model::edit_rad )/2 ); // left value + (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); // left value QRect old_arrow = QWindowsStyle::subControlRect( CC_ComboBox, cmb, SC_ComboBoxArrow, w ); int aDelta = res.height() - old_arrow.width(); // right value @@ -1891,6 +2060,13 @@ QSize Style_Salome::sizeFromContents( ContentsType ct, const QStyleOption* opt, return sz; } +/*! + \brief Returns a pixmap for the given \a standardPixmap. + \param stPixmap standard pixmap type + \param opt style option + \param w widget (optional) + \return standard pixmap +*/ QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption *opt, const QWidget *w) const { @@ -1914,12 +2090,19 @@ QPixmap Style_Salome::standardPixmap(StandardPixmap stPixmap, const QStyleOption } } +/*! + \brief Returns an icon for the given \a standardIcon. + \param standardIcon standard icon type + \param opt style option + \param w widget (optional) + \return standard icon +*/ QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, const QStyleOption* opt, - const QWidget* widget ) const + const QWidget* w ) const { if ( checkDebugLevel(10) ) { - return QWindowsStyle::standardIconImplementation( standardIcon, opt, widget ); + return QWindowsStyle::standardIconImplementation( standardIcon, opt, w ); } switch ( standardIcon ) @@ -1935,21 +2118,30 @@ QIcon Style_Salome::standardIconImplementation( StandardPixmap standardIcon, default: break; } - return QWindowsStyle::standardIconImplementation( standardIcon, opt, widget ); + return QWindowsStyle::standardIconImplementation( standardIcon, opt, w ); } -int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* widget, +/*! + \brief Returns an integer representing the specified style \a hint for the + given widget \a w described by the provided style option \a opt. + \param hint hint type + \param opt style option + \param w widget (optional) + \param returnData (currently not used) + \return style hint value +*/ +int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWidget* w, QStyleHintReturn* returnData ) const { if ( checkDebugLevel(11) ) { - return QWindowsStyle::styleHint( hint, opt, widget, returnData ); + return QWindowsStyle::styleHint( hint, opt, w, returnData ); } - int aRes = QWindowsStyle::styleHint( hint, opt, widget, returnData ); + int aRes = QWindowsStyle::styleHint( hint, opt, w, returnData ); switch( hint ) { case SH_Table_GridLineColor: { if ( opt ) - aRes = getColor( Style_Model::tbl_grline_clr ).rgb(); + aRes = model()->color( Style_Model::GridLine ).rgb(); // Style_Model::tbl_grline_clr else return aRes; break; @@ -1960,6 +2152,16 @@ int Style_Salome::styleHint( StyleHint hint, const QStyleOption* opt, const QWid return aRes; } +/*! + \brief Get the rectangle containing the specified subcontrol \a sc of the given + complex control \a cc (with the style specified by option \a opt). + The rectangle is defined in screen coordinates. + \param cc complex control type + \param opt style option + \param sc subcontrol type + \param wid widget (optional) + \return subcontrol rectangle +*/ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex* opt, SubControl sc, const QWidget* wid ) const { @@ -1986,7 +2188,7 @@ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex case CC_ComboBox: { if (const QStyleOptionComboBox *cb = qstyleoption_cast(opt)) { res = cb->rect; - int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)getDblValue( Style_Model::edit_rad )/2 ); + int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); int x = res.x(), w = res.width(), h = res.height(); switch( sc ) { case SC_ComboBoxEditField: { @@ -2009,7 +2211,7 @@ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex case CC_ScrollBar: if (const QStyleOptionSlider *scrollbar = qstyleoption_cast(opt)) { QRect slider_r = QWindowsStyle::subControlRect( cc, opt, SC_ScrollBarSlider, wid ); - int aRect = Style_Tools::getMaxRect( slider_r, (int)getDblValue( Style_Model::btn_rad ) ); + int aRect = Style_Tools::getMaxRect( slider_r, (int)model()->widgetRounding( Style_Model::ButtonRadius ) ); switch( sc ) { case SC_ScrollBarSubPage: // between top/left button and slider if (scrollbar->orientation == Qt::Horizontal) @@ -2049,6 +2251,15 @@ QRect Style_Salome::subControlRect( ComplexControl cc, const QStyleOptionComplex return res; } +/*! + \brief Returns the sub-area for the given element \a se as described + in the provided style option \a opt. + The returned rectangle is defined in screen coordinates. + \param se subelement type + \param opt style option + \param wid widget (optional) + \return subelement rectangle +*/ QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt, const QWidget* wid ) const { @@ -2057,7 +2268,7 @@ QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt, } QRect res = QWindowsStyle::subElementRect( se, opt, wid ); - int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)getDblValue( Style_Model::edit_rad )/2 ); + int aHalfRect = (int)Style_Tools::getMaxRect( res, (int)model()->widgetRounding( Style_Model::EditRadius )/2 ); int w = res.width(), h = res.height(); switch ( se ) { case SE_ComboBoxFocusRect: { @@ -2086,89 +2297,33 @@ QRect Style_Salome::subElementRect( SubElement se, const QStyleOption* opt, return res; } +/*! + \brief Update palette colors from style model +*/ void Style_Salome::updatePaletteColors() { - QPalette aPal = QApplication::palette(); - aPal.setColor( QPalette::WindowText, getColor( Style_Model::pal_wtext_clr ) ); - aPal.setColor( QPalette::Button, getColor( Style_Model::button_clr ) ); - aPal.setColor( QPalette::Light, getColor( Style_Model::pal_light_clr ) ); - aPal.setColor( QPalette::Midlight, getColor( Style_Model::pal_light_clr ).light(115) ); - aPal.setColor( QPalette::Dark, getColor( Style_Model::pal_dark_clr ) ); - aPal.setColor( QPalette::Mid, aPal.color( QPalette::Active, QPalette::Button ).dark(150) ); - aPal.setColor( QPalette::Text, getColor( Style_Model::pal_text_clr ) ); - //aPal.setColor( QPalette::BrightText, ??? ); - aPal.setColor( QPalette::ButtonText, getColor( Style_Model::pal_btext_clr ) ); - aPal.setColor( QPalette::Base, getColor( Style_Model::pal_base_clr ) ); - aPal.setColor( QPalette::AlternateBase, getColor( Style_Model::pal_base_clr ).dark( 110 ) ); - aPal.setColor( QPalette::Window, getColor( Style_Model::bg_clr ) ); - //aPal.setColor( QPalette::Shadow, ??? ); - QColor hc = getColor( Style_Model::pal_high_clr ); - hc.setAlpha(100); - aPal.setColor( QPalette::Highlight, hc ); - aPal.setColor( QPalette::HighlightedText, getColor( Style_Model::pal_high_text_clr ) ); - //aPal.setColor( QPalette::Link, ??? ); - //aPal.setColor( QPalette::LinkVisited, ??? ); - - // dependant colors - if (aPal.midlight() == aPal.button()) - aPal.setColor(QPalette::Inactive, QPalette::Midlight, aPal.color(QPalette::Active, QPalette::Button).light(110)); - if (aPal.window() != aPal.base()) { - QColor hc1 = aPal.color(QPalette::Inactive, QPalette::Window); - hc1.setAlpha(100); - aPal.setColor(QPalette::Inactive, QPalette::Highlight, hc1); - aPal.setColor(QPalette::Inactive, QPalette::HighlightedText, aPal.color(QPalette::Inactive, QPalette::Text)); - } - - const QColor bg = aPal.window().color(); - const QColor fg = aPal.windowText().color(); - const QColor btn = aPal.button().color(); - - QColor disabled((fg.red()+btn.red())/2,(fg.green()+btn.green())/2, - (fg.blue()+btn.blue())/2); - - aPal.setColor(QPalette::Disabled, QPalette::WindowText, disabled); - aPal.setColor(QPalette::Disabled, QPalette::Text, disabled); - aPal.setColor(QPalette::Disabled, QPalette::ButtonText, disabled); - aPal.setColor(QPalette::Disabled, QPalette::Base, bg); - - QApplication::setPalette( aPal ); - - QColor aWndCol = myTTipWnd, - aTextCol = myTTipText; - if( getBoolValue( Style_Model::ttip_is_change ) ) { - if ( getColor( Style_Model::ttip_bg_clr ).isValid() ) - aWndCol = getColor( Style_Model::ttip_bg_clr ); - if ( getColor( Style_Model::ttip_text_clr ).isValid() ) - aTextCol = getColor( Style_Model::ttip_text_clr ); - } - QPalette tiplabel = QToolTip::palette(); - bool isChangeWnd = aWndCol != tiplabel.color( QPalette::Window ), - isChangeTxt = aTextCol != tiplabel.color( QPalette::Text ); - if ( isChangeWnd || isChangeTxt ) { - if ( isChangeWnd ) { - tiplabel.setColor(QPalette::Window, aWndCol); - tiplabel.setColor(QPalette::Button, aWndCol); + QPalette pal = QApplication::palette(); + // colors + for ( int i = (int)QPalette::Active; i <= (int)QPalette::Inactive; i++ ) { + for ( int j = (int)Style_Model::WindowText; j < (int)Style_Model::NColorRoles; j++ ) { + if ( j == QPalette::NoRole ) continue; + pal.setColor( (QPalette::ColorGroup)i, (QPalette::ColorRole)j, + model()->color( (Style_Model::ColorRole)j, (QPalette::ColorGroup)i ) ); } - if ( isChangeTxt ) { - tiplabel.setColor(QPalette::Text, aTextCol); - tiplabel.setColor(QPalette::WindowText, aTextCol); - tiplabel.setColor(QPalette::ButtonText, aTextCol); - } - const QColor fg = tiplabel.foreground().color(), btn = tiplabel.button().color(); - QColor disabled((fg.red()+btn.red())/2,(fg.green()+btn.green())/2, - (fg.blue()+btn.blue())/2); - tiplabel.setColor(QPalette::Disabled, QPalette::WindowText, disabled); - tiplabel.setColor(QPalette::Disabled, QPalette::Text, disabled); - tiplabel.setColor(QPalette::Disabled, QPalette::Base, Qt::white); - tiplabel.setColor(QPalette::Disabled, QPalette::BrightText, Qt::white); - QToolTip::setPalette(tiplabel); } + QPixmapCache::clear(); + QApplication::setPalette( pal ); } +/*! + \brief Update all widgets with the current style properties. + \param app application object +*/ void Style_Salome::updateAllWidgets( QApplication* app ) { if ( !app ) return; + QWidgetList all = app->allWidgets(); QWidget* w; for (QWidgetList::ConstIterator it2 = all.constBegin(); it2 != all.constEnd(); ++it2) { @@ -2183,20 +2338,32 @@ void Style_Salome::updateAllWidgets( QApplication* app ) } } +/*! + \brief Check if any widget effect is currently used + \return \c true if any widget effect is currently used +*/ bool Style_Salome::hasHover() const { - return getBoolValue( Style_Model::auto_raising_wdg ) || - getBoolValue( Style_Model::highlight_wdg ); + return model()->widgetEffect() != Style_Model::NoEffect; } +/*! + \brief Draw rectangle for the hovered widget + \param p painter + \param r rectangle + \param bgCol background color + \param rad corners rounding radius + \param type shadow type + \param border if \c true border is colored with specific color +*/ void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgCol, const double rad, const int type, const bool border ) const { if ( !hasHover() ) return; - bool isAutoRaising = getBoolValue( Style_Model::auto_raising_wdg ); - bool isHighWdg = getBoolValue( Style_Model::highlight_wdg ); - QColor aBorder = getColor( Style_Model::border_bot_clr ), + bool isAutoRaising = model()->widgetEffect() == Style_Model::AutoRaiseEffect; + bool isHighWdg = model()->widgetEffect() == Style_Model::HighlightEffect; + QColor aBorder = model()->color( Style_Model::BorderTop ), // Style_Model::border_bot_clr aCol, aBrdCol; double aMargin = HIGH_WDG_MARGIN; if ( isAutoRaising ) { @@ -2207,20 +2374,27 @@ void Style_Salome::drawHoverRect( QPainter* p, const QRect& r, const QColor& bgC aMargin = 0; } else if ( isHighWdg ) { - aCol = getColor( Style_Model::high_wdg_clr ); - aBrdCol = getColor( Style_Model::high_brd_wdg_clr ); + aCol = model()->color( Style_Model::HighlightWidget ); // Style_Model::high_wdg_clr + aBrdCol = model()->color( Style_Model::HighlightBorder ); // Style_Model::high_brd_wdg_clr if ( !border ) aBorder = aBrdCol; } Style_Tools::highlightRect( p, r, rad, type, aMargin, aCol, aBrdCol, aBorder ); } +/*! + \brief Draw widget handle + \param p painter + \param r rectangle + \param horiz if \c true draw horizontal handle, otherwise draw vertical handle + \param isRect if \c true surrounding rectangle is also drawn +*/ void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isRect ) const { QPixmap hole( (const char**)hole_xpm ); int i, j; - double d_hor = getDblValue( Style_Model::hor_handle_delta ); - double d_ver = getDblValue( Style_Model::ver_handle_delta ); + double d_hor = model()->handleDelta( Qt::Horizontal ); + double d_ver = model()->handleDelta( Qt::Vertical ); if ( !d_hor || !d_ver || !r.width() || !r.height() ) return; int c_hor = (int)(r.width()/d_hor)-1; @@ -2258,6 +2432,15 @@ void Style_Salome::drawHandle( QPainter* p, const QRect& r, bool horiz, bool isR } } +/*! + \brief Draw background. + \param p painter + \param r rectangle + \param bgCol background color + \param fill 'fill rectangle' flag + \param grad 'draw gradient' flag + \param horix 'draw horizontal item' flag (usefull for gradient background) +*/ void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bgCol, const bool fill, const bool grad, const bool horiz ) const { @@ -2271,40 +2454,56 @@ void Style_Salome::drawBackground( QPainter* p, const QRect& r, const QColor& bg p->fillRect( r, gr ); } } - if ( !getBoolValue( Style_Model::is_lines ) ) - return; - QColor c = getColor( Style_Model::lines_clr ); - int anAlpha = (int)( 255*( 1 - getDblValue( Style_Model::lines_transp )/100 ) ); - c.setAlpha( anAlpha ); - p->setPen( c ); - p->setRenderHint( QPainter::Antialiasing ); - int aLines = getIntValue( Style_Model::lines_type ); int x = r.x(), y = r.y(), left = r.left(), top = r.top(); int w = r.width(), h = r.height(); + QVector lines; - if ( aLines == 0 ) { // horizontal lines - const int d = 3; - for( int i=0; i<=h; i+=d ) - lines.append( QLine( x, y+i, w, r.y()+i ) ); + + switch ( model()->linesType() ) { + case Style_Model::Horizontal: + { + const int d = 3; + for ( int i = 0; i <= h; i += d ) + lines.append( QLine( x, y+i, w, r.y()+i ) ); + } + break; + case Style_Model::Inclined: + { + const int d = 5; + w = w/d*d; + h = h/d*d; + for ( int i = 0; i <= w; i += d ) + lines.append( QLine( x+i, y, x, y+i ) ); + for ( int i = 0; i < h; i += d ) + lines.append( QLine( left+w-i, top+h, left+w, top+h-i ) ); + } + break; + default: + break; } - else if ( aLines == 1 ) { - const int d = 5; - w = w/d*d; - h = h/d*d; - for( int i=0; i<=w; i+=d ) - lines.append( QLine( x+i, y, x, y+i ) ); - for( int i=0; icolor( Style_Model::Lines ); + int anAlpha = (int)( 255*( 1 - model()->linesTransparency()/100 ) ); + c.setAlpha( anAlpha ); + p->setPen( c ); + p->setRenderHint( QPainter::Antialiasing ); + p->drawLines( lines ); } - p->drawLines( lines ); } +/*! + \brief Draw border + \param p painter + \param r rectangle + \param horiz 'draw horizontal item' flag +*/ void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const { QPen oldPen = p->pen(); - QColor aBrdTopCol = getColor( Style_Model::border_tab_top_clr ), - aBrdBotCol = getColor( Style_Model::border_tab_bot_clr ); + QColor aBrdTopCol = model()->color( Style_Model::TabBorderTop ); // Style_Model::border_tab_top_clr + QColor aBrdBotCol = model()->color( Style_Model::TabBorderBottom ); // Style_Model::border_tab_bot_clr p->setPen( aBrdTopCol ); if (horiz) { p->drawLine(r.left(), r.top(), r.right(), r.top()); @@ -2319,35 +2518,13 @@ void Style_Salome::drawBorder( QPainter* p, const QRect& r, bool horiz ) const p->setPen(oldPen); } -QColor Style_Salome::getColor( int type ) const -{ - return myModel->getColorValue( type ); -} - -double Style_Salome::getDblValue( int type ) const -{ - return myModel->getDblValue( type ); -} - -int Style_Salome::getIntValue( int type ) const -{ - return myModel->getIntValue( type ); -} - -bool Style_Salome::getBoolValue( int type ) const -{ - return myModel->getBoolValue( type ); -} - -QString Style_Salome::getStringValue( int type ) const -{ - return myModel->getStringValue( type ); -} - /*! - \return corrected title text \param txt - title text - \param w - possible width - \param fm - font metrics + \brief Get corrected title text + \param txt original text + \param W possible width + \param H possible height + \param f used font + \return corrected title text */ QString Style_Salome::titleText( const QString& txt, const int W, const int H, QFont& f ) const { diff --git a/src/Style/Style_Salome.h b/src/Style/Style_Salome.h index edcfd1973..de4f9b6d6 100644 --- a/src/Style/Style_Salome.h +++ b/src/Style/Style_Salome.h @@ -26,74 +26,73 @@ #include "Style.h" #include -#include class Style_Model; class QApplication; class QWidget; -class QStyleOption; class QPainter; -class QSize; -class QVariant; +class QtxResourceMgr; class STYLE_SALOME_EXPORT Style_Salome : public QWindowsStyle { Q_OBJECT -public: + +private: Style_Salome(); + +public: virtual ~Style_Salome(); - Style_Model* getModel() const; + static void initialize( QtxResourceMgr* = 0, const QString& = QString() ); + static void apply(); + static void restore(); - void updateSettings( QApplication* ); + static bool isActive(); - virtual void polish( QApplication* ); - virtual void polish( QWidget* ); - virtual void unpolish( QWidget* ); - virtual void drawComplexControl( ComplexControl, const QStyleOptionComplex*, - QPainter*, const QWidget* = 0 ) const; + static Style_Model* model(); + + static void update(); + + virtual void polish( QApplication* ); + virtual void polish( QWidget* ); + virtual void unpolish( QWidget* ); + virtual void drawComplexControl( ComplexControl, const QStyleOptionComplex*, + QPainter*, const QWidget* = 0 ) const; - virtual void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const; - virtual void drawPrimitive( PrimitiveElement, const QStyleOption*, - QPainter*, const QWidget* = 0 ) const; - virtual int pixelMetric( PixelMetric, const QStyleOption* = 0, - const QWidget* = 0 ) const; - virtual QSize sizeFromContents ( ContentsType, const QStyleOption*, - const QSize&, const QWidget* = 0 ) const; - virtual QPixmap standardPixmap( StandardPixmap, const QStyleOption*, - const QWidget* = 0) const; - virtual int styleHint( StyleHint, const QStyleOption* = 0, - const QWidget* = 0, QStyleHintReturn* = 0 ) const; - virtual QRect subControlRect( ComplexControl, const QStyleOptionComplex*, - SubControl, const QWidget* = 0 ) const; - virtual QRect subElementRect( SubElement, const QStyleOption*, const QWidget* = 0 ) const; + virtual void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const; + virtual void drawPrimitive( PrimitiveElement, const QStyleOption*, + QPainter*, const QWidget* = 0 ) const; + virtual int pixelMetric( PixelMetric, const QStyleOption* = 0, + const QWidget* = 0 ) const; + virtual QSize sizeFromContents ( ContentsType, const QStyleOption*, + const QSize&, const QWidget* = 0 ) const; + virtual QPixmap standardPixmap( StandardPixmap, const QStyleOption*, + const QWidget* = 0) const; + virtual int styleHint( StyleHint, const QStyleOption* = 0, + const QWidget* = 0, QStyleHintReturn* = 0 ) const; + virtual QRect subControlRect( ComplexControl, const QStyleOptionComplex*, + SubControl, const QWidget* = 0 ) const; + virtual QRect subElementRect( SubElement, const QStyleOption*, const QWidget* = 0 ) const; protected slots: - QIcon standardIconImplementation( StandardPixmap, const QStyleOption* = 0, - const QWidget* = 0 ) const; - + QIcon standardIconImplementation( StandardPixmap, const QStyleOption* = 0, + const QWidget* = 0 ) const; private: - void updatePaletteColors(); - void updateAllWidgets( QApplication* ); - bool hasHover() const; - void drawHoverRect( QPainter*, const QRect&, const QColor&, const double, - const int, const bool ) const; - void drawHandle( QPainter*, const QRect&, bool, bool = true ) const; - void drawBackground( QPainter*, const QRect&, const QColor&, const bool, - const bool = false, const bool = true ) const; - void drawBorder( QPainter*, const QRect&, bool ) const; - - QColor getColor( int ) const; - double getDblValue( int ) const; - int getIntValue( int ) const; - bool getBoolValue( int ) const; - QString getStringValue( int ) const; - QString titleText( const QString&, const int, const int, QFont& ) const; + void updatePaletteColors(); + void updateAllWidgets( QApplication* ); + bool hasHover() const; + void drawHoverRect( QPainter*, const QRect&, const QColor&, const double, + const int, const bool ) const; + void drawHandle( QPainter*, const QRect&, bool, bool = true ) const; + void drawBackground( QPainter*, const QRect&, const QColor&, const bool, + const bool = false, const bool = true ) const; + void drawBorder( QPainter*, const QRect&, bool ) const; + + QString titleText( const QString&, const int, const int, QFont& ) const; private: - Style_Model* myModel; - QColor myTTipWnd, myTTipText; + static Style_Model* myModel; }; #endif // STYLE_SALOME_H diff --git a/src/Style/Style_Tools.cxx b/src/Style/Style_Tools.cxx index 390fa1332..53a401f02 100644 --- a/src/Style/Style_Tools.cxx +++ b/src/Style/Style_Tools.cxx @@ -29,6 +29,16 @@ #include #include +/*! + \class Style_Tools + \brief A set of utility functions used by SALOME style to draw widgets +*/ + +/*! + \brief Create painter path for specified rectangle + \param r rectangle on which painter path is build + \return resulting painter path +*/ QPainterPath Style_Tools::painterPath( const QRect& r ) { QPainterPath res; @@ -41,6 +51,13 @@ QPainterPath Style_Tools::painterPath( const QRect& r ) return res; } +/*! + \brief Create painter path by subtracting painter path \a path from another + painter path \a fromPath + \param fromPath initial painter path + \param path painter path being subtracted from \a fromPath + \return resulting painter path +*/ QPainterPath Style_Tools::substractPath( const QPainterPath& fromPath, const QPainterPath& path ) { @@ -52,6 +69,15 @@ QPainterPath Style_Tools::substractPath( const QPainterPath& fromPath, return res; } +/*! + \brief Create painter path basing on specified rectangle \a r with rounded corners + specified by radius \a r, operation \a type and shadow type \a shType. + \param r initial rectangle + \param rad rounding radius + \param type rounding type operation (Style_Tools::RoundType) + \param shType shadow type (Style_Tools::ShadowType) + \return resulting painter path +*/ QPainterPath Style_Tools::roundRect( const QRect& r, const double rad, int type, int shType ) { @@ -102,6 +128,17 @@ QPainterPath Style_Tools::roundRect( const QRect& r, const double rad, int type, return res; } +/*! + \brief Draw rectangle with rounded corners. + \param p painter + \param r drawing rectangle + \param rad corner rounding radius + \param type rounding type operation (Style_Tools::RoundType) + \param c1 first gradient color + \param c2 second gradient color + \param fill if \c true rectangle is filled with gradiented background according to \a c1 and \a c2 + \param antial if \c true, rectangle corners are anti-aliased +*/ void Style_Tools::roundRect( QPainter* p, const QRect& r, const double rad, const int type, const QColor& c1, const QColor& c2, bool fill, bool antial ) { @@ -120,6 +157,23 @@ void Style_Tools::roundRect( QPainter* p, const QRect& r, const double rad, cons p->strokePath( path, QPen( c2, Qt::SolidLine ) ); } +/*! + \brief Draw rectangle with rounded corners and shadow. + \param p painter + \param r drawing rectangle + \param rad corner rounding radius + \param marg drawing margin + \param shad shadow size + \param type rounding type operation (Style_Tools::RoundType) + \param light background's first gradient color + \param dark background's second gradient color + \param border_top top-left border's color + \param border_bot bottom-right border's color + \param antialize if \c true, rectangle corners are anti-aliased + \param isButton \c true if button is drawn + \param btnOn \c true if button is drawn and it is pressed + \param fill if \c true rectangle is filled with gradiented background according to \a light and \a dark +*/ void Style_Tools::shadowRect( QPainter* p, const QRect& r, const double rad, const double marg, const int shad, int type, const QColor& light, const QColor& dark, const QColor& border_top, const QColor& border_bot, const bool antialize, @@ -194,6 +248,17 @@ void Style_Tools::shadowRect( QPainter* p, const QRect& r, const double rad, con p->restore(); } +/*! + \brief Draw shadow of the check-mark + \param p painter + \param r drawing rectangle + \param rad corner rounding radius + \param type rounding type operation (Style_Tools::RoundType) + \param light background's first gradient color + \param dark background's second gradient color + \param border_top top-left border's color + \param border_bot bottom-right border's color +*/ void Style_Tools::shadowCheck( QPainter* p, const QRect& r, const double rad, const int type, const QColor& light, const QColor& dark, const QColor& border_top, const QColor& border_bot ) @@ -213,7 +278,14 @@ void Style_Tools::shadowCheck( QPainter* p, const QRect& r, const double rad, co p->strokePath( topPath, border_top ); } - +/*! + \brief Draw rectnagle arrow + \param p painter + \param re drawing rectangle + \param frame frame color + \param gr1 background's first gradient color + \param gr2 background's second gradient color +*/ void Style_Tools::arrowRect( QPainter* p, const QRect& re, const QColor& frame, const QColor& gr1, const QColor& gr2 ) { @@ -241,18 +313,33 @@ void Style_Tools::arrowRect( QPainter* p, const QRect& re, const QColor& frame, p->strokePath( path, QPen( frame, Qt::SolidLine ) ); } -void Style_Tools::fillRect( QPainter* p, const QRect& re, const QColor& _c1, - const QColor& _c2, const int alpha ) +/*! + \brief Fill rectangle with gradiented background + \param p painter + \param re drawing rectangle + \param c1 background's first gradient color + \param c2 background's second gradient color +*/ +void Style_Tools::fillRect( QPainter* p, const QRect& re, const QColor& c1, + const QColor& c2, const int alpha ) { QLinearGradient gr( re.x(), re.y(), re.x()+re.width(), re.y()+re.height() ); - QColor c1 = _c1, c2 = _c2; - c1.setAlpha( alpha ); - c2.setAlpha( alpha ); - gr.setColorAt( 0.0, c1 ); - gr.setColorAt( 1.0, c2 ); + QColor cc1 = c1, cc2 = c2; + cc1.setAlpha( alpha ); + cc2.setAlpha( alpha ); + gr.setColorAt( 0.0, cc1 ); + gr.setColorAt( 1.0, cc2 ); p->fillRect( re, gr ); } +/*! + \brief Draw arrow (for example, for combo-box drop-down menu button) + \param type primitive type + \param p painter + \param r drawing rectangle + \param pen foreground painter pen + \param brush background painter brush +*/ void Style_Tools::drawArrow( QStyle::PrimitiveElement type, QPainter* p, const QRect& r, const QColor& pen, const QColor& brush ) { @@ -338,6 +425,14 @@ void Style_Tools::drawArrow( QStyle::PrimitiveElement type, QPainter* p, const Q p->restore(); } +/*! + \brief Draw indicator (for example, for spin box's increment/decrement buttons) + \param type primitive type + \param p painter + \param r drawing rectangle + \param pen foreground painter pen + \param brush background painter brush +*/ void Style_Tools::drawSign( QStyle::PrimitiveElement type, QPainter* p, const QRect& r, const QColor& pen, const QColor& brush ) { @@ -409,6 +504,24 @@ void Style_Tools::drawSign( QStyle::PrimitiveElement type, QPainter* p, const QR p->restore(); } +/*! + \brief Create painter path for tab bar and optionally draw it + \param p painter + \param r drawing rectangle + \param position tab position + \param rad rounding radius + \param delta gap between tabs + \param light background's first gradient color + \param dark background's second gradient color + \param border_top top-left border's color + \param border_bot bottom-right border's color + \param selected \c true if tab is selected + \param isLast \c true if tab is last in the tabs list + \param isHover \c true if tab is hovered + \param focusRect focus rectangle + \param draw if \c true, tab bar is drawn + \return tab bar's painter path +*/ QPainterPath Style_Tools::tabRect( QPainter* p, const QRect& r, const int position, const double rad, const double delta, const QColor& light, const QColor& dark, const QColor& border_top, const QColor& border_bot, @@ -531,6 +644,14 @@ QPainterPath Style_Tools::tabRect( QPainter* p, const QRect& r, const int positi return path; } +/*! + \brief Draw widget's focus + \param p painter + \param aRect drawing rectangle + \param rad rounding radius + \param type rounding operation type + \param border focus rectangle color +*/ void Style_Tools::drawFocus( QPainter* p, const QRect& aRect, const double rad, const int type, const QColor& border ) { @@ -539,6 +660,13 @@ void Style_Tools::drawFocus( QPainter* p, const QRect& aRect, const double rad, drawFocus( p, path, border ); } +/*! + \brief Draw widget's focus + \param p painter + \param path drawing painter path + \param border focus rectangle color + \param line if \c true, focus is drawn as dotted line +*/ void Style_Tools::drawFocus( QPainter* p, const QPainterPath& path, const QColor& border, const bool line ) { @@ -553,6 +681,17 @@ void Style_Tools::drawFocus( QPainter* p, const QPainterPath& path, const QColor p->setPen( oldPen ); } +/*! + \brief Draw slider + \param p painter + \param r drawing rectangle + \param rad rounding radius + \param slider slider type + \param light background's first gradient color + \param dark background's second gradient color + \param border_top top-left border's color + \param border_bot bottom-right border's color +*/ void Style_Tools::drawSlider( QPainter* p, const QRect& r, const double rad, SliderType type, const QColor& light, const QColor& dark, const QColor& border_top, const QColor& border_bot ) @@ -625,6 +764,17 @@ void Style_Tools::drawSlider( QPainter* p, const QRect& r, const double rad, p->restore(); } +/*! + \brief Draw highlighted rectangle + \param p painter + \param rect drawing rectangle + \param rad rounding radius + \param type rounding operation type + \parma marg margin size + \param center background's center gradient color + \param out_center background's second color + \param border border color +*/ void Style_Tools::highlightRect( QPainter* p, const QRect& rect, const double rad, const int type, const double marg, const QColor& center, const QColor& out_center, const QColor& border ) @@ -656,6 +806,13 @@ void Style_Tools::highlightRect( QPainter* p, const QRect& rect, const double ra p->strokePath( path, border ); } +/*! + \brief Get minimal delta value (the minimum between \a rect and \a size dimensions) + \param rect rectangle + \param size size + \param defDelta default minimum delta + \return resulting minimum value +*/ int Style_Tools::getMinDelta( const QRect& rect, const QSize& size, const int defDelta ) { int aDelta = defDelta; @@ -664,6 +821,12 @@ int Style_Tools::getMinDelta( const QRect& rect, const QSize& size, const int de return aDelta; } +/*! + \brief Get halved size of the quadrangle covering specified rectangle + \param rect rectangle + \param defRect default quadranle size value + \return resulting value +*/ int Style_Tools::getMaxRect( const QRect& rect, const int defRect ) { int aRect = defRect; @@ -671,4 +834,3 @@ int Style_Tools::getMaxRect( const QRect& rect, const int defRect ) aRect = qMin( aRect, rect.width() / 2 ); return aRect; } - diff --git a/src/Style/Style_Tools.h b/src/Style/Style_Tools.h index 06ddc54b3..841ebdb33 100644 --- a/src/Style/Style_Tools.h +++ b/src/Style/Style_Tools.h @@ -23,28 +23,45 @@ #ifndef STYLE_TOOLS_H #define STYLE_TOOLS_H -#include "Style.h" #include #include #include #include -class STYLE_SALOME_EXPORT Style_Tools +// +// This class is private for Style package. +// Normally it should not be exported. +// +class Style_Tools { public: - typedef enum { None = 0x00000000, - All = 0x00000001, - Right = 0x00000002, - Left = 0x00000004, - TopLeft = 0x00000008, - TopRight = 0x00000010, - BottomLeft = 0x00000020, - BottomRight = 0x00000040 - } RoundType; + //! Rounding operation type + typedef enum { + None = 0x00000000, //!< No rounding required + All = 0x00000001, //!< All corners + Right = 0x00000002, //!< Right corners + Left = 0x00000004, //!< Left corners + TopLeft = 0x00000008, //!< Top-left corner + TopRight = 0x00000010, //!< Top-right corner + BottomLeft = 0x00000020, //!< Bottom-left corner + BottomRight = 0x00000040 //!< Bottom-right corner + } RoundType; - typedef enum { WholePath, BottomPath, TopPath } ShadowType; + //! Shadow type + typedef enum { + WholePath, //!< Whole path + BottomPath, //!< Bottom path + TopPath //!< Top path + } ShadowType; - typedef enum { SlUp, SlDown, SlLeft, SlRight, SlNone } SliderType; + //! Slider type + typedef enum { + SlUp, //!< Up-to-down gradient + SlDown, //!< Down-to-up gradient + SlLeft, //!< Left-to-right gradient + SlRight, //!< Right-to-left gradient + SlNone //!< No gradient + } SliderType; static QPainterPath painterPath( const QRect& ); static QPainterPath substractPath( const QPainterPath&, const QPainterPath& ); -- 2.39.2