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

webstyle.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2001 Rik Hemsley (rikkus) <rik@kde.org>
00003  *
00004  *  This library is free software; you can redistribute it and/or
00005  *  modify it under the terms of the GNU Library General Public
00006  *  License as published by the Free Software Foundation; either
00007  *  version 2 of the License, or (at your option) any later version.
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., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef INCLUDE_MENUITEM_DEF
00021 #define INCLUDE_MENUITEM_DEF
00022 #endif
00023 
00024 #include <qmenudata.h>
00025 #include <qpalette.h>
00026 #include <qbitmap.h>
00027 #include <qtabbar.h>
00028 #include <qpointarray.h>
00029 #include <qscrollbar.h>
00030 #include <qframe.h>
00031 #include <qpushbutton.h>
00032 #include <qdrawutil.h>
00033 #include <qpainter.h>
00034 
00035 #include "webstyle.h"
00036 
00037 static const int  _indicatorSize = 9;
00038 static QButton *  _highlightedButton = 0;
00039 static const int  _scrollBarExtent = 12;
00040 
00041 static QFrame *   _currentFrame = 0;
00042 static int        _savedFrameLineWidth;
00043 static int        _savedFrameMidLineWidth;
00044 static ulong      _savedFrameStyle;
00045 
00046 static const int ITEMFRAME       = 1; // menu stuff
00047 static const int ITEMHMARGIN     = 3;
00048 static const int ITEMVMARGIN     = 0;
00049 
00050 static const int ARROWMARGIN     = 6;
00051 static const int RIGHTBORDER     = 10;
00052 static const int MINICONSIZE     = 12;
00053 
00054 
00055 static QColor contrastingForeground(const QColor & fg, const QColor & bg)
00056 {
00057   int h, s, vbg, vfg;
00058 
00059   bg.hsv(&h, &s, &vbg);
00060   fg.hsv(&h, &s, &vfg);
00061 
00062   int diff(vbg - vfg);
00063 
00064   if ((diff > -72) && (diff < 72))
00065   {
00066     return (vbg < 128) ? Qt::white : Qt::black;
00067   }
00068   else
00069   {
00070     return fg;
00071   }
00072 }
00073 
00074 // Gotta keep it separated.
00075 
00076   static void
00077 scrollBarControlsMetrics
00078 (
00079  const QScrollBar * sb,
00080  int sliderStart,
00081  int /* sliderMin */,
00082  int sliderMax,
00083  int sliderLength,
00084  int buttonDim,
00085  QRect & rSub,
00086  QRect & rAdd,
00087  QRect & rSubPage,
00088  QRect & rAddPage,
00089  QRect & rSlider
00090  )
00091 {
00092   bool horizontal = sb->orientation() == QScrollBar::Horizontal;
00093 
00094   int len     = horizontal ? sb->width()  : sb->height();
00095 
00096   int extent  = horizontal ? sb->height() : sb->width();
00097 
00098   QColorGroup g = sb->colorGroup();
00099 
00100   if (sliderStart > sliderMax)
00101     sliderStart = sliderMax;
00102 
00103   int sliderEnd = sliderStart + sliderLength;
00104 
00105   int addX, addY;
00106   int subX, subY;
00107   int subPageX, subPageY, subPageW, subPageH;
00108   int addPageX, addPageY, addPageW, addPageH;
00109   int sliderX, sliderY, sliderW, sliderH;
00110 
00111   if (horizontal)
00112   {
00113     subY      = 0;
00114     addY      = 0;
00115     subX      = 0;
00116     addX      = buttonDim;
00117 
00118     subPageX  = buttonDim * 2;
00119     subPageY  = 0;
00120     subPageW  = sliderStart - 1;
00121     subPageH  = extent;
00122 
00123     addPageX  = sliderEnd;
00124     addPageY  = 0;
00125     addPageW  = len - sliderEnd;
00126     addPageH  = extent;
00127 
00128     sliderX   = sliderStart;
00129     sliderY   = 0;
00130     sliderW   = sliderLength;
00131     sliderH   = extent;
00132   }
00133   else
00134   {
00135     subX    = 0;
00136     addX    = 0;
00137     subY    = len - buttonDim * 2;
00138     addY    = len - buttonDim;
00139 
00140     subPageX = 0;
00141     subPageY = 0;
00142     subPageW = extent;
00143     subPageH = sliderStart;
00144 
00145     addPageX  = 0;
00146     addPageY  = sliderEnd;
00147     addPageW  = extent;
00148     addPageH  = subY - sliderEnd;
00149 
00150     sliderX   = 0;
00151     sliderY   = sliderStart;
00152     sliderW   = extent;
00153     sliderH   = sliderLength;
00154   }
00155 
00156   rSub      .setRect(    subX,      subY, buttonDim, buttonDim);
00157   rAdd      .setRect(    addX,      addY, buttonDim, buttonDim);
00158   rSubPage  .setRect(subPageX,  subPageY,  subPageW,  subPageH);
00159   rAddPage  .setRect(addPageX,  addPageY,  addPageW,  addPageH);
00160   rSlider   .setRect( sliderX,   sliderY,   sliderW,   sliderH);
00161 }
00162 
00163 // Rounded rects my way.
00164 
00165   static void
00166 drawFunkyRect
00167 (
00168  QPainter * p,
00169  int x,
00170  int y,
00171  int w,
00172  int h,
00173  bool small
00174 )
00175 {
00176   p->translate(x, y);
00177 
00178   if (small)
00179   {
00180     p->drawLine(      2,      0,  w - 3,      0  );
00181     p->drawLine(  w - 1,      2,  w - 1,  h - 3  );
00182     p->drawLine(  w - 3,  h - 1,      2,  h - 1  );
00183     p->drawLine(      0,  h - 3,      0,      2  );
00184 
00185     // Use an array of points so that there's only one round-trip with the
00186     // X server.
00187 
00188     QCOORD pointList[] =
00189     {
00190           1,      1,
00191       w - 2,      1,
00192       w - 2,  h - 2,
00193           1,  h - 2
00194     };
00195 
00196     p->drawPoints(QPointArray(4, pointList));
00197   }
00198   else
00199   {
00200     p->drawLine(      3,      0,  w - 4,      0  );
00201     p->drawLine(  w - 1,      3,  w - 1,  h - 4  );
00202     p->drawLine(  w - 4,  h - 1,      3,  h - 1  );
00203     p->drawLine(      0,  h - 4,      0,      3  );
00204 
00205     QCOORD pointList[] =
00206     {
00207           1,      2,
00208           2,      1,
00209       w - 3,      1,
00210       w - 2,      2,
00211       w - 2,  h - 3,
00212       w - 3,  h - 2,
00213           2,  h - 2,
00214           1,  h - 3
00215     };
00216 
00217     p->drawPoints(QPointArray(8, pointList));
00218   }
00219 
00220   p->translate(-x, -y);
00221 }
00222 
00223 WebStyle::WebStyle()
00224   : QWindowsStyle()
00225 {
00226   setButtonDefaultIndicatorWidth(1);
00227   setScrollBarExtent(_scrollBarExtent, _scrollBarExtent);
00228   setButtonMargin( 3 );
00229   setSliderThickness(_scrollBarExtent );
00230 }
00231 
00232 WebStyle::~WebStyle()
00233 {
00234   // Empty.
00235 }
00236 
00237   void
00238 WebStyle::polish(QApplication *)
00239 {
00240   // Empty.
00241 }
00242 
00243   void
00244 WebStyle::polish(QPalette &)
00245 {
00246   // Empty.
00247 }
00248 
00249   void
00250 WebStyle::unPolish(QApplication *)
00251 {
00252   // Empty.
00253 }
00254 
00255   void
00256 WebStyle::polish(QWidget * w)
00257 {
00258   if (w->inherits("QPushButton"))
00259     w->installEventFilter(this);
00260 
00261   else if (w->inherits("QGroupBox") || w->inherits("QFrame"))
00262   {
00263     QFrame * f(static_cast<QFrame *>(w));
00264 
00265     if (f->frameStyle() != QFrame::NoFrame)
00266     {
00267       _currentFrame = f;
00268 
00269       _savedFrameLineWidth = f->lineWidth();
00270       _savedFrameMidLineWidth = f->midLineWidth();
00271       _savedFrameStyle = f->frameStyle();
00272 
00273       if (f->frameShape() == QFrame::HLine || f->frameShape() == QFrame::VLine)
00274       {
00275         f->setMidLineWidth(1);
00276         f->setFrameStyle(f->frameShape() | QFrame::Plain);
00277       }
00278       else
00279       {
00280         f->setLineWidth(1);
00281         f->setFrameStyle(QFrame::Box | QFrame::Plain);
00282       }
00283     }
00284   }
00285 }
00286 
00287   void
00288 WebStyle::unPolish(QWidget * w)
00289 {
00290   if (w->inherits("QPushButton"))
00291     w->removeEventFilter(this);
00292 
00293   else if (w == _currentFrame)
00294   {
00295     QFrame * f(static_cast<QFrame *>(w));
00296 
00297     f->setLineWidth(_savedFrameLineWidth);
00298     f->setMidLineWidth(_savedFrameMidLineWidth);
00299     f->setFrameStyle(_savedFrameStyle);
00300   }
00301 }
00302 
00303   bool
00304 WebStyle::eventFilter(QObject * o, QEvent * e)
00305 {
00306   QPushButton * pb(static_cast<QPushButton *>(o));
00307 
00308   if (e->type() == QEvent::Enter)
00309   {
00310     _highlightedButton = pb;
00311     pb->repaint(false);
00312   }
00313   else if (e->type() == QEvent::Leave)
00314   {
00315     _highlightedButton = 0;
00316     pb->repaint(false);
00317   }
00318 
00319   return false;
00320 }
00321 
00322   void
00323 WebStyle::drawButton
00324 (
00325  QPainter * p,
00326  int x,
00327  int y,
00328  int w,
00329  int h,
00330  const QColorGroup & g,
00331  bool sunken,
00332  const QBrush * fill
00333 )
00334 {
00335   p->save();
00336 
00337   if (sunken)
00338     p->setPen(contrastingForeground(g.light(), g.button()));
00339   else
00340     p->setPen(contrastingForeground(g.mid(), g.button()));
00341 
00342   p->setBrush(0 == fill ? NoBrush : *fill);
00343 
00344   drawFunkyRect(p, x, y, w, h, true);
00345 
00346   p->restore();
00347 }
00348 
00349   QRect
00350 WebStyle::buttonRect(int x, int y, int w, int h)
00351 {
00352   return QRect(x + 2, y + 2, w - 4, h - 4);
00353 }
00354 
00355   void
00356 WebStyle::drawBevelButton
00357 (
00358  QPainter * p,
00359  int x,
00360  int y,
00361  int w,
00362  int h,
00363  const QColorGroup & g,
00364  bool sunken,
00365  const QBrush * fill
00366 )
00367 {
00368   drawButton(p, x, y, w, h, g, sunken, fill);
00369 }
00370 
00371   void
00372 WebStyle::drawPushButton(QPushButton * b, QPainter * p)
00373 {
00374   // Note: painter is already translated for us.
00375 
00376   bool sunken(b->isDown() || b->isOn());
00377   bool hl(_highlightedButton == b);
00378 
00379   QColor bg(b->colorGroup().button());
00380 
00381   p->save();
00382   p->fillRect(b->rect(), b->colorGroup().brush(QColorGroup::Background));
00383 
00384   if (b->isDefault())
00385   {
00386     QColor c(hl ? b->colorGroup().highlight() : b->colorGroup().mid());
00387 
00388     p->setPen(contrastingForeground(c, bg));
00389 
00390     drawFunkyRect(p, 0, 0, b->width(), b->height(), false);
00391   }
00392 
00393   p->fillRect
00394     (
00395      4,
00396      4,
00397      b->width() - 8,
00398      b->height() - 8,
00399      b->colorGroup().brush(QColorGroup::Button)
00400     );
00401 
00402   if (b->isEnabled())
00403   {
00404     if (sunken)
00405     {
00406       p->setPen(contrastingForeground(b->colorGroup().light(), bg));
00407     }
00408     else
00409     {
00410       if (hl)
00411         p->setPen(contrastingForeground(b->colorGroup().highlight(), bg));
00412       else
00413         p->setPen(contrastingForeground(b->colorGroup().mid(), bg));
00414     }
00415   }
00416   else
00417   {
00418     p->setPen(b->colorGroup().button());
00419   }
00420 
00421   drawFunkyRect(p, 3, 3, b->width() - 6, b->height() - 6, true);
00422 
00423   p->restore();
00424 }
00425 
00426   void
00427 WebStyle::drawPushButtonLabel(QPushButton * b, QPainter * p)
00428 {
00429   // This is complicated stuff and we don't really want to mess with it.
00430 
00431   QWindowsStyle::drawPushButtonLabel(b, p);
00432 }
00433 
00434   void
00435 WebStyle::drawScrollBarControls
00436 (
00437  QPainter * p,
00438  const QScrollBar * sb,
00439  int sliderStart,
00440  uint controls,
00441  uint activeControl
00442 )
00443 {
00444   p->save();
00445 
00446   int sliderMin, sliderMax, sliderLength, buttonDim;
00447 
00448   scrollBarMetrics(sb, sliderMin, sliderMax, sliderLength, buttonDim);
00449 
00450   QRect rSub, rAdd, rSubPage, rAddPage, rSlider;
00451 
00452   scrollBarControlsMetrics
00453     (
00454      sb,
00455      sliderStart,
00456      sliderMin,
00457      sliderMax,
00458      sliderLength,
00459      buttonDim,
00460      rSub,
00461      rAdd,
00462      rSubPage,
00463      rAddPage,
00464      rSlider
00465     );
00466 
00467   QColorGroup g(sb->colorGroup());
00468 
00469   if (controls & AddLine && rAdd.isValid())
00470   {
00471     bool active(activeControl & AddLine);
00472 
00473     QColor c(active ? g.highlight() : g.dark());
00474 
00475     p->setPen(c);
00476     p->setBrush(g.button());
00477     p->drawRect(rAdd);
00478 
00479     Qt::ArrowType t =
00480       sb->orientation() == Horizontal ? Qt::RightArrow : Qt::DownArrow;
00481 
00482     // Is it me or is KStyle::drawArrow broken ?
00483 
00484     drawArrow
00485       (
00486        p,
00487        t,
00488        true, // FIXME - down ?
00489        rAdd.x(),
00490        rAdd.y(),
00491        rAdd.width(),
00492        rAdd.height(),
00493        g,
00494        true // FIXME - enabled ?
00495       );
00496   }
00497 
00498   if (controls & SubLine && rSub.isValid())
00499   {
00500     bool active(activeControl & SubLine);
00501 
00502     QColor c(active ? g.highlight() : g.dark());
00503 
00504     p->setPen(c);
00505     p->setBrush(g.button());
00506     p->drawRect(rSub);
00507 
00508     Qt::ArrowType t =
00509       sb->orientation() == Horizontal ? Qt::LeftArrow : Qt::UpArrow;
00510 
00511     drawArrow
00512       (
00513        p,
00514        t,
00515        true, // FIXME - down ?
00516        rSub.x(),
00517        rSub.y(),
00518        rSub.width(),
00519        rSub.height(),
00520        g,
00521        true // FIXME - enabled ?
00522       );
00523   }
00524 
00525   if (controls & SubPage && rSubPage.isValid())
00526   {
00527     p->setPen(g.mid());
00528     p->setBrush(g.base());
00529     p->drawRect(rSubPage);
00530   }
00531 
00532   if (controls & AddPage && rAddPage.isValid())
00533   {
00534     p->setPen(g.mid());
00535     p->setBrush(g.base());
00536     p->drawRect(rAddPage);
00537   }
00538 
00539   if (controls & Slider && rSlider.isValid())
00540   {
00541     p->setPen(activeControl & Slider ? g.highlight() : g.dark());
00542 
00543     p->setBrush(g.button());
00544     p->drawRect(rSlider);
00545 
00546     p->setBrush(g.light());
00547     p->setPen(g.dark());
00548 
00549     if (sliderLength > _scrollBarExtent * 2)
00550     {
00551       int ellipseSize =
00552         Horizontal == sb->orientation()
00553         ?
00554         rSlider.height() - 4
00555         :
00556         rSlider.width()  - 4
00557         ;
00558 
00559       QPoint center(rSlider.center());
00560 
00561       if (Horizontal == sb->orientation())
00562       {
00563         p->drawEllipse
00564           (
00565            center.x() - ellipseSize / 2, rSlider.y() + 2,
00566            ellipseSize, ellipseSize
00567           );
00568       }
00569       else
00570       {
00571         p->drawEllipse
00572           (
00573            rSlider.x() + 2, center.y() - ellipseSize / 2,
00574            ellipseSize, ellipseSize
00575           );
00576       }
00577     }
00578   }
00579 
00580   p->restore();
00581 }
00582 
00583   QStyle::ScrollControl
00584 WebStyle::scrollBarPointOver
00585 (
00586  const QScrollBar * sb,
00587  int sliderStart,
00588  const QPoint & point
00589 )
00590 {
00591   if (!sb->rect().contains(point))
00592     return NoScroll;
00593 
00594   int sliderMin, sliderMax, sliderLength, buttonDim;
00595 
00596   scrollBarMetrics(sb, sliderMin, sliderMax, sliderLength, buttonDim);
00597 
00598   if (sb->orientation() == QScrollBar::Horizontal)
00599   {
00600     int x = point.x();
00601 
00602     if (x <= buttonDim)
00603       return SubLine;
00604 
00605     else if (x <= buttonDim * 2)
00606       return AddLine;
00607 
00608     else if (x < sliderStart)
00609       return SubPage;
00610 
00611     else if (x < sliderStart+sliderLength)
00612       return Slider;
00613 
00614     return AddPage;
00615   }
00616   else
00617   {
00618     int y = point.y();
00619 
00620     if (y < sliderStart)
00621       return SubPage;
00622 
00623     else if (y < sliderStart + sliderLength)
00624       return Slider;
00625 
00626     else if (y < sliderMax + sliderLength)
00627       return AddPage;
00628 
00629     else if (y < sliderMax + sliderLength + buttonDim)
00630       return SubLine;
00631 
00632     return AddLine;
00633   }
00634 }
00635 
00636   void
00637 WebStyle::scrollBarMetrics
00638 (
00639  const QScrollBar * sb,
00640  int & sliderMin,
00641  int & sliderMax,
00642  int & sliderLength,
00643  int & buttonDim
00644 )
00645 {
00646 //    return QWindowsStyle::scrollBarMetrics(sb, sliderMin, sliderMax,
00647 //                                           sliderLength, buttonDim );
00648     int maxlen;
00649 
00650   bool horizontal = sb->orientation() == QScrollBar::Horizontal;
00651 
00652   int len = (horizontal) ? sb->width() : sb->height();
00653 
00654   int extent = (horizontal) ? sb->height() : sb->width();
00655 
00656   if (len > (extent - 1) * 2)
00657     buttonDim = extent;
00658   else
00659     buttonDim = len / 2 - 1;
00660 
00661   if (horizontal)
00662     sliderMin = buttonDim * 2;
00663   else
00664     sliderMin = 1;
00665 
00666   maxlen = len - buttonDim * 2 - 1;
00667 
00668   int div = QMAX(1, (sb->maxValue() - sb->minValue() + sb->pageStep() ) );
00669 
00670   sliderLength =
00671     (sb->pageStep() * maxlen) / div;
00672 
00673   if (sliderLength < _scrollBarExtent)
00674     sliderLength = _scrollBarExtent;
00675 
00676   if (sliderLength > maxlen)
00677     sliderLength = maxlen;
00678 
00679   sliderMax = sliderMin + maxlen - sliderLength;
00680 }
00681 
00682   QSize
00683 WebStyle::indicatorSize() const
00684 {
00685   return QSize(_indicatorSize, _indicatorSize);
00686 }
00687 
00688   void
00689 WebStyle::drawIndicator
00690 (
00691  QPainter * p,
00692  int x,
00693  int y,
00694  int w,
00695  int h,
00696  const QColorGroup & g,
00697  int state,
00698  bool down,
00699  bool enabled
00700 )
00701 {
00702   p->save();
00703 
00704   p->fillRect(x, y, w, h, g.background());
00705 
00706   if (enabled)
00707   {
00708     p->setPen(down ? g.highlight() : contrastingForeground(g.dark(), g.background()));
00709   }
00710   else
00711   {
00712     g.mid();
00713   }
00714 
00715   p->drawRect(x, y, w, h);
00716 
00717   if (state != QButton::Off)
00718   {
00719     p->fillRect(x + 2, y + 2, w - 4, h - 4, enabled ? g.highlight() : g.mid());
00720 
00721     if (state == QButton::NoChange)
00722     {
00723       p->fillRect(x + 4, y + 4, w - 8, h - 8, g.background());
00724     }
00725   }
00726 
00727   p->restore();
00728 }
00729 
00730   QSize
00731 WebStyle::exclusiveIndicatorSize() const
00732 {
00733   return QSize(_indicatorSize+2, _indicatorSize+2);
00734 }
00735 
00736   void
00737 WebStyle::drawExclusiveIndicator
00738 (
00739  QPainter * p,
00740  int x,
00741  int y,
00742  int w,
00743  int h,
00744  const QColorGroup & g,
00745  bool on,
00746  bool down,
00747  bool enabled
00748 )
00749 {
00750   p->save();
00751 
00752   p->fillRect(x, y, w, h, g.background());
00753 
00754   if (enabled)
00755   {
00756     p->setPen(down ? g.highlight() : contrastingForeground(g.dark(), g.background()));
00757   }
00758   else
00759   {
00760     p->setPen(g.mid());
00761   }
00762 
00763   p->setBrush(g.brush(QColorGroup::Background));
00764 
00765   // Avoid misshapen ellipses. Qt or X bug ? Who knows...
00766 
00767   if (0 == w % 2)
00768     --w;
00769 
00770   if (0 == h % 2)
00771     --h;
00772 
00773   p->drawEllipse(x, y, w, h);
00774 
00775   if (on)
00776   {
00777     p->setPen(enabled ? g.highlight() : g.mid());
00778     p->setBrush(enabled ? g.highlight() : g.mid());
00779     p->drawEllipse(x + 3, y + 3, w - 6, h - 6);
00780   }
00781 
00782   p->restore();
00783 }
00784 
00785   void
00786 WebStyle::drawIndicatorMask
00787 (
00788  QPainter * p,
00789  int x,
00790  int y,
00791  int w,
00792  int h,
00793  int /* state */
00794 )
00795 {
00796   p->fillRect(x, y, w, h, Qt::color1);
00797 }
00798 
00799   void
00800 WebStyle::drawExclusiveIndicatorMask
00801 (
00802  QPainter * p,
00803  int x,
00804  int y,
00805  int w,
00806  int h,
00807  bool /* on */
00808 )
00809 {
00810   if (0 == w % 2)
00811     --w;
00812 
00813   if (0 == h % 2)
00814     --h;
00815 
00816   p->setPen(Qt::color1);
00817   p->setBrush(Qt::color1);
00818   p->drawEllipse(x, y, w, h);
00819 }
00820 
00821   void
00822 WebStyle::drawComboButton
00823 (
00824  QPainter * p,
00825  int x,
00826  int y,
00827  int w,
00828  int h,
00829  const QColorGroup & g,
00830  bool sunken,
00831  bool editable,
00832  bool enabled,
00833  const QBrush * fill
00834 )
00835 {
00836   p->save();
00837 
00838   p->setPen(NoPen);
00839   p->setBrush(0 == fill ? g.brush(QColorGroup::Background) : *fill);
00840   p->drawRect(x, y, w, h);
00841 
00842   if (enabled)
00843   {
00844     if (sunken)
00845       p->setPen(contrastingForeground(g.highlight(), g.background()));
00846     else
00847       p->setPen(contrastingForeground(g.mid(), g.background()));
00848   }
00849   else
00850   {
00851     p->setPen(contrastingForeground(g.mid(), g.background()));
00852   }
00853 
00854   drawFunkyRect(p, x, y, w, h, true);
00855 
00856   p->drawPoint(w - 10, h - 6);
00857   p->drawPoint(w - 9, h - 6);
00858   p->drawPoint(w - 8, h - 6);
00859   p->drawPoint(w - 7, h - 6);
00860   p->drawPoint(w - 6, h - 6);
00861 
00862   p->drawPoint(w - 9, h - 7);
00863   p->drawPoint(w - 8, h - 7);
00864   p->drawPoint(w - 7, h - 7);
00865   p->drawPoint(w - 6, h - 7);
00866 
00867   p->drawPoint(w - 8, h - 8);
00868   p->drawPoint(w - 7, h - 8);
00869   p->drawPoint(w - 6, h - 8);
00870 
00871   p->drawPoint(w - 7, h - 9);
00872   p->drawPoint(w - 6, h - 9);
00873 
00874   p->drawPoint(w - 6, h - 10);
00875 
00876   if (editable)
00877     p->fillRect(comboButtonFocusRect(x, y, w, h), Qt::red);
00878 
00879   p->restore();
00880 }
00881 
00882   QRect
00883 WebStyle::comboButtonRect(int x, int y, int w, int h)
00884 {
00885   return QRect(x + 2, y + 2, w - 20, h - 4);
00886 }
00887 
00888   QRect
00889 WebStyle::comboButtonFocusRect(int x, int y, int w, int h)
00890 {
00891   return QRect(x + 2, y + 2, w - 20, h - 4);
00892 }
00893 
00894   int
00895 WebStyle::sliderLength() const
00896 {
00897   return 13;
00898 }
00899 
00900   void
00901 WebStyle::drawSliderGroove
00902 (
00903  QPainter * p,
00904  int x,
00905  int y,
00906  int w,
00907  int h,
00908  const QColorGroup & g,
00909  QCOORD /* c */,
00910  Orientation o
00911 )
00912 {
00913   p->save();
00914 
00915   p->setPen(QPen(g.dark(), 0, Qt::DotLine));
00916 
00917   if( o == Qt::Horizontal )
00918     p->drawLine(x, y + h / 2, w, y + h / 2);
00919   else
00920   if( o == Qt::Vertical )
00921     p->drawLine(x + w / 2, y, x + w / 2, h);
00922 
00923   p->restore();
00924 }
00925 
00926   void
00927 WebStyle::drawArrow
00928 (
00929  QPainter * p,
00930  Qt::ArrowType type,
00931  bool down,
00932  int x,
00933  int y,
00934  int w,
00935  int h,
00936  const QColorGroup & g,
00937  bool enabled,
00938  const QBrush * fill
00939 )
00940 {
00941   QWindowsStyle::drawArrow(p, type, down, x, y, w, h, g, enabled, fill);
00942 }
00943 
00944   void
00945 WebStyle::drawSlider
00946 (
00947  QPainter * p,
00948  int x,
00949  int y,
00950  int w,
00951  int h,
00952  const QColorGroup & g,
00953  Orientation o,
00954  bool /* tickAbove */,
00955  bool /* tickBelow */
00956 )
00957 {
00958   p->save();
00959 
00960   p->fillRect(x + 1, y + 1, w - 2, h - 2, g.background());
00961   p->setPen(g.dark());
00962   p->setBrush(g.light());
00963 
00964   int sl = sliderLength();
00965 
00966   if( o == Qt::Horizontal )
00967     p->drawEllipse(x, y + h / 2 - sl / 2, sl, sl);
00968   else
00969   if( o == Qt::Vertical )
00970     p->drawEllipse(x + w / 2 - sl / 2, y, sl, sl);
00971 
00972   p->restore();
00973 }
00974 
00975   void
00976 WebStyle::drawPopupMenuItem
00977 (
00978  QPainter * p,
00979  bool checkable,
00980  int maxpmw,
00981  int tabwidth,
00982  QMenuItem * mi,
00983  const QPalette & pal,
00984  bool act,
00985  bool enabled,
00986  int x,
00987  int y,
00988  int w,
00989  int h
00990 )
00991 {
00992   // TODO
00993   //QWindowsStyle::drawPopupMenuItem(p, checkable, maxpmw, tab, mi, pal, act, enabled, x, y, w, h);
00994     if ( !mi )
00995         return;
00996 
00997     QRect rect(x, y, w, h );
00998     int x2, y2;
00999     x2 = rect.right();
01000     y2 = rect.bottom();
01001     const QColorGroup& g = pal.active();
01002     QColorGroup itemg    = !enabled ? pal.disabled() : pal.active();
01003 
01004     if ( checkable || maxpmw ) maxpmw = QMAX(maxpmw, 20);
01005 
01006     if (act && enabled )
01007         p->fillRect(x, y, w, h, g.highlight() );
01008     else
01009         p->fillRect(x, y, w, h, g.background() );
01010 
01011     // draw seperator
01012     if (mi->isSeparator() ) {
01013     p->setPen( g.dark() );
01014     p->drawLine( x+8, y+1, x+w-8, y+1 );
01015 
01016         p->setPen( g.mid() );
01017         p->drawLine( x+8,   y, x+w-8, y );
01018         p->drawPoint(x+w,y+1);
01019 
01020     p->setPen( g.midlight() );
01021     p->drawLine( x+8, y-1, x+w-8, y-1 );
01022         p->drawPoint(x+8, y );
01023         return;
01024     }
01025 
01026     // draw icon
01027     QIconSet::Mode mode;
01028     if ( mi->iconSet() && !mi->isChecked() ) {
01029         if ( act )
01030             mode = enabled ? QIconSet::Active : QIconSet::Disabled;
01031         else
01032             mode = enabled ? QIconSet::Normal : QIconSet::Disabled;
01033         QPixmap pixmap;
01034         if ( mode == QIconSet::Disabled )
01035             pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
01036         else
01037             pixmap = mi->iconSet()->pixmap();
01038         QRect pmrect(0, 0, pixmap.width(), pixmap.height() );
01039         QRect cr(x, y, maxpmw, h );
01040         pmrect.moveCenter( cr.center() );
01041         p->drawPixmap(pmrect.topLeft(), pixmap);
01042     }
01043 
01044     // draw check
01045     if(mi->isChecked() ) {
01046         drawCheckMark(p, x, y, maxpmw, h, itemg, act, !enabled );
01047     }
01048 
01049 
01050     // draw text
01051     int xm = maxpmw + 2;
01052     int xp = x + xm;
01053     int tw = w -xm - 2;
01054 
01055     p->setPen( enabled ? ( act ? g.highlightedText() : g.buttonText() ) :
01056                          g.mid() );
01057 
01058 
01059     if ( mi->custom() ) {
01060         p->save();
01061         mi->custom()->paint(p, g, act, enabled,
01062                               xp, y+1, tw, h-2 );
01063         p->restore();
01064     }else { // draw label
01065         QString text = mi->text();
01066         if (!text.isNull() ) {
01067             int t = text.find('\t');
01068             const int tflags = AlignVCenter | DontClip |
01069                                ShowPrefix |  SingleLine |
01070                                AlignLeft;
01071 
01072             if (t >= 0) {
01073                 int tabx = x + w - tabwidth - RIGHTBORDER -
01074                            ITEMHMARGIN - ITEMFRAME;
01075                 p->drawText(tabx, y+ITEMVMARGIN, tabwidth,
01076                             h-2*ITEMVMARGIN, tflags,
01077                             text.mid(t+1) );
01078                 text = text.left(t );
01079             }
01080 
01081             // draw left label
01082              p->drawText(xp, y+ITEMVMARGIN,
01083                          tw, h-2*ITEMVMARGIN,
01084                          tflags, text, t);
01085         }else if ( mi->pixmap() ) { // pixmap as label
01086             QPixmap pixmap = *mi->pixmap();
01087             if ( pixmap.depth() == 1 )
01088                 p->setBackgroundMode( OpaqueMode );
01089 
01090             int dx = ((w-pixmap.width() )  /2 ) +
01091                  ((w - pixmap.width()) %2 );
01092             p->drawPixmap(x+dx, y+ITEMFRAME, pixmap );
01093 
01094             if ( pixmap.depth() == 1 )
01095                 p->setBackgroundMode( TransparentMode );
01096         }
01097     }
01098 
01099     if ( mi->popup() ) { // draw submenu arrow
01100         int dim = (h-2*ITEMFRAME) / 2;
01101         drawArrow( p, RightArrow, false,
01102                    x+w-ARROWMARGIN-ITEMFRAME-dim,
01103                    y+h/2-dim/2, dim, dim, g, enabled );
01104     }
01105 }
01106 
01107   void
01108 WebStyle::drawFocusRect
01109 (
01110  QPainter * p,
01111  const QRect & r,
01112  const QColorGroup & g,
01113  const QColor * pen,
01114  bool atBorder
01115 )
01116 {
01117   p->save();
01118 
01119   if (0 != pen)
01120   p->setPen(0 == pen ? g.foreground() : *pen);
01121   p->setBrush(NoBrush);
01122 
01123   if (atBorder)
01124   {
01125     p->drawRect(QRect(r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2));
01126   }
01127   else
01128   {
01129     p->drawRect(r);
01130   }
01131 
01132   p->restore();
01133 }
01134 
01135   void
01136 WebStyle::drawPanel
01137 (
01138  QPainter * p,
01139  int x,
01140  int y,
01141  int w,
01142  int h,
01143  const QColorGroup & g,
01144  bool /* sunken */,
01145  int /* lineWidth */,
01146  const QBrush * fill
01147 )
01148 {
01149   p->save();
01150 
01151   p->setPen(g.dark());
01152 
01153   p->setBrush(0 == fill ? NoBrush : *fill);
01154 
01155   p->drawRect(x, y, w, h);
01156 
01157   p->restore();
01158 }
01159 
01160   void
01161 WebStyle::drawPopupPanel
01162 (
01163  QPainter * p,
01164  int x,
01165  int y,
01166  int w,
01167  int h,
01168  const QColorGroup & g,
01169  int /* lineWidth */,
01170  const QBrush * fill
01171 )
01172 {
01173   p->save();
01174 
01175   p->setPen(g.dark());
01176 
01177   p->setBrush(0 == fill ? NoBrush : *fill);
01178 
01179   p->drawRect(x, y, w, h);
01180 
01181   p->restore();
01182 }
01183 
01184   void
01185 WebStyle::drawSeparator
01186 (
01187  QPainter * p,
01188  int x,
01189  int y,
01190  int w,
01191  int h,
01192  const QColorGroup & g,
01193  bool /* sunken */,
01194  int /* lineWidth */,
01195  int /* midLineWidth */
01196 )
01197 {
01198   p->save();
01199 
01200   p->setPen(g.dark());
01201 
01202   if (w > h)
01203   {
01204     p->drawLine(x, y + h / 2, x + w, y + h / 2);
01205   }
01206   else
01207   {
01208     p->drawLine(x + w / 2, y, x + w / 2, y + h);
01209   }
01210 
01211   p->restore();
01212 }
01213 
01214   void
01215 WebStyle::drawTab
01216 (
01217  QPainter * p,
01218  const QTabBar * tabBar,
01219  QTab * tab,
01220  bool selected
01221 )
01222 {
01223   QRect r(tab->rect());
01224 
01225   QColorGroup g(tabBar->colorGroup());
01226 
01227   p->save();
01228 
01229   p->setPen(selected ? g.dark() : g.mid());
01230   p->fillRect(r, g.brush(QColorGroup::Background));
01231 
01232   switch (tabBar->shape())
01233   {
01234     case QTabBar::RoundedAbove:
01235     case QTabBar::TriangularAbove:
01236       p->drawLine(r.left(), r.top(), r.left(), r.bottom());
01237       p->drawLine(r.left(), r.top(), r.right(), r.top());
01238       p->drawLine(r.right(), r.top(), r.right(), r.bottom());
01239       if (!selected)
01240       {
01241         p->setPen(g.dark());
01242         p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());
01243       }
01244       break;
01245     case QTabBar::RoundedBelow:
01246     case QTabBar::TriangularBelow:
01247       if (!selected)
01248       {
01249         p->setPen(g.dark());
01250         p->drawLine(r.left(), r.top(), r.right(), r.top());
01251       }
01252       p->drawLine(r.left(), r.top(), r.left(), r.bottom());
01253       p->drawLine(r.left(), r.bottom(), r.right(), r.bottom());
01254       p->drawLine(r.right(), r.top(), r.right(), r.bottom());
01255       break;
01256   }
01257 
01258   p->restore();
01259 }
01260 
01261   void
01262 WebStyle::drawTabMask
01263 (
01264  QPainter * p,
01265  const QTabBar *,
01266  QTab * tab,
01267  bool
01268 )
01269 {
01270   p->fillRect(tab->rect(), Qt::color1);
01271 }
01272 
01273 
01274   int
01275 WebStyle::popupMenuItemHeight(bool, QMenuItem * i, const QFontMetrics & fm)
01276 {
01277   if (i->isSeparator())
01278     return 1;
01279 
01280   int h = 0;
01281 
01282   if (0 != i->pixmap())
01283   {
01284     h = i->pixmap()->height();
01285   }
01286 
01287   if (0 != i->iconSet())
01288   {
01289     h = QMAX
01290       (
01291        i->iconSet()->pixmap().height(),
01292        h
01293       );
01294   }
01295 
01296   h = QMAX(fm.height() + 4, h);
01297 
01298   h = QMAX(18, h);
01299 
01300   return h;
01301 
01302 }
01303 

Generated on Sat Nov 5 16:18:00 2005 for OPIE by  doxygen 1.4.2