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

fresh.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000-2002 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of the Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #include "fresh.h"
00022 #include <qpe/qpeapplication.h>
00023 #include <qpushbutton.h>
00024 #include <qpainter.h>
00025 #include <qfontmetrics.h>
00026 #include <qpalette.h>
00027 #include <qdrawutil.h>
00028 #include <qscrollbar.h>
00029 #include <qbutton.h>
00030 #include <qframe.h>
00031 #include <qtabbar.h>
00032 
00033 #define INCLUDE_MENUITEM_DEF
00034 #include <qmenudata.h>
00035 
00036 #define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)
00037 
00038 FreshStyle::FreshStyle()
00039 {
00040     setButtonMargin(2);
00041     setScrollBarExtent(13,13);
00042 }
00043 
00044 FreshStyle::~FreshStyle()
00045 {
00046 }
00047 
00048 int FreshStyle::buttonMargin() const
00049 {
00050     return 2;
00051 }
00052 
00053 QSize FreshStyle::scrollBarExtent() const
00054 {
00055     return QSize(13,13);
00056 }
00057 
00058 void FreshStyle::polish ( QPalette & )
00059 {
00060 }
00061 
00062 void FreshStyle::polish( QWidget *w )
00063 {
00064     if ( w->inherits( "QListBox" ) ||
00065          w->inherits( "QListView" ) ||
00066          w->inherits( "QPopupMenu" ) ||
00067          w->inherits( "QSpinBox" ) ) {
00068         QFrame *f = (QFrame *)w;
00069         f->setFrameShape( QFrame::StyledPanel );
00070         f->setLineWidth( 1 );
00071     }
00072 }
00073 
00074 void FreshStyle::unPolish( QWidget *w )
00075 {
00076     if ( w->inherits( "QListBox" ) ||
00077          w->inherits( "QListView" ) ||
00078          w->inherits( "QPopupMenu" ) ||
00079          w->inherits( "QSpinBox" ) ) {
00080         QFrame *f = (QFrame *)w;
00081         f->setFrameShape( QFrame::StyledPanel );
00082         f->setLineWidth( 2 );
00083     }
00084 }
00085 
00086 int FreshStyle::defaultFrameWidth() const
00087 {
00088     return 1;
00089 }
00090 
00091 void FreshStyle::drawPanel ( QPainter * p, int x, int y, int w, int h,
00092                             const QColorGroup &g, bool sunken, int lineWidth, const QBrush * fill )
00093 {
00094     qDrawShadePanel( p, QRect(x, y, w, h), g, sunken, lineWidth, fill );
00095 }
00096 
00097 void FreshStyle::drawButton( QPainter *p, int x, int y, int w, int h,
00098                                 const QColorGroup &cg, bool sunken, const QBrush* fill )
00099 {
00100     QPen oldPen = p->pen();
00101     int off = sunken ? 1 : 0;
00102     p->fillRect( x+1+off, y+1+off, w-3, h-3, fill?(*fill):cg.brush(QColorGroup::Button) );
00103 
00104     int x2 = x+w-1;
00105     int y2 = y+h-1;
00106 
00107     if ( sunken )
00108         p->setPen( cg.dark() );
00109     else
00110         p->setPen( cg.light() );
00111     p->drawLine( x, y, x, y2-1 );
00112     p->drawLine( x, y, x2, y );
00113 
00114     if ( sunken ) {
00115         p->setPen( white );
00116         p->drawLine( x+1, y+1, x+1, y2-2 );
00117         p->drawLine( x+1, y+1, x2-2, y+1 );
00118     }
00119 
00120     if ( sunken )
00121         p->setPen( cg.light() );
00122     else
00123         p->setPen( cg.dark() );
00124     p->drawLine( x2, y+1, x2, y2 );
00125     p->drawLine( x, y2, x2, y2 );
00126 
00127     if ( !sunken ) {
00128         p->setPen( white );
00129         p->drawLine( x2-1, y+1, x2-1, y2-1 );
00130         p->drawLine( x+1, y2-1, x2-1, y2-1 );
00131     }
00132     p->setPen( oldPen );
00133 }
00134 
00135 void FreshStyle::drawButtonMask ( QPainter * p, int x, int y, int w, int h )
00136 {
00137     p->fillRect( x, y, w, h, color1 );
00138 }
00139 
00140 void FreshStyle::drawBevelButton( QPainter *p, int x, int y, int w, int h,
00141                                 const QColorGroup &g, bool sunken, const QBrush* fill )
00142 {
00143     drawButton( p, x, y, w, h, g, sunken, fill );
00144 }
00145 
00146 QRect FreshStyle::comboButtonRect( int x, int y, int w, int h)
00147 {
00148     return QRect(x+1, y+1, w-2-14, h-2);
00149 }
00150 
00151 
00152 QRect FreshStyle::comboButtonFocusRect( int x, int y, int w, int h)
00153 {
00154     return QRect(x+2, y+2, w-4-14, h-4);
00155 }
00156 
00157 void FreshStyle::drawComboButton( QPainter *p, int x, int y, int w, int h,
00158                                      const QColorGroup &g, bool sunken,
00159                                      bool /*editable*/,
00160                                      bool enabled,
00161                                      const QBrush *fill )
00162 {
00163     drawBevelButton( p, x, y, w, h, g, FALSE, fill );
00164     drawBevelButton( p, x+w-14, y, 14, h, g, sunken, fill );
00165     drawArrow( p, QStyle::DownArrow, sunken,
00166                x+w-14+ 2, y+ 2, 14- 4, h- 4, g, enabled,
00167                &g.brush( QColorGroup::Button ) );
00168 
00169 }
00170 
00171 
00172 void FreshStyle::drawExclusiveIndicator ( QPainter * p, int x, int y, int w,
00173         int h, const QColorGroup &cg, bool on, bool down, bool enabled )
00174 {
00175     static const QCOORD pts1[] = {              // dark lines
00176         1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
00177     static const QCOORD pts4[] = {              // white lines
00178         2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
00179         11,4, 10,3, 10,2 };
00180     static const QCOORD pts5[] = {              // inner fill
00181         4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
00182 
00183     p->eraseRect( x, y, w, h );
00184     QPointArray a( QCOORDARRLEN(pts1), pts4 );
00185     a.translate( x, y );
00186     p->setPen( cg.dark() );
00187     p->drawPolyline( a );
00188     a.setPoints( QCOORDARRLEN(pts4), pts1 );
00189     a.translate( x, y );
00190     p->setPen( cg.light() );
00191     p->drawPolyline( a );
00192     a.setPoints( QCOORDARRLEN(pts5), pts5 );
00193     a.translate( x, y );
00194     QColor fillColor = ( down || !enabled ) ? cg.button() : cg.base();
00195     p->setPen( fillColor );
00196     p->setBrush( fillColor  ) ;
00197     p->drawPolygon( a );
00198     if ( on ) {
00199         p->setPen( NoPen );
00200         p->setBrush( cg.text() );
00201         p->drawRect( x+5, y+4, 2, 4 );
00202         p->drawRect( x+4, y+5, 4, 2 );
00203     }
00204 }
00205 
00206 void FreshStyle::drawIndicator ( QPainter * p, int x, int y, int w, int h,
00207         const QColorGroup &cg, int state, bool down, bool enabled )
00208 {
00209     QColorGroup mycg( cg );
00210     mycg.setBrush( QColorGroup::Button, QBrush() );
00211     QBrush fill;
00212     drawButton( p, x, y, w, h, mycg, TRUE, 0 );
00213     if ( down )
00214         fill = cg.brush( QColorGroup::Button );
00215     else
00216         fill = cg.brush( enabled ? QColorGroup::Base : QColorGroup::Background );
00217     mycg.setBrush( QColorGroup::Button, fill );
00218     p->fillRect( x+1, y+1, w-2, h-2, fill );
00219     if ( state != QButton::Off ) {
00220         QPointArray a( 7*2 );
00221         int i, xx, yy;
00222         xx = x+3;
00223         yy = y+5;
00224         for ( i=0; i<3; i++ ) {
00225             a.setPoint( 2*i,   xx, yy );
00226             a.setPoint( 2*i+1, xx, yy+2 );
00227             xx++; yy++;
00228         }
00229         yy -= 2;
00230         for ( i=3; i<7; i++ ) {
00231             a.setPoint( 2*i,   xx, yy );
00232             a.setPoint( 2*i+1, xx, yy+2 );
00233             xx++; yy--;
00234         }
00235         if ( state == QButton::NoChange ) {
00236             p->setPen( mycg.dark() );
00237         } else {
00238             p->setPen( mycg.text() );
00239         }
00240         p->drawLineSegments( a );
00241     }
00242 }
00243 
00244 #define HORIZONTAL      (sb->orientation() == QScrollBar::Horizontal)
00245 #define VERTICAL        !HORIZONTAL
00246 #define MOTIF_BORDER    2
00247 #define SLIDER_MIN      9 // ### motif says 6 but that's too small
00248 
00251 void FreshStyle::scrollBarMetrics( const QScrollBar* sb, int &sliderMin, int &sliderMax, int &sliderLength, int& buttonDim )
00252 {
00253     int maxLength;
00254     int length = HORIZONTAL ? sb->width()  : sb->height();
00255     int extent = HORIZONTAL ? sb->height() : sb->width();
00256 
00257     if ( length > (extent - 1)*2 )
00258         buttonDim = extent;
00259     else
00260         buttonDim = length/2 - 1;
00261 
00262     sliderMin = 0;
00263     maxLength  = length - buttonDim*2;
00264 
00265      if ( sb->maxValue() == sb->minValue() ) {
00266         sliderLength = maxLength;
00267      } else {
00268         sliderLength = (sb->pageStep()*maxLength)/
00269                         (sb->maxValue()-sb->minValue()+sb->pageStep());
00270         uint range = sb->maxValue()-sb->minValue();
00271         if ( sliderLength < SLIDER_MIN || range > INT_MAX/2 )
00272             sliderLength = SLIDER_MIN;
00273         if ( sliderLength > maxLength )
00274             sliderLength = maxLength;
00275      }
00276 
00277     sliderMax = sliderMin + maxLength - sliderLength;
00278 }
00279 
00282 QStyle::ScrollControl FreshStyle::scrollBarPointOver( const QScrollBar* sb, int sliderStart, const QPoint& p )
00283 {
00284         if ( !sb->rect().contains( p ) )
00285         return NoScroll;
00286     int sliderMin, sliderMax, sliderLength, buttonDim, pos;
00287     scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00288 
00289     if (sb->orientation() == QScrollBar::Horizontal)
00290         pos = p.x();
00291     else
00292         pos = p.y();
00293 
00294     if (pos < sliderStart)
00295         return SubPage;
00296     if (pos < sliderStart + sliderLength)
00297         return Slider;
00298     if (pos < sliderMax + sliderLength)
00299         return AddPage;
00300     if (pos < sliderMax + sliderLength + buttonDim)
00301         return SubLine;
00302     return AddLine;
00303 }
00304 
00307 void FreshStyle::drawScrollBarControls( QPainter* p, const QScrollBar* sb, int sliderStart, uint controls, uint activeControl )
00308 {
00309 #define ADD_LINE_ACTIVE ( activeControl == AddLine )
00310 #define SUB_LINE_ACTIVE ( activeControl == SubLine )
00311     QColorGroup g  = sb->colorGroup();
00312 
00313     int sliderMin, sliderMax, sliderLength, buttonDim;
00314     scrollBarMetrics( sb, sliderMin, sliderMax, sliderLength, buttonDim );
00315 
00316     if ( controls == (AddLine | SubLine | AddPage | SubPage | Slider | First | Last ) )
00317         p->fillRect( 0, 0, sb->width(), sb->height(), g.brush( QColorGroup::Mid ));
00318 
00319     if (sliderStart > sliderMax) { // sanity check
00320         sliderStart = sliderMax;
00321     }
00322 
00323     int dimB = buttonDim;
00324     QRect addB;
00325     QRect subB;
00326     QRect addPageR;
00327     QRect subPageR;
00328     QRect sliderR;
00329     int addX, addY, subX, subY;
00330     int length = HORIZONTAL ? sb->width()  : sb->height();
00331     int extent = HORIZONTAL ? sb->height() : sb->width();
00332 
00333     if ( HORIZONTAL ) {
00334         subY = addY = ( extent - dimB ) / 2;
00335         subX = length - dimB - dimB;
00336         addX = length - dimB;
00337     } else {
00338         subX = addX = ( extent - dimB ) / 2;
00339         subY = length - dimB - dimB;
00340         addY = length - dimB;
00341     }
00342 
00343     int sliderEnd = sliderStart + sliderLength;
00344     int sliderW = extent;
00345     if ( HORIZONTAL ) {
00346         subB.setRect( subX,subY+1,dimB,dimB-1 );
00347         addB.setRect( addX,addY+1,dimB,dimB-1 );
00348 
00349         subPageR.setRect( 0, 0,
00350                           sliderStart+1, sliderW );
00351         addPageR.setRect( sliderEnd-1, 0, subX - sliderEnd+1, sliderW );
00352         sliderR .setRect( sliderStart, 1, sliderLength, sliderW-1 );
00353 
00354     } else {
00355         subB.setRect( subX+1,subY,dimB-1,dimB );
00356         addB.setRect( addX+1,addY,dimB-1,dimB );
00357 
00358         subPageR.setRect( 0, 0, sliderW,
00359                           sliderStart+1 );
00360         addPageR.setRect( 0, sliderEnd-1, sliderW, subY - sliderEnd+1 );
00361         sliderR .setRect( 1, sliderStart, sliderW-1, sliderLength );
00362     }
00363 
00364     bool maxedOut = (sb->maxValue() == sb->minValue());
00365     if ( controls & AddLine ) {
00366         drawBevelButton( p, addB.x(), addB.y(),
00367                          addB.width(), addB.height(), g,
00368                          ADD_LINE_ACTIVE);
00369         p->setPen(g.shadow());
00370         drawArrow( p, VERTICAL ? DownArrow : RightArrow,
00371                    FALSE, addB.x()+2, addB.y()+2,
00372                    addB.width()-4, addB.height()-4, g, !maxedOut,
00373                                      &g.brush( QColorGroup::Button ));
00374     }
00375     if ( controls & SubLine ) {
00376         drawBevelButton( p, subB.x(), subB.y(),
00377                          subB.width(), subB.height(), g,
00378                          SUB_LINE_ACTIVE );
00379         p->setPen(g.shadow());
00380         drawArrow( p, VERTICAL ? UpArrow : LeftArrow,
00381                     FALSE, subB.x()+2, subB.y()+2,
00382                    subB.width()-4, subB.height()-4, g, !maxedOut,
00383                                      &g.brush( QColorGroup::Button ));
00384     }
00385 
00386 
00387     if ( controls & SubPage )
00388         p->fillRect( subPageR.x(), subPageR.y(), subPageR.width(),
00389                     subPageR.height(), g.brush( QColorGroup::Mid ));
00390     if ( controls & AddPage )
00391         p->fillRect( addPageR.x(), addPageR.y(), addPageR.width(),
00392                      addPageR.height(), g.brush( QColorGroup::Mid ));
00393     if ( controls & Slider ) {
00394         QPoint bo = p->brushOrigin();
00395         p->setBrushOrigin(sliderR.topLeft());
00396         drawBevelButton( p, sliderR.x(), sliderR.y(),
00397                          sliderR.width(), sliderR.height(), g,
00398                          FALSE, &g.brush( QColorGroup::Button ) );
00399         p->setBrushOrigin(bo);
00400         drawRiffles( p, sliderR.x(), sliderR.y(),
00401                      sliderR.width(), sliderR.height(), g, HORIZONTAL );
00402     }
00403 
00404     // ### perhaps this should not be able to accept focus if maxedOut?
00405     if ( sb->hasFocus() && (controls & Slider) )
00406         p->drawWinFocusRect( sliderR.x()+2, sliderR.y()+2,
00407                              sliderR.width()-5, sliderR.height()-5,
00408                              sb->backgroundColor() );
00409 
00410 }
00411 
00412 void FreshStyle::drawRiffles( QPainter* p,  int x, int y, int w, int h,
00413                       const QColorGroup &g, bool horizontal )
00414 {
00415     return;
00416     if (!horizontal) {
00417         if (h > 20) {
00418             y += (h-20)/2 ;
00419             h = 20;
00420         }
00421         if (h > 12) {
00422             int n = 3;
00423             int my = y+h/2-4;
00424             int i ;
00425             p->setPen(g.light());
00426             for (i=0; i<n; i++) {
00427                 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
00428             }
00429             p->setPen(g.dark());
00430             my++;
00431             for (i=0; i<n; i++) {
00432                 p->drawLine(x+2, my+3*i, x+w-4, my+3*i);
00433             }
00434         }
00435     }
00436     else {
00437         if (w > 20) {
00438             x += (w-20)/2 ;
00439             w = 20;
00440         }
00441         if (w > 12) {
00442             int n = 3;
00443             int mx = x+w/2-4;
00444             int i ;
00445             p->setPen(g.light());
00446             for (i=0; i<n; i++) {
00447                 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
00448             }
00449             p->setPen(g.dark());
00450             mx++;
00451             for (i=0; i<n; i++) {
00452                 p->drawLine(mx+3*i, y+2, mx + 3*i, y+h-4);
00453             }
00454         }
00455     }
00456 }
00457 
00458 int FreshStyle::sliderLength() const
00459 {
00460     return 12;
00461 }
00462 
00463 void FreshStyle::drawSlider( QPainter *p, int x, int y, int w, int h,
00464         const QColorGroup &g, Orientation o, bool tickAbove, bool tickBelow )
00465 {
00466     int a = tickAbove ? 3 : 0;
00467     int b = tickBelow ? 3 : 0;
00468 
00469     if ( o == Horizontal ) {
00470         drawBevelButton( p, x, y+a, w, h-a-b, g, FALSE, &g.brush( QColorGroup::Button ) );
00471         int xp = x + w/2;
00472         qDrawShadeLine( p, xp, y+a+2, xp, y+h-b-3, g );
00473     } else {
00474         drawBevelButton( p, x+a, y, w-a-b, h, g, FALSE, &g.brush( QColorGroup::Button ) );
00475         int yp = y + h/2;
00476         qDrawShadeLine( p, x+a+2, yp, x+w-b-3, yp, g );
00477     }
00478 }
00479 
00480 void FreshStyle::drawSliderMask ( QPainter * p, int x, int y, int w, int h,
00481         Orientation o, bool tickAbove, bool tickBelow )
00482 {
00483     int a = tickAbove ? 3 : 0;
00484     int b = tickBelow ? 3 : 0;
00485     if ( o == Horizontal )
00486         p->fillRect( x, y+a, w, h-a-b, color1 );
00487     else
00488         p->fillRect( x+a, y, w-a-b, h, color1 );
00489 }
00490 
00493 void FreshStyle::drawSliderGrooveMask( QPainter *p,
00494                                         int x, int y, int w, int h,
00495                                         const QColorGroup& , QCOORD c,
00496                                         Orientation orient )
00497 {
00498     if ( orient == Horizontal )
00499         p->fillRect( x, y + c - 2,  w, 4, color1 );
00500     else
00501         p->fillRect( x + c - 2, y, 4, h, color1 );
00502 }
00503 
00504 void FreshStyle::drawTab( QPainter *p, const QTabBar *tb, QTab *t, bool selected )
00505 {
00506     QRect r( t->rect() );
00507     if ( tb->shape()  == QTabBar::RoundedAbove ) {
00508         p->setPen( tb->colorGroup().light() );
00509         p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
00510         if ( r.left() == 0 )
00511             p->drawPoint( tb->rect().bottomLeft() );
00512         else {
00513             p->setPen( tb->colorGroup().light() );
00514             p->drawLine( r.left(), r.bottom(), r.right(), r.bottom() );
00515         }
00516 
00517         if ( selected ) {
00518             p->setPen( tb->colorGroup().background() );
00519             p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
00520             p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-2),
00521                          tb->colorGroup().brush( QColorGroup::Background ));
00522         } else {
00523             r.setRect( r.left() + 2, r.top() + 2,
00524                        r.width() - 4, r.height() - 2 );
00525             p->setPen( tb->colorGroup().button() );
00526             p->drawLine( r.left()+2, r.top()+1, r.right()-2, r.top()+1 );
00527             p->fillRect( QRect( r.left()+1, r.top()+2, r.width()-2, r.height()-3),
00528                          tb->colorGroup().brush( QColorGroup::Button ));
00529 
00530             //do shading; will not work for pixmap brushes
00531             QColor bg = tb->colorGroup().button();
00532             //      int h,s,v;
00533             //      bg.hsv( &h, &s, &v );
00534             int n = r.height()/2;
00535             int dark = 100;
00536             for ( int i = 1; i < n; i++ ) {
00537                 dark = (dark * (100+(i*15)/n) )/100;
00538                 p->setPen( bg.dark( dark ) );
00539                 int y = r.bottom()-n+i;
00540                 int x1 = r.left()+1;
00541                 int x2 = r.right()-1;
00542                 p->drawLine( x1, y, x2, y );
00543             }
00544         }
00545 
00546         p->setPen( tb->colorGroup().light() );
00547         p->drawLine( r.left(), r.bottom()-1, r.left(), r.top() + 2 );
00548         p->drawPoint( r.left()+1, r.top() + 1 );
00549         p->drawLine( r.left()+2, r.top(),
00550                      r.right() - 2, r.top() );
00551 
00552         p->setPen( tb->colorGroup().dark() );
00553         p->drawPoint( r.right() - 1, r.top() + 1 );
00554         p->drawLine( r.right(), r.top() + 2, r.right(), r.bottom() - 1);
00555     } else if ( tb->shape() == QTabBar::RoundedBelow ) {
00556         if ( selected ) {
00557             p->setPen( tb->colorGroup().background() );
00558             p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
00559             p->fillRect( QRect( r.left()+1, r.top(), r.width()-2, r.height()-2),
00560                          tb->palette().normal().brush( QColorGroup::Background ));
00561         } else {
00562             p->setPen( tb->colorGroup().dark() );
00563             p->drawLine( r.left(), r.top(),
00564                          r.right(), r.top() );
00565             r.setRect( r.left() + 2, r.top(),
00566                        r.width() - 4, r.height() - 2 );
00567             p->setPen( tb->colorGroup().button() );
00568             p->drawLine( r.left()+2, r.bottom()-1, r.right()-2, r.bottom()-1 );
00569             p->fillRect( QRect( r.left()+1, r.top()+1, r.width()-2, r.height()-3),
00570                          tb->palette().normal().brush( QColorGroup::Button ));
00571         }
00572 
00573         p->setPen( tb->colorGroup().dark() );
00574         p->drawLine( r.right(), r.top(),
00575                      r.right(), r.bottom() - 2 );
00576         p->drawPoint( r.right() - 1, r.bottom() - 1 );
00577         p->drawLine( r.right() - 2, r.bottom(),
00578                      r.left() + 2, r.bottom() );
00579 
00580         p->setPen( tb->colorGroup().light() );
00581         p->drawLine( r.left(), r.top()+1,
00582                      r.left(), r.bottom() - 2 );
00583         p->drawPoint( r.left() + 1, r.bottom() - 1 );
00584         if ( r.left() == 0 )
00585             p->drawPoint( tb->rect().topLeft() );
00586 
00587     } else {
00588         QCommonStyle::drawTab( p, tb, t, selected );
00589     }
00590 }
00591 
00592 static const int motifItemFrame         = 0;    // menu item frame width
00593 static const int motifSepHeight         = 2;    // separator item height
00594 static const int motifItemHMargin       = 1;    // menu item hor text margin
00595 static const int motifItemVMargin       = 2;    // menu item ver text margin
00596 static const int motifArrowHMargin      = 0;    // arrow horizontal margin
00597 static const int motifTabSpacing        = 12;   // space between text and tab
00598 static const int motifCheckMarkHMargin  = 1;    // horiz. margins of check mark
00599 static const int windowsRightBorder     = 8;    // right border on windows
00600 static const int windowsCheckMarkWidth  = 2;    // checkmarks width on windows
00601 
00604 int FreshStyle::extraPopupMenuItemWidth( bool checkable, int maxpmw, QMenuItem* mi, const QFontMetrics& /*fm*/ )
00605 {
00606 #ifndef QT_NO_MENUDATA
00607     int w = 2*motifItemHMargin + 2*motifItemFrame; // a little bit of border can never harm
00608 
00609     if ( mi->isSeparator() )
00610         return 10; // arbitrary
00611     else if ( mi->pixmap() )
00612         w += mi->pixmap()->width();     // pixmap only
00613 
00614     if ( !mi->text().isNull() ) {
00615         if ( mi->text().find('\t') >= 0 )       // string contains tab
00616             w += motifTabSpacing;
00617     }
00618 
00619     if ( maxpmw ) { // we have iconsets
00620         w += maxpmw;
00621         w += 6; // add a little extra border around the iconset
00622     }
00623 
00624     if ( checkable && maxpmw < windowsCheckMarkWidth ) {
00625         w += windowsCheckMarkWidth - maxpmw; // space for the checkmarks
00626     }
00627 
00628     if ( maxpmw > 0 || checkable ) // we have a check-column ( iconsets or checkmarks)
00629         w += motifCheckMarkHMargin; // add space to separate the columns
00630 
00631     w += windowsRightBorder; // windows has a strange wide border on the right side
00632 
00633     return w;
00634 #endif
00635 }
00636 
00639 int FreshStyle::popupMenuItemHeight( bool /*checkable*/, QMenuItem* mi, const QFontMetrics& fm )
00640 {
00641 #ifndef QT_NO_MENUDATA
00642     int h = 0;
00643     if ( mi->isSeparator() )                    // separator height
00644         h = motifSepHeight;
00645     else if ( mi->pixmap() )            // pixmap height
00646         h = mi->pixmap()->height() + 2*motifItemFrame;
00647     else                                        // text height
00648         h = fm.height() + 2*motifItemVMargin + 2*motifItemFrame - 1;
00649 
00650     if ( !mi->isSeparator() && mi->iconSet() != 0 ) {
00651         h = QMAX( h, mi->iconSet()->pixmap().height() + 2*motifItemFrame );
00652     }
00653     if ( mi->custom() )
00654         h = QMAX( h, mi->custom()->sizeHint().height() + 2*motifItemVMargin + 2*motifItemFrame ) - 1;
00655     return h;
00656 #endif
00657 }
00658 
00659 void FreshStyle::drawPopupMenuItem( QPainter* p, bool checkable, int maxpmw, int tab, QMenuItem* mi,
00660                                        const QPalette& pal,
00661                                        bool act, bool enabled, int x, int y, int w, int h)
00662 {
00663 #ifndef QT_NO_MENUDATA
00664     const QColorGroup & g = pal.active();
00665     bool dis      = !enabled;
00666     QColorGroup itemg = dis ? pal.disabled() : pal.active();
00667 
00668     if ( checkable )
00669         maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks
00670 
00671     int checkcol          =     maxpmw;
00672 
00673     if ( mi && mi->isSeparator() ) {                    // draw separator
00674         p->setPen( g.dark() );
00675         p->drawLine( x, y, x+w, y );
00676         p->setPen( g.light() );
00677         p->drawLine( x, y+1, x+w, y+1 );
00678         return;
00679     }
00680 
00681     QBrush fill = act? g.brush( QColorGroup::Highlight ) :
00682                             g.brush( QColorGroup::Button );
00683     p->fillRect( x, y, w, h, fill);
00684 
00685     if ( !mi )
00686         return;
00687 
00688     if ( mi->isChecked() ) {
00689         if ( act && !dis ) {
00690             qDrawShadePanel( p, x, y, checkcol, h,
00691                              g, TRUE, 1, &g.brush( QColorGroup::Button ) );
00692         } else {
00693             qDrawShadePanel( p, x, y, checkcol, h,
00694                              g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
00695         }
00696     } else if ( !act ) {
00697         p->fillRect(x, y, checkcol , h,
00698                     g.brush( QColorGroup::Button ));
00699     }
00700 
00701     if ( mi->iconSet() ) {              // draw iconset
00702         QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
00703         if (act && !dis )
00704             mode = QIconSet::Active;
00705     QPixmap pixmap;
00706     if ( mode == QIconSet::Disabled )
00707         pixmap = mi->iconSet()->pixmap( QIconSet::Automatic, mode );
00708     else
00709         pixmap = mi->iconSet()->pixmap();
00710         int pixw = pixmap.width();
00711         int pixh = pixmap.height();
00712         if ( act && !dis ) {
00713             if ( !mi->isChecked() )
00714                 qDrawShadePanel( p, x, y, checkcol, h, g, FALSE,  1, &g.brush( QColorGroup::Button ) );
00715         }
00716         QRect cr( x, y, checkcol, h );
00717         QRect pmr( 0, 0, pixw, pixh );
00718         pmr.moveCenter( cr.center() );
00719         p->setPen( itemg.text() );
00720         p->drawPixmap( pmr.topLeft(), pixmap );
00721 
00722         QBrush fill = act? g.brush( QColorGroup::Highlight ) :
00723                               g.brush( QColorGroup::Button );
00724         p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
00725     } else  if ( checkable ) {  // just "checking"...
00726         int mw = checkcol + motifItemFrame;
00727         int mh = h - 2*motifItemFrame;
00728         if ( mi->isChecked() ) {
00729             drawCheckMark( p, x + motifItemFrame + 2,
00730                            y+motifItemFrame, mw, mh, itemg, act, dis );
00731         }
00732     }
00733 
00734     p->setPen( act ? g.highlightedText() : g.buttonText() );
00735 
00736     QColor discol;
00737     if ( dis ) {
00738         discol = itemg.text();
00739         p->setPen( discol );
00740     }
00741 
00742     int xm = motifItemFrame + checkcol + motifItemHMargin;
00743 
00744     if ( mi->custom() ) {
00745         int m = motifItemVMargin;
00746         p->save();
00747         if ( dis && !act ) {
00748             p->setPen( g.light() );
00749             mi->custom()->paint( p, itemg, act, enabled,
00750                                  x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
00751             p->setPen( discol );
00752         }
00753         mi->custom()->paint( p, itemg, act, enabled,
00754                              x+xm, y+m, w-xm-tab+1, h-2*m );
00755         p->restore();
00756     }
00757     QString s = mi->text();
00758     if ( !s.isNull() ) {                        // draw text
00759         int t = s.find( '\t' );
00760         int m = motifItemVMargin;
00761         const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
00762         if ( t >= 0 ) {                         // draw tab text
00763             if ( dis && !act ) {
00764                 p->setPen( g.light() );
00765                 p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
00766                              y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
00767                 p->setPen( discol );
00768             }
00769             p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
00770                          y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
00771         }
00772         if ( dis && !act ) {
00773             p->setPen( g.light() );
00774             p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
00775             p->setPen( discol );
00776         }
00777         p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
00778     } else if ( mi->pixmap() ) {                        // draw pixmap
00779         QPixmap *pixmap = mi->pixmap();
00780         if ( pixmap->depth() == 1 )
00781             p->setBackgroundMode( OpaqueMode );
00782         p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
00783         if ( pixmap->depth() == 1 )
00784             p->setBackgroundMode( TransparentMode );
00785     }
00786     if ( mi->popup() ) {                        // draw sub menu arrow
00787         int dim = (h-2*motifItemFrame) / 2;
00788         if ( act ) {
00789             if ( !dis )
00790                 discol = white;
00791             QColorGroup g2( discol, g.highlight(),
00792                             white, white,
00793                             dis ? discol : white,
00794                             discol, white );
00795             drawArrow( p, RightArrow, FALSE,
00796                                x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,
00797                                dim, dim, g2, TRUE );
00798         } else {
00799             drawArrow( p, RightArrow,
00800                                FALSE,
00801                                x+w - motifArrowHMargin - motifItemFrame - dim,  y+h/2-dim/2,
00802                                dim, dim, g, mi->isEnabled() );
00803         }
00804     }
00805 #endif
00806 }
00807 
00808 //===========================================================================
00809 
00810 FreshStyleImpl::FreshStyleImpl()
00811     : fresh(0)
00812 {
00813 }
00814 
00815 FreshStyleImpl::~FreshStyleImpl()
00816 {
00817     // We do not delete the style because Qt does that when a new style
00818     // is set.
00819 }
00820 
00821 QStyle *FreshStyleImpl::style()
00822 {
00823     if ( !fresh )
00824         fresh = new FreshStyle();
00825     return fresh;
00826 }
00827 
00828 QString FreshStyleImpl::name() const
00829 {
00830     return QString("Fresh");
00831 }
00832 
00833 QRESULT FreshStyleImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
00834 {
00835     *iface = 0;
00836     if ( uuid == IID_QUnknown )
00837         *iface = this;
00838     else if ( uuid == IID_Style )
00839         *iface = this;
00840     else
00841         return QS_FALSE;
00842 
00843     if ( *iface )
00844         (*iface)->addRef();
00845     return QS_OK;
00846 }
00847 
00848 Q_EXPORT_INTERFACE()
00849 {
00850     Q_CREATE_INSTANCE( FreshStyleImpl )
00851 }
00852 

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