1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenconfiguration.cpp
3
// decoration configuration
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to
10
// deal in the Software without restriction, including without limitation the
11
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
// sell copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
//////////////////////////////////////////////////////////////////////////////
27
#include "oxygenconfiguration.h"
28
#include "oxygenshadowconfiguration.h"
29
#include "oxygenexception.h"
31
#include <QTextStream>
37
//__________________________________________________
38
Configuration::Configuration( void ):
39
_titleAlignment( Qt::AlignHCenter ),
40
_centerTitleOnFullWidth( true ),
41
_buttonSize( ButtonDefault ),
42
_frameBorder( BorderTiny ),
43
_blendColor( BlendFromStyle ),
44
_sizeGripMode( SizeGripWhenNeeded ),
45
_separatorMode( SeparatorNever ),
46
_drawTitleOutline( false ),
47
_hideTitleBar( false ),
48
_useDropShadows( true ),
49
_useOxygenShadows( true ),
50
_useAnimations( true ),
51
_animateTitleChange( true ),
52
_animationsDuration( 150 ),
54
_useNarrowButtonSpacing( false ),
55
_shadowCacheMode( CacheVariable )
58
//__________________________________________________
59
Configuration::Configuration( KConfigGroup group )
62
// used to set default values when entries are not found in kconfig
63
Configuration defaultConfiguration;
66
setTitleAlignment( titleAlignment(
67
group.readEntry( OxygenConfig::TITLE_ALIGNMENT,
68
defaultConfiguration.titleAlignmentName( false ) ), false ) );
70
// center title on full width
71
setCenterTitleOnFullWidth( group.readEntry( OxygenConfig::CENTER_TITLE_ON_FULL_WIDTH,
72
defaultConfiguration.centerTitleOnFullWidth() ) );
75
setButtonSize( buttonSize(
76
group.readEntry( OxygenConfig::BUTTON_SIZE,
77
defaultConfiguration.buttonSizeName( false ) ), false ) );
80
setFrameBorder( frameBorder(
81
group.readEntry( OxygenConfig::FRAME_BORDER,
82
defaultConfiguration.frameBorderName( false ) ), false ) );
85
setBlendColor( blendColor(
86
group.readEntry( OxygenConfig::BLEND_COLOR,
87
defaultConfiguration.blendColorName( false ) ), false ) );
90
setSizeGripMode( sizeGripMode(
91
group.readEntry( OxygenConfig::SIZE_GRIP_MODE,
92
defaultConfiguration.sizeGripModeName( false ) ), false ) );
95
if( !group.readEntry( OxygenConfig::DRAW_SEPARATOR, defaultConfiguration.separatorMode() != SeparatorNever ) )
98
setSeparatorMode( SeparatorNever );
100
} else if( group.readEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, defaultConfiguration.separatorMode() == SeparatorActive ) ) {
102
setSeparatorMode( SeparatorActive );
104
} else setSeparatorMode( SeparatorAlways );
107
setDrawTitleOutline( group.readEntry(
108
OxygenConfig::DRAW_TITLE_OUTLINE,
109
defaultConfiguration.drawTitleOutline() ) );
112
setHideTitleBar( group.readEntry(
113
OxygenConfig::HIDE_TITLEBAR,
114
defaultConfiguration.hideTitleBar() ) );
117
setUseDropShadows( group.readEntry(
118
OxygenConfig::USE_DROP_SHADOWS,
119
defaultConfiguration.useDropShadows() ) );
122
setUseOxygenShadows( group.readEntry(
123
OxygenConfig::USE_OXYGEN_SHADOWS,
124
defaultConfiguration.useOxygenShadows() ) );
127
setUseAnimations( group.readEntry(
128
OxygenConfig::USE_ANIMATIONS,
129
defaultConfiguration.useAnimations() ) );
132
setAnimateTitleChange( group.readEntry(
133
OxygenConfig::ANIMATE_TITLE_CHANGE,
134
defaultConfiguration.animateTitleChange() ) );
137
setAnimationsDuration( group.readEntry(
138
OxygenConfig::ANIMATIONS_DURATION,
139
defaultConfiguration.animationsDuration() ) );
142
setTabsEnabled( group.readEntry(
143
OxygenConfig::TABS_ENABLED,
144
defaultConfiguration.tabsEnabled() ) );
147
setUseNarrowButtonSpacing( group.readEntry(
148
OxygenConfig::NARROW_BUTTON_SPACING,
149
defaultConfiguration.useNarrowButtonSpacing() ) );
152
setShadowCacheMode( shadowCacheMode( group.readEntry(
153
OxygenConfig::SHADOW_CACHE_MODE, defaultConfiguration.shadowCacheModeName( false ) ), false ) );
157
//__________________________________________________
158
void Configuration::readException( const Exception& exception )
160
// propagate all features found in mask to the output configuration
161
if( exception.mask() & Exception::FrameBorder ) setFrameBorder( exception.frameBorder() );
162
if( exception.mask() & Exception::BlendColor ) setBlendColor( exception.blendColor() );
163
if( exception.mask() & Exception::DrawSeparator ) setSeparatorMode( exception.separatorMode() );
164
if( exception.mask() & Exception::TitleOutline ) setDrawTitleOutline( exception.drawTitleOutline() );
165
if( exception.mask() & Exception::SizeGripMode ) setSizeGripMode( exception.sizeGripMode() );
166
setHideTitleBar( exception.hideTitleBar() );
169
//__________________________________________________
170
void Configuration::write( KConfigGroup& group ) const
173
Configuration defaultConfiguration;
175
if( titleAlignment() != defaultConfiguration.titleAlignment() ) group.writeEntry( OxygenConfig::TITLE_ALIGNMENT, titleAlignmentName( false ) );
176
if( centerTitleOnFullWidth() != defaultConfiguration.centerTitleOnFullWidth() ) group.writeEntry( OxygenConfig::CENTER_TITLE_ON_FULL_WIDTH, centerTitleOnFullWidth() );
177
if( buttonSize() != defaultConfiguration.buttonSize() ) group.writeEntry( OxygenConfig::BUTTON_SIZE, buttonSizeName( false ) );
179
if( blendColor() != defaultConfiguration.blendColor() ) group.writeEntry( OxygenConfig::BLEND_COLOR, blendColorName( false ) );
180
if( frameBorder() != defaultConfiguration.frameBorder() ) group.writeEntry( OxygenConfig::FRAME_BORDER, frameBorderName( false ) );
181
if( sizeGripMode() != defaultConfiguration.sizeGripMode() ) group.writeEntry( OxygenConfig::SIZE_GRIP_MODE, sizeGripModeName( false ) );
183
if( separatorMode() != defaultConfiguration.separatorMode() )
185
group.writeEntry( OxygenConfig::DRAW_SEPARATOR, separatorMode() != SeparatorNever );
186
group.writeEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, separatorMode() == SeparatorActive );
189
if( drawTitleOutline() != defaultConfiguration.drawTitleOutline() ) group.writeEntry( OxygenConfig::DRAW_TITLE_OUTLINE, drawTitleOutline() );
190
if( hideTitleBar() != defaultConfiguration.hideTitleBar() ) group.writeEntry( OxygenConfig::HIDE_TITLEBAR, hideTitleBar() );
191
if( useDropShadows() != defaultConfiguration.useDropShadows() ) group.writeEntry( OxygenConfig::USE_DROP_SHADOWS, useDropShadows() );
192
if( useOxygenShadows() != defaultConfiguration.useOxygenShadows() ) group.writeEntry( OxygenConfig::USE_OXYGEN_SHADOWS, useOxygenShadows() );
193
if( useAnimations() != defaultConfiguration.useAnimations() ) group.writeEntry( OxygenConfig::USE_ANIMATIONS, useAnimations() );
194
if( animateTitleChange() != defaultConfiguration.animateTitleChange() ) group.writeEntry( OxygenConfig::ANIMATE_TITLE_CHANGE, animateTitleChange() );
195
if( animationsDuration() != defaultConfiguration.animationsDuration() ) group.writeEntry( OxygenConfig::ANIMATIONS_DURATION, animationsDuration() );
196
if( tabsEnabled() != defaultConfiguration.tabsEnabled() ) group.writeEntry( OxygenConfig::TABS_ENABLED, tabsEnabled() );
197
if( useNarrowButtonSpacing() != defaultConfiguration.useNarrowButtonSpacing() ) group.writeEntry( OxygenConfig::NARROW_BUTTON_SPACING, useNarrowButtonSpacing() );
198
if( shadowCacheMode() != defaultConfiguration.shadowCacheMode() ) group.writeEntry( OxygenConfig::SHADOW_CACHE_MODE, shadowCacheModeName( false ) );
202
//__________________________________________________
203
QString Configuration::titleAlignmentName( Qt::Alignment value, bool translated, bool fullWidth )
208
case Qt::AlignLeft: out = translated ? i18n( "Left" ):"Left"; break;
209
case Qt::AlignHCenter:
212
if( fullWidth ) out = translated ? i18n( "Center (Full Width)" ):"Center (Full Width)";
213
else out = translated ? i18n( "Center" ):"Center";
216
case Qt::AlignRight: out = translated ? i18n( "Right" ):"Right"; break;
217
default: return Configuration().titleAlignmentName( translated );
224
//__________________________________________________
225
Qt::Alignment Configuration::titleAlignment( QString value, bool translated )
227
if (value == titleAlignmentName( Qt::AlignLeft, translated ) ) return Qt::AlignLeft;
228
else if (value == titleAlignmentName( Qt::AlignHCenter, translated, false ) || value == titleAlignmentName( Qt::AlignHCenter, translated, true ) ) return Qt::AlignHCenter;
229
else if (value == titleAlignmentName( Qt::AlignRight, translated ) ) return Qt::AlignRight;
230
else return Configuration().titleAlignment();
233
//__________________________________________________
234
QString Configuration::buttonSizeName( ButtonSize value, bool translated )
239
case ButtonSmall: out = translated ? i18nc( "@item:inlistbox Button size:", "Small" ):"Small"; break;
240
case ButtonDefault: out = translated ? i18nc( "@item:inlistbox Button size:", "Normal" ):"Normal"; break;
241
case ButtonLarge: out = translated ? i18nc( "@item:inlistbox Button size:", "Large" ):"Large"; break;
242
case ButtonVeryLarge: out = translated ? i18nc( "@item:inlistbox Button size:", "Very Large" ):"Very Large"; break;
243
case ButtonHuge: out = translated ? i18nc( "@item:inlistbox Button size:", "Huge" ):"Huge"; break;
244
default: return Configuration().buttonSizeName( translated );
251
//__________________________________________________
252
Configuration::ButtonSize Configuration::buttonSize( QString value, bool translated )
254
if( value == buttonSizeName( ButtonSmall, translated ) ) return ButtonSmall;
255
else if( value == buttonSizeName( ButtonDefault, translated ) ) return ButtonDefault;
256
else if( value == buttonSizeName( ButtonLarge, translated ) ) return ButtonLarge;
257
else if( value == buttonSizeName( ButtonVeryLarge, translated ) ) return ButtonVeryLarge;
258
else if( value == buttonSizeName( ButtonHuge, translated ) ) return ButtonHuge;
259
else return Configuration().buttonSize();
262
//__________________________________________________
263
int Configuration::iconScale( ButtonSize value )
267
case ButtonSmall: return 13;
268
case ButtonDefault: return 16;
269
case ButtonLarge: return 20;
270
case ButtonVeryLarge: return 24;
271
case ButtonHuge: return 35;
272
default: return Configuration().iconScale();
277
//__________________________________________________
278
QString Configuration::frameBorderName( FrameBorder value, bool translated )
283
case BorderNone: out = translated ? i18nc( "@item:inlistbox Border size:", "No Border" ):"No Border"; break;
284
case BorderNoSide: out = translated ? i18nc( "@item:inlistbox Border size:", "No Side Border" ):"No Side Border"; break;
285
case BorderTiny: out = translated ? i18nc( "@item:inlistbox Border size:", "Tiny" ):"Tiny"; break;
286
case BorderDefault: out = translated ? i18nc( "@item:inlistbox Border size:", "Normal" ):"Normal"; break;
287
case BorderLarge: out = translated ? i18nc( "@item:inlistbox Border size:", "Large" ):"Large"; break;
288
case BorderVeryLarge: out = translated ? i18nc( "@item:inlistbox Border size:", "Very Large" ):"Very Large"; break;
289
case BorderHuge: out = translated ? i18nc( "@item:inlistbox Border size:", "Huge" ):"Huge"; break;
290
case BorderVeryHuge: out = translated ? i18nc( "@item:inlistbox Border size:", "Very Huge" ):"Very Huge"; break;
291
case BorderOversized: out = translated ? i18nc( "@item:inlistbox Border size:", "Oversized" ):"Oversized"; break;
292
default: return Configuration().frameBorderName( translated );
299
//__________________________________________________
300
Configuration::FrameBorder Configuration::frameBorder( QString value, bool translated )
302
if( value == frameBorderName( BorderNone, translated ) ) return BorderNone;
303
else if( value == frameBorderName( BorderNoSide, translated ) ) return BorderNoSide;
304
else if( value == frameBorderName( BorderTiny, translated ) ) return BorderTiny;
305
else if( value == frameBorderName( BorderDefault, translated ) ) return BorderDefault;
306
else if( value == frameBorderName( BorderLarge, translated ) ) return BorderLarge;
307
else if( value == frameBorderName( BorderVeryLarge, translated ) ) return BorderVeryLarge;
308
else if( value == frameBorderName( BorderHuge, translated ) ) return BorderHuge;
309
else if( value == frameBorderName( BorderVeryHuge, translated ) ) return BorderVeryHuge;
310
else if( value == frameBorderName( BorderOversized, translated ) ) return BorderOversized;
311
else return Configuration().frameBorder();
314
//__________________________________________________
315
QString Configuration::blendColorName( BlendColorType value, bool translated )
320
case NoBlending: out = translated ? i18n( "Solid Color" ):"Solid Color"; break;
321
case RadialBlending: out = translated ? i18n( "Radial Gradient" ):"Radial Gradient"; break;
322
case BlendFromStyle: out = translated ? i18n( "Follow Style Hint" ):"Follow Style Hint"; break;
323
default: return Configuration().blendColorName( translated );
330
//__________________________________________________
331
Configuration::BlendColorType Configuration::blendColor( QString value, bool translated )
333
if( value == blendColorName( NoBlending, translated ) ) return NoBlending;
334
else if( value == blendColorName( RadialBlending, translated ) ) return RadialBlending;
335
else if( value == blendColorName( BlendFromStyle, translated ) ) return BlendFromStyle;
336
else return Configuration().blendColor();
339
//__________________________________________________
340
QString Configuration::sizeGripModeName( SizeGripMode value, bool translated )
345
case SizeGripNever: out = translated ? i18n( "Always Hide Extra Size Grip" ):"Always Hide Extra Size Grip"; break;
346
case SizeGripWhenNeeded: out = translated ? i18n( "Show Extra Size Grip When Needed" ):"Show Extra Size Grip When Needed"; break;
347
default: return Configuration().sizeGripModeName( translated );
354
//__________________________________________________
355
Configuration::SizeGripMode Configuration::sizeGripMode( QString value, bool translated )
357
if( value == sizeGripModeName( SizeGripNever, translated ) ) return SizeGripNever;
358
else if( value == sizeGripModeName( SizeGripWhenNeeded, translated ) ) return SizeGripWhenNeeded;
359
else return Configuration().sizeGripMode();
362
//________________________________________________________
363
bool Configuration::operator == (const Configuration& other ) const
367
titleAlignment() == other.titleAlignment() &&
368
centerTitleOnFullWidth() == other.centerTitleOnFullWidth() &&
369
buttonSize() == other.buttonSize() &&
370
frameBorder() == other.frameBorder() &&
371
blendColor() == other.blendColor() &&
372
sizeGripMode() == other.sizeGripMode() &&
373
separatorMode() == other.separatorMode() &&
374
drawTitleOutline() == other.drawTitleOutline() &&
375
hideTitleBar() == other.hideTitleBar() &&
376
useDropShadows() == other.useDropShadows() &&
377
useOxygenShadows() == other.useOxygenShadows() &&
378
useAnimations() == other.useAnimations() &&
379
animateTitleChange() == other.animateTitleChange() &&
380
animationsDuration() == other.animationsDuration() &&
381
tabsEnabled() == other.tabsEnabled() &&
382
useNarrowButtonSpacing() == other.useNarrowButtonSpacing() &&
383
shadowCacheMode() == other.shadowCacheMode();
387
//__________________________________________________
388
QString Configuration::shadowCacheModeName( ShadowCacheMode value, bool translated )
393
case CacheDisabled: out = translated ? i18n( "Disabled" ):"Disabled"; break;
394
case CacheVariable: out = translated ? i18n( "Variable" ):"Variable"; break;
395
case CacheMaximum: out = translated ? i18n( "Maximum" ):"Maximum"; break;
396
default: return Configuration().shadowCacheModeName( translated );
403
//__________________________________________________
404
Configuration::ShadowCacheMode Configuration::shadowCacheMode( QString value, bool translated )
406
if( value == shadowCacheModeName( CacheDisabled, translated ) ) return CacheDisabled;
407
else if( value == shadowCacheModeName( CacheVariable, translated ) ) return CacheVariable;
408
else if( value == shadowCacheModeName( CacheMaximum, translated ) ) return CacheMaximum;
409
else return Configuration().shadowCacheMode();