Diffstat (limited to 'noncore/settings/appearance2/appearance.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/appearance2/appearance.cpp | 174 |
1 files changed, 25 insertions, 149 deletions
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp index cf3069e..23630c5 100644 --- a/noncore/settings/appearance2/appearance.cpp +++ b/noncore/settings/appearance2/appearance.cpp | |||
@@ -69,18 +69,10 @@ | |||
69 | #include "stylelistitem.h" | 69 | #include "stylelistitem.h" |
70 | #include "decolistitem.h" | 70 | #include "decolistitem.h" |
71 | #include "fontlistitem.h" | ||
72 | #include "colorlistitem.h" | 71 | #include "colorlistitem.h" |
73 | 72 | ||
74 | #include "sample.h" | 73 | #include "sample.h" |
75 | 74 | ||
75 | #include <opie/ofontselector.h> | ||
76 | 76 | ||
77 | static int findItemCB ( QComboBox *box, const QString &str ) | ||
78 | { | ||
79 | for ( int i = 0; i < box-> count ( ); i++ ) { | ||
80 | if ( box-> text ( i ) == str ) | ||
81 | return i; | ||
82 | } | ||
83 | return -1; | ||
84 | } | ||
85 | 77 | ||
86 | class DefaultWindowDecoration : public WindowDecorationInterface | 78 | class DefaultWindowDecoration : public WindowDecorationInterface |
@@ -193,13 +185,4 @@ void Appearance::loadColors ( QListBox *list ) | |||
193 | } | 185 | } |
194 | 186 | ||
195 | void Appearance::loadFonts ( QListBox *list ) | ||
196 | { | ||
197 | FontDatabase fd; | ||
198 | QStringList f = fd. families ( ); | ||
199 | |||
200 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) | ||
201 | list-> insertItem ( new FontListItem ( *it, fd. styles ( *it ), fd. pointSizes ( *it ))); | ||
202 | } | ||
203 | |||
204 | 187 | ||
205 | QWidget *Appearance::createStyleTab ( QWidget *parent ) | 188 | QWidget *Appearance::createStyleTab ( QWidget *parent ) |
@@ -260,50 +243,15 @@ QWidget *Appearance::createFontTab ( QWidget *parent ) | |||
260 | config. setGroup ( "Appearance" ); | 243 | config. setGroup ( "Appearance" ); |
261 | 244 | ||
262 | |||
263 | QWidget *tab = new QWidget( parent, "FontTab" ); | ||
264 | QGridLayout *gridLayout = new QGridLayout ( tab, 0, 0, 4, 4 ); | ||
265 | gridLayout->setRowStretch ( 4, 10 ); | ||
266 | |||
267 | m_font_family_list = new QListBox( tab, "FontListBox" ); | ||
268 | gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 ); | ||
269 | connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); | ||
270 | |||
271 | QLabel *label = new QLabel( tr( "Style" ), tab ); | ||
272 | gridLayout->addWidget( label, 0, 1 ); | ||
273 | |||
274 | m_font_style_list = new QComboBox( tab, "StyleListBox" ); | ||
275 | connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); | ||
276 | gridLayout->addWidget( m_font_style_list, 1, 1 ); | ||
277 | |||
278 | label = new QLabel( tr( "Size" ), tab ); | ||
279 | gridLayout->addWidget( label, 2, 1 ); | ||
280 | |||
281 | m_font_size_list = new QComboBox( tab, "SizeListBox" ); | ||
282 | connect( m_font_size_list, SIGNAL( activated( int ) ), | ||
283 | this, SLOT( fontSizeClicked( int ) ) ); | ||
284 | gridLayout->addWidget( m_font_size_list, 3, 1 ); | ||
285 | |||
286 | loadFonts ( m_font_family_list ); | ||
287 | |||
288 | QString familyStr = config.readEntry( "FontFamily", "Helvetica" ); | 245 | QString familyStr = config.readEntry( "FontFamily", "Helvetica" ); |
289 | QString styleStr = config.readEntry( "FontStyle", "Regular" ); | 246 | QString styleStr = config.readEntry( "FontStyle", "Regular" ); |
290 | QString sizeStr = config.readEntry( "FontSize", "10" ); | 247 | int size = config.readNumEntry( "FontSize", 10 ); |
291 | 248 | ||
292 | m_font_family_list-> setCurrentItem ( m_font_family_list-> findItem ( familyStr )); | 249 | m_fontselect = new OFontSelector ( parent, "FontTab" ); |
293 | m_original_fontfamily = m_font_family_list-> currentItem ( ); | 250 | m_fontselect-> setSelectedFont ( familyStr, styleStr, size ); |
294 | if ( m_font_family_list-> currentItem ( ) < 0 ) | ||
295 | m_font_family_list-> setCurrentItem ( 0 ); | ||
296 | 251 | ||
297 | fontFamilyClicked ( m_original_fontfamily ); | 252 | connect( m_fontselect, SIGNAL( fontSelected ( const QFont & )), |
253 | this, SLOT( fontClicked ( const QFont & ))); | ||
298 | 254 | ||
299 | m_font_style_list-> setCurrentItem ( findItemCB ( m_font_style_list, styleStr )); | 255 | return m_fontselect; |
300 | m_original_fontstyle = m_font_style_list-> currentItem ( ); | ||
301 | fontStyleClicked ( m_original_fontstyle ); | ||
302 | |||
303 | m_font_size_list-> setCurrentItem ( findItemCB ( m_font_size_list, sizeStr )); | ||
304 | m_original_fontsize = m_font_size_list-> currentItem ( ); | ||
305 | fontSizeClicked ( m_original_fontsize ); | ||
306 | |||
307 | return tab; | ||
308 | } | 256 | } |
309 | 257 | ||
@@ -353,5 +301,6 @@ QWidget *Appearance::createGuiTab ( QWidget *parent ) | |||
353 | QGridLayout* gridLayout = new QGridLayout ( vertLayout ); | 301 | QGridLayout* gridLayout = new QGridLayout ( vertLayout ); |
354 | 302 | ||
355 | int style = config. readNumEntry ( "TabStyle", 2 ); | 303 | int style = config. readNumEntry ( "TabStyle", 2 ) - 1; |
304 | bool tabtop = ( config. readEntry ( "TabPosition", "Top" ) == "Top" ); | ||
356 | 305 | ||
357 | QLabel* label = new QLabel( tr( "Tab style:" ), tab ); | 306 | QLabel* label = new QLabel( tr( "Tab style:" ), tab ); |
@@ -366,5 +315,5 @@ QWidget *Appearance::createGuiTab ( QWidget *parent ) | |||
366 | m_tabstyle_list-> insertItem ( tr( "Drop down list" )); | 315 | m_tabstyle_list-> insertItem ( tr( "Drop down list" )); |
367 | m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" )); | 316 | m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" )); |
368 | m_tabstyle_list-> setCurrentItem ( style & 0xff ); | 317 | m_tabstyle_list-> setCurrentItem ( style ); |
369 | gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 ); | 318 | gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 ); |
370 | 319 | ||
@@ -374,12 +323,12 @@ QWidget *Appearance::createGuiTab ( QWidget *parent ) | |||
374 | 323 | ||
375 | m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" ); | 324 | m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" ); |
376 | btngrp-> insert ( m_tabstyle_top ); | 325 | btngrp-> insert ( m_tabstyle_bottom ); |
377 | gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 ); | 326 | gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 ); |
378 | 327 | ||
379 | bool tabtop = ( style & 0xff00 ) == 0; | ||
380 | m_tabstyle_top-> setChecked ( tabtop ); | 328 | m_tabstyle_top-> setChecked ( tabtop ); |
381 | m_tabstyle_bottom-> setChecked ( !tabtop ); | 329 | m_tabstyle_bottom-> setChecked ( !tabtop ); |
382 | 330 | ||
383 | m_original_tabstyle = style; | 331 | m_original_tabstyle = style; |
332 | m_original_tabpos = tabtop; | ||
384 | 333 | ||
385 | return tab; | 334 | return tab; |
@@ -424,25 +373,23 @@ void Appearance::accept ( ) | |||
424 | config.setGroup( "Appearance" ); | 373 | config.setGroup( "Appearance" ); |
425 | 374 | ||
426 | int newstyle = m_style_list-> currentItem ( ); | 375 | int newtabstyle = m_tabstyle_list-> currentItem ( ); |
427 | int newtabstyle = ( m_tabstyle_list-> currentItem ( ) & 0xff ) | \ | 376 | bool newtabpos = m_tabstyle_top-> isChecked ( ); |
428 | ( m_tabstyle_top-> isChecked ( ) ? 0x000 : 0x100 ); | ||
429 | int newfontfamily = m_font_family_list-> currentItem ( ); | ||
430 | int newfontstyle = m_font_style_list-> currentItem ( ); | ||
431 | int newfontsize = m_font_size_list-> currentItem ( ); | ||
432 | 377 | ||
433 | 378 | ||
434 | if ( m_style_changed ) { | 379 | if ( m_style_changed ) { |
435 | StyleListItem *item = (StyleListItem *) m_style_list-> item ( newstyle ); | 380 | StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( )); |
436 | if ( item ) | 381 | if ( item ) |
437 | config.writeEntry( "Style", item-> key ( )); | 382 | config.writeEntry( "Style", item-> key ( )); |
438 | } | 383 | } |
439 | if ( newtabstyle != m_original_tabstyle ) { | 384 | |
440 | config. writeEntry ( "TabStyle", newtabstyle ); | 385 | if (( newtabstyle != m_original_tabstyle ) || ( newtabpos != m_original_tabpos )) { |
386 | config. writeEntry ( "TabStyle", newtabstyle + 1 ); | ||
387 | config. writeEntry ( "TabPosition", newtabpos ? "Top" : "Bottom" ); | ||
441 | } | 388 | } |
442 | 389 | ||
443 | if ( m_font_changed ) { | 390 | if ( m_font_changed ) { |
444 | config.writeEntry( "FontFamily", m_font_family_list-> text ( newfontfamily )); | 391 | config. writeEntry ( "FontFamily", m_fontselect-> fontFamily ( )); |
445 | config.writeEntry( "FontStyle", m_font_style_list-> text ( newfontstyle )); | 392 | config. writeEntry ( "FontStyle", m_fontselect-> fontStyle ( )); |
446 | config.writeEntry( "FontSize", m_font_size_list-> text ( newfontsize )); | 393 | config. writeEntry ( "FontSize", m_fontselect-> fontSize ( )); |
447 | } | 394 | } |
448 | 395 | ||
@@ -522,79 +469,8 @@ void Appearance::decoClicked ( int index ) | |||
522 | } | 469 | } |
523 | 470 | ||
524 | void Appearance::fontFamilyClicked ( int index ) | 471 | void Appearance::fontClicked ( const QFont &f ) |
525 | { | 472 | { |
526 | QString oldstyle = m_font_style_list-> currentText ( ); | 473 | m_font_changed |= ( f != m_sample-> font ( )); |
527 | QString oldsize = m_font_size_list-> currentText ( ); | 474 | m_sample-> setFont ( f ); |
528 | |||
529 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index ); | ||
530 | |||
531 | m_font_style_list-> clear ( ); | ||
532 | m_font_style_list-> insertStringList ( fli-> styles ( )); | ||
533 | m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( )); | ||
534 | |||
535 | int i; | ||
536 | |||
537 | i = findItemCB ( m_font_style_list, oldstyle ); | ||
538 | if ( i < 0 ) | ||
539 | i = findItemCB ( m_font_style_list, "Regular" ); | ||
540 | if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 )) | ||
541 | i = 0; | ||
542 | |||
543 | if ( i >= 0 ) { | ||
544 | m_font_style_list-> setCurrentItem ( i ); | ||
545 | fontStyleClicked ( i ); | ||
546 | } | ||
547 | |||
548 | m_font_size_list-> clear ( ); | ||
549 | QValueList<int> sl = fli-> sizes ( ); | ||
550 | |||
551 | for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) | ||
552 | m_font_size_list-> insertItem ( QString::number ( *it )); | ||
553 | |||
554 | i = findItemCB ( m_font_size_list, oldsize ); | ||
555 | if ( i < 0 ) | ||
556 | i = findItemCB ( m_font_size_list, "10" ); | ||
557 | if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 )) | ||
558 | i = 0; | ||
559 | |||
560 | if ( i >= 0 ) { | ||
561 | m_font_size_list-> setCurrentItem ( i ); | ||
562 | fontSizeClicked ( i ); | ||
563 | } | ||
564 | changeText ( ); | ||
565 | |||
566 | m_font_changed |= ( index != m_original_fontfamily ); | ||
567 | } | ||
568 | |||
569 | void Appearance::fontStyleClicked ( int index ) | ||
570 | { | ||
571 | changeText ( ); | ||
572 | |||
573 | m_font_changed |= ( index != m_original_fontstyle ); | ||
574 | } | ||
575 | |||
576 | void Appearance::fontSizeClicked ( int index ) | ||
577 | { | ||
578 | changeText ( ); | ||
579 | |||
580 | m_font_changed |= ( index != m_original_fontsize ); | ||
581 | } | ||
582 | |||
583 | void Appearance::changeText ( ) | ||
584 | { | ||
585 | int ffa = m_font_family_list-> currentItem ( ); | ||
586 | int fst = m_font_style_list-> currentItem ( ); | ||
587 | int fsi = m_font_size_list-> currentItem ( ); | ||
588 | |||
589 | FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa ); | ||
590 | |||
591 | if ( fli ) { | ||
592 | FontDatabase fdb; | ||
593 | |||
594 | m_sample-> setFont ( fdb. font ( fli-> family ( ), \ | ||
595 | fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \ | ||
596 | fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \ | ||
597 | fdb. charSets ( fli-> family ( )) [0] )); | ||
598 | } | ||
599 | } | 475 | } |
600 | 476 | ||