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