~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/oxygenconfiguration.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygenconfiguration.cpp
 
3
// decoration configuration
 
4
// -------------------
 
5
//
 
6
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
7
//
 
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:
 
14
//
 
15
// The above copyright notice and this permission notice shall be included in
 
16
// all copies or substantial portions of the Software.
 
17
//
 
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
 
24
// IN THE SOFTWARE.
 
25
//////////////////////////////////////////////////////////////////////////////
 
26
 
 
27
#include "oxygenconfiguration.h"
 
28
#include "oxygenshadowconfiguration.h"
 
29
#include "oxygenexception.h"
 
30
 
 
31
#include <QTextStream>
 
32
#include <KLocale>
 
33
 
 
34
namespace Oxygen
 
35
{
 
36
 
 
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 ),
 
53
        _tabsEnabled( true ),
 
54
        _useNarrowButtonSpacing( false ),
 
55
        _shadowCacheMode( CacheVariable )
 
56
    {}
 
57
 
 
58
    //__________________________________________________
 
59
    Configuration::Configuration( KConfigGroup group )
 
60
    {
 
61
 
 
62
        // used to set default values when entries are not found in kconfig
 
63
        Configuration defaultConfiguration;
 
64
 
 
65
        // title alignment
 
66
        setTitleAlignment( titleAlignment(
 
67
            group.readEntry( OxygenConfig::TITLE_ALIGNMENT,
 
68
            defaultConfiguration.titleAlignmentName( false ) ), false ) );
 
69
 
 
70
        // center title on full width
 
71
        setCenterTitleOnFullWidth( group.readEntry( OxygenConfig::CENTER_TITLE_ON_FULL_WIDTH,
 
72
            defaultConfiguration.centerTitleOnFullWidth() ) );
 
73
 
 
74
        // button size
 
75
        setButtonSize( buttonSize(
 
76
            group.readEntry( OxygenConfig::BUTTON_SIZE,
 
77
            defaultConfiguration.buttonSizeName( false ) ), false ) );
 
78
 
 
79
        // frame border
 
80
        setFrameBorder( frameBorder(
 
81
            group.readEntry( OxygenConfig::FRAME_BORDER,
 
82
            defaultConfiguration.frameBorderName( false ) ), false ) );
 
83
 
 
84
        // blend color
 
85
        setBlendColor( blendColor(
 
86
            group.readEntry( OxygenConfig::BLEND_COLOR,
 
87
            defaultConfiguration.blendColorName( false ) ), false ) );
 
88
 
 
89
        // size grip
 
90
        setSizeGripMode( sizeGripMode(
 
91
            group.readEntry( OxygenConfig::SIZE_GRIP_MODE,
 
92
            defaultConfiguration.sizeGripModeName( false ) ), false ) );
 
93
 
 
94
        // separator mode
 
95
        if( !group.readEntry( OxygenConfig::DRAW_SEPARATOR, defaultConfiguration.separatorMode() != SeparatorNever ) )
 
96
        {
 
97
 
 
98
            setSeparatorMode( SeparatorNever );
 
99
 
 
100
        } else if( group.readEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, defaultConfiguration.separatorMode() == SeparatorActive ) ) {
 
101
 
 
102
            setSeparatorMode( SeparatorActive );
 
103
 
 
104
        } else setSeparatorMode( SeparatorAlways );
 
105
 
 
106
        // title outline
 
107
        setDrawTitleOutline( group.readEntry(
 
108
            OxygenConfig::DRAW_TITLE_OUTLINE,
 
109
            defaultConfiguration.drawTitleOutline() ) );
 
110
 
 
111
        // hide title bar
 
112
        setHideTitleBar( group.readEntry(
 
113
            OxygenConfig::HIDE_TITLEBAR,
 
114
            defaultConfiguration.hideTitleBar() ) );
 
115
 
 
116
        // drop shadows
 
117
        setUseDropShadows( group.readEntry(
 
118
            OxygenConfig::USE_DROP_SHADOWS,
 
119
            defaultConfiguration.useDropShadows() ) );
 
120
 
 
121
        // oxygen shadows
 
122
        setUseOxygenShadows( group.readEntry(
 
123
            OxygenConfig::USE_OXYGEN_SHADOWS,
 
124
            defaultConfiguration.useOxygenShadows() ) );
 
125
 
 
126
        // animations
 
127
        setUseAnimations( group.readEntry(
 
128
            OxygenConfig::USE_ANIMATIONS,
 
129
            defaultConfiguration.useAnimations() ) );
 
130
 
 
131
        // animations
 
132
        setAnimateTitleChange( group.readEntry(
 
133
            OxygenConfig::ANIMATE_TITLE_CHANGE,
 
134
            defaultConfiguration.animateTitleChange() ) );
 
135
 
 
136
        // animations
 
137
        setAnimationsDuration( group.readEntry(
 
138
            OxygenConfig::ANIMATIONS_DURATION,
 
139
            defaultConfiguration.animationsDuration() ) );
 
140
 
 
141
        // tabbing
 
142
        setTabsEnabled( group.readEntry(
 
143
            OxygenConfig::TABS_ENABLED,
 
144
            defaultConfiguration.tabsEnabled() ) );
 
145
 
 
146
        // buttonSpacing
 
147
        setUseNarrowButtonSpacing( group.readEntry(
 
148
            OxygenConfig::NARROW_BUTTON_SPACING,
 
149
            defaultConfiguration.useNarrowButtonSpacing() ) );
 
150
 
 
151
        // shadow cache mode
 
152
        setShadowCacheMode( shadowCacheMode( group.readEntry(
 
153
            OxygenConfig::SHADOW_CACHE_MODE, defaultConfiguration.shadowCacheModeName( false ) ), false ) );
 
154
 
 
155
    }
 
156
 
 
157
    //__________________________________________________
 
158
    void Configuration::readException( const Exception& exception )
 
159
    {
 
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() );
 
167
    }
 
168
 
 
169
    //__________________________________________________
 
170
    void Configuration::write( KConfigGroup& group ) const
 
171
    {
 
172
 
 
173
        Configuration defaultConfiguration;
 
174
 
 
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 ) );
 
178
 
 
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 ) );
 
182
 
 
183
        if( separatorMode() != defaultConfiguration.separatorMode() )
 
184
        {
 
185
            group.writeEntry( OxygenConfig::DRAW_SEPARATOR, separatorMode() != SeparatorNever );
 
186
            group.writeEntry( OxygenConfig::SEPARATOR_ACTIVE_ONLY, separatorMode() == SeparatorActive );
 
187
        }
 
188
 
 
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 ) );
 
199
 
 
200
    }
 
201
 
 
202
    //__________________________________________________
 
203
    QString Configuration::titleAlignmentName( Qt::Alignment value, bool translated, bool fullWidth )
 
204
    {
 
205
        QString out;
 
206
        switch( value )
 
207
        {
 
208
            case Qt::AlignLeft: out = translated ? i18n( "Left" ):"Left"; break;
 
209
            case Qt::AlignHCenter:
 
210
            {
 
211
 
 
212
                if( fullWidth ) out = translated ? i18n( "Center (Full Width)" ):"Center (Full Width)";
 
213
                else out = translated ? i18n( "Center" ):"Center";
 
214
 
 
215
            } break;
 
216
            case Qt::AlignRight: out = translated ? i18n( "Right" ):"Right"; break;
 
217
            default: return Configuration().titleAlignmentName( translated );
 
218
        }
 
219
 
 
220
        return out;
 
221
 
 
222
    }
 
223
 
 
224
    //__________________________________________________
 
225
    Qt::Alignment Configuration::titleAlignment( QString value, bool translated )
 
226
    {
 
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();
 
231
    }
 
232
 
 
233
    //__________________________________________________
 
234
    QString Configuration::buttonSizeName( ButtonSize value, bool translated )
 
235
    {
 
236
        QString out;
 
237
        switch( value )
 
238
        {
 
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 );
 
245
        }
 
246
 
 
247
        return out;
 
248
 
 
249
    }
 
250
 
 
251
    //__________________________________________________
 
252
    Configuration::ButtonSize Configuration::buttonSize( QString value, bool translated )
 
253
    {
 
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();
 
260
    }
 
261
 
 
262
    //__________________________________________________
 
263
    int Configuration::iconScale( ButtonSize value )
 
264
    {
 
265
        switch( value )
 
266
        {
 
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();
 
273
        }
 
274
 
 
275
    }
 
276
 
 
277
    //__________________________________________________
 
278
    QString Configuration::frameBorderName( FrameBorder value, bool translated )
 
279
    {
 
280
        QString out;
 
281
        switch( value )
 
282
        {
 
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 );
 
293
        }
 
294
 
 
295
        return out;
 
296
 
 
297
    }
 
298
 
 
299
    //__________________________________________________
 
300
    Configuration::FrameBorder Configuration::frameBorder( QString value, bool translated )
 
301
    {
 
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();
 
312
    }
 
313
 
 
314
    //__________________________________________________
 
315
    QString Configuration::blendColorName( BlendColorType value, bool translated )
 
316
    {
 
317
        QString out;
 
318
        switch( value )
 
319
        {
 
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 );
 
324
        }
 
325
 
 
326
        return out;
 
327
 
 
328
    }
 
329
 
 
330
    //__________________________________________________
 
331
    Configuration::BlendColorType Configuration::blendColor( QString value, bool translated )
 
332
    {
 
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();
 
337
    }
 
338
 
 
339
    //__________________________________________________
 
340
    QString Configuration::sizeGripModeName( SizeGripMode value, bool translated )
 
341
    {
 
342
        QString out;
 
343
        switch( value )
 
344
        {
 
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 );
 
348
        }
 
349
 
 
350
        return out;
 
351
 
 
352
    }
 
353
 
 
354
    //__________________________________________________
 
355
    Configuration::SizeGripMode Configuration::sizeGripMode( QString value, bool translated )
 
356
    {
 
357
        if( value == sizeGripModeName( SizeGripNever, translated ) ) return SizeGripNever;
 
358
        else if( value == sizeGripModeName( SizeGripWhenNeeded, translated ) ) return SizeGripWhenNeeded;
 
359
        else return Configuration().sizeGripMode();
 
360
    }
 
361
 
 
362
    //________________________________________________________
 
363
    bool Configuration::operator == (const Configuration& other ) const
 
364
    {
 
365
 
 
366
        return
 
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();
 
384
 
 
385
    }
 
386
 
 
387
    //__________________________________________________
 
388
    QString Configuration::shadowCacheModeName( ShadowCacheMode value, bool translated )
 
389
    {
 
390
        QString out;
 
391
        switch( value )
 
392
        {
 
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 );
 
397
        }
 
398
 
 
399
        return out;
 
400
 
 
401
    }
 
402
 
 
403
    //__________________________________________________
 
404
    Configuration::ShadowCacheMode Configuration::shadowCacheMode( QString value, bool translated )
 
405
    {
 
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();
 
410
    }
 
411
 
 
412
}