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