33
Q_GLOBAL_STATIC(DecoHelper, s_helper)
35
//______________________________________________________________________________
36
DecoHelper* DecoHelper::self()
38
if (!s_helper.exists()) {
39
//-> operator creates an instance
40
s_helper->loadConfig();
45
33
//______________________________________________________________________________
46
34
DecoHelper::DecoHelper():
47
35
Helper(KSharedConfig::openConfig("oxygenrc"))
147
//_______________________________________________________________________
148
QRegion DecoHelper::decoRoundedMask( const QRect& r, int left, int right, int top, int bottom ) const
152
r.getRect(&x, &y, &w, &h);
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));
161
//______________________________________________________________________________
162
const QColor& DecoHelper::inactiveTitleBarTextColor( const QPalette& palette )
165
const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
166
QColor* out( _titleBarTextColorCache.object( key ) );
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 );
183
//______________________________________________________________________________
184
const QColor& DecoHelper::inactiveButtonTextColor( const QPalette& palette )
187
const quint32 key( colorKey( palette.color(QPalette::Active, QPalette::Window) ) );
188
QColor* out( _buttonTextColorCache.object( key ) );
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 );
204
//_________________________________________________________
205
QColor DecoHelper::reduceContrast(const QColor &c0, const QColor &c1, double t) const
207
const double s( KColorUtils::contrastRatio(c0, c1) );
208
if( s < t ) return c1;
215
for (int maxiter = 16; maxiter; --maxiter)
219
r = KColorUtils::mix(c0, c1, a);
220
x = KColorUtils::contrastRatio(c0, r);
222
if ( std::abs(x - t) < 0.01) break;