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

« back to all changes in this revision

Viewing changes to libs/oxygen/oxygenshadowconfiguration.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
// oxygenshadowconfiguration.cpp
 
3
// shadow 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 "oxygenshadowconfiguration.h"
 
28
 
 
29
#include <cassert>
 
30
 
 
31
namespace Oxygen
 
32
{
 
33
 
 
34
    //_________________________________________________________
 
35
    ShadowConfiguration::ShadowConfiguration( QPalette::ColorGroup colorGroup ):
 
36
        _colorGroup( colorGroup ),
 
37
        _enabled( true )
 
38
    {
 
39
 
 
40
        // check colorgroup
 
41
        assert( colorGroup == QPalette::Active || colorGroup == QPalette::Inactive );
 
42
 
 
43
        if( colorGroup == QPalette::Active )
 
44
        {
 
45
 
 
46
            _shadowSize = 40;
 
47
            _horizontalOffset = 0;
 
48
            _verticalOffset = 0.1;
 
49
            _useOuterColor = true;
 
50
 
 
51
            _innerColor = QColor( "#70EFFF" );
 
52
            _outerColor = QColor( "#54A7F0" );
 
53
            _outerColor2 = calcOuterColor();
 
54
            _midColor = calcMidColor();
 
55
 
 
56
        } else {
 
57
 
 
58
            _shadowSize = 40;
 
59
            _horizontalOffset = 0;
 
60
            _verticalOffset = 0.2;
 
61
            _useOuterColor = false;
 
62
 
 
63
            _innerColor = QColor( Qt::black );
 
64
            _outerColor = _outerColor2 = calcOuterColor();
 
65
            _midColor = calcMidColor();
 
66
 
 
67
        }
 
68
 
 
69
    }
 
70
 
 
71
    //_________________________________________________________
 
72
    ShadowConfiguration::ShadowConfiguration( QPalette::ColorGroup colorGroup, const KConfigGroup& group ):
 
73
        _colorGroup( colorGroup ),
 
74
        _enabled( true )
 
75
    {
 
76
 
 
77
        // get default configuration
 
78
        ShadowConfiguration defaultConfiguration( ShadowConfiguration::colorGroup() );
 
79
 
 
80
        setShadowSize( group.readEntry( OxygenConfig::SHADOW_SIZE, defaultConfiguration.shadowSize() ) );
 
81
        setHorizontalOffset( group.readEntry( OxygenConfig::SHADOW_HOFFSET, defaultConfiguration.horizontalOffset() ) );
 
82
        setVerticalOffset( group.readEntry( OxygenConfig::SHADOW_VOFFSET, defaultConfiguration.verticalOffset() ) );
 
83
        setUseOuterColor( group.readEntry( OxygenConfig::SHADOW_USE_OUTER_COLOR, defaultConfiguration.useOuterColor() ) );
 
84
 
 
85
        setInnerColor( group.readEntry( OxygenConfig::SHADOW_INNER_COLOR, defaultConfiguration.innerColor() ) );
 
86
        setOuterColor( group.readEntry( OxygenConfig::SHADOW_OUTER_COLOR, defaultConfiguration.outerColor() ) );
 
87
        setOuterColor2( calcOuterColor() );
 
88
        setMidColor( calcMidColor() );
 
89
 
 
90
    }
 
91
 
 
92
    //_________________________________________________________
 
93
    void ShadowConfiguration::write( KConfigGroup& group ) const
 
94
    {
 
95
        ShadowConfiguration defaultConfiguration( _colorGroup );
 
96
        if( shadowSize() != defaultConfiguration.shadowSize() ) group.writeEntry( OxygenConfig::SHADOW_SIZE, shadowSize() );
 
97
        if( horizontalOffset() != defaultConfiguration.horizontalOffset() ) group.writeEntry( OxygenConfig::SHADOW_HOFFSET, horizontalOffset() );
 
98
        if( verticalOffset() != defaultConfiguration.verticalOffset() ) group.writeEntry( OxygenConfig::SHADOW_VOFFSET, verticalOffset() );
 
99
        if( innerColor() != defaultConfiguration.innerColor() ) group.writeEntry( OxygenConfig::SHADOW_INNER_COLOR, innerColor().name() );
 
100
        if( outerColor() != defaultConfiguration.outerColor() ) group.writeEntry( OxygenConfig::SHADOW_OUTER_COLOR, outerColor().name() );
 
101
        if( useOuterColor() != defaultConfiguration.useOuterColor() ) group.writeEntry( OxygenConfig::SHADOW_USE_OUTER_COLOR, useOuterColor() );
 
102
    }
 
103
 
 
104
    //_________________________________________________________
 
105
    void ShadowConfiguration::setInnerColor( QColor color )
 
106
    { _innerColor = color.isValid() ? color : ShadowConfiguration( colorGroup() ).innerColor(); }
 
107
 
 
108
    //_________________________________________________________
 
109
    void ShadowConfiguration::setMidColor( QColor color )
 
110
    { _midColor = color.isValid() ? color : ShadowConfiguration( colorGroup() ).midColor(); }
 
111
 
 
112
    //_________________________________________________________
 
113
    void ShadowConfiguration::setOuterColor( QColor color )
 
114
    { _outerColor = color.isValid() ? color : ShadowConfiguration( colorGroup() ).outerColor(); }
 
115
 
 
116
    //_________________________________________________________
 
117
    void ShadowConfiguration::setOuterColor2( QColor color )
 
118
    { _outerColor2 = color.isValid() ? color : ShadowConfiguration( colorGroup() ).outerColor2(); }
 
119
 
 
120
    //_________________________________________________________
 
121
    QColor ShadowConfiguration::calcOuterColor( void ) const
 
122
    {
 
123
        QColor innerColor( ShadowConfiguration::innerColor() );
 
124
        assert( innerColor.isValid() );
 
125
 
 
126
        // should contain a more ellaborate mathematical formula
 
127
        // to calculate outer color from inner color
 
128
        return innerColor;
 
129
    }
 
130
 
 
131
    //_________________________________________________________
 
132
    QColor ShadowConfiguration::calcMidColor( void ) const
 
133
    {
 
134
        QColor innerColor( ShadowConfiguration::innerColor() );
 
135
        QColor outerColor( ShadowConfiguration::outerColor() );
 
136
        assert( innerColor.isValid() && outerColor.isValid() );
 
137
 
 
138
        // should contain a more ellaborate mathematical formula
 
139
        // to calculate mid color from inner and outer colors
 
140
        return outerColor;
 
141
    }
 
142
 
 
143
}