From: sln Date: Tue, 9 Dec 2008 12:17:15 +0000 (+0000) Subject: 0013557: field values display X-Git-Tag: Phase8_Part1_16122008 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3293b0702bde90739dfd01a5d86a1afb14a3dd9e;p=modules%2Fgui.git 0013557: field values display QtxFontEdit class and related controls in preferences has been updated in order to support custom fonts instead of system fonts only. For example VTK viewer uses only three fonts Arial, Courier and Times. As result there is no point in providing control with system fonts for VTK viewer. Also ?S? button has been added in QtxFontEdit in order to provide ?Shadow? style of VTK font. ?1underline? property of QFont is replaced with ?overline? property in order to store ?Shadow? status of font to avoid conflict simultaneous usage of ?U? and ?S? button. All related controls for font definition in SMESH and VISU modules have been updated accordingly --- diff --git a/src/Qtx/QtxFontEdit.cxx b/src/Qtx/QtxFontEdit.cxx index 972284cdf..ea1687911 100644 --- a/src/Qtx/QtxFontEdit.cxx +++ b/src/Qtx/QtxFontEdit.cxx @@ -57,7 +57,8 @@ */ QtxFontEdit::QtxFontEdit( const int feat, QWidget* parent ) : QFrame( parent ), - myFeatures( feat ) + myFeatures( feat ), + myMode( Native ) { initialize(); } @@ -119,6 +120,7 @@ QFont QtxFontEdit::currentFont() const fnt.setBold( script & Bold ); fnt.setItalic( script & Italic ); fnt.setUnderline( script & Underline ); + fnt.setOverline( script & Shadow ); //addVtkFontPref( tr( "LABELS" ), valLblFontGr, "values_labeling_font" ); return fnt; } @@ -131,18 +133,21 @@ QFont QtxFontEdit::currentFont() const void QtxFontEdit::setCurrentFont( const QFont& fnt ) { myFamily->blockSignals( true ); + myCustomFams->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 ) ); + ( fnt.underline() ? Underline : 0 ) | + ( fnt.overline() ? Shadow : 0 ) ); myFamily->blockSignals( false ); + myCustomFams->blockSignals( false ); mySize->blockSignals( false ); myB->blockSignals( false ); myI->blockSignals( false ); @@ -158,7 +163,10 @@ void QtxFontEdit::setCurrentFont( const QFont& fnt ) */ QString QtxFontEdit::fontFamily() const { - return myFamily->currentFont().family(); + if ( myMode == Native ) + return myFamily->currentFont().family(); + else + return myCustomFams->currentText(); } /*! @@ -182,7 +190,8 @@ int QtxFontEdit::fontScripting() const { return ( myB->isChecked() ? Bold : 0 ) | ( myI->isChecked() ? Italic : 0 ) | - ( myU->isChecked() ? Underline : 0 ); + ( myU->isChecked() ? Underline : 0 ) | + ( myS->isChecked() ? Shadow : 0 ) ; } /*! @@ -192,8 +201,17 @@ int QtxFontEdit::fontScripting() const */ void QtxFontEdit::setFontFamily( const QString& fam ) { - myFamily->setCurrentFont( QFont( fam ) ); - onFontChanged( myFamily->currentFont() ); + if ( myMode == Native ) + { + myFamily->setCurrentFont( QFont( fam ) ); + onFontChanged( myFamily->currentFont() ); + } + else + { + myCustomFams->setCurrentIndex( myCustomFams->findText( fam ) ); + if ( !myCustomFams->signalsBlocked() ) + emit( changed( currentFont() ) ); + } } /*! @@ -223,6 +241,7 @@ void QtxFontEdit::setFontScripting( const int script ) myB->setChecked( script & Bold ); myI->setChecked( script & Italic ); myU->setChecked( script & Underline ); + myS->setChecked( script & Shadow ); } /*! @@ -232,11 +251,13 @@ void QtxFontEdit::updateState() { int feat = features(); - myFamily->setVisible( feat & Family ); + myFamily->setVisible( ( feat & Family ) && myMode == Native ); + myCustomFams->setVisible( ( feat & Family ) && myMode == Custom ); mySize->setVisible( feat & Size ); myB->setVisible( feat & Bold ); myI->setVisible( feat & Italic ); myU->setVisible( feat & Underline ); + myS->setVisible( feat & Shadow ); myPreview->setVisible( feat & Preview ); mySize->setEditable( feat & UserSize ); @@ -296,6 +317,7 @@ void QtxFontEdit::initialize() base->setSpacing( 5 ); base->addWidget( myFamily = new QFontComboBox( this ) ); + base->addWidget( myCustomFams = new QComboBox( this ) ); base->addWidget( mySize = new QtxComboBox( this ) ); mySize->setInsertPolicy( QComboBox::NoInsert ); mySize->setValidator( new QIntValidator( 1, 250, mySize ) ); @@ -312,10 +334,15 @@ void QtxFontEdit::initialize() myU->setText( tr( "U" ) ); myU->setCheckable( true ); + base->addWidget( myS = new QToolButton( this ) ); + myS->setText( tr( "S" ) ); + myS->setCheckable( true ); + base->addWidget( myPreview = new QToolButton( this ) ); myPreview->setText( "..." ); myFamily->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); + myCustomFams->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& ) ) ); @@ -325,6 +352,141 @@ void QtxFontEdit::initialize() connect( myI, SIGNAL( toggled( bool ) ), this, SLOT( onPropertyChanged() ) ); connect( myU, SIGNAL( toggled( bool ) ), this, SLOT( onPropertyChanged() ) ); + myCustomFams->hide(); + myS->hide(); + updateState(); onFontChanged( currentFont() ); } + +/*! + \brief Specifies whether widget works in Native or Custom mode. Native mode + is intended for working with system fonts. Custom mode is intended for + working with manually defined set of fonts. Set of custom fonts can be + specified with setCustomFonts() method + \param mode mode from QtxFontEdit::Mode enumeration + \sa mode() +*/ +void QtxFontEdit::setMode( const int mode ) +{ + if ( myMode == mode ) + return; + + myMode = mode; + + myFamily->setShown( myMode == Native ); + myCustomFams->setShown( myMode == Custom ); + + updateGeometry(); +} + +/*! + \brief Verifies whether widget works in Native or Custom mode + \return Native or Custom mode + \sa setMode() +*/ +int QtxFontEdit::mode() const +{ + return myMode; +} + +/*! + \brief Sets list of custom fonts. + This method is intended for working in Custom mode. + \param fams list of families + \sa fonts(), setMode() +*/ +void QtxFontEdit::setFonts( const QStringList& fams ) +{ + QString currFam = myCustomFams->currentText(); + + myCustomFams->clear(); + myCustomFams->addItems( fams ); + + int ind = myCustomFams->findText( currFam ); + if ( ind != -1 ) + myCustomFams->setCurrentIndex( ind ); + + setSizes( QList() ); +} + +/*! + \brief Sets list of available font sizes. + This method is intended for working in Custom mode. The list of sizes can + be empty. In this case system generate listof size automatically from 8 till 72. + \param sizes list of sizes + \sa sizes(), setMode() +*/ +void QtxFontEdit::setSizes( const QList& sizes ) +{ + QString currSize = mySize->currentText(); + + mySize->clear(); + if ( !sizes.isEmpty() ) + { + QStringList szList; + for ( QList::const_iterator it = sizes.begin(); it != sizes.end(); ++it ) + szList.append( QString::number( *it ) ); + mySize->addItems( szList ); + } + else + { + static QStringList defLst; + if ( defLst.isEmpty() ) + { + QString str( "8 9 10 11 12 14 16 18 20 22 24 26 28 36 48 72" ); + defLst = str.split( " " ); + } + mySize->addItems( defLst ); + } + + int ind = mySize->findText( currSize ); + if ( ind != -1 ) + mySize->setCurrentIndex( ind ); +} + +/*! + \brief Gets list of custom fonts + \return list of families + \sa setFonts(), setMode() +*/ +QStringList QtxFontEdit::fonts() const +{ + QStringList fams; + for ( int i = 0, n = myCustomFams->count(); i < n; i++ ) + fams.append( myCustomFams->itemText( i ) ); + return fams; +} + +/*! + \brief Gets list of custom fonts + \return list of families + \sa setCustomFonts(), setMode() +*/ +QList QtxFontEdit::sizes() const +{ + QList lst; + for ( int i = 0, n = mySize->count(); i < n; i++ ) + lst.append( mySize->itemText( i ).toInt() ); + return lst; +} + + + + + + + + + + + + + + + + + + + + diff --git a/src/Qtx/QtxFontEdit.h b/src/Qtx/QtxFontEdit.h index 897b10a47..b0dbe3b1a 100644 --- a/src/Qtx/QtxFontEdit.h +++ b/src/Qtx/QtxFontEdit.h @@ -27,6 +27,7 @@ #include class QtxComboBox; +class QComboBox; class QToolButton; class QFontComboBox; @@ -43,11 +44,18 @@ public: Bold = 0x08, //!< show 'bold' widget Italic = 0x10, //!< show 'italic' widget Underline = 0x20, //!< show 'underline' widget - Preview = 0x40, //!< show font preview widget + Shadow = 0x40, //!< show 'shadow' widget + Preview = 0x80, //!< show font preview widget Scripting = Bold | Italic | Underline, //!< show font scripting widgets ('bold','italic','underline') All = Family | Size | UserSize | Scripting | Preview //!< show all font widgets } Features; + typedef enum + { + Native, //!< Native mode intended for working with system fonts + Custom //!< Custom mode intended for working with manually defined set of fonts + } Mode; + public: QtxFontEdit( const int, QWidget* = 0 ); QtxFontEdit( QWidget* = 0 ); @@ -67,6 +75,15 @@ public: int features() const; void setFeatures( const int ); + void setMode( const int ); + int mode() const; + + void setFonts( const QStringList& ); + QStringList fonts() const; + + void setSizes( const QList& = QList() ); + QList sizes() const; + signals: void changed( const QFont& ); @@ -84,7 +101,9 @@ private: QFontComboBox* myFamily; QToolButton* myPreview; int myFeatures; - QToolButton *myB, *myI, *myU; + QToolButton *myB, *myI, *myU, *myS; + int myMode; + QComboBox* myCustomFams; }; #endif // QTXFONTEDIT_H diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 30a08cea6..f8562a18e 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -3013,6 +3013,72 @@ void QtxPagePrefFontItem::setFeatures( const int f ) myFont->setFeatures( f ); } +/*! + \brief Specifies whether widget works in Native or Custom mode. Native mode + is intended for working with system fonts. Custom mode is intended for + working with manually defined set of fonts. Set of custom fonts can be + specified with setFonts() method + \param mode mode from QtxFontEdit::Mode enumeration + \sa mode() +*/ +void QtxPagePrefFontItem::setMode( const int mode ) +{ + myFont->setMode( mode ); +} + +/*! + \brief Verifies whether widget works in Native or Custom mode + \return Native or Custom mode + \sa setMode() +*/ +int QtxPagePrefFontItem::mode() const +{ + return myFont->mode(); +} + +/*! + \brief Sets list of custom fonts. + This method is intended for working in Custom mode only. + \param fams list of families + \sa fonts(), setMode() +*/ +void QtxPagePrefFontItem::setFonts( const QStringList& fams ) +{ + myFont->setFonts( fams ); +} + +/*! + \brief Gets list of custom fonts + \return list of families + \sa setFonts(), setMode() +*/ +QStringList QtxPagePrefFontItem::fonts() const +{ + return myFont->fonts(); +} + +/*! + \brief Sets list of available font sizes. + This method is intended for working in Custom mode only. The list of sizes can + be empty. In this case system generate listof size automatically from 8 till 72. + \param sizes list of sizes + \sa sizes(), setMode() +*/ +void QtxPagePrefFontItem::setSizes( const QList& sizes ) +{ + myFont->setSizes( sizes ); +} + +/*! + \brief Gets list of custom fonts + \return list of families + \sa setFonts(), setMode() +*/ +QList QtxPagePrefFontItem::sizes() const +{ + return myFont->sizes(); +} + /*! \brief Store preference item to the resource manager. \sa retrieve() @@ -3041,6 +3107,18 @@ QVariant QtxPagePrefFontItem::optionValue( const QString& name ) const { if ( name == "features" ) return features(); + else if ( name == "mode" ) + return mode(); + else if ( name == "fonts" || name == "families" ) + return fonts(); + else if ( name == "sizes" ) + { + QList lst; + QList nums = sizes(); + for ( QList::const_iterator it = nums.begin(); it != nums.end(); ++it ) + lst.append( *it ); + return lst; + } else return QtxPageNamedPrefItem::optionValue( name ); } @@ -3058,6 +3136,30 @@ void QtxPagePrefFontItem::setOptionValue( const QString& name, const QVariant& v if ( val.canConvert( QVariant::Int ) ) setFeatures( val.toInt() ); } + else if ( name == "mode" ) + { + if ( val.canConvert( QVariant::Int ) ) + setMode( val.toInt() ); + } + else if ( name == "fonts" || name == "families" ) + { + if ( val.canConvert( QVariant::StringList ) ) + setFonts( val.toStringList() ); + } + else if ( name == "sizes" ) + { + if ( val.type() == QVariant::List ) + { + QList lst; + QList varList = val.toList(); + for ( QList::const_iterator it = varList.begin(); it != varList.end(); ++it ) + { + if ( (*it).canConvert( QVariant::Int ) ) + lst.append( (*it).toInt() ); + } + setSizes( lst ); + } + } else QtxPageNamedPrefItem::setOptionValue( name, val ); } diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 40d0dd992..1a411da96 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -521,6 +521,15 @@ public: int features() const; void setFeatures( const int ); + void setMode( const int ); + int mode() const; + + void setFonts( const QStringList& ); + QStringList fonts() const; + + void setSizes( const QList& = QList() ); + QList sizes() const; + virtual void store(); virtual void retrieve(); diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index de647ba3b..6668c332f 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1388,6 +1388,8 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QFont& fVa fVal.setItalic( true ); else if ( curval == QString( "underline" ) ) fVal.setUnderline( true ); + else if ( curval == QString( "shadow" ) || curval == QString( "overline" ) ) + fVal.setOverline( true ); else { bool isOk = false; @@ -1823,6 +1825,8 @@ void QtxResourceMgr::setValue( const QString& sect, const QString& name, const Q fontDescr.append( "Italic" ); if ( val.underline() ) fontDescr.append( "Underline" ); + if ( val.overline() ) + fontDescr.append( "Overline" ); fontDescr.append( QString( "%1" ).arg( val.pointSize() ) ); setResource( sect, name, fontDescr.join( "," ) );