summaryrefslogtreecommitdiff
path: root/noncore/styles/theme/othemebase.cpp
Unidiff
Diffstat (limited to 'noncore/styles/theme/othemebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/styles/theme/othemebase.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/noncore/styles/theme/othemebase.cpp b/noncore/styles/theme/othemebase.cpp
index 62b3a11..7ce4e5a 100644
--- a/noncore/styles/theme/othemebase.cpp
+++ b/noncore/styles/theme/othemebase.cpp
@@ -1,59 +1,61 @@
1/* This file is part of the KDE libraries 1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> 2 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public 5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation. 6 License version 2 as published by the Free Software Foundation.
7 7
8 This library is distributed in the hope that it will be useful, 8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of 9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details. 11 Library General Public License for more details.
12 12
13 You should have received a copy of the GNU Library General Public License 13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to 14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 15 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 Boston, MA 02111-1307, USA. 16 Boston, MA 02111-1307, USA.
17*/ 17*/
18
18#include "othemebase.h" 19#include "othemebase.h"
19#include "ogfxeffect.h" 20#include "ogfxeffect.h"
21
22/* OPIE */
23#include <opie2/odebug.h>
20#include <qpe/qpeapplication.h> 24#include <qpe/qpeapplication.h>
21//#include <kdebug.h> 25#include <qpe/config.h>
22//#include <klocale.h> 26using namespace Opie::Core;
23#include <qpe/config.h> 27
24//#include <kglobal.h> 28/* QT */
25//#include <kglobalsettings.h>
26//#include <kstddirs.h>
27#include <qfile.h> 29#include <qfile.h>
28#include <qtextstream.h> 30#include <qtextstream.h>
29#include <qdir.h> 31#include <qdir.h>
30#include <qpainter.h> 32#include <qpainter.h>
31#include <qbitmap.h> 33#include <qbitmap.h>
32#include <stdlib.h>
33#include <qstringlist.h> 34#include <qstringlist.h>
34 35
35#include <stdio.h> 36/* STD */
37#include <stdlib.h>
36 38
37 39
38template class QIntCache<OThemePixmap> 40template class QIntCache<OThemePixmap>
39; 41;
40 42
41static const char *widgetEntries[] = 43static const char *widgetEntries[] =
42 { // unsunken widgets (see header) 44 { // unsunken widgets (see header)
43 "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton", 45 "PushButton", "ComboBox", "HSBarSlider", "VSBarSlider", "Bevel", "ToolButton",
44 "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab", 46 "ScrollButton", "HScrollDeco", "VScrollDeco", "ComboDeco", "MenuItem", "Tab",
45 "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", 47 "ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight",
46 // sunken widgets 48 // sunken widgets
47 "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown", 49 "PushButtonDown", "ComboBoxDown", "HSBarSliderDown", "VSBarSliderDown",
48 "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown", 50 "BevelDown", "ToolButtonDown", "ScrollButtonDown", "HScrollDecoDown",
49 "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp", 51 "VScrollDecoDown", "ComboDecoDown", "MenuItemDown", "TabDown", "SunkenArrowUp",
50 "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight", 52 "SunkenArrowDown", "SunkenArrowLeft", "SunkenArrowRight",
51 // everything else 53 // everything else
52 "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown", 54 "HScrollGroove", "VScrollGroove", "Slider", "SliderGroove", "CheckBoxDown",
53 "CheckBox", "RadioDown", "Radio", "HBarHandle", "VBarHandle", 55 "CheckBox", "RadioDown", "Radio", "HBarHandle", "VBarHandle",
54 "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp", 56 "ToolBar", "Splitter", "CheckMark", "MenuBar", "DisableArrowUp",
55 "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar", 57 "DisableArrowDown", "DisableArrowLeft", "DisableArrowRight", "ProgressBar",
56 "ProgressBackground", "MenuBarItem", "Background" 58 "ProgressBackground", "MenuBarItem", "Background"
57 }; 59 };
58 60
59#define INHERIT_ITEMS 16 61#define INHERIT_ITEMS 16
@@ -241,82 +243,75 @@ void OThemeBase::copyWidgetConfig( int sourceID, int destID, QString *pixnames,
241} 243}
242 244
243void OThemeBase::readConfig( Qt::GUIStyle /*style*/ ) 245void OThemeBase::readConfig( Qt::GUIStyle /*style*/ )
244{ 246{
245#define PREBLEND_ITEMS 12 247#define PREBLEND_ITEMS 12
246 static WidgetType preBlend[] = {Slider, IndicatorOn, IndicatorOff, 248 static WidgetType preBlend[] = {Slider, IndicatorOn, IndicatorOff,
247 ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown, 249 ExIndicatorOn, ExIndicatorOff, HScrollDeco, VScrollDeco, HScrollDecoDown,
248 VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark}; 250 VScrollDecoDown, ComboDeco, ComboDecoDown, CheckMark};
249 251
250 int i; 252 int i;
251 QString tmpStr; 253 QString tmpStr;
252 QString copyfrom[ WIDGETS ]; 254 QString copyfrom[ WIDGETS ];
253 QString pixnames[ WIDGETS ]; // used for duplicate check 255 QString pixnames[ WIDGETS ]; // used for duplicate check
254 QString brdnames[ WIDGETS ]; 256 QString brdnames[ WIDGETS ];
255 bool loaded[ WIDGETS ]; // used for preloading for CopyWidget 257 bool loaded[ WIDGETS ]; // used for preloading for CopyWidget
256 258
257 if ( configFileName.isEmpty() ) { 259 if ( configFileName.isEmpty() ) {
258 Config cfg ( "qpe" ); 260 Config cfg ( "qpe" );
259 cfg. setGroup ( "Appearance" ); 261 cfg. setGroup ( "Appearance" );
260 262
261 configFileName = cfg. readEntry ( "Theme", "default" ); 263 configFileName = cfg. readEntry ( "Theme", "default" );
262 } 264 }
263 Config config( configFilePath + "/themes/" + configFileName + ".themerc" , Config::File ); 265 Config config( configFilePath + "/themes/" + configFileName + ".themerc" , Config::File );
264 266
265 //printf ( "Opened config file: %s\n", ( configFilePath + "/themes/" + configFileName + ".themerc" ). ascii());
266
267 // Are we initalized? 267 // Are we initalized?
268 applyMiscResourceGroup( &config ); 268 applyMiscResourceGroup( &config );
269 for ( i = 0; i < INHERIT_ITEMS; ++i ) { 269 for ( i = 0; i < INHERIT_ITEMS; ++i ) {
270 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 270 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
271 // printf ( "%d [%s]: copy=%s, pix=%s, brd=%s\n", i, widgetEntries [i], copyfrom [i].latin1(), pixnames[i].latin1(),brdnames[i].latin1() );
272 } 271 }
273 for ( ; i < INHERIT_ITEMS*2; ++i ) { 272 for ( ; i < INHERIT_ITEMS*2; ++i ) {
274 if ( config.hasGroup( QString( widgetEntries[ i ] ) ) ) { 273 if ( config.hasGroup( QString( widgetEntries[ i ] ) ) ) {
275 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 274 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
276 // printf ( "%d [%s]: copy=%s, pix=%s, brd=%s\n", i, widgetEntries [i], copyfrom [i].latin1(), pixnames[i].latin1(),brdnames[i].latin1() );
277 } 275 }
278 else { 276 else {
279 copyfrom [ i ] = widgetEntries[ i - INHERIT_ITEMS ]; 277 copyfrom [ i ] = widgetEntries[ i - INHERIT_ITEMS ];
280 // printf ( "%d [%s]: copy=%s\n", i, widgetEntries [i], copyfrom [i].latin1());
281 } 278 }
282 } 279 }
283 for ( ; i < WIDGETS; ++i ) { 280 for ( ; i < WIDGETS; ++i ) {
284 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames ); 281 applyResourceGroup( &config, i, copyfrom, pixnames, brdnames );
285 // printf ( "%d [%s]: copy=%s, pix=%s, brd=%s\n", i, widgetEntries [i], copyfrom [i].latin1(), pixnames[i].latin1(),brdnames[i].latin1() );
286 } 282 }
287 283
288 // initalize defaults that may not be read 284 // initalize defaults that may not be read
289 for ( i = 0; i < WIDGETS; ++i ) 285 for ( i = 0; i < WIDGETS; ++i )
290 loaded[ i ] = false; 286 loaded[ i ] = false;
291 btnXShift = btnYShift = focus3DOffset = 0; 287 btnXShift = btnYShift = focus3DOffset = 0;
292 aTabLine = iTabLine = true; 288 aTabLine = iTabLine = true;
293 roundedButton = roundedCombo = roundedSlider = focus3D = false; 289 roundedButton = roundedCombo = roundedSlider = focus3D = false;
294 splitterWidth = 10; 290 splitterWidth = 10;
295 291
296 for ( i = 0; i < WIDGETS; ++i ) { 292 for ( i = 0; i < WIDGETS; ++i ) {
297 readResourceGroup( i, copyfrom, pixnames, brdnames, loaded ); 293 readResourceGroup( i, copyfrom, pixnames, brdnames, loaded );
298 // printf ( "%d [%s]: copy=%s, pix=%s, brd=%s, colors=%s\n", i, widgetEntries [i], copyfrom [i].latin1(), pixnames[i].latin1(),brdnames[i].latin1(), (colors[i]?colors[i]->background().name().latin1():"<none)" ));
299 } 294 }
300 295
301 // misc items 296 // misc items
302 readMiscResourceGroup(); 297 readMiscResourceGroup();
303 298
304 // Handle preblend items 299 // Handle preblend items
305 for ( i = 0; i < PREBLEND_ITEMS; ++i ) { 300 for ( i = 0; i < PREBLEND_ITEMS; ++i ) {
306 if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 ) 301 if ( pixmaps[ preBlend[ i ] ] != NULL && blends[ preBlend[ i ] ] != 0.0 )
307 blend( preBlend[ i ] ); 302 blend( preBlend[ i ] );
308 } 303 }
309} 304}
310 305
311OThemeBase::OThemeBase( const QString & configFile ) 306OThemeBase::OThemeBase( const QString & configFile )
312 : QWindowsStyle() 307 : QWindowsStyle()
313{ 308{
314 configFilePath = QPEApplication::qpeDir ( ) + "/plugins/styles/"; 309 configFilePath = QPEApplication::qpeDir ( ) + "/plugins/styles/";
315 configFileName = configFile; 310 configFileName = configFile;
316 311
317 readConfig( Qt::WindowsStyle ); 312 readConfig( Qt::WindowsStyle );
318 cache = new OThemeCache( cacheSize ); 313 cache = new OThemeCache( cacheSize );
319} 314}
320 315
321void OThemeBase::applyConfigFile( const QString &/*file*/ ) 316void OThemeBase::applyConfigFile( const QString &/*file*/ )
322{ 317{
@@ -386,49 +381,49 @@ QImage* OThemeBase::loadImage( QString &name )
386OThemePixmap* OThemeBase::loadPixmap( QString &name ) 381OThemePixmap* OThemeBase::loadPixmap( QString &name )
387{ 382{
388 OThemePixmap * pixmap = new OThemePixmap( false ); 383 OThemePixmap * pixmap = new OThemePixmap( false );
389 QString path = configFilePath + "/pixmaps/" + name; 384 QString path = configFilePath + "/pixmaps/" + name;
390 pixmap->load( path ); 385 pixmap->load( path );
391 if ( !pixmap->isNull() ) 386 if ( !pixmap->isNull() )
392 return pixmap; 387 return pixmap;
393 qDebug ( "OThemeBase: Unable to load pixmap %s\n", name.ascii() ); 388 qDebug ( "OThemeBase: Unable to load pixmap %s\n", name.ascii() );
394 delete pixmap; 389 delete pixmap;
395 return ( NULL ); 390 return ( NULL );
396} 391}
397 392
398OThemePixmap* OThemeBase::scale( int w, int h, WidgetType widget ) 393OThemePixmap* OThemeBase::scale( int w, int h, WidgetType widget )
399{ 394{
400 if ( scaleHints[ widget ] == FullScale ) { 395 if ( scaleHints[ widget ] == FullScale ) {
401 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w || 396 if ( !pixmaps[ widget ] || pixmaps[ widget ] ->width() != w ||
402 pixmaps[ widget ] ->height() != h ) { 397 pixmaps[ widget ] ->height() != h ) {
403 OThemePixmap * cachePix = cache->pixmap( w, h, widget ); 398 OThemePixmap * cachePix = cache->pixmap( w, h, widget );
404 if ( cachePix ) { 399 if ( cachePix ) {
405 cachePix = new OThemePixmap( *cachePix ); 400 cachePix = new OThemePixmap( *cachePix );
406 if ( pixmaps[ widget ] ) 401 if ( pixmaps[ widget ] )
407 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, 402 cache->insert( pixmaps[ widget ], OThemeCache::FullScale,
408 widget ); 403 widget );
409 else 404 else
410 qDebug( "We would have inserted a null pixmap!\n" ); 405 odebug << "We would have inserted a null pixmap!\n" << oendl;
411 pixmaps[ widget ] = cachePix; 406 pixmaps[ widget ] = cachePix;
412 } 407 }
413 else { 408 else {
414 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget ); 409 cache->insert( pixmaps[ widget ], OThemeCache::FullScale, widget );
415 QImage tmpImg = images[ widget ] ->smoothScale( w, h ); 410 QImage tmpImg = images[ widget ] ->smoothScale( w, h );
416 pixmaps[ widget ] = new OThemePixmap; 411 pixmaps[ widget ] = new OThemePixmap;
417 pixmaps[ widget ] ->convertFromImage( tmpImg ); 412 pixmaps[ widget ] ->convertFromImage( tmpImg );
418 if ( blends[ widget ] != 0.0 ) 413 if ( blends[ widget ] != 0.0 )
419 blend( widget ); 414 blend( widget );
420 } 415 }
421 } 416 }
422 } 417 }
423 else if ( scaleHints[ widget ] == HorizontalScale ) { 418 else if ( scaleHints[ widget ] == HorizontalScale ) {
424 if ( pixmaps[ widget ] ->width() != w ) { 419 if ( pixmaps[ widget ] ->width() != w ) {
425 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget ); 420 OThemePixmap * cachePix = cache->horizontalPixmap( w, widget );
426 if ( cachePix ) { 421 if ( cachePix ) {
427 cachePix = new OThemePixmap( *cachePix ); 422 cachePix = new OThemePixmap( *cachePix );
428 if ( pixmaps[ widget ] ) 423 if ( pixmaps[ widget ] )
429 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget ); 424 cache->insert( pixmaps[ widget ], OThemeCache::HorizontalScale, widget );
430 else 425 else
431 qDebug ( "We would have inserted a null pixmap!\n" ); 426 qDebug ( "We would have inserted a null pixmap!\n" );
432 pixmaps[ widget ] = cachePix; 427 pixmaps[ widget ] = cachePix;
433 } 428 }
434 else { 429 else {