summaryrefslogtreecommitdiff
path: root/noncore/settings/appearance2
authorsandman <sandman>2002-09-20 01:42:10 (UTC)
committer sandman <sandman>2002-09-20 01:42:10 (UTC)
commitb1f3d33cb0b3f203f153074a8812d5988c3031b2 (patch) (unidiff)
tree1734ac2808dab8f0982b23a2a9101486fcdcfee5 /noncore/settings/appearance2
parent9204c61f669fb265f6c5f14bfd6ca363a2929e40 (diff)
downloadopie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.zip
opie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.tar.gz
opie-b1f3d33cb0b3f203f153074a8812d5988c3031b2.tar.bz2
New experimental appearance settings
Diffstat (limited to 'noncore/settings/appearance2') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/appearance2/appearance.cpp729
-rw-r--r--noncore/settings/appearance2/appearance.h116
-rw-r--r--noncore/settings/appearance2/appearance2.pro12
-rw-r--r--noncore/settings/appearance2/colorlistitem.h28
-rw-r--r--noncore/settings/appearance2/decolistitem.h79
-rw-r--r--noncore/settings/appearance2/editScheme.cpp83
-rw-r--r--noncore/settings/appearance2/editScheme.h48
-rw-r--r--noncore/settings/appearance2/fontlistitem.h40
-rw-r--r--noncore/settings/appearance2/main.cpp35
-rw-r--r--noncore/settings/appearance2/sample.cpp236
-rw-r--r--noncore/settings/appearance2/sample.h49
-rw-r--r--noncore/settings/appearance2/stylelistitem.h85
12 files changed, 1540 insertions, 0 deletions
diff --git a/noncore/settings/appearance2/appearance.cpp b/noncore/settings/appearance2/appearance.cpp
new file mode 100644
index 0000000..52c7125
--- a/dev/null
+++ b/noncore/settings/appearance2/appearance.cpp
@@ -0,0 +1,729 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19***********************************************************************
20**
21** Enhancements by: Dan Williams, <williamsdr@acm.org>
22**
23**********************************************************************/
24
25#include "appearance.h"
26#include "editScheme.h"
27
28#include <opie/ofiledialog.h>
29#include <opie/otabwidget.h>
30
31#include <qpe/applnk.h>
32#include <qpe/config.h>
33#include <qpe/global.h>
34#include <qpe/resource.h>
35#include <qpe/qpeapplication.h>
36#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
37#include <qpe/qcopenvelope_qws.h>
38#endif
39
40#include <qaction.h>
41#include <qbuttongroup.h>
42#include <qcheckbox.h>
43#include <qcombobox.h>
44#include <qdialog.h>
45#include <qdir.h>
46#include <qlabel.h>
47#include <qlayout.h>
48#include <qlineedit.h>
49#include <qlistbox.h>
50#include <qmessagebox.h>
51#include <qmultilineedit.h>
52#include <qpopupmenu.h>
53#include <qpushbutton.h>
54#include <qradiobutton.h>
55#if QT_VERSION >= 300
56#include <qstylefactory.h>
57#else
58#include <qwindowsstyle.h>
59#include <qpe/qpestyle.h>
60#include <qpe/lightstyle.h>
61#include <qpe/qlibrary.h>
62#include <qpe/styleinterface.h>
63#endif
64#include <qtabwidget.h>
65#include <qtoolbutton.h>
66#include <qvgroupbox.h>
67#include <qwidget.h>
68
69#include "stylelistitem.h"
70#include "decolistitem.h"
71#include "fontlistitem.h"
72#include "colorlistitem.h"
73
74#include "sample.h"
75
76
77static 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
86class DefaultWindowDecoration : public WindowDecorationInterface
87{
88public:
89 DefaultWindowDecoration() : ref(0) {}
90 QString name() const {
91 return "Default";
92 }
93 QPixmap icon() const {
94 return QPixmap();
95 }
96 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
97 *iface = 0;
98 if ( uuid == IID_QUnknown )
99 *iface = this;
100 else if ( uuid == IID_WindowDecoration )
101 *iface = this;
102
103 if ( *iface )
104 (*iface)->addRef();
105 return QS_OK;
106 }
107 Q_REFCOUNT
108
109private:
110 ulong ref;
111};
112
113
114struct {
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
131void Appearance::loadStyles ( QListBox *list )
132{
133#if QT_VERSION >= 300
134 list->insertStringList(QStyleFactory::styles());
135#else
136 list->insertItem( new StyleListItem ( "Windows", new QWindowsStyle ( )));
137 list->insertItem( new StyleListItem ( "Light", new LightStyle ( )));
138#ifndef QT_NO_STYLE_MOTIF
139 list->insertItem( new StyleListItem ( "Motif", new QMotifStyle ( )));
140#endif
141#ifndef QT_NO_STYLE_MOTIFPLUS
142 list->insertItem( new StyleListItem ( "MotifPlus", new QMotifPlusStyle ( )));
143#endif
144#ifndef QT_NO_STYLE_PLATINUM
145 list->insertItem( new StyleListItem ( "Platinum", new QPlatinumStyle ( )));
146#endif
147#endif
148 list->insertItem( new StyleListItem ( "QPE", new QPEStyle ( )));
149
150#if QT_VERSION < 300
151 {
152 QString path = QPEApplication::qpeDir() + "/plugins/styles/";
153 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
154
155 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) {
156 QLibrary *lib = new QLibrary ( path + "/" + *it );
157 StyleInterface *iface;
158
159 if ( lib-> queryInterface ( IID_Style, (QUnknownInterface **) &iface ) == QS_OK )
160 list-> insertItem ( new StyleListItem ( lib, iface ));
161 else
162 delete lib;
163 }
164 }
165
166#endif
167}
168
169void Appearance::loadDecos ( QListBox *list )
170{
171 list-> insertItem ( new DecoListItem ( tr( "Default" )));
172
173 {
174 QString path = QPEApplication::qpeDir() + "/plugins/decorations/";
175 QStringList sl = QDir ( path, "lib*.so" ). entryList ( );
176
177 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) {
178 QLibrary *lib = new QLibrary ( path + "/" + *it );
179 WindowDecorationInterface *iface;
180
181 if ( lib-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &iface ) == QS_OK )
182 list-> insertItem ( new DecoListItem ( lib, iface ));
183 else
184 delete lib;
185 }
186 }
187}
188
189static 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
211void Appearance::loadColors ( QListBox *list )
212{
213 list-> clear ( );
214 {
215 Config config ( "qpe" );
216 config. setGroup ( "Appearance" );
217
218 list-> insertItem ( new ColorListItem ( tr( "Current scheme" ), readColorPalette ( config )));
219 }
220
221 QString path = QPEApplication::qpeDir ( ) + "/etc/colors/";
222 QStringList sl = QDir ( path ). entryList ( "*.scheme" );
223
224 for ( QStringList::Iterator it = sl. begin ( ); it != sl. end ( ); ++it ) {
225 QString name = (*it). left ((*it). find ( ".scheme" ));
226 Config config ( path + *it, Config::File );
227 config. setGroup ( "Colors" );
228
229 list-> insertItem ( new ColorListItem ( name, readColorPalette ( config )));
230 }
231}
232
233void Appearance::loadFonts ( QListBox *list )
234{
235 FontDatabase fd;
236 QStringList f = fd. families ( );
237
238 for ( QStringList::ConstIterator it = f. begin ( ); it != f. end ( ); ++it )
239 list-> insertItem ( new FontListItem ( *it, fd. styles ( *it ), fd. pointSizes ( *it )));
240}
241
242
243QWidget *Appearance::createStyleTab ( QWidget *parent )
244{
245 Config config ( "qpe" );
246 config. setGroup ( "Appearance" );
247
248 QWidget* tab = new QWidget( parent, "StyleTab" );
249 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 4, 4 );
250
251 m_style_list = new QListBox( tab, "m_style_list" );
252 vertLayout->addWidget( m_style_list );
253
254 m_style_settings = new QPushButton ( tr( "Settings..." ), tab );
255 connect ( m_style_settings, SIGNAL( clicked ( )), this, SLOT( styleSettingsClicked ( )));
256 vertLayout-> addWidget ( m_style_settings );
257
258 loadStyles ( m_style_list );
259
260 QString s = config. readEntry ( "Style", "Light" );
261 m_style_list-> setCurrentItem ( m_style_list-> findItem ( s ));
262 m_original_style = m_style_list-> currentItem ( );
263 styleClicked ( m_original_style );
264
265 connect( m_style_list, SIGNAL( highlighted( int ) ), this, SLOT( styleClicked( int ) ) );
266
267 return tab;
268}
269
270QWidget *Appearance::createDecoTab ( QWidget *parent )
271{
272 Config config ( "qpe" );
273 config. setGroup ( "Appearance" );
274
275 QWidget* tab = new QWidget( parent, "DecoTab" );
276 QVBoxLayout* vertLayout = new QVBoxLayout( tab, 4, 4 );
277
278 m_deco_list = new QListBox( tab, "m_deco_list" );
279 vertLayout->addWidget( m_deco_list );
280
281 loadDecos ( m_deco_list );
282
283 QString s = config. readEntry ( "Decoration" );
284 m_deco_list-> setCurrentItem ( m_deco_list-> findItem ( s ));
285 m_original_deco = m_deco_list-> currentItem ( );
286 if ( m_deco_list-> currentItem ( ) < 0 )
287 m_deco_list-> setCurrentItem ( 0 );
288 decoClicked ( m_original_deco );
289
290 connect( m_deco_list, SIGNAL( highlighted( int ) ), this, SLOT( decoClicked( int ) ) );
291
292 return tab;
293}
294
295QWidget *Appearance::createFontTab ( QWidget *parent )
296{
297 Config config ( "qpe" );
298 config. setGroup ( "Appearance" );
299
300
301 QWidget *tab = new QWidget( parent, "FontTab" );
302 QGridLayout *gridLayout = new QGridLayout ( tab, 0, 0, 4, 4 );
303 gridLayout->setRowStretch ( 4, 10 );
304
305 m_font_family_list = new QListBox( tab, "FontListBox" );
306 gridLayout->addMultiCellWidget( m_font_family_list, 0, 4, 0, 0 );
307 connect( m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) );
308
309 QLabel *label = new QLabel( tr( "Style" ), tab );
310 gridLayout->addWidget( label, 0, 1 );
311
312 m_font_style_list = new QComboBox( tab, "StyleListBox" );
313 connect( m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) );
314 gridLayout->addWidget( m_font_style_list, 1, 1 );
315
316 label = new QLabel( tr( "Size" ), tab );
317 gridLayout->addWidget( label, 2, 1 );
318
319 m_font_size_list = new QComboBox( tab, "SizeListBox" );
320 connect( m_font_size_list, SIGNAL( activated( int ) ),
321 this, SLOT( fontSizeClicked( int ) ) );
322 gridLayout->addWidget( m_font_size_list, 3, 1 );
323
324 loadFonts ( m_font_family_list );
325
326 QString familyStr = config.readEntry( "FontFamily", "Helvetica" );
327 QString styleStr = config.readEntry( "FontStyle", "Regular" );
328 QString sizeStr = config.readEntry( "FontSize", "10" );
329
330 m_font_family_list-> setCurrentItem ( m_font_family_list-> findItem ( familyStr ));
331 m_original_fontfamily = m_font_family_list-> currentItem ( );
332 if ( m_font_family_list-> currentItem ( ) < 0 )
333 m_font_family_list-> setCurrentItem ( 0 );
334
335 fontFamilyClicked ( m_original_fontfamily );
336
337 m_font_style_list-> setCurrentItem ( findItemCB ( m_font_style_list, styleStr ));
338 m_original_fontstyle = m_font_style_list-> currentItem ( );
339 fontStyleClicked ( m_original_fontstyle );
340
341 m_font_size_list-> setCurrentItem ( findItemCB ( m_font_size_list, sizeStr ));
342 m_original_fontsize = m_font_size_list-> currentItem ( );
343 fontSizeClicked ( m_original_fontsize );
344
345 return tab;
346}
347
348QWidget *Appearance::createColorTab ( QWidget *parent )
349{
350 Config config ( "qpe" );
351 config. setGroup ( "Appearance" );
352
353
354 QWidget *tab = new QWidget( parent, "ColorTab" );
355 QGridLayout *gridLayout = new QGridLayout( tab, 0, 0, 4, 4 );
356 gridLayout->setRowStretch ( 3, 10 );
357
358 m_color_list = new QListBox ( tab );
359 gridLayout->addMultiCellWidget ( m_color_list, 0, 3, 0, 0 );
360 connect( m_color_list, SIGNAL( highlighted( int ) ), this, SLOT( colorClicked( int ) ) );
361
362 loadColors ( m_color_list );
363 m_color_list-> setCurrentItem ( 0 );
364
365 QPushButton* tempButton = new QPushButton( tab, "editSchemeButton" );
366 tempButton->setText( tr( "Edit..." ) );
367 connect( tempButton, SIGNAL( clicked() ), this, SLOT( editSchemeClicked() ) );
368 gridLayout->addWidget( tempButton, 0, 1 );
369
370 tempButton = new QPushButton( tab, "deleteSchemeButton" );
371 tempButton->setText( tr( "Delete" ) );
372 connect( tempButton, SIGNAL( clicked() ), this, SLOT( deleteSchemeClicked() ) );
373 gridLayout->addWidget( tempButton, 1, 1 );
374
375 tempButton = new QPushButton( tab, "saveSchemeButton" );
376 tempButton->setText( tr( "Save" ) );
377 connect( tempButton, SIGNAL( clicked() ), this, SLOT( saveSchemeClicked() ) );
378 gridLayout->addWidget( tempButton, 2, 1 );
379
380 return tab;
381}
382
383QWidget *Appearance::createGuiTab ( QWidget *parent )
384{
385 Config config ( "qpe" );
386 config. setGroup ( "Appearance" );
387
388 QWidget *tab = new QWidget( parent, "AdvancedTab" );
389 QVBoxLayout *vertLayout = new QVBoxLayout( tab, 4, 4 );
390
391 QGridLayout* gridLayout = new QGridLayout ( vertLayout );
392
393 int style = config. readNumEntry ( "TabStyle", 2 );
394
395 QLabel* label = new QLabel( tr( "Tab style:" ), tab );
396 gridLayout-> addWidget ( label, 0, 0 );
397 QButtonGroup* btngrp = new QButtonGroup( tab, "buttongroup" );
398 btngrp-> hide ( );
399 btngrp-> setExclusive ( true );
400
401 m_tabstyle_list = new QComboBox ( false, tab, "tabstyle" );
402 m_tabstyle_list-> insertItem ( tr( "Tabs" ));
403 m_tabstyle_list-> insertItem ( tr( "Tabs w/icons" ));
404 m_tabstyle_list-> insertItem ( tr( "Drop down list" ));
405 m_tabstyle_list-> insertItem ( tr( "Drop down list w/icons" ));
406 m_tabstyle_list-> setCurrentItem ( style & 0xff );
407 gridLayout-> addMultiCellWidget ( m_tabstyle_list, 0, 0, 1, 2 );
408
409 m_tabstyle_top = new QRadioButton( tr( "Top" ), tab, "tabpostop" );
410 btngrp-> insert ( m_tabstyle_top );
411 gridLayout-> addWidget( m_tabstyle_top, 1, 1 );
412
413 m_tabstyle_bottom = new QRadioButton( tr( "Bottom" ), tab, "tabposbottom" );
414 btngrp-> insert ( m_tabstyle_top );
415 gridLayout-> addWidget( m_tabstyle_bottom, 1, 2 );
416
417 bool tabtop = ( style & 0xff00 ) == 0;
418 m_tabstyle_top-> setChecked ( tabtop );
419 m_tabstyle_bottom-> setChecked ( !tabtop );
420
421 m_original_tabstyle = style;
422
423 return tab;
424}
425
426
427Appearance::Appearance( QWidget* parent, const char* name, WFlags )
428 : QDialog ( parent, name, true )
429{
430 setCaption( tr( "Appearance" ) );
431
432 Config config( "qpe" );
433 config.setGroup( "Appearance" );
434
435 QVBoxLayout *top = new QVBoxLayout ( this, 4, 4 );
436
437 m_sample = new SampleWindow ( this );
438 m_sample-> setDecoration ( new DefaultWindowDecoration ( ));
439
440 OTabWidget* tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom );
441 QWidget *styletab;
442
443 tw-> addTab ( styletab = createStyleTab ( tw ), "appearance/styletabicon.png", tr( "Style" ));
444 tw-> addTab ( createFontTab ( tw ), "appearance/fonttabicon.png", tr( "Font" ));
445 tw-> addTab ( createColorTab ( tw ), "appearance/colorstabicon.png", tr( "Colors" ) );
446 tw-> addTab ( createDecoTab ( tw ), "appearance/styletabicon.png", tr( "Windows" ) );
447 tw-> addTab ( createGuiTab ( tw ), "appearance/backgroundtabicon.png", tr( "Gui" ) );
448
449 top-> addWidget ( tw, 10 );
450 top-> addWidget ( m_sample, 1 );
451
452 tw-> setCurrentTab ( styletab );
453}
454
455Appearance::~Appearance()
456{
457}
458
459void Appearance::accept ( )
460{
461 Config config("qpe");
462 config.setGroup( "Appearance" );
463
464 int newstyle = m_style_list-> currentItem ( );
465 int newtabstyle = ( m_tabstyle_list-> currentItem ( ) & 0xff ) | \
466 ( m_tabstyle_top-> isChecked ( ) ? 0x000 : 0x100 );
467 int newfontfamily = m_font_family_list-> currentItem ( );
468 int newfontstyle = m_font_style_list-> currentItem ( );
469 int newfontsize = m_font_size_list-> currentItem ( );
470
471
472 if ( m_style_changed ) {
473 StyleListItem *item = (StyleListItem *) m_style_list-> item ( newstyle );
474 if ( item )
475 config.writeEntry( "Style", item-> key ( ));
476 }
477 if ( newtabstyle != m_original_tabstyle ) {
478 config. writeEntry ( "TabStyle", newtabstyle );
479 }
480
481 if ( m_font_changed ) {
482 config.writeEntry( "FontFamily", m_font_family_list-> text ( newfontfamily ));
483 config.writeEntry( "FontStyle", m_font_style_list-> text ( newfontstyle ));
484 config.writeEntry( "FontSize", m_font_size_list-> text ( newfontsize ));
485 }
486
487/*
488 if ( schemeChanged )
489 {
490 int i;
491 for ( i = 0; i < MAX_CONTROL; i++ )
492 {
493 config.writeEntry( controlList[i], controlColor[i] );
494 }
495 }
496*/
497 config. write ( ); // need to flush the config info first
498 Global::applyStyle ( );
499
500 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()" );
502 }
503
504 QDialog::accept ( );
505}
506
507void Appearance::done ( int r )
508{
509 QDialog::done ( r );
510 close ( );
511}
512
513
514void Appearance::styleClicked ( int index )
515{
516 StyleListItem *sli = (StyleListItem *) m_style_list-> item ( index );
517 m_style_settings-> setEnabled ( sli ? sli-> hasSettings ( ) : false );
518
519 if ( m_sample && sli && sli-> style ( ))
520 m_sample-> setStyle2 ( sli-> style ( ));
521
522 m_style_changed |= ( index != m_original_style );
523}
524
525void Appearance::styleSettingsClicked ( )
526{
527 StyleListItem *item = (StyleListItem *) m_style_list-> item ( m_style_list-> currentItem ( ));
528
529 if ( item && item-> hasSettings ( )) {
530 QDialog *d = new QDialog ( this, "SETTINGS-DLG", true );
531 QVBoxLayout *vbox = new QVBoxLayout ( d, 4, 0 );
532
533 QWidget *w = item-> settings ( d );
534
535 if ( w ) {
536 vbox-> addWidget ( w );
537
538 d-> setCaption ( w-> caption ( ));
539
540 d-> showMaximized ( );
541 bool accepted = ( d-> exec ( ) == QDialog::Accepted );
542
543 if ( item-> setSettings ( accepted ))
544 m_style_changed = true;
545 }
546 delete d;
547 }
548}
549
550void Appearance::decoClicked ( int index )
551{
552 DecoListItem *dli = (DecoListItem *) m_deco_list-> item ( index );
553
554 if ( m_sample ) {
555 if ( dli && dli-> interface ( ))
556 m_sample-> setDecoration ( dli-> interface ( ));
557 else
558 m_sample-> setDecoration ( new DefaultWindowDecoration ( ));
559 }
560 m_deco_changed |= ( index != m_original_deco );
561}
562
563void Appearance::fontFamilyClicked ( int index )
564{
565 QString oldstyle = m_font_style_list-> currentText ( );
566 QString oldsize = m_font_size_list-> currentText ( );
567
568 FontListItem *fli = (FontListItem *) m_font_family_list-> item ( index );
569
570 m_font_style_list-> clear ( );
571 m_font_style_list-> insertStringList ( fli-> styles ( ));
572 m_font_style_list-> setEnabled ( !fli-> styles ( ). isEmpty ( ));
573
574 int i;
575
576 i = findItemCB ( m_font_style_list, oldstyle );
577 if ( i < 0 )
578 i = findItemCB ( m_font_style_list, "Regular" );
579 if (( i < 0 ) && ( m_font_style_list-> count ( ) > 0 ))
580 i = 0;
581
582 if ( i >= 0 ) {
583 m_font_style_list-> setCurrentItem ( i );
584 fontStyleClicked ( i );
585 }
586
587 m_font_size_list-> clear ( );
588 QValueList<int> sl = fli-> sizes ( );
589
590 for ( QValueList<int>::Iterator it = sl. begin ( ); it != sl. end ( ); ++it )
591 m_font_size_list-> insertItem ( QString::number ( *it ));
592
593 i = findItemCB ( m_font_size_list, oldsize );
594 if ( i < 0 )
595 i = findItemCB ( m_font_size_list, "10" );
596 if (( i < 0 ) && ( m_font_size_list-> count ( ) > 0 ))
597 i = 0;
598
599 if ( i >= 0 ) {
600 m_font_size_list-> setCurrentItem ( i );
601 fontSizeClicked ( i );
602 }
603 changeText ( );
604
605 m_font_changed |= ( index != m_original_fontfamily );
606}
607
608void Appearance::fontStyleClicked ( int index )
609{
610 changeText ( );
611
612 m_font_changed |= ( index != m_original_fontstyle );
613}
614
615void Appearance::fontSizeClicked ( int index )
616{
617 changeText ( );
618
619 m_font_changed |= ( index != m_original_fontsize );
620}
621
622void Appearance::changeText ( )
623{
624 int ffa = m_font_family_list-> currentItem ( );
625 int fst = m_font_style_list-> currentItem ( );
626 int fsi = m_font_size_list-> currentItem ( );
627
628 FontListItem *fli = (FontListItem *) m_font_family_list-> item ( ffa );
629
630 if ( fli ) {
631 FontDatabase fdb;
632
633 m_sample-> setFont ( fdb. font ( fli-> family ( ), \
634 fst >= 0 ? fli-> styles ( ) [fst] : QString::null, \
635 fsi >= 0 ? fli-> sizes ( ) [fsi] : 10, \
636 fdb. charSets ( fli-> family ( )) [0] ));
637 }
638}
639
640void Appearance::colorClicked ( int index )
641{
642 ColorListItem *item = (ColorListItem *) m_color_list-> item ( index );
643
644 if ( item )
645 m_sample-> setPalette ( item-> palette ( ));
646
647 m_color_changed |= ( item-> palette ( ) != qApp-> palette ( ));
648}
649
650
651void Appearance::editSchemeClicked ( )
652{
653 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
654
655/*
656 EditScheme* editdlg = new EditScheme( this, "editScheme", TRUE, 0,
657 9, controlLabel, controlColor );
658 editdlg->showMaximized();
659 if ( editdlg->exec() == QDialog::Accepted )
660 {
661 int i;
662 for ( i = 0; i < MAX_CONTROL; i++ )
663 {
664 controlColor[i] = editdlg->colorList[i];
665 }
666 m_color_changed = true;
667 }
668 delete editdlg;
669 */
670}
671
672
673void Appearance::saveSchemeClicked()
674{
675 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
676
677 if ( !item )
678 return;
679
680 QDialog *d = new QDialog ( this, 0, true );
681 d-> setCaption ( tr( "Save Scheme" ));
682 QLineEdit *ed = new QLineEdit ( this );
683 ( new QVBoxLayout ( d, 4, 4 ))-> addWidget ( ed );
684
685 if ( d-> exec ( ) == QDialog::Accepted ) {
686 QString schemename = ed-> text ( );
687 QFile file ( QPEApplication::qpeDir() + "/etc/colors/" + schemename + ".scheme" );
688 if ( !file. exists ( ))
689 {
690 QPalette p = item-> palette ( );
691
692 Config config ( file.name(), Config::File );
693 config.setGroup( "Colors" );
694
695 for ( int i = 0; colorLUT [i]. role != QColorGroup::NColorRoles; i++ )
696 config.writeEntry ( colorLUT [i]. key, p. color ( QPalette::Active, colorLUT [i]. role ). name ( ));
697
698 config. write ( ); // need to flush the config info first
699 loadColors ( m_color_list );
700 }
701 else
702 {
703 QMessageBox::information ( this, tr( "Save scheme" ), tr( "Scheme does already exist." ));
704 }
705 }
706 delete d;
707}
708
709void Appearance::deleteSchemeClicked()
710{
711 ColorListItem *item = (ColorListItem *) m_color_list-> item ( m_color_list-> currentItem ( ));
712
713 if ( !item )
714 return;
715
716 if ( m_color_list-> currentItem ( ) > 0 )
717 {
718 if ( QMessageBox::warning ( this, tr( "Delete scheme" ), tr( "Do you really want to delete\n" ) + item-> text ( ) + "?",
719 tr( "Yes" ), tr( "No" ), 0, 0, 1 ) == 0 ) {
720 QFile::remove ( QPEApplication::qpeDir ( ) + "/etc/colors/" + item-> text ( ) + ".scheme" );
721 loadColors ( m_color_list );
722 }
723 }
724 else
725 {
726 QMessageBox::information( this, tr( "Delete scheme" ), tr( "Unable to delete current scheme." ));
727 }
728}
729
diff --git a/noncore/settings/appearance2/appearance.h b/noncore/settings/appearance2/appearance.h
new file mode 100644
index 0000000..ce0d4b0
--- a/dev/null
+++ b/noncore/settings/appearance2/appearance.h
@@ -0,0 +1,116 @@
1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3**
4** This file is part of the Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19***********************************************************************
20**
21** Enhancements by: Dan Williams, <williamsdr@acm.org>
22**
23**********************************************************************/
24
25#ifndef APPEARANCESETTINGS_H
26#define APPEARANCESETTINGS_H
27
28#include <qpe/fontdatabase.h>
29
30#include <qmainwindow.h>
31#include <qdialog.h>
32
33class QCheckBox;
34class QComboBox;
35class QLabel;
36class QLineEdit;
37class QListBox;
38class QMultiLineEdit;
39class QPushButton;
40class QRadioButton;
41class QToolButton;
42class SampleWindow;
43
44class Appearance : public QDialog
45{
46 Q_OBJECT
47
48public:
49 Appearance( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
50 ~Appearance();
51
52protected:
53 virtual void accept ( );
54 virtual void done ( int r );
55
56protected slots:
57 void styleClicked ( int );
58 void styleSettingsClicked ( );
59 void decoClicked ( int );
60 void fontFamilyClicked ( int );
61 void fontStyleClicked ( int );
62 void fontSizeClicked ( int );
63 void colorClicked ( int );
64// void tabStyleClicked ( int );
65
66 void editSchemeClicked();
67 void saveSchemeClicked();
68 void deleteSchemeClicked();
69
70private:
71 void loadStyles ( QListBox * );
72 void loadDecos ( QListBox * );
73 void loadFonts ( QListBox * );
74 void loadColors ( QListBox * );
75
76 void changeText();
77
78 QWidget *createStyleTab ( QWidget *parent );
79 QWidget *createDecoTab ( QWidget *parent );
80 QWidget *createFontTab ( QWidget *parent );
81 QWidget *createColorTab ( QWidget *parent );
82 QWidget *createGuiTab ( QWidget *parent );
83
84private:
85 bool m_style_changed;
86 bool m_font_changed;
87 bool m_scheme_changed;
88 bool m_deco_changed;
89 bool m_color_changed;
90
91 int m_original_style;
92 int m_original_deco;
93 int m_original_fontfamily;
94 int m_original_fontstyle;
95 int m_original_fontsize;
96 int m_original_tabstyle;
97
98 QListBox * m_style_list;
99 QPushButton * m_style_settings;
100
101 QListBox * m_deco_list;
102
103 QListBox * m_color_list;
104
105 QListBox * m_font_family_list;
106 QComboBox * m_font_style_list;
107 QComboBox * m_font_size_list;
108
109 SampleWindow *m_sample;
110
111 QComboBox * m_tabstyle_list;
112 QRadioButton *m_tabstyle_top;
113 QRadioButton *m_tabstyle_bottom;
114};
115
116#endif // APPEARANCESETTINGS_H
diff --git a/noncore/settings/appearance2/appearance2.pro b/noncore/settings/appearance2/appearance2.pro
new file mode 100644
index 0000000..3147148
--- a/dev/null
+++ b/noncore/settings/appearance2/appearance2.pro
@@ -0,0 +1,12 @@
1TEMPLATE = app
2CONFIG = qt warn_on release
3DESTDIR = $(OPIEDIR)/bin
4HEADERS = appearance.h editScheme.h sample.h
5SOURCES = appearance.cpp editScheme.cpp main.cpp sample.cpp
6INCLUDEPATH += $(OPIEDIR)/include
7DEPENDPATH += ../$(OPIEDIR)/include
8LIBS += -lqpe -lopie
9TARGET = appearance2
10INCLUDEPATH += $(OPIEDIR)/include
11DEPENDPATH += $(OPIEDIR)/include
12
diff --git a/noncore/settings/appearance2/colorlistitem.h b/noncore/settings/appearance2/colorlistitem.h
new file mode 100644
index 0000000..c7318a6
--- a/dev/null
+++ b/noncore/settings/appearance2/colorlistitem.h
@@ -0,0 +1,28 @@
1#ifndef COLORLISTITEM_H
2#define COLORLISTITEM_H
3
4#include <qlistbox.h>
5#include <qpalette.h>
6
7class ColorListItem : public QListBoxText {
8public:
9 ColorListItem ( const QString &t, const QPalette &pal ) : QListBoxText ( t )
10 {
11 m_pal = pal;
12 }
13
14 virtual ~ColorListItem ( )
15 {
16 }
17
18 QPalette palette ( )
19 {
20 return m_pal;
21 }
22
23private:
24 QPalette m_pal;
25};
26
27
28#endif
diff --git a/noncore/settings/appearance2/decolistitem.h b/noncore/settings/appearance2/decolistitem.h
new file mode 100644
index 0000000..dfdce47
--- a/dev/null
+++ b/noncore/settings/appearance2/decolistitem.h
@@ -0,0 +1,79 @@
1#ifndef DECOLISTITEM_H
2#define DECOLISTITEM_H
3
4#include <qpe/windowdecorationinterface.h>
5#include <qlistbox.h>
6
7class DecoListItem : public QListBoxText {
8public:
9 DecoListItem ( const QString &t ) : QListBoxText ( t )
10 {
11 m_lib = 0;
12 m_window_if = 0;
13 // m_settings_if = 0;
14 }
15
16 DecoListItem ( QLibrary *lib, WindowDecorationInterface *iface ) : QListBoxText ( iface-> name ( ))
17 {
18 m_lib = lib;
19 m_window_if = iface;
20
21 // iface-> queryInterface ( IID_WindowDecoration, (QUnknownInterface **) &m_settings_if );
22 }
23
24 virtual ~DecoListItem ( )
25 {
26 // if ( m_settings_if )
27 // m_settings_if-> release ( );
28 if ( m_window_if )
29 m_window_if-> release ( );
30 delete m_lib;
31 }
32
33 bool hasSettings ( ) const
34 {
35 // return ( m_settings_if );
36 return false;
37 }
38
39 QWidget *settings ( QWidget * /*parent*/ )
40 {
41 // return m_settings_if ? m_settings_if-> create ( parent ) : 0;
42 return 0;
43 }
44
45 bool setSettings ( bool /*accepted*/ )
46 {
47 // if ( !m_settings_if )
48 // return false;
49
50 // if ( accepted )
51 // return m_settings_if-> accept ( );
52 // else {
53 // m_settings_if-> reject ( );
54 // return false;
55 // }
56 return false;
57 }
58
59 QString key ( )
60 {
61 if ( m_window_if )
62 return QString ( m_window_if-> name ( ));
63 else
64 return text ( );
65 }
66
67 WindowDecorationInterface *interface ( )
68 {
69 return m_window_if;
70 }
71
72private:
73 QLibrary *m_lib;
74 WindowDecorationInterface *m_window_if;
75 //WindowDecorationSettingsInterface *m_settings_if;
76
77};
78
79#endif \ No newline at end of file
diff --git a/noncore/settings/appearance2/editScheme.cpp b/noncore/settings/appearance2/editScheme.cpp
new file mode 100644
index 0000000..2453c7b
--- a/dev/null
+++ b/noncore/settings/appearance2/editScheme.cpp
@@ -0,0 +1,83 @@
1/**********************************************************************
2** EditScheme
3**
4** Dialog for editing color scheme
5**
6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org
8** http://draknor.net
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#include "editScheme.h"
21
22#include "opie/colorpopupmenu.h"
23
24#include <qaction.h>
25#include <qlabel.h>
26#include <qlayout.h>
27#include <qpopupmenu.h>
28#include <qscrollview.h>
29#include <qtoolbutton.h>
30
31EditScheme::EditScheme( QWidget* parent, const char* name, bool modal, WFlags fl,
32 int max, QString list[], QString colors[] )
33 : QDialog( parent, name, modal, fl )
34{
35 setCaption( tr( "Edit scheme" ) );
36 QGridLayout* layout = new QGridLayout( this );
37 layout->setSpacing( 4 );
38 layout->setMargin( 4 );
39
40
41 maxCount = max;
42 int i;
43 QLabel* label;
44 ColorPopupMenu* colorPopupMenu;
45 for ( i = 0; i < max; i++ )
46 {
47 colorList[i] = colors[i];
48 surfaceList[i] = list[i];
49 label = new QLabel( tr( surfaceList[i] ), this );
50 layout->addWidget( label, i, 0 );
51 colorButtons[i] = new QToolButton( this, list[i] );
52 colorButtons[i]->setPalette( QPalette( QColor( colors[i] ) ) );
53 layout->addWidget( colorButtons[i], i, 1 );
54
55 colorPopupMenu = new ColorPopupMenu( colors[i], 0, list[i] );
56 colorButtons[i]->setPopup( colorPopupMenu );
57 colorButtons[i]->setPopupDelay( 0 );
58 connect( colorPopupMenu, SIGNAL( colorSelected( const QColor& ) ), this, SLOT( changeColor( const QColor& ) ) );
59 }
60}
61
62EditScheme::~EditScheme()
63{
64}
65
66void EditScheme::changeColor( const QColor& color )
67{
68 QString name( sender()->name() );
69 int i;
70
71 for ( i = 0; i < maxCount; i++ )
72 {
73 if ( name == colorButtons[i]->name() )
74 {
75 break;
76 }
77 }
78 if ( i < maxCount && name == colorButtons[i]->name() )
79 {
80 colorList[i] = color.name();
81 colorButtons[i]->setPalette( QPalette( QColor( colorList[i] ) ) );
82 }
83}
diff --git a/noncore/settings/appearance2/editScheme.h b/noncore/settings/appearance2/editScheme.h
new file mode 100644
index 0000000..cf238c6
--- a/dev/null
+++ b/noncore/settings/appearance2/editScheme.h
@@ -0,0 +1,48 @@
1/**********************************************************************
2** EditScheme
3**
4** Dialog for editing color scheme
5**
6** Copyright (C) 2002, Dan Williams
7** williamsdr@acm.org
8** http://draknor.net
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#ifndef EDITSCHEME_H
21#define EDITSCHEME_H
22
23#include <qdialog.h>
24#include <qtoolbutton.h>
25
26class QColor;
27
28class EditScheme : public QDialog
29{
30 Q_OBJECT
31
32public:
33 EditScheme( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0,
34 int = 0, QString[] = 0, QString[] = 0 );
35 ~EditScheme();
36
37 int maxCount;
38 QString surfaceList[9];
39 QString colorList[9];
40
41
42 QToolButton* colorButtons[9];
43
44protected slots:
45 void changeColor( const QColor& );
46};
47
48#endif // EDITSCHEME_H
diff --git a/noncore/settings/appearance2/fontlistitem.h b/noncore/settings/appearance2/fontlistitem.h
new file mode 100644
index 0000000..73f1d54
--- a/dev/null
+++ b/noncore/settings/appearance2/fontlistitem.h
@@ -0,0 +1,40 @@
1#ifndef FONTLISTITEM_H
2#define FONTLISTITEM_H
3
4#include <qlistbox.h>
5
6class FontListItem : public QListBoxText {
7public:
8 FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText ( )
9 {
10 m_name = t;
11 m_styles = styles;
12 m_sizes = sizes;
13
14 QString str = t;
15 str [0] = str [0]. upper ( );
16 setText ( str );
17 }
18
19 QString family ( ) const
20 {
21 return m_name;
22 }
23
24 const QStringList &styles ( ) const
25 {
26 return m_styles;
27 }
28
29 const QValueList<int> &sizes ( ) const
30 {
31 return m_sizes;
32 }
33
34private:
35 QStringList m_styles;
36 QValueList<int> m_sizes;
37 QString m_name;
38};
39
40#endif \ No newline at end of file
diff --git a/noncore/settings/appearance2/main.cpp b/noncore/settings/appearance2/main.cpp
new file mode 100644
index 0000000..cfbab0b
--- a/dev/null
+++ b/noncore/settings/appearance2/main.cpp
@@ -0,0 +1,35 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "appearance.h"
22
23#include <qpe/qpeapplication.h>
24
25
26int main ( int argc, char **argv )
27{
28 QPEApplication app ( argc, argv );
29
30 Appearance m;
31 app. showMainDocumentWidget ( &m );
32
33 return app. exec ( );
34}
35
diff --git a/noncore/settings/appearance2/sample.cpp b/noncore/settings/appearance2/sample.cpp
new file mode 100644
index 0000000..ee27d60
--- a/dev/null
+++ b/noncore/settings/appearance2/sample.cpp
@@ -0,0 +1,236 @@
1#include <qvbox.h>
2#include <qpopupmenu.h>
3#include <qpainter.h>
4#include <qmenubar.h>
5#include <qcheckbox.h>
6#include <qpushbutton.h>
7#include <qscrollbar.h>
8#include <qlayout.h>
9#include <qwhatsthis.h>
10#include <qpixmapcache.h>
11#include <qtimer.h>
12#include <qobjectlist.h>
13
14#include "sample.h"
15
16
17class SampleText : public QWidget
18{
19public:
20 SampleText( const QString &t, bool h, QWidget *parent )
21 : QWidget( parent ), hl(h), text(t)
22 {
23 if ( hl )
24 setBackgroundMode( PaletteHighlight );
25 else
26 setBackgroundMode( PaletteBase );
27 }
28
29 QSize sizeHint() const
30 {
31 QFontMetrics fm(font());
32 return QSize( fm.width(text)+10, fm.height()+4 );
33 }
34
35 void paintEvent( QPaintEvent * )
36 {
37 QPainter p(this);
38 if ( hl )
39 p.setPen( colorGroup().highlightedText() );
40 else
41 p.setPen( colorGroup().text() );
42 p.drawText( rect(), AlignCenter, text );
43 }
44
45private:
46 bool hl;
47 QString text;
48};
49
50
51SampleWindow::SampleWindow( QWidget *parent ) : QWidget(parent), iface(0)
52{
53 init();
54}
55
56QSize SampleWindow::sizeHint() const
57{
58 return container->sizeHint() + QSize( 10, 35 );
59}
60
61void SampleWindow::setFont( const QFont &f )
62{
63 QWidget::setFont( f );
64 popup->setFont( f );
65 QTimer::singleShot ( 0, this, SLOT( fixGeometry ( )));
66}
67
68static void setStyleRecursive ( QWidget *w, QStyle *s )
69{
70 QObjectList *childObjects=(QObjectList*)w->children();
71 if ( childObjects ) {
72 QObject * o;
73 for(o=childObjects->first();o!=0;o=childObjects->next()) {
74 if( o->isWidgetType() ) {
75 setStyleRecursive((QWidget *)o,s);
76 }
77 }
78 }
79 w->setStyle( s );
80}
81
82
83void SampleWindow::setStyle2 ( QStyle *sty )
84{
85 QPixmapCache::clear ( );
86 QPalette p = palette ( );
87 sty-> polish ( p );
88 setStyleRecursive ( this, sty );
89 QTimer::singleShot ( 0, this, SLOT( fixGeometry ( )));
90}
91
92
93void SampleWindow::setDecoration( WindowDecorationInterface *i )
94{
95 iface = i;
96 wd.rect = QRect( 0, 0, 150, 75 );
97 wd.caption = tr("Sample");
98 wd.palette = palette();
99 wd.flags = WindowDecorationInterface::WindowData::Dialog |
100 WindowDecorationInterface::WindowData::Active;
101 wd.reserved = 1;
102
103 th = iface->metric(WindowDecorationInterface::TitleHeight, &wd);
104 tb = iface->metric(WindowDecorationInterface::TopBorder, &wd);
105 lb = iface->metric(WindowDecorationInterface::LeftBorder, &wd);
106 rb = iface->metric(WindowDecorationInterface::RightBorder, &wd);
107 bb = iface->metric(WindowDecorationInterface::BottomBorder, &wd);
108
109 int yoff = th + tb;
110 int xoff = lb;
111
112 wd.rect.setX( 0 );
113 wd.rect.setWidth( width() - lb - rb );
114 wd.rect.setY( 0 );
115 wd.rect.setHeight( height() - yoff - bb );
116
117 container->setGeometry( xoff, yoff, wd.rect.width(), wd.rect.height() );
118 setMinimumSize( container->sizeHint().width()+lb+rb,
119 container->sizeHint().height()+tb+th+bb );
120}
121
122void SampleWindow::paintEvent( QPaintEvent * )
123{
124 if ( !iface )
125 return;
126
127 QPainter p( this );
128
129 p.translate( lb, th+tb );
130
131 iface->drawArea(WindowDecorationInterface::Border, &p, &wd);
132 iface->drawArea(WindowDecorationInterface::Title, &p, &wd);
133
134 p.setPen(palette().active().color(QColorGroup::HighlightedText));
135 QFont f( font() );
136 f.setWeight( QFont::Bold );
137 p.setFont(f);
138 iface->drawArea(WindowDecorationInterface::TitleText, &p, &wd);
139
140 QRect brect( 0, -th, iface->metric(WindowDecorationInterface::HelpWidth,&wd), th );
141 iface->drawButton( WindowDecorationInterface::Help, &p, &wd,
142 brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );
143 brect.moveBy( wd.rect.width() -
144 iface->metric(WindowDecorationInterface::OKWidth,&wd) -
145 iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 );
146 iface->drawButton( WindowDecorationInterface::Close, &p, &wd,
147 brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );
148 brect.moveBy( iface->metric(WindowDecorationInterface::CloseWidth,&wd), 0 );
149 iface->drawButton( WindowDecorationInterface::OK, &p, &wd,
150 brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)0 );
151}
152
153void SampleWindow::init()
154{
155 container = new QVBox( this );
156 popup = new QPopupMenu( this );
157 popup->insertItem( tr("Normal Item"), 1 );
158 popup->insertItem( tr("Disabled Item"), 2 );
159 popup->setItemEnabled(2, FALSE);
160 QMenuBar *mb = new QMenuBar( container );
161 mb->insertItem( tr("Menu"), popup );
162 QHBox *hb = new QHBox( container );
163 QWidget *w = new QWidget( hb );
164 (void)new QScrollBar( 0, 0, 0, 0, 0, Vertical, hb );
165
166 QGridLayout *gl = new QGridLayout( w, 2, 2, 4 );
167 SampleText *l = new SampleText( tr("Normal Text"), FALSE, w );
168 gl->addWidget( l, 0, 0 );
169
170 l = new SampleText( tr("Highlighted Text"), TRUE, w );
171 gl->addWidget( l, 1, 0 );
172
173 QPushButton *pb = new QPushButton( tr("Button"), w );
174 gl->addWidget( pb, 0, 1 );
175 pb->setFocusPolicy( NoFocus );
176
177 QCheckBox *cb = new QCheckBox( tr("Check Box"), w );
178 gl->addWidget( cb, 1, 1 );
179 cb->setFocusPolicy( NoFocus );
180 cb->setChecked( TRUE );
181
182 QWhatsThis::add( this, tr("Sample window using the selected settings.") );
183}
184
185bool SampleWindow::eventFilter( QObject *, QEvent *e )
186{
187 switch ( e->type() ) {
188 case QEvent::MouseButtonPress:
189 case QEvent::MouseButtonRelease:
190 case QEvent::MouseButtonDblClick:
191 case QEvent::MouseMove:
192 case QEvent::KeyPress:
193 case QEvent::KeyRelease:
194 return TRUE;
195 default:
196 break;
197 }
198
199 return FALSE;
200}
201
202void SampleWindow::paletteChange( const QPalette &old )
203{
204 QWidget::paletteChange ( old );
205 wd. palette = palette ( );
206 popup-> setPalette ( palette ( ));
207}
208
209void SampleWindow::setPalette ( const QPalette &pal )
210{
211 QPixmapCache::clear ( );
212 QPalette p = pal;
213 style ( ). polish ( p );
214
215 QWidget::setPalette ( p );
216}
217
218void SampleWindow::resizeEvent( QResizeEvent *re )
219{
220 wd.rect = QRect( 0, 0, 150, 75 );
221
222 wd.rect.setX( 0 );
223 wd.rect.setWidth( width() - lb - rb );
224 wd.rect.setY( 0 );
225 wd.rect.setHeight( height() - th - tb - bb );
226
227 container->setGeometry( lb, th+tb, wd.rect.width(), wd.rect.height() );
228 QWidget::resizeEvent( re );
229}
230
231void SampleWindow::fixGeometry()
232{
233 setMinimumSize( container->sizeHint().width()+lb+rb,
234 container->sizeHint().height()+tb+th+bb );
235}
236
diff --git a/noncore/settings/appearance2/sample.h b/noncore/settings/appearance2/sample.h
new file mode 100644
index 0000000..c6f9b5a
--- a/dev/null
+++ b/noncore/settings/appearance2/sample.h
@@ -0,0 +1,49 @@
1#ifndef __PREVIEW_H__
2#define __PREVIEW_H__
3
4#include <qwidget.h>
5
6#include <qpe/windowdecorationinterface.h>
7
8class QVBox;
9class QPopupMenu;
10class SampleText;
11
12class SampleWindow : public QWidget
13{
14 Q_OBJECT
15public:
16 SampleWindow( QWidget *parent );
17
18 QSize sizeHint() const;
19
20 virtual void setFont( const QFont &f );
21
22 void setStyle2 ( QStyle *sty );
23 void setDecoration( WindowDecorationInterface *i );
24 void setPalette ( const QPalette & );
25
26 virtual void paintEvent( QPaintEvent * );
27
28 void init();
29
30 virtual bool eventFilter( QObject *, QEvent *e );
31 virtual void paletteChange( const QPalette &old );
32 virtual void resizeEvent( QResizeEvent *re );
33
34public slots:
35 void fixGeometry();
36
37protected:
38 WindowDecorationInterface *iface;
39 WindowDecorationInterface::WindowData wd;
40 QVBox *container;
41 QPopupMenu *popup;
42 int th;
43 int tb;
44 int lb;
45 int rb;
46 int bb;
47};
48
49#endif
diff --git a/noncore/settings/appearance2/stylelistitem.h b/noncore/settings/appearance2/stylelistitem.h
new file mode 100644
index 0000000..3cc63dc
--- a/dev/null
+++ b/noncore/settings/appearance2/stylelistitem.h
@@ -0,0 +1,85 @@
1#ifndef STYLELISTITEM_H
2#define STYLELISTITEM_H
3
4#include <qlistbox.h>
5#include <qpe/styleinterface.h>
6
7#include <stdio.h>
8
9class StyleListItem : public QListBoxText {
10public:
11 StyleListItem ( const QString &t, QStyle *sty ) : QListBoxText ( t )
12 {
13 m_lib = 0;
14 m_style_if = 0;
15 m_settings_if = 0;
16 m_style = sty;
17 }
18
19 StyleListItem ( QLibrary *lib, StyleInterface *iface ) : QListBoxText ( iface-> name ( ))
20 {
21 m_lib = lib;
22 m_style_if = iface;
23 m_settings_if = 0;
24 m_style = iface-> create ( );
25
26 iface-> queryInterface ( IID_StyleSettings, (QUnknownInterface **) &m_settings_if );
27 }
28
29 virtual ~StyleListItem ( )
30 {
31 delete m_style;
32
33 if ( m_settings_if )
34 m_settings_if-> release ( );
35 if ( m_style_if )
36 m_style_if-> release ( );
37 delete m_lib;
38 }
39
40 bool hasSettings ( ) const
41 {
42 return ( m_settings_if );
43 }
44
45 QWidget *settings ( QWidget *parent )
46 {
47 return m_settings_if ? m_settings_if-> create ( parent ) : 0;
48 }
49
50 bool setSettings ( bool accepted )
51 {
52 if ( !m_settings_if )
53 return false;
54
55 if ( accepted )
56 return m_settings_if-> accept ( );
57 else {
58 m_settings_if-> reject ( );
59 return false;
60 }
61 }
62
63 QString key ( )
64 {
65 if ( m_style_if )
66 return QString ( m_style_if-> key ( ));
67 else
68 return text ( );
69 }
70
71 QStyle *style ( )
72 {
73 return m_style;
74 }
75
76private:
77 QLibrary *m_lib;
78 QStyle *m_style;
79 StyleInterface *m_style_if;
80 StyleSettingsInterface *m_settings_if;
81
82};
83
84
85#endif