• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KStyles

helper.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2007 Matthew Woehlke <mw_triad@users.sourceforge.net>
00003  * Copyright 2007 Casper Boemann <cbr@boemann.dk>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License version 2 as published by the Free Software Foundation.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "helper.h"
00021 #include "elements/scrollbar.h"
00022 #include "elements/progressbar.h"
00023 
00024 #include <KColorUtils>
00025 #include <KColorScheme>
00026 
00027 #include <QtGui/QPainter>
00028 #include <QtGui/QLinearGradient>
00029 
00030 #include <math.h>
00031 
00032 const double OxygenStyleHelper::_slabThickness = 0.45; //TODO: configurable?
00033 
00034 OxygenStyleHelper::OxygenStyleHelper(const QByteArray &componentName)
00035     : OxygenHelper(componentName)
00036 {
00037 }
00038 
00039 QColor OxygenStyleHelper::calcMidColor(const QColor &color) const
00040 {
00041     return KColorScheme::shade(color, KColorScheme::MidShade, _contrast - 1.0);
00042 }
00043 
00044 void OxygenStyleHelper::invalidateCaches()
00045 {
00046     m_slabCache.clear();
00047     m_slabSunkenCache.clear();
00048     m_slabInvertedCache.clear();
00049     m_holeCache.clear();
00050     m_holeFlatCache.clear();
00051     m_slopeCache.clear();
00052     m_slitCache.clear();
00053     m_verticalScrollBarCache.clear();
00054     m_horizontalScrollBarCache.clear();
00055     m_progressBarCache.clear();
00056     OxygenHelper::invalidateCaches();
00057 }
00058 
00059 SlabCache* OxygenStyleHelper::slabCache(const QColor &color)
00060 {
00061     quint64 key = (quint64(color.rgba()) << 32);
00062     SlabCache *cache = m_slabCache.object(key);
00063 
00064     if (!cache)
00065     {
00066         cache = new SlabCache;
00067         m_slabCache.insert(key, cache);
00068     }
00069 
00070     return cache;
00071 }
00072 
00073 QPixmap OxygenStyleHelper::roundSlab(const QColor &color, double shade, int size)
00074 {
00075     SlabCache *cache = slabCache(color);
00076     quint64 key = (int)(256.0 * shade) << 24 | size;
00077     QPixmap *pixmap = cache->m_roundSlabCache.object(key);
00078 
00079     if (!pixmap)
00080     {
00081         pixmap = new QPixmap(size*3, size*3);
00082         pixmap->fill(QColor(0,0,0,0));
00083 
00084         QPainter p(pixmap);
00085         p.setRenderHints(QPainter::Antialiasing);
00086         p.setPen(Qt::NoPen);
00087         p.setWindow(0,0,21,21);
00088 
00089         QColor base = KColorUtils::shade(color, shade);
00090         QColor light = KColorUtils::shade(calcLightColor(color), shade);
00091         QColor dark = KColorUtils::shade(calcDarkColor(color), shade);
00092 
00093         // shadow
00094         drawShadow(p, calcShadowColor(color), 21);
00095 
00096         // bevel, part 1
00097         qreal y = KColorUtils::luma(base);
00098         qreal yl = KColorUtils::luma(light);
00099         qreal yd = KColorUtils::luma(dark);
00100         QLinearGradient bevelGradient1(0, 10, 0, 18);
00101         bevelGradient1.setColorAt(0.0, light);
00102         bevelGradient1.setColorAt(0.9, dark);
00103         if (y < yl && y > yd) // no middle when color is very light/dark
00104             bevelGradient1.setColorAt(0.5, base);
00105         p.setBrush(bevelGradient1);
00106         p.drawEllipse(QRectF(3.0,3.0,15.0,15.0));
00107 
00108         // bevel, part 2
00109         if (_slabThickness > 0.0) {
00110             QLinearGradient bevelGradient2(0, 7, 0, 28);
00111             bevelGradient2.setColorAt(0.0, light);
00112             bevelGradient2.setColorAt(0.9, base);
00113             p.setBrush(bevelGradient2);
00114             p.drawEllipse(QRectF(3.6,3.6,13.8,13.8));
00115         }
00116 
00117         // inside
00118         QLinearGradient innerGradient(0, -17, 0, 20);
00119         innerGradient.setColorAt(0.0, light);
00120         innerGradient.setColorAt(1.0, base);
00121         p.setBrush(innerGradient);
00122         double ic = 3.6 + _slabThickness;
00123         double is = 13.8 - (2.0*_slabThickness);
00124         p.drawEllipse(QRectF(ic, ic, is, is));
00125 
00126         p.end();
00127 
00128         cache->m_roundSlabCache.insert(key, pixmap);
00129     }
00130 
00131     return *pixmap;
00132 }
00133 
00134 QPixmap OxygenStyleHelper::roundSlabFocused(const QColor &color, const QColor &glowColor, double shade, int size)
00135 {
00136     SlabCache *cache = slabCache(color);
00137     quint64 key = (quint64(glowColor.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
00138     QPixmap *pixmap = cache->m_roundSlabCache.object(key);
00139 
00140     if (!pixmap)
00141     {
00142         pixmap = new QPixmap(size*3, size*3);
00143         pixmap->fill(QColor(0,0,0,0));
00144 
00145         QPainter p(pixmap);
00146         p.setRenderHints(QPainter::Antialiasing);
00147         p.setPen(Qt::NoPen);
00148         p.setWindow(0,0,21,21);
00149 
00150         // slab
00151         QPixmap slabPixmap = roundSlab(color, shade, size);
00152         p.drawPixmap(0, 0, slabPixmap);
00153 
00154         // glow
00155         QPixmap gp = glow(glowColor, 21, size*3);
00156         p.drawPixmap(0, 0, gp);
00157 
00158         p.end();
00159 
00160         cache->m_roundSlabCache.insert(key, pixmap);
00161     }
00162     return *pixmap;
00163 }
00164 
00165 void OxygenStyleHelper::drawHole(QPainter &p, const QColor &color, double shade, int r) const
00166 {
00167     const int r2 = 2*r;
00168     QColor base = KColorUtils::shade(color, shade);
00169     QColor light = KColorUtils::shade(calcLightColor(color), shade);
00170     QColor dark = KColorUtils::shade(calcDarkColor(color), shade);
00171     QColor mid = KColorUtils::shade(calcMidColor(color), shade);
00172 
00173     // bevel
00174     qreal y = KColorUtils::luma(base);
00175     qreal yl = KColorUtils::luma(light);
00176     qreal yd = KColorUtils::luma(dark);
00177     QLinearGradient bevelGradient1(0, 2, 0, r2-2);
00178     bevelGradient1.setColorAt(0.2, dark);
00179     bevelGradient1.setColorAt(0.5, mid);
00180     bevelGradient1.setColorAt(1.0, light);
00181     if (y < yl && y > yd) // no middle when color is very light/dark
00182         bevelGradient1.setColorAt(0.6, base);
00183     p.setBrush(bevelGradient1);
00184     p.drawEllipse(3,3,r2-5,r2-5);
00185 
00186     // mask
00187     QRadialGradient maskGradient(r,r,r-2);
00188     maskGradient.setColorAt(0.80, QColor(0,0,0,255));
00189     maskGradient.setColorAt(0.90, QColor(0,0,0,140));
00190     maskGradient.setColorAt(1.00, QColor(0,0,0,0));
00191     p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00192     p.setBrush(maskGradient);
00193     p.drawRect(0,0,r2,r2);
00194     p.setCompositionMode(QPainter::CompositionMode_SourceOver);
00195 }
00196 
00197 void OxygenStyleHelper::drawSlab(QPainter &p, const QColor &color, double shade) const
00198 {
00199     QColor base = KColorUtils::shade(color, shade);
00200     QColor light = KColorUtils::shade(calcLightColor(color), shade);
00201     QColor dark = KColorUtils::shade(calcDarkColor(color), shade);
00202 
00203     // bevel, part 1
00204     qreal y = KColorUtils::luma(base);
00205     qreal yl = KColorUtils::luma(light);
00206     qreal yd = KColorUtils::luma(dark);
00207     QLinearGradient bevelGradient1(0, 7, 0, 11);
00208     bevelGradient1.setColorAt(0.0, light);
00209     if (y < yl && y > yd) // no middle when color is very light/dark
00210         bevelGradient1.setColorAt(0.5, base);
00211     bevelGradient1.setColorAt(0.9, base);
00212     p.setBrush(bevelGradient1);
00213     p.drawEllipse(QRectF(3.0,3.0,8.0,8.0));
00214 
00215     // bevel, part 2
00216     if (_slabThickness > 0.0) {
00217         QLinearGradient bevelGradient2(0, 6, 0, 19);
00218         bevelGradient2.setColorAt(0.0, light);
00219         bevelGradient2.setColorAt(0.9, base);
00220         p.setBrush(bevelGradient2);
00221         p.drawEllipse(QRectF(3.6,3.6,6.8,6.8));
00222     }
00223 
00224     // inside mask
00225     p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
00226     p.setBrush(QBrush(Qt::black));
00227     double ic = 3.6 + _slabThickness;
00228     double is = 6.8 - (2.0*_slabThickness);
00229     p.drawEllipse(QRectF(ic, ic, is, is));
00230 }
00231 
00232 void OxygenStyleHelper::drawInverseShadow(QPainter &p, const QColor &color,
00233                                           int pad, int size, double fuzz) const
00234 {
00235     double m = double(size)*0.5;
00236 
00237     const double offset = 0.8;
00238     double k0 = (m-2.0) / double(m+2.0);
00239     QRadialGradient shadowGradient(pad+m, pad+m+offset, m+2.0);
00240     for (int i = 0; i < 8; i++) { // sinusoidal gradient
00241         double k1 = (double(8 - i) + k0 * double(i)) * 0.125;
00242         double a = (cos(3.14159 * i * 0.125) + 1.0) * 0.25;
00243         shadowGradient.setColorAt(k1, alphaColor(color, a * _shadowGain));
00244     }
00245     shadowGradient.setColorAt(k0, alphaColor(color, 0.0));
00246     p.setBrush(shadowGradient);
00247     p.drawEllipse(QRectF(pad-fuzz, pad-fuzz, size+fuzz*2.0, size+fuzz*2.0));
00248 }
00249 
00250 void OxygenStyleHelper::drawInverseGlow(QPainter &p, const QColor &color,
00251                                         int pad, int size, int rsize) const
00252 {
00253     QRectF r(pad, pad, size, size);
00254     double m = double(size)*0.5;
00255 
00256     const double width = 3.0;
00257     const double bias = _glowBias * 7.0 / double(rsize);
00258     double k0 = (m-width) / (m-bias);
00259     QRadialGradient glowGradient(pad+m, pad+m, m-bias);
00260     for (int i = 0; i < 8; i++) { // inverse parabolic gradient
00261         double k1 = (k0 * double(i) + double(8 - i)) * 0.125;
00262         double a = 1.0 - sqrt(i * 0.125);
00263         glowGradient.setColorAt(k1, alphaColor(color, a));
00264     }
00265     glowGradient.setColorAt(k0, alphaColor(color, 0.0));
00266     p.setBrush(glowGradient);
00267     p.drawEllipse(r);
00268 }
00269 
00270 void OxygenStyleHelper::fillSlab(QPainter &p, const QRect &rect, int size)
00271 {
00272     const double s = double(size) * (3.6 + (0.5 * _slabThickness)) / 7.0;
00273     QRectF r = rect;
00274     r.adjust(s, s, -s, -s);
00275     double w = r.width(), h = r.height();
00276     if (w <= 0 || h <= 0)
00277         return;
00278     const double ra = 200.0 * (7.0 - (3.6 + (0.5 * _slabThickness))) / 7.0;
00279     qreal rx = floor((ra*size) / w);
00280     qreal ry = floor((ra*size) / h);
00281 
00282     p.drawRoundRect(r, rx, ry);
00283 }
00284 
00285 void OxygenStyleHelper::fillHole(QPainter &p, const QRect &rect, int size)
00286 {
00287     const double s = double(size) * 3.0 / 7.0;
00288     p.drawRoundedRect(rect.adjusted(s,s,-s,-s), 4, 4);
00289 }
00290 
00291 TileSet *OxygenStyleHelper::slab(const QColor &color, double shade, int size)
00292 {
00293     SlabCache *cache = slabCache(color);
00294     quint64 key = (int)(256.0 * shade) << 24 | size;
00295     TileSet *tileSet = cache->m_slabCache.object(key);
00296 
00297     if (!tileSet)
00298     {
00299         QPixmap pixmap(size*2, size*2);
00300         pixmap.fill(QColor(0,0,0,0));
00301 
00302         QPainter p(&pixmap);
00303         p.setRenderHints(QPainter::Antialiasing);
00304         p.setPen(Qt::NoPen);
00305         p.setWindow(0,0,14,14);
00306 
00307         // shadow
00308         drawShadow(p, calcShadowColor(color), 14);
00309 
00310         // slab
00311         drawSlab(p, color, shade);
00312 
00313         p.end();
00314 
00315         tileSet = new TileSet(pixmap, size, size, size, size, size-1, size, 2, 1);
00316 
00317         cache->m_slabCache.insert(key, tileSet);
00318     }
00319     return tileSet;
00320 }
00321 
00322 TileSet *OxygenStyleHelper::slabFocused(const QColor &color, const QColor &glowColor, double shade, int size)
00323 {
00324     SlabCache *cache = slabCache(color);
00325     quint64 key = (quint64(glowColor.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
00326     TileSet *tileSet = cache->m_slabCache.object(key);
00327 
00328     if (!tileSet)
00329     {
00330         QPixmap pixmap(size*2,size*2);
00331         pixmap.fill(QColor(0,0,0,0));
00332 
00333         QPainter p(&pixmap);
00334         p.setRenderHints(QPainter::Antialiasing);
00335         p.setPen(Qt::NoPen);
00336         p.setWindow(0,0,14,14);
00337 
00338         TileSet *slabTileSet = slab(color, shade, size);
00339 
00340         // slab
00341         slabTileSet->render(QRect(0,0,14,14), &p);
00342 
00343         // glow
00344         QPixmap gp = glow(glowColor, 14, size*2);
00345         p.drawPixmap(0, 0, gp);
00346 
00347         p.end();
00348 
00349         tileSet = new TileSet(pixmap, size, size, size, size, size-1, size, 2, 1);
00350 
00351         cache->m_slabCache.insert(key, tileSet);
00352     }
00353     return tileSet;
00354 }
00355 
00356 TileSet *OxygenStyleHelper::slabSunken(const QColor &color, double shade, int size)
00357 {
00358     quint64 key = (quint64(color.rgba()) << 32);
00359     TileSet *tileSet = m_slabSunkenCache.object(key);
00360 
00361     if (!tileSet)
00362     {
00363         QPixmap pixmap(size*2, size*2);
00364         pixmap.fill(QColor(0,0,0,0));
00365 
00366         QPainter p(&pixmap);
00367         p.setRenderHints(QPainter::Antialiasing);
00368         p.setPen(Qt::NoPen);
00369         p.setWindow(0,0,14,14);
00370 
00371         // slab
00372         drawSlab(p, color, shade);
00373 
00374         // shadow
00375         p.setCompositionMode(QPainter::CompositionMode_SourceOver);
00376         drawInverseShadow(p, calcShadowColor(color), 3, 8, 0.0);
00377 
00378         p.end();
00379 
00380         tileSet = new TileSet(pixmap, size, size, size, size, size-1, size, 2, 1);
00381 
00382         m_slabSunkenCache.insert(key, tileSet);
00383     }
00384     return tileSet;
00385 }
00386 
00387 TileSet *OxygenStyleHelper::slabInverted(const QColor &color, double shade, int size)
00388 {
00389     quint64 key = (quint64(color.rgba()) << 32);
00390     TileSet *tileSet = m_slabInvertedCache.object(key);
00391 
00392     if (!tileSet)
00393     {
00394         QPixmap pixmap(size*2, size*2);
00395         pixmap.fill(QColor(0,0,0,0));
00396 
00397         QPainter p(&pixmap);
00398         p.setRenderHints(QPainter::Antialiasing);
00399         p.setPen(Qt::NoPen);
00400         p.setWindow(0,0,14,14);
00401 
00402         QColor base = KColorUtils::shade(color, shade);
00403         QColor light = KColorUtils::shade(calcLightColor(color), shade);
00404         QColor dark = KColorUtils::shade(calcDarkColor(color), shade);
00405 
00406         // bevel, part 2
00407         QLinearGradient bevelGradient2(0, 8, 0, -8);
00408         bevelGradient2.setColorAt(0.0, light);
00409         bevelGradient2.setColorAt(0.9, base);
00410         p.setBrush(bevelGradient2);
00411         p.drawEllipse(QRectF(2.6,2.6,8.8,8.8));
00412 
00413         // bevel, part 1
00414         qreal y = KColorUtils::luma(base);
00415         qreal yl = KColorUtils::luma(light);
00416         qreal yd = KColorUtils::luma(dark);
00417         QLinearGradient bevelGradient1(0, 7, 0, 4);
00418         bevelGradient1.setColorAt(0.0, light);
00419         bevelGradient1.setColorAt(0.9, dark);
00420         if (y < yl && y > yd) // no middle when color is very light/dark
00421             bevelGradient1.setColorAt(0.5, base);
00422         p.setBrush(bevelGradient1);
00423         p.drawEllipse(QRectF(3.4,3.4,7.2,7.2));
00424 
00425         // inside mask
00426         p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
00427         p.setBrush(QBrush(Qt::black));
00428         p.drawEllipse(QRectF(4.0,4.0,6.0,6.0));
00429 
00430         // shadow
00431         p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
00432         drawInverseShadow(p, calcShadowColor(color), 4, 6, 0.5);
00433 
00434         p.end();
00435 
00436         tileSet = new TileSet(pixmap, size, size, size, size, size-1, size, 2, 1);
00437 
00438         m_slabInvertedCache.insert(key, tileSet);
00439     }
00440     return tileSet;
00441 }
00442 
00443 TileSet *OxygenStyleHelper::slope(const QColor &color, double shade, int size)
00444 {
00445     quint64 key = (quint64(color.rgba()) << 32);
00446     TileSet *tileSet = m_slopeCache.object(key);
00447 
00448     if (!tileSet)
00449     {
00450         // TODO - rebase??
00451         QPixmap pixmap(size*4, size*4);
00452         pixmap.fill(QColor(0,0,0,0));
00453 
00454         QPainter p(&pixmap);
00455         p.setPen(Qt::NoPen);
00456 
00457         // edges
00458         TileSet *slabTileSet = slab(color, shade, size);
00459         slabTileSet->render(QRect(0, 0, size*4, size*5), &p,
00460                             TileSet::Left | TileSet::Right | TileSet::Top);
00461 
00462         p.setWindow(0,0,28,28);
00463 
00464         // bottom
00465         QColor base = color;
00466         QColor light = KColorUtils::shade(calcLightColor(color), shade);
00467         QLinearGradient fillGradient(0, -28, 0, 28);
00468         light.setAlphaF(0.4);
00469         fillGradient.setColorAt(0.0, light);
00470         base.setAlphaF(0.4);
00471         fillGradient.setColorAt(1.0, base);
00472         p.setBrush(fillGradient);
00473         p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
00474         p.drawRect(3, 9, 22, 17);
00475 
00476         // fade bottom
00477         QLinearGradient maskGradient(0, 7, 0, 28);
00478         maskGradient.setColorAt(0.0, QColor(0, 0, 0, 255));
00479         maskGradient.setColorAt(1.0, QColor(0, 0, 0, 0));
00480 
00481         p.setBrush(maskGradient);
00482         p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
00483         p.drawRect(0, 9, 28, 19);
00484 
00485         tileSet = new TileSet(pixmap, size, size, size*2, 2);
00486         m_slopeCache.insert(key, tileSet);
00487     }
00488     return tileSet;
00489 }
00490 
00491 TileSet *OxygenStyleHelper::hole(const QColor &color, double shade, int size)
00492 {
00493     quint64 key = (quint64(color.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
00494     TileSet *tileSet = m_holeCache.object(key);
00495 
00496     if (!tileSet)
00497     {
00498         int rsize = (int)ceil(double(size) * 5.0/7.0);
00499         QPixmap pixmap(rsize*2, rsize*2);
00500         pixmap.fill(QColor(0,0,0,0));
00501 
00502         QPainter p(&pixmap);
00503         p.setRenderHints(QPainter::Antialiasing);
00504         p.setPen(Qt::NoPen);
00505         p.setWindow(2,2,10,10);
00506 
00507         // hole mask
00508         p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
00509         p.setBrush(Qt::black);
00510         p.drawEllipse(3,3,8,8);
00511 
00512         // shadow
00513         p.setCompositionMode(QPainter::CompositionMode_SourceOver);
00514         drawInverseShadow(p, calcShadowColor(color), 3, 8, 0.0);
00515 
00516         p.end();
00517 
00518         tileSet = new TileSet(pixmap, rsize, rsize, rsize, rsize, rsize-1, rsize, 2, 1);
00519 
00520         m_holeCache.insert(key, tileSet);
00521     }
00522     return tileSet;
00523 }
00524 
00525 TileSet *OxygenStyleHelper::holeFlat(const QColor &color, double shade, int size)
00526 {
00527     quint64 key = (quint64(color.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
00528     TileSet *tileSet = m_holeFlatCache.object(key);
00529 
00530     if (!tileSet)
00531     {
00532         int rsize = (int)ceil(double(size) * 5.0/7.0);
00533         QPixmap pixmap(rsize*2, rsize*2);
00534         pixmap.fill(QColor(0,0,0,0));
00535 
00536         QPainter p(&pixmap);
00537         p.setRenderHints(QPainter::Antialiasing);
00538         p.setPen(Qt::NoPen);
00539         p.setWindow(2,2,10,10);
00540 
00541         // hole
00542         drawHole(p, color, shade, 7);
00543 
00544         // hole inside
00545         p.setBrush(color);
00546         p.drawEllipse(QRectF(3.2,3.2,7.6,7.6));
00547 
00548         p.end();
00549 
00550         tileSet = new TileSet(pixmap, rsize, rsize, rsize, rsize, rsize-1, rsize, 2, 1);
00551 
00552         m_holeFlatCache.insert(key, tileSet);
00553     }
00554     return tileSet;
00555 }
00556 
00557 TileSet *OxygenStyleHelper::holeFocused(const QColor &color, const QColor &glowColor, double shade, int size)
00558 {
00559     // FIXME must move to s/slabcache/cache/ b/c key is wrong
00560     quint64 key = (quint64(color.rgba()) << 32) | quint64(glowColor.rgba());
00561     TileSet *tileSet = m_holeCache.object(key);
00562 
00563     if (!tileSet)
00564     {
00565         int rsize = (int)ceil(double(size) * 5.0/7.0);
00566         QPixmap pixmap(rsize*2, rsize*2);
00567         pixmap.fill(QColor(0,0,0,0));
00568 
00569         QPainter p(&pixmap);
00570         p.setRenderHints(QPainter::Antialiasing);
00571         p.setPen(Qt::NoPen);
00572 
00573         TileSet *holeTileSet = hole(color, shade, size);
00574 
00575         // hole
00576         holeTileSet->render(QRect(0,0,10,10), &p);
00577 
00578         p.setWindow(2,2,10,10);
00579 
00580         // glow
00581         drawInverseGlow(p, glowColor, 3, 8, size);
00582 
00583         p.end();
00584 
00585         tileSet = new TileSet(pixmap, rsize, rsize, rsize, rsize, rsize-1, rsize, 2, 1);
00586 
00587         m_holeCache.insert(key, tileSet);
00588     }
00589     return tileSet;
00590 }
00591 
00592 TileSet *OxygenStyleHelper::groove(const QColor &color, double shade, int size)
00593 {
00594     quint64 key = (quint64(color.rgba()) << 32) | (int)(256.0 * shade) << 24 | size;
00595     TileSet *tileSet = m_grooveCache.object(key);
00596 
00597     if (!tileSet)
00598     {
00599         int rsize = (int)ceil(double(size) * 3.0/7.0);
00600         QPixmap pixmap(rsize*2, rsize*2);
00601         pixmap.fill(QColor(0,0,0,0));
00602 
00603         QPainter p(&pixmap);
00604         p.setRenderHints(QPainter::Antialiasing);
00605         p.setPen(Qt::NoPen);
00606         p.setWindow(2,2,6,6);
00607 
00608         // hole mask
00609         p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
00610         p.setBrush(Qt::black);
00611         p.drawEllipse(4,4,2,2);
00612 
00613         // shadow
00614         p.setCompositionMode(QPainter::CompositionMode_SourceOver);
00615         drawInverseShadow(p, calcShadowColor(color), 3, 4, 0.0);
00616 
00617         p.end();
00618 
00619         tileSet = new TileSet(pixmap, rsize, rsize, rsize, rsize, rsize-1, rsize, 2, 1);
00620 
00621         m_grooveCache.insert(key, tileSet);
00622     }
00623     return tileSet;
00624 }
00625 
00626 TileSet *OxygenStyleHelper::slitFocused(const QColor &glowColor)
00627 {
00628     quint64 key = (quint64(glowColor.rgba()) << 32);
00629     TileSet *tileSet = m_slitCache.object(key);
00630 
00631     if (!tileSet)
00632     {
00633         QImage tmpImg(9, 9, QImage::Format_ARGB32);
00634         QPainter p;
00635 
00636         tmpImg.fill(Qt::transparent);
00637 
00638         p.begin(&tmpImg);
00639         p.setPen(Qt::NoPen);
00640         p.setRenderHint(QPainter::Antialiasing);
00641         QRadialGradient rg = QRadialGradient(4.5, 4.5, 4.5, 4.5, 4.5);
00642         QColor tmpColor = glowColor;
00643         tmpColor.setAlpha(180);
00644         rg.setColorAt(0.75, tmpColor);
00645         tmpColor.setAlpha(0);
00646         rg.setColorAt(0.90, tmpColor);
00647         rg.setColorAt(0.4, tmpColor);
00648         p.setBrush(rg);
00649         p.drawEllipse(QRectF(0, 0, 9, 9));
00650 
00651         tileSet = new TileSet(QPixmap::fromImage(tmpImg), 4, 4, 1, 1);
00652 
00653         m_slitCache.insert(key, tileSet);
00654     }
00655     return tileSet;
00656 }
00657 
00658 TileSet *OxygenStyleHelper::verticalScrollBar(const QColor &color, int width, int offset, int size)
00659 {
00660     size = (size*4)/3; // this code is writetn wrong :-), with base size == 8, not 6
00661     offset %= (size * 4);
00662 
00663     quint64 key = (quint64(color.rgba()) << 32) | (width<<22) | (offset<<10) | size;
00664     TileSet *tileSet = m_verticalScrollBarCache.object(key);
00665     if (!tileSet)
00666     {
00667         tileSet = OxygenScrollbar(color, _contrast).vertical(size, width, offset);
00668         m_verticalScrollBarCache.insert(key, tileSet);
00669     }
00670     return tileSet;
00671 }
00672 
00673 TileSet *OxygenStyleHelper::horizontalScrollBar(const QColor &color, int width, int offset, int size)
00674 {
00675     size = (size*4)/3; // this code is writetn wrong :-), with base size == 8, not 6
00676     offset %= (size * 4);
00677 
00678     quint64 key = (quint64(color.rgba()) << 32) | (width<<12) | offset;
00679     TileSet *tileSet = m_horizontalScrollBarCache.object(key);
00680     if (!tileSet)
00681     {
00682         tileSet = OxygenScrollbar(color, _contrast).horizontal(size, width, offset);
00683         m_horizontalScrollBarCache.insert(key, tileSet);
00684     }
00685     return tileSet;
00686 }
00687 
00688 TileSet *OxygenStyleHelper::progressBar(const QColor &color, QRect rect,  Qt::Orientation orient, int size)
00689 {
00690     size = (size*4)/3; // this code is writetn wrong :-), with base size == 8, not 6
00691     int width;
00692     if (orient == Qt::Horizontal)
00693         width = rect.height();
00694     else
00695         width = rect.width();
00696 
00697     quint64 key = (quint64(color.rgba()) << 32) | (width<<1) | (orient == Qt::Horizontal);
00698     TileSet *tileSet = m_progressBarCache.object(key);
00699     if (!tileSet)
00700     {
00701         if (orient == Qt::Horizontal)
00702             tileSet = OxygenProgressBar(color, _contrast).horizontal(size, width);
00703         else
00704             tileSet = OxygenProgressBar(color, _contrast).vertical(size, width);
00705         m_progressBarCache.insert(key, tileSet);
00706     }
00707     return tileSet;
00708 }

KStyles

Skip menu "KStyles"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal