Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

phasestyle.cpp

Go to the documentation of this file.
00001 
00002 // phasestyle.h
00003 // -------------------
00004 // A style for KDE
00005 // -------------------
00006 // Copyright (c) 2004 David Johnson <david@usermode.org>
00007 //
00008 // Permission is hereby granted, free of charge, to any person obtaining a copy
00009 // of this software and associated documentation files (the "Software"), to
00010 // deal in the Software without restriction, including without limitation the
00011 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
00012 // sell copies of the Software, and to permit persons to whom the Software is
00013 // furnished to do so, subject to the following conditions:
00014 //
00015 // The above copyright notice and this permission notice shall be included in
00016 // all copies or substantial portions of the Software.
00017 //
00018 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00023 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00024 // IN THE SOFTWARE.
00026 
00027 #include "phasestyle.h"
00028 
00029 #include "bitmaps.h"
00030 
00031 #define INCLUDE_MENUITEM_DEF
00032 #include <qpopupmenu.h>
00033 #include <qpushbutton.h>
00034 #include <qtoolbutton.h>
00035 #include <qpainter.h>
00036 #include <qbrush.h>
00037 #include <qiconset.h>
00038 #include <qtabbar.h>
00039 #include <qscrollbar.h>
00040 
00041 
00042 /* Spacing and sizeHint */
00043 static unsigned contrast = 110;
00044 
00045 static const int ITEMFRAME       = 1; // menu stuff
00046 static const int ITEMHMARGIN     = 3;
00047 static const int ITEMVMARGIN     = 0;
00048 
00049 static const int ARROWMARGIN     = 6;
00050 static const int RIGHTBORDER     = 10;
00051 static const int MINICONSIZE     = 12;
00052 static const int CHECKSIZE       = 9;
00053 static const int SCROLLBAR_EXTENT = 12;
00054 
00055 
00056 /*
00057  * Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org>
00058  * LGPLv2 from kdelibs/kdefx/kdrawutil.cpp
00059  */
00060 void kColorBitmaps(QPainter *p, const QColorGroup &g, int x, int y,
00061                    QBitmap *lightColor, QBitmap *midColor,
00062                    QBitmap *midlightColor, QBitmap *darkColor,
00063                    QBitmap *blackColor, QBitmap *whiteColor)
00064 {
00065     QBitmap *bitmaps[]={lightColor, midColor, midlightColor, darkColor,
00066         blackColor, whiteColor};
00067 
00068     QColor colors[]={g.light(), g.mid(), g.midlight(), g.dark(),
00069         Qt::black, Qt::white};
00070 
00071     int i;
00072     for(i=0; i < 6; ++i){
00073         if(bitmaps[i]){
00074             if(!bitmaps[i]->mask())
00075                 bitmaps[i]->setMask(*bitmaps[i]);
00076             p->setPen(colors[i]);
00077             p->drawPixmap(x, y, *bitmaps[i]);
00078         }
00079     }
00080 }
00081 
00082 
00083 /*
00084  * drawMenuBarItem is not virtual
00085  * this way we define our draw handler
00086  */
00087 typedef void (QStyle::*QDrawMenuBarItemImpl) (QPainter *, int, int, int, int, QMenuItem *,
00088                           QColorGroup &, bool, bool);
00089 
00090 extern QDrawMenuBarItemImpl qt_set_draw_menu_bar_impl(QDrawMenuBarItemImpl impl);
00091 
00092 
00093 PhaseStyle::PhaseStyle()
00094     : QWindowsStyle()
00095 {
00096     setName( "PhaseStyle" );
00097 
00098     /* small default sizes */
00099     setButtonDefaultIndicatorWidth(1);
00100     setScrollBarExtent(SCROLLBAR_EXTENT, SCROLLBAR_EXTENT);
00101     setSliderThickness(12);
00102     setButtonMargin( 1 );
00103 
00104     // create bitmaps
00105     uarrow = QBitmap(6, 6, uarrow_bits, true);
00106     uarrow.setMask(uarrow);
00107     darrow = QBitmap(6, 6, darrow_bits, true);
00108     darrow.setMask(darrow);
00109     larrow = QBitmap(6, 6, larrow_bits, true);
00110     larrow.setMask(larrow);
00111     rarrow = QBitmap(6, 6, rarrow_bits, true);
00112     rarrow.setMask(rarrow);
00113     bplus = QBitmap(6, 6, bplus_bits, true);
00114     bplus.setMask(bplus);
00115     bminus = QBitmap(6, 6, bminus_bits, true);
00116     bminus.setMask(bminus);
00117     bcheck = QBitmap(9, 9, bcheck_bits, true);
00118     bcheck.setMask(bcheck);
00119     dexpand = QBitmap(9, 9, dexpand_bits, true);
00120     dexpand.setMask(dexpand);
00121     rexpand = QBitmap(9, 9, rexpand_bits, true);
00122     rexpand.setMask(rexpand);
00123     doodad_mid = QBitmap(4, 4, doodad_mid_bits, true);
00124     doodad_light = QBitmap(4, 4, doodad_light_bits, true);
00125 }
00126 
00127 PhaseStyle::~PhaseStyle() {
00128     /* deleted by Qt */
00129 }
00130 
00131 void PhaseStyle::drawCheckMark ( QPainter * p, int x, int y, int w,
00132                                  int h, const QColorGroup & g,
00133                                  bool , bool) {
00134     p->setPen(g.text());
00135     p->drawPixmap(x+w/2-4, y+h/2-4, bcheck);
00136 }
00137 
00138 void PhaseStyle::drawArrow(QPainter *painter, Qt::ArrowType type, bool down,
00139                            int x, int y, int w, int h, const QColorGroup &group,
00140                            bool enabled , const QBrush * ) {
00141     switch( type ) {
00142     case UpArrow:
00143         if (enabled)
00144             painter->setPen(down ? group.midlight() : group.dark());
00145         else painter->setPen(group.mid());
00146         painter->drawPixmap(x+w/2-3, y+h/2-3, uarrow);
00147         break;
00148     case DownArrow:
00149         if (enabled) painter->setPen(down ? group.midlight() : group.dark());
00150         else painter->setPen(group.mid());
00151         painter->drawPixmap(x+w/2-3, y+h/2-3, darrow);
00152         break;
00153     case LeftArrow:
00154         if (enabled) painter->setPen(down ? group.midlight() : group.dark());
00155         else painter->setPen(group.mid());
00156         painter->drawPixmap(x+w/2-3, y+h/2-3, larrow);
00157         break;
00158     case RightArrow:
00159         if (enabled) painter->setPen(down ? group.midlight() : group.dark());
00160         else painter->setPen(group.mid());
00161         painter->drawPixmap(x+w/2-3, y+h/2-3, rarrow);
00162         break;
00163     }
00164 }
00165 
00166 void PhaseStyle::drawPushButton(QPushButton *btn, QPainter *painter) {
00167     QRect r = btn->rect();
00168     int x = r.x();
00169     int y = r.y();
00170     int h = r.height();
00171     int w = r.width();
00172     bool depress = btn->isOn() || btn->isDown();
00173     QColorGroup group = btn->colorGroup();
00174     QBrush brush(group.button() );
00175 //    int bd = pixelMetric(PM_ButtonDefaultIndicator, widget) + 1;
00176     static int bd = 2;
00177 
00178     if (btn->isDefault() && !depress) {
00179         drawPanel(painter, x, y, w, h, group,
00180                   &group.brush(QColorGroup::Mid), true);
00181         drawBevelButton(painter, x+bd, y+bd, w-bd*2, h-bd*2, group,
00182                         false, &brush  );
00183     } else {
00184         drawButton(painter, x, y, w, h, group, depress,
00185                    &brush );
00186     }
00187 
00188     if (btn->hasFocus() ) { // draw focus
00189         QColor col;
00190         drawFocusRect(painter, r, group,
00191                       &col, false );
00192     }
00193 }
00194 
00195 
00196 void PhaseStyle::drawPanel(QPainter* painter, int x, int y, int w, int h,
00197                            const QColorGroup& group, bool sunken,
00198                            int , const QBrush* fill) {
00199     int x2 = x + w - 1;
00200     int y2 = y + h - 1;
00201     painter->save();
00202 
00203     if (sunken) {
00204         painter->setPen(group.dark());
00205         painter->drawRect(x+1, y+1, w-2, h-2);
00206         painter->setPen(group.midlight());
00207         painter->drawLine(x+1, y2, x2, y2);
00208         painter->drawLine(x2, y+1, x2, y2-1);
00209         painter->setPen(group.mid());
00210         painter->drawLine(x, y, x, y2-1);
00211         painter->drawLine(x+1, y, x2-1, y);
00212         painter->setPen(group.background());
00213         painter->drawPoint(x, y2);
00214         painter->drawPoint(x2, y);
00215     } else {
00216         painter->setPen(group.dark());
00217         painter->drawRect(x, y, w, h);
00218         painter->setPen(group.midlight());
00219         painter->drawLine(x+1, y+1, x2-2, y+1);
00220         painter->drawLine(x+1, y+2, x+1, y2-2);
00221         painter->setPen(group.mid());
00222         painter->drawLine(x+2, y2-1, x2-1, y2-1);
00223         painter->drawLine(x2-1, y+2, x2-1, y2-2);
00224         painter->setPen(group.background());
00225         painter->drawPoint(x+1, y2-1);
00226         painter->drawPoint(x2-1, y+1);
00227     }
00228 
00229     if (fill) {
00230         painter->fillRect(x+2, y+2, w-4, h-4, *fill );
00231     }
00232     painter->restore();
00233 }
00234 
00235 
00236 
00237 void  PhaseStyle::drawButton(QPainter *p, int x, int y, int w, int h,
00238                              const QColorGroup &group, bool sunken ,
00239                              const QBrush *fill  ) {
00240     int x2 = x + w - 1;
00241     int y2 = y + h - 1;
00242 
00243     p->setPen(group.midlight());
00244     p->drawLine(x+1, y2, x2, y2);
00245     p->drawLine(x2, y+1, x2, y2-1);
00246 
00247     p->setPen(group.mid());
00248     p->drawLine(x, y,  x2-1, y);
00249     p->drawLine(x, y+1, x, y2-1);
00250 
00251     p->setPen(group.button());
00252     p->drawPoint(x, y2);
00253     p->drawPoint(x2, y);
00254 
00255     drawBevelButton(p, x+1, y+1, w-2, h-2, group, sunken,
00256                     fill);
00257 }
00258 
00259 void PhaseStyle::drawButtonMask( QPainter* p, int x, int y,
00260                                  int w, int h ) {
00261     QRect rect(x, y, w, h );
00262     p->fillRect(rect, Qt::color1);
00263     p->setPen(Qt::color0);
00264 }
00265 
00266 
00267 void PhaseStyle::drawBevelButton(QPainter* p, int x, int y,
00268                                  int w, int h, const QColorGroup& group,
00269                                  bool sunken, const QBrush* fill ) {
00270     int x2 = x + w - 1;
00271     int y2 = y + h - 1;
00272     p->save();
00273 
00274     p->setPen(group.dark());
00275     p->drawRect(x, y, w, h);
00276 
00277     p->setPen(sunken ? group.mid() : group.midlight());
00278     p->drawLine(x+1, y+1, x2-2, y+1);
00279     p->drawLine(x+1, y+2, x+1, y2-2);
00280 
00281     p->setPen(sunken ? group.midlight() : group.mid());
00282     p->drawLine(x+2, y2-1, x2-1, y2-1);
00283     p->drawLine(x2-1, y+2, x2-1, y2-2);
00284 
00285     p->setPen(group.button());
00286     p->drawPoint(x+1, y2-1);
00287     p->drawPoint(x2-1, y+1);
00288 
00289     QBrush b = fill ? *fill : group.brush( QColorGroup::Button );
00290     if (sunken) {
00291         // sunken bevels don't get gradients
00292         p->fillRect(x+2, y+2, w-4, h-4, b);
00293     } else
00294         drawPhaseGradient(p, QRect(x+2, y+2, w-4, h-4), b.color() );
00295 
00296     p->restore();
00297 }
00298 
00299 void PhaseStyle::drawPhaseGradient(QPainter* painter,
00300                                    const QRect& rect,
00301                                    const QColor& color )const {
00302     painter->fillRect(rect, color);
00303 }
00304 
00305 void PhaseStyle::polish( QWidget* widget ) {
00306     QWindowsStyle::polish(widget );
00307 
00308 #if 0
00309     if (widget->inherits("QMenuBar")    ||
00310         widget->inherits("QPopupMenu" ) ||
00311         widget->inherits("QToolButton") ||
00312         widget->inherits("QHeader" )   ) {
00313         widget->setBackgroundMode(QWidget::NoBackground);
00314     }
00315 //    else if (widget->inherits("QFrame") ) {
00316 //        widget->installEventFilter(this);
00317 //    }
00318 #endif
00319 }
00320 
00321 void PhaseStyle::unPolish( QWidget *w )
00322 {
00323     QWindowsStyle::unPolish( w );
00324 }
00325 
00326 void PhaseStyle::polish( QPalette &pal ) {
00327     QWindowsStyle::polish( pal );
00328     // lighten up a bit, so the look is not so "crisp"
00329     if (QPixmap::defaultDepth() > 8) { // but not on low color displays
00330         pal.setColor(QPalette::Disabled, QColorGroup::Dark,
00331                      pal.color(QPalette::Disabled, QColorGroup::Dark).light(contrast));
00332         pal.setColor(QPalette::Active, QColorGroup::Dark,
00333                      pal.color(QPalette::Active, QColorGroup::Dark).light(contrast));
00334         pal.setColor(QPalette::Inactive, QColorGroup::Dark,
00335                      pal.color(QPalette::Inactive, QColorGroup::Dark).light(contrast));
00336     }
00337 }
00338 
00339 void PhaseStyle::polish( QApplication* app ) {
00340     QWindowsStyle::polish( app );
00341 
00342     qt_set_draw_menu_bar_impl((QDrawMenuBarItemImpl)&PhaseStyle::drawMenuBarItem);
00343 }
00344 
00345 void PhaseStyle::unPolish( QApplication* app ) {
00346     QWindowsStyle::unPolish(app);
00347     qt_set_draw_menu_bar_impl ( 0 );
00348 }
00349 
00350 void PhaseStyle::drawPushButtonLabel (QPushButton *button, QPainter *painter) {
00351     bool active = button->isOn() || button->isDown();
00352     QRect r = pushButtonContentsRect( button );
00353     QColorGroup group = button->colorGroup();
00354     int x, y, w, h;
00355     r.rect( &x, &y, &w, &h );
00356     bool sunken = false;
00357     QIconSet::Mode mode;
00358     QPixmap pixmap;
00359 
00360     if (active)  {// shift contents
00361         x++; y++;
00362         sunken = true;
00363     }
00364 
00365 
00366     if (button->isMenuButton()) { // draw the indicator
00367         //dx = pixelMetric(PM_MenuButtonIndicator, widget);
00368         int dx = menuButtonIndicatorWidth( button->height() );
00369         drawArrow(painter, Qt::DownArrow, active,
00370                   x+w-dx, y+2, dx-4, h-4, group,button->isEnabled() );
00371         w -= dx;
00372     }
00373 
00374     if (button->iconSet() && !button->iconSet()->isNull()) { // draw icon
00375         if (button->isEnabled()) {
00376             if (button->hasFocus()) {
00377                 mode = QIconSet::Active;
00378             } else {
00379                 mode = QIconSet::Normal;
00380             }
00381         } else {
00382             mode = QIconSet::Disabled;
00383         }
00384 
00385 #if 0
00386         if (button->isToggleButton() && button->isOn()) {
00387             state = true;
00388         } else {
00389             state = false;
00390         }
00391 #endif
00392 
00393         if ( mode == QIconSet::Disabled )
00394             pixmap = button->iconSet()->pixmap( QIconSet::Automatic, mode );
00395         else
00396             pixmap = button->iconSet()->pixmap();
00397         if (button->text().isEmpty() && !button->pixmap()) {
00398             painter->drawPixmap(x+w/2 - pixmap.width()/2,
00399                                 y+h/2 - pixmap.height()/2, pixmap);
00400         } else {
00401             painter->drawPixmap(x+4, y+h/2 - pixmap.height()/2, pixmap);
00402         }
00403         x += pixmap.width() + 4;
00404         w -= pixmap.width() + 4;
00405     }
00406 
00407     if (active || button->isDefault()) { // default button
00408         for(int n=0; n<2; n++) {
00409             drawItem(painter, x+n, y, w, h,
00410                      AlignCenter | ShowPrefix,
00411                      button->colorGroup(),
00412                      button->isEnabled(),
00413                      button->pixmap(),
00414                      button->text(), -1,
00415                      (button->isEnabled()) ?
00416                      &button->colorGroup().buttonText() :
00417                      &button->colorGroup().mid());
00418         }
00419     } else { // normal button
00420         drawItem(painter, x, y, w, h,
00421                  AlignCenter | ShowPrefix,
00422                  button->colorGroup(),
00423                  button->isEnabled(),
00424                  button->pixmap(),
00425                  button->text(), -1,
00426                  (button->isEnabled()) ?
00427                  &button->colorGroup().buttonText() :
00428                  &button->colorGroup().mid());
00429     }
00430 }
00431 
00432 
00433 void PhaseStyle::drawFocusRect(QPainter *painter, const QRect &rect,
00434                                const QColorGroup &group,
00435                                const QColor *, bool atBorder) {
00436 
00437 
00438     QPen old = painter->pen();
00439     painter->setPen(group.highlight().dark(contrast));
00440     painter->setBrush(NoBrush);
00441 
00442     if ( atBorder )
00443         painter->drawRect(QRect(rect.x()+1,     rect.y()+1,
00444                                 rect.width()-2, rect.height()-2 ));
00445     else
00446         painter->drawRect(rect);
00447 
00448 
00449     painter->setPen(old);
00450 
00451 }
00452 
00453 void PhaseStyle::drawSeperator( QPainter* painter, int x, int y, int w,
00454                                 int h, const QColorGroup& group,  bool,
00455                                 int , int  ) {
00456     qWarning( "Seperator" );
00457     QRect rect(x, y, w, h);
00458     int x2 = rect.right();
00459     int y2 = rect.bottom();
00460 
00461     painter->setPen(group.dark());
00462     if (w < h)
00463         painter->drawLine(w/2, y, w/2, y2);
00464     else
00465         painter->drawLine(x, h/2, x2, h/2);
00466 }
00467 
00468 void PhaseStyle::drawMenuBarItem(QPainter* p, int x, int y, int w, int h,
00469                          QMenuItem *mi, QColorGroup& g, bool enabled,
00470                          bool act ) {
00471     return QWindowsStyle::drawMenuBarItem(p, x, y, w, h, mi, g, enabled, act);
00472 }
00473 
00474 
00475 void PhaseStyle::drawIndicator(QPainter* painter, int x, int y, int w, int h,
00476                                const QColorGroup &group, int state, bool,
00477                                bool enabled  ) {
00478     drawPanel(painter, x, y, w, h, group, true, 1, enabled ?
00479                    &group.brush(QColorGroup::Base) :
00480                    &group.brush(QColorGroup::Background));
00481 
00482     if (QButton::On == state ) {
00483         painter->setPen(group.dark());
00484         painter->drawRect(x+3, y+3, w-6, h-6);
00485         painter->fillRect(x+4, y+4, w-8, h-8,
00486                           group.brush(QColorGroup::Highlight));
00487     }
00488 }
00489 
00490 
00491 void PhaseStyle::drawExclusiveIndicator(QPainter* painter,  int x, int y, int w, int h,
00492                                         const QColorGroup &group, bool on,
00493                                         bool /*down*/, bool enabled) {
00494 
00495     QRect r(x, y, w, h );
00496 
00497 
00498     /*
00499      * As Polygon and Polyline are broken in Qt2 lets use
00500      * something not that spectacilur -> ellipse
00501      */
00502     painter->save();
00503     painter->fillRect(x, y, w, h, group.background());
00504 
00505 
00506     painter->setBrush(enabled
00507                       ? group.brush(QColorGroup::Base)
00508                       : group.brush(QColorGroup::Background));
00509     painter->setPen(group.dark());
00510 
00511     if (0 == w % 2) --w;
00512     if (0 == h % 2) --h;
00513     painter->drawEllipse(x, y, w, h );
00514 
00515     if(on) {
00516         painter->setBrush(group.brush(QColorGroup::Highlight));
00517         painter->drawEllipse(x+3,y+3,w-6,h-6);
00518     }
00519 
00520     painter->restore();
00521 }
00522 
00523 
00524 /*
00525  * Does not get called in QWS as it seems
00526  */
00527 void PhaseStyle::drawExclusiveIndicatorMask(QPainter *painter, int x, int y, int w,
00528                                             int h, bool /*on*/ ) {
00529     return;
00530 
00531 
00532 
00533     if (0 != w%2) --w;
00534     if (0 != h%2) --h;
00535 
00536     QRect r(x, y, w, h );
00537     int x2 = r.right();
00538     int y2 = r.bottom();
00539     int cx = (x + x2) / 2;
00540     int cy = (y + y2) / 2;
00541     QPointArray parray;
00542 
00543 
00544     painter->setBrush(Qt::color1);
00545     painter->setPen(Qt::color1);
00546     parray.putPoints(0, 8,
00547                      x,cy+1, x,cy,    cx,y,    cx+1,y,
00548                      x2,cy,  x2,cy+1, cx+1,y2, cx,y2);
00549     painter->drawPolygon(parray, 0, 8);
00550 }
00551 
00552 int PhaseStyle::defaultFrameWidth()const {
00553     return 1;
00554 }
00555 
00556 int PhaseStyle::popupMenuItemHeight ( bool ,
00557                                       QMenuItem * mi,
00558                                       const QFontMetrics & fm ) {
00559     int h = 0;
00560     if (mi->custom() ) {
00561         h = mi->custom()->sizeHint().height();
00562         if (!mi->custom()->fullSpan() )
00563             h += ITEMVMARGIN*2 + ITEMFRAME*2;
00564     }else if (mi->isSeparator() ) {
00565         h = 1;
00566     }else {
00567         if ( mi->pixmap() ) {
00568             h = QMAX(h, mi->pixmap()->height() + ITEMFRAME*2);
00569         }else {
00570             h = QMAX(h, MINICONSIZE+ITEMFRAME*2 );
00571             h = QMAX(h, fm.height()
00572                      + ITEMVMARGIN*2 + ITEMFRAME*2 );
00573         }
00574         if ( mi->iconSet() )
00575             h = QMAX(h, mi->iconSet()->pixmap().height()
00576                      + ITEMFRAME*2 );
00577     }
00578 
00579 
00580     return h;
00581 }
00582 
00583 int PhaseStyle::extraPopupMenuItemWidth(bool checkable, int maxpmw,
00584                                         QMenuItem* mi, const QFontMetrics& ) {
00585     int w = 0;
00586     if (mi->isSeparator() )
00587         return 3;
00588 
00589     else if ( mi->pixmap() )
00590         w = mi->pixmap()->width();
00591 
00592     if (!mi->text().isNull() &&
00593         mi->text().find('\t' ) >= 0 )
00594         w += 12;
00595     else if ( mi->popup() )
00596         w += 2*ARROWMARGIN;
00597 
00598     if ( maxpmw  )
00599         w += maxpmw +4;
00600 
00601 
00602     if (  maxpmw > 0 || checkable )
00603         w += ITEMHMARGIN*2+8;
00604 
00605     w += RIGHTBORDER;
00606     return w;
00607 }
00608 
00609 QSize PhaseStyle::indicatorSize()const {
00610     return QSize( 11, 11 );
00611 }
00612 
00613 QSize PhaseStyle::exclusiveIndicatorSize()const {
00614     return QSize( 11, 11 );
00615 }
00616 
00617 void PhaseStyle::getButtonShift( int &x, int &y ) {
00618     x++;
00619     y++;
00620 }
00621 
00622 void PhaseStyle::drawPopupMenuItem ( QPainter * p, bool checkable,
00623                                      int maxpmw,int tabwidth,
00624                                      QMenuItem * mi, const QPalette & pal,
00625                                      bool act, bool enabled, int x,
00626                                      int y, int w, int h ) {
00627     if ( !mi )
00628         return;
00629 
00630     QRect rect(x, y, w, h );
00631     int x2, y2;
00632     x2 = rect.right();
00633     y2 = rect.bottom();
00634     const QColorGroup& g = pal.active();
00635     QColorGroup itemg    = !enabled ? pal.disabled() : pal.active();
00636 
00637     if ( checkable || maxpmw ) maxpmw = QMAX(maxpmw, 20);
00638 
00639     if (act && enabled )
00640         p->fillRect(x, y, w, h, g.highlight() );
00641     else
00642         p->fillRect(x, y, w, h, g.background() );
00643 
00644     // draw seperator
00645     if (mi->isSeparator() ) {
00646     p->setPen( g.dark() );
00647     p->drawLine( x+8, y+1, x+w-8, y+1 );
00648 
00649         p->setPen( g.mid() );
00650         p->drawLine( x+8,   y, x+w-8, y );
00651         p->drawPoint(x+w,y+1);
00652 
00653     p->setPen( g.midlight() );
00654     p->drawLine( x+8, y-1, x+w-8, y-1 );
00655         p->drawPoint(x+8, y );
00656         return;
00657     }
00658 
00659     // draw icon
00660     QIconSet::Mode mode;
00661     if ( mi->iconSet() && !mi->isChecked() ) {
00662         if ( act )
00663             mode = enabled ? QIconSet::Active : QIconSet::Disabled;
00664         else
00665             mode = enabled ? QIconSet::Normal : QIconSet::Disabled;
00666         QPixmap pixmap;
00667         if ( mode == QIconSet::Disabled )
00668             pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
00669         else
00670             pixmap = mi->iconSet()->pixmap();
00671         QRect pmrect(0, 0, pixmap.width(), pixmap.height() );
00672         QRect cr(x, y, maxpmw, h );
00673         pmrect.moveCenter( cr.center() );
00674         p->drawPixmap(pmrect.topLeft(), pixmap);
00675     }
00676 
00677     // draw check
00678     if(mi->isChecked() ) {
00679         drawCheckMark(p, x, y, maxpmw, h, itemg, act, !enabled );
00680     }
00681 
00682 
00683     // draw text
00684     int xm = maxpmw + 2;
00685     int xp = x + xm;
00686     int tw = w -xm - 2;
00687 
00688     p->setPen( enabled ? ( act ? g.highlightedText() : g.buttonText() ) :
00689                          g.mid() );
00690 
00691 
00692     if ( mi->custom() ) {
00693         p->save();
00694         mi->custom()->paint(p, g, act, enabled,
00695                               xp, y+1, tw, h-2 );
00696         p->restore();
00697     }else { // draw label
00698         QString text = mi->text();
00699         if (!text.isNull() ) {
00700             int t = text.find('\t');
00701             const int tflags = AlignVCenter | DontClip |
00702                                ShowPrefix |  SingleLine |
00703                                AlignLeft;
00704 
00705             if (t >= 0) {
00706                 int tabx = x + w - tabwidth - RIGHTBORDER -
00707                            ITEMHMARGIN - ITEMFRAME;
00708                 p->drawText(tabx, y+ITEMVMARGIN, tabwidth,
00709                             h-2*ITEMVMARGIN, tflags,
00710                             text.mid(t+1) );
00711                 text = text.left(t );
00712             }
00713 
00714             // draw left label
00715              p->drawText(xp, y+ITEMVMARGIN,
00716                          tw, h-2*ITEMVMARGIN,
00717                          tflags, text, t);
00718         }else if ( mi->pixmap() ) { // pixmap as label
00719             QPixmap pixmap = *mi->pixmap();
00720             if ( pixmap.depth() == 1 )
00721                 p->setBackgroundMode( OpaqueMode );
00722 
00723             int dx = ((w-pixmap.width() )  /2 ) +
00724                  ((w - pixmap.width()) %2 );
00725             p->drawPixmap(x+dx, y+ITEMFRAME, pixmap );
00726 
00727             if ( pixmap.depth() == 1 )
00728                 p->setBackgroundMode( TransparentMode );
00729         }
00730     }
00731 
00732     if ( mi->popup() ) { // draw submenu arrow
00733         int dim = (h-2*ITEMFRAME) / 2;
00734         drawArrow( p, RightArrow, false,
00735                    x+w-ARROWMARGIN-ITEMFRAME-dim,
00736                    y+h/2-dim/2, dim, dim, g, enabled );
00737     }
00738 }
00739 
00740 
00741 QRect PhaseStyle::comboButtonRect ( int x, int y, int w, int h ) {
00742     return QRect(x+2, y+2, w-4-17, h-5 );
00743 }
00744 
00745 void PhaseStyle::drawComboButton( QPainter * p, int x, int y,
00746                                   int w, int h,
00747                                   const QColorGroup & g,
00748                                   bool sunken,
00749                                   bool editable,
00750                                   bool,
00751                                   const QBrush *) {
00752     drawButton(p, x, y, w, h, g,
00753                sunken, &g.brush(QColorGroup::Button ));
00754 
00755     for ( int n = 0; n < 2; ++n )
00756         kColorBitmaps(p, g, w-16+(6*n), y+(h/2)-2,
00757                       0, &doodad_mid, &doodad_light, 0, 0, 0 );
00758 
00759 
00760     if (editable ) {
00761         const int x2 = x+w-1; const int y2 = y+h-1;
00762         p->setPen(g.dark());
00763         p->drawLine(x2+1, y, x2+1, y2);
00764         p->setPen(g.midlight());
00765         p->drawLine(x2+2, y, x2+2, y2-1);
00766         p->setPen(g.button());
00767         p->drawPoint(x2+2, y2);
00768     }
00769 
00770     p->setPen(g.buttonText() );
00771 }
00772 
00773 void PhaseStyle::tabbarMetrics( const QTabBar* t, int &hframe, int &vframe,  int& ov ) {
00774     QCommonStyle::tabbarMetrics( t, hframe, vframe, ov );
00775     hframe -= 2;
00776     vframe += 1;
00777 }
00778 
00779 
00780 void PhaseStyle::drawTab(QPainter* painter, const QTabBar* bar, QTab* tab,
00781                          bool selected ) {
00782     bool edge = false;
00783     int x, y, w, h;
00784     QRect r = tab->rect();
00785     r.rect(&x,&y,&w,&h);
00786     const int x2 = x+w-1;
00787     const int y2 = y+h-1;
00788     const QColorGroup &group = bar->colorGroup();
00789 
00790 
00791     painter->save();
00792 
00793     // what position is the tab?
00794     if ((bar->count() == 1 ))
00795     edge = true;
00796     else
00797     edge = false;
00798 
00799     switch (QTabBar::Shape(bar->shape())) {
00800     case QTabBar::RoundedAbove:
00801     case QTabBar::TriangularAbove: {
00802         if (!selected) { // shorten
00803             y += 2; h -= 2;
00804         }
00805         if (selected) {
00806             painter->setPen(Qt::NoPen);
00807             painter->fillRect(x+1, y+1, w-1, h-1,
00808                               group.brush(QColorGroup::Background));
00809         } else
00810             drawPhaseGradient(painter, QRect(x+1, y+1, w-1, h-2),
00811                               group.background().dark(contrast) );
00812 
00813 
00814         // draw tab
00815         painter->setPen(group.dark());
00816         painter->drawLine(x, y, x, y2-2);
00817         painter->drawLine(x+1, y, x2, y);
00818         painter->drawLine(x2, y+1, x2, y2-2);
00819 
00820         painter->setPen(group.mid());
00821         painter->drawLine(x2-1, y+2, x2-1, y2-2);
00822 
00823         painter->setPen(group.midlight());
00824         painter->drawLine(x+1, y+1, x2-2, y+1);
00825         if ((selected) || edge) painter->drawLine(x+1, y+2, x+1, y2-2);
00826 
00827         // finish off bottom
00828         if (selected) {
00829             painter->setPen(group.dark());
00830             painter->drawPoint(x, y2-1);
00831             painter->drawPoint(x2, y2-1);
00832 
00833             painter->setPen(group.midlight());
00834             painter->drawPoint(x, y2);
00835             painter->drawLine(x+1, y2-1, x+1, y2);
00836             painter->drawPoint(x2, y2);
00837 
00838             painter->setPen(group.mid());
00839             painter->drawPoint(x2-1, y2-1);
00840 
00841             if (edge) {
00842                 painter->setPen(group.dark());
00843                 painter->drawLine(x, y2-1, x, y2);
00844                 painter->setPen(group.midlight());
00845                 painter->drawPoint(x+1, y2);
00846             }
00847         } else {
00848             painter->setPen(group.dark());
00849             painter->drawLine(x, y2-1, x2, y2-1);
00850 
00851             painter->setPen(group.midlight());
00852             painter->drawLine(x, y2, x2, y2);
00853 
00854             if (edge) {
00855                 painter->setPen(group.dark());
00856                 painter->drawLine(x, y2-1, x, y2);
00857             }
00858         }
00859         break;
00860     }
00861     case QTabBar::RoundedBelow:
00862     case QTabBar::TriangularBelow: {
00863         painter->setBrush( group.background().dark(contrast));
00864         painter->setPen(Qt::NoPen);
00865         painter->fillRect(x+1, y+1, w-1, h-1, painter->brush());
00866 
00867         // draw tab
00868         painter->setPen(group.dark());
00869         painter->drawLine(x, y+1, x, y2);
00870         painter->drawLine(x+1, y2, x2, y2);
00871         painter->drawLine(x2, y+1, x2, y2-1);
00872 
00873         painter->setPen(group.mid());
00874         painter->drawLine(x2-1, y+1, x2-1, y2-1);
00875         painter->drawLine(x+2, y2-1, x2-1, y2-1);
00876         painter->drawPoint(x, y);
00877         painter->drawPoint(x2, y);
00878 
00879         if ((selected) || edge) {
00880             painter->setPen(group.midlight());
00881             painter->drawLine(x+1, y+1, x+1, y2-2);
00882         }
00883 
00884         // finish off top
00885         if (selected) {
00886             if (edge) {
00887                 painter->setPen(group.dark());
00888                 painter->drawPoint(x, y);
00889                 painter->setPen(group.midlight());
00890                 painter->drawPoint(x+1, y);
00891             }
00892         } else {
00893             painter->setPen(group.dark());
00894             painter->drawLine(x, y+1, x2, y+1);
00895 
00896             painter->setPen(group.mid());
00897             painter->drawLine(x, y, x2, y);
00898 
00899             if (edge) {
00900                 painter->setPen(group.dark());
00901                 painter->drawPoint(x, y);
00902             }
00903         }
00904           break;
00905     }
00906     }
00907 
00908     painter->restore();
00909 }
00910 
00911 void PhaseStyle::drawTabMask( QPainter* p, const QTabBar*, QTab* tab,
00912                               bool ) {
00913     p->fillRect(tab->rect(), Qt::color1);
00914 }
00915 
00916 void PhaseStyle::drawToolButton(QPainter * p, int x, int y,
00917                                 int w, int h, const QColorGroup & g,
00918                                 bool sunken,
00919                                 const QBrush * fill ) {
00920     QRect r(x, y, w, h );
00921     p->fillRect(r, g.background());
00922 
00923     drawPanel(p, x, y, w, h, g, sunken, 1,
00924               fill ? fill : &g.brush(QColorGroup::Button) );
00925 
00926 
00927     p->setPen(g.text() );
00928 }
00929 
00930 
00931 /*
00932  * LGPLv2  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
00933  *
00934  * ../web/webstyle.cpp
00935  */
00936 void PhaseStyle::scrollBarMetrics(const QScrollBar* sb, int& sliderMin,
00937                                   int& sliderMax, int &sliderLength,
00938                                   int& buttonDim ) {
00939     int maxlen;
00940     bool horizontal = sb->orientation() == QScrollBar::Horizontal;
00941     int len = (horizontal) ? sb->width() : sb->height();
00942     int extent = (horizontal) ? sb->height() : sb->width();
00943 
00944     if (len > (extent - 1) * 2)
00945         buttonDim = extent;
00946     else
00947         buttonDim = len / 2 - 1;
00948 
00949     if (horizontal)
00950         sliderMin = buttonDim * 2;
00951     else
00952         sliderMin = 1;
00953 
00954     maxlen = len - buttonDim * 2 - 1;
00955     int div = QMAX(1, (sb->maxValue() - sb->minValue() + sb->pageStep() ) );
00956 
00957     sliderLength =
00958         (sb->pageStep() * maxlen) / div;
00959 
00960     if (sliderLength < SCROLLBAR_EXTENT)
00961         sliderLength = SCROLLBAR_EXTENT;
00962 
00963     if (sliderLength > maxlen)
00964         sliderLength = maxlen;
00965 
00966     sliderMax = sliderMin + maxlen - sliderLength;
00967 }
00968 
00969 void PhaseStyle::drawScrollBarControls( QPainter* p, const QScrollBar *sb,
00970                                         int sliderStart, uint controls,
00971                                         uint activeControl) {
00972     const bool horizontal = (sb->orientation() == Qt::Horizontal );
00973     int sliderMin, sliderMax, sliderLength, buttonDim;
00974     const QColorGroup& g = sb->colorGroup();
00975     QRect sub, add, subPage, addPage, slider;
00976     int x, y, x2, y2;
00977 
00978     scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00979 
00980     /* lets get the positions */
00981     scrollBarItemPositions(sb, horizontal, sliderStart,
00982                            sliderMax, sliderLength, buttonDim,
00983                            sub, add, subPage, addPage,
00984                            slider );
00985 
00986 
00987     /* sanity */
00988     if ( sliderStart > sliderMax )
00989         sliderStart = sliderMax;
00990 
00991     // addline
00992     if ( controls & AddLine && add.isValid() ) {
00993         x =  add.x();     y  = add.y();
00994         x2 = add.width(); y2 = add.height();
00995         const bool down = (activeControl & AddLine );
00996         drawBevelButton(p, x, y, x2, y2, g, down,
00997                         &g.brush(QColorGroup::Button));
00998 
00999         Qt::ArrowType arrow = horizontal ? RightArrow : DownArrow;
01000         if (down ) {
01001             switch (arrow ) {
01002             case DownArrow:   y++; break;
01003             case RightArrow:  x++; break;
01004             default:               break;
01005             }
01006         }
01007         drawArrow( p, arrow, down, x, y, x2, y2, g, true );
01008     }
01009 
01010     if ( controls & SubLine && sub.isValid() ) {
01011         x =  sub.x();     y  = sub.y();
01012         x2 = sub.width(); y2 = sub.height();
01013         const bool down = (activeControl & SubLine );
01014         drawBevelButton(p, x, y, x2, y2, g, down,
01015                         &g.brush(QColorGroup::Button));
01016 
01017         Qt::ArrowType arrow = horizontal ? LeftArrow : UpArrow;
01018         if (down ) {
01019             switch (arrow ) {
01020             case UpArrow:   y--; break;
01021             case LeftArrow: x--; break;
01022             default:             break;
01023             }
01024         }
01025         drawArrow( p, arrow, down, x, y, x2, y2, g, true );
01026     }
01027 
01028     if ( controls & AddPage && addPage.isValid()  ) {
01029         x  = addPage.x();     y  = addPage.y();
01030         x2 = addPage.right(); y2 = addPage.bottom();
01031 
01032         p->fillRect(addPage, g.mid());
01033         p->setPen(g.dark());
01034         if (horizontal) { // vertical
01035             p->drawLine(x, y, x2, y);
01036             p->drawLine(x, y2, x2, y2);
01037         } else { // horizontal
01038             p->drawLine(x, y, x, y2);
01039             p->drawLine(x2, y, x2, y2);
01040         }
01041     }
01042 
01043     if ( controls & SubPage && subPage.isValid() ) {
01044         x  = subPage.x();     y  = subPage.y();
01045         x2 = subPage.right(); y2 = subPage.bottom();
01046 
01047         p->fillRect(subPage, g.mid());
01048         p->setPen(g.dark());
01049         if (horizontal) { // vertical
01050             p->drawLine(x, y, x2, y);
01051             p->drawLine(x, y2, x2, y2);
01052         } else { // horizontal
01053             p->drawLine(x, y, x, y2);
01054             p->drawLine(x2, y, x2, y2);
01055         }
01056 }
01057 
01058     if ( controls & Slider && slider.isValid() ) {
01059         x  = slider.x();     y  = slider.y();
01060         x2 = slider.width(); y2 = slider.height();
01061         const bool down = ( activeControl & Slider );
01062         int cx = x + x2/2 -2; int cy = y + y2/2 -2;
01063 
01064         drawBevelButton(p, x, y, x2, y2, g, down,
01065                         &g.brush(QColorGroup::Button) );
01066 
01067         if (horizontal && (x2 >=20)) {
01068             for (int n = -5; n <= 5; n += 5)
01069                 kColorBitmaps(p, g, cx+n, cy,
01070                                 0, &doodad_mid, &doodad_light, 0, 0, 0);
01071         } else if (!horizontal && (y2 >= 20)) {
01072             for (int n = -5; n <= 5; n += 5)
01073                 kColorBitmaps(p, g, cx, cy+n,
01074                               0, &doodad_mid, &doodad_light, 0, 0, 0);
01075         }
01076 
01077         if ( sb->hasFocus() && down ) {
01078             slider = QRect(slider.x()+2, slider.y()+2,
01079                            slider.width()-2, slider.height()-2 );
01080             drawFocusRect(p, slider, g, false );
01081         }
01082 
01083     }
01084 }
01085 
01086 /*
01087  * LGPLv2  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
01088  *
01089  * ../web/webstyle.cpp
01090  */
01091 QStyle::ScrollControl PhaseStyle::scrollBarPointOver( const QScrollBar * sb,
01092                                      int sliderStart,
01093                                      const QPoint & point ) {
01094     if (!sb->rect().contains(point))
01095         return NoScroll;
01096 
01097     int sliderMin, sliderMax, sliderLength, buttonDim;
01098     scrollBarMetrics(sb, sliderMin, sliderMax, sliderLength, buttonDim);
01099 
01100     if (sb->orientation() == QScrollBar::Horizontal) {
01101         int x = point.x();
01102 
01103         if (x <= buttonDim)
01104             return SubLine;
01105         else if (x <= buttonDim * 2)
01106             return AddLine;
01107         else if (x < sliderStart)
01108             return SubPage;
01109         else if (x < sliderStart+sliderLength)
01110             return Slider;
01111         else
01112             return AddPage;
01113     } else   {
01114         int y = point.y();
01115 
01116         if (y < sliderStart)
01117             return SubPage;
01118         else if (y < sliderStart + sliderLength)
01119             return Slider;
01120         else if (y < sliderMax + sliderLength)
01121             return AddPage;
01122         else if (y < sliderMax + sliderLength + buttonDim)
01123             return SubLine;
01124         else
01125             return AddLine;
01126   }
01127 }
01128 
01129 /*
01130  * LGPLv2  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
01131  *
01132  * ../web/webstyle.cpp
01133  * scrollBarControlsMetrics
01134  */
01135 void PhaseStyle::scrollBarItemPositions( const QScrollBar* sb, const bool horizontal,
01136                                          int sliderStart, int sliderMax,
01137                                          int sliderLength, int buttonDim,
01138                                          QRect &rSub, QRect& rAdd, QRect& rSubPage,
01139                                          QRect &rAddPage, QRect& rSlider ) {
01140 
01141     int len     = horizontal ? sb->width()  : sb->height();
01142     int extent  = horizontal ? sb->height() : sb->width();
01143 
01144     QColorGroup g = sb->colorGroup();
01145 
01146     if (sliderStart > sliderMax)
01147         sliderStart = sliderMax;
01148 
01149     int sliderEnd = sliderStart + sliderLength;
01150 
01151     int addX, addY;
01152     int subX, subY;
01153     int subPageX, subPageY, subPageW, subPageH;
01154     int addPageX, addPageY, addPageW, addPageH;
01155     int sliderX, sliderY, sliderW, sliderH;
01156 
01157     if (horizontal){
01158         subY      = 0;
01159         addY      = 0;
01160         subX      = 0;
01161         addX      = buttonDim;
01162 
01163         subPageX  = buttonDim * 2;
01164         subPageY  = 0;
01165         subPageW  = sliderStart - 1;
01166         subPageH  = extent;
01167 
01168         addPageX  = sliderEnd;
01169         addPageY  = 0;
01170         addPageW  = len - sliderEnd;
01171         addPageH  = extent;
01172 
01173         sliderX   = sliderStart;
01174         sliderY   = 0;
01175         sliderW   = sliderLength;
01176         sliderH   = extent;
01177     }else {
01178         subX    = 0;
01179         addX    = 0;
01180         subY    = len - buttonDim * 2;
01181         addY    = len - buttonDim;
01182 
01183         subPageX = 0;
01184         subPageY = 0;
01185         subPageW = extent;
01186         subPageH = sliderStart;
01187 
01188         addPageX  = 0;
01189         addPageY  = sliderEnd;
01190         addPageW  = extent;
01191         addPageH  = subY - sliderEnd;
01192 
01193         sliderX   = 0;
01194         sliderY   = sliderStart;
01195         sliderW   = extent;
01196         sliderH   = sliderLength;
01197     }
01198 
01199     rSub      .setRect(    subX,      subY, buttonDim, buttonDim);
01200     rAdd      .setRect(    addX,      addY, buttonDim, buttonDim);
01201     rSubPage  .setRect(subPageX,  subPageY,  subPageW,  subPageH);
01202     rAddPage  .setRect(addPageX,  addPageY,  addPageW,  addPageH);
01203     rSlider   .setRect( sliderX,   sliderY,   sliderW,   sliderH);
01204 
01205 }
01206 
01207 
01208 void PhaseStyle::drawSlider (QPainter * p, int x, int y,
01209                              int w, int h, const QColorGroup &g,
01210                              Orientation o, bool, bool ) {
01211     int cx = x + w/2;
01212     int cy = y + h/2;
01213     QBrush brush = g.brush( QColorGroup::Button );
01214 
01215     if ( o == Horizontal ) {
01216         drawBevelButton(p, cx-5, y, 6, h, g, false,
01217                         &brush );
01218         drawBevelButton(p, cx, y, 6, h, g, false,
01219                         &brush );
01220     }else {
01221         drawBevelButton(p, x, cy-5, w, 6, g, false,
01222                         &brush );
01223         drawBevelButton(p, x, cy, w, 6, g, false,
01224                         &brush );
01225     }
01226 }
01227 
01228 void PhaseStyle::drawSliderGroove(QPainter* p, int x, int y,
01229                                   int w, int h, const QColorGroup& g,
01230                                   QCOORD , Orientation o ) {
01231     int cx = x + w/2;
01232     int cy = y + h/2;
01233 
01234     if ( o == Horizontal ) {
01235         y = cy-3; h = 7;
01236     }else {
01237         x = cx-3; w = 7;
01238     }
01239 
01240     drawPanel(p, x, y, w, h, g, true, 1,
01241               &g.brush(QColorGroup::Mid ) );
01242 }

Generated on Sat Nov 5 16:17:59 2005 for OPIE by  doxygen 1.4.2