author | sandman <sandman> | 2002-09-25 23:12:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-09-25 23:12:14 (UTC) |
commit | 489bc02ad26767dc45b81bf122a09ef55ac20249 (patch) (side-by-side diff) | |
tree | b7c26f8af38e9b0146179a1618a8fdf2504490fe /libopie | |
parent | 0c6ce9f1600bf1efb7736f87fd14dd8215db851f (diff) | |
download | opie-489bc02ad26767dc45b81bf122a09ef55ac20249.zip opie-489bc02ad26767dc45b81bf122a09ef55ac20249.tar.gz opie-489bc02ad26767dc45b81bf122a09ef55ac20249.tar.bz2 |
some fixes to make ofontselector more robust, if you specify invalid font
families/styles/sizes
-rw-r--r-- | libopie/ofontselector.cpp | 63 | ||||
-rw-r--r-- | libopie/ofontselector.h | 2 |
2 files changed, 42 insertions, 23 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp index f6fd541..d32aeb4 100644 --- a/libopie/ofontselector.cpp +++ b/libopie/ofontselector.cpp @@ -99,54 +99,63 @@ OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : label = new QLabel( tr( "Size" ), this ); gridLayout->addWidget( label, 2, 1 ); m_font_size_list = new QComboBox( this, "SizeListBox" ); connect( m_font_size_list, SIGNAL( activated( int ) ), this, SLOT( fontSizeClicked( int ) ) ); gridLayout->addWidget( m_font_size_list, 3, 1 ); loadFonts ( m_font_family_list ); } OFontSelector::~OFontSelector ( ) { } -bool OFontSelector::setSelectedFont ( const QString &family, const QString &styleStr, int size, const QString & /*charset*/ ) +bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) { - if ( size <= 0 ) - size = 10; - QString familyStr = family. isEmpty ( ) ? QString ( "Helvetica" ) : family; - QString sizeStr = QString::number ( size ); - - m_font_family_list-> setCurrentItem ( m_font_family_list-> findItem ( familyStr )); - if ( m_font_family_list-> currentItem ( ) < 0 ) - m_font_family_list-> setCurrentItem ( 0 ); - - fontFamilyClicked ( m_font_family_list-> currentItem ( )); - - m_font_style_list-> setCurrentItem ( findItemCB ( m_font_style_list, styleStr )); - fontStyleClicked ( m_font_style_list-> currentItem ( )); - - m_font_size_list-> setCurrentItem ( findItemCB ( m_font_size_list, sizeStr )); - fontSizeClicked ( m_font_size_list-> currentItem ( )); - - return (( m_font_family_list-> currentItem ( ) >= 0 ) && - ( m_font_style_list-> currentItem ( ) >= 0 ) && - ( m_font_size_list-> currentItem ( ) >= 0 )); + QString sizeStr = QString::number ( sizeVal ); + + QListBoxItem *family = m_font_family_list-> findItem ( familyStr ); + if ( !family ) + family = m_font_family_list-> findItem ( "Helvetica" ); + if ( !family ) + family = m_font_family_list-> firstItem ( ); + m_font_family_list-> setCurrentItem ( family ); + fontFamilyClicked ( m_font_family_list-> index ( family )); + + int style = findItemCB ( m_font_style_list, styleStr ); + if ( style < 0 ) + style = findItemCB ( m_font_style_list, "Regular" ); + if ( style < 0 && m_font_style_list-> count ( ) > 0 ) + style = 0; + m_font_style_list-> setCurrentItem ( style ); + fontStyleClicked ( style ); + + int size = findItemCB ( m_font_size_list, sizeStr ); + if ( size < 0 ) + size = findItemCB ( m_font_size_list, "10" ); + if ( size < 0 && m_font_size_list-> count ( ) > 0 ) + size = 0; + m_font_size_list-> setCurrentItem ( size ); + fontSizeClicked ( size ); + + return (( family ) && + ( style >= 0 ) && + ( size >= 0 )); } bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) { QString dummy; return selectedFont ( family, style, size, dummy ); } QString OFontSelector::fontFamily ( ) const { FontListItem *fli = (FontListItem *) m_font_family_list-> item ( m_font_family_list-> currentItem ( )); return fli ? fli-> family ( ) : QString::null; } @@ -246,32 +255,40 @@ void OFontSelector::fontFamilyClicked ( int index ) } changeFont ( ); } void OFontSelector::fontStyleClicked ( int /*index*/ ) { changeFont ( ); } void OFontSelector::fontSizeClicked ( int /*index*/ ) { changeFont ( ); } void OFontSelector::changeFont ( ) { + emit fontSelected ( selectedFont ( )); +} + + +QFont OFontSelector::selectedFont ( ) +{ int ffa = m_font_family_list-> currentItem ( ); int fst = m_font_style_list-> currentItem ( ); int fsi = m_font_size_list-> currentItem ( ); FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); if ( fli ) { - emit fontSelected ( m_fdb. font ( fli-> family ( ), \ + return m_fdb. font ( fli-> family ( ), \ fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ - m_fdb. charSets ( fli-> family ( )) [0] )); + m_fdb. charSets ( fli-> family ( )) [0] ); } + else + return QFont ( ); }
\ No newline at end of file diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h index 9227e48..2011e43 100644 --- a/libopie/ofontselector.h +++ b/libopie/ofontselector.h @@ -34,32 +34,34 @@ class QComboBox; class QListBox; class QFont; class OFontSelector : public QWidget { Q_OBJECT public: OFontSelector ( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); virtual ~OFontSelector ( ); bool selectedFont ( QString &family, QString &style, int &size ); bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); + QFont selectedFont ( ); + bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); QString fontFamily ( ) const; QString fontStyle ( ) const; int fontSize ( ) const; QString fontCharSet ( ) const; signals: void fontSelected ( const QFont & ); protected slots: virtual void fontFamilyClicked ( int ); virtual void fontStyleClicked ( int ); virtual void fontSizeClicked ( int ); private: |