Back to index

kdeartwork  4.3.2
Static.cpp
Go to the documentation of this file.
00001 /*
00002   RISC OS KWin client
00003 
00004   Copyright 2000
00005     Rik Hemsley <rik@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU General Public
00009   License as published by the Free Software Foundation; either
00010   version 2 of the License, or (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018   along with this program; see the file COPYING.  If not, write to
00019   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020   Boston, MA 02110-1301, USA.
00021 */
00022 
00023 // for enable-final
00024 #ifdef Bool
00025 #undef Bool
00026 #endif
00027 
00028 #include <qimage.h>
00029 #include <qpixmap.h>
00030 #include <qpainter.h>
00031 #include <q3ptrlist.h>
00032 #include <kcommondecoration.h>
00033 #include <kdecoration.h>
00034 
00035 // #include <ksimpleconfig.h>
00036 
00037 #include "Static.h"
00038 
00039 namespace RiscOS
00040 {
00041 
00042 /* XPM */
00043 static const char * const texture_xpm[] = {
00044 "64 12 3 1",
00045 "      c None",
00046 "a     c #000000",
00047 "b     c #FFFFFF",
00048 "   b           b         b     b   b b       b        a       b ",
00049 " b       aa   b  aaa aaa     b   a   b   aab     bb           a ",
00050 " b     b    a b    b   b             b       aa      b b   aa   ",
00051 " b b     b     a         a b   b b b  aa  ab             ab     ",
00052 "         b     b   b b       b                 b   b  ba        ",
00053 " aaa aaa         aa       b          b b b   b           b      ",
00054 "   b       b      bb a b     aa  b         a  a  aaa a     b    ",
00055 " b         b b b b     a b       b       b         b           b",
00056 "   b b       b              b  a a b  b  aa      b       baa    ",
00057 "       a     b    a  bb  aa    bb aa aaa  b     aa a            ",
00058 "   a a       aab       b  b   aa aab          a  b              ",
00059 " b        a        b   b aaa  a      b      bb     b   b     b b"};
00060 
00061 Static* Static::instance_ = NULL;
00062 
00063 Static::Static()
00064 {
00065    instance_ = this;
00066    _init();
00067 }
00068 
00069 Static::~Static()
00070 {
00071    instance_ = NULL;
00072 }
00073 
00074 const QPixmap& Static::titleTextLeft(bool active) const
00075 {
00076    return active ? aTitleTextLeft_ : iTitleTextLeft_;
00077 }
00078 
00079 const QPixmap& Static::titleTextRight(bool active) const
00080 {
00081    return active ? aTitleTextRight_ : iTitleTextRight_;
00082 }
00083 
00084 const QPixmap& Static::resizeMidLeft(bool active) const
00085 {
00086    return active ? aResizeMidLeft_ : iResizeMidLeft_;
00087 }
00088 
00089 const QPixmap& Static::resizeMidRight(bool active) const
00090 {
00091    return active ? aResizeMidRight_ : iResizeMidRight_;
00092 }
00093 
00094 const QPixmap& Static::titleTextMid(bool active) const
00095 {
00096    return active ? aTitleTextMid_ : iTitleTextMid_;
00097 }
00098 
00099 const QPixmap& Static::resizeMidMid(bool active) const
00100 {
00101    return active ? aResizeMid_ : iResizeMid_;
00102 }
00103 
00104 const QPixmap& Static::resize(bool active) const
00105 {
00106    return active ? aResize_ : iResize_;
00107 }
00108 
00109 int Static::animationStyle() const
00110 {
00111    return animationStyle_;
00112 }
00113 
00114 int Static::titleHeight() const
00115 {
00116    return titleHeight_;
00117 }
00118 
00119 int Static::resizeHeight() const
00120 {
00121    return resizeHeight_;
00122 }
00123 
00124 void Static::_drawBorder(QPixmap &pix, int w, int h)
00125 {
00126    // 0111111113
00127    // 1122222235
00128    // 12      46
00129    // 12      46
00130    // 12      46
00131    // 1344444476
00132    // 3566666667
00133 
00134    painter_.begin(&pix);
00135    painter_.translate(transx, transy);
00136 
00137    QColor c0 = down_ ? palette_[7] : palette_[0];
00138    QColor c1 = down_ ? palette_[6] : palette_[1];
00139    QColor c2 = down_ ? palette_[5] : palette_[2];
00140    QColor c3 = down_ ? palette_[4] : palette_[3];
00141    QColor c4 = down_ ? palette_[3] : palette_[4];
00142    QColor c5 = down_ ? palette_[2] : palette_[5];
00143    QColor c6 = down_ ? palette_[2] : palette_[6];
00144    QColor c7 = down_ ? palette_[1] : palette_[7];
00145 
00146    painter_.setPen(c0);
00147    painter_.drawPoint(0, 0);
00148 
00149    painter_.setPen(c1);
00150    painter_.drawPoint(1, 1);
00151    painter_.drawLine(1, 0, w - 1, 0);
00152    painter_.drawLine(0, 1, 0, h - 1);
00153 
00154    painter_.setPen(c2);
00155    painter_.drawLine(2, 1, w - 2, 1);
00156    painter_.drawLine(1, 2, 1, h - 2);
00157 
00158    painter_.setPen(c3);
00159    painter_.drawPoint(0, h);
00160    painter_.drawPoint(1, h - 1);
00161    painter_.drawPoint(w, 0);
00162    painter_.drawPoint(w - 1, 1);
00163    painter_.fillRect(2, 2, w - 2, h - 2, c3);
00164 
00165    painter_.setPen(c4);
00166    painter_.drawLine(2, h - 1, w - 2, h - 1);
00167    painter_.drawLine(w - 1, 2, w - 1, h - 2);
00168 
00169    painter_.setPen(c5);
00170    painter_.drawPoint(w, 1);
00171    painter_.drawPoint(1, h);
00172 
00173    painter_.setPen(c6);
00174    painter_.drawLine(w, 2, w, h - 1);
00175    painter_.drawLine(2, h, w - 1, h);
00176 
00177    painter_.setPen(c7);
00178    painter_.drawPoint(w - 1, h - 1);
00179    painter_.drawPoint(w, h);
00180 
00181    painter_.end();
00182 
00183    painter_.resetXForm();
00184 }
00185 
00186 void setPalette(Palette &pal, QColor c)
00187 {
00188    pal[3] = c.rgb();
00189 
00190    int h, s, v;
00191    c.hsv(&h, &s, &v);
00192 
00193    if (v < 72)
00194       c.setHsv(h, s, 72);
00195 
00196    pal[0] = c.light(200).rgb();
00197    pal[1] = c.light(166).rgb();
00198    pal[2] = c.light(125).rgb();
00199    pal[4] = c.dark(133).rgb();
00200    pal[5] = c.dark(166).rgb();
00201    pal[6] = c.dark(200).rgb();
00202    pal[7] = c.dark(300).rgb();
00203 }
00204 
00205 void Static::_init()
00206 {
00207    hicolour_ = QPixmap::defaultDepth() > 8;
00208    animationStyle_ = 0;
00209    updatePixmaps();
00210 }
00211 
00212 void Static::reset()
00213 {
00214    updatePixmaps();
00215 //   Workspace::self()->slotResetAllClientsDelayed();
00216 }
00217 
00218 void Static::updatePixmaps()
00219 {
00220    _initSizes();
00221 
00222    _resizeAllPixmaps();
00223 
00224    _blankAllPixmaps();
00225 
00226    if (hicolour_)
00227    {
00228       _initPalettes();
00229       _initTextures();
00230    }
00231 
00232    _drawTitleTextAreaSides();
00233 
00234    _drawResizeCentralAreaSides();
00235 
00236    _drawTitleTextAreaBackground();
00237 
00238    _drawResizeCentralAreaBackground();
00239 
00240    _drawResizeHandles();
00241 
00242    _drawButtonBackgrounds();
00243 }
00244 
00245 void Static::_createTexture(QPixmap &px, int t, bool active)
00246 {
00247    const QImage texture(QPixmap((const char **)texture_xpm).convertToImage());
00248    const QRgb w(qRgb(255, 255, 255));
00249    const QRgb b(qRgb(0, 0, 0));
00250 
00251    QColor c(KDecoration::options()->color(KDecoration::ColorType(t), active));
00252 
00253    QRgb mid    (c.rgb());
00254    QRgb light  (c.light(110).rgb());
00255    QRgb dark   (c.dark(110).rgb());
00256 
00257    QRgb* data(reinterpret_cast<QRgb *>(texture.bits()));
00258 
00259    for (int x = 0; x < 64*12; x++)
00260       if (data[x] == w)
00261          data[x] = light;
00262       else if (data[x] == b)
00263          data[x] = dark;
00264       else
00265          data[x] = mid;
00266 
00267    px.convertFromImage(texture);
00268 }
00269 
00270 const QPixmap& Static::buttonBase(bool active, bool down) const
00271 {
00272    if (active)
00273       return down ? aButtonDown_ : aButtonUp_;
00274    else
00275       return down ? iButtonDown_ : iButtonUp_;
00276 }
00277 
00278 void Static::_initSizes()
00279 {
00280    QFont f(KDecoration::options()->font(true)); // XXX false doesn't work right at the moment
00281 
00282    QFontMetrics fm(f);
00283 
00284    int h = fm.height();
00285 
00286    titleHeight_ = h + 6;
00287 
00288    if (titleHeight_ < 20)
00289       titleHeight_ = 20;
00290 
00291    buttonSize_ = titleHeight_ - 1;
00292 
00293    resizeHeight_ = 10;
00294 }
00295 
00296 void Static::_resizeAllPixmaps()
00297 {
00298    aResize_        .resize(30, resizeHeight_);
00299    iResize_        .resize(30, resizeHeight_);
00300    aTitleTextLeft_ .resize( 3, titleHeight_);
00301    aTitleTextRight_.resize( 3, titleHeight_);
00302    iTitleTextLeft_ .resize( 3, titleHeight_);
00303    iTitleTextRight_.resize( 3, titleHeight_);
00304    aTitleTextMid_  .resize(64, titleHeight_);
00305    iTitleTextMid_  .resize(64, titleHeight_);
00306    aResizeMidLeft_ .resize( 3, resizeHeight_);
00307    aResizeMidRight_.resize( 3, resizeHeight_);
00308    iResizeMidLeft_ .resize( 3, resizeHeight_);
00309    iResizeMidRight_.resize( 3, resizeHeight_);
00310    aResizeMid_     .resize(64, resizeHeight_);
00311    iResizeMid_     .resize(64, resizeHeight_);
00312 
00313    aButtonUp_      .resize(buttonSize_, buttonSize_);
00314    iButtonUp_      .resize(buttonSize_, buttonSize_);
00315    aButtonDown_    .resize(buttonSize_, buttonSize_);
00316    iButtonDown_    .resize(buttonSize_, buttonSize_);
00317 }
00318 
00319 void Static::_blankAllPixmaps()
00320 {
00321    aResize_        .fill(Qt::black);
00322    iResize_        .fill(Qt::black);
00323    aTitleTextLeft_ .fill(Qt::black);
00324    aTitleTextRight_.fill(Qt::black);
00325    iTitleTextLeft_ .fill(Qt::black);
00326    iTitleTextRight_.fill(Qt::black);
00327    aTitleTextMid_  .fill(Qt::black);
00328    iTitleTextMid_  .fill(Qt::black);
00329    aResizeMidLeft_ .fill(Qt::black);
00330    aResizeMidRight_.fill(Qt::black);
00331    iResizeMidLeft_ .fill(Qt::black);
00332    iResizeMidRight_.fill(Qt::black);
00333    aResizeMid_     .fill(Qt::black);
00334    iResizeMid_     .fill(Qt::black);
00335    aButtonUp_      .fill(Qt::black);
00336    iButtonUp_      .fill(Qt::black);
00337    aButtonDown_    .fill(Qt::black);
00338    iButtonDown_    .fill(Qt::black);
00339 }
00340 
00341 void Static::_initPalettes()
00342 {
00343    const KDecorationOptions* options = KDecoration::options();
00344    setPalette(aButPal_, options->color(KDecoration::ColorButtonBg, true));
00345    setPalette(iButPal_, options->color(KDecoration::ColorButtonBg, false));
00346 
00347    setPalette(aTitlePal_,  options->color(KDecoration::ColorTitleBar, true));
00348    setPalette(iTitlePal_,  options->color(KDecoration::ColorTitleBar, false));
00349 
00350    setPalette(aResizePal_, options->color(KDecoration::ColorTitleBar, true));
00351    setPalette(iResizePal_, options->color(KDecoration::ColorTitleBar, false));
00352 }
00353 
00354 void Static::_initTextures()
00355 {
00356    _createTexture(aTexture_,  KDecoration::ColorTitleBar, true);
00357    _createTexture(iTexture_,  KDecoration::ColorTitleBar, false);
00358    _createTexture(abTexture_, KDecoration::ColorButtonBg, true);
00359    _createTexture(ibTexture_, KDecoration::ColorButtonBg, false);
00360 }
00361 
00362 void Static::_drawTitleTextAreaSides()
00363 {
00364    QPixmap temp(4, titleHeight_);
00365    temp.fill(Qt::black);
00366 
00367    transx = transy = 0.0;
00368 
00369    palette_ = aTitlePal_;
00370    down_ = false;
00371 
00372    _drawBorder(temp, 4, titleHeight_ - 2);
00373 
00374    painter_.begin(&aTitleTextLeft_);
00375    painter_.drawPixmap(1, 1, temp, 0, 1);
00376    painter_.end();
00377 
00378    painter_.begin(&aTitleTextRight_);
00379    painter_.drawPixmap(0, 1, temp, 2, 1);
00380    painter_.end();
00381 
00382    palette_ = iTitlePal_;
00383    _drawBorder(temp, 4, titleHeight_ - 2);
00384 
00385    painter_.begin(&iTitleTextLeft_);
00386    painter_.drawPixmap(1, 1, temp, 0, 1);
00387    painter_.end();
00388 
00389    painter_.begin(&iTitleTextRight_);
00390    painter_.drawPixmap(0, 1, temp, 2, 1);
00391    painter_.end();
00392 }
00393 
00394 void Static::_drawResizeCentralAreaSides()
00395 {
00396    QPixmap temp(4, resizeHeight_);
00397    temp.fill(Qt::black);
00398 
00399    transy = 1.0;
00400 
00401    palette_ = aResizePal_;
00402 
00403    _drawBorder(temp, 4, resizeHeight_ - 3);
00404 
00405    painter_.begin(&aResizeMidLeft_);
00406    painter_.drawPixmap(0, 1, temp, 0, 1);
00407    painter_.end();
00408 
00409    painter_.begin(&aResizeMidRight_);
00410    painter_.drawPixmap(0, 1, temp, 2, 1);
00411    painter_.end();
00412 
00413    palette_ = iResizePal_;
00414    _drawBorder(temp, 4, resizeHeight_ - 3);
00415 
00416    painter_.begin(&iResizeMidLeft_);
00417    painter_.drawPixmap(0, 1, temp, 0, 1);
00418    painter_.end();
00419 
00420    painter_.begin(&iResizeMidRight_);
00421    painter_.drawPixmap(0, 1, temp, 2, 1);
00422    painter_.end();
00423 }
00424 
00425 void Static::_drawTitleTextAreaBackground()
00426 {
00427    QPixmap temp(70, titleHeight_);
00428    temp.fill(Qt::black);
00429 
00430    transx = transy = 0.0;
00431 
00432    palette_ = aTitlePal_;
00433    _drawBorder(temp, 70, titleHeight_ - 3);
00434 
00435    painter_.begin(&aTitleTextMid_);
00436    painter_.drawPixmap(0, 1, temp, 2, 0);
00437    if (hicolour_)
00438       painter_.drawTiledPixmap(0, 4, 64, titleHeight_ - 8, aTexture_);
00439    painter_.end();
00440 
00441    palette_ = iTitlePal_;
00442    _drawBorder(temp, 70, titleHeight_ - 3);
00443 
00444    painter_.begin(&iTitleTextMid_);
00445    painter_.drawPixmap(0, 1, temp, 2, 0);
00446    if (hicolour_)
00447       painter_.drawTiledPixmap(0, 4, 64, titleHeight_ - 8, iTexture_);
00448    painter_.end();
00449 }
00450 
00451 void Static::_drawResizeCentralAreaBackground()
00452 {
00453    QPixmap temp(70, titleHeight_);
00454    temp.fill(Qt::black);
00455 
00456    transy = 1.0;
00457 
00458    palette_ = aResizePal_;
00459    _drawBorder(temp, 70, resizeHeight_ - 3);
00460 
00461    painter_.begin(&aResizeMid_);
00462    painter_.drawPixmap(0, 0, temp, 2, 0);
00463    if (hicolour_)
00464       painter_.drawTiledPixmap(0, 4, 64, resizeHeight_ - 8, aTexture_);
00465    painter_.end();
00466 
00467    palette_ = iResizePal_;
00468    _drawBorder(temp, 70, 7);
00469 
00470    painter_.begin(&iResizeMid_);
00471    painter_.drawPixmap(0, 0, temp, 2, 0);
00472    if (hicolour_)
00473       painter_.drawTiledPixmap(0, 4, 64, resizeHeight_ - 8, iTexture_);
00474    painter_.end();
00475 }
00476 
00477 void Static::_drawResizeHandles()
00478 {
00479    transx = transy = 1.0;
00480 
00481    down_ = false;
00482 
00483    palette_ = aResizePal_;
00484    _drawBorder(aResize_, 28, resizeHeight_ - 3);
00485 
00486    if (hicolour_)
00487    {
00488       painter_.begin(&aResize_);
00489       painter_.drawTiledPixmap(4, 4, 20, resizeHeight_ - 8, aTexture_);
00490       painter_.end();
00491    }
00492 
00493    palette_ = iResizePal_;
00494    _drawBorder(iResize_, 28, resizeHeight_ - 3);
00495 
00496    if (hicolour_)
00497    {
00498       painter_.begin(&iResize_);
00499       painter_.drawTiledPixmap(4, 4, 20, resizeHeight_ - 8, iTexture_);
00500       painter_.end();
00501    }
00502 }
00503 
00504 void Static::_drawButtonBackgrounds()
00505 {
00506    buttonSize_ -= 2;
00507 
00508    down_ = false;
00509    transx = 0.0;
00510    transy = 1.0;
00511    palette_ = aButPal_;
00512    _drawBorder(aButtonUp_, buttonSize_, buttonSize_);
00513    down_ = true;
00514    _drawBorder(aButtonDown_, buttonSize_, buttonSize_);
00515 
00516    palette_ = iButPal_;
00517    _drawBorder(iButtonDown_, buttonSize_, buttonSize_);
00518    down_ = false;
00519    _drawBorder(iButtonUp_, buttonSize_, buttonSize_);
00520 
00521    painter_.begin(&aButtonUp_);
00522 
00523    if (hicolour_)
00524       painter_.drawTiledPixmap(2, 4, buttonSize_ - 4, buttonSize_ - 5,
00525                                abTexture_);
00526 
00527    painter_.end();
00528 
00529    painter_.begin(&iButtonUp_);
00530    if (hicolour_)
00531       painter_.drawTiledPixmap(2, 4, buttonSize_ - 4, buttonSize_ - 5,
00532                                ibTexture_);
00533 
00534    painter_.end();
00535 }
00536 
00537 } // End namespace
00538 
00539 // vim:ts=2:sw=2:tw=78
00540