-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 | |||
@@ -40,3 +40,3 @@ | |||
40 | class OFontSelectorPrivate { | 40 | class OFontSelectorPrivate { |
41 | public: | 41 | public: |
42 | QListBox * m_font_family_list; | 42 | QListBox * m_font_family_list; |
@@ -46,3 +46,3 @@ public: | |||
46 | 46 | ||
47 | bool m_pointbug; | 47 | bool m_pointbug : 1; |
48 | 48 | ||
@@ -51,2 +51,3 @@ public: | |||
51 | 51 | ||
52 | namespace { | ||
52 | 53 | ||
@@ -59,3 +60,3 @@ public: | |||
59 | m_sizes = sizes; | 60 | m_sizes = sizes; |
60 | 61 | ||
61 | QString str = t; | 62 | QString str = t; |
@@ -69,3 +70,3 @@ public: | |||
69 | } | 70 | } |
70 | 71 | ||
71 | const QStringList &styles ( ) const | 72 | const QStringList &styles ( ) const |
@@ -74,3 +75,3 @@ public: | |||
74 | } | 75 | } |
75 | 76 | ||
76 | const QValueList<int> &sizes ( ) const | 77 | const QValueList<int> &sizes ( ) const |
@@ -79,3 +80,3 @@ public: | |||
79 | } | 80 | } |
80 | 81 | ||
81 | private: | 82 | private: |
@@ -96,3 +97,4 @@ static int findItemCB ( QComboBox *box, const QString &str ) | |||
96 | 97 | ||
97 | 98 | } | |
99 | /* static same as anon. namespace */ | ||
98 | static int qt_version ( ) | 100 | static int qt_version ( ) |
@@ -104,3 +106,9 @@ static int qt_version ( ) | |||
104 | 106 | ||
105 | 107 | /** | |
108 | * Constructs the Selector object | ||
109 | * @param withpreview If a font preview should be given | ||
110 | * @param parent The parent of the Font Selector | ||
111 | * @param name The name of the object | ||
112 | * @param fl WidgetFlags | ||
113 | */ | ||
106 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) | 114 | OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) |
@@ -137,3 +145,3 @@ OFontSelector::OFontSelector ( bool withpreview, QWidget *parent, const char *na | |||
137 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); | 145 | d-> m_preview-> setWordWrap ( QMultiLineEdit::WidgetWidth ); |
138 | d-> m_preview-> setMargin ( 3 ); | 146 | d-> m_preview-> setMargin ( 3 ); |
139 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); | 147 | d-> m_preview-> setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); |
@@ -154,2 +162,7 @@ OFontSelector::~OFontSelector ( ) | |||
154 | 162 | ||
163 | /** | ||
164 | * This methods tries to set the font | ||
165 | * @param f The wishes font | ||
166 | * @return success or failure | ||
167 | */ | ||
155 | bool OFontSelector::setSelectedFont ( const QFont &f ) | 168 | bool OFontSelector::setSelectedFont ( const QFont &f ) |
@@ -159,3 +172,11 @@ bool OFontSelector::setSelectedFont ( const QFont &f ) | |||
159 | 172 | ||
160 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & /*charset*/ ) | 173 | |
174 | /** | ||
175 | * This is an overloaded method @see setSelectedFont | ||
176 | * @param familyStr The family of the font | ||
177 | * @param styleStr The style of the font | ||
178 | * @param sizeVal The size of font | ||
179 | * @param charset The charset to be used. Will be deprecated by QT3 | ||
180 | */ | ||
181 | bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) | ||
161 | { | 182 | { |
@@ -168,3 +189,3 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s | |||
168 | family = d-> m_font_family_list-> firstItem ( ); | 189 | family = d-> m_font_family_list-> firstItem ( ); |
169 | d-> m_font_family_list-> setCurrentItem ( family ); | 190 | d-> m_font_family_list-> setCurrentItem ( family ); |
170 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); | 191 | fontFamilyClicked ( d-> m_font_family_list-> index ( family )); |
@@ -186,3 +207,3 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s | |||
186 | fontSizeClicked ( size ); | 207 | fontSizeClicked ( size ); |
187 | 208 | ||
188 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); | 209 | return (( family ) && ( style >= 0 ) && ( size >= 0 )); |
@@ -190,2 +211,10 @@ bool OFontSelector::setSelectedFont ( const QString &familyStr, const QString &s | |||
190 | 211 | ||
212 | /** | ||
213 | * This method returns the name, style and size of the currently selected | ||
214 | * font or false if no font is selected | ||
215 | * @param family The font family will be written there | ||
216 | * @param style The style will be written there | ||
217 | * @param size The size will be written there | ||
218 | * @return success or failure | ||
219 | */ | ||
191 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | 220 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) |
@@ -197,2 +226,7 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) | |||
197 | 226 | ||
227 | /** | ||
228 | * This method does return the font family or QString::null if there is | ||
229 | * no font item selected | ||
230 | * @return the font family | ||
231 | */ | ||
198 | QString OFontSelector::fontFamily ( ) const | 232 | QString OFontSelector::fontFamily ( ) const |
@@ -200,3 +234,3 @@ QString OFontSelector::fontFamily ( ) const | |||
200 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 234 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
201 | 235 | ||
202 | return fli ? fli-> family ( ) : QString::null; | 236 | return fli ? fli-> family ( ) : QString::null; |
@@ -204,2 +238,6 @@ QString OFontSelector::fontFamily ( ) const | |||
204 | 238 | ||
239 | /** | ||
240 | * This method will return the style of the font or QString::null | ||
241 | * @return the style of the font | ||
242 | */ | ||
205 | QString OFontSelector::fontStyle ( ) const | 243 | QString OFontSelector::fontStyle ( ) const |
@@ -207,3 +245,3 @@ QString OFontSelector::fontStyle ( ) const | |||
207 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 245 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
208 | int fst = d-> m_font_style_list-> currentItem ( ); | 246 | int fst = d-> m_font_style_list-> currentItem ( ); |
209 | 247 | ||
@@ -212,2 +250,5 @@ QString OFontSelector::fontStyle ( ) const | |||
212 | 250 | ||
251 | /** | ||
252 | * This method will return the font size or 10 if no font size is available | ||
253 | */ | ||
213 | int OFontSelector::fontSize ( ) const | 254 | int OFontSelector::fontSize ( ) const |
@@ -215,3 +256,3 @@ int OFontSelector::fontSize ( ) const | |||
215 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); | 256 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( d-> m_font_family_list-> currentItem ( )); |
216 | int fsi = d-> m_font_size_list-> currentItem ( ); | 257 | int fsi = d-> m_font_size_list-> currentItem ( ); |
217 | 258 | ||
@@ -220,2 +261,5 @@ int OFontSelector::fontSize ( ) const | |||
220 | 261 | ||
262 | /** | ||
263 | * returns the charset of the font or QString::null | ||
264 | */ | ||
221 | QString OFontSelector::fontCharSet ( ) const | 265 | QString OFontSelector::fontCharSet ( ) const |
@@ -227,2 +271,6 @@ QString OFontSelector::fontCharSet ( ) const | |||
227 | 271 | ||
272 | /** | ||
273 | * Overloaded member function see above | ||
274 | * @see selectedFont | ||
275 | */ | ||
228 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) | 276 | bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) |
@@ -230,7 +278,7 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, Q | |||
230 | int ffa = d-> m_font_family_list-> currentItem ( ); | 278 | int ffa = d-> m_font_family_list-> currentItem ( ); |
231 | int fst = d-> m_font_style_list-> currentItem ( ); | 279 | int fst = d-> m_font_style_list-> currentItem ( ); |
232 | int fsi = d-> m_font_size_list-> currentItem ( ); | 280 | int fsi = d-> m_font_size_list-> currentItem ( ); |
233 | 281 | ||
234 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 282 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
235 | 283 | ||
236 | if ( fli ) { | 284 | if ( fli ) { |
@@ -248,3 +296,3 @@ bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, Q | |||
248 | 296 | ||
249 | 297 | ||
250 | 298 | ||
@@ -253,6 +301,6 @@ void OFontSelector::loadFonts ( QListBox *list ) | |||
253 | QStringList f = d-> m_fdb. families ( ); | 301 | QStringList f = d-> m_fdb. families ( ); |
254 | 302 | ||
255 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { | 303 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) { |
256 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); | 304 | QValueList <int> ps = d-> m_fdb. pointSizes ( *it ); |
257 | 305 | ||
258 | if ( d-> m_pointbug ) { | 306 | if ( d-> m_pointbug ) { |
@@ -261,3 +309,3 @@ void OFontSelector::loadFonts ( QListBox *list ) | |||
261 | } | 309 | } |
262 | 310 | ||
263 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); | 311 | list-> insertItem ( new FontListItem ( *it, d-> m_fdb. styles ( *it ), ps )); |
@@ -270,6 +318,6 @@ void OFontSelector::fontFamilyClicked ( int index ) | |||
270 | QString oldsize = d-> m_font_size_list-> currentText ( ); | 318 | QString oldsize = d-> m_font_size_list-> currentText ( ); |
271 | 319 | ||
272 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); | 320 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( index ); |
273 | 321 | ||
274 | d-> m_font_style_list-> clear ( ); | 322 | d-> m_font_style_list-> clear ( ); |
275 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); | 323 | d-> m_font_style_list-> insertStringList ( fli-> styles ( )); |
@@ -278,3 +326,3 @@ void OFontSelector::fontFamilyClicked ( int index ) | |||
278 | int i; | 326 | int i; |
279 | 327 | ||
280 | i = findItemCB ( d-> m_font_style_list, oldstyle ); | 328 | i = findItemCB ( d-> m_font_style_list, oldstyle ); |
@@ -284,12 +332,12 @@ void OFontSelector::fontFamilyClicked ( int index ) | |||
284 | i = 0; | 332 | i = 0; |
285 | 333 | ||
286 | if ( i >= 0 ) { | 334 | if ( i >= 0 ) { |
287 | d-> m_font_style_list-> setCurrentItem ( i ); | 335 | d-> m_font_style_list-> setCurrentItem ( i ); |
288 | fontStyleClicked ( i ); | 336 | fontStyleClicked ( i ); |
289 | } | 337 | } |
290 | 338 | ||
291 | d-> m_font_size_list-> clear ( ); | 339 | d-> m_font_size_list-> clear ( ); |
292 | QValueList<int> sl = fli-> sizes ( ); | 340 | QValueList<int> sl = fli-> sizes ( ); |
293 | 341 | ||
294 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | 342 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) |
295 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); | 343 | d-> m_font_size_list-> insertItem ( QString::number ( *it )); |
@@ -301,8 +349,8 @@ void OFontSelector::fontFamilyClicked ( int index ) | |||
301 | i = 0; | 349 | i = 0; |
302 | 350 | ||
303 | if ( i >= 0 ) { | 351 | if ( i >= 0 ) { |
304 | d-> m_font_size_list-> setCurrentItem ( i ); | 352 | d-> m_font_size_list-> setCurrentItem ( i ); |
305 | fontSizeClicked ( i ); | 353 | fontSizeClicked ( i ); |
306 | } | 354 | } |
307 | changeFont ( ); | 355 | changeFont ( ); |
308 | } | 356 | } |
@@ -311,3 +359,3 @@ void OFontSelector::fontStyleClicked ( int /*index*/ ) | |||
311 | { | 359 | { |
312 | changeFont ( ); | 360 | changeFont ( ); |
313 | } | 361 | } |
@@ -329,3 +377,5 @@ void OFontSelector::changeFont ( ) | |||
329 | 377 | ||
330 | 378 | /** | |
379 | * Return the selected font | ||
380 | */ | ||
331 | QFont OFontSelector::selectedFont ( ) | 381 | QFont OFontSelector::selectedFont ( ) |
@@ -333,7 +383,7 @@ QFont OFontSelector::selectedFont ( ) | |||
333 | int ffa = d-> m_font_family_list-> currentItem ( ); | 383 | int ffa = d-> m_font_family_list-> currentItem ( ); |
334 | int fst = d-> m_font_style_list-> currentItem ( ); | 384 | int fst = d-> m_font_style_list-> currentItem ( ); |
335 | int fsi = d-> m_font_size_list-> currentItem ( ); | 385 | int fsi = d-> m_font_size_list-> currentItem ( ); |
336 | 386 | ||
337 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); | 387 | FontListItem *fli = (FontListItem *) d-> m_font_family_list-> item ( ffa ); |
338 | 388 | ||
339 | if ( fli ) { | 389 | if ( fli ) { |
@@ -357,6 +407,6 @@ void OFontSelector::resizeEvent ( QResizeEvent *re ) | |||
357 | QWidget::resizeEvent ( re ); | 407 | QWidget::resizeEvent ( re ); |
358 | 408 | ||
359 | if ( d-> m_preview ) | 409 | if ( d-> m_preview ) |
360 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); | 410 | d-> m_preview-> setFixedHeight ( d-> m_preview-> height ( )); |
361 | 411 | ||
362 | } | 412 | } |