-rw-r--r-- | libopie/ofontselector.cpp | 65 |
1 files changed, 41 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 | |||
@@ -109,34 +109,43 @@ OFontSelector::OFontSelector ( QWidget *parent, const char *name, WFlags fl ) : | |||
109 | } | 109 | } |
110 | 110 | ||
111 | OFontSelector::~OFontSelector ( ) | 111 | OFontSelector::~OFontSelector ( ) |
112 | { | 112 | { |
113 | } | 113 | } |
114 | 114 | ||
115 | bool OFontSelector::setSelectedFont ( const QString &family, const QString &styleStr, int size, const QString & /*charset*/ ) | 115 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) |
116 | { | 116 | { |
117 | if ( size <= 0 ) | 117 | QString sizeStr = QString::number ( sizeVal ); |
118 | size = 10; | 118 | |
119 | QString familyStr = family. isEmpty ( ) ? QString ( "Helvetica" ) : family; | 119 | QListBoxItem *family = m_font_family_list-> findItem ( familyStr ); |
120 | QString sizeStr = QString::number ( size ); | 120 | if ( !family ) |
121 | 121 | family = m_font_family_list-> findItem ( "Helvetica" ); | |
122 | m_font_family_list-> setCurrentItem ( m_font_family_list-> findItem ( familyStr )); | 122 | if ( !family ) |
123 | if ( m_font_family_list-> currentItem ( ) < 0 ) | 123 | family = m_font_family_list-> firstItem ( ); |
124 | m_font_family_list-> setCurrentItem ( 0 ); | 124 | m_font_family_list-> setCurrentItem ( family ); |
125 | 125 | fontFamilyClicked ( m_font_family_list-> index ( family )); | |
126 | fontFamilyClicked ( m_font_family_list-> currentItem ( )); | 126 | |
127 | 127 | int style = findItemCB ( m_font_style_list, styleStr ); | |
128 | m_font_style_list-> setCurrentItem ( findItemCB ( m_font_style_list, styleStr )); | 128 | if ( style < 0 ) |
129 | fontStyleClicked ( m_font_style_list-> currentItem ( )); | 129 | style = findItemCB ( m_font_style_list, "Regular" ); |
130 | 130 | if ( style < 0 && m_font_style_list-> count ( ) > 0 ) | |
131 | m_font_size_list-> setCurrentItem ( findItemCB ( m_font_size_list, sizeStr )); | 131 | style = 0; |
132 | fontSizeClicked ( m_font_size_list-> currentItem ( )); | 132 | m_font_style_list-> setCurrentItem ( style ); |
133 | fontStyleClicked ( style ); | ||
134 | |||
135 | int size = findItemCB ( m_font_size_list, sizeStr ); | ||
136 | if ( size < 0 ) | ||
137 | size = findItemCB ( m_font_size_list, "10" ); | ||
138 | if ( size < 0 && m_font_size_list-> count ( ) > 0 ) | ||
139 | size = 0; | ||
140 | m_font_size_list-> setCurrentItem ( size ); | ||
141 | fontSizeClicked ( size ); | ||
133 | 142 | ||
134 | return (( m_font_family_list-> currentItem ( ) >= 0 ) && | 143 | return (( family ) && |
135 | ( m_font_style_list-> currentItem ( ) >= 0 ) && | 144 | ( style >= 0 ) && |
136 | ( m_font_size_list-> currentItem ( ) >= 0 )); | 145 | ( size >= 0 )); |
137 | } | 146 | } |
138 | 147 | ||
139 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 148 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
140 | { | 149 | { |
141 | QString dummy; | 150 | QString dummy; |
142 | return selectedFont ( family, style, size, dummy ); | 151 | return selectedFont ( family, style, size, dummy ); |
@@ -256,22 +265,30 @@ void OFontSelector::fontSizeClicked ( int /*index*/ ) | |||
256 | { | 265 | { |
257 | changeFont ( ); | 266 | changeFont ( ); |
258 | } | 267 | } |
259 | 268 | ||
260 | void OFontSelector::changeFont ( ) | 269 | void OFontSelector::changeFont ( ) |
261 | { | 270 | { |
271 | emit fontSelected ( selectedFont ( )); | ||
272 | } | ||
273 | |||
274 | |||
275 | QFont OFontSelector::selectedFont ( ) | ||
276 | { | ||
262 | int ffa = m_font_family_list-> currentItem ( ); | 277 | int ffa = m_font_family_list-> currentItem ( ); |
263 | int fst = m_font_style_list-> currentItem ( ); | 278 | int fst = m_font_style_list-> currentItem ( ); |
264 | int fsi = m_font_size_list-> currentItem ( ); | 279 | int fsi = m_font_size_list-> currentItem ( ); |
265 | 280 | ||
266 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | 281 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); |
267 | 282 | ||
268 | if ( fli ) { | 283 | if ( fli ) { |
269 | emit fontSelected ( m_fdb. font ( fli-> family ( ), \ | 284 | return m_fdb. font ( fli-> family ( ), \ |
270 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | 285 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ |
271 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | 286 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ |
272 | m_fdb. charSets ( fli-> family ( )) [0] )); | 287 | m_fdb. charSets ( fli-> family ( )) [0] ); |
273 | } | 288 | } |
289 | else | ||
290 | return QFont ( ); | ||
274 | } | 291 | } |
275 | 292 | ||
276 | 293 | ||
277 | \ No newline at end of file | 294 | \ No newline at end of file |