Diffstat (limited to 'noncore/settings/appearance2/appearance.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/appearance2/appearance.cpp | 99 |
1 files changed, 39 insertions, 60 deletions
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp index 52c7125..cf3069e 100644 --- a/noncore/settings/appearance2/appearance.cpp +++ b/noncore/settings/appearance2/appearance.cpp | |||
@@ -102,40 +102,24 @@ public: | |||
102 | 102 | ||
103 | if ( *iface ) | 103 | if ( *iface ) |
104 | (*iface)->addRef(); | 104 | (*iface)->addRef(); |
105 | return QS_OK; | 105 | return QS_OK; |
106 | } | 106 | } |
107 | Q_REFCOUNT | 107 | Q_REFCOUNT |
108 | 108 | ||
109 | private: | 109 | private: |
110 | ulong ref; | 110 | ulong ref; |
111 | }; | 111 | }; |
112 | 112 | ||
113 | 113 | ||
114 | struct { | ||
115 | QColorGroup::ColorRole role; | ||
116 | const char *key; | ||
117 | const char *def; | ||
118 | } colorLUT [] = { | ||
119 | { QColorGroup::Base, "Base", "#FFFFFF" }, | ||
120 | { QColorGroup::Background, "Background", "#E5E1D5" }, | ||
121 | { QColorGroup::Button, "Button", "#D6CDBB" }, | ||
122 | { QColorGroup::ButtonText, "ButtonText", "#000000" }, | ||
123 | { QColorGroup::Highlight, "Highlight", "#800000" }, | ||
124 | { QColorGroup::HighlightedText, "HighlightedText", "#FFFFFF" }, | ||
125 | { QColorGroup::Text, "Text", "#000000" }, | ||
126 | |||
127 | { QColorGroup::NColorRoles, 0, 0 } | ||
128 | }; | ||
129 | |||
130 | 114 | ||
131 | void Appearance::loadStyles ( QListBox *list ) | 115 | void Appearance::loadStyles ( QListBox *list ) |
132 | { | 116 | { |
133 | #if QT_VERSION >= 300 | 117 | #if QT_VERSION >= 300 |
134 | list->insertStringList(QStyleFactory::styles()); | 118 | list->insertStringList(QStyleFactory::styles()); |
135 | #else | 119 | #else |
136 | list->insertItem( new StyleListItem ( "Windows", new QWindowsStyle ( ))); | 120 | list->insertItem( new StyleListItem ( "Windows", new QWindowsStyle ( ))); |
137 | list->insertItem( new StyleListItem ( "Light", new LightStyle ( ))); | 121 | list->insertItem( new StyleListItem ( "Light", new LightStyle ( ))); |
138 | #ifndef QT_NO_STYLE_MOTIF | 122 | #ifndef QT_NO_STYLE_MOTIF |
139 | list->insertItem( new StyleListItem ( "Motif", new QMotifStyle ( ))); | 123 | list->insertItem( new StyleListItem ( "Motif", new QMotifStyle ( ))); |
140 | #endif | 124 | #endif |
141 | #ifndef QT_NO_STYLE_MOTIFPLUS | 125 | #ifndef QT_NO_STYLE_MOTIFPLUS |
@@ -177,65 +161,43 @@ void Appearance::loadDecos ( QListBox *list ) | |||
177 | for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { | 161 | for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { |
178 | QLibrary *lib = new QLibrary ( path + "/" + *it ); | 162 | QLibrary *lib = new QLibrary ( path + "/" + *it ); |
179 | WindowDecorationInterface *iface; | 163 | WindowDecorationInterface *iface; |
180 | 164 | ||
181 | if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK ) | 165 | if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK ) |
182 | list-> insertItem ( new DecoListItem ( lib, iface )); | 166 | list-> insertItem ( new DecoListItem ( lib, iface )); |
183 | else | 167 | else |
184 | delete lib; | 168 | delete lib; |
185 | } | 169 | } |
186 | } | 170 | } |
187 | } | 171 | } |
188 | 172 | ||
189 | static QPalette readColorPalette ( Config &config ) | ||
190 | { | ||
191 | QColor bgcolor( config. readEntry( "Background", "#E5E1D5" ) ); | ||
192 | QColor btncolor( config. readEntry( "Button", "#D6CDBB" ) ); | ||
193 | QPalette pal( btncolor, bgcolor ); | ||
194 | |||
195 | QString color = config. readEntry( "Highlight", "#800000" ); | ||
196 | pal.setColor( QColorGroup::Highlight, QColor(color) ); | ||
197 | color = config. readEntry( "HighlightedText", "#FFFFFF" ); | ||
198 | pal.setColor( QColorGroup::HighlightedText, QColor(color) ); | ||
199 | color = config. readEntry( "Text", "#000000" ); | ||
200 | pal.setColor( QColorGroup::Text, QColor(color) ); | ||
201 | color = config. readEntry( "ButtonText", "#000000" ); | ||
202 | pal.setColor( QPalette::Active, QColorGroup::ButtonText, QColor(color) ); | ||
203 | color = config. readEntry( "Base", "#FFFFFF" ); | ||
204 | pal.setColor( QColorGroup::Base, QColor(color) ); | ||
205 | |||
206 | pal.setColor( QPalette::Disabled, QColorGroup::Text, pal.color(QPalette::Active, QColorGroup::Background).dark() ); | ||
207 | |||
208 | return pal; | ||
209 | } | ||
210 | |||
211 | void Appearance::loadColors ( QListBox *list ) | 173 | void Appearance::loadColors ( QListBox *list ) |
212 | { | 174 | { |
213 | list-> clear ( ); | 175 | list-> clear ( ); |
214 | { | 176 | { |
215 | Config config ( "qpe" ); | 177 | Config config ( "qpe" ); |
216 | config. setGroup ( "Appearance" ); | 178 | config. setGroup ( "Appearance" ); |
217 | 179 | ||
218 | list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), readColorPalette ( config ))); | 180 | list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), config )); |
219 | } | 181 | } |
220 | 182 | ||
221 | QString path = QPEApplication::qpeDir ( ) + "/etc/colors/"; | 183 | QString path = QPEApplication::qpeDir ( ) + "/etc/colors/"; |
222 | QStringList sl = QDir ( path ). entryList ( "*.scheme" ); | 184 | QStringList sl = QDir ( path ). entryList ( "*.scheme" ); |
223 | 185 | ||
224 | for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { | 186 | for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) { |
225 | QString name = (*it). left ((*it). find ( ".scheme" )); | 187 | QString name = (*it). left ((*it). find ( ".scheme" )); |
226 | Config config ( path + *it, Config::File ); | 188 | Config config ( path + *it, Config::File ); |
227 | config. setGroup ( "Colors" ); | 189 | config. setGroup ( "Colors" ); |
228 | 190 | ||
229 | list-> insertItem ( new ColorListItem ( name, readColorPalette ( config ))); | 191 | list-> insertItem ( new ColorListItem ( name, config )); |
230 | } | 192 | } |
231 | } | 193 | } |
232 | 194 | ||
233 | void Appearance::loadFonts ( QListBox *list ) | 195 | void Appearance::loadFonts ( QListBox *list ) |
234 | { | 196 | { |
235 | FontDatabase fd; | 197 | FontDatabase fd; |
236 | QStringList f = fd. families ( ); | 198 | QStringList f = fd. families ( ); |
237 | 199 | ||
238 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) | 200 | for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it ) |
239 | list-> insertItem ( new FontListItem ( *it, fd. styles ( *it ), fd. pointSizes ( *it ))); | 201 | list-> insertItem ( new FontListItem ( *it, fd. styles ( *it ), fd. pointSizes ( *it ))); |
240 | } | 202 | } |
241 | 203 | ||
@@ -475,34 +437,33 @@ void Appearance::accept ( ) | |||
475 | config.writeEntry( "Style", item-> key ( )); | 437 | config.writeEntry( "Style", item-> key ( )); |
476 | } | 438 | } |
477 | if ( newtabstyle != m_original_tabstyle ) { | 439 | if ( newtabstyle != m_original_tabstyle ) { |
478 | config. writeEntry ( "TabStyle", newtabstyle ); | 440 | config. writeEntry ( "TabStyle", newtabstyle ); |
479 | } | 441 | } |
480 | 442 | ||
481 | if ( m_font_changed ) { | 443 | if ( m_font_changed ) { |
482 | config.writeEntry( "FontFamily", m_font_family_list-> text ( newfontfamily )); | 444 | config.writeEntry( "FontFamily", m_font_family_list-> text ( newfontfamily )); |
483 | config.writeEntry( "FontStyle", m_font_style_list-> text ( newfontstyle )); | 445 | config.writeEntry( "FontStyle", m_font_style_list-> text ( newfontstyle )); |
484 | config.writeEntry( "FontSize", m_font_size_list-> text ( newfontsize )); | 446 | config.writeEntry( "FontSize", m_font_size_list-> text ( newfontsize )); |
485 | } | 447 | } |
486 | 448 | ||
487 | /* | 449 | |
488 | if ( schemeChanged ) | 450 | if ( m_color_changed ) |
489 | { | ||
490 | int i; | ||
491 | for ( i = 0; i < MAX_CONTROL; i++ ) | ||
492 | { | 451 | { |
493 | config.writeEntry( controlList[i], controlColor[i] ); | 452 | ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); |
494 | } | 453 | |
454 | if ( item ) | ||
455 | item-> save ( config ); | ||
495 | } | 456 | } |
496 | */ | 457 | |
497 | config. write ( ); // need to flush the config info first | 458 | config. write ( ); // need to flush the config info first |
498 | Global::applyStyle ( ); | 459 | Global::applyStyle ( ); |
499 | 460 | ||
500 | if ( QMessageBox::warning ( this, tr( "Restart" ), tr( "Do you want to restart Opie now?" ), tr( "Yes" ), tr( "No" ), 0, 0, 1 ) == 0 ) { | 461 | if ( QMessageBox::warning ( this, tr( "Restart" ), tr( "Do you want to restart Opie now?" ), tr( "Yes" ), tr( "No" ), 0, 0, 1 ) == 0 ) { |
501 | QCopEnvelope e( "QPE/System", "restart()" ); | 462 | QCopEnvelope e( "QPE/System", "restart()" ); |
502 | } | 463 | } |
503 | 464 | ||
504 | QDialog::accept ( ); | 465 | QDialog::accept ( ); |
505 | } | 466 | } |
506 | 467 | ||
507 | void Appearance::done ( int r ) | 468 | void Appearance::done ( int r ) |
508 | { | 469 | { |
@@ -643,39 +604,58 @@ void Appearance::colorClicked ( int index ) | |||
643 | 604 | ||
644 | if ( item ) | 605 | if ( item ) |
645 | m_sample-> setPalette ( item-> palette ( )); | 606 | m_sample-> setPalette ( item-> palette ( )); |
646 | 607 | ||
647 | m_color_changed |= ( item-> palette ( ) != qApp-> palette ( )); | 608 | m_color_changed |= ( item-> palette ( ) != qApp-> palette ( )); |
648 | } | 609 | } |
649 | 610 | ||
650 | 611 | ||
651 | void Appearance::editSchemeClicked ( ) | 612 | void Appearance::editSchemeClicked ( ) |
652 | { | 613 | { |
653 | ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); | 614 | ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); |
654 | 615 | ||
655 | /* | 616 | int cnt = 0; |
656 | EditScheme* editdlg = new EditScheme( this, "editScheme", TRUE, 0, | 617 | QString controlLabel [QColorGroup::NColorRoles]; |
657 | 9, controlLabel, controlColor ); | 618 | QString controlColor [QColorGroup::NColorRoles]; |
619 | |||
620 | for ( QColorGroup::ColorRole role = (QColorGroup::ColorRole) 0; role != QColorGroup::NColorRoles; ((int) role )++ ) { | ||
621 | QColor col = item-> color ( role ); | ||
622 | |||
623 | if ( col. isValid ( )) { | ||
624 | controlLabel [cnt] = item-> label ( role ); | ||
625 | controlColor [cnt] = col. name ( ); | ||
626 | |||
627 | cnt++; | ||
628 | } | ||
629 | } | ||
630 | |||
631 | EditScheme* editdlg = new EditScheme( this, "editScheme", true, 0, cnt, controlLabel, controlColor ); | ||
658 | editdlg->showMaximized(); | 632 | editdlg->showMaximized(); |
659 | if ( editdlg->exec() == QDialog::Accepted ) | 633 | if ( editdlg-> exec ( ) == QDialog::Accepted ) { |
660 | { | 634 | ColorListItem *citem = (ColorListItem *) m_color_list-> item ( 0 ); |
661 | int i; | 635 | cnt = 0; |
662 | for ( i = 0; i < MAX_CONTROL; i++ ) | 636 | |
663 | { | 637 | for ( QColorGroup::ColorRole role = (QColorGroup::ColorRole) 0; role != QColorGroup::NColorRoles; ((int) role )++ ) { |
664 | controlColor[i] = editdlg->colorList[i]; | 638 | if ( item-> color ( role ). isValid ( )) { |
639 | citem-> setColor ( role, QColor ( controlColor [cnt] )); | ||
640 | cnt++; | ||
641 | } | ||
665 | } | 642 | } |
643 | |||
644 | m_color_list-> setCurrentItem ( 0 ); | ||
645 | colorClicked ( 0 ); | ||
646 | |||
666 | m_color_changed = true; | 647 | m_color_changed = true; |
667 | } | 648 | } |
668 | delete editdlg; | 649 | delete editdlg; |
669 | */ | ||
670 | } | 650 | } |
671 | 651 | ||
672 | 652 | ||
673 | void Appearance::saveSchemeClicked() | 653 | void Appearance::saveSchemeClicked() |
674 | { | 654 | { |
675 | ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); | 655 | ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( )); |
676 | 656 | ||
677 | if ( !item ) | 657 | if ( !item ) |
678 | return; | 658 | return; |
679 | 659 | ||
680 | QDialog *d = new QDialog ( this, 0, true ); | 660 | QDialog *d = new QDialog ( this, 0, true ); |
681 | d-> setCaption ( tr( "Save Scheme" )); | 661 | d-> setCaption ( tr( "Save Scheme" )); |
@@ -683,26 +663,25 @@ void Appearance::saveSchemeClicked() | |||
683 | ( new QVBoxLayout ( d, 4, 4 ))-> addWidget ( ed ); | 663 | ( new QVBoxLayout ( d, 4, 4 ))-> addWidget ( ed ); |
684 | 664 | ||
685 | if ( d-> exec ( ) == QDialog::Accepted ) { | 665 | if ( d-> exec ( ) == QDialog::Accepted ) { |
686 | QString schemename = ed-> text ( ); | 666 | QString schemename = ed-> text ( ); |
687 | QFile file ( QPEApplication::qpeDir() + "/etc/colors/" + schemename + ".scheme" ); | 667 | QFile file ( QPEApplication::qpeDir() + "/etc/colors/" + schemename + ".scheme" ); |
688 | if ( !file. exists ( )) | 668 | if ( !file. exists ( )) |
689 | { | 669 | { |
690 | QPalette p = item-> palette ( ); | 670 | QPalette p = item-> palette ( ); |
691 | 671 | ||
692 | Config config ( file.name(), Config::File ); | 672 | Config config ( file.name(), Config::File ); |
693 | config.setGroup( "Colors" ); | 673 | config.setGroup( "Colors" ); |
694 | 674 | ||
695 | for ( int i = 0; colorLUT [i]. role != QColorGroup::NColorRoles; i++ ) | 675 | item-> save ( config ); |
696 | config.writeEntry ( colorLUT [i]. key, p. color ( QPalette::Active, colorLUT [i]. role ). name ( )); | ||
697 | 676 | ||
698 | config. write ( ); // need to flush the config info first | 677 | config. write ( ); // need to flush the config info first |
699 | loadColors ( m_color_list ); | 678 | loadColors ( m_color_list ); |
700 | } | 679 | } |
701 | else | 680 | else |
702 | { | 681 | { |
703 | QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." )); | 682 | QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." )); |
704 | } | 683 | } |
705 | } | 684 | } |
706 | delete d; | 685 | delete d; |
707 | } | 686 | } |
708 | 687 | ||