2 * KDE3 HighColor Style (version 1.0)
3 * Copyright (C) 2001-2002 Karol Szwed <gallium@kde.org>
4 * (C) 2001-2002 Fredrik Höglund <fredrik@kde.org>
6 * Drawing routines adapted from the KDE2 HCStyle,
7 * Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
8 * (C) 2000 Dirk Mueller <mueller@kde.org>
9 * (C) 2001 Martijn Klingens <klingens@kde.org>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License version 2 as published by the Free Software Foundation.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public License
21 * along with this library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
26 #include "highcolor.h"
27 #include "highcolor.moc"
29 #include <QtGui/qdrawutil.h>
30 #include <QtGui/QPainter>
31 #include <Qt3Support/Q3PointArray>
32 #include <QtGui/QStylePlugin>
34 #include <QtGui/QComboBox>
35 #include <Qt3Support/Q3Header>
36 #include <QtGui/QMenuBar>
37 #include <QtGui/QPushButton>
38 #include <QtGui/QScrollBar>
39 #include <QtGui/QSlider>
40 #include <QtGui/QTabBar>
41 #include <QtGui/QToolButton>
42 #include <Qt3Support/Q3ToolBar>
43 #include <QtGui/QMenu>
44 #include <Qt3Support/Q3IntDict>
46 #include <kdrawutil.h>
47 #include <kpixmapeffect.h>
52 // -- Style Plugin Interface -------------------------
53 class HighColorStylePlugin
: public QStylePlugin
56 HighColorStylePlugin() {}
57 ~HighColorStylePlugin() {}
59 QStringList
keys() const
61 return QStringList() << "HighColor" << "Default" << "B3";
64 QStyle
* create( const QString
& key
)
66 if ( key
== "highcolor" )
67 return new HighColorStyle( HighColorStyle::HighColor
);
69 else if ( key
== "default" )
70 return new HighColorStyle( HighColorStyle::Default
);
72 else if ( key
== "b3" )
73 return new HighColorStyle( HighColorStyle::B3
);
79 Q_EXPORT_PLUGIN( HighColorStylePlugin
)
80 // ---------------------------------------------------
83 static QBitmap lightBmp
;
84 static QBitmap grayBmp
;
85 static QBitmap dgrayBmp
;
86 static QBitmap centerBmp
;
87 static QBitmap maskBmp
;
89 static Q3IntDict
<GradientSet
> gDict
;
91 static const int itemFrame
= 1;
92 static const int itemHMargin
= 3;
93 static const int itemVMargin
= 0;
94 static const int arrowHMargin
= 6;
95 static const int rightBorder
= 12;
96 static const char* kdeToolbarWidget
= "kde toolbar widget";
98 // ---------------------------------------------------------------------------
100 GradientSet::GradientSet(const QColor
&baseColor
)
103 for(int i
=0; i
< GradientCount
; i
++)
108 GradientSet::~GradientSet()
110 for(int i
=0; i
< GradientCount
; i
++)
116 KPixmap
* GradientSet::gradient(GradientType type
)
119 return gradients
[type
];
124 gradients
[VSmall
] = new KPixmap
;
125 gradients
[VSmall
]->resize(18, 24);
126 KPixmapEffect::gradient(*gradients
[VSmall
], c
.light(110), c
.dark(110),
127 KPixmapEffect::VerticalGradient
);
132 gradients
[VMed
] = new KPixmap
;
133 gradients
[VMed
]->resize(18, 34);
134 KPixmapEffect::gradient(*gradients
[VMed
], c
.light(110), c
.dark(110),
135 KPixmapEffect::VerticalGradient
);
140 gradients
[VLarge
] = new KPixmap
;
141 gradients
[VLarge
]->resize(18, 64);
142 KPixmapEffect::gradient(*gradients
[VLarge
], c
.light(110), c
.dark(110),
143 KPixmapEffect::VerticalGradient
);
148 gradients
[HMed
] = new KPixmap
;
149 gradients
[HMed
]->resize(34, 18);
150 KPixmapEffect::gradient(*gradients
[HMed
], c
.light(110), c
.dark(110),
151 KPixmapEffect::HorizontalGradient
);
156 gradients
[HLarge
] = new KPixmap
;
157 gradients
[HLarge
]->resize(52, 18);
158 KPixmapEffect::gradient(*gradients
[HLarge
], c
.light(110), c
.dark(110),
159 KPixmapEffect::HorizontalGradient
);
166 return(gradients
[type
]);
171 // ---------------------------------------------------------------------------
173 HighColorStyle::HighColorStyle( StyleType styleType
)
174 : KStyle( AllowMenuTransparency
| FilledFrameWorkaround
, ThreeButtonScrollBar
)
177 highcolor
= (type
== HighColor
&& QPixmap::defaultDepth() > 8);
178 gDict
.setAutoDelete(true);
180 selectionBackground
= false;
184 HighColorStyle::~HighColorStyle()
189 void HighColorStyle::polish(QWidget
* widget
)
191 // Put in order of highest occurrence to maximise hit rate
192 if (widget
->inherits("QPushButton")) {
193 widget
->installEventFilter(this);
194 } else if (widget
->inherits("QMenuBar") || widget
->inherits("QPopupMenu")) {
195 widget
->setBackgroundMode(Qt::NoBackground
);
196 } else if (type
== HighColor
&& widget
->inherits("QToolBarExtensionWidget")) {
197 widget
->installEventFilter(this);
198 } else if ( !qstrcmp( widget
->name(), kdeToolbarWidget
) ) {
199 widget
->setBackgroundMode( Qt::NoBackground
); // We paint the whole background.
200 widget
->installEventFilter(this);
201 } else if (widget
->inherits("QToolBoxButton")) {
202 QFont font
= widget
->font();
204 widget
->setFont(font
);
207 KStyle::polish( widget
);
211 void HighColorStyle::unPolish(QWidget
* widget
)
213 if (widget
->inherits("QPushButton")) {
214 widget
->removeEventFilter(this);
216 else if (widget
->inherits("QMenuBar") || widget
->inherits("QPopupMenu")) {
217 widget
->setBackgroundMode(Qt::PaletteBackground
);
218 } else if (type
== HighColor
&& widget
->inherits("QToolBarExtensionWidget")) {
219 widget
->removeEventFilter(this);
220 } else if ( !qstrcmp( widget
->name(), kdeToolbarWidget
) ) {
221 widget
->removeEventFilter(this);
222 widget
->setBackgroundMode( Qt::PaletteBackground
);
225 KStyle::unPolish( widget
);
230 void HighColorStyle::renderMenuBlendPixmap( KPixmap
& pix
, const QColorGroup
&cg
,
231 const QMenu
* /* popup */ ) const
233 QColor col
= cg
.button();
235 #ifdef Q_WS_X11 // Only draw menu gradients on TrueColor, X11 visuals
236 if ( QPaintDevice::x11AppDepth() >= 24 )
237 KPixmapEffect::gradient( pix
, col
.light(120), col
.dark(115),
238 KPixmapEffect::HorizontalGradient
);
245 // This function draws primitive elements as well as their masks.
246 void HighColorStyle::drawPrimitive( PrimitiveElement pe
,
249 const QColorGroup
&cg
,
251 const QStyleOption
& opt
) const
253 bool down
= flags
& Style_Down
;
254 bool on
= flags
& Style_On
;
259 // -------------------------------------------------------------------
260 case PE_ButtonDefault
: {
261 if ( type
!= HighColor
) {
263 r
.getCoords( &x1
, &y1
, &x2
, &y2
);
265 // Button default indicator
266 p
->setPen( cg
.shadow() );
267 p
->drawLine( x1
+1, y1
, x2
-1, y1
);
268 p
->drawLine( x1
, y1
+1, x1
, y2
-1 );
269 p
->drawLine( x1
+1, y2
, x2
-1, y2
);
270 p
->drawLine( x2
, y1
+1, x2
, y2
-1 );
275 case PE_ButtonDropDown
:
276 case PE_ButtonTool
: {
277 bool sunken
= on
|| down
;
279 r
.rect(&x
, &y
, &w
, &h
);
282 QPen oldPen
= p
->pen();
284 // Outer frame (round style)
285 p
->setPen(cg
.shadow());
286 p
->drawLine(x
+1,y
,x2
-1,y
);
287 p
->drawLine(x
,y
+1,x
,y2
-1);
288 p
->drawLine(x
+1,y2
,x2
-1,y2
);
289 p
->drawLine(x2
,y
+1,x2
,y2
-1);
292 p
->setPen(sunken
? cg
.mid() : cg
.light());
293 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
294 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
295 p
->setPen(sunken
? cg
.light() : cg
.mid());
296 p
->drawLine(x
+2, y2
-1, x2
-1, y2
-1);
297 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
299 p
->fillRect(x
+2, y
+2, w
-4, h
-4, cg
.button());
306 // -------------------------------------------------------------------
307 case PE_ButtonCommand
: {
308 bool sunken
= on
|| down
;
309 bool flat
= !(flags
& (Style_Raised
| Style_Sunken
));
311 r
.rect(&x
, &y
, &w
, &h
);
316 kDrawBeButton( p
, x
, y
, w
, h
, cg
, true,
317 &cg
.brush(QPalette::Mid
) );
319 else if ( flags
& Style_MouseOver
&& !flat
) {
320 QBrush
brush(cg
.button().light(110));
321 kDrawBeButton( p
, x
, y
, w
, h
, cg
, false, &brush
);
326 if ( flags
& Style_MouseOver
)
327 p
->fillRect(r
, cg
.button().light(110));
329 renderGradient(p
, QRect(x
, y
, w
-1, h
-1),
332 p
->setPen(cg
.button().light(75));
333 p
->drawLine(x
, y
, x2
, y
);
334 p
->drawLine(x
, y
, x
, y2
);
335 p
->drawLine(x
, y2
, x2
, y2
);
336 p
->drawLine(x2
, y
, x2
, y2
);
343 p
->setPen(cg
.shadow());
344 p
->drawLine(x
+1, y
, x2
-1, y
);
345 p
->drawLine(x
+1, y2
, x2
-1, y2
);
346 p
->drawLine(x
, y
+1, x
, y2
-1);
347 p
->drawLine(x2
, y
+1, x2
, y2
-1);
349 p
->setPen(cg
.light());
350 p
->drawLine(x
+2, y
+2, x2
-1, y
+2);
351 p
->drawLine(x
+2, y
+3, x2
-2, y
+3);
352 p
->drawLine(x
+2, y
+4, x
+2, y2
-1);
353 p
->drawLine(x
+3, y
+4, x
+3, y2
-2);
356 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
357 p
->drawLine(x
+2, y2
-1, x2
-1, y2
-1);
359 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
360 p
->drawLine(x
+1, y
+2, x
+1, y2
-1);
361 p
->drawLine(x2
-2, y
+3, x2
-2, y2
-2);
363 renderGradient(p
, QRect(x
+4, y
+4, w
-6, h
-6),
366 kDrawBeButton(p
, x
, y
, w
, h
, cg
, false,
367 &cg
.brush(QPalette::Button
));
373 // -------------------------------------------------------------------
374 case PE_ButtonBevel
: {
376 r
.rect(&x
, &y
, &w
, &h
);
377 bool sunken
= on
|| down
;
382 p
->setPen(cg
.shadow());
386 p
->setPen(sunken
? cg
.mid() : cg
.light());
387 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
388 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
389 p
->setPen(sunken
? cg
.light() : cg
.mid());
390 p
->drawLine(x
+2, y2
-1, x2
-1, y2
-1);
391 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
393 if (w
> 4 && h
> 4) {
395 p
->fillRect(x
+2, y
+2, w
-4, h
-4, cg
.button());
397 renderGradient( p
, QRect(x
+2, y
+2, w
-4, h
-4),
398 cg
.button(), flags
& Style_Horizontal
);
405 // -------------------------------------------------------------------
407 p
->drawWinFocusRect( r
);
413 // -------------------------------------------------------------------
414 case PE_HeaderSection
: {
415 // Temporary solution for the proper orientation of gradients.
416 bool horizontal
= true;
417 if (p
&& p
->device()->devType() == QInternal::Widget
) {
418 Q3Header
* hdr
= dynamic_cast<Q3Header
*>(p
->device());
420 horizontal
= hdr
->orientation() == Qt::Horizontal
;
424 r
.rect(&x
, &y
, &w
, &h
);
425 bool sunken
= on
|| down
;
428 QPen oldPen
= p
->pen();
431 p
->setPen(sunken
? cg
.mid() : cg
.light());
432 p
->drawLine(x
, y
, x2
-1, y
);
433 p
->drawLine(x
, y
, x
, y2
-1);
434 p
->setPen(sunken
? cg
.light() : cg
.mid());
435 p
->drawLine(x
+1, y2
-1, x2
-1, y2
-1);
436 p
->drawLine(x2
-1, y
+1, x2
-1, y2
-1);
437 p
->setPen(cg
.shadow());
438 p
->drawLine(x
, y2
, x2
, y2
);
439 p
->drawLine(x2
, y
, x2
, y2
);
442 p
->fillRect(x
+1, y
+1, w
-3, h
-3, cg
.button());
444 renderGradient( p
, QRect(x
+1, y
+1, w
-3, h
-3),
445 cg
.button(), !horizontal
);
452 // -------------------------------------------------------------------
453 case PE_ScrollBarSlider
: {
454 // Small hack to ensure scrollbar gradients are drawn the right way.
455 flags
^= Style_Horizontal
;
457 drawPrimitive(PE_ButtonBevel
, p
, r
, cg
, flags
| Style_Enabled
| Style_Raised
);
459 // Draw a scrollbar riffle (note direction after above changes)
462 // HighColor & Default scrollbar
463 if (flags
& Style_Horizontal
) {
464 if (r
.height() >= 15) {
466 int y
= r
.y() + (r
.height()-7)/2;
467 int x2
= r
.right()-3;
468 p
->setPen(cg
.light());
469 p
->drawLine(x
, y
, x2
, y
);
470 p
->drawLine(x
, y
+3, x2
, y
+3);
471 p
->drawLine(x
, y
+6, x2
, y
+6);
474 p
->drawLine(x
, y
+1, x2
, y
+1);
475 p
->drawLine(x
, y
+4, x2
, y
+4);
476 p
->drawLine(x
, y
+7, x2
, y
+7);
479 if (r
.width() >= 15) {
481 int x
= r
.x() + (r
.width()-7)/2;
482 int y2
= r
.bottom()-3;
483 p
->setPen(cg
.light());
484 p
->drawLine(x
, y
, x
, y2
);
485 p
->drawLine(x
+3, y
, x
+3, y2
);
486 p
->drawLine(x
+6, y
, x
+6, y2
);
489 p
->drawLine(x
+1, y
, x
+1, y2
);
490 p
->drawLine(x
+4, y
, x
+4, y2
);
491 p
->drawLine(x
+7, y
, x
+7, y2
);
497 if (flags
& Style_Horizontal
) {
500 if (r
.height() >= 36) buttons
= 3;
501 else if (r
.height() >=24) buttons
= 2;
502 else if (r
.height() >=16) buttons
= 1;
504 int x
= r
.x() + (r
.width()-7) / 2;
505 int y
= r
.y() + (r
.height() - (buttons
* 5) -
509 for ( int i
=0; i
<buttons
; i
++, y
+=6 )
511 p
->setPen( cg
.mid() );
512 p
->drawLine( x
+1, y
, x2
-1, y
);
513 p
->drawLine( x
, y
+1, x
, y
+3 );
514 p
->setPen( cg
.light() );
515 p
->drawLine( x
+1, y
+1, x2
-1, y
+1 );
516 p
->drawLine( x
+1, y
+1, x
+1, y
+3 );
517 p
->setPen( cg
.dark() );
518 p
->drawLine( x
+1, y
+4, x2
-1, y
+4 );
519 p
->drawLine( x2
, y
+1, x2
, y
+3 );
524 if (r
.width() >= 36) buttons
= 3;
525 else if (r
.width() >=24) buttons
= 2;
526 else if (r
.width() >=16) buttons
= 1;
528 int x
= r
.x() + (r
.width() - (buttons
* 5) -
530 int y
= r
.y() + (r
.height()-7) / 2;
533 for ( int i
=0; i
<buttons
; i
++, x
+=6 )
535 p
->setPen( cg
.mid() );
536 p
->drawLine( x
+1, y
, x
+3, y
);
537 p
->drawLine( x
, y
+1, x
, y2
-1 );
538 p
->setPen( cg
.light() );
539 p
->drawLine( x
+1, y
+1, x
+3, y
+1 );
540 p
->drawLine( x
+1, y
+1, x
+1, y2
-1 );
541 p
->setPen( cg
.dark() );
542 p
->drawLine( x
+1, y2
, x
+3, y2
);
543 p
->drawLine( x
+4, y
+1, x
+4, y2
-1 );
551 case PE_ScrollBarAddPage
:
552 case PE_ScrollBarSubPage
: {
554 r
.rect(&x
, &y
, &w
, &h
);
559 // HighColor & Default scrollbar
561 p
->setPen(cg
.shadow());
563 if (flags
& Style_Horizontal
) {
564 p
->drawLine(x
, y
, x2
, y
);
565 p
->drawLine(x
, y2
, x2
, y2
);
566 renderGradient(p
, QRect(x
, y
+1, w
, h
-2),
569 p
->drawLine(x
, y
, x
, y2
);
570 p
->drawLine(x2
, y
, x2
, y2
);
571 renderGradient(p
, QRect(x
+1, y
, w
-2, h
),
577 p
->setPen( cg
.mid() );
579 if (flags
& Style_Horizontal
) {
580 p
->drawLine(x
, y
, x2
, y
);
581 p
->drawLine(x
, y2
, x2
, y2
);
582 p
->fillRect( QRect(x
, y
+1, w
, h
-2),
583 flags
& Style_Down
? cg
.button() : cg
.midlight() );
585 p
->drawLine(x
, y
, x
, y2
);
586 p
->drawLine(x2
, y
, x2
, y2
);
587 p
->fillRect( QRect(x
+1, y
, w
-2, h
),
588 flags
& Style_Down
? cg
.button() : cg
.midlight() );
595 case PE_ScrollBarAddLine
: {
596 drawPrimitive( PE_ButtonBevel
, p
, r
, cg
, (flags
& Style_Enabled
) |
597 ((flags
& Style_Down
) ? Style_Down
: Style_Raised
) );
599 drawPrimitive( ((flags
& Style_Horizontal
) ? PE_ArrowRight
: PE_ArrowDown
),
605 case PE_ScrollBarSubLine
: {
606 drawPrimitive( PE_ButtonBevel
, p
, r
, cg
, (flags
& Style_Enabled
) |
607 ((flags
& Style_Down
) ? Style_Down
: Style_Raised
) );
609 drawPrimitive( ((flags
& Style_Horizontal
) ? PE_ArrowLeft
: PE_ArrowUp
),
615 // CHECKBOX (indicator)
616 // -------------------------------------------------------------------
619 bool enabled
= flags
& Style_Enabled
;
620 bool nochange
= flags
& Style_NoChange
;
623 xBmp
= QBitmap(7, 7, x_bits
, true);
628 x
=r
.x(); y
=r
.y(); w
=r
.width(); h
=r
.height();
633 p
->drawLine(x
, y
, x2
, y
);
634 p
->drawLine(x
, y
, x
, y2
);
636 p
->setPen(cg
.light());
637 p
->drawLine(x2
, y
+1, x2
, y2
);
638 p
->drawLine(x
+1, y2
, x2
, y2
);
640 p
->setPen(cg
.shadow());
641 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
642 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
644 p
->setPen(cg
.midlight());
645 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
646 p
->drawLine(x
+2, y2
-1, x2
-1, y2
-1);
649 p
->fillRect(x
+2, y
+2, w
-4, h
-4,
650 down
? cg
.button(): cg
.base());
652 p
->fillRect(x
+2, y
+2, w
-4, h
-4, cg
.background());
654 if (!(flags
& Style_Off
)) {
656 p
->setPen(nochange
? cg
.dark() : cg
.text());
657 p
->drawPixmap(x
+3, y
+3, xBmp
);
660 p
->setPen(cg
.shadow());
661 p
->drawRect(x
+2, y
+2, w
-4, h
-4);
662 p
->setPen(nochange
? cg
.text() : cg
.dark());
663 p
->drawLine(x
+3, (y
+h
)/2-2, x
+w
-4, (y
+h
)/2-2);
664 p
->drawLine(x
+3, (y
+h
)/2, x
+w
-4, (y
+h
)/2);
665 p
->drawLine(x
+3, (y
+h
)/2+2, x
+w
-4, (y
+h
)/2+2);
672 // RADIOBUTTON (exclusive indicator)
673 // -------------------------------------------------------------------
674 case PE_ExclusiveIndicator
: {
676 if (lightBmp
.isNull()) {
677 lightBmp
= QBitmap(13, 13, radiooff_light_bits
, true);
678 grayBmp
= QBitmap(13, 13, radiooff_gray_bits
, true);
679 dgrayBmp
= QBitmap(13, 13, radiooff_dgray_bits
, true);
680 centerBmp
= QBitmap(13, 13, radiooff_center_bits
, true);
681 centerBmp
.setMask( centerBmp
);
685 kColorBitmaps(p
, cg
, r
.x(), r
.y(), &lightBmp
, &grayBmp
,
688 // The center fill of the indicator (grayed out when disabled)
689 if ( flags
& Style_Enabled
)
690 p
->setPen( down
? cg
.button() : cg
.base() );
692 p
->setPen( cg
.background() );
693 p
->drawPixmap( r
.x(), r
.y(), centerBmp
);
697 QColor color
= flags
& Style_NoChange
?
698 cg
.dark() : cg
.text();
701 p
->drawLine(5, 4, 7, 4);
702 p
->drawLine(4, 5, 4, 7);
703 p
->drawLine(5, 8, 7, 8);
704 p
->drawLine(8, 5, 8, 7);
705 p
->fillRect(5, 5, 3, 3, color
);
712 // RADIOBUTTON (exclusive indicator) mask
713 // -------------------------------------------------------------------
714 case PE_ExclusiveIndicatorMask
: {
715 if (maskBmp
.isNull()) {
716 maskBmp
= QBitmap(13, 13, radiomask_bits
, true);
717 maskBmp
.setMask(maskBmp
);
720 p
->setPen(Qt::color1
);
721 p
->drawPixmap(r
.x(), r
.y(), maskBmp
);
726 // SPLITTER/DOCKWINDOW HANDLES
727 // -------------------------------------------------------------------
728 case PE_DockWindowResizeHandle
:
731 r
.rect(&x
, &y
, &w
, &h
);
735 p
->setPen(cg
.dark());
736 p
->drawRect(x
, y
, w
, h
);
737 p
->setPen(cg
.background());
741 p
->drawPoint(x2
, y2
);
742 p
->setPen(cg
.light());
743 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
744 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
745 p
->setPen(cg
.midlight());
746 p
->drawLine(x
+2, y
+2, x
+2, y2
-2);
747 p
->drawLine(x
+2, y
+2, x2
-2, y
+2);
749 p
->drawLine(x2
-1, y
+1, x2
-1, y2
-1);
750 p
->drawLine(x
+1, y2
-1, x2
-1, y2
-1);
751 p
->fillRect(x
+3, y
+3, w
-5, h
-5, cg
.brush(QPalette::Background
));
757 // -------------------------------------------------------------------
761 case PE_PanelLineEdit
: {
762 bool sunken
= flags
& Style_Sunken
;
763 int lw
= opt
.isDefault() ? pixelMetric(PM_DefaultFrameWidth
)
767 QPen oldPen
= p
->pen();
769 r
.rect(&x
, &y
, &w
, &h
);
772 p
->setPen(sunken
? cg
.light() : cg
.dark());
773 p
->drawLine(x
, y2
, x2
, y2
);
774 p
->drawLine(x2
, y
, x2
, y2
);
775 p
->setPen(sunken
? cg
.mid() : cg
.light());
776 p
->drawLine(x
, y
, x2
, y
);
777 p
->drawLine(x
, y
, x
, y2
);
778 p
->setPen(sunken
? cg
.midlight() : cg
.mid());
779 p
->drawLine(x
+1, y2
-1, x2
-1, y2
-1);
780 p
->drawLine(x2
-1, y
+1, x2
-1, y2
-1);
781 p
->setPen(sunken
? cg
.dark() : cg
.midlight());
782 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
783 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
786 KStyle::drawPrimitive(pe
, p
, r
, cg
, flags
, opt
);
792 // MENU / TOOLBAR PANEL
793 // -------------------------------------------------------------------
794 case PE_PanelMenuBar
: // Menu
795 case PE_PanelDockWindow
: { // Toolbar
796 int x2
= r
.x()+r
.width()-1;
797 int y2
= r
.y()+r
.height()-1;
798 int lw
= opt
.isDefault() ? pixelMetric(PM_DefaultFrameWidth
)
803 p
->setPen(cg
.light());
804 p
->drawLine(r
.x(), r
.y(), x2
-1, r
.y());
805 p
->drawLine(r
.x(), r
.y(), r
.x(), y2
-1);
806 p
->setPen(cg
.dark());
807 p
->drawLine(r
.x(), y2
, x2
, y2
);
808 p
->drawLine(x2
, r
.y(), x2
, y2
);
810 // ### Qt should specify Style_Horizontal where appropriate
811 renderGradient( p
, QRect(r
.x()+1, r
.y()+1, r
.width()-2, r
.height()-2),
813 (r
.width() < r
.height()) && (pe
!= PE_PanelMenuBar
) );
816 renderGradient( p
, r
, cg
.button(),
817 (r
.width() < r
.height()) && (pe
!= PE_PanelMenuBar
) );
825 // -------------------------------------------------------------------
826 case PE_DockWindowSeparator
: {
827 renderGradient( p
, r
, cg
.button(),
828 !(flags
& Style_Horizontal
));
829 if ( !(flags
& Style_Horizontal
) ) {
831 p
->drawLine(4, r
.height()/2, r
.width()-5, r
.height()/2);
832 p
->setPen(cg
.light());
833 p
->drawLine(4, r
.height()/2+1, r
.width()-5, r
.height()/2+1);
836 p
->drawLine(r
.width()/2, 4, r
.width()/2, r
.height()-5);
837 p
->setPen(cg
.light());
838 p
->drawLine(r
.width()/2+1, 4, r
.width()/2+1, r
.height()-5);
847 // -------------------------------------------------------------------
848 if (pe
>= PE_ArrowUp
&& pe
<= PE_ArrowLeft
)
853 // HighColor & Default arrows
856 a
.setPoints(QCOORDARRLEN(u_arrow
), u_arrow
);
860 a
.setPoints(QCOORDARRLEN(d_arrow
), d_arrow
);
864 a
.setPoints(QCOORDARRLEN(l_arrow
), l_arrow
);
868 a
.setPoints(QCOORDARRLEN(r_arrow
), r_arrow
);
874 a
.setPoints(QCOORDARRLEN(B3::u_arrow
), B3::u_arrow
);
878 a
.setPoints(QCOORDARRLEN(B3::d_arrow
), B3::d_arrow
);
882 a
.setPoints(QCOORDARRLEN(B3::l_arrow
), B3::l_arrow
);
886 a
.setPoints(QCOORDARRLEN(B3::r_arrow
), B3::r_arrow
);
891 if ( flags
& Style_Down
)
892 p
->translate( pixelMetric( PM_ButtonShiftHorizontal
),
893 pixelMetric( PM_ButtonShiftVertical
) );
895 if ( flags
& Style_Enabled
) {
896 a
.translate( r
.x() + r
.width() / 2, r
.y() + r
.height() / 2 );
897 p
->setPen( cg
.buttonText() );
898 p
->drawLineSegments( a
);
900 a
.translate( r
.x() + r
.width() / 2 + 1, r
.y() + r
.height() / 2 + 1 );
901 p
->setPen( cg
.light() );
902 p
->drawLineSegments( a
);
903 a
.translate( -1, -1 );
904 p
->setPen( cg
.mid() );
905 p
->drawLineSegments( a
);
910 KStyle::drawPrimitive( pe
, p
, r
, cg
, flags
, opt
);
916 void HighColorStyle::drawKStylePrimitive( KStylePrimitive kpe
,
918 const QWidget
* widget
,
920 const QColorGroup
&cg
,
922 const QStyleOption
&opt
) const
927 // -------------------------------------------------------------------
928 case KPE_ToolBarHandle
: {
929 int x
= r
.x(); int y
= r
.y();
930 int x2
= r
.x() + r
.width()-1;
931 int y2
= r
.y() + r
.height()-1;
933 if (flags
& Style_Horizontal
) {
935 renderGradient( p
, r
, cg
.button(), false);
936 p
->setPen(cg
.light());
937 p
->drawLine(x
+1, y
+4, x
+1, y2
-4);
938 p
->drawLine(x
+3, y
+4, x
+3, y2
-4);
939 p
->drawLine(x
+5, y
+4, x
+5, y2
-4);
942 p
->drawLine(x
+2, y
+4, x
+2, y2
-4);
943 p
->drawLine(x
+4, y
+4, x
+4, y2
-4);
944 p
->drawLine(x
+6, y
+4, x
+6, y2
-4);
948 renderGradient( p
, r
, cg
.button(), true);
949 p
->setPen(cg
.light());
950 p
->drawLine(x
+4, y
+1, x2
-4, y
+1);
951 p
->drawLine(x
+4, y
+3, x2
-4, y
+3);
952 p
->drawLine(x
+4, y
+5, x2
-4, y
+5);
955 p
->drawLine(x
+4, y
+2, x2
-4, y
+2);
956 p
->drawLine(x
+4, y
+4, x2
-4, y
+4);
957 p
->drawLine(x
+4, y
+6, x2
-4, y
+6);
964 // GENERAL/KICKER HANDLE
965 // -------------------------------------------------------------------
966 case KPE_GeneralHandle
: {
967 int x
= r
.x(); int y
= r
.y();
968 int x2
= r
.x() + r
.width()-1;
969 int y2
= r
.y() + r
.height()-1;
971 if (flags
& Style_Horizontal
) {
973 p
->setPen(cg
.light());
974 p
->drawLine(x
+1, y
, x
+1, y2
);
975 p
->drawLine(x
+3, y
, x
+3, y2
);
976 p
->drawLine(x
+5, y
, x
+5, y2
);
979 p
->drawLine(x
+2, y
, x
+2, y2
);
980 p
->drawLine(x
+4, y
, x
+4, y2
);
981 p
->drawLine(x
+6, y
, x
+6, y2
);
985 p
->setPen(cg
.light());
986 p
->drawLine(x
, y
+1, x2
, y
+1);
987 p
->drawLine(x
, y
+3, x2
, y
+3);
988 p
->drawLine(x
, y
+5, x2
, y
+5);
991 p
->drawLine(x
, y
+2, x2
, y
+2);
992 p
->drawLine(x
, y
+4, x2
, y
+4);
993 p
->drawLine(x
, y
+6, x2
, y
+6);
1001 // -------------------------------------------------------------------
1002 case KPE_SliderGroove
: {
1003 const QSlider
* slider
= (const QSlider
*)widget
;
1004 bool horizontal
= slider
->orientation() == Qt::Horizontal
;
1005 int gcenter
= (horizontal
? r
.height() : r
.width()) / 2;
1009 gr
= QRect(r
.x(), r
.y()+gcenter
-3, r
.width(), 7);
1011 gr
= QRect(r
.x()+gcenter
-3, r
.y(), 7, r
.height());
1014 gr
.rect(&x
, &y
, &w
, &h
);
1018 // Draw the slider groove.
1019 p
->setPen(cg
.dark());
1020 p
->drawLine(x
+2, y
, x2
-2, y
);
1021 p
->drawLine(x
, y
+2, x
, y2
-2);
1022 p
->fillRect(x
+2,y
+2,w
-4, h
-4,
1023 slider
->isEnabled() ? cg
.dark() : cg
.mid());
1024 p
->setPen(cg
.shadow());
1025 p
->drawRect(x
+1, y
+1, w
-2, h
-2);
1026 p
->setPen(cg
.light());
1027 p
->drawPoint(x
+1,y2
-1);
1028 p
->drawPoint(x2
-1,y2
-1);
1029 p
->drawLine(x2
, y
+2, x2
, y2
-2);
1030 p
->drawLine(x
+2, y2
, x2
-2, y2
);
1035 // -------------------------------------------------------------------
1036 case KPE_SliderHandle
: {
1037 const QSlider
* slider
= (const QSlider
*)widget
;
1038 bool horizontal
= slider
->orientation() == Qt::Horizontal
;
1040 r
.rect(&x
, &y
, &w
, &h
);
1044 p
->setPen(cg
.mid());
1045 p
->drawLine(x
+1, y
, x2
-1, y
);
1046 p
->drawLine(x
, y
+1, x
, y2
-1);
1047 p
->setPen(cg
.shadow());
1048 p
->drawLine(x
+1, y2
, x2
-1, y2
);
1049 p
->drawLine(x2
, y
+1, x2
, y2
-1);
1051 p
->setPen(cg
.light());
1052 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
1053 p
->drawLine(x
+1, y
+1, x
+1, y2
-1);
1054 p
->setPen(cg
.dark());
1055 p
->drawLine(x
+2, y2
-1, x2
-1, y2
-1);
1056 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
1057 p
->setPen(cg
.midlight());
1058 p
->drawLine(x
+2, y
+2, x2
-2, y
+2);
1059 p
->drawLine(x
+2, y
+2, x
+2, y2
-2);
1060 p
->setPen(cg
.mid());
1061 p
->drawLine(x
+3, y2
-2, x2
-2, y2
-2);
1062 p
->drawLine(x2
-2, y
+3, x2
-2, y2
-2);
1063 renderGradient(p
, QRect(x
+3, y
+3, w
-6, h
-6),
1064 cg
.button(), !horizontal
);
1068 p
->setPen(cg
.light());
1069 p
->drawLine(x
+5, y
+4, x
+5, y2
-4);
1070 p
->drawLine(x
+8, y
+4, x
+8, y2
-4);
1071 p
->drawLine(x
+11,y
+4, x
+11, y2
-4);
1072 p
->setPen(slider
->isEnabled() ? cg
.shadow(): cg
.mid());
1073 p
->drawLine(x
+6, y
+4, x
+6, y2
-4);
1074 p
->drawLine(x
+9, y
+4, x
+9, y2
-4);
1075 p
->drawLine(x
+12,y
+4, x
+12, y2
-4);
1077 p
->setPen(cg
.light());
1078 p
->drawLine(x
+4, y
+5, x2
-4, y
+5);
1079 p
->drawLine(x
+4, y
+8, x2
-4, y
+8);
1080 p
->drawLine(x
+4, y
+11, x2
-4, y
+11);
1081 p
->setPen(slider
->isEnabled() ? cg
.shadow() : cg
.mid());
1082 p
->drawLine(x
+4, y
+6, x2
-4, y
+6);
1083 p
->drawLine(x
+4, y
+9, x2
-4, y
+9);
1084 p
->drawLine(x
+4, y
+12, x2
-4, y
+12);
1090 KStyle::drawKStylePrimitive( kpe
, p
, widget
, r
, cg
, flags
, opt
);
1095 void HighColorStyle::drawControl( ControlElement element
,
1097 const QWidget
*widget
,
1099 const QColorGroup
&cg
,
1101 const QStyleOption
& opt
) const
1106 // -------------------------------------------------------------------
1107 case CE_PushButton
: {
1108 if ( widget
== hoverWidget
)
1109 flags
|= Style_MouseOver
;
1111 if ( type
!= HighColor
) {
1112 QPushButton
*button
= (QPushButton
*) widget
;
1114 bool btnDefault
= button
->isDefault();
1116 if ( btnDefault
|| button
->autoDefault() ) {
1117 // Compensate for default indicator
1118 static int di
= pixelMetric( PM_ButtonDefaultIndicator
);
1119 br
.adjust( di
, di
, -di
, -di
);
1123 drawPrimitive( PE_ButtonDefault
, p
, r
, cg
, flags
);
1125 drawPrimitive( PE_ButtonCommand
, p
, br
, cg
, flags
);
1128 drawPrimitive( PE_ButtonCommand
, p
, r
, cg
, flags
);
1135 // -------------------------------------------------------------------
1136 case CE_PushButtonLabel
: {
1137 const QPushButton
* button
= (const QPushButton
*)widget
;
1138 bool active
= button
->isOn() || button
->isDown();
1140 r
.rect( &x
, &y
, &w
, &h
);
1142 // Shift button contents if pushed.
1144 x
+= pixelMetric(PM_ButtonShiftHorizontal
, widget
);
1145 y
+= pixelMetric(PM_ButtonShiftVertical
, widget
);
1146 flags
|= Style_Sunken
;
1149 // Does the button have a popup menu?
1150 if ( button
->isMenuButton() ) {
1151 int dx
= pixelMetric( PM_MenuButtonIndicator
, widget
);
1152 drawPrimitive( PE_ArrowDown
, p
, QRect(x
+ w
- dx
- 2, y
+ 2, dx
, h
- 4),
1157 // Draw the icon if there is one
1158 if ( button
->iconSet() && !button
->iconSet()->isNull() ) {
1159 QIcon::Mode mode
= QIcon::Disabled
;
1160 QIcon::State state
= QIcon::Off
;
1162 if (button
->isEnabled())
1163 mode
= button
->hasFocus() ? QIcon::Active
: QIcon::Normal
;
1164 if (button
->isToggleButton() && button
->isOn())
1167 QPixmap pixmap
= button
->iconSet()->pixmap( QIcon::Small
, mode
, state
);
1169 // Center the iconset if there's no text or pixmap
1170 if (button
->text().isEmpty() && !button
->pixmap())
1171 p
->drawPixmap( x
+ (w
- pixmap
.width()) / 2,
1172 y
+ (h
- pixmap
.height()) / 2, pixmap
);
1174 p
->drawPixmap( x
+ 4, y
+ (h
- pixmap
.height()) / 2, pixmap
);
1176 int pw
= pixmap
.width();
1181 // Make the label indicate if the button is a default button or not
1182 if ( active
|| button
->isDefault() ) {
1183 // Draw "fake" bold text - this enables the font metrics to remain
1184 // the same as computed in QPushButton::sizeHint(), but gives
1185 // a reasonable bold effect.
1189 if (button
->isEnabled()) // Don't draw double-shadow when disabled
1191 drawItem( p
, QRect(x
+i
+1, y
+1, w
, h
), Qt::AlignCenter
| Qt::TextShowMnemonic
,
1192 button
->colorGroup(), button
->isEnabled(), NULL
,
1194 active
? &button
->colorGroup().dark() : &button
->colorGroup().mid() );
1198 drawItem( p
, QRect(x
+i
, y
, w
, h
), Qt::AlignCenter
| Qt::TextShowMnemonic
,
1199 button
->colorGroup(), button
->isEnabled(), i
== 0 ? button
->pixmap() : NULL
,
1201 active
? &button
->colorGroup().light() : &button
->colorGroup().buttonText() );
1203 drawItem( p
, QRect(x
, y
, w
, h
), Qt::AlignCenter
| Qt::TextShowMnemonic
, button
->colorGroup(),
1204 button
->isEnabled(), button
->pixmap(), button
->text(), -1,
1205 active
? &button
->colorGroup().light() : &button
->colorGroup().buttonText() );
1207 // Draw a focus rect if the button has focus
1208 if ( flags
& Style_HasFocus
)
1209 drawPrimitive( PE_FocusRect
, p
,
1210 QStyle::visualRect(subRect(SR_PushButtonFocusRect
, widget
), widget
),
1216 // -------------------------------------------------------------------
1219 bool pressed
= flags
& Style_Down
;
1220 bool selected
= flags
& Style_Selected
;
1222 r
.getCoords( &x
, &y
, &x2
, &y2
);
1224 p
->setPen( pressed
? cg
.shadow() : cg
.light() );
1225 p
->drawLine( x
, y
, x2
-1, y
);
1226 p
->drawLine( x
, y
, x
, y2
-1 );
1228 p
->setPen( pressed
? cg
.light() : cg
.shadow() );
1229 p
->drawLine( x
, y2
, x2
, y2
);
1230 p
->drawLine( x2
, y
, x2
, y2
);
1232 QColor fill
= selected
? cg
.highlight() : cg
.button();
1233 selectionBackground
= selected
;
1236 p
->fillRect( QRect(x
+1, y
+1, r
.width()-2, r
.height()-2), fill
);
1238 renderGradient(p
, QRect(x
+1, y
+1, r
.width()-2, r
.height()-2),
1243 // MENUBAR BACKGROUND
1244 // -------------------------------------------------------------------
1245 case CE_MenuBarEmptyArea
:
1247 renderGradient(p
, r
, cg
.button(), false);
1251 // MENUBAR ITEM (sunken panel on mouse over)
1252 // -------------------------------------------------------------------
1253 case CE_MenuBarItem
:
1255 QMenuBar
*mb
= (QMenuBar
*)widget
;
1256 QMenuItem
*mi
= opt
.menuItem();
1257 QRect pr
= mb
->rect();
1259 bool active
= flags
& Style_Active
;
1260 bool focused
= flags
& Style_HasFocus
;
1262 if ( active
&& focused
)
1263 qDrawShadePanel(p
, r
.x(), r
.y(), r
.width(), r
.height(),
1264 cg
, true, 1, &cg
.brush(QPalette::Midlight
));
1266 renderGradient( p
, r
, cg
.button(), false,
1267 r
.x(), r
.y()-1, pr
.width()-2, pr
.height()-2);
1269 drawItem( p
, r
, Qt::AlignCenter
| Qt::AlignVCenter
| Qt::TextShowMnemonic
1270 | Qt::TextDontClip
| Qt::TextSingleLine
, cg
, flags
& Style_Enabled
,
1271 mi
->pixmap(), mi
->text() );
1278 // -------------------------------------------------------------------
1279 case CE_PopupMenuItem
: {
1280 const QMenu
*popupmenu
= (const QMenu
*) widget
;
1282 QMenuItem
*mi
= opt
.menuItem();
1284 // Don't leave blank holes if we set NoBackground for the QPopupMenu.
1285 // This only happens when the popupMenu spans more than one column.
1286 if (! (widget
->erasePixmap() && !widget
->erasePixmap()->isNull()) )
1287 p
->fillRect(r
, cg
.brush(QPalette::Button
) );
1291 int tab
= opt
.tabWidth();
1292 int checkcol
= opt
.maxIconWidth();
1293 bool enabled
= mi
->isEnabled();
1294 bool checkable
= popupmenu
->isCheckable();
1295 bool active
= flags
& Style_Active
;
1296 bool etchtext
= styleHint( SH_EtchDisabledText
);
1297 bool reverse
= QApplication::isRightToLeft();
1299 r
.rect( &x
, &y
, &w
, &h
);
1302 checkcol
= qMax( checkcol
, 20 );
1304 // Are we a menu item separator?
1305 if ( mi
->isSeparator() ) {
1306 p
->setPen( cg
.dark() );
1307 p
->drawLine( x
, y
, x
+w
, y
);
1308 p
->setPen( cg
.light() );
1309 p
->drawLine( x
, y
+1, x
+w
, y
+1 );
1313 // Draw the menu item background
1315 qDrawShadePanel( p
, x
, y
, w
, h
, cg
, true, 1,
1316 &cg
.brush(QPalette::Midlight
) );
1317 // Draw the transparency pixmap
1318 else if ( widget
->erasePixmap() && !widget
->erasePixmap()->isNull() )
1319 p
->drawPixmap( x
, y
, *widget
->erasePixmap(), x
, y
, w
, h
);
1320 // Draw a solid background
1322 p
->fillRect( r
, cg
.button() );
1324 // Do we have an icon?
1325 if ( mi
->iconSet() ) {
1327 QRect cr
= visualRect( QRect(x
, y
, checkcol
, h
), r
);
1329 // Select the correct icon from the iconset
1331 mode
= enabled
? QIcon::Active
: QIcon::Disabled
;
1333 mode
= enabled
? QIcon::Normal
: QIcon::Disabled
;
1335 // Do we have an icon and are checked at the same time?
1336 // Then draw a "pressed" background behind the icon
1337 if ( checkable
&& !active
&& mi
->isChecked() )
1338 qDrawShadePanel( p
, cr
.x(), cr
.y(), cr
.width(), cr
.height(),
1339 cg
, true, 1, &cg
.brush(QPalette::Midlight
) );
1341 QPixmap pixmap
= mi
->iconSet()->pixmap( QIcon::Small
, mode
);
1342 QRect
pmr( 0, 0, pixmap
.width(), pixmap
.height() );
1343 pmr
.moveCenter( cr
.center() );
1344 p
->drawPixmap( pmr
.topLeft(), pixmap
);
1347 // Are we checked? (This time without an icon)
1348 else if ( checkable
&& mi
->isChecked() ) {
1349 int cx
= reverse
? x
+w
- checkcol
: x
;
1351 // We only have to draw the background if the menu item is inactive -
1352 // if it's active the "pressed" background is already drawn
1354 qDrawShadePanel( p
, cx
, y
, checkcol
, h
, cg
, true, 1,
1355 &cg
.brush(QPalette::Midlight
) );
1357 // Draw the checkmark
1358 SFlags cflags
= Style_Default
;
1359 cflags
|= active
? Style_Enabled
: Style_On
;
1361 drawPrimitive( PE_CheckMark
, p
, QRect( cx
+ itemFrame
, y
+ itemFrame
,
1362 checkcol
- itemFrame
*2, h
- itemFrame
*2), cg
, cflags
);
1365 // Time to draw the menu item label...
1366 int xm
= itemFrame
+ checkcol
+ itemHMargin
; // X position margin
1368 int xp
= reverse
? // X position
1369 x
+ tab
+ rightBorder
+ itemHMargin
+ itemFrame
- 1 :
1372 int offset
= reverse
? -1 : 1; // Shadow offset for etched text
1374 // Label width (minus the width of the accelerator portion)
1375 int tw
= w
- xm
- tab
- arrowHMargin
- itemHMargin
* 3 - itemFrame
+ 1;
1377 // Set the color for enabled and disabled text
1378 // (used for both active and inactive menu items)
1379 p
->setPen( enabled
? cg
.buttonText() : cg
.mid() );
1381 // This color will be used instead of the above if the menu item
1382 // is active and disabled at the same time. (etched text)
1383 QColor discol
= cg
.mid();
1385 // Does the menu item draw it's own label?
1386 if ( mi
->custom() ) {
1387 int m
= itemVMargin
;
1388 // Save the painter state in case the custom
1389 // paint method changes it in some way
1392 // Draw etched text if we're inactive and the menu item is disabled
1393 if ( etchtext
&& !enabled
&& !active
) {
1394 p
->setPen( cg
.light() );
1395 mi
->custom()->paint( p
, cg
, active
, enabled
, xp
+offset
, y
+m
+1, tw
, h
-2*m
);
1396 p
->setPen( discol
);
1398 mi
->custom()->paint( p
, cg
, active
, enabled
, xp
, y
+m
, tw
, h
-2*m
);
1402 // The menu item doesn't draw it's own label
1403 QString s
= mi
->text();
1405 // Does the menu item have a text label?
1406 if ( !s
.isNull() ) {
1407 int t
= s
.find( '\t' );
1408 int m
= itemVMargin
;
1409 int text_flags
= Qt::AlignVCenter
| Qt::TextShowMnemonic
| Qt::TextDontClip
| Qt::TextSingleLine
;
1410 text_flags
|= reverse
? Qt::AlignRight
: Qt::AlignLeft
;
1412 // Does the menu item have a tabstop? (for the accelerator text)
1414 int tabx
= reverse
? x
+ rightBorder
+ itemHMargin
+ itemFrame
:
1415 x
+ w
- tab
- rightBorder
- itemHMargin
- itemFrame
;
1417 // Draw the right part of the label (accelerator text)
1418 if ( etchtext
&& !enabled
&& !active
) {
1419 // Draw etched text if we're inactive and the menu item is disabled
1420 p
->setPen( cg
.light() );
1421 p
->drawText( tabx
+offset
, y
+m
+1, tab
, h
-2*m
, text_flags
, s
.mid( t
+1 ) );
1422 p
->setPen( discol
);
1424 p
->drawText( tabx
, y
+m
, tab
, h
-2*m
, text_flags
, s
.mid( t
+1 ) );
1428 // Draw the left part of the label (or the whole label
1429 // if there's no accelerator)
1430 if ( etchtext
&& !enabled
&& !active
) {
1431 // Etched text again for inactive disabled menu items...
1432 p
->setPen( cg
.light() );
1433 p
->drawText( xp
+offset
, y
+m
+1, tw
, h
-2*m
, text_flags
, s
, t
);
1434 p
->setPen( discol
);
1437 p
->drawText( xp
, y
+m
, tw
, h
-2*m
, text_flags
, s
, t
);
1441 // The menu item doesn't have a text label
1442 // Check if it has a pixmap instead
1443 else if ( mi
->pixmap() ) {
1444 QPixmap
*pixmap
= mi
->pixmap();
1447 if ( pixmap
->depth() == 1 )
1448 p
->setBackgroundMode( Qt::OpaqueMode
);
1450 int diffw
= ( ( w
- pixmap
->width() ) / 2 )
1451 + ( ( w
- pixmap
->width() ) % 2 );
1452 p
->drawPixmap( x
+diffw
, y
+itemFrame
, *pixmap
);
1454 if ( pixmap
->depth() == 1 )
1455 p
->setBackgroundMode( Qt::TransparentMode
);
1459 // Does the menu item have a submenu?
1460 if ( mi
->popup() ) {
1461 PrimitiveElement arrow
= reverse
? PE_ArrowLeft
: PE_ArrowRight
;
1462 int dim
= pixelMetric(PM_MenuButtonIndicator
);
1463 QRect vr
= visualRect( QRect( x
+ w
- arrowHMargin
- 2*itemFrame
- dim
,
1464 y
+ h
/ 2 - dim
/ 2, dim
, dim
), r
);
1466 // Draw an arrow at the far end of the menu item
1469 discol
= cg
.buttonText();
1471 QColorGroup
g2( discol
, cg
.highlight(), Qt::white
, Qt::white
,
1472 enabled
? Qt::white
: discol
, discol
, Qt::white
);
1474 drawPrimitive( arrow
, p
, vr
, g2
, Style_Enabled
);
1476 drawPrimitive( arrow
, p
, vr
, cg
,
1477 enabled
? Style_Enabled
: Style_Default
);
1483 KStyle::drawControl(element
, p
, widget
, r
, cg
, flags
, opt
);
1488 void HighColorStyle::drawControlMask( ControlElement element
,
1490 const QWidget
*widget
,
1492 const QStyleOption
& opt
) const
1497 // ----------------------------------------------------------------------
1498 case CE_PushButton
: {
1500 r
.getCoords( &x1
, &y1
, &x2
, &y2
);
1501 QCOORD corners
[] = { x1
,y1
, x2
,y1
, x1
,y2
, x2
,y2
};
1502 p
->fillRect( r
, Qt::color1
);
1503 p
->setPen( Qt::color0
);
1504 p
->drawPoints( Q3PointArray(4, corners
) );
1509 KStyle::drawControlMask(element
, p
, widget
, r
, opt
);
1514 void HighColorStyle::drawComplexControl( ComplexControl control
,
1516 const QWidget
*widget
,
1518 const QColorGroup
&cg
,
1522 const QStyleOption
& opt
) const
1527 // -------------------------------------------------------------------
1530 // Draw box and arrow
1531 if ( controls
& SC_ComboBoxArrow
) {
1532 bool sunken
= (active
== SC_ComboBoxArrow
);
1536 r
.rect(&x
, &y
, &w
, &h
);
1540 p
->setPen(cg
.shadow());
1541 p
->drawLine(x
+1, y
, x2
-1, y
);
1542 p
->drawLine(x
+1, y2
, x2
-1, y2
);
1543 p
->drawLine(x
, y
+1, x
, y2
-1);
1544 p
->drawLine(x2
, y
+1, x2
, y2
-1);
1546 // Ensure the edge notches are properly colored
1547 p
->setPen(cg
.button());
1551 p
->drawPoint(x2
,y2
);
1553 renderGradient( p
, QRect(x
+2, y
+2, w
-4, h
-4),
1554 cg
.button(), false);
1556 p
->setPen(sunken
? cg
.light() : cg
.mid());
1557 p
->drawLine(x2
-1, y
+2, x2
-1, y2
-1);
1558 p
->drawLine(x
+1, y2
-1, x2
-1, y2
-1);
1560 p
->setPen(sunken
? cg
.mid() : cg
.light());
1561 p
->drawLine(x
+1, y
+1, x2
-1, y
+1);
1562 p
->drawLine(x
+1, y
+2, x
+1, y2
-2);
1564 // Get the button bounding box
1565 QRect ar
= QStyle::visualRect(
1566 querySubControlMetrics(CC_ComboBox
, widget
, SC_ComboBoxArrow
),
1570 if ( widget
->isEnabled() )
1571 flags
|= Style_Enabled
;
1573 // Are we "pushed" ?
1574 if ( active
& Style_Sunken
)
1575 flags
|= Style_Sunken
;
1577 drawPrimitive(PE_ArrowDown
, p
, ar
, cg
, flags
);
1580 // Draw an edit field if required
1581 if ( controls
& SC_ComboBoxEditField
)
1583 const QComboBox
* cb
= (const QComboBox
*) widget
;
1584 QRect re
= QStyle::visualRect(
1585 querySubControlMetrics( CC_ComboBox
, widget
,
1586 SC_ComboBoxEditField
), widget
);
1589 if (cb
->editable()) {
1590 p
->setPen( cg
.dark() );
1591 p
->drawLine( re
.x(), re
.y()-1, re
.x()+re
.width(), re
.y()-1 );
1592 p
->drawLine( re
.x()-1, re
.y(), re
.x()-1, re
.y()+re
.height() );
1595 if ( cb
->hasFocus() ) {
1596 p
->setPen( cg
.highlightedText() );
1597 p
->setBackgroundColor( cg
.highlight() );
1599 p
->setPen( cg
.text() );
1600 p
->setBackgroundColor( cg
.button() );
1603 if ( cb
->hasFocus() && !cb
->editable() ) {
1604 // Draw the contents
1605 p
->fillRect( re
.x(), re
.y(), re
.width(), re
.height(),
1606 cg
.brush( QPalette::Highlight
) );
1608 QRect re
= QStyle::visualRect(
1609 subRect(SR_ComboBoxFocusRect
, cb
), widget
);
1611 drawPrimitive( PE_FocusRect
, p
, re
, cg
,
1612 Style_FocusAtBorder
, QStyleOption(cg
.highlight()));
1619 // -------------------------------------------------------------------
1620 case CC_ToolButton
: {
1621 const QToolButton
*toolbutton
= (const QToolButton
*) widget
;
1623 QRect button
, menuarea
;
1624 button
= querySubControlMetrics(control
, widget
, SC_ToolButton
, opt
);
1625 menuarea
= querySubControlMetrics(control
, widget
, SC_ToolButtonMenu
, opt
);
1627 SFlags bflags
= flags
,
1630 if (active
& SC_ToolButton
)
1631 bflags
|= Style_Down
;
1632 if (active
& SC_ToolButtonMenu
)
1633 mflags
|= Style_Down
;
1635 if (controls
& SC_ToolButton
)
1637 // If we're pressed, on, or raised...
1638 if (bflags
& (Style_Down
| Style_On
| Style_Raised
))
1639 drawPrimitive(PE_ButtonTool
, p
, button
, cg
, bflags
, opt
);
1641 // Check whether to draw a background pixmap
1642 else if ( toolbutton
->parentWidget() &&
1643 toolbutton
->parentWidget()->backgroundPixmap() &&
1644 !toolbutton
->parentWidget()->backgroundPixmap()->isNull() )
1646 QPixmap pixmap
= *(toolbutton
->parentWidget()->backgroundPixmap());
1647 p
->drawTiledPixmap( r
, pixmap
, toolbutton
->pos() );
1649 else if (widget
->parent())
1651 if (widget
->parent()->inherits("QToolBar"))
1653 Q3ToolBar
* parent
= (Q3ToolBar
*)widget
->parent();
1654 QRect pr
= parent
->rect();
1656 renderGradient( p
, r
, cg
.button(),
1657 parent
->orientation() == Qt::Vertical
,
1658 r
.x(), r
.y(), pr
.width()-2, pr
.height()-2);
1660 else if (widget
->parent()->inherits("QToolBarExtensionWidget"))
1662 QWidget
* parent
= (QWidget
*)widget
->parent();
1663 Q3ToolBar
* toolbar
= (Q3ToolBar
*)parent
->parent();
1664 QRect tr
= toolbar
->rect();
1666 if ( toolbar
->orientation() == Qt::Horizontal
) {
1667 renderGradient( p
, r
, cg
.button(), false, r
.x(), r
.y(),
1668 r
.width(), tr
.height() );
1670 renderGradient( p
, r
, cg
.button(), true, r
.x(), r
.y(),
1671 tr
.width(), r
.height() );
1677 // Draw a toolbutton menu indicator if required
1678 if (controls
& SC_ToolButtonMenu
)
1680 if (mflags
& (Style_Down
| Style_On
| Style_Raised
))
1681 drawPrimitive(PE_ButtonDropDown
, p
, menuarea
, cg
, mflags
, opt
);
1682 drawPrimitive(PE_ArrowDown
, p
, menuarea
, cg
, mflags
, opt
);
1685 if (toolbutton
->hasFocus() && !toolbutton
->focusProxy()) {
1686 QRect fr
= toolbutton
->rect();
1687 fr
.adjust(3, 3, -3, -3);
1688 drawPrimitive(PE_FocusRect
, p
, fr
, cg
);
1696 KStyle::drawComplexControl(control
, p
, widget
,
1697 r
, cg
, flags
, controls
, active
, opt
);
1703 void HighColorStyle::drawComplexControlMask( ComplexControl control
,
1705 const QWidget
*widget
,
1707 const QStyleOption
& opt
) const
1711 // COMBOBOX & TOOLBUTTON MASKS
1712 // -------------------------------------------------------------------
1714 case CC_ToolButton
: {
1716 r
.getCoords( &x1
, &y1
, &x2
, &y2
);
1717 QCOORD corners
[] = { x1
,y1
, x2
,y1
, x1
,y2
, x2
,y2
};
1718 p
->fillRect( r
, Qt::color1
);
1719 p
->setPen( Qt::color0
);
1720 p
->drawPoints( Q3PointArray(4, corners
) );
1725 KStyle::drawComplexControlMask(control
, p
, widget
, r
, opt
);
1730 void HighColorStyle::drawItem( QPainter
*p
,
1733 const QColorGroup
&cg
,
1735 const QPixmap
*pixmap
,
1736 const QString
&text
,
1738 const QColor
*penColor
) const
1740 // We only reimplement this method this so we can override the
1741 // text color used for widgets when we draw them with the selection
1742 // color and Qt expects them to be drawn them with the button color.
1743 // -------------------------------------------------------------------
1746 if ( selectionBackground
) {
1747 col
= &cg
.highlightedText();
1748 selectionBackground
= false;
1752 KStyle::drawItem( p
, r
, flags
, cg
, enabled
, pixmap
,
1757 QRect
HighColorStyle::subRect(SubRect r
, const QWidget
*widget
) const
1759 // We want the focus rect for buttons to be adjusted from
1760 // the Qt3 defaults to be similar to Qt 2's defaults.
1761 // -------------------------------------------------------------------
1762 if (r
== SR_PushButtonFocusRect
) {
1763 const QPushButton
* button
= (const QPushButton
*) widget
;
1764 QRect
wrect(widget
->rect());
1765 int dbw1
= 0, dbw2
= 0;
1767 if (button
->isDefault() || button
->autoDefault()) {
1768 dbw1
= pixelMetric(PM_ButtonDefaultIndicator
, widget
);
1772 int dfw1
= pixelMetric(PM_DefaultFrameWidth
, widget
) * 2,
1775 return QRect(wrect
.x() + dfw1
+ dbw1
+ 1,
1776 wrect
.y() + dfw1
+ dbw1
+ 1,
1777 wrect
.width() - dfw2
- dbw2
- 1,
1778 wrect
.height() - dfw2
- dbw2
- 1);
1780 return KStyle::subRect(r
, widget
);
1784 int HighColorStyle::pixelMetric(PixelMetric m
, const QWidget
*widget
) const
1789 // -------------------------------------------------------------------
1790 case PM_ButtonMargin
: // Space btw. frame and label
1793 case PM_ButtonDefaultIndicator
: {
1794 if ( type
== HighColor
)
1795 return 0; // No indicator when highcolor
1800 case PM_MenuButtonIndicator
: { // Arrow width
1807 // CHECKBOXES / RADIO BUTTONS
1808 // -------------------------------------------------------------------
1809 case PM_ExclusiveIndicatorWidth
: // Radiobutton size
1810 case PM_ExclusiveIndicatorHeight
:
1811 case PM_IndicatorWidth
: // Checkbox size
1812 case PM_IndicatorHeight
: {
1817 return KStyle::pixelMetric(m
, widget
);
1822 QSize
HighColorStyle::sizeFromContents( ContentsType contents
,
1823 const QWidget
* widget
,
1824 const QSize
&contentSize
,
1825 const QStyleOption
& opt
) const
1830 // ------------------------------------------------------------------
1831 case CT_PushButton
: {
1832 const QPushButton
* button
= (const QPushButton
*) widget
;
1833 int w
= contentSize
.width();
1834 int h
= contentSize
.height();
1835 int bm
= pixelMetric( PM_ButtonMargin
, widget
);
1836 int fw
= pixelMetric( PM_DefaultFrameWidth
, widget
) * 2;
1838 w
+= bm
+ fw
+ 6; // ### Add 6 to make way for bold font.
1841 // Ensure we stick to standard width and heights.
1842 if ( button
->isDefault() || button
->autoDefault() ) {
1843 if ( w
< 80 && !button
->text().isEmpty() )
1846 if ( type
!= HighColor
) {
1847 // Compensate for default indicator
1848 int di
= pixelMetric( PM_ButtonDefaultIndicator
);
1857 return QSize( w
, h
);
1861 // POPUPMENU ITEM SIZE
1862 // -----------------------------------------------------------------
1863 case CT_PopupMenuItem
: {
1864 if ( ! widget
|| opt
.isDefault() )
1867 const QMenu
*popup
= (const QMenu
*) widget
;
1868 bool checkable
= popup
->isCheckable();
1869 QMenuItem
*mi
= opt
.menuItem();
1870 int maxpmw
= opt
.maxIconWidth();
1871 int w
= contentSize
.width(), h
= contentSize
.height();
1873 if ( mi
->custom() ) {
1874 w
= mi
->custom()->sizeHint().width();
1875 h
= mi
->custom()->sizeHint().height();
1876 if ( ! mi
->custom()->fullSpan() )
1877 h
+= 2*itemVMargin
+ 2*itemFrame
;
1879 else if ( mi
->widget() ) {
1880 } else if ( mi
->isSeparator() ) {
1881 w
= 10; // Arbitrary
1886 h
= qMax( h
, mi
->pixmap()->height() + 2*itemFrame
);
1888 // Ensure that the minimum height for text-only menu items
1889 // is the same as the icon size used by KDE.
1890 h
= qMax( h
, 16 + 2*itemFrame
);
1891 h
= qMax( h
, popup
->fontMetrics().height()
1892 + 2*itemVMargin
+ 2*itemFrame
);
1895 if ( mi
->iconSet() )
1896 h
= qMax( h
, mi
->iconSet()->pixmap(
1897 QIcon::Small
, QIcon::Normal
).height() +
1901 if ( ! mi
->text().isNull() && mi
->text().find('\t') >= 0 )
1903 else if ( mi
->popup() )
1904 w
+= 2 * arrowHMargin
;
1908 if ( checkable
&& maxpmw
< 20 )
1910 if ( checkable
|| maxpmw
> 0 )
1915 return QSize( w
, h
);
1920 return KStyle::sizeFromContents( contents
, widget
, contentSize
, opt
);
1925 // Fix Qt's wacky image alignment
1926 QPixmap
HighColorStyle::stylePixmap(StylePixmap stylepixmap
,
1927 const QWidget
* widget
,
1928 const QStyleOption
& opt
) const
1930 switch (stylepixmap
) {
1931 case SP_TitleBarMinButton
:
1932 return QPixmap((const char **)hc_minimize_xpm
);
1933 case SP_TitleBarCloseButton
:
1934 return QPixmap((const char **)hc_close_xpm
);
1939 return KStyle::stylePixmap(stylepixmap
, widget
, opt
);
1943 bool HighColorStyle::eventFilter( QObject
*object
, QEvent
*event
)
1945 if (KStyle::eventFilter( object
, event
))
1950 // Handle push button hover effects.
1951 QPushButton
* button
= dynamic_cast<QPushButton
*>(object
);
1954 if ( (event
->type() == QEvent::Enter
) &&
1955 (button
->isEnabled()) ) {
1956 hoverWidget
= button
;
1957 button
->repaint( false );
1959 else if ( (event
->type() == QEvent::Leave
) &&
1960 (object
== hoverWidget
) ) {
1962 button
->repaint( false );
1964 } else if ( object
->parent() && !qstrcmp( object
->name(), kdeToolbarWidget
) )
1966 // Draw a gradient background for custom widgets in the toolbar
1967 // that have specified a "kde toolbar widget" name.
1969 if (event
->type() == QEvent::Paint
) {
1970 // Find the top-level toolbar of this widget, since it may be nested in other
1971 // widgets that are on the toolbar.
1972 QWidget
*widget
= static_cast<QWidget
*>(object
);
1973 QWidget
*parent
= static_cast<QWidget
*>(object
->parent());
1974 int x_offset
= widget
->x(), y_offset
= widget
->y();
1975 while (parent
&& parent
->parent() && !qstrcmp( parent
->name(), kdeToolbarWidget
) )
1977 x_offset
+= parent
->x();
1978 y_offset
+= parent
->y();
1979 parent
= static_cast<QWidget
*>(parent
->parent());
1982 QRect r
= widget
->rect();
1983 QRect pr
= parent
->rect();
1984 bool horiz_grad
= pr
.width() < pr
.height();
1986 // Check if the parent is a QToolbar, and use its orientation, else guess.
1987 Q3ToolBar
* tb
= dynamic_cast<Q3ToolBar
*>(parent
);
1988 if (tb
) horiz_grad
= tb
->orientation() == Qt::Vertical
;
1990 QPainter
p( widget
);
1991 renderGradient(&p
, r
, parent
->colorGroup().button(), horiz_grad
,
1992 x_offset
, y_offset
, pr
.width(), pr
.height());
1994 return false; // Now draw the contents
1996 } else if ( object
->parent() &&
1997 (toolbar
= dynamic_cast<Q3ToolBar
*>(object
->parent())) )
1999 // We need to override the paint event to draw a
2000 // gradient on a QToolBarExtensionWidget.
2001 if ( event
->type() == QEvent::Paint
) {
2002 QWidget
*widget
= static_cast<QWidget
*>(object
);
2003 QRect wr
= widget
->rect(), tr
= toolbar
->rect();
2004 QPainter
p( widget
);
2005 renderGradient(&p
, wr
, toolbar
->colorGroup().button(),
2006 toolbar
->orientation() == Qt::Vertical
,
2007 wr
.x(), wr
.y(), tr
.width() - 2, tr
.height() - 2);
2009 p
.setPen( toolbar
->colorGroup().dark() );
2010 if ( toolbar
->orientation() == Qt::Horizontal
)
2011 p
.drawLine( wr
.width()-1, 0, wr
.width()-1, wr
.height()-1 );
2013 p
.drawLine( 0, wr
.height()-1, wr
.width()-1, wr
.height()-1 );
2023 void HighColorStyle::renderGradient( QPainter
* p
, const QRect
& r
,
2024 QColor clr
, bool horizontal
, int px
, int py
, int pwidth
, int pheight
) const
2026 // Make 8 bit displays happy
2028 p
->fillRect(r
, clr
);
2032 // px, py specify the gradient pixmap offset relative to the top-left corner.
2033 // pwidth, pheight specify the width and height of the parent's pixmap.
2034 // We use these to draw parent-relative pixmaps for toolbar buttons
2035 // and menubar items.
2037 GradientSet
* grSet
= gDict
.find( clr
.rgb() );
2040 grSet
= new GradientSet(clr
);
2041 gDict
.insert( clr
.rgb(), grSet
);
2045 int width
= (pwidth
!= -1) ? pwidth
: r
.width();
2048 p
->drawTiledPixmap(r
, *grSet
->gradient(HMed
), QPoint(px
, 0));
2049 else if (width
<= 52)
2050 p
->drawTiledPixmap(r
, *grSet
->gradient(HLarge
), QPoint(px
, 0));
2052 KPixmap
*hLarge
= grSet
->gradient(HLarge
);
2054 // Don't draw a gradient if we don't need to
2055 if (hLarge
->width() > px
)
2057 int pixmapWidth
= hLarge
->width() - px
;
2059 // Draw the gradient
2060 p
->drawTiledPixmap( r
.x(), r
.y(), pixmapWidth
, r
.height(),
2062 // Draw the remaining fill
2063 p
->fillRect(r
.x()+pixmapWidth
, r
.y(), r
.width()-pixmapWidth
,
2064 r
.height(), clr
.dark(110));
2067 p
->fillRect(r
, clr
.dark(110));
2071 // Vertical gradient
2072 // -----------------
2073 int height
= (pheight
!= -1) ? pheight
: r
.height();
2076 p
->drawTiledPixmap(r
, *grSet
->gradient(VSmall
), QPoint(0, py
));
2077 else if (height
<= 34)
2078 p
->drawTiledPixmap(r
, *grSet
->gradient(VMed
), QPoint(0, py
));
2079 else if (height
<= 64)
2080 p
->drawTiledPixmap(r
, *grSet
->gradient(VLarge
), QPoint(0, py
));
2082 KPixmap
*vLarge
= grSet
->gradient(VLarge
);
2084 // Only draw the upper gradient if we need to.
2085 if (vLarge
->height() > py
)
2087 int pixmapHeight
= vLarge
->height() - py
;
2089 // Draw the gradient
2090 p
->drawTiledPixmap( r
.x(), r
.y(), r
.width(), pixmapHeight
,
2092 // Draw the remaining fill
2093 p
->fillRect(r
.x(), r
.y()+pixmapHeight
, r
.width(),
2094 r
.height()-pixmapHeight
, clr
.dark(110));
2097 p
->fillRect(r
, clr
.dark(110));
2103 // vim: set noet ts=4 sw=4: