-rw-r--r-- | libopie/ofontselector.cpp | 132 |
1 files changed, 91 insertions, 41 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp index b905474..c8471cc 100644 --- a/libopie/ofontselector.cpp +++ b/libopie/ofontselector.cpp @@ -39,5 +39,5 @@ class OFontSelectorPrivate { -public: +public: QListBox * m_font_family_list; QComboBox * m_font_style_list; @@ -45,9 +45,10 @@ public: QMultiLineEdit *m_preview; - bool m_pointbug; + bool m_pointbug : 1; FontDatabase m_fdb; }; +namespace { class FontListItem : public QListBoxText { @@ -58,5 +59,5 @@ public: m_styles = styles; m_sizes = sizes; - + QString str = t; str [0] = str [0]. upper ( ); @@ -68,15 +69,15 @@ public: return m_name; } - + const QStringList &styles ( ) const { return m_styles; } - + const QValueList<int> &sizes ( ) const { return m_sizes; } - + private: QStringList m_styles; @@ -95,5 +96,6 @@ static int findItemCB ( QComboBox *box, const QString &str ) } - +} +/* static same as anon. namespace */ static int qt_version ( ) { @@ -103,5 +105,11 @@ static int qt_version ( ) } - +/** + * Constructs the Selector object + * @param withpreview If a font preview should be given + * @param parent The parent of the Font Selector + * @param name The name of the object + * @param fl WidgetFlags + */ OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) { @@ -136,5 +144,5 @@ OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *na d-> m_preview-> setAlignment ( AlignCenter ); d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); - d-> m_preview-> setMargin ( 3 ); + d-> m_preview-> setMargin ( 3 ); d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); gridLayout-> addRowSpacing ( 5, 4 ); @@ -153,4 +161,9 @@ OFontSelector::~OFontSelector ( ) } +/** + * This methods tries to set the font + * @param f The wishes font + * @return success or failure + */ bool OFontSelector::setSelectedFont ( const QFont &f ) { @@ -158,5 +171,13 @@ bool OFontSelector::setSelectedFont ( const QFont &f ) } -bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) + +/** + * This is an overloaded method @see setSelectedFont + * @param familyStr The family of the font + * @param styleStr The style of the font + * @param sizeVal The size of font + * @param charset The charset to be used. Will be deprecated by QT3 + */ +bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) { QString sizeStr = QString::number ( sizeVal ); @@ -167,5 +188,5 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s if ( !family ) family = d-> m_font_family_list-> firstItem ( ); - d-> m_font_family_list-> setCurrentItem ( family ); + d-> m_font_family_list-> setCurrentItem ( family ); fontFamilyClicked ( d-> m_font_family_list-> index ( family )); @@ -185,8 +206,16 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s d-> m_font_size_list-> setCurrentItem ( size ); fontSizeClicked ( size ); - + return (( family ) && ( style >= 0 ) && ( size >= 0 )); } +/** + * This method returns the name, style and size of the currently selected + * font or false if no font is selected + * @param family The font family will be written there + * @param style The style will be written there + * @param size The size will be written there + * @return success or failure + */ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) { @@ -196,27 +225,42 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) +/** + * This method does return the font family or QString::null if there is + * no font item selected + * @return the font family + */ QString OFontSelector::fontFamily ( ) const { FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); - + return fli ? fli-> family ( ) : QString::null; } +/** + * This method will return the style of the font or QString::null + * @return the style of the font + */ QString OFontSelector::fontStyle ( ) const { FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); - int fst = d-> m_font_style_list-> currentItem ( ); + int fst = d-> m_font_style_list-> currentItem ( ); return ( fli && fst >= 0 ) ? fli-> styles ( ) [fst] : QString::null; } +/** + * This method will return the font size or 10 if no font size is available + */ int OFontSelector::fontSize ( ) const { FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); - int fsi = d-> m_font_size_list-> currentItem ( ); + int fsi = d-> m_font_size_list-> currentItem ( ); return ( fli && fsi >= 0 ) ? fli-> sizes ( ) [fsi] : 10; } +/** + * returns the charset of the font or QString::null + */ QString OFontSelector::fontCharSet ( ) const { @@ -226,12 +270,16 @@ QString OFontSelector::fontCharSet ( ) const } +/** + * Overloaded member function see above + * @see selectedFont + */ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) { int ffa = d-> m_font_family_list-> currentItem ( ); - int fst = d-> m_font_style_list-> currentItem ( ); + int fst = d-> m_font_style_list-> currentItem ( ); int fsi = d-> m_font_size_list-> currentItem ( ); - + FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); - + if ( fli ) { family = fli-> family ( ); @@ -247,18 +295,18 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, Q - + void OFontSelector::loadFonts ( QListBox *list ) { QStringList f = d-> m_fdb. families ( ); - + for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); - + if ( d-> m_pointbug ) { for ( QValueList <int>::Iterator it = ps. begin ( ); it != ps. end ( ); it++ ) *it /= 10; } - + list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); } @@ -269,13 +317,13 @@ void OFontSelector::fontFamilyClicked ( int index ) QString oldstyle = d-> m_font_style_list-> currentText ( ); QString oldsize = d-> m_font_size_list-> currentText ( ); - + FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); - - d-> m_font_style_list-> clear ( ); + + d-> m_font_style_list-> clear ( ); d-> m_font_style_list-> insertStringList ( fli-> styles ( )); d-> m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); int i; - + i = findItemCB ( d-> m_font_style_list, oldstyle ); if ( i < 0 ) @@ -283,14 +331,14 @@ void OFontSelector::fontFamilyClicked ( int index ) if (( i < 0 ) && ( d-> m_font_style_list-> count ( ) > 0 )) i = 0; - + if ( i >= 0 ) { - d-> m_font_style_list-> setCurrentItem ( i ); + d-> m_font_style_list-> setCurrentItem ( i ); fontStyleClicked ( i ); } - + d-> m_font_size_list-> clear ( ); QValueList<int> sl = fli-> sizes ( ); - - for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) + + for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) d-> m_font_size_list-> insertItem ( QString::number ( *it )); @@ -300,15 +348,15 @@ void OFontSelector::fontFamilyClicked ( int index ) if (( i < 0 ) && ( d-> m_font_size_list-> count ( ) > 0 )) i = 0; - + if ( i >= 0 ) { - d-> m_font_size_list-> setCurrentItem ( i ); + d-> m_font_size_list-> setCurrentItem ( i ); fontSizeClicked ( i ); } - changeFont ( ); + changeFont ( ); } void OFontSelector::fontStyleClicked ( int /*index*/ ) { - changeFont ( ); + changeFont ( ); } @@ -328,13 +376,15 @@ void OFontSelector::changeFont ( ) } - +/** + * Return the selected font + */ QFont OFontSelector::selectedFont ( ) { int ffa = d-> m_font_family_list-> currentItem ( ); - int fst = d-> m_font_style_list-> currentItem ( ); + int fst = d-> m_font_style_list-> currentItem ( ); int fsi = d-> m_font_size_list-> currentItem ( ); - + FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); - + if ( fli ) { return d-> m_fdb. font ( fli-> family ( ), \ @@ -356,7 +406,7 @@ void OFontSelector::resizeEvent ( QResizeEvent *re ) QWidget::resizeEvent ( re ); - + if ( d-> m_preview ) d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); - + } |