1
//=========================================================
4
// $Id: mstyle.cpp,v 1.1 2002/01/30 14:54:03 muse Exp $
6
// (C) Copyright 2001 Werner Schweer (ws@seh.de)
7
//=========================================================
10
#include "qapplication.h"
11
#include "qcombobox.h"
13
#include "qdrawutil.h"
19
#include "qpushbutton.h"
21
#include "qrangecontrol.h"
22
#include "qscrollbar.h"
26
#include "stonedark.xpm"
30
MuseStyle::MuseStyle() : QMuseWindowsStyle() { }
32
//---------------------------------------------------------
34
//---------------------------------------------------------
36
void MuseStyle::polish(QApplication *app)
38
oldPalette = app->palette();
40
// we simply create a nice QColorGroup with a couple of fancy
41
// pixmaps here and apply to it all widgets
43
QFont f("times", app->font().pointSize());
46
app->setFont(f, true, "QMenuBar");
47
app->setFont(f, true, "QPopupMenu");
49
// QPixmap button( stonedark_xpm );
51
QColor gold("#B9B9A5A54040"); //same as topgrad below
55
QPixmap background(marble_xpm);
57
dark.fill(red.dark());
58
QPixmap mid(stone1_xpm);
59
QPixmap light(stone1_xpm );//1, 1 );
62
QPalette op = app->palette();
64
QColor backCol(227,227,227);
66
// QPalette op(white);
67
QColorGroup active (op.active().foreground(),
68
QBrush(op.active().button(),button),
69
QBrush(op.active().light(), light),
70
QBrush(op.active().dark(), dark),
71
QBrush(op.active().mid(), mid),
74
op.active().base(),// QColor(236,182,120),
75
QBrush(backCol, background)
77
active.setColor( QColorGroup::ButtonText, Qt::white );
78
active.setColor( QColorGroup::Shadow, Qt::black );
79
QColorGroup disabled (op.disabled().foreground(),
80
QBrush(op.disabled().button(),button),
81
QBrush(op.disabled().light(), light),
83
QBrush(op.disabled().mid(), mid),
86
op.disabled().base(),// QColor(236,182,120),
87
QBrush(backCol, background)
90
QPalette newPalette( active, disabled, active );
91
app->setPalette( newPalette, TRUE );
94
//---------------------------------------------------------
96
//---------------------------------------------------------
98
void MuseStyle::unPolish( QApplication *app)
100
app->setPalette(oldPalette, true);
101
app->setFont(app->font(), true);
105
Reimplementation from QStyle
107
void MuseStyle::polish( QWidget* w)
110
// the polish function sets some widgets to transparent mode and
111
// some to translate background mode in order to get the full
112
// benefit from the nice pixmaps in the color group.
114
if (w->inherits("QPushButton")){
115
w->setBackgroundMode( QWidget::NoBackground );
119
if ( !w->isTopLevel() ) {
120
if ( w->backgroundPixmap() )
121
w->setBackgroundOrigin( QWidget::WindowOrigin );
125
void MuseStyle::unPolish( QWidget* w)
128
// the polish function sets some widgets to transparent mode and
129
// some to translate background mode in order to get the full
130
// benefit from the nice pixmaps in the color group.
132
if (w->inherits("QPushButton")){
133
w->setBackgroundMode( QWidget::PaletteButton );
136
if ( !w->isTopLevel() ) {
137
if ( w->backgroundPixmap() )
138
w->setBackgroundOrigin( QWidget::WidgetOrigin );
143
void MuseStyle::drawPrimitive( PrimitiveElement pe,
146
const QColorGroup &cg,
147
SFlags flags, const QStyleOption& opt ) const
150
case PE_HeaderSection:
151
if ( flags & Style_Sunken )
152
flags ^= Style_Sunken | Style_Raised;
155
case PE_ButtonCommand:
156
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
157
(flags & (Style_Sunken|Style_On|Style_Down)),
158
TRUE, !(flags & Style_Raised) );
160
case PE_PanelMenuBar:
161
drawMetalFrame( p, r.x(), r.y(), r.width(), r.height() );
163
case PE_ScrollBarAddLine:
164
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
165
flags & Style_Down, !( flags & Style_Horizontal ) );
166
drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowRight :PE_ArrowDown,
167
p, r, cg, flags, opt );
169
case PE_ScrollBarSubLine:
170
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
171
flags & Style_Down, !( flags & Style_Horizontal ) );
172
drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp,
173
p, r, cg, flags, opt );
177
case PE_ScrollBarSlider:
178
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), FALSE,
179
flags & Style_Horizontal );
182
QMuseWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt );
187
void MuseStyle::drawControl( ControlElement element,
189
const QWidget *widget,
191
const QColorGroup &cg,
193
const QStyleOption& opt ) const
198
const QPushButton *btn;
199
btn = (const QPushButton*)widget;
202
r.coords( &x1, &y1, &x2, &y2 );
204
p->setPen( cg.foreground() );
205
p->setBrush( QBrush(cg.button(), NoBrush) );
210
fill = cg.brush( QColorGroup::Mid );
211
else if ( btn->isOn() )
212
fill = QBrush( cg.mid(), Dense4Pattern );
214
fill = cg.brush( QColorGroup::Button );
216
if ( btn->isDefault() ) {
219
x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
220
x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
221
p->setPen( Qt::black );
222
p->drawPolyline( a );
228
SFlags flags = Style_Default;
233
if ( !btn->isFlat() && !btn->isDown() )
234
flags |= Style_Raised;
235
drawPrimitive( PE_ButtonCommand, p,
236
QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
239
if ( btn->isMenuButton() ) {
240
flags = Style_Default;
241
if ( btn->isEnabled() )
242
flags |= Style_Enabled;
244
int dx = ( y1 - y2 - 4 ) / 3;
245
drawPrimitive( PE_ArrowDown, p,
246
QRect(x2 - dx, dx, y1, y2 - y1),
249
if ( p->brush().style() != NoBrush )
250
p->setBrush( NoBrush );
253
case CE_PushButtonLabel:
255
const QPushButton *btn;
256
btn = (const QPushButton*)widget;
258
r.rect( &x, &y, &w, &h );
261
r.coords( &x1, &y1, &x2, &y2 );
264
if ( btn->isMenuButton() )
265
dx = ( y2 - y1 ) / 3;
266
if ( btn->isOn() || btn->isDown() ) {
271
p->translate( dx, dy );
276
drawItem( p, QRect( x, y, w, h ),
277
AlignCenter|ShowPrefix,
278
cg, btn->isEnabled(),
279
btn->pixmap(), btn->text(), -1,
280
(btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
282
p->translate( -dx, -dy );
286
QMuseWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
290
void MuseStyle::drawComplexControl( ComplexControl cc,
292
const QWidget *widget,
294
const QColorGroup &cg,
298
const QStyleOption& opt ) const
303
const QSlider *slider = ( const QSlider* ) widget;
304
QRect handle = querySubControlMetrics( CC_Slider, widget,
305
SC_SliderHandle, opt);
306
if ( sub & SC_SliderGroove )
307
QMuseWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
308
SC_SliderGroove, subActive, opt );
309
if ( (sub & SC_SliderHandle) && handle.isValid() )
310
drawMetalButton( p, handle.x(), handle.y(), handle.width(),
311
handle.height(), FALSE,
312
slider->orientation() == QSlider::Horizontal);
317
// not exactly correct...
318
const QComboBox *cmb = ( const QComboBox* ) widget;
320
qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
321
cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
322
&cg.brush( QColorGroup::Background ) );
323
drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
324
how & Style_Sunken, TRUE );
325
drawPrimitive( PE_ArrowDown, p,
326
QRect( r.x() + r.width() - 2 - 16 + 2,
327
r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
329
cmb->isEnabled() ? Style_Enabled : Style_Default,
334
QMuseWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
342
Draw a metallic button, sunken if \a sunken is TRUE, horizontal if
346
void MuseStyle::drawMetalButton( QPainter *p, int x, int y, int w, int h,
347
bool sunken, bool horz, bool flat ) const
350
drawMetalFrame( p, x, y, w, h );
351
drawMetalGradient( p, x, y, w, h, sunken, horz, flat );
357
void MuseStyle::drawMetalFrame( QPainter *p, int x, int y, int w, int h ) const
359
QColor top1("#878769691515");
360
QColor top2("#C6C6B4B44949");
362
QColor bot2("#70705B5B1414");
363
QColor bot1("#56564A4A0E0E"); //first from the bottom
372
p->drawLine( x, y2, x, y );
373
p->drawLine( x, y, x2-1, y );
375
p->drawLine( x+1, y2 -1, x+1, y+1 );
376
p->drawLine( x+1, y+1 , x2-2, y+1 );
379
p->drawLine( x+1, y2, x2, y2 );
380
p->drawLine( x2, y2, x2, y );
382
p->drawLine( x+1, y2-1, x2-1, y2-1 );
383
p->drawLine( x2-1, y2-1, x2-1, y+1 );
389
void MuseStyle::drawMetalGradient( QPainter *p, int x, int y, int w, int h,
390
bool sunken, bool horz, bool flat ) const
393
QColor highlight("#E8E8DDDD6565");
394
QColor subh1("#CECEBDBD5151");
395
QColor subh2("#BFBFACAC4545");
397
QColor topgrad("#B9B9A5A54040");
398
QColor botgrad("#89896C6C1A1A");
402
if ( flat && !sunken ) {
403
p->fillRect( x + 2, y + 2, w - 4,h -4, topgrad );
416
#define DRAWLINE if (horz) \
417
p->drawLine( x1, y1+i, x2, y1+i ); \
419
p->drawLine( x1+i, y1, x1+i, y2 ); \
423
p->setPen( highlight );
432
int ng = (horz ? h : w) - 8; // how many lines for the gradient?
434
int h1, h2, s1, s2, v1, v2;
436
topgrad.hsv( &h1, &s1, &v1 );
437
botgrad.hsv( &h2, &s2, &v2 );
439
botgrad.hsv( &h1, &s1, &v1 );
440
topgrad.hsv( &h2, &s2, &v2 );
444
for ( int j =0; j < ng; j++ ) {
445
p->setPen( QColor( h1 + ((h2-h1)*j)/(ng-1),
446
s1 + ((s2-s1)*j)/(ng-1),
447
v1 + ((v2-v1)*j)/(ng-1), QColor::Hsv ) );
450
} else if ( ng == 1 ) {
451
p->setPen( QColor((h1+h2)/2, (s1+s2)/2, (v1+v2)/2, QColor::Hsv) );
461
p->setPen( highlight );
468
int MuseStyle::pixelMetric( PixelMetric metric, const QWidget *w ) const
471
case PM_MenuBarFrameWidth:
474
return QMuseWindowsStyle::pixelMetric( metric, w );