00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include "config.h"
00028 #endif
00029
00030 #include "kstyle.h"
00031
00032 #include <qapplication.h>
00033 #include <qbitmap.h>
00034 #include <qcleanuphandler.h>
00035 #include <qmap.h>
00036 #include <qimage.h>
00037 #include <qlistview.h>
00038 #include <qmenubar.h>
00039 #include <qpainter.h>
00040 #include <qpixmap.h>
00041 #include <qpopupmenu.h>
00042 #include <qprogressbar.h>
00043 #include <qscrollbar.h>
00044 #include <qsettings.h>
00045 #include <qslider.h>
00046 #include <qstylefactory.h>
00047 #include <qtabbar.h>
00048 #include <qtoolbar.h>
00049
00050 #include <kpixmap.h>
00051 #include <kpixmapeffect.h>
00052 #include <kimageeffect.h>
00053
00054 #ifdef Q_WS_X11
00055 # include <X11/Xlib.h>
00056 # ifdef HAVE_XRENDER
00057 # include <X11/extensions/Xrender.h>
00058 extern bool qt_use_xrender;
00059 # endif
00060 #else
00061 #undef HAVE_XRENDER
00062 #endif
00063
00064
00065 #include <limits.h>
00066
00067 namespace
00068 {
00069
00070 enum TransparencyEngine {
00071 Disabled = 0,
00072 SoftwareTint,
00073 SoftwareBlend,
00074 XRender
00075 };
00076
00077
00078 struct ShadowElements {
00079 QWidget* w1;
00080 QWidget* w2;
00081 };
00082 typedef QMap<const QPopupMenu*,ShadowElements> ShadowMap;
00083 static ShadowMap *_shadowMap = 0;
00084 QSingleCleanupHandler<ShadowMap> cleanupShadowMap;
00085 ShadowMap &shadowMap() {
00086 if ( !_shadowMap ) {
00087 _shadowMap = new ShadowMap;
00088 cleanupShadowMap.set( &_shadowMap );
00089 }
00090 return *_shadowMap;
00091 }
00092
00093
00094
00095
00096 const double top_right_corner[16] =
00097 { 0.949, 0.965, 0.980, 0.992,
00098 0.851, 0.890, 0.945, 0.980,
00099 0.706, 0.780, 0.890, 0.960,
00100 0.608, 0.706, 0.851, 0.949 };
00101
00102 const double bottom_right_corner[16] =
00103 { 0.608, 0.706, 0.851, 0.949,
00104 0.706, 0.780, 0.890, 0.960,
00105 0.851, 0.890, 0.945, 0.980,
00106 0.949, 0.965, 0.980, 0.992 };
00107
00108 const double bottom_left_corner[16] =
00109 { 0.949, 0.851, 0.706, 0.608,
00110 0.965, 0.890, 0.780, 0.706,
00111 0.980, 0.945, 0.890, 0.851,
00112 0.992, 0.980, 0.960, 0.949 };
00113
00114 const double shadow_strip[4] =
00115 { 0.565, 0.675, 0.835, 0.945 };
00116 }
00117
00118
00119 namespace
00120 {
00121 class TransparencyHandler : public QObject
00122 {
00123 public:
00124 TransparencyHandler(KStyle* style, TransparencyEngine tEngine,
00125 float menuOpacity, bool useDropShadow);
00126 ~TransparencyHandler();
00127 bool eventFilter(QObject* object, QEvent* event);
00128
00129 protected:
00130 void blendToColor(const QColor &col);
00131 void blendToPixmap(const QColorGroup &cg, const QPopupMenu* p);
00132 #ifdef HAVE_XRENDER
00133 void XRenderBlendToPixmap(const QPopupMenu* p);
00134 #endif
00135 void createShadowWindows(const QPopupMenu* p);
00136 void removeShadowWindows(const QPopupMenu* p);
00137 void rightShadow(QImage& dst);
00138 void bottomShadow(QImage& dst);
00139 private:
00140 bool dropShadow;
00141 float opacity;
00142 QPixmap pix;
00143 KStyle* kstyle;
00144 TransparencyEngine te;
00145 };
00146 }
00147
00148 struct KStylePrivate
00149 {
00150 bool highcolor : 1;
00151 bool useFilledFrameWorkaround : 1;
00152 bool etchDisabledText : 1;
00153 bool scrollablePopupmenus : 1;
00154 bool menuAltKeyNavigation : 1;
00155 bool menuDropShadow : 1;
00156 bool sloppySubMenus : 1;
00157 bool semiTransparentRubberband : 1;
00158 int popupMenuDelay;
00159 float menuOpacity;
00160
00161 TransparencyEngine transparencyEngine;
00162 KStyle::KStyleScrollBarType scrollbarType;
00163 TransparencyHandler* menuHandler;
00164 KStyle::KStyleFlags flags;
00165
00166
00167 QBitmap *verticalLine;
00168 QBitmap *horizontalLine;
00169 };
00170
00171
00172
00173
00174 KStyle::KStyle( KStyleFlags flags, KStyleScrollBarType sbtype )
00175 : QCommonStyle(), d(new KStylePrivate)
00176 {
00177 d->flags = flags;
00178 bool useMenuTransparency = (flags & AllowMenuTransparency);
00179 d->useFilledFrameWorkaround = (flags & FilledFrameWorkaround);
00180 d->scrollbarType = sbtype;
00181 d->highcolor = QPixmap::defaultDepth() > 8;
00182
00183
00184 QSettings settings;
00185 d->popupMenuDelay = settings.readNumEntry ("/KStyle/Settings/PopupMenuDelay", 256);
00186 d->sloppySubMenus = settings.readBoolEntry("/KStyle/Settings/SloppySubMenus", false);
00187 d->etchDisabledText = settings.readBoolEntry("/KStyle/Settings/EtchDisabledText", true);
00188 d->menuAltKeyNavigation = settings.readBoolEntry("/KStyle/Settings/MenuAltKeyNavigation", true);
00189 d->scrollablePopupmenus = settings.readBoolEntry("/KStyle/Settings/ScrollablePopupMenus", false);
00190 d->menuDropShadow = settings.readBoolEntry("/KStyle/Settings/MenuDropShadow", false);
00191 d->semiTransparentRubberband = settings.readBoolEntry("/KStyle/Settings/SemiTransparentRubberband", false);
00192 d->menuHandler = NULL;
00193
00194 if (useMenuTransparency) {
00195 QString effectEngine = settings.readEntry("/KStyle/Settings/MenuTransparencyEngine", "Disabled");
00196
00197 #ifdef HAVE_XRENDER
00198 if (effectEngine == "XRender")
00199 d->transparencyEngine = XRender;
00200 #else
00201 if (effectEngine == "XRender")
00202 d->transparencyEngine = SoftwareBlend;
00203 #endif
00204 else if (effectEngine == "SoftwareBlend")
00205 d->transparencyEngine = SoftwareBlend;
00206 else if (effectEngine == "SoftwareTint")
00207 d->transparencyEngine = SoftwareTint;
00208 else
00209 d->transparencyEngine = Disabled;
00210
00211 if (d->transparencyEngine != Disabled) {
00212
00213 d->menuOpacity = settings.readDoubleEntry("/KStyle/Settings/MenuOpacity", 0.90);
00214 d->menuHandler = new TransparencyHandler(this, d->transparencyEngine,
00215 d->menuOpacity, d->menuDropShadow);
00216 }
00217 }
00218
00219 d->verticalLine = 0;
00220 d->horizontalLine = 0;
00221
00222
00223 if (!d->menuHandler && d->menuDropShadow)
00224 d->menuHandler = new TransparencyHandler(this, Disabled, 1.0, d->menuDropShadow);
00225 }
00226
00227
00228 KStyle::~KStyle()
00229 {
00230 delete d->verticalLine;
00231 delete d->horizontalLine;
00232
00233 delete d->menuHandler;
00234
00235 d->menuHandler = NULL;
00236 delete d;
00237 }
00238
00239
00240 QString KStyle::defaultStyle()
00241 {
00242 if (QPixmap::defaultDepth() > 8)
00243 return QString("plastik");
00244 else
00245 return QString("light, 3rd revision");
00246 }
00247
00248
00249 void KStyle::polish( QWidget* widget )
00250 {
00251 if ( d->useFilledFrameWorkaround )
00252 {
00253 if ( QFrame *frame = ::qt_cast< QFrame* >( widget ) ) {
00254 QFrame::Shape shape = frame->frameShape();
00255 if (shape == QFrame::ToolBarPanel || shape == QFrame::MenuBarPanel)
00256 widget->installEventFilter(this);
00257 }
00258 }
00259 }
00260
00261
00262 void KStyle::unPolish( QWidget* widget )
00263 {
00264 if ( d->useFilledFrameWorkaround )
00265 {
00266 if ( QFrame *frame = ::qt_cast< QFrame* >( widget ) ) {
00267 QFrame::Shape shape = frame->frameShape();
00268 if (shape == QFrame::ToolBarPanel || shape == QFrame::MenuBarPanel)
00269 widget->removeEventFilter(this);
00270 }
00271 }
00272 }
00273
00274
00275
00276 void KStyle::polishPopupMenu( QPopupMenu* p )
00277 {
00278 if (!p->testWState( WState_Polished ))
00279 p->setCheckable(true);
00280
00281
00282 if ( d->menuHandler &&
00283 (strcmp(p->name(), "tear off menu") != 0))
00284 p->installEventFilter(d->menuHandler);
00285 }
00286
00287
00288
00289
00290
00291
00292 void KStyle::setScrollBarType(KStyleScrollBarType sbtype)
00293 {
00294 d->scrollbarType = sbtype;
00295 }
00296
00297 KStyle::KStyleFlags KStyle::styleFlags() const
00298 {
00299 return d->flags;
00300 }
00301
00302 void KStyle::renderMenuBlendPixmap( KPixmap &pix, const QColorGroup &cg,
00303 const QPopupMenu* ) const
00304 {
00305 pix.fill(cg.button());
00306 }
00307
00308
00309 void KStyle::drawKStylePrimitive( KStylePrimitive kpe,
00310 QPainter* p,
00311 const QWidget* widget,
00312 const QRect &r,
00313 const QColorGroup &cg,
00314 SFlags flags,
00315 const QStyleOption& ) const
00316 {
00317 switch( kpe )
00318 {
00319
00320
00321
00322 case KPE_DockWindowHandle: {
00323
00324
00325 QWidget* wid = const_cast<QWidget*>(widget);
00326 bool horizontal = flags & Style_Horizontal;
00327 int x,y,w,h,x2,y2;
00328
00329 r.rect( &x, &y, &w, &h );
00330 if ((w <= 2) || (h <= 2)) {
00331 p->fillRect(r, cg.highlight());
00332 return;
00333 }
00334
00335
00336 x2 = x + w - 1;
00337 y2 = y + h - 1;
00338
00339 QFont fnt;
00340 fnt = QApplication::font(wid);
00341 fnt.setPointSize( fnt.pointSize()-2 );
00342
00343
00344
00345
00346 QPixmap pix;
00347 if (horizontal)
00348 pix.resize( h-2, w-2 );
00349 else
00350 pix.resize( w-2, h-2 );
00351
00352 QString title = wid->parentWidget()->caption();
00353 QPainter p2;
00354 p2.begin(&pix);
00355 p2.fillRect(pix.rect(), cg.brush(QColorGroup::Highlight));
00356 p2.setPen(cg.highlightedText());
00357 p2.setFont(fnt);
00358 p2.drawText(pix.rect(), AlignCenter, title);
00359 p2.end();
00360
00361
00362 p->setPen(cg.dark());
00363 p->drawLine(x, y, x2, y);
00364 p->drawLine(x, y, x, y2);
00365 p->setPen(cg.light());
00366 p->drawLine(x+1, y2, x2, y2);
00367 p->drawLine(x2, y+1, x2, y2);
00368
00369 if (horizontal) {
00370 QWMatrix m;
00371 m.rotate(-90.0);
00372 QPixmap vpix = pix.xForm(m);
00373 bitBlt(wid, r.x()+1, r.y()+1, &vpix);
00374 } else
00375 bitBlt(wid, r.x()+1, r.y()+1, &pix);
00376
00377 break;
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387 case KPE_ListViewExpander: {
00388
00389 int radius = (r.width() - 4) / 2;
00390 int centerx = r.x() + r.width()/2;
00391 int centery = r.y() + r.height()/2;
00392
00393
00394 p->setPen( cg.mid() );
00395 p->drawRect( r );
00396
00397
00398 p->setPen( cg.text() );
00399 p->drawLine( centerx - radius, centery, centerx + radius, centery );
00400 if ( flags & Style_On )
00401 p->drawLine( centerx, centery - radius, centerx, centery + radius );
00402 break;
00403 }
00404
00405 case KPE_ListViewBranch: {
00406
00407
00408
00409 if ( !d->verticalLine )
00410 {
00411
00412
00413 d->verticalLine = new QBitmap( 1, 129, true );
00414 d->horizontalLine = new QBitmap( 128, 1, true );
00415 QPointArray a( 64 );
00416 QPainter p2;
00417 p2.begin( d->verticalLine );
00418
00419 int i;
00420 for( i=0; i < 64; i++ )
00421 a.setPoint( i, 0, i*2+1 );
00422 p2.setPen( color1 );
00423 p2.drawPoints( a );
00424 p2.end();
00425 QApplication::flushX();
00426 d->verticalLine->setMask( *d->verticalLine );
00427
00428 p2.begin( d->horizontalLine );
00429 for( i=0; i < 64; i++ )
00430 a.setPoint( i, i*2+1, 0 );
00431 p2.setPen( color1 );
00432 p2.drawPoints( a );
00433 p2.end();
00434 QApplication::flushX();
00435 d->horizontalLine->setMask( *d->horizontalLine );
00436 }
00437
00438 p->setPen( cg.text() );
00439
00440 if (flags & Style_Horizontal)
00441 {
00442 int point = r.x();
00443 int other = r.y();
00444 int end = r.x()+r.width();
00445 int thickness = r.height();
00446
00447 while( point < end )
00448 {
00449 int i = 128;
00450 if ( i+point > end )
00451 i = end-point;
00452 p->drawPixmap( point, other, *d->horizontalLine, 0, 0, i, thickness );
00453 point += i;
00454 }
00455
00456 } else {
00457 int point = r.y();
00458 int other = r.x();
00459 int end = r.y()+r.height();
00460 int thickness = r.width();
00461 int pixmapoffset = (flags & Style_NoChange) ? 0 : 1;
00462
00463 while( point < end )
00464 {
00465 int i = 128;
00466 if ( i+point > end )
00467 i = end-point;
00468 p->drawPixmap( other, point, *d->verticalLine, 0, pixmapoffset, thickness, i );
00469 point += i;
00470 }
00471 }
00472
00473 break;
00474 }
00475
00476
00477
00478 case KPE_ToolBarHandle:
00479 case KPE_GeneralHandle:
00480 case KPE_SliderHandle:
00481 p->fillRect(r, cg.light());
00482 break;
00483
00484 case KPE_SliderGroove:
00485 p->fillRect(r, cg.dark());
00486 break;
00487
00488 default:
00489 p->fillRect(r, Qt::yellow);
00490 break;
00491 }
00492 }
00493
00494
00495 int KStyle::kPixelMetric( KStylePixelMetric kpm, const QWidget* ) const
00496 {
00497 int value;
00498 switch(kpm)
00499 {
00500 case KPM_ListViewBranchThickness:
00501 value = 1;
00502 break;
00503
00504 case KPM_MenuItemSeparatorHeight:
00505 case KPM_MenuItemHMargin:
00506 case KPM_MenuItemVMargin:
00507 case KPM_MenuItemHFrame:
00508 case KPM_MenuItemVFrame:
00509 case KPM_MenuItemCheckMarkHMargin:
00510 case KPM_MenuItemArrowHMargin:
00511 case KPM_MenuItemTabSpacing:
00512 default:
00513 value = 0;
00514 }
00515
00516 return value;
00517 }
00518
00519
00520
00521
00522 void KStyle::drawPrimitive( PrimitiveElement pe,
00523 QPainter* p,
00524 const QRect &r,
00525 const QColorGroup &cg,
00526 SFlags flags,
00527 const QStyleOption& opt ) const
00528 {
00529
00530
00531 if (pe == PE_DockWindowHandle)
00532 {
00533
00534 QWidget *widget, *parent;
00535
00536 if (p && p->device()->devType() == QInternal::Widget) {
00537 widget = static_cast<QWidget*>(p->device());
00538 parent = widget->parentWidget();
00539 } else
00540 return;
00541
00542
00543 if ( parent &&
00544 (parent->inherits("QToolBar") ||
00545 (parent->inherits("QMainWindow")) ))
00546
00547
00548 drawKStylePrimitive( KPE_ToolBarHandle, p, widget, r, cg, flags, opt );
00549
00550 else if ( widget->inherits("QDockWindowHandle") )
00551
00552
00553 drawKStylePrimitive( KPE_DockWindowHandle, p, widget, r, cg, flags, opt );
00554
00555 else
00556
00557 drawKStylePrimitive( KPE_GeneralHandle, p, widget, r, cg, flags, opt );
00558 #if QT_VERSION >= 0x030300
00559 #ifdef HAVE_XRENDER
00560 } else if ( d->semiTransparentRubberband && pe == QStyle::PE_RubberBand ) {
00561 QRect rect = r.normalize();
00562 QPoint point;
00563 point = p->xForm( point );
00564
00565 static XRenderColor clr = { 0, 0, 0, 0 };
00566 static unsigned long fillColor = 0;
00567 if ( fillColor != cg.highlight().rgb() ) {
00568 fillColor = cg.highlight().rgb();
00569
00570 unsigned long color = fillColor << 8 | 0x40;
00571
00572 int red = (color >> 24) & 0xff;
00573 int green = (color >> 16) & 0xff;
00574 int blue = (color >> 8) & 0xff;
00575 int alpha = (color >> 0) & 0xff;
00576
00577 red = red * alpha / 255;
00578 green = green * alpha / 255;
00579 blue = blue * alpha / 255;
00580
00581 clr.red = (red << 8) + red;
00582 clr.green = (green << 8) + green;
00583 clr.blue = (blue << 8) + blue;
00584 clr.alpha = (alpha << 8) + alpha;
00585 }
00586
00587 XRenderFillRectangle(
00588 p->device()->x11Display(),
00589 PictOpOver,
00590 p->device()->x11RenderHandle(),
00591 &clr,
00592 rect.x() + point.x(),
00593 rect.y() + point.y(),
00594 rect.width(),
00595 rect.height() );
00596
00597 p->save();
00598 p->setRasterOp( Qt::CopyROP );
00599 p->setPen( QPen( cg.highlight().dark( 160 ), 1 ) );
00600 p->setBrush( NoBrush );
00601 p->drawRect(
00602 rect.x() + point.x(),
00603 rect.y() + point.y(),
00604 rect.width(),
00605 rect.height() );
00606 p->restore();
00607 #endif
00608 #endif
00609 } else
00610 QCommonStyle::drawPrimitive( pe, p, r, cg, flags, opt );
00611 }
00612
00613
00614
00615 void KStyle::drawControl( ControlElement element,
00616 QPainter* p,
00617 const QWidget* widget,
00618 const QRect &r,
00619 const QColorGroup &cg,
00620 SFlags flags,
00621 const QStyleOption &opt ) const
00622 {
00623 switch (element)
00624 {
00625
00626
00627 case CE_TabBarTab: {
00628 const QTabBar* tb = (const QTabBar*) widget;
00629 QTabBar::Shape tbs = tb->shape();
00630 bool selected = flags & Style_Selected;
00631 int x = r.x(), y=r.y(), bottom=r.bottom(), right=r.right();
00632
00633 switch (tbs) {
00634
00635 case QTabBar::RoundedAbove: {
00636 if (!selected)
00637 p->translate(0,1);
00638 p->setPen(selected ? cg.light() : cg.shadow());
00639 p->drawLine(x, y+4, x, bottom);
00640 p->drawLine(x, y+4, x+4, y);
00641 p->drawLine(x+4, y, right-1, y);
00642 if (selected)
00643 p->setPen(cg.shadow());
00644 p->drawLine(right, y+1, right, bottom);
00645
00646 p->setPen(cg.midlight());
00647 p->drawLine(x+1, y+4, x+1, bottom);
00648 p->drawLine(x+1, y+4, x+4, y+1);
00649 p->drawLine(x+5, y+1, right-2, y+1);
00650
00651 if (selected) {
00652 p->setPen(cg.mid());
00653 p->drawLine(right-1, y+1, right-1, bottom);
00654 } else {
00655 p->setPen(cg.mid());
00656 p->drawPoint(right-1, y+1);
00657 p->drawLine(x+4, y+2, right-1, y+2);
00658 p->drawLine(x+3, y+3, right-1, y+3);
00659 p->fillRect(x+2, y+4, r.width()-3, r.height()-6, cg.mid());
00660
00661 p->setPen(cg.light());
00662 p->drawLine(x, bottom-1, right, bottom-1);
00663 p->translate(0,-1);
00664 }
00665 break;
00666 }
00667
00668 case QTabBar::RoundedBelow: {
00669 if (!selected)
00670 p->translate(0,-1);
00671 p->setPen(selected ? cg.light() : cg.shadow());
00672 p->drawLine(x, bottom-4, x, y);
00673 if (selected)
00674 p->setPen(cg.mid());
00675 p->drawLine(x, bottom-4, x+4, bottom);
00676 if (selected)
00677 p->setPen(cg.shadow());
00678 p->drawLine(x+4, bottom, right-1, bottom);
00679 p->drawLine(right, bottom-1, right, y);
00680
00681 p->setPen(cg.midlight());
00682 p->drawLine(x+1, bottom-4, x+1, y);
00683 p->drawLine(x+1, bottom-4, x+4, bottom-1);
00684 p->drawLine(x+5, bottom-1, right-2, bottom-1);
00685
00686 if (selected) {
00687 p->setPen(cg.mid());
00688 p->drawLine(right-1, y, right-1, bottom-1);
00689 } else {
00690 p->setPen(cg.mid());
00691 p->drawPoint(right-1, bottom-1);
00692 p->drawLine(x+4, bottom-2, right-1, bottom-2);
00693 p->drawLine(x+3, bottom-3, right-1, bottom-3);
00694 p->fillRect(x+2, y+2, r.width()-3, r.height()-6, cg.mid());
00695 p->translate(0,1);
00696 p->setPen(cg.dark());
00697 p->drawLine(x, y, right, y);
00698 }
00699 break;
00700 }
00701
00702 case QTabBar::TriangularAbove: {
00703 if (!selected)
00704 p->translate(0,1);
00705 p->setPen(selected ? cg.light() : cg.shadow());
00706 p->drawLine(x, bottom, x, y+6);
00707 p->drawLine(x, y+6, x+6, y);
00708 p->drawLine(x+6, y, right-6, y);
00709 if (selected)
00710 p->setPen(cg.mid());
00711 p->drawLine(right-5, y+1, right-1, y+5);
00712 p->setPen(cg.shadow());
00713 p->drawLine(right, y+6, right, bottom);
00714
00715 p->setPen(cg.midlight());
00716 p->drawLine(x+1, bottom, x+1, y+6);
00717 p->drawLine(x+1, y+6, x+6, y+1);
00718 p->drawLine(x+6, y+1, right-6, y+1);
00719 p->drawLine(right-5, y+2, right-2, y+5);
00720 p->setPen(cg.mid());
00721 p->drawLine(right-1, y+6, right-1, bottom);
00722
00723 QPointArray a(6);
00724 a.setPoint(0, x+2, bottom);
00725 a.setPoint(1, x+2, y+7);
00726 a.setPoint(2, x+7, y+2);
00727 a.setPoint(3, right-7, y+2);
00728 a.setPoint(4, right-2, y+7);
00729 a.setPoint(5, right-2, bottom);
00730 p->setPen (selected ? cg.background() : cg.mid());
00731 p->setBrush(selected ? cg.background() : cg.mid());
00732 p->drawPolygon(a);
00733 p->setBrush(NoBrush);
00734 if (!selected) {
00735 p->translate(0,-1);
00736 p->setPen(cg.light());
00737 p->drawLine(x, bottom, right, bottom);
00738 }
00739 break;
00740 }
00741
00742 default: {
00743 if (!selected)
00744 p->translate(0,-1);
00745 p->setPen(selected ? cg.light() : cg.shadow());
00746 p->drawLine(x, y, x, bottom-6);
00747 if (selected)
00748 p->setPen(cg.mid());
00749 p->drawLine(x, bottom-6, x+6, bottom);
00750 if (selected)
00751 p->setPen(cg.shadow());
00752 p->drawLine(x+6, bottom, right-6, bottom);
00753 p->drawLine(right-5, bottom-1, right-1, bottom-5);
00754 if (!selected)
00755 p->setPen(cg.shadow());
00756 p->drawLine(right, bottom-6, right, y);
00757
00758 p->setPen(cg.midlight());
00759 p->drawLine(x+1, y, x+1, bottom-6);
00760 p->drawLine(x+1, bottom-6, x+6, bottom-1);
00761 p->drawLine(x+6, bottom-1, right-6, bottom-1);
00762 p->drawLine(right-5, bottom-2, right-2, bottom-5);
00763 p->setPen(cg.mid());
00764 p->drawLine(right-1, bottom-6, right-1, y);
00765
00766 QPointArray a(6);
00767 a.setPoint(0, x+2, y);
00768 a.setPoint(1, x+2, bottom-7);
00769 a.setPoint(2, x+7, bottom-2);
00770 a.setPoint(3, right-7, bottom-2);
00771 a.setPoint(4, right-2, bottom-7);
00772 a.setPoint(5, right-2, y);
00773 p->setPen (selected ? cg.background() : cg.mid());
00774 p->setBrush(selected ? cg.background() : cg.mid());
00775 p->drawPolygon(a);
00776 p->setBrush(NoBrush);
00777 if (!selected) {
00778 p->translate(0,1);
00779 p->setPen(cg.dark());
00780 p->drawLine(x, y, right, y);
00781 }
00782 break;
00783 }
00784 };
00785
00786 break;
00787 }
00788
00789
00790
00791 case CE_PopupMenuScroller: {
00792 p->fillRect(r, cg.background());
00793 drawPrimitive(PE_ButtonTool, p, r, cg, Style_Enabled);
00794 drawPrimitive((flags & Style_Up) ? PE_ArrowUp : PE_ArrowDown, p, r, cg, Style_Enabled);
00795 break;
00796 }
00797
00798
00799
00800
00801 case CE_ProgressBarGroove: {
00802 QRect fr = subRect(SR_ProgressBarGroove, widget);
00803 drawPrimitive(PE_Panel, p, fr, cg, Style_Sunken, QStyleOption::Default);
00804 break;
00805 }
00806
00807 case CE_ProgressBarContents: {
00808
00809 const QProgressBar* pb = (const QProgressBar*)widget;
00810 QRect cr = subRect(SR_ProgressBarContents, widget);
00811 double progress = pb->progress();
00812 bool reverse = QApplication::reverseLayout();
00813 int steps = pb->totalSteps();
00814
00815 if (!cr.isValid())
00816 return;
00817
00818
00819 if (progress > 0 || steps == 0) {
00820 double pg = (steps == 0) ? 0.1 : progress / steps;
00821 int width = QMIN(cr.width(), (int)(pg * cr.width()));
00822 if (steps == 0) {
00823
00824 if (width < 1) width = 1;
00825
00826 int remWidth = cr.width() - width;
00827 if (remWidth <= 0) remWidth = 1;
00828
00829 int pstep = int(progress) % ( 2 * remWidth );
00830
00831 if ( pstep > remWidth ) {
00832
00833
00834 pstep = - (pstep - 2 * remWidth );
00835 }
00836
00837 if (reverse)
00838 p->fillRect(cr.x() + cr.width() - width - pstep, cr.y(), width, cr.height(),
00839 cg.brush(QColorGroup::Highlight));
00840 else
00841 p->fillRect(cr.x() + pstep, cr.y(), width, cr.height(),
00842 cg.brush(QColorGroup::Highlight));
00843
00844 return;
00845 }
00846
00847
00848
00849 if (d->highcolor) {
00850 QColor c(cg.highlight());
00851 KPixmap pix;
00852 pix.resize(cr.width(), cr.height());
00853 KPixmapEffect::gradient(pix, reverse ? c.light(150) : c.dark(150),
00854 reverse ? c.dark(150) : c.light(150),
00855 KPixmapEffect::HorizontalGradient);
00856 if (reverse)
00857 p->drawPixmap(cr.x()+(cr.width()-width), cr.y(), pix,
00858 cr.width()-width, 0, width, cr.height());
00859 else
00860 p->drawPixmap(cr.x(), cr.y(), pix, 0, 0, width, cr.height());
00861 } else
00862 if (reverse)
00863 p->fillRect(cr.x()+(cr.width()-width), cr.y(), width, cr.height(),
00864 cg.brush(QColorGroup::Highlight));
00865 else
00866 p->fillRect(cr.x(), cr.y(), width, cr.height(),
00867 cg.brush(QColorGroup::Highlight));
00868 }
00869 break;
00870 }
00871
00872 case CE_ProgressBarLabel: {
00873 const QProgressBar* pb = (const QProgressBar*)widget;
00874 QRect cr = subRect(SR_ProgressBarContents, widget);
00875 double progress = pb->progress();
00876 bool reverse = QApplication::reverseLayout();
00877 int steps = pb->totalSteps();
00878
00879 if (!cr.isValid())
00880 return;
00881
00882 QFont font = p->font();
00883 font.setBold(true);
00884 p->setFont(font);
00885
00886
00887 if (progress > 0 || steps == 0) {
00888 double pg = (steps == 0) ? 1.0 : progress / steps;
00889 int width = QMIN(cr.width(), (int)(pg * cr.width()));
00890 QRect crect;
00891 if (reverse)
00892 crect.setRect(cr.x()+(cr.width()-width), cr.y(), cr.width(), cr.height());
00893 else
00894 crect.setRect(cr.x()+width, cr.y(), cr.width(), cr.height());
00895
00896 p->save();
00897 p->setPen(pb->isEnabled() ? (reverse ? cg.text() : cg.highlightedText()) : cg.text());
00898 p->drawText(r, AlignCenter, pb->progressString());
00899 p->setClipRect(crect);
00900 p->setPen(reverse ? cg.highlightedText() : cg.text());
00901 p->drawText(r, AlignCenter, pb->progressString());
00902 p->restore();
00903
00904 } else {
00905 p->setPen(cg.text());
00906 p->drawText(r, AlignCenter, pb->progressString());
00907 }
00908
00909 break;
00910 }
00911
00912 default:
00913 QCommonStyle::drawControl(element, p, widget, r, cg, flags, opt);
00914 }
00915 }
00916
00917
00918 QRect KStyle::subRect(SubRect r, const QWidget* widget) const
00919 {
00920 switch(r)
00921 {
00922
00923
00924 case SR_ProgressBarGroove:
00925 return widget->rect();
00926
00927 case SR_ProgressBarContents:
00928 case SR_ProgressBarLabel: {
00929
00930 QRect rt = widget->rect();
00931 return QRect(rt.x()+2, rt.y()+2, rt.width()-4, rt.height()-4);
00932 }
00933
00934 default:
00935 return QCommonStyle::subRect(r, widget);
00936 }
00937 }
00938
00939
00940 int KStyle::pixelMetric(PixelMetric m, const QWidget* widget) const
00941 {
00942 switch(m)
00943 {
00944
00945
00946 case PM_ButtonShiftHorizontal:
00947 case PM_ButtonShiftVertical:
00948 return 1;
00949
00950 case PM_DockWindowHandleExtent:
00951 {
00952 QWidget* parent = 0;
00953
00954
00955 if (widget && (parent = widget->parentWidget() )
00956 && !parent->inherits("QToolBar")
00957 && !parent->inherits("QMainWindow")
00958 && widget->inherits("QDockWindowHandle") )
00959 return widget->fontMetrics().lineSpacing();
00960 else
00961 return QCommonStyle::pixelMetric(m, widget);
00962 }
00963
00964
00965
00966 case PM_TabBarTabHSpace:
00967 return 24;
00968
00969 case PM_TabBarTabVSpace: {
00970 const QTabBar * tb = (const QTabBar *) widget;
00971 if ( tb->shape() == QTabBar::RoundedAbove ||
00972 tb->shape() == QTabBar::RoundedBelow )
00973 return 10;
00974 else
00975 return 4;
00976 }
00977
00978 case PM_TabBarTabOverlap: {
00979 const QTabBar* tb = (const QTabBar*)widget;
00980 QTabBar::Shape tbs = tb->shape();
00981
00982 if ( (tbs == QTabBar::RoundedAbove) ||
00983 (tbs == QTabBar::RoundedBelow) )
00984 return 0;
00985 else
00986 return 2;
00987 }
00988
00989
00990
00991 case PM_SliderLength:
00992 return 18;
00993
00994 case PM_SliderThickness:
00995 return 24;
00996
00997
00998
00999 case PM_SliderControlThickness: {
01000 const QSlider* slider = (const QSlider*)widget;
01001 QSlider::TickSetting ts = slider->tickmarks();
01002 int thickness = (slider->orientation() == Horizontal) ?
01003 slider->height() : slider->width();
01004 switch (ts) {
01005 case QSlider::NoMarks:
01006 break;
01007 case QSlider::Both:
01008 thickness = (thickness/2) + 3;
01009 break;
01010 default:
01011 thickness = ((thickness*2)/3) + 3;
01012 break;
01013 };
01014 return thickness;
01015 }
01016
01017
01018
01019 case PM_SplitterWidth:
01020 if (widget && widget->inherits("QDockWindowResizeHandle"))
01021 return 8;
01022 else
01023 return 6;
01024
01025
01026
01027 case PM_MenuBarFrameWidth:
01028 return 1;
01029
01030 case PM_DockWindowFrameWidth:
01031 return 1;
01032
01033
01034
01035 case PM_MaximumDragDistance:
01036 return -1;
01037
01038 #if QT_VERSION >= 0x030300
01039 case PM_MenuBarItemSpacing:
01040 return 5;
01041
01042 case PM_ToolBarItemSpacing:
01043 return 0;
01044 #endif
01045 case PM_PopupMenuScrollerHeight:
01046 return pixelMetric( PM_ScrollBarExtent, 0);
01047
01048 default:
01049 return QCommonStyle::pixelMetric( m, widget );
01050 }
01051 }
01052
01053
01054 static QListViewItem* nextVisibleSibling(QListViewItem* item)
01055 {
01056 QListViewItem* sibling = item;
01057 do
01058 {
01059 sibling = sibling->nextSibling();
01060 }
01061 while (sibling && !sibling->isVisible());
01062
01063 return sibling;
01064 }
01065
01066 void KStyle::drawComplexControl( ComplexControl control,
01067 QPainter* p,
01068 const QWidget* widget,
01069 const QRect &r,
01070 const QColorGroup &cg,
01071 SFlags flags,
01072 SCFlags controls,
01073 SCFlags active,
01074 const QStyleOption &opt ) const
01075 {
01076 switch(control)
01077 {
01078
01079
01080 case CC_ScrollBar: {
01081
01082 bool useThreeButtonScrollBar = (d->scrollbarType & ThreeButtonScrollBar);
01083
01084 const QScrollBar *sb = (const QScrollBar*)widget;
01085 bool maxedOut = (sb->minValue() == sb->maxValue());
01086 bool horizontal = (sb->orientation() == Qt::Horizontal);
01087 SFlags sflags = ((horizontal ? Style_Horizontal : Style_Default) |
01088 (maxedOut ? Style_Default : Style_Enabled));
01089
01090 QRect addline, subline, subline2, addpage, subpage, slider, first, last;
01091 subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt);
01092 addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt);
01093 subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt);
01094 addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt);
01095 slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt);
01096 first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt);
01097 last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt);
01098 subline2 = addline;
01099
01100 if ( useThreeButtonScrollBar )
01101 if (horizontal)
01102 subline2.moveBy(-addline.width(), 0);
01103 else
01104 subline2.moveBy(0, -addline.height());
01105
01106
01107 if ((controls & SC_ScrollBarSubLine) && subline.isValid()) {
01108 drawPrimitive(PE_ScrollBarSubLine, p, subline, cg,
01109 sflags | (active == SC_ScrollBarSubLine ?
01110 Style_Down : Style_Default));
01111
01112 if (useThreeButtonScrollBar && subline2.isValid())
01113 drawPrimitive(PE_ScrollBarSubLine, p, subline2, cg,
01114 sflags | (active == SC_ScrollBarSubLine ?
01115 Style_Down : Style_Default));
01116 }
01117
01118 if ((controls & SC_ScrollBarAddLine) && addline.isValid())
01119 drawPrimitive(PE_ScrollBarAddLine, p, addline, cg,
01120 sflags | ((active == SC_ScrollBarAddLine) ?
01121 Style_Down : Style_Default));
01122
01123 if ((controls & SC_ScrollBarSubPage) && subpage.isValid())
01124 drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg,
01125 sflags | ((active == SC_ScrollBarSubPage) ?
01126 Style_Down : Style_Default));
01127
01128 if ((controls & SC_ScrollBarAddPage) && addpage.isValid())
01129 drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg,
01130 sflags | ((active == SC_ScrollBarAddPage) ?
01131 Style_Down : Style_Default));
01132
01133 if ((controls & SC_ScrollBarFirst) && first.isValid())
01134 drawPrimitive(PE_ScrollBarFirst, p, first, cg,
01135 sflags | ((active == SC_ScrollBarFirst) ?
01136 Style_Down : Style_Default));
01137
01138 if ((controls & SC_ScrollBarLast) && last.isValid())
01139 drawPrimitive(PE_ScrollBarLast, p, last, cg,
01140 sflags | ((active == SC_ScrollBarLast) ?
01141 Style_Down : Style_Default));
01142
01143 if ((controls & SC_ScrollBarSlider) && slider.isValid()) {
01144 drawPrimitive(PE_ScrollBarSlider, p, slider, cg,
01145 sflags | ((active == SC_ScrollBarSlider) ?
01146 Style_Down : Style_Default));
01147
01148 if (sb->hasFocus()) {
01149 QRect fr(slider.x() + 2, slider.y() + 2,
01150 slider.width() - 5, slider.height() - 5);
01151 drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default);
01152 }
01153 }
01154 break;
01155 }
01156
01157
01158
01159
01160 case CC_Slider: {
01161 const QSlider* slider = (const QSlider*)widget;
01162 QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, opt);
01163 QRect handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, opt);
01164
01165
01166 QPixmap pix(widget->size());
01167 QPainter p2;
01168 p2.begin(&pix);
01169
01170 if ( slider->parentWidget() &&
01171 slider->parentWidget()->backgroundPixmap() &&
01172 !slider->parentWidget()->backgroundPixmap()->isNull() ) {
01173 QPixmap pixmap = *(slider->parentWidget()->backgroundPixmap());
01174 p2.drawTiledPixmap(r, pixmap, slider->pos());
01175 } else
01176 pix.fill(cg.background());
01177
01178
01179 if ((controls & SC_SliderGroove) && groove.isValid()) {
01180 drawKStylePrimitive( KPE_SliderGroove, &p2, widget, groove, cg, flags, opt );
01181
01182
01183 if (slider->hasFocus())
01184 drawPrimitive(PE_FocusRect, &p2, groove, cg);
01185 }
01186
01187
01188 if (controls & SC_SliderTickmarks)
01189 QCommonStyle::drawComplexControl(control, &p2, widget,
01190 r, cg, flags, SC_SliderTickmarks, active, opt);
01191
01192
01193 if ((controls & SC_SliderHandle) && handle.isValid()) {
01194 if (active == SC_SliderHandle)
01195 flags |= Style_Active;
01196 drawKStylePrimitive( KPE_SliderHandle, &p2, widget, handle, cg, flags, opt );
01197 }
01198
01199 p2.end();
01200 bitBlt((QWidget*)widget, r.x(), r.y(), &pix);
01201 break;
01202 }
01203
01204
01205
01206 case CC_ListView: {
01207
01208
01209
01210
01211
01212
01213
01214 if ( controls & SC_ListView )
01215 QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
01216
01217
01218 if ( controls & (SC_ListViewBranch | SC_ListViewExpand) )
01219 {
01220
01221 if (opt.isDefault())
01222 break;
01223
01224 QListViewItem *item = opt.listViewItem();
01225 QListViewItem *child = item->firstChild();
01226
01227 int y = r.y();
01228 int c;
01229 int dotoffset = 0;
01230 QPointArray dotlines;
01231
01232 if ( active == SC_All && controls == SC_ListViewExpand ) {
01233
01234 c = 2;
01235 dotlines.resize(2);
01236 dotlines[0] = QPoint( r.right(), r.top() );
01237 dotlines[1] = QPoint( r.right(), r.bottom() );
01238
01239 } else {
01240
01241 int linetop = 0, linebot = 0;
01242
01243 dotoffset = (item->itemPos() + item->height() - y) % 2;
01244 dotlines.resize( item->childCount() * 4 );
01245 c = 0;
01246
01247
01248 while ( child && y + child->height() <= 0 )
01249 {
01250 y += child->totalHeight();
01251 child = nextVisibleSibling(child);
01252 }
01253
01254 int bx = r.width() / 2;
01255
01256
01257 QListView* v = item->listView();
01258 int lh = QMAX( p->fontMetrics().height() + 2 * v->itemMargin(),
01259 QApplication::globalStrut().height() );
01260 if ( lh % 2 > 0 )
01261 lh++;
01262
01263
01264 QRect boxrect;
01265 QStyle::StyleFlags boxflags;
01266 while ( child && y < r.height() )
01267 {
01268 linebot = y + lh/2;
01269 if ( (child->isExpandable() || child->childCount()) &&
01270 (child->height() > 0) )
01271 {
01272
01273 boxrect = QRect( bx-4, linebot-4, 9, 9 );
01274 boxflags = child->isOpen() ? QStyle::Style_Off : QStyle::Style_On;
01275
01276
01277 drawKStylePrimitive( KPE_ListViewExpander, p, NULL, boxrect, cg, boxflags, opt );
01278
01279
01280 p->setPen( cg.mid() );
01281 dotlines[c++] = QPoint( bx, linetop );
01282 dotlines[c++] = QPoint( bx, linebot - 5 );
01283 dotlines[c++] = QPoint( bx + 5, linebot );
01284 dotlines[c++] = QPoint( r.width(), linebot );
01285 linetop = linebot + 5;
01286 } else {
01287
01288 dotlines[c++] = QPoint( bx+1, linebot );
01289 dotlines[c++] = QPoint( r.width(), linebot );
01290 }
01291
01292 y += child->totalHeight();
01293 child = nextVisibleSibling(child);
01294 }
01295
01296 if ( child )
01297 linebot = r.height();
01298
01299 if ( linetop < linebot )
01300 {
01301 dotlines[c++] = QPoint( bx, linetop );
01302 dotlines[c++] = QPoint( bx, linebot );
01303 }
01304 }
01305
01306
01307 static int thickness = kPixelMetric( KPM_ListViewBranchThickness );
01308 int line;
01309 QRect branchrect;
01310 QStyle::StyleFlags branchflags;
01311 for( line = 0; line < c; line += 2 )
01312 {
01313
01314
01315
01316
01317
01318
01319
01320 if ( dotlines[line].y() == dotlines[line+1].y() )
01321 {
01322
01323 int end = dotlines[line+1].x();
01324 int point = dotlines[line].x();
01325 int other = dotlines[line].y();
01326
01327 branchrect = QRect( point, other-(thickness/2), end-point, thickness );
01328 branchflags = QStyle::Style_Horizontal;
01329
01330
01331 drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
01332
01333 } else {
01334
01335 int end = dotlines[line+1].y();
01336 int point = dotlines[line].y();
01337 int other = dotlines[line].x();
01338 int pixmapoffset = ((point & 1) != dotoffset ) ? 1 : 0;
01339
01340 branchrect = QRect( other-(thickness/2), point, thickness, end-point );
01341 if (!pixmapoffset)
01342 branchflags = QStyle::Style_NoChange;
01343 else
01344 branchflags = QStyle::Style_Default;
01345
01346
01347 drawKStylePrimitive( KPE_ListViewBranch, p, NULL, branchrect, cg, branchflags, opt );
01348 }
01349 }
01350 }
01351 break;
01352 }
01353
01354 default:
01355 QCommonStyle::drawComplexControl( control, p, widget, r, cg,
01356 flags, controls, active, opt );
01357 break;
01358 }
01359 }
01360
01361
01362 QStyle::SubControl KStyle::querySubControl( ComplexControl control,
01363 const QWidget* widget,
01364 const QPoint &pos,
01365 const QStyleOption &opt ) const
01366 {
01367 QStyle::SubControl ret = QCommonStyle::querySubControl(control, widget, pos, opt);
01368
01369 if (d->scrollbarType == ThreeButtonScrollBar) {
01370
01371 if (control == CC_ScrollBar && ret == SC_None)
01372 ret = SC_ScrollBarSubLine;
01373 }
01374 return ret;
01375 }
01376
01377
01378 QRect KStyle::querySubControlMetrics( ComplexControl control,
01379 const QWidget* widget,
01380 SubControl sc,
01381 const QStyleOption &opt ) const
01382 {
01383 QRect ret;
01384
01385 if (control == CC_ScrollBar)
01386 {
01387 bool threeButtonScrollBar = d->scrollbarType & ThreeButtonScrollBar;
01388 bool platinumScrollBar = d->scrollbarType & PlatinumStyleScrollBar;
01389 bool nextScrollBar = d->scrollbarType & NextStyleScrollBar;
01390
01391 const QScrollBar *sb = (const QScrollBar*)widget;
01392 bool horizontal = sb->orientation() == Qt::Horizontal;
01393 int sliderstart = sb->sliderStart();
01394 int sbextent = pixelMetric(PM_ScrollBarExtent, widget);
01395 int maxlen = (horizontal ? sb->width() : sb->height())
01396 - (sbextent * (threeButtonScrollBar ? 3 : 2));
01397 int sliderlen;
01398
01399
01400 if (sb->maxValue() != sb->minValue())
01401 {
01402 uint range = sb->maxValue() - sb->minValue();
01403 sliderlen = (sb->pageStep() * maxlen) / (range + sb->pageStep());
01404
01405 int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget );
01406 if ( sliderlen < slidermin || range > INT_MAX / 2 )
01407 sliderlen = slidermin;
01408 if ( sliderlen > maxlen )
01409 sliderlen = maxlen;
01410 } else
01411 sliderlen = maxlen;
01412
01413
01414 switch (sc)
01415 {
01416 case SC_ScrollBarSubLine: {
01417
01418 if (platinumScrollBar) {
01419 if (horizontal)
01420 ret.setRect(sb->width() - 2 * sbextent, 0, sbextent, sbextent);
01421 else
01422 ret.setRect(0, sb->height() - 2 * sbextent, sbextent, sbextent);
01423 } else
01424 ret.setRect(0, 0, sbextent, sbextent);
01425 break;
01426 }
01427
01428 case SC_ScrollBarAddLine: {
01429
01430 if (nextScrollBar) {
01431 if (horizontal)
01432 ret.setRect(sbextent, 0, sbextent, sbextent);
01433 else
01434 ret.setRect(0, sbextent, sbextent, sbextent);
01435 } else {
01436 if (horizontal)
01437 ret.setRect(sb->width() - sbextent, 0, sbextent, sbextent);
01438 else
01439 ret.setRect(0, sb->height() - sbextent, sbextent, sbextent);
01440 }
01441 break;
01442 }
01443
01444 case SC_ScrollBarSubPage: {
01445
01446 if (platinumScrollBar) {
01447 if (horizontal)
01448 ret.setRect(0, 0, sliderstart, sbextent);
01449 else
01450 ret.setRect(0, 0, sbextent, sliderstart);
01451 } else if (nextScrollBar) {
01452 if (horizontal)
01453 ret.setRect(sbextent*2, 0, sliderstart-2*sbextent, sbextent);
01454 else
01455 ret.setRect(0, sbextent*2, sbextent, sliderstart-2*sbextent);
01456 } else {
01457 if (horizontal)
01458 ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
01459 else
01460 ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
01461 }
01462 break;
01463 }
01464
01465 case SC_ScrollBarAddPage: {
01466
01467 int fudge;
01468
01469 if (platinumScrollBar)
01470 fudge = 0;
01471 else if (nextScrollBar)
01472 fudge = 2*sbextent;
01473 else
01474 fudge = sbextent;
01475
01476 if (horizontal)
01477 ret.setRect(sliderstart + sliderlen, 0,
01478 maxlen - sliderstart - sliderlen + fudge, sbextent);
01479 else
01480 ret.setRect(0, sliderstart + sliderlen, sbextent,
01481 maxlen - sliderstart - sliderlen + fudge);
01482 break;
01483 }
01484
01485 case SC_ScrollBarGroove: {
01486 int multi = threeButtonScrollBar ? 3 : 2;
01487 int fudge;
01488
01489 if (platinumScrollBar)
01490 fudge = 0;
01491 else if (nextScrollBar)
01492 fudge = 2*sbextent;
01493 else
01494 fudge = sbextent;
01495
01496 if (horizontal)
01497 ret.setRect(fudge, 0, sb->width() - sbextent * multi, sb->height());
01498 else
01499 ret.setRect(0, fudge, sb->width(), sb->height() - sbextent * multi);
01500 break;
01501 }
01502
01503 case SC_ScrollBarSlider: {
01504 if (horizontal)
01505 ret.setRect(sliderstart, 0, sliderlen, sbextent);
01506 else
01507 ret.setRect(0, sliderstart, sbextent, sliderlen);
01508 break;
01509 }
01510
01511 default:
01512 ret = QCommonStyle::querySubControlMetrics(control, widget, sc, opt);
01513 break;
01514 }
01515 } else
01516 ret = QCommonStyle::querySubControlMetrics(control, widget, sc, opt);
01517
01518 return ret;
01519 }
01520
01521 static const char * const kstyle_close_xpm[] = {
01522 "12 12 2 1",
01523 "# c #000000",
01524 ". c None",
01525 "............",
01526 "............",
01527 "..##....##..",
01528 "...##..##...",
01529 "....####....",
01530 ".....##.....",
01531 "....####....",
01532 "...##..##...",
01533 "..##....##..",
01534 "............",
01535 "............",
01536 "............"};
01537
01538 static const char * const kstyle_maximize_xpm[]={
01539 "12 12 2 1",
01540 "# c #000000",
01541 ". c None",
01542 "............",
01543 "............",
01544 ".##########.",
01545 ".##########.",
01546 ".#........#.",
01547 ".#........#.",
01548 ".#........#.",
01549 ".#........#.",
01550 ".#........#.",
01551 ".#........#.",
01552 ".##########.",
01553 "............"};
01554
01555
01556 static const char * const kstyle_minimize_xpm[] = {
01557 "12 12 2 1",
01558 "# c #000000",
01559 ". c None",
01560 "............",
01561 "............",
01562 "............",
01563 "............",
01564 "............",
01565 "............",
01566 "............",
01567 "...######...",
01568 "...######...",
01569 "............",
01570 "............",
01571 "............"};
01572
01573 static const char * const kstyle_normalizeup_xpm[] = {
01574 "12 12 2 1",
01575 "# c #000000",
01576 ". c None",
01577 "............",
01578 "...#######..",
01579 "...#######..",
01580 "...#.....#..",
01581 ".#######.#..",
01582 ".#######.#..",
01583 ".#.....#.#..",
01584 ".#.....###..",
01585 ".#.....#....",
01586 ".#.....#....",
01587 ".#######....",
01588 "............"};
01589
01590
01591 static const char * const kstyle_shade_xpm[] = {
01592 "12 12 2 1",
01593 "# c #000000",
01594 ". c None",
01595 "............",
01596 "............",
01597 "............",
01598 "............",
01599 "............",
01600 ".....#......",
01601 "....###.....",
01602 "...#####....",
01603 "..#######...",
01604 "............",
01605 "............",
01606 "............"};
01607
01608 static const char * const kstyle_unshade_xpm[] = {
01609 "12 12 2 1",
01610 "# c #000000",
01611 ". c None",
01612 "............",
01613 "............",
01614 "............",
01615 "............",
01616 "..#######...",
01617 "...#####....",
01618 "....###.....",
01619 ".....#......",
01620 "............",
01621 "............",
01622 "............",
01623 "............"};
01624
01625 static const char * const dock_window_close_xpm[] = {
01626 "8 8 2 1",
01627 "# c #000000",
01628 ". c None",
01629 "##....##",
01630 ".##..##.",
01631 "..####..",
01632 "...##...",
01633 "..####..",
01634 ".##..##.",
01635 "##....##",
01636 "........"};
01637
01638
01639
01640
01641
01642
01643
01644
01645 static const char * const information_xpm[]={
01646 "32 32 5 1",
01647 ". c None",
01648 "c c #000000",
01649 "* c #999999",
01650 "a c #ffffff",
01651 "b c #0000ff",
01652 "...........********.............",
01653 "........***aaaaaaaa***..........",
01654 "......**aaaaaaaaaaaaaa**........",
01655 ".....*aaaaaaaaaaaaaaaaaa*.......",
01656 "....*aaaaaaaabbbbaaaaaaaac......",
01657 "...*aaaaaaaabbbbbbaaaaaaaac.....",
01658 "..*aaaaaaaaabbbbbbaaaaaaaaac....",
01659 ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
01660 ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
01661 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
01662 "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
01663 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
01664 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
01665 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
01666 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
01667 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
01668 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
01669 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
01670 "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
01671 "...caaaaaaabbbbbbbbbaaaaaac****.",
01672 "....caaaaaaaaaaaaaaaaaaaac****..",
01673 ".....caaaaaaaaaaaaaaaaaac****...",
01674 "......ccaaaaaaaaaaaaaacc****....",
01675 ".......*cccaaaaaaaaccc*****.....",
01676 "........***cccaaaac*******......",
01677 "..........****caaac*****........",
01678 ".............*caaac**...........",
01679 "...............caac**...........",
01680 "................cac**...........",
01681 ".................cc**...........",
01682 "..................***...........",
01683 "...................**..........."};
01684
01685 static const char* const warning_xpm[]={
01686 "32 32 4 1",
01687 ". c None",
01688 "a c #ffff00",
01689 "* c #000000",
01690 "b c #999999",
01691 ".............***................",
01692 "............*aaa*...............",
01693 "...........*aaaaa*b.............",
01694 "...........*aaaaa*bb............",
01695 "..........*aaaaaaa*bb...........",
01696 "..........*aaaaaaa*bb...........",
01697 ".........*aaaaaaaaa*bb..........",
01698 ".........*aaaaaaaaa*bb..........",
01699 "........*aaaaaaaaaaa*bb.........",
01700 "........*aaaa***aaaa*bb.........",
01701 ".......*aaaa*****aaaa*bb........",
01702 ".......*aaaa*****aaaa*bb........",
01703 "......*aaaaa*****aaaaa*bb.......",
01704 "......*aaaaa*****aaaaa*bb.......",
01705 ".....*aaaaaa*****aaaaaa*bb......",
01706 ".....*aaaaaa*****aaaaaa*bb......",
01707 "....*aaaaaaaa***aaaaaaaa*bb.....",
01708 "....*aaaaaaaa***aaaaaaaa*bb.....",
01709 "...*aaaaaaaaa***aaaaaaaaa*bb....",
01710 "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
01711 "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
01712 "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
01713 ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
01714 ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
01715 "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
01716 "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
01717 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
01718 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
01719 ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
01720 "..*************************bbbbb",
01721 "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
01722 ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
01723
01724 static const char* const critical_xpm[]={
01725 "32 32 4 1",
01726 ". c None",
01727 "a c #999999",
01728 "* c #ff0000",
01729 "b c #ffffff",
01730 "...........********.............",
01731 ".........************...........",
01732 ".......****************.........",
01733 "......******************........",
01734 ".....********************a......",
01735 "....**********************a.....",
01736 "...************************a....",
01737 "..*******b**********b*******a...",
01738 "..******bbb********bbb******a...",
01739 ".******bbbbb******bbbbb******a..",
01740 ".*******bbbbb****bbbbb*******a..",
01741 "*********bbbbb**bbbbb*********a.",
01742 "**********bbbbbbbbbb**********a.",
01743 "***********bbbbbbbb***********aa",
01744 "************bbbbbb************aa",
01745 "************bbbbbb************aa",
01746 "***********bbbbbbbb***********aa",
01747 "**********bbbbbbbbbb**********aa",
01748 "*********bbbbb**bbbbb*********aa",
01749 ".*******bbbbb****bbbbb*******aa.",
01750 ".******bbbbb******bbbbb******aa.",
01751 "..******bbb********bbb******aaa.",
01752 "..*******b**********b*******aa..",
01753 "...************************aaa..",
01754 "....**********************aaa...",
01755 "....a********************aaa....",
01756 ".....a******************aaa.....",
01757 "......a****************aaa......",
01758 ".......aa************aaaa.......",
01759 ".........aa********aaaaa........",
01760 "...........aaaaaaaaaaa..........",
01761 ".............aaaaaaa............"};
01762
01763 QPixmap KStyle::stylePixmap( StylePixmap stylepixmap,
01764 const QWidget* widget,
01765 const QStyleOption& opt) const
01766 {
01767 switch (stylepixmap) {
01768 case SP_TitleBarShadeButton:
01769 return QPixmap(const_cast<const char**>(kstyle_shade_xpm));
01770 case SP_TitleBarUnshadeButton:
01771 return QPixmap(const_cast<const char**>(kstyle_unshade_xpm));
01772 case SP_TitleBarNormalButton:
01773 return QPixmap(const_cast<const char**>(kstyle_normalizeup_xpm));
01774 case SP_TitleBarMinButton:
01775 return QPixmap(const_cast<const char**>(kstyle_minimize_xpm));
01776 case SP_TitleBarMaxButton:
01777 return QPixmap(const_cast<const char**>(kstyle_maximize_xpm));
01778 case SP_TitleBarCloseButton:
01779 return QPixmap(const_cast<const char**>(kstyle_close_xpm));
01780 case SP_DockWindowCloseButton:
01781 return QPixmap(const_cast<const char**>(dock_window_close_xpm ));
01782 case SP_MessageBoxInformation:
01783 return QPixmap(const_cast<const char**>(information_xpm));
01784 case SP_MessageBoxWarning:
01785 return QPixmap(const_cast<const char**>(warning_xpm));
01786 case SP_MessageBoxCritical:
01787 return QPixmap(const_cast<const char**>(critical_xpm));
01788 default:
01789 break;
01790 }
01791 return QCommonStyle::stylePixmap(stylepixmap, widget, opt);
01792 }
01793
01794
01795 int KStyle::styleHint( StyleHint sh, const QWidget* w,
01796 const QStyleOption &opt, QStyleHintReturn* shr) const
01797 {
01798 switch (sh)
01799 {
01800 case SH_EtchDisabledText:
01801 return d->etchDisabledText ? 1 : 0;
01802
01803 case SH_PopupMenu_Scrollable:
01804 return d->scrollablePopupmenus ? 1 : 0;
01805
01806 case SH_MenuBar_AltKeyNavigation:
01807 return d->menuAltKeyNavigation ? 1 : 0;
01808
01809 case SH_PopupMenu_SubMenuPopupDelay:
01810 if ( styleHint( SH_PopupMenu_SloppySubMenus, w ) )
01811 return QMIN( 100, d->popupMenuDelay );
01812 else
01813 return d->popupMenuDelay;
01814
01815 case SH_PopupMenu_SloppySubMenus:
01816 return d->sloppySubMenus;
01817
01818 case SH_ItemView_ChangeHighlightOnFocus:
01819 case SH_Slider_SloppyKeyEvents:
01820 case SH_MainWindow_SpaceBelowMenuBar:
01821 case SH_PopupMenu_AllowActiveAndDisabled:
01822 return 0;
01823
01824 case SH_Slider_SnapToValue:
01825 case SH_PrintDialog_RightAlignButtons:
01826 case SH_FontDialog_SelectAssociatedText:
01827 case SH_MenuBar_MouseTracking:
01828 case SH_PopupMenu_MouseTracking:
01829 case SH_ComboBox_ListMouseTracking:
01830 case SH_ScrollBar_MiddleClickAbsolutePosition:
01831 return 1;
01832
01833 default:
01834 return QCommonStyle::styleHint(sh, w, opt, shr);
01835 }
01836 }
01837
01838
01839 bool KStyle::eventFilter( QObject* object, QEvent* event )
01840 {
01841 if ( d->useFilledFrameWorkaround )
01842 {
01843
01844
01845
01846
01847
01848
01849
01850 QFrame *frame = 0;
01851 if ( event->type() == QEvent::Paint
01852 && (frame = ::qt_cast<QFrame*>(object)) )
01853 {
01854 if (frame->frameShape() != QFrame::ToolBarPanel && frame->frameShape() != QFrame::MenuBarPanel)
01855 return false;
01856
01857 bool horizontal = true;
01858 QPaintEvent* pe = (QPaintEvent*)event;
01859 QToolBar *toolbar = ::qt_cast< QToolBar *>( frame );
01860 QRect r = pe->rect();
01861
01862 if (toolbar && toolbar->orientation() == Qt::Vertical)
01863 horizontal = false;
01864
01865 if (horizontal) {
01866 if ( r.height() == frame->height() )
01867 return false;
01868
01869
01870 QPaintEvent dummyPE( QRect( r.x(), 0, r.width(), frame->height()) );
01871 QApplication::sendEvent( frame, &dummyPE );
01872 }
01873 else {
01874 if ( r.width() == frame->width() )
01875 return false;
01876
01877 QPaintEvent dummyPE( QRect( 0, r.y(), frame->width(), r.height()) );
01878 QApplication::sendEvent( frame, &dummyPE );
01879 }
01880
01881
01882 return true;
01883 }
01884 }
01885
01886 return false;
01887 }
01888
01889
01890
01891
01892
01893
01894 TransparencyHandler::TransparencyHandler( KStyle* style,
01895 TransparencyEngine tEngine, float menuOpacity, bool useDropShadow )
01896 : QObject()
01897 {
01898 te = tEngine;
01899 kstyle = style;
01900 opacity = menuOpacity;
01901 dropShadow = useDropShadow;
01902 pix.setOptimization(QPixmap::BestOptim);
01903 }
01904
01905 TransparencyHandler::~TransparencyHandler()
01906 {
01907 }
01908
01909
01910 void TransparencyHandler::rightShadow(QImage& dst)
01911 {
01912 if (dst.depth() != 32)
01913 dst = dst.convertDepth(32);
01914
01915
01916 int pixels = dst.width() * dst.height();
01917 #ifdef WORDS_BIGENDIAN
01918 register unsigned char* data = dst.bits() + 1;
01919 #else
01920 register unsigned char* data = dst.bits();
01921 #endif
01922 for(register int i = 0; i < 16; i++) {
01923 *data = (unsigned char)((*data)*top_right_corner[i]); data++;
01924 *data = (unsigned char)((*data)*top_right_corner[i]); data++;
01925 *data = (unsigned char)((*data)*top_right_corner[i]); data++;
01926 data++;
01927 }
01928
01929 pixels -= 32;
01930 register int c = 0;
01931 for(register int i = 0; i < pixels; i++) {
01932 *data = (unsigned char)((*data)*shadow_strip[c]); data++;
01933 *data = (unsigned char)((*data)*shadow_strip[c]); data++;
01934 *data = (unsigned char)((*data)*shadow_strip[c]); data++;
01935 data++;
01936 ++c;
01937 c %= 4;
01938 }
01939
01940
01941 for(register int i = 0; i < 16; i++) {
01942 *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
01943 *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
01944 *data = (unsigned char)((*data)*bottom_right_corner[i]); data++;
01945 data++;
01946 }
01947 }
01948
01949 void TransparencyHandler::bottomShadow(QImage& dst)
01950 {
01951 if (dst.depth() != 32)
01952 dst = dst.convertDepth(32);
01953
01954 int line = 0;
01955 int width = dst.width() - 4;
01956 double strip_data = shadow_strip[0];
01957 double* corner = const_cast<double*>(bottom_left_corner);
01958
01959 #ifdef WORDS_BIGENDIAN
01960 register unsigned char* data = dst.bits() + 1;
01961 #else
01962 register unsigned char* data = dst.bits();
01963 #endif
01964
01965 for(int y = 0; y < 4; y++)
01966 {
01967
01968 for(register int x = 0; x < 4; x++) {
01969 *data = (unsigned char)((*data)*(*corner)); data++;
01970 *data = (unsigned char)((*data)*(*corner)); data++;
01971 *data = (unsigned char)((*data)*(*corner)); data++;
01972 data++;
01973 corner++;
01974 }
01975
01976
01977 for(register int x = 0; x < width; x++) {
01978 *data = (unsigned char)((*data)*strip_data); data++;
01979 *data = (unsigned char)((*data)*strip_data); data++;
01980 *data = (unsigned char)((*data)*strip_data); data++;
01981 data++;
01982 }
01983
01984 strip_data = shadow_strip[++line];
01985 }
01986 }
01987
01988
01989 void TransparencyHandler::createShadowWindows(const QPopupMenu* p)
01990 {
01991 #ifdef Q_WS_X11
01992 int x2 = p->x()+p->width();
01993 int y2 = p->y()+p->height();
01994 QRect shadow1(x2, p->y() + 4, 4, p->height());
01995 QRect shadow2(p->x() + 4, y2, p->width() - 4, 4);
01996
01997
01998 ShadowElements se;
01999 se.w1 = new QWidget(0, 0, WStyle_Customize | WType_Popup | WX11BypassWM );
02000 se.w2 = new QWidget(0, 0, WStyle_Customize | WType_Popup | WX11BypassWM );
02001 se.w1->setGeometry(shadow1);
02002 se.w2->setGeometry(shadow2);
02003 XSelectInput(qt_xdisplay(), se.w1->winId(), StructureNotifyMask );
02004 XSelectInput(qt_xdisplay(), se.w2->winId(), StructureNotifyMask );
02005
02006
02007 shadowMap()[p] = se;
02008
02009
02010 QPixmap pix_shadow1 = QPixmap::grabWindow(qt_xrootwin(),
02011 shadow1.x(), shadow1.y(), shadow1.width(), shadow1.height());
02012 QPixmap pix_shadow2 = QPixmap::grabWindow(qt_xrootwin(),
02013 shadow2.x(), shadow2.y(), shadow2.width(), shadow2.height());
02014
02015 QImage img;
02016 img = pix_shadow1.convertToImage();
02017 rightShadow(img);
02018 pix_shadow1.convertFromImage(img);
02019 img = pix_shadow2.convertToImage();
02020 bottomShadow(img);
02021 pix_shadow2.convertFromImage(img);
02022
02023
02024 se.w1->setErasePixmap(pix_shadow1);
02025 se.w2->setErasePixmap(pix_shadow2);
02026
02027
02028
02029 XMapWindow(qt_xdisplay(), se.w1->winId());
02030 XMapWindow(qt_xdisplay(), se.w2->winId());
02031 #else
02032 Q_UNUSED( p )
02033 #endif
02034 }
02035
02036 void TransparencyHandler::removeShadowWindows(const QPopupMenu* p)
02037 {
02038 #ifdef Q_WS_X11
02039 ShadowMap::iterator it = shadowMap().find(p);
02040 if (it != shadowMap().end())
02041 {
02042 ShadowElements se = it.data();
02043 XUnmapWindow(qt_xdisplay(), se.w1->winId());
02044 XUnmapWindow(qt_xdisplay(), se.w2->winId());
02045 XFlush(qt_xdisplay());
02046 delete se.w1;
02047 delete se.w2;
02048 shadowMap().erase(it);
02049 }
02050 #else
02051 Q_UNUSED( p )
02052 #endif
02053 }
02054
02055 bool TransparencyHandler::eventFilter( QObject* object, QEvent* event )
02056 {
02057 #if !defined Q_WS_MAC && !defined Q_WS_WIN
02058
02059
02060
02061
02062 QPopupMenu* p = (QPopupMenu*)object;
02063 QEvent::Type et = event->type();
02064
02065 if (et == QEvent::Show)
02066 {
02067
02068 if (te != Disabled)
02069 {
02070 pix = QPixmap::grabWindow(qt_xrootwin(),
02071 p->x(), p->y(), p->width(), p->height());
02072
02073 switch (te) {
02074 #ifdef HAVE_XRENDER
02075 case XRender:
02076 if (qt_use_xrender) {
02077 XRenderBlendToPixmap(p);
02078 break;
02079 }
02080
02081 #else
02082 case XRender:
02083 #endif
02084 case SoftwareBlend:
02085 blendToPixmap(p->colorGroup(), p);
02086 break;
02087
02088 case SoftwareTint:
02089 default:
02090 blendToColor(p->colorGroup().button());
02091 };
02092
02093 p->setErasePixmap(pix);
02094 }
02095
02096
02097
02098
02099
02100
02101 if (dropShadow && p->width() > 16 && p->height() > 16 && !shadowMap().contains( p ))
02102 createShadowWindows(p);
02103 }
02104 else if (et == QEvent::Hide)
02105 {
02106
02107 if (dropShadow)
02108 removeShadowWindows(p);
02109
02110
02111 if (te != Disabled)
02112 p->setErasePixmap(QPixmap());
02113 }
02114
02115 #endif
02116 return false;
02117 }
02118
02119
02120
02121 void TransparencyHandler::blendToColor(const QColor &col)
02122 {
02123 if (opacity < 0.0 || opacity > 1.0)
02124 return;
02125
02126 QImage img = pix.convertToImage();
02127 KImageEffect::blend(col, img, opacity);
02128 pix.convertFromImage(img);
02129 }
02130
02131
02132 void TransparencyHandler::blendToPixmap(const QColorGroup &cg, const QPopupMenu* p)
02133 {
02134 if (opacity < 0.0 || opacity > 1.0)
02135 return;
02136
02137 KPixmap blendPix;
02138 blendPix.resize( pix.width(), pix.height() );
02139
02140 if (blendPix.width() != pix.width() ||
02141 blendPix.height() != pix.height())
02142 return;
02143
02144
02145 kstyle->renderMenuBlendPixmap( blendPix, cg, p );
02146
02147 QImage blendImg = blendPix.convertToImage();
02148 QImage backImg = pix.convertToImage();
02149 KImageEffect::blend(blendImg, backImg, opacity);
02150 pix.convertFromImage(backImg);
02151 }
02152
02153
02154 #ifdef HAVE_XRENDER
02155
02156
02157
02158 void TransparencyHandler::XRenderBlendToPixmap(const QPopupMenu* p)
02159 {
02160 KPixmap renderPix;
02161 renderPix.resize( pix.width(), pix.height() );
02162
02163
02164 kstyle->renderMenuBlendPixmap( renderPix, p->colorGroup(), p );
02165
02166 Display* dpy = qt_xdisplay();
02167 Pixmap alphaPixmap;
02168 Picture alphaPicture;
02169 XRenderPictFormat Rpf;
02170 XRenderPictureAttributes Rpa;
02171 XRenderColor clr;
02172 clr.alpha = ((unsigned short)(255*opacity) << 8);
02173
02174 Rpf.type = PictTypeDirect;
02175 Rpf.depth = 8;
02176 Rpf.direct.alphaMask = 0xff;
02177 Rpa.repeat = True;
02178
02179 XRenderPictFormat* xformat = XRenderFindFormat(dpy,
02180 PictFormatType | PictFormatDepth | PictFormatAlphaMask, &Rpf, 0);
02181
02182 alphaPixmap = XCreatePixmap(dpy, p->handle(), 1, 1, 8);
02183 alphaPicture = XRenderCreatePicture(dpy, alphaPixmap, xformat, CPRepeat, &Rpa);
02184
02185 XRenderFillRectangle(dpy, PictOpSrc, alphaPicture, &clr, 0, 0, 1, 1);
02186
02187 XRenderComposite(dpy, PictOpOver,
02188 renderPix.x11RenderHandle(), alphaPicture, pix.x11RenderHandle(),
02189 0, 0,
02190 0, 0,
02191 0, 0,
02192 pix.width(), pix.height());
02193
02194 XRenderFreePicture(dpy, alphaPicture);
02195 XFreePixmap(dpy, alphaPixmap);
02196 }
02197 #endif
02198
02199 void KStyle::virtual_hook( int, void* )
02200 { }
02201
02202
02203
02204
02205 #include "kstyle.moc"