From: asl Date: Wed, 20 Jul 2005 09:50:04 +0000 (+0000) Subject: New methods allowing to store in resource manager string information about font and... X-Git-Tag: V3_0_1~36 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c38bd41c3e1c73ad990ed3a64a53ad0ed89190d0;p=modules%2Fgui.git New methods allowing to store in resource manager string information about font and to construct font automatically by this info --- diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 3257154fc..917037bb4 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -670,6 +670,11 @@ bool QtxResourceMgr::value( const QString& name, QColor& val ) const return value( currentSection(), name, val ); } +bool QtxResourceMgr::value( const QString& name, QFont& val ) const +{ + return value( currentSection(), name, val ); +} + bool QtxResourceMgr::value( const QString& name, QString& val, const bool subst ) const { return value( currentSection(), name, val, subst ); @@ -751,6 +756,41 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QColor& cV return res; } +bool QtxResourceMgr::value( const QString& sect, const QString& name, QFont& fVal ) const +{ + QString val = stringValue( sect, name, "" ).stripWhiteSpace(); + QStringList font_values = QStringList::split( val, "," ); + if( font_values.count()<2 || font_values.count()>4 ) + return false; + + QString family = font_values[0]; + bool isBold = false, isItalic = false, isOk = false; + int pSize = -1; + for( int i=1, n=font_values.count(); i0 && !family.isEmpty() ) + { + fVal = QFont( family, pSize ); + fVal.setBold( isBold ); + fVal.setItalic( isItalic ); + return true; + } + else + return false; +} + bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& val, const bool subst ) const { initialize(); @@ -781,6 +821,11 @@ bool QtxResourceMgr::booleanValue( const QString& name, const bool def ) const return booleanValue( currentSection(), name, def ); } +QFont QtxResourceMgr::fontValue( const QString& name, const QFont& def ) const +{ + return fontValue( currentSection(), name, def ); +} + QColor QtxResourceMgr::colorValue( const QString& name, const QColor& def ) const { return colorValue( currentSection(), name, def ); @@ -815,6 +860,14 @@ bool QtxResourceMgr::booleanValue( const QString& sect, const QString& name, con return val; } +QFont QtxResourceMgr::fontValue( const QString& sect, const QString& name, const QFont& def ) const +{ + QFont font; + if( !value( sect, name, font ) ) + font = def; + return font; +} + QColor QtxResourceMgr::colorValue( const QString& sect, const QString& name, const QColor& def ) const { QColor val; @@ -878,6 +931,11 @@ void QtxResourceMgr::setValue( const QString& name, const QColor& val ) setValue( currentSection(), name, val ); } +void QtxResourceMgr::setValue( const QString& name, const QFont& val ) +{ + setValue( currentSection(), name, val ); +} + void QtxResourceMgr::setValue( const QString& name, const QString& val ) { setValue( currentSection(), name, val ); @@ -903,6 +961,19 @@ void QtxResourceMgr::setValue( const QString& sect, const QString& name, const Q setValue( sect, name, QString( "%1, %2, %3").arg( val.red() ).arg( val.green() ).arg( val.blue() ) ); } +void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QFont& f ) +{ + QStringList val; + val.append( f.family() ); + if( f.bold() ) + val.append( "Bold" ); + if( f.italic() ) + val.append( "Italic" ); + val.append( QString( "%1" ).arg( f.pointSize() ) ); + + setValue( sect, name, val.join( "," ) ); +} + void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QString& val ) { initialize(); diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 6b0262bc8..d91a58c05 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -43,25 +44,29 @@ public: bool value( const QString&, double& ) const; bool value( const QString&, bool& ) const; bool value( const QString&, QColor& ) const; + bool value( const QString&, QFont& ) const; bool value( const QString&, QString&, const bool = true ) const; bool value( const QString&, const QString&, int& ) const; bool value( const QString&, const QString&, double& ) const; bool value( const QString&, const QString&, bool& ) const; bool value( const QString&, const QString&, QColor& ) const; + bool value( const QString&, const QString&, QFont& ) const; bool value( const QString&, const QString&, QString&, const bool = true ) const; int integerValue( const QString&, const int = 0 ) const; - double doubleValue( const QString&, const double = 0 ) const; + double doubleValue ( const QString&, const double = 0 ) const; bool booleanValue( const QString&, const bool = false ) const; - QColor colorValue( const QString&, const QColor& = QColor() ) const; - QString stringValue( const QString&, const char* = 0 ) const; + QColor colorValue ( const QString&, const QColor& = QColor() ) const; + QFont fontValue ( const QString&, const QFont& = QFont() ) const; + QString stringValue ( const QString&, const char* = 0 ) const; int integerValue( const QString&, const QString&, const int = 0 ) const; - double doubleValue( const QString&, const QString&, const double = 0 ) const; + double doubleValue ( const QString&, const QString&, const double = 0 ) const; bool booleanValue( const QString&, const QString&, const bool = false ) const; - QColor colorValue( const QString&, const QString&, const QColor& = QColor() ) const; - QString stringValue( const QString&, const QString&, const char* = 0 ) const; + QColor colorValue ( const QString&, const QString&, const QColor& = QColor() ) const; + QFont fontValue ( const QString&, const QString&, const QFont& = QFont() ) const; + QString stringValue ( const QString&, const QString&, const char* = 0 ) const; bool hasSection( const QString& ) const; bool hasValue( const QString& ) const; @@ -71,12 +76,14 @@ public: void setValue( const QString&, const double ); void setValue( const QString&, const bool ); void setValue( const QString&, const QColor& ); + void setValue( const QString&, const QFont& ); void setValue( const QString&, const QString& ); void setValue( const QString&, const QString&, const int ); void setValue( const QString&, const QString&, const double ); void setValue( const QString&, const QString&, const bool ); void setValue( const QString&, const QString&, const QColor& ); + void setValue( const QString&, const QString&, const QFont& ); void setValue( const QString&, const QString&, const QString& ); void remove( const QString& );