• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KStyles

highcolor.cpp

Go to the documentation of this file.
00001 /*
00002  * KDE3 HighColor Style (version 1.0)
00003  * Copyright (C) 2001-2002 Karol Szwed      <gallium@kde.org>
00004  *           (C) 2001-2002 Fredrik Höglund  <fredrik@kde.org> 
00005  *
00006  * Drawing routines adapted from the KDE2 HCStyle,
00007  * Copyright (C) 2000 Daniel M. Duley       <mosfet@kde.org>
00008  *           (C) 2000 Dirk Mueller          <mueller@kde.org>
00009  *           (C) 2001 Martijn Klingens      <klingens@kde.org>
00010  *
00011  * This library is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU Library General Public
00013  * License version 2 as published by the Free Software Foundation.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public License
00021  * along with this library; see the file COPYING.LIB.  If not, write to
00022  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00023  * Boston, MA 02110-1301, USA.
00024  */
00025 
00026 #include "highcolor.h"
00027 #include "highcolor.moc"
00028 
00029 #include <QtGui/qdrawutil.h>
00030 #include <QtGui/QPainter>
00031 #include <Qt3Support/Q3PointArray>
00032 #include <QtGui/QStylePlugin>
00033 
00034 #include <QtGui/QComboBox>
00035 #include <Qt3Support/Q3Header>
00036 #include <QtGui/QMenuBar>
00037 #include <QtGui/QPushButton>
00038 #include <QtGui/QScrollBar>
00039 #include <QtGui/QSlider>
00040 #include <QtGui/QTabBar>
00041 #include <QtGui/QToolButton>
00042 #include <Qt3Support/Q3ToolBar>
00043 #include <QtGui/QMenu>
00044 #include <Qt3Support/Q3IntDict>
00045 
00046 #include <kdrawutil.h>
00047 #include <kpixmapeffect.h>
00048 
00049 #include "bitmaps.h"
00050 
00051 
00052 // -- Style Plugin Interface -------------------------
00053 class HighColorStylePlugin : public QStylePlugin
00054 {
00055     public:
00056         HighColorStylePlugin() {}
00057         ~HighColorStylePlugin() {}
00058 
00059         QStringList keys() const
00060         {
00061             return QStringList() << "HighColor" << "Default" << "B3";
00062         }
00063 
00064         QStyle* create( const QString& key )
00065         {
00066             if ( key == "highcolor" )
00067                 return new HighColorStyle( HighColorStyle::HighColor );
00068             
00069             else if ( key == "default" )
00070                 return new HighColorStyle( HighColorStyle::Default );
00071 
00072             else if ( key == "b3" )
00073                 return new HighColorStyle( HighColorStyle::B3 );
00074             
00075             return 0;
00076         }
00077 };
00078 
00079 Q_EXPORT_PLUGIN( HighColorStylePlugin )
00080 // ---------------------------------------------------
00081 
00082 
00083 static QBitmap lightBmp;
00084 static QBitmap grayBmp;
00085 static QBitmap dgrayBmp;
00086 static QBitmap centerBmp;
00087 static QBitmap maskBmp;
00088 static QBitmap xBmp;
00089 static Q3IntDict<GradientSet> gDict;
00090 
00091 static const int itemFrame       = 1;
00092 static const int itemHMargin     = 3;
00093 static const int itemVMargin     = 0;
00094 static const int arrowHMargin    = 6;
00095 static const int rightBorder     = 12;
00096 static const char* kdeToolbarWidget = "kde toolbar widget";
00097 
00098 // ---------------------------------------------------------------------------
00099 
00100 GradientSet::GradientSet(const QColor &baseColor)
00101 {
00102     c = baseColor;
00103     for(int i=0; i < GradientCount; i++)
00104         gradients[i] = NULL;
00105 }
00106 
00107 
00108 GradientSet::~GradientSet()
00109 {
00110     for(int i=0; i < GradientCount; i++)
00111         if(gradients[i])
00112             delete gradients[i];
00113 }
00114 
00115 
00116 KPixmap* GradientSet::gradient(GradientType type)
00117 {
00118     if (gradients[type])
00119         return gradients[type];
00120 
00121     switch(type)
00122     {
00123         case VSmall: {
00124             gradients[VSmall] = new KPixmap;
00125             gradients[VSmall]->resize(18, 24);
00126             KPixmapEffect::gradient(*gradients[VSmall], c.light(110), c.dark(110),
00127                                             KPixmapEffect::VerticalGradient);
00128             break;
00129         }
00130 
00131         case VMed: {
00132             gradients[VMed] = new KPixmap;
00133             gradients[VMed]->resize(18, 34);
00134             KPixmapEffect::gradient(*gradients[VMed], c.light(110), c.dark(110),
00135                                             KPixmapEffect::VerticalGradient);
00136             break;
00137         }
00138 
00139         case VLarge: {
00140             gradients[VLarge] = new KPixmap;
00141             gradients[VLarge]->resize(18, 64);
00142             KPixmapEffect::gradient(*gradients[VLarge], c.light(110), c.dark(110),
00143                                             KPixmapEffect::VerticalGradient);
00144             break;
00145         }
00146 
00147         case HMed: {
00148             gradients[HMed] = new KPixmap;
00149             gradients[HMed]->resize(34, 18);
00150             KPixmapEffect::gradient(*gradients[HMed], c.light(110), c.dark(110),
00151                                             KPixmapEffect::HorizontalGradient);
00152             break;
00153         }
00154 
00155         case HLarge: {
00156             gradients[HLarge] = new KPixmap;
00157             gradients[HLarge]->resize(52, 18);
00158             KPixmapEffect::gradient(*gradients[HLarge], c.light(110), c.dark(110),
00159                                             KPixmapEffect::HorizontalGradient);
00160             break;
00161         }
00162 
00163         default:
00164             break;
00165     }
00166     return(gradients[type]);
00167 }
00168 
00169 
00170 
00171 // ---------------------------------------------------------------------------
00172 
00173 HighColorStyle::HighColorStyle( StyleType styleType ) 
00174     : KStyle( AllowMenuTransparency | FilledFrameWorkaround, ThreeButtonScrollBar )
00175 {
00176     type = styleType;
00177     highcolor = (type == HighColor && QPixmap::defaultDepth() > 8);
00178     gDict.setAutoDelete(true);
00179     hoverWidget = 0L;
00180     selectionBackground = false;
00181 }
00182 
00183 
00184 HighColorStyle::~HighColorStyle()
00185 {
00186 }
00187 
00188 
00189 void HighColorStyle::polish(QWidget* widget)
00190 {
00191     // Put in order of highest occurrence to maximise hit rate
00192     if (widget->inherits("QPushButton")) {
00193         widget->installEventFilter(this);
00194     } else if (widget->inherits("QMenuBar") || widget->inherits("QPopupMenu")) {
00195         widget->setBackgroundMode(Qt::NoBackground);
00196     } else if (type == HighColor && widget->inherits("QToolBarExtensionWidget")) {
00197         widget->installEventFilter(this);
00198     } else if ( !qstrcmp( widget->name(), kdeToolbarWidget) ) {
00199         widget->setBackgroundMode( Qt::NoBackground );  // We paint the whole background.
00200         widget->installEventFilter(this);
00201     } else if (widget->inherits("QToolBoxButton")) {
00202         QFont font = widget->font();
00203         font.setBold(true);
00204         widget->setFont(font);
00205     }
00206 
00207     KStyle::polish( widget );
00208 }
00209 
00210 
00211 void HighColorStyle::unPolish(QWidget* widget)
00212 {
00213     if (widget->inherits("QPushButton")) {
00214         widget->removeEventFilter(this);
00215     }
00216     else if (widget->inherits("QMenuBar") || widget->inherits("QPopupMenu")) {
00217         widget->setBackgroundMode(Qt::PaletteBackground);
00218     } else if (type == HighColor && widget->inherits("QToolBarExtensionWidget")) {
00219         widget->removeEventFilter(this);
00220     } else if ( !qstrcmp( widget->name(), kdeToolbarWidget) ) {
00221         widget->removeEventFilter(this);
00222         widget->setBackgroundMode( Qt::PaletteBackground );
00223     }
00224 
00225     KStyle::unPolish( widget );
00226 }
00227 
00228 
00229 /* reimp. */
00230 void HighColorStyle::renderMenuBlendPixmap( KPixmap& pix, const QColorGroup &cg,
00231         const QMenu* /* popup */ ) const
00232 {
00233     QColor col = cg.button();
00234 
00235 #ifdef Q_WS_X11 // Only draw menu gradients on TrueColor, X11 visuals
00236     if ( QPaintDevice::x11AppDepth() >= 24 )
00237         KPixmapEffect::gradient( pix, col.light(120), col.dark(115),
00238                 KPixmapEffect::HorizontalGradient );
00239     else
00240 #endif
00241     pix.fill( col );
00242 }
00243 
00244 
00245 // This function draws primitive elements as well as their masks.
00246 void HighColorStyle::drawPrimitive( PrimitiveElement pe,
00247                                     QPainter *p,
00248                                     const QRect &r,
00249                                     const QColorGroup &cg,
00250                                     SFlags flags,
00251                                     const QStyleOption& opt ) const
00252 {
00253     bool down = flags & Style_Down;
00254     bool on   = flags & Style_On;
00255 
00256     switch(pe)
00257     {
00258         // BUTTONS
00259         // -------------------------------------------------------------------
00260         case PE_ButtonDefault: {
00261             if ( type != HighColor ) {
00262                 int x1, y1, x2, y2;
00263                 r.getCoords( &x1, &y1, &x2, &y2 );
00264                 
00265                 // Button default indicator
00266                 p->setPen( cg.shadow() );
00267                 p->drawLine( x1+1, y1, x2-1, y1 );
00268                 p->drawLine( x1, y1+1, x1, y2-1 );
00269                 p->drawLine( x1+1, y2, x2-1, y2 );
00270                 p->drawLine( x2, y1+1, x2, y2-1 );
00271             }
00272             break;
00273         }
00274             
00275         case PE_ButtonDropDown:
00276         case PE_ButtonTool: {
00277             bool sunken = on || down;
00278             int  x,y,w,h;
00279             r.rect(&x, &y, &w, &h);
00280             int x2 = x+w-1;
00281             int y2 = y+h-1;
00282             QPen oldPen = p->pen();
00283 
00284             // Outer frame (round style)
00285             p->setPen(cg.shadow());
00286             p->drawLine(x+1,y,x2-1,y);
00287             p->drawLine(x,y+1,x,y2-1);
00288             p->drawLine(x+1,y2,x2-1,y2);
00289             p->drawLine(x2,y+1,x2,y2-1);
00290 
00291             // Bevel
00292             p->setPen(sunken ? cg.mid() : cg.light());
00293             p->drawLine(x+1, y+1, x2-1, y+1);
00294             p->drawLine(x+1, y+1, x+1, y2-1);
00295             p->setPen(sunken ? cg.light() : cg.mid());
00296             p->drawLine(x+2, y2-1, x2-1, y2-1);
00297             p->drawLine(x2-1, y+2, x2-1, y2-1);
00298 
00299             p->fillRect(x+2, y+2, w-4, h-4, cg.button());
00300 
00301             p->setPen( oldPen );
00302             break;
00303         }
00304 
00305         // PUSH BUTTON
00306         // -------------------------------------------------------------------
00307         case PE_ButtonCommand: {
00308             bool sunken = on || down;
00309             bool flat = !(flags & (Style_Raised | Style_Sunken));
00310             int  x, y, w, h;
00311             r.rect(&x, &y, &w, &h);
00312             int x2 = x+w-1;
00313             int y2 = y+h-1;
00314 
00315             if ( sunken )
00316                 kDrawBeButton( p, x, y, w, h, cg, true,
00317                         &cg.brush(QPalette::Mid) );
00318 
00319             else if ( flags & Style_MouseOver && !flat ) {
00320                 QBrush brush(cg.button().light(110));
00321                 kDrawBeButton( p, x, y, w, h, cg, false, &brush );
00322             }
00323 
00324             // "Flat" button
00325             else if ( flat ) {
00326                 if ( flags & Style_MouseOver )
00327                     p->fillRect(r, cg.button().light(110));
00328                 else
00329                     renderGradient(p, QRect(x, y, w-1, h-1),
00330                                     cg.button(), false);
00331 
00332                 p->setPen(cg.button().light(75));
00333                 p->drawLine(x, y, x2, y);
00334                 p->drawLine(x, y, x, y2);
00335                 p->drawLine(x, y2, x2, y2);
00336                 p->drawLine(x2, y, x2, y2);
00337             }      
00338 
00339             else if( highcolor )
00340             {
00341                 int x2 = x+w-1;
00342                 int y2 = y+h-1;
00343                 p->setPen(cg.shadow());
00344                 p->drawLine(x+1, y, x2-1, y);
00345                 p->drawLine(x+1, y2, x2-1, y2);
00346                 p->drawLine(x, y+1, x, y2-1);
00347                 p->drawLine(x2, y+1, x2, y2-1);
00348 
00349                 p->setPen(cg.light());
00350                 p->drawLine(x+2, y+2, x2-1, y+2);
00351                 p->drawLine(x+2, y+3, x2-2, y+3);
00352                 p->drawLine(x+2, y+4, x+2, y2-1);
00353                 p->drawLine(x+3, y+4, x+3, y2-2);
00354 
00355                 p->setPen(cg.mid());
00356                 p->drawLine(x2-1, y+2, x2-1, y2-1);
00357                 p->drawLine(x+2, y2-1, x2-1, y2-1);
00358 
00359                 p->drawLine(x+1, y+1, x2-1, y+1);
00360                 p->drawLine(x+1, y+2, x+1, y2-1);
00361                 p->drawLine(x2-2, y+3, x2-2, y2-2);
00362 
00363                 renderGradient(p, QRect(x+4, y+4, w-6, h-6),
00364                                 cg.button(), false);
00365             } else
00366                 kDrawBeButton(p, x, y, w, h, cg, false,
00367                               &cg.brush(QPalette::Button));
00368             break;
00369         }
00370 
00371 
00372         // BEVELS
00373         // -------------------------------------------------------------------
00374         case PE_ButtonBevel: {
00375             int x,y,w,h;
00376             r.rect(&x, &y, &w, &h);
00377             bool sunken = on || down;
00378             int x2 = x+w-1;
00379             int y2 = y+h-1;
00380 
00381             // Outer frame
00382             p->setPen(cg.shadow());
00383             p->drawRect(r);
00384 
00385             // Bevel
00386             p->setPen(sunken ? cg.mid() : cg.light());
00387             p->drawLine(x+1, y+1, x2-1, y+1);
00388             p->drawLine(x+1, y+1, x+1, y2-1);
00389             p->setPen(sunken ? cg.light() : cg.mid());
00390             p->drawLine(x+2, y2-1, x2-1, y2-1);
00391             p->drawLine(x2-1, y+2, x2-1, y2-1);
00392 
00393             if (w > 4 && h > 4) {
00394                 if (sunken)
00395                     p->fillRect(x+2, y+2, w-4, h-4, cg.button());
00396                 else
00397                     renderGradient( p, QRect(x+2, y+2, w-4, h-4),
00398                                     cg.button(), flags & Style_Horizontal );
00399             }
00400             break;
00401         }
00402 
00403 
00404         // FOCUS RECT
00405         // -------------------------------------------------------------------
00406         case PE_FocusRect: {
00407             p->drawWinFocusRect( r );
00408             break;
00409         }
00410 
00411 
00412         // HEADER SECTION
00413         // -------------------------------------------------------------------
00414         case PE_HeaderSection: {
00415             // Temporary solution for the proper orientation of gradients.
00416             bool horizontal = true;
00417             if (p && p->device()->devType() == QInternal::Widget) {
00418                 Q3Header* hdr = dynamic_cast<Q3Header*>(p->device());
00419                 if (hdr)
00420                     horizontal = hdr->orientation() == Qt::Horizontal;
00421             }
00422 
00423             int x,y,w,h;
00424             r.rect(&x, &y, &w, &h);
00425             bool sunken = on || down;
00426             int x2 = x+w-1;
00427             int y2 = y+h-1;
00428             QPen oldPen = p->pen();
00429 
00430             // Bevel
00431             p->setPen(sunken ? cg.mid() : cg.light());
00432             p->drawLine(x, y, x2-1, y);
00433             p->drawLine(x, y, x, y2-1);
00434             p->setPen(sunken ? cg.light() : cg.mid());
00435             p->drawLine(x+1, y2-1, x2-1, y2-1);
00436             p->drawLine(x2-1, y+1, x2-1, y2-1);
00437             p->setPen(cg.shadow());
00438             p->drawLine(x, y2, x2, y2);
00439             p->drawLine(x2, y, x2, y2);
00440 
00441             if (sunken)
00442                 p->fillRect(x+1, y+1, w-3, h-3, cg.button());
00443             else
00444                 renderGradient( p, QRect(x+1, y+1, w-3, h-3),
00445                                 cg.button(), !horizontal );
00446             p->setPen( oldPen );
00447             break;
00448         }
00449 
00450 
00451         // SCROLLBAR
00452         // -------------------------------------------------------------------
00453         case PE_ScrollBarSlider: {
00454             // Small hack to ensure scrollbar gradients are drawn the right way.
00455             flags ^= Style_Horizontal;
00456 
00457             drawPrimitive(PE_ButtonBevel, p, r, cg, flags | Style_Enabled | Style_Raised);
00458 
00459             // Draw a scrollbar riffle (note direction after above changes)
00460             if ( type != B3 ) {
00461                 
00462                 // HighColor & Default scrollbar
00463                 if (flags & Style_Horizontal) {
00464                     if (r.height() >= 15) {
00465                         int x = r.x()+3;
00466                         int y = r.y() + (r.height()-7)/2;
00467                         int x2 = r.right()-3;
00468                         p->setPen(cg.light());
00469                         p->drawLine(x, y, x2, y);
00470                         p->drawLine(x, y+3, x2, y+3);
00471                         p->drawLine(x, y+6, x2, y+6);
00472 
00473                         p->setPen(cg.mid());
00474                         p->drawLine(x, y+1, x2, y+1);
00475                         p->drawLine(x, y+4, x2, y+4);
00476                         p->drawLine(x, y+7, x2, y+7);
00477                     }
00478                 } else {
00479                     if (r.width() >= 15) {
00480                         int y = r.y()+3;
00481                         int x = r.x() + (r.width()-7)/2;
00482                         int y2 = r.bottom()-3;
00483                         p->setPen(cg.light());
00484                         p->drawLine(x, y, x, y2);
00485                         p->drawLine(x+3, y, x+3, y2);
00486                         p->drawLine(x+6, y, x+6, y2);
00487 
00488                         p->setPen(cg.mid());
00489                         p->drawLine(x+1, y, x+1, y2);
00490                         p->drawLine(x+4, y, x+4, y2);
00491                         p->drawLine(x+7, y, x+7, y2);
00492                     }
00493                 }
00494             } else {
00495                 
00496                 // B3 scrollbar
00497                 if (flags & Style_Horizontal) {
00498                     int buttons = 0;
00499                     
00500                     if (r.height() >= 36) buttons = 3;
00501                     else if (r.height() >=24) buttons = 2;
00502                     else if (r.height() >=16) buttons = 1;
00503                     
00504                     int x = r.x() + (r.width()-7) / 2;
00505                     int y = r.y() + (r.height() - (buttons * 5) -
00506                             (buttons-1)) / 2;
00507                     int x2 = x + 7;
00508                     
00509                     for ( int i=0; i<buttons; i++, y+=6 )
00510                     {
00511                         p->setPen( cg.mid() );
00512                         p->drawLine( x+1, y, x2-1, y );
00513                         p->drawLine( x, y+1, x, y+3 );
00514                         p->setPen( cg.light() );
00515                         p->drawLine( x+1, y+1, x2-1, y+1 );
00516                         p->drawLine( x+1, y+1, x+1, y+3 );
00517                         p->setPen( cg.dark() );
00518                         p->drawLine( x+1, y+4, x2-1, y+4 );
00519                         p->drawLine( x2, y+1, x2, y+3 );
00520                     }
00521                 } else {
00522                     int buttons = 0;
00523                     
00524                     if (r.width() >= 36) buttons = 3;
00525                     else if (r.width() >=24) buttons = 2;
00526                     else if (r.width() >=16) buttons = 1;
00527                     
00528                     int x = r.x() + (r.width() - (buttons * 5) -
00529                             (buttons-1)) / 2;
00530                     int y = r.y() + (r.height()-7) / 2;
00531                     int y2 = y + 7;
00532                     
00533                     for ( int i=0; i<buttons; i++, x+=6 )
00534                     {
00535                         p->setPen( cg.mid() );
00536                         p->drawLine( x+1, y, x+3, y );
00537                         p->drawLine( x, y+1, x, y2-1 );
00538                         p->setPen( cg.light() );
00539                         p->drawLine( x+1, y+1, x+3, y+1 );
00540                         p->drawLine( x+1, y+1, x+1, y2-1 );
00541                         p->setPen( cg.dark() );
00542                         p->drawLine( x+1, y2, x+3, y2 );
00543                         p->drawLine( x+4, y+1, x+4, y2-1 );
00544                     }
00545                 }
00546             }
00547             break;
00548         }
00549 
00550 
00551         case PE_ScrollBarAddPage:
00552         case PE_ScrollBarSubPage: {
00553             int x, y, w, h;
00554             r.rect(&x, &y, &w, &h);
00555             int x2 = x+w-1;
00556             int y2 = y+h-1;
00557 
00558             if ( type != B3 ) {
00559                 // HighColor & Default scrollbar
00560                 
00561                 p->setPen(cg.shadow());
00562                 
00563                 if (flags & Style_Horizontal) {
00564                     p->drawLine(x, y, x2, y);
00565                     p->drawLine(x, y2, x2, y2);
00566                     renderGradient(p, QRect(x, y+1, w, h-2),
00567                                 cg.mid(), false);
00568                 } else {
00569                     p->drawLine(x, y, x, y2);
00570                     p->drawLine(x2, y, x2, y2);
00571                     renderGradient(p, QRect(x+1, y, w-2, h),
00572                                 cg.mid(), true);
00573                 }   
00574             } else {
00575                 // B3 scrollbar
00576                 
00577                 p->setPen( cg.mid() );
00578                 
00579                 if (flags & Style_Horizontal) {
00580                     p->drawLine(x, y, x2, y);
00581                     p->drawLine(x, y2, x2, y2);
00582                     p->fillRect( QRect(x, y+1, w, h-2), 
00583                             flags & Style_Down ? cg.button() : cg.midlight() );
00584                 } else {
00585                     p->drawLine(x, y, x, y2);
00586                     p->drawLine(x2, y, x2, y2);
00587                     p->fillRect( QRect(x+1, y, w-2, h), 
00588                             flags & Style_Down ? cg.button() : cg.midlight() );
00589                 }
00590             }
00591             break;
00592         }
00593 
00594 
00595         case PE_ScrollBarAddLine: {
00596             drawPrimitive( PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) |
00597                     ((flags & Style_Down) ? Style_Down : Style_Raised) );
00598 
00599             drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown),
00600                     p, r, cg, flags );
00601             break;
00602         }
00603 
00604 
00605         case PE_ScrollBarSubLine: {
00606             drawPrimitive( PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) |
00607                     ((flags & Style_Down) ? Style_Down : Style_Raised) );
00608 
00609             drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp),
00610                     p, r, cg, flags );
00611             break;
00612         }
00613 
00614 
00615         // CHECKBOX (indicator)
00616         // -------------------------------------------------------------------
00617         case PE_Indicator: {
00618             
00619             bool enabled  = flags & Style_Enabled;
00620             bool nochange = flags & Style_NoChange;
00621             
00622             if (xBmp.isNull()) {
00623                 xBmp = QBitmap(7, 7, x_bits, true);
00624                 xBmp.setMask(xBmp);
00625             }
00626 
00627             int x,y,w,h;
00628             x=r.x(); y=r.y(); w=r.width(); h=r.height();
00629             int x2 = x+w-1;
00630             int y2 = y+h-1;
00631 
00632             p->setPen(cg.mid());
00633             p->drawLine(x, y, x2, y);
00634             p->drawLine(x, y, x, y2);
00635 
00636             p->setPen(cg.light());
00637             p->drawLine(x2, y+1, x2, y2);
00638             p->drawLine(x+1, y2, x2, y2);
00639 
00640             p->setPen(cg.shadow());
00641             p->drawLine(x+1, y+1, x2-1, y+1);
00642             p->drawLine(x+1, y+1, x+1, y2-1);
00643 
00644             p->setPen(cg.midlight());
00645             p->drawLine(x2-1, y+2, x2-1, y2-1);
00646             p->drawLine(x+2, y2-1, x2-1, y2-1);
00647 
00648             if ( enabled )
00649                 p->fillRect(x+2, y+2, w-4, h-4, 
00650                         down ? cg.button(): cg.base());
00651             else
00652                 p->fillRect(x+2, y+2, w-4, h-4, cg.background());
00653             
00654             if (!(flags & Style_Off)) {
00655                 if (on) {
00656                     p->setPen(nochange ? cg.dark() : cg.text());
00657                     p->drawPixmap(x+3, y+3, xBmp);
00658                 }
00659                 else {
00660                     p->setPen(cg.shadow());
00661                     p->drawRect(x+2, y+2, w-4, h-4);
00662                     p->setPen(nochange ? cg.text() : cg.dark());
00663                     p->drawLine(x+3, (y+h)/2-2, x+w-4, (y+h)/2-2);
00664                     p->drawLine(x+3, (y+h)/2, x+w-4, (y+h)/2);
00665                     p->drawLine(x+3, (y+h)/2+2, x+w-4, (y+h)/2+2);
00666                 }
00667             }
00668             break;
00669         }
00670 
00671 
00672         // RADIOBUTTON (exclusive indicator)
00673         // -------------------------------------------------------------------
00674         case PE_ExclusiveIndicator: {
00675             
00676             if (lightBmp.isNull()) {
00677                 lightBmp  = QBitmap(13, 13, radiooff_light_bits,  true);
00678                 grayBmp   = QBitmap(13, 13, radiooff_gray_bits,   true);
00679                 dgrayBmp  = QBitmap(13, 13, radiooff_dgray_bits,  true);
00680                 centerBmp = QBitmap(13, 13, radiooff_center_bits, true);
00681                 centerBmp.setMask( centerBmp );
00682             }
00683 
00684             // Bevel
00685             kColorBitmaps(p, cg, r.x(), r.y(), &lightBmp , &grayBmp,
00686                           NULL, &dgrayBmp);
00687             
00688             // The center fill of the indicator (grayed out when disabled)
00689             if ( flags & Style_Enabled )
00690                 p->setPen( down ? cg.button() : cg.base() );
00691             else
00692                 p->setPen( cg.background() );
00693             p->drawPixmap( r.x(), r.y(), centerBmp );
00694 
00695             // Indicator "dot"
00696             if ( on ) {
00697                 QColor color = flags & Style_NoChange ?
00698                     cg.dark() : cg.text();
00699                 
00700                 p->setPen(color);
00701                 p->drawLine(5, 4, 7, 4);
00702                 p->drawLine(4, 5, 4, 7);
00703                 p->drawLine(5, 8, 7, 8);
00704                 p->drawLine(8, 5, 8, 7);
00705                 p->fillRect(5, 5, 3, 3, color);
00706             }
00707 
00708             break;
00709         }
00710 
00711 
00712         // RADIOBUTTON (exclusive indicator) mask
00713         // -------------------------------------------------------------------
00714         case PE_ExclusiveIndicatorMask: {
00715             if (maskBmp.isNull()) {
00716                 maskBmp = QBitmap(13, 13, radiomask_bits, true);
00717                 maskBmp.setMask(maskBmp);
00718             }
00719                 
00720             p->setPen(Qt::color1);
00721             p->drawPixmap(r.x(), r.y(), maskBmp);
00722             break;
00723         }
00724 
00725 
00726         // SPLITTER/DOCKWINDOW HANDLES
00727         // -------------------------------------------------------------------
00728         case PE_DockWindowResizeHandle:
00729         case PE_Splitter: {
00730             int x,y,w,h;
00731             r.rect(&x, &y, &w, &h);
00732             int x2 = x+w-1;
00733             int y2 = y+h-1;
00734 
00735             p->setPen(cg.dark());
00736             p->drawRect(x, y, w, h);
00737             p->setPen(cg.background());
00738             p->drawPoint(x, y);
00739             p->drawPoint(x2, y);
00740             p->drawPoint(x, y2);
00741             p->drawPoint(x2, y2);
00742             p->setPen(cg.light());
00743             p->drawLine(x+1, y+1, x+1, y2-1);
00744             p->drawLine(x+1, y+1, x2-1, y+1);
00745             p->setPen(cg.midlight());
00746             p->drawLine(x+2, y+2, x+2, y2-2);
00747             p->drawLine(x+2, y+2, x2-2, y+2);
00748             p->setPen(cg.mid());
00749             p->drawLine(x2-1, y+1, x2-1, y2-1);
00750             p->drawLine(x+1, y2-1, x2-1, y2-1);
00751             p->fillRect(x+3, y+3, w-5, h-5, cg.brush(QPalette::Background));
00752             break;
00753         }
00754 
00755 
00756         // GENERAL PANELS
00757         // -------------------------------------------------------------------
00758         case PE_Panel:
00759         case PE_PanelPopup:
00760         case PE_WindowFrame:
00761         case PE_PanelLineEdit: {
00762             bool sunken  = flags & Style_Sunken;
00763             int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth)
00764                                         : opt.lineWidth();
00765             if (lw == 2)
00766             {
00767                 QPen oldPen = p->pen();
00768                 int x,y,w,h;
00769                 r.rect(&x, &y, &w, &h);
00770                 int x2 = x+w-1;
00771                 int y2 = y+h-1;
00772                 p->setPen(sunken ? cg.light() : cg.dark());
00773                 p->drawLine(x, y2, x2, y2);
00774                 p->drawLine(x2, y, x2, y2);
00775                 p->setPen(sunken ? cg.mid() : cg.light());
00776                 p->drawLine(x, y, x2, y);
00777                 p->drawLine(x, y, x, y2);
00778                 p->setPen(sunken ? cg.midlight() : cg.mid());
00779                 p->drawLine(x+1, y2-1, x2-1, y2-1);
00780                 p->drawLine(x2-1, y+1, x2-1, y2-1);
00781                 p->setPen(sunken ? cg.dark() : cg.midlight());
00782                 p->drawLine(x+1, y+1, x2-1, y+1);
00783                 p->drawLine(x+1, y+1, x+1, y2-1);
00784                 p->setPen(oldPen);
00785             } else
00786                 KStyle::drawPrimitive(pe, p, r, cg, flags, opt);
00787 
00788             break;
00789         }
00790 
00791 
00792         // MENU / TOOLBAR PANEL
00793         // -------------------------------------------------------------------
00794         case PE_PanelMenuBar:           // Menu
00795         case PE_PanelDockWindow: {      // Toolbar
00796             int x2 = r.x()+r.width()-1;
00797             int y2 = r.y()+r.height()-1;
00798             int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth)
00799                 : opt.lineWidth();
00800             
00801             if (lw)
00802             {
00803                 p->setPen(cg.light());
00804                 p->drawLine(r.x(), r.y(), x2-1,  r.y());
00805                 p->drawLine(r.x(), r.y(), r.x(), y2-1);
00806                 p->setPen(cg.dark());
00807                 p->drawLine(r.x(), y2, x2, y2);
00808                 p->drawLine(x2, r.y(), x2, y2);
00809 
00810                 // ### Qt should specify Style_Horizontal where appropriate
00811                 renderGradient( p, QRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2),
00812                                 cg.button(), 
00813                                 (r.width() < r.height()) && (pe != PE_PanelMenuBar) );
00814             }
00815             else
00816                 renderGradient( p, r, cg.button(), 
00817                                 (r.width() < r.height()) && (pe != PE_PanelMenuBar) );
00818 
00819             break;
00820         }
00821 
00822 
00823 
00824         // TOOLBAR SEPARATOR
00825         // -------------------------------------------------------------------
00826         case PE_DockWindowSeparator: {
00827             renderGradient( p, r, cg.button(),
00828                             !(flags & Style_Horizontal));
00829             if ( !(flags & Style_Horizontal) ) {
00830                 p->setPen(cg.mid());
00831                 p->drawLine(4, r.height()/2, r.width()-5, r.height()/2);
00832                 p->setPen(cg.light());
00833                 p->drawLine(4, r.height()/2+1, r.width()-5, r.height()/2+1);
00834             } else {
00835                 p->setPen(cg.mid());
00836                 p->drawLine(r.width()/2, 4, r.width()/2, r.height()-5);
00837                 p->setPen(cg.light());
00838                 p->drawLine(r.width()/2+1, 4, r.width()/2+1, r.height()-5);
00839             }
00840             break;
00841         }
00842 
00843 
00844         default:
00845         {
00846             // ARROWS
00847             // -------------------------------------------------------------------
00848             if (pe >= PE_ArrowUp && pe <= PE_ArrowLeft)
00849             {
00850                 Q3PointArray a;
00851                 
00852                 if ( type != B3 ) {
00853                     // HighColor & Default arrows
00854                     switch(pe) {
00855                         case PE_ArrowUp:
00856                             a.setPoints(QCOORDARRLEN(u_arrow), u_arrow);
00857                             break;
00858 
00859                         case PE_ArrowDown:
00860                             a.setPoints(QCOORDARRLEN(d_arrow), d_arrow);
00861                             break;
00862 
00863                         case PE_ArrowLeft:
00864                             a.setPoints(QCOORDARRLEN(l_arrow), l_arrow);
00865                             break;
00866 
00867                         default:
00868                             a.setPoints(QCOORDARRLEN(r_arrow), r_arrow);
00869                     }
00870                 } else {
00871                     // B3 arrows
00872                     switch(pe) {
00873                         case PE_ArrowUp:
00874                             a.setPoints(QCOORDARRLEN(B3::u_arrow), B3::u_arrow);
00875                             break;
00876 
00877                         case PE_ArrowDown:
00878                             a.setPoints(QCOORDARRLEN(B3::d_arrow), B3::d_arrow);
00879                             break;
00880 
00881                         case PE_ArrowLeft:
00882                             a.setPoints(QCOORDARRLEN(B3::l_arrow), B3::l_arrow);
00883                             break;
00884 
00885                         default:
00886                             a.setPoints(QCOORDARRLEN(B3::r_arrow), B3::r_arrow);
00887                     }
00888                 }
00889                     
00890                 p->save();
00891                 if ( flags & Style_Down )
00892                     p->translate( pixelMetric( PM_ButtonShiftHorizontal ),
00893                                   pixelMetric( PM_ButtonShiftVertical ) );
00894 
00895                 if ( flags & Style_Enabled ) {
00896                     a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 );
00897                     p->setPen( cg.buttonText() );
00898                     p->drawLineSegments( a );
00899                 } else {
00900                     a.translate( r.x() + r.width() / 2 + 1, r.y() + r.height() / 2 + 1 );
00901                     p->setPen( cg.light() );
00902                     p->drawLineSegments( a );
00903                     a.translate( -1, -1 );
00904                     p->setPen( cg.mid() );
00905                     p->drawLineSegments( a );
00906                 }
00907                 p->restore();
00908             
00909             } else
00910                 KStyle::drawPrimitive( pe, p, r, cg, flags, opt );
00911         }
00912     }
00913 }
00914 
00915 
00916 void HighColorStyle::drawKStylePrimitive( KStylePrimitive kpe,
00917                                           QPainter* p,
00918                                           const QWidget* widget,
00919                                           const QRect &r,
00920                                           const QColorGroup &cg,
00921                                           SFlags flags,
00922                                           const QStyleOption &opt ) const
00923 {
00924     switch ( kpe )
00925     {
00926         // TOOLBAR HANDLE
00927         // -------------------------------------------------------------------
00928         case KPE_ToolBarHandle: {
00929             int x = r.x(); int y = r.y();
00930             int x2 = r.x() + r.width()-1;
00931             int y2 = r.y() + r.height()-1;
00932 
00933             if (flags & Style_Horizontal) {
00934 
00935                 renderGradient( p, r, cg.button(), false);
00936                 p->setPen(cg.light());
00937                 p->drawLine(x+1, y+4, x+1, y2-4);
00938                 p->drawLine(x+3, y+4, x+3, y2-4);
00939                 p->drawLine(x+5, y+4, x+5, y2-4);
00940 
00941                 p->setPen(cg.mid());
00942                 p->drawLine(x+2, y+4, x+2, y2-4);
00943                 p->drawLine(x+4, y+4, x+4, y2-4);
00944                 p->drawLine(x+6, y+4, x+6, y2-4);
00945 
00946             } else {
00947                 
00948                 renderGradient( p, r, cg.button(), true);
00949                 p->setPen(cg.light());
00950                 p->drawLine(x+4, y+1, x2-4, y+1);
00951                 p->drawLine(x+4, y+3, x2-4, y+3);
00952                 p->drawLine(x+4, y+5, x2-4, y+5);
00953 
00954                 p->setPen(cg.mid());
00955                 p->drawLine(x+4, y+2, x2-4, y+2);
00956                 p->drawLine(x+4, y+4, x2-4, y+4);
00957                 p->drawLine(x+4, y+6, x2-4, y+6);
00958 
00959             }
00960             break;
00961         }
00962 
00963                                
00964         // GENERAL/KICKER HANDLE
00965         // -------------------------------------------------------------------
00966         case KPE_GeneralHandle: {
00967             int x = r.x(); int y = r.y();
00968             int x2 = r.x() + r.width()-1;
00969             int y2 = r.y() + r.height()-1;
00970 
00971             if (flags & Style_Horizontal) {
00972 
00973                 p->setPen(cg.light());
00974                 p->drawLine(x+1, y, x+1, y2);
00975                 p->drawLine(x+3, y, x+3, y2);
00976                 p->drawLine(x+5, y, x+5, y2);
00977 
00978                 p->setPen(cg.mid());
00979                 p->drawLine(x+2, y, x+2, y2);
00980                 p->drawLine(x+4, y, x+4, y2);
00981                 p->drawLine(x+6, y, x+6, y2);
00982                 
00983             } else {
00984 
00985                 p->setPen(cg.light());
00986                 p->drawLine(x, y+1, x2, y+1);
00987                 p->drawLine(x, y+3, x2, y+3);
00988                 p->drawLine(x, y+5, x2, y+5);
00989 
00990                 p->setPen(cg.mid());
00991                 p->drawLine(x, y+2, x2, y+2);
00992                 p->drawLine(x, y+4, x2, y+4);
00993                 p->drawLine(x, y+6, x2, y+6);
00994 
00995             }
00996             break;
00997         }
00998 
00999 
01000         // SLIDER GROOVE
01001         // -------------------------------------------------------------------
01002         case KPE_SliderGroove: {
01003             const QSlider* slider = (const QSlider*)widget;
01004             bool horizontal = slider->orientation() == Qt::Horizontal;
01005             int gcenter = (horizontal ? r.height() : r.width()) / 2;
01006 
01007             QRect gr;
01008             if (horizontal)
01009                 gr = QRect(r.x(), r.y()+gcenter-3, r.width(), 7);
01010             else
01011                 gr = QRect(r.x()+gcenter-3, r.y(), 7, r.height());
01012 
01013             int x,y,w,h;
01014             gr.rect(&x, &y, &w, &h);
01015             int x2=x+w-1;
01016             int y2=y+h-1;
01017 
01018             // Draw the slider groove.
01019             p->setPen(cg.dark());
01020             p->drawLine(x+2, y, x2-2, y);
01021             p->drawLine(x, y+2, x, y2-2);
01022             p->fillRect(x+2,y+2,w-4, h-4, 
01023                 slider->isEnabled() ? cg.dark() : cg.mid());
01024             p->setPen(cg.shadow());
01025             p->drawRect(x+1, y+1, w-2, h-2);
01026             p->setPen(cg.light());
01027             p->drawPoint(x+1,y2-1);
01028             p->drawPoint(x2-1,y2-1);
01029             p->drawLine(x2, y+2, x2, y2-2);
01030             p->drawLine(x+2, y2, x2-2, y2);
01031             break;
01032         }
01033 
01034         // SLIDER HANDLE
01035         // -------------------------------------------------------------------
01036         case KPE_SliderHandle: {
01037             const QSlider* slider = (const QSlider*)widget;
01038             bool horizontal = slider->orientation() == Qt::Horizontal;
01039             int x,y,w,h;
01040             r.rect(&x, &y, &w, &h);
01041             int x2 = x+w-1;
01042             int y2 = y+h-1;
01043                 
01044             p->setPen(cg.mid());
01045             p->drawLine(x+1, y, x2-1, y);
01046             p->drawLine(x, y+1, x, y2-1);
01047             p->setPen(cg.shadow());
01048             p->drawLine(x+1, y2, x2-1, y2);
01049             p->drawLine(x2, y+1, x2, y2-1);
01050 
01051             p->setPen(cg.light());
01052             p->drawLine(x+1, y+1, x2-1, y+1);
01053             p->drawLine(x+1, y+1, x+1,  y2-1);
01054             p->setPen(cg.dark());
01055             p->drawLine(x+2, y2-1, x2-1, y2-1);
01056             p->drawLine(x2-1, y+2, x2-1, y2-1);
01057             p->setPen(cg.midlight());
01058             p->drawLine(x+2, y+2, x2-2, y+2);
01059             p->drawLine(x+2, y+2, x+2, y2-2);
01060             p->setPen(cg.mid());
01061             p->drawLine(x+3, y2-2, x2-2, y2-2);
01062             p->drawLine(x2-2, y+3, x2-2, y2-2);
01063             renderGradient(p, QRect(x+3, y+3, w-6, h-6), 
01064                            cg.button(), !horizontal);
01065 
01066             // Paint riffles
01067             if (horizontal) {
01068                 p->setPen(cg.light());
01069                 p->drawLine(x+5, y+4, x+5, y2-4);
01070                 p->drawLine(x+8, y+4, x+8, y2-4);
01071                 p->drawLine(x+11,y+4, x+11, y2-4);
01072                 p->setPen(slider->isEnabled() ? cg.shadow(): cg.mid());
01073                 p->drawLine(x+6, y+4, x+6, y2-4);
01074                 p->drawLine(x+9, y+4, x+9, y2-4);
01075                 p->drawLine(x+12,y+4, x+12, y2-4);
01076             } else {
01077                 p->setPen(cg.light());
01078                 p->drawLine(x+4, y+5, x2-4, y+5);
01079                 p->drawLine(x+4, y+8, x2-4, y+8);
01080                 p->drawLine(x+4, y+11, x2-4, y+11);
01081                 p->setPen(slider->isEnabled() ? cg.shadow() : cg.mid());
01082                 p->drawLine(x+4, y+6, x2-4, y+6);
01083                 p->drawLine(x+4, y+9, x2-4, y+9);
01084                 p->drawLine(x+4, y+12, x2-4, y+12);
01085             }
01086             break;
01087         }
01088 
01089         default:
01090             KStyle::drawKStylePrimitive( kpe, p, widget, r, cg, flags, opt);
01091     }
01092 }
01093 
01094 
01095 void HighColorStyle::drawControl( ControlElement element,
01096                                   QPainter *p,
01097                                   const QWidget *widget,
01098                                   const QRect &r,
01099                                   const QColorGroup &cg,
01100                                   SFlags flags,
01101                                   const QStyleOption& opt ) const
01102 {
01103     switch (element)
01104     {
01105         // PUSHBUTTON
01106         // -------------------------------------------------------------------
01107         case CE_PushButton: {
01108             if ( widget == hoverWidget )
01109                 flags |= Style_MouseOver;
01110             
01111             if ( type != HighColor ) {
01112                 QPushButton *button = (QPushButton*) widget;
01113                 QRect br = r;
01114                 bool btnDefault = button->isDefault();
01115                 
01116                 if ( btnDefault || button->autoDefault() ) {
01117                     // Compensate for default indicator
01118                     static int di = pixelMetric( PM_ButtonDefaultIndicator );
01119                     br.adjust( di, di, -di, -di );
01120                 }
01121 
01122                 if ( btnDefault )
01123                     drawPrimitive( PE_ButtonDefault, p, r, cg, flags );
01124                 
01125                 drawPrimitive( PE_ButtonCommand, p, br, cg, flags );
01126                 
01127             } else
01128                 drawPrimitive( PE_ButtonCommand, p, r, cg, flags );
01129             
01130             break;
01131         }
01132 
01133 
01134         // PUSHBUTTON LABEL
01135         // -------------------------------------------------------------------
01136         case CE_PushButtonLabel: {
01137             const QPushButton* button = (const QPushButton*)widget;
01138             bool active = button->isOn() || button->isDown();
01139             int x, y, w, h;
01140             r.rect( &x, &y, &w, &h );
01141 
01142             // Shift button contents if pushed.
01143             if ( active ) {
01144                 x += pixelMetric(PM_ButtonShiftHorizontal, widget); 
01145                 y += pixelMetric(PM_ButtonShiftVertical, widget);
01146                 flags |= Style_Sunken;
01147             }
01148 
01149             // Does the button have a popup menu?
01150             if ( button->isMenuButton() ) {
01151                 int dx = pixelMetric( PM_MenuButtonIndicator, widget );
01152                 drawPrimitive( PE_ArrowDown, p, QRect(x + w - dx - 2, y + 2, dx, h - 4),
01153                                cg, flags, opt );
01154                 w -= dx;
01155             }
01156 
01157             // Draw the icon if there is one
01158             if ( button->iconSet() && !button->iconSet()->isNull() ) {
01159                 QIcon::Mode  mode  = QIcon::Disabled;
01160                 QIcon::State state = QIcon::Off;
01161 
01162                 if (button->isEnabled())
01163                     mode = button->hasFocus() ? QIcon::Active : QIcon::Normal;
01164                 if (button->isToggleButton() && button->isOn())
01165                     state = QIcon::On;
01166 
01167                 QPixmap pixmap = button->iconSet()->pixmap( QIcon::Small, mode, state );
01168 
01169                 // Center the iconset if there's no text or pixmap
01170                 if (button->text().isEmpty() && !button->pixmap())
01171                     p->drawPixmap( x + (w - pixmap.width())  / 2, 
01172                                    y + (h - pixmap.height()) / 2, pixmap );
01173                 else
01174                     p->drawPixmap( x + 4, y + (h - pixmap.height()) / 2, pixmap );
01175 
01176                 int  pw = pixmap.width();
01177                 x += pw + 4;
01178                 w -= pw + 4;
01179             }
01180 
01181             // Make the label indicate if the button is a default button or not
01182             if ( active || button->isDefault() ) {
01183                 // Draw "fake" bold text  - this enables the font metrics to remain
01184                 // the same as computed in QPushButton::sizeHint(), but gives
01185                 // a reasonable bold effect.
01186                 int i;
01187 
01188                 // Text shadow
01189                 if (button->isEnabled()) // Don't draw double-shadow when disabled
01190                     for(i=0; i<2; i++)
01191                         drawItem( p, QRect(x+i+1, y+1, w, h), Qt::AlignCenter | Qt::TextShowMnemonic, 
01192                                 button->colorGroup(), button->isEnabled(), NULL,
01193                                 button->text(), -1, 
01194                                 active ? &button->colorGroup().dark() : &button->colorGroup().mid() );
01195 
01196                 // Normal Text
01197                 for(i=0; i<2; i++)
01198                     drawItem( p, QRect(x+i, y, w, h), Qt::AlignCenter | Qt::TextShowMnemonic, 
01199                             button->colorGroup(), button->isEnabled(), i == 0 ? button->pixmap() : NULL,
01200                             button->text(), -1,
01201                             active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
01202             } else
01203                 drawItem( p, QRect(x, y, w, h), Qt::AlignCenter | Qt::TextShowMnemonic, button->colorGroup(),
01204                         button->isEnabled(), button->pixmap(), button->text(), -1,
01205                         active ? &button->colorGroup().light() : &button->colorGroup().buttonText() );
01206 
01207             // Draw a focus rect if the button has focus
01208             if ( flags & Style_HasFocus )
01209                 drawPrimitive( PE_FocusRect, p,
01210                         QStyle::visualRect(subRect(SR_PushButtonFocusRect, widget), widget),
01211                         cg, flags );
01212             break;
01213         }
01214 
01215         // TOOLBOX TAB
01216         // -------------------------------------------------------------------
01217         case CE_ToolBoxTab:
01218         {
01219             bool pressed = flags & Style_Down;
01220             bool selected = flags & Style_Selected;
01221             int x, y, x2, y2;
01222             r.getCoords( &x, &y, &x2, &y2 );
01223 
01224             p->setPen( pressed ? cg.shadow() : cg.light() );
01225             p->drawLine( x, y, x2-1, y );
01226             p->drawLine( x, y, x, y2-1 );
01227 
01228             p->setPen( pressed ? cg.light() : cg.shadow() );
01229             p->drawLine( x, y2, x2, y2 );
01230             p->drawLine( x2, y, x2, y2 );
01231 
01232             QColor fill = selected ? cg.highlight() : cg.button();
01233             selectionBackground = selected;
01234 
01235             if ( pressed )
01236                 p->fillRect( QRect(x+1, y+1, r.width()-2, r.height()-2), fill );
01237             else
01238                 renderGradient(p, QRect(x+1, y+1, r.width()-2, r.height()-2),
01239                         fill, false);
01240             break;
01241         }
01242 
01243         // MENUBAR BACKGROUND
01244         // -------------------------------------------------------------------
01245         case CE_MenuBarEmptyArea:
01246         {
01247             renderGradient(p, r, cg.button(), false);
01248             break;
01249         }
01250 
01251         // MENUBAR ITEM (sunken panel on mouse over)
01252         // -------------------------------------------------------------------
01253         case CE_MenuBarItem:
01254         {
01255             QMenuBar  *mb = (QMenuBar*)widget;
01256             QMenuItem *mi = opt.menuItem();
01257             QRect      pr = mb->rect();
01258 
01259             bool active  = flags & Style_Active;
01260             bool focused = flags & Style_HasFocus;
01261 
01262             if ( active && focused )
01263                 qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(),
01264                                 cg, true, 1, &cg.brush(QPalette::Midlight));
01265             else
01266                 renderGradient( p, r, cg.button(), false,
01267                                 r.x(), r.y()-1, pr.width()-2, pr.height()-2);
01268 
01269             drawItem( p, r, Qt::AlignCenter | Qt::AlignVCenter | Qt::TextShowMnemonic
01270                     | Qt::TextDontClip | Qt::TextSingleLine, cg, flags & Style_Enabled,
01271                     mi->pixmap(), mi->text() );
01272 
01273             break;
01274         }
01275 
01276 
01277         // POPUPMENU ITEM
01278         // -------------------------------------------------------------------
01279         case CE_PopupMenuItem: {
01280             const QMenu *popupmenu = (const QMenu *) widget;
01281 
01282             QMenuItem *mi = opt.menuItem();
01283             if ( !mi ) {
01284                 // Don't leave blank holes if we set NoBackground for the QPopupMenu.
01285                 // This only happens when the popupMenu spans more than one column.
01286                 if (! (widget->erasePixmap() && !widget->erasePixmap()->isNull()) )
01287                     p->fillRect(r, cg.brush(QPalette::Button) );
01288                 break;
01289             }
01290 
01291             int  tab        = opt.tabWidth();
01292             int  checkcol   = opt.maxIconWidth();
01293             bool enabled    = mi->isEnabled();
01294             bool checkable  = popupmenu->isCheckable();
01295             bool active     = flags & Style_Active;
01296             bool etchtext   = styleHint( SH_EtchDisabledText );
01297             bool reverse    = QApplication::isRightToLeft();
01298             int x, y, w, h;
01299             r.rect( &x, &y, &w, &h );
01300 
01301             if ( checkable )
01302                 checkcol = qMax( checkcol, 20 );
01303 
01304             // Are we a menu item separator?
01305             if ( mi->isSeparator() ) {
01306                 p->setPen( cg.dark() );
01307                 p->drawLine( x, y, x+w, y );
01308                 p->setPen( cg.light() );
01309                 p->drawLine( x, y+1, x+w, y+1 );
01310                 break;
01311             }
01312 
01313             // Draw the menu item background
01314             if ( active )
01315                 qDrawShadePanel( p, x, y, w, h, cg, true, 1,
01316                                  &cg.brush(QPalette::Midlight) );
01317             // Draw the transparency pixmap
01318             else if ( widget->erasePixmap() && !widget->erasePixmap()->isNull() )
01319                 p->drawPixmap( x, y, *widget->erasePixmap(), x, y, w, h );
01320             // Draw a solid background
01321             else
01322                 p->fillRect( r, cg.button() );
01323 
01324             // Do we have an icon?
01325             if ( mi->iconSet() ) {
01326                 QIcon::Mode mode;
01327                 QRect cr = visualRect( QRect(x, y, checkcol, h), r );
01328                 
01329                 // Select the correct icon from the iconset
01330                 if ( active )
01331                     mode = enabled ? QIcon::Active : QIcon::Disabled;
01332                 else
01333                     mode = enabled ? QIcon::Normal : QIcon::Disabled;
01334 
01335                 // Do we have an icon and are checked at the same time?
01336                 // Then draw a "pressed" background behind the icon
01337                 if ( checkable && !active && mi->isChecked() )
01338                     qDrawShadePanel( p, cr.x(), cr.y(), cr.width(), cr.height(),
01339                                      cg, true, 1, &cg.brush(QPalette::Midlight) );
01340                 // Draw the icon
01341                 QPixmap pixmap = mi->iconSet()->pixmap( QIcon::Small, mode );
01342                 QRect pmr( 0, 0, pixmap.width(), pixmap.height() );
01343                 pmr.moveCenter( cr.center() );
01344                 p->drawPixmap( pmr.topLeft(), pixmap );
01345             }
01346 
01347             // Are we checked? (This time without an icon)
01348             else if ( checkable && mi->isChecked() ) {
01349                 int cx = reverse ? x+w - checkcol : x;
01350 
01351                 // We only have to draw the background if the menu item is inactive -
01352                 // if it's active the "pressed" background is already drawn
01353                 if ( ! active )
01354                     qDrawShadePanel( p, cx, y, checkcol, h, cg, true, 1,
01355                                      &cg.brush(QPalette::Midlight) );
01356 
01357                 // Draw the checkmark
01358                 SFlags cflags = Style_Default;
01359                 cflags |= active ? Style_Enabled : Style_On;
01360 
01361                 drawPrimitive( PE_CheckMark, p, QRect( cx + itemFrame, y + itemFrame,
01362                                 checkcol - itemFrame*2, h - itemFrame*2), cg, cflags );
01363             }
01364 
01365             // Time to draw the menu item label...
01366             int xm = itemFrame + checkcol + itemHMargin; // X position margin
01367             
01368             int xp = reverse ? // X position
01369                     x + tab + rightBorder + itemHMargin + itemFrame - 1 :
01370                     x + xm;
01371             
01372             int offset = reverse ? -1 : 1;  // Shadow offset for etched text
01373             
01374             // Label width (minus the width of the accelerator portion)
01375             int tw = w - xm - tab - arrowHMargin - itemHMargin * 3 - itemFrame + 1; 
01376 
01377             // Set the color for enabled and disabled text 
01378             // (used for both active and inactive menu items)
01379             p->setPen( enabled ? cg.buttonText() : cg.mid() );
01380 
01381             // This color will be used instead of the above if the menu item
01382             // is active and disabled at the same time. (etched text)
01383             QColor discol = cg.mid();
01384 
01385             // Does the menu item draw it's own label?
01386             if ( mi->custom() ) {
01387                 int m = itemVMargin;
01388                 // Save the painter state in case the custom
01389                 // paint method changes it in some way
01390                 p->save();
01391 
01392                 // Draw etched text if we're inactive and the menu item is disabled
01393                 if ( etchtext && !enabled && !active ) {
01394                     p->setPen( cg.light() );
01395                     mi->custom()->paint( p, cg, active, enabled, xp+offset, y+m+1, tw, h-2*m );
01396                     p->setPen( discol );
01397                 }
01398                 mi->custom()->paint( p, cg, active, enabled, xp, y+m, tw, h-2*m );
01399                 p->restore();
01400             }
01401             else {
01402                 // The menu item doesn't draw it's own label
01403                 QString s = mi->text();
01404 
01405                 // Does the menu item have a text label?
01406                 if ( !s.isNull() ) {
01407                     int t = s.find( '\t' );
01408                     int m = itemVMargin;
01409                     int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
01410                     text_flags |= reverse ? Qt::AlignRight : Qt::AlignLeft;
01411                     
01412                     // Does the menu item have a tabstop? (for the accelerator text)
01413                     if ( t >= 0 ) {
01414                         int tabx = reverse ? x + rightBorder + itemHMargin + itemFrame :
01415                             x + w - tab - rightBorder - itemHMargin - itemFrame;
01416 
01417                         // Draw the right part of the label (accelerator text)
01418                         if ( etchtext && !enabled && !active ) {
01419                             // Draw etched text if we're inactive and the menu item is disabled
01420                             p->setPen( cg.light() );
01421                             p->drawText( tabx+offset, y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ) );
01422                             p->setPen( discol );
01423                         }
01424                         p->drawText( tabx, y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
01425                         s = s.left( t );
01426                     }
01427 
01428                     // Draw the left part of the label (or the whole label 
01429                     // if there's no accelerator)
01430                     if ( etchtext && !enabled && !active ) {
01431                         // Etched text again for inactive disabled menu items...
01432                         p->setPen( cg.light() );
01433                         p->drawText( xp+offset, y+m+1, tw, h-2*m, text_flags, s, t );
01434                         p->setPen( discol );
01435                     }
01436 
01437                     p->drawText( xp, y+m, tw, h-2*m, text_flags, s, t );
01438 
01439                 }
01440 
01441                 // The menu item doesn't have a text label
01442                 // Check if it has a pixmap instead
01443                 else if ( mi->pixmap() ) {
01444                     QPixmap *pixmap = mi->pixmap();
01445 
01446                     // Draw the pixmap
01447                     if ( pixmap->depth() == 1 )
01448                         p->setBackgroundMode( Qt::OpaqueMode );
01449 
01450                     int diffw = ( ( w - pixmap->width() ) / 2 )
01451                                     + ( ( w - pixmap->width() ) % 2 );
01452                     p->drawPixmap( x+diffw, y+itemFrame, *pixmap );
01453                     
01454                     if ( pixmap->depth() == 1 )
01455                         p->setBackgroundMode( Qt::TransparentMode );
01456                 }
01457             }
01458 
01459             // Does the menu item have a submenu?
01460             if ( mi->popup() ) {
01461                 PrimitiveElement arrow = reverse ? PE_ArrowLeft : PE_ArrowRight;
01462                 int dim = pixelMetric(PM_MenuButtonIndicator);
01463                 QRect vr = visualRect( QRect( x + w - arrowHMargin - 2*itemFrame - dim,
01464                             y + h / 2 - dim / 2, dim, dim), r );
01465 
01466                 // Draw an arrow at the far end of the menu item
01467                 if ( active ) {
01468                     if ( enabled )
01469                         discol = cg.buttonText();
01470 
01471                     QColorGroup g2( discol, cg.highlight(), Qt::white, Qt::white,
01472                                     enabled ? Qt::white : discol, discol, Qt::white );
01473 
01474                     drawPrimitive( arrow, p, vr, g2, Style_Enabled );
01475                 } else
01476                     drawPrimitive( arrow, p, vr, cg,
01477                             enabled ? Style_Enabled : Style_Default );
01478             }
01479             break;
01480         }
01481 
01482         default:
01483             KStyle::drawControl(element, p, widget, r, cg, flags, opt);
01484     }
01485 }
01486 
01487 
01488 void HighColorStyle::drawControlMask( ControlElement element,
01489                                       QPainter *p,
01490                                       const QWidget *widget,
01491                                       const QRect &r,
01492                                       const QStyleOption& opt ) const
01493 {
01494     switch (element)
01495     {
01496         // PUSHBUTTON MASK
01497         // ----------------------------------------------------------------------
01498         case CE_PushButton: {
01499             int x1, y1, x2, y2;
01500             r.getCoords( &x1, &y1, &x2, &y2 );
01501             QCOORD corners[] = { x1,y1, x2,y1, x1,y2, x2,y2 };
01502             p->fillRect( r, Qt::color1 );
01503             p->setPen( Qt::color0 );
01504             p->drawPoints( Q3PointArray(4, corners) );
01505             break;
01506         }
01507 
01508         default:
01509             KStyle::drawControlMask(element, p, widget, r, opt);
01510     }
01511 }
01512 
01513 
01514 void HighColorStyle::drawComplexControl( ComplexControl control,
01515                                          QPainter *p,
01516                                          const QWidget *widget,
01517                                          const QRect &r,
01518                                          const QColorGroup &cg,
01519                                          SFlags flags,
01520                                          SCFlags controls,
01521                                          SCFlags active,
01522                                          const QStyleOption& opt ) const
01523 {
01524     switch(control)
01525     {
01526         // COMBOBOX
01527         // -------------------------------------------------------------------
01528         case CC_ComboBox: {
01529 
01530             // Draw box and arrow
01531             if ( controls & SC_ComboBoxArrow ) {
01532                 bool sunken = (active == SC_ComboBoxArrow);
01533 
01534                 // Draw the combo
01535                 int x,y,w,h;
01536                 r.rect(&x, &y, &w, &h);
01537                 int x2 = x+w-1;
01538                 int y2 = y+h-1;
01539 
01540                 p->setPen(cg.shadow());
01541                 p->drawLine(x+1, y, x2-1, y);
01542                 p->drawLine(x+1, y2, x2-1, y2);
01543                 p->drawLine(x, y+1, x, y2-1);
01544                 p->drawLine(x2, y+1, x2, y2-1);
01545 
01546                 // Ensure the edge notches are properly colored
01547                 p->setPen(cg.button());
01548                 p->drawPoint(x,y);
01549                 p->drawPoint(x,y2);
01550                 p->drawPoint(x2,y);
01551                 p->drawPoint(x2,y2);
01552 
01553                 renderGradient( p, QRect(x+2, y+2, w-4, h-4),
01554                                 cg.button(), false);
01555 
01556                 p->setPen(sunken ? cg.light() : cg.mid());
01557                 p->drawLine(x2-1, y+2, x2-1, y2-1);
01558                 p->drawLine(x+1, y2-1, x2-1, y2-1);
01559 
01560                 p->setPen(sunken ? cg.mid() : cg.light());
01561                 p->drawLine(x+1, y+1, x2-1, y+1);
01562                 p->drawLine(x+1, y+2, x+1, y2-2);
01563 
01564                 // Get the button bounding box
01565                 QRect ar = QStyle::visualRect(
01566                     querySubControlMetrics(CC_ComboBox, widget, SC_ComboBoxArrow),
01567                     widget );
01568 
01569                 // Are we enabled?
01570                 if ( widget->isEnabled() )
01571                     flags |= Style_Enabled;
01572 
01573                 // Are we "pushed" ?
01574                 if ( active & Style_Sunken )
01575                     flags |= Style_Sunken;
01576 
01577                 drawPrimitive(PE_ArrowDown, p, ar, cg, flags);
01578             }
01579 
01580             // Draw an edit field if required
01581             if ( controls & SC_ComboBoxEditField )
01582             {
01583                 const QComboBox * cb = (const QComboBox *) widget;
01584                 QRect re = QStyle::visualRect(
01585                     querySubControlMetrics( CC_ComboBox, widget,
01586                                             SC_ComboBoxEditField), widget );
01587 
01588                 // Draw the indent
01589                 if (cb->editable()) {
01590                     p->setPen( cg.dark() );
01591                     p->drawLine( re.x(), re.y()-1, re.x()+re.width(), re.y()-1 );
01592                     p->drawLine( re.x()-1, re.y(), re.x()-1, re.y()+re.height() );
01593                 }
01594 
01595                 if ( cb->hasFocus() ) {
01596                     p->setPen( cg.highlightedText() );
01597                     p->setBackgroundColor( cg.highlight() );
01598                 } else {
01599                     p->setPen( cg.text() );
01600                     p->setBackgroundColor( cg.button() );
01601                 }
01602 
01603                 if ( cb->hasFocus() && !cb->editable() ) {
01604                     // Draw the contents
01605                     p->fillRect( re.x(), re.y(), re.width(), re.height(),
01606                                  cg.brush( QPalette::Highlight ) );
01607 
01608                     QRect re = QStyle::visualRect( 
01609                                 subRect(SR_ComboBoxFocusRect, cb), widget);
01610 
01611                     drawPrimitive( PE_FocusRect, p, re, cg,
01612                                    Style_FocusAtBorder, QStyleOption(cg.highlight()));
01613                 }
01614             }
01615             break;
01616         }
01617 
01618         // TOOLBUTTON
01619         // -------------------------------------------------------------------
01620         case CC_ToolButton: {
01621             const QToolButton *toolbutton = (const QToolButton *) widget;
01622 
01623             QRect button, menuarea;
01624             button   = querySubControlMetrics(control, widget, SC_ToolButton, opt);
01625             menuarea = querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt);
01626 
01627             SFlags bflags = flags,
01628                    mflags = flags;
01629 
01630             if (active & SC_ToolButton)
01631                 bflags |= Style_Down;
01632             if (active & SC_ToolButtonMenu)
01633                 mflags |= Style_Down;
01634 
01635             if (controls & SC_ToolButton)
01636             {
01637                 // If we're pressed, on, or raised...
01638                 if (bflags & (Style_Down | Style_On | Style_Raised))
01639                     drawPrimitive(PE_ButtonTool, p, button, cg, bflags, opt);
01640 
01641                 // Check whether to draw a background pixmap
01642                 else if ( toolbutton->parentWidget() &&
01643                           toolbutton->parentWidget()->backgroundPixmap() &&
01644                           !toolbutton->parentWidget()->backgroundPixmap()->isNull() )
01645                 {
01646                     QPixmap pixmap = *(toolbutton->parentWidget()->backgroundPixmap());
01647                     p->drawTiledPixmap( r, pixmap, toolbutton->pos() );
01648                 }
01649                 else if (widget->parent())
01650                 {
01651                     if (widget->parent()->inherits("QToolBar"))
01652                     {
01653                         Q3ToolBar* parent = (Q3ToolBar*)widget->parent();
01654                         QRect pr = parent->rect();
01655 
01656                         renderGradient( p, r, cg.button(),
01657                                     parent->orientation() == Qt::Vertical,
01658                                     r.x(), r.y(), pr.width()-2, pr.height()-2);
01659                     }
01660                     else if (widget->parent()->inherits("QToolBarExtensionWidget"))
01661                     {
01662                         QWidget* parent = (QWidget*)widget->parent();
01663                         Q3ToolBar* toolbar = (Q3ToolBar*)parent->parent();
01664                         QRect tr = toolbar->rect();
01665 
01666                         if ( toolbar->orientation() == Qt::Horizontal ) {
01667                             renderGradient( p, r, cg.button(), false, r.x(), r.y(),
01668                                     r.width(), tr.height() );
01669                         } else {
01670                             renderGradient( p, r, cg.button(), true, r.x(), r.y(),
01671                                     tr.width(), r.height() );
01672                         }
01673                     }
01674                 }
01675             }
01676 
01677             // Draw a toolbutton menu indicator if required
01678             if (controls & SC_ToolButtonMenu)
01679             {
01680                 if (mflags & (Style_Down | Style_On | Style_Raised))
01681                     drawPrimitive(PE_ButtonDropDown, p, menuarea, cg, mflags, opt);
01682                 drawPrimitive(PE_ArrowDown, p, menuarea, cg, mflags, opt);
01683             }
01684 
01685             if (toolbutton->hasFocus() && !toolbutton->focusProxy()) {
01686                 QRect fr = toolbutton->rect();
01687                 fr.adjust(3, 3, -3, -3);
01688                 drawPrimitive(PE_FocusRect, p, fr, cg);
01689             }
01690 
01691             break;
01692         }
01693 
01694 
01695         default:
01696             KStyle::drawComplexControl(control, p, widget,
01697                         r, cg, flags, controls, active, opt);
01698             break;
01699     }
01700 }
01701 
01702 
01703 void HighColorStyle::drawComplexControlMask( ComplexControl control,
01704                                              QPainter *p,
01705                                              const QWidget *widget,
01706                                              const QRect &r,
01707                                              const QStyleOption& opt ) const
01708 {
01709     switch (control)
01710     {
01711         // COMBOBOX & TOOLBUTTON MASKS
01712         // -------------------------------------------------------------------
01713         case CC_ComboBox:
01714         case CC_ToolButton: {
01715             int x1, y1, x2, y2;
01716             r.getCoords( &x1, &y1, &x2, &y2 );
01717             QCOORD corners[] = { x1,y1, x2,y1, x1,y2, x2,y2 };
01718             p->fillRect( r, Qt::color1 );
01719             p->setPen( Qt::color0 );
01720             p->drawPoints( Q3PointArray(4, corners) );
01721             break;
01722         }
01723 
01724         default:
01725             KStyle::drawComplexControlMask(control, p, widget, r, opt);
01726     }
01727 }
01728 
01729 
01730 void HighColorStyle::drawItem( QPainter *p,
01731                                const QRect &r,
01732                                int flags,
01733                                const QColorGroup &cg,
01734                                bool enabled,
01735                                const QPixmap *pixmap,
01736                                const QString &text,
01737                                int len,
01738                                const QColor *penColor ) const
01739 {
01740     // We only reimplement this method this so we can override the
01741     // text color used for widgets when we draw them with the selection
01742     // color and Qt expects them to be drawn them with the button color.
01743     // -------------------------------------------------------------------
01744     const QColor *col;
01745 
01746     if ( selectionBackground ) {
01747         col = &cg.highlightedText();
01748         selectionBackground = false;
01749     } else
01750         col = penColor;
01751 
01752     KStyle::drawItem( p, r, flags, cg, enabled, pixmap,
01753             text, len, col );
01754 }
01755 
01756 
01757 QRect HighColorStyle::subRect(SubRect r, const QWidget *widget) const
01758 {
01759     // We want the focus rect for buttons to be adjusted from
01760     // the Qt3 defaults to be similar to Qt 2's defaults.
01761     // -------------------------------------------------------------------
01762     if (r == SR_PushButtonFocusRect ) {
01763         const QPushButton* button = (const QPushButton*) widget;
01764         QRect wrect(widget->rect());
01765         int dbw1 = 0, dbw2 = 0;
01766 
01767         if (button->isDefault() || button->autoDefault()) {
01768             dbw1 = pixelMetric(PM_ButtonDefaultIndicator, widget);
01769             dbw2 = dbw1 * 2;
01770         }
01771 
01772         int dfw1 = pixelMetric(PM_DefaultFrameWidth, widget) * 2,
01773             dfw2 = dfw1 * 2;
01774 
01775         return QRect(wrect.x()      + dfw1 + dbw1 + 1,
01776                      wrect.y()      + dfw1 + dbw1 + 1,
01777                      wrect.width()  - dfw2 - dbw2 - 1,
01778                      wrect.height() - dfw2 - dbw2 - 1);
01779     } else
01780         return KStyle::subRect(r, widget);
01781 }
01782 
01783 
01784 int HighColorStyle::pixelMetric(PixelMetric m, const QWidget *widget) const
01785 {
01786     switch(m)
01787     {
01788         // BUTTONS
01789         // -------------------------------------------------------------------
01790         case PM_ButtonMargin:               // Space btw. frame and label
01791             return 4;
01792 
01793         case PM_ButtonDefaultIndicator: {
01794             if ( type == HighColor )
01795                 return 0;                   // No indicator when highcolor
01796             else
01797                 return 3;
01798         }
01799 
01800         case PM_MenuButtonIndicator: {      // Arrow width
01801             if ( type != B3 )
01802                 return 8;
01803             else
01804                 return 7;
01805         }
01806                                         
01807         // CHECKBOXES / RADIO BUTTONS
01808         // -------------------------------------------------------------------
01809         case PM_ExclusiveIndicatorWidth:    // Radiobutton size
01810         case PM_ExclusiveIndicatorHeight:
01811         case PM_IndicatorWidth:             // Checkbox size
01812         case PM_IndicatorHeight: {
01813             return 13;                      // 13x13
01814         }
01815 
01816         default:
01817             return KStyle::pixelMetric(m, widget);
01818     }
01819 }
01820 
01821 
01822 QSize HighColorStyle::sizeFromContents( ContentsType contents,
01823                                         const QWidget* widget,
01824                                         const QSize &contentSize,
01825                                         const QStyleOption& opt ) const
01826 {
01827     switch (contents)
01828     {
01829         // PUSHBUTTON SIZE
01830         // ------------------------------------------------------------------
01831         case CT_PushButton: {
01832             const QPushButton* button = (const QPushButton*) widget;
01833             int w  = contentSize.width();
01834             int h  = contentSize.height();
01835             int bm = pixelMetric( PM_ButtonMargin, widget );
01836             int fw = pixelMetric( PM_DefaultFrameWidth, widget ) * 2;
01837 
01838             w += bm + fw + 6;   // ### Add 6 to make way for bold font.
01839             h += bm + fw;
01840 
01841             // Ensure we stick to standard width and heights.
01842             if ( button->isDefault() || button->autoDefault() ) {
01843                 if ( w < 80 && !button->text().isEmpty() )
01844                     w = 80;
01845 
01846                 if ( type != HighColor ) {
01847                     // Compensate for default indicator
01848                     int di = pixelMetric( PM_ButtonDefaultIndicator );
01849                     w += di * 2;
01850                     h += di * 2;
01851                 }
01852             }
01853 
01854             if ( h < 22 )
01855                 h = 22;
01856 
01857             return QSize( w, h );
01858         }
01859 
01860 
01861         // POPUPMENU ITEM SIZE
01862         // -----------------------------------------------------------------
01863         case CT_PopupMenuItem: {
01864             if ( ! widget || opt.isDefault() )
01865                 return contentSize;
01866 
01867             const QMenu *popup = (const QMenu *) widget;
01868             bool checkable = popup->isCheckable();
01869             QMenuItem *mi = opt.menuItem();
01870             int maxpmw = opt.maxIconWidth();
01871             int w = contentSize.width(), h = contentSize.height();
01872 
01873             if ( mi->custom() ) {
01874                 w = mi->custom()->sizeHint().width();
01875                 h = mi->custom()->sizeHint().height();
01876                 if ( ! mi->custom()->fullSpan() )
01877                     h += 2*itemVMargin + 2*itemFrame;
01878             }
01879             else if ( mi->widget() ) {
01880             } else if ( mi->isSeparator() ) {
01881                 w = 10; // Arbitrary
01882                 h = 2;
01883             }
01884             else {
01885                 if ( mi->pixmap() )
01886                     h = qMax( h, mi->pixmap()->height() + 2*itemFrame );
01887                 else {
01888                     // Ensure that the minimum height for text-only menu items
01889                     // is the same as the icon size used by KDE.
01890                     h = qMax( h, 16 + 2*itemFrame );
01891                     h = qMax( h, popup->fontMetrics().height()
01892                             + 2*itemVMargin + 2*itemFrame );
01893                 }
01894                     
01895                 if ( mi->iconSet() )
01896                     h = qMax( h, mi->iconSet()->pixmap(
01897                                 QIcon::Small, QIcon::Normal).height() +
01898                                 2 * itemFrame );
01899             }
01900 
01901             if ( ! mi->text().isNull() && mi->text().find('\t') >= 0 )
01902                 w += 12;
01903             else if ( mi->popup() )
01904                 w += 2 * arrowHMargin;
01905 
01906             if ( maxpmw )
01907                 w += maxpmw + 6;
01908             if ( checkable && maxpmw < 20 )
01909                 w += 20 - maxpmw;
01910             if ( checkable || maxpmw > 0 )
01911                 w += 12;
01912 
01913             w += rightBorder;
01914 
01915             return QSize( w, h );
01916         }
01917 
01918 
01919         default:
01920             return KStyle::sizeFromContents( contents, widget, contentSize, opt );
01921     }
01922 }
01923 
01924 
01925 // Fix Qt's wacky image alignment
01926 QPixmap HighColorStyle::stylePixmap(StylePixmap stylepixmap,
01927                                     const QWidget* widget,
01928                                     const QStyleOption& opt) const
01929 {
01930     switch (stylepixmap) {
01931         case SP_TitleBarMinButton:
01932             return QPixmap((const char **)hc_minimize_xpm);
01933         case SP_TitleBarCloseButton:
01934             return QPixmap((const char **)hc_close_xpm);
01935         default:
01936             break;
01937     }
01938 
01939     return KStyle::stylePixmap(stylepixmap, widget, opt);
01940 }
01941 
01942 
01943 bool HighColorStyle::eventFilter( QObject *object, QEvent *event )
01944 {
01945     if (KStyle::eventFilter( object, event ))
01946         return true;
01947 
01948     Q3ToolBar* toolbar;
01949 
01950     // Handle push button hover effects.
01951     QPushButton* button = dynamic_cast<QPushButton*>(object);
01952     if ( button )
01953     {
01954         if ( (event->type() == QEvent::Enter) &&
01955              (button->isEnabled()) ) {
01956             hoverWidget = button;
01957             button->repaint( false );
01958         } 
01959         else if ( (event->type() == QEvent::Leave) &&
01960                   (object == hoverWidget) ) {
01961             hoverWidget = 0L;
01962             button->repaint( false );
01963         }
01964     } else if ( object->parent() && !qstrcmp( object->name(), kdeToolbarWidget ) )
01965     {
01966         // Draw a gradient background for custom widgets in the toolbar
01967         // that have specified a "kde toolbar widget" name.
01968 
01969         if (event->type() == QEvent::Paint ) {
01970             // Find the top-level toolbar of this widget, since it may be nested in other
01971             // widgets that are on the toolbar.
01972             QWidget *widget = static_cast<QWidget*>(object);
01973             QWidget *parent = static_cast<QWidget*>(object->parent());
01974             int x_offset = widget->x(), y_offset = widget->y();
01975             while (parent && parent->parent() && !qstrcmp( parent->name(), kdeToolbarWidget ) )
01976             {
01977                 x_offset += parent->x();
01978                 y_offset += parent->y();
01979                 parent = static_cast<QWidget*>(parent->parent());
01980             }
01981 
01982             QRect r  = widget->rect();
01983             QRect pr = parent->rect();
01984             bool horiz_grad = pr.width() < pr.height();
01985 
01986             // Check if the parent is a QToolbar, and use its orientation, else guess.
01987             Q3ToolBar* tb = dynamic_cast<Q3ToolBar*>(parent);
01988             if (tb) horiz_grad = tb->orientation() == Qt::Vertical;
01989 
01990             QPainter p( widget );
01991             renderGradient(&p, r, parent->colorGroup().button(), horiz_grad,
01992                     x_offset, y_offset, pr.width(), pr.height());
01993 
01994             return false;   // Now draw the contents
01995         }
01996     } else if ( object->parent() &&
01997             (toolbar = dynamic_cast<Q3ToolBar*>(object->parent())) )
01998     {
01999         // We need to override the paint event to draw a 
02000         // gradient on a QToolBarExtensionWidget.
02001         if ( event->type() == QEvent::Paint ) {
02002             QWidget *widget = static_cast<QWidget*>(object);
02003             QRect wr = widget->rect(), tr = toolbar->rect();
02004             QPainter p( widget );
02005             renderGradient(&p, wr, toolbar->colorGroup().button(),
02006                     toolbar->orientation() == Qt::Vertical,
02007                     wr.x(), wr.y(), tr.width() - 2, tr.height() - 2);
02008             
02009             p.setPen( toolbar->colorGroup().dark() );
02010             if ( toolbar->orientation() == Qt::Horizontal )
02011                 p.drawLine( wr.width()-1, 0, wr.width()-1, wr.height()-1 );
02012             else
02013                 p.drawLine( 0, wr.height()-1, wr.width()-1, wr.height()-1 );
02014             
02015             return true;
02016         }
02017     }
02018     
02019     return false;
02020 }
02021 
02022 
02023 void HighColorStyle::renderGradient( QPainter* p, const QRect& r,
02024     QColor clr, bool horizontal, int px, int py, int pwidth, int pheight) const
02025 {
02026     // Make 8 bit displays happy
02027     if (!highcolor) {
02028         p->fillRect(r, clr);
02029         return;
02030     }
02031 
02032     // px, py specify the gradient pixmap offset relative to the top-left corner.
02033     // pwidth, pheight specify the width and height of the parent's pixmap.
02034     // We use these to draw parent-relative pixmaps for toolbar buttons
02035     // and menubar items.
02036 
02037     GradientSet* grSet = gDict.find( clr.rgb() );
02038 
02039     if (!grSet) {
02040         grSet = new GradientSet(clr);
02041         gDict.insert( clr.rgb(), grSet );
02042     }
02043 
02044     if (horizontal) {
02045         int width = (pwidth != -1) ? pwidth : r.width();
02046 
02047         if (width <= 34)
02048             p->drawTiledPixmap(r, *grSet->gradient(HMed), QPoint(px, 0));
02049         else if (width <= 52)
02050             p->drawTiledPixmap(r, *grSet->gradient(HLarge), QPoint(px, 0));
02051         else {
02052             KPixmap *hLarge = grSet->gradient(HLarge);
02053 
02054             // Don't draw a gradient if we don't need to
02055             if (hLarge->width() > px)
02056             {
02057                 int pixmapWidth = hLarge->width() - px;
02058 
02059                 // Draw the gradient
02060                 p->drawTiledPixmap( r.x(), r.y(), pixmapWidth, r.height(),
02061                                     *hLarge, px, 0 );
02062                 // Draw the remaining fill
02063                 p->fillRect(r.x()+pixmapWidth, r.y(), r.width()-pixmapWidth, 
02064                         r.height(), clr.dark(110));
02065 
02066             } else
02067                 p->fillRect(r, clr.dark(110));
02068         }
02069 
02070     } else {
02071         // Vertical gradient
02072         // -----------------
02073         int height = (pheight != -1) ? pheight : r.height();
02074 
02075         if (height <= 24)
02076             p->drawTiledPixmap(r, *grSet->gradient(VSmall), QPoint(0, py));
02077         else if (height <= 34)
02078             p->drawTiledPixmap(r, *grSet->gradient(VMed), QPoint(0, py));
02079         else if (height <= 64)
02080             p->drawTiledPixmap(r, *grSet->gradient(VLarge), QPoint(0, py));
02081         else {
02082             KPixmap *vLarge = grSet->gradient(VLarge);
02083 
02084             // Only draw the upper gradient if we need to.
02085             if (vLarge->height() > py)
02086             {
02087                 int pixmapHeight = vLarge->height() - py;
02088 
02089                 // Draw the gradient
02090                 p->drawTiledPixmap( r.x(), r.y(), r.width(), pixmapHeight,
02091                                     *vLarge, 0, py );
02092                 // Draw the remaining fill
02093                 p->fillRect(r.x(), r.y()+pixmapHeight, r.width(), 
02094                         r.height()-pixmapHeight, clr.dark(110));
02095 
02096             } else
02097                 p->fillRect(r, clr.dark(110));
02098         }
02099     }
02100 }
02101 
02102 
02103 // vim: set noet ts=4 sw=4:
02104 

KStyles

Skip menu "KStyles"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KCMShell
  • KNotify
  • KStyles
  • Nepomuk Daemons
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal