~ubuntu-branches/ubuntu/wily/oxygen/wily

« back to all changes in this revision

Viewing changes to kdecoration/oxygendecohelper.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Scarlett Clark, Jonathan Riddell
  • Date: 2015-08-10 23:18:51 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20150810231851-wtw33zvkigya4f7t
Tags: 4:5.3.95-0ubuntu1
[ Scarlett Clark ]
* Vivid backport. 

[ Jonathan Riddell ]
* new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
namespace Oxygen
31
31
{
32
32
 
33
 
    Q_GLOBAL_STATIC(DecoHelper, s_helper)
34
 
 
35
 
    //______________________________________________________________________________
36
 
    DecoHelper* DecoHelper::self()
37
 
    {
38
 
        if (!s_helper.exists()) {
39
 
            //-> operator creates an instance
40
 
            s_helper->loadConfig();
41
 
        }
42
 
        return s_helper;
43
 
    }
44
 
 
45
33
    //______________________________________________________________________________
46
34
    DecoHelper::DecoHelper():
47
35
        Helper(KSharedConfig::openConfig("oxygenrc"))
55
43
 
56
44
        // local caches
57
45
        _windecoButtonCache.clear();
58
 
        _titleBarTextColorCache.clear();
59
 
        _buttonTextColorCache.clear();
60
46
 
61
47
    }
62
48
 
83
69
            if( color.isValid() )
84
70
            {
85
71
                p.save();
86
 
                p.translate( 0, -1.4 );
 
72
                p.translate( 0, -0.2 );
87
73
                drawShadow( p, calcShadowColor( color ), 21 );
88
74
                p.restore();
89
75
            }
92
78
            if( glow.isValid() )
93
79
            {
94
80
                p.save();
95
 
                p.translate( 0, -1.4 );
 
81
                p.translate( 0, -0.2 );
96
82
                drawOuterGlow( p, glow, 21 );
97
83
                p.restore();
98
84
            }
99
85
 
100
86
            // button slab
 
87
            p.translate( 0, 1 );
101
88
            p.setWindow( 0, 0, 18, 18 );
102
89
            if( color.isValid() )
103
90
            {
144
131
        return *pixmap;
145
132
    }
146
133
 
147
 
    //_______________________________________________________________________
148
 
    QRegion DecoHelper::decoRoundedMask( const QRect& r, int left, int right, int top, int bottom ) const
149
 
    {
150
 
        // get rect geometry
151
 
        int x, y, w, h;
152
 
        r.getRect(&x, &y, &w, &h);
153
 
 
154
 
        QRegion mask(x + 3*left, y + 0*top, w-3*(left+right), h-0*(top+bottom));
155
 
        mask += QRegion(x + 0*left, y + 3*top, w-0*(left+right), h-3*(top+bottom));
156
 
        mask += QRegion(x + 1*left, y + 1*top, w-1*(left+right), h-1*(top+bottom));
157
 
 
158
 
        return mask;
159
 
    }
160
 
 
161
 
    //______________________________________________________________________________
162
 
    const QColor& DecoHelper::inactiveTitleBarTextColor( const QPalette& palette )
163
 
    {
164
 
 
165
 
        const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
166
 
        QColor* out( _titleBarTextColorCache.object( key ) );
167
 
        if( !out )
168
 
        {
169
 
 
170
 
            // todo: reimplement cache
171
 
            const QColor ab = palette.color(QPalette::Active, QPalette::Window);
172
 
            const QColor af = palette.color(QPalette::Active, QPalette::WindowText);
173
 
            const QColor nb = palette.color(QPalette::Inactive, QPalette::Window);
174
 
            const QColor nf = palette.color(QPalette::Inactive, QPalette::WindowText);
175
 
            out = new QColor( reduceContrast(nb, nf, qMax(qreal(2.5), KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4)))) );
176
 
            _titleBarTextColorCache.insert( key, out );
177
 
        }
178
 
 
179
 
        return *out;
180
 
    }
181
 
 
182
 
 
183
 
    //______________________________________________________________________________
184
 
    const QColor& DecoHelper::inactiveButtonTextColor( const QPalette& palette )
185
 
    {
186
 
 
187
 
        const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
188
 
        QColor* out( _buttonTextColorCache.object( key ) );
189
 
        if( !out )
190
 
        {
191
 
 
192
 
            // todo: reimplement cache
193
 
            const QColor ab = palette.color(QPalette::Active, QPalette::Button);
194
 
            const QColor af = palette.color(QPalette::Active, QPalette::ButtonText);
195
 
            const QColor nb = palette.color(QPalette::Inactive, QPalette::Button);
196
 
            const QColor nf = palette.color(QPalette::Inactive, QPalette::ButtonText);
197
 
            out = new QColor( reduceContrast(nb, nf, qMax(qreal(2.5), KColorUtils::contrastRatio(ab, KColorUtils::mix(ab, af, 0.4)))) );
198
 
            _buttonTextColorCache.insert( key, out );
199
 
        }
200
 
 
201
 
        return *out;
202
 
    }
203
 
 
204
 
    //_________________________________________________________
205
 
    QColor DecoHelper::reduceContrast(const QColor &c0, const QColor &c1, double t) const
206
 
    {
207
 
        const double s( KColorUtils::contrastRatio(c0, c1) );
208
 
        if( s < t ) return c1;
209
 
 
210
 
        double l(0);
211
 
        double h(1.0);
212
 
        double x(s);
213
 
        double a;
214
 
        QColor r( c1 );
215
 
        for (int maxiter = 16; maxiter; --maxiter)
216
 
        {
217
 
 
218
 
            a = 0.5 * (l + h);
219
 
            r = KColorUtils::mix(c0, c1, a);
220
 
            x = KColorUtils::contrastRatio(c0, r);
221
 
 
222
 
            if ( std::abs(x - t) < 0.01) break;
223
 
            if (x > t) h = a;
224
 
            else l = a;
225
 
        }
226
 
 
227
 
        return r;
228
 
    }
229
 
 
230
134
}