summaryrefslogtreecommitdiff
path: root/libopie
Side-by-side diff
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/ofontselector.cpp65
-rw-r--r--libopie/ofontselector.h2
2 files changed, 43 insertions, 24 deletions
diff --git a/libopie/ofontselector.cpp b/libopie/ofontselector.cpp
index f6fd541..d32aeb4 100644
--- a/libopie/ofontselector.cpp
+++ b/libopie/ofontselector.cpp
@@ -114,24 +114,33 @@ 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 ( ));
+ 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 (( m_font_family_list-> currentItem ( ) >= 0 ) &&
- ( m_font_style_list-> currentItem ( ) >= 0 ) &&
- ( m_font_size_list-> currentItem ( ) >= 0 ));
+ return (( family ) &&
+ ( style >= 0 ) &&
+ ( size >= 0 ));
}
@@ -261,2 +270,8 @@ void OFontSelector::changeFont ( )
{
+ emit fontSelected ( selectedFont ( ));
+}
+
+
+QFont OFontSelector::selectedFont ( )
+{
int ffa = m_font_family_list-> currentItem ( );
@@ -268,7 +283,9 @@ void OFontSelector::changeFont ( )
if ( fli ) {
- emit fontSelected ( m_fdb. font ( fli-> family ( ), \
- fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
- fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
- m_fdb. charSets ( fli-> family ( )) [0] ));
+ 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] );
}
+ else
+ return QFont ( );
}
diff --git a/libopie/ofontselector.h b/libopie/ofontselector.h
index 9227e48..2011e43 100644
--- a/libopie/ofontselector.h
+++ b/libopie/ofontselector.h
@@ -49,2 +49,4 @@ public:
+ QFont selectedFont ( );
+
bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 );