*/
QtxFontEdit::QtxFontEdit( const int feat, QWidget* parent )
: QFrame( parent ),
- myFeatures( feat )
+ myFeatures( feat ),
+ myMode( Native )
{
initialize();
}
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;
}
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 );
*/
QString QtxFontEdit::fontFamily() const
{
- return myFamily->currentFont().family();
+ if ( myMode == Native )
+ return myFamily->currentFont().family();
+ else
+ return myCustomFams->currentText();
}
/*!
{
return ( myB->isChecked() ? Bold : 0 ) |
( myI->isChecked() ? Italic : 0 ) |
- ( myU->isChecked() ? Underline : 0 );
+ ( myU->isChecked() ? Underline : 0 ) |
+ ( myS->isChecked() ? Shadow : 0 ) ;
}
/*!
*/
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() ) );
+ }
}
/*!
myB->setChecked( script & Bold );
myI->setChecked( script & Italic );
myU->setChecked( script & Underline );
+ myS->setChecked( script & Shadow );
}
/*!
{
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 );
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 ) );
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& ) ) );
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.
+ <b>This method is intended for working in Custom mode.</b>
+ \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<int>() );
+}
+
+/*!
+ \brief Sets list of available font sizes.
+ <b>This method is intended for working in Custom mode.</b> 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<int>& sizes )
+{
+ QString currSize = mySize->currentText();
+
+ mySize->clear();
+ if ( !sizes.isEmpty() )
+ {
+ QStringList szList;
+ for ( QList<int>::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<int> QtxFontEdit::sizes() const
+{
+ QList<int> lst;
+ for ( int i = 0, n = mySize->count(); i < n; i++ )
+ lst.append( mySize->itemText( i ).toInt() );
+ return lst;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#include <QFrame>
class QtxComboBox;
+class QComboBox;
class QToolButton;
class QFontComboBox;
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 );
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<int>& = QList<int>() );
+ QList<int> sizes() const;
+
signals:
void changed( const QFont& );
QFontComboBox* myFamily;
QToolButton* myPreview;
int myFeatures;
- QToolButton *myB, *myI, *myU;
+ QToolButton *myB, *myI, *myU, *myS;
+ int myMode;
+ QComboBox* myCustomFams;
};
#endif // QTXFONTEDIT_H
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.
+ <b>This method is intended for working in Custom mode only.</b>
+ \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.
+ <b>This method is intended for working in Custom mode only.</b> 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<int>& sizes )
+{
+ myFont->setSizes( sizes );
+}
+
+/*!
+ \brief Gets list of custom fonts
+ \return list of families
+ \sa setFonts(), setMode()
+*/
+QList<int> QtxPagePrefFontItem::sizes() const
+{
+ return myFont->sizes();
+}
+
/*!
\brief Store preference item to the resource manager.
\sa retrieve()
{
if ( name == "features" )
return features();
+ else if ( name == "mode" )
+ return mode();
+ else if ( name == "fonts" || name == "families" )
+ return fonts();
+ else if ( name == "sizes" )
+ {
+ QList<QVariant> lst;
+ QList<int> nums = sizes();
+ for ( QList<int>::const_iterator it = nums.begin(); it != nums.end(); ++it )
+ lst.append( *it );
+ return lst;
+ }
else
return QtxPageNamedPrefItem::optionValue( name );
}
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<int> lst;
+ QList<QVariant> varList = val.toList();
+ for ( QList<QVariant>::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 );
}