summaryrefslogtreecommitdiffstats
path: root/examples/themes/metal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/themes/metal.cpp')
-rw-r--r--examples/themes/metal.cpp253
1 files changed, 124 insertions, 129 deletions
diff --git a/examples/themes/metal.cpp b/examples/themes/metal.cpp
index 45c30d6..636e562 100644
--- a/examples/themes/metal.cpp
+++ b/examples/themes/metal.cpp
@@ -41,113 +41,112 @@ MetalStyle::MetalStyle() : QWindowsStyle() { }
/*!
Reimplementation from QStyle
*/
-void MetalStyle::polish( QApplication *app)
+void MetalStyle::applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
- oldPalette = app->palette();
-
- // we simply create a nice QColorGroup with a couple of fancy
- // pixmaps here and apply to it all widgets
-
- QFont f("times", app->font().pointSize() );
- f.setBold( TRUE );
- f.setItalic( TRUE );
- app->setFont( f, TRUE, "QMenuBar");
- app->setFont( f, TRUE, "QPopupMenu");
-
-
-
- // QPixmap button( stonedark_xpm );
-
- QColor gold("#B9B9A5A54040"); //same as topgrad below
- QPixmap button( 1, 1 ); button.fill( gold );
-
- QPixmap background(marble_xpm);
- QPixmap dark( 1, 1 ); dark.fill( red.dark() );
- QPixmap mid( stone1_xpm );
- QPixmap light( stone1_xpm );//1, 1 ); light.fill( green );
-
- QPalette op = app->palette();
-
- QColor backCol( 227,227,227 );
-
- // QPalette op(white);
- QColorGroup active (op.active().foreground(),
- QBrush(op.active().button(),button),
- QBrush(op.active().light(), light),
- QBrush(op.active().dark(), dark),
- QBrush(op.active().mid(), mid),
- op.active().text(),
- Qt::white,
- op.active().base(),// QColor(236,182,120),
- QBrush(backCol, background)
- );
- active.setColor( QColorGroup::ButtonText, Qt::white );
- active.setColor( QColorGroup::Shadow, Qt::black );
- QColorGroup disabled (op.disabled().foreground(),
- QBrush(op.disabled().button(),button),
- QBrush(op.disabled().light(), light),
- op.disabled().dark(),
- QBrush(op.disabled().mid(), mid),
- op.disabled().text(),
- Qt::white,
- op.disabled().base(),// QColor(236,182,120),
- QBrush(backCol, background)
- );
-
- QPalette newPalette( active, disabled, active );
- app->setPalette( newPalette, TRUE );
+ oldPalette = ceData.palette;
+
+ // we simply create a nice QColorGroup with a couple of fancy
+ // pixmaps here and apply to it all widgets
+
+ QFont f("times", ceData.font.pointSize() );
+ f.setBold( TRUE );
+ f.setItalic( TRUE );
+ applicationActionRequest(ceData, elementFlags, ptr, AAR_SetFont, QStyleApplicationActionRequestData(f, TRUE, "QMenuBar"));
+ applicationActionRequest(ceData, elementFlags, ptr, AAR_SetFont, QStyleApplicationActionRequestData(f, TRUE, "QPopupMenu"));
+
+ // QPixmap button( stonedark_xpm );
+
+ QColor gold("#B9B9A5A54040"); //same as topgrad below
+ QPixmap button( 1, 1 ); button.fill( gold );
+
+ QPixmap background(marble_xpm);
+ QPixmap dark( 1, 1 ); dark.fill( red.dark() );
+ QPixmap mid( stone1_xpm );
+ QPixmap light( stone1_xpm );//1, 1 ); light.fill( green );
+
+ QPalette op = ceData.palette;
+
+ QColor backCol( 227,227,227 );
+
+ // QPalette op(white);
+ QColorGroup active (op.active().foreground(),
+ QBrush(op.active().button(),button),
+ QBrush(op.active().light(), light),
+ QBrush(op.active().dark(), dark),
+ QBrush(op.active().mid(), mid),
+ op.active().text(),
+ Qt::white,
+ op.active().base(),// QColor(236,182,120),
+ QBrush(backCol, background)
+ );
+ active.setColor( QColorGroup::ButtonText, Qt::white );
+ active.setColor( QColorGroup::Shadow, Qt::black );
+ QColorGroup disabled (op.disabled().foreground(),
+ QBrush(op.disabled().button(),button),
+ QBrush(op.disabled().light(), light),
+ op.disabled().dark(),
+ QBrush(op.disabled().mid(), mid),
+ op.disabled().text(),
+ Qt::white,
+ op.disabled().base(),// QColor(236,182,120),
+ QBrush(backCol, background)
+ );
+
+ QPalette newPalette( active, disabled, active );
+ applicationActionRequest(ceData, elementFlags, ptr, AAR_SetPalette, QStyleApplicationActionRequestData(newPalette, TRUE));
}
/*!
Reimplementation from QStyle
*/
-void MetalStyle::unPolish( QApplication *app)
+void MetalStyle::applicationUnPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
- app->setPalette(oldPalette, TRUE);
- app->setFont( app->font(), TRUE );
+ applicationActionRequest(ceData, elementFlags, ptr, AAR_SetPalette, QStyleApplicationActionRequestData(oldPalette, TRUE));
+ applicationActionRequest(ceData, elementFlags, ptr, AAR_SetFont, QStyleApplicationActionRequestData(ceData.font, TRUE));
}
/*!
Reimplementation from QStyle
*/
-void MetalStyle::polish( QWidget* w)
+void MetalStyle::polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
+ // the polish function sets some widgets to transparent mode and
+ // some to translate background mode in order to get the full
+ // benefit from the nice pixmaps in the color group.
- // the polish function sets some widgets to transparent mode and
- // some to translate background mode in order to get the full
- // benefit from the nice pixmaps in the color group.
-
- if (w->inherits("QPushButton")){
- w->setBackgroundMode( QWidget::NoBackground );
- return;
- }
-
- if ( !w->isTopLevel() ) {
- if ( w->backgroundPixmap() )
- w->setBackgroundOrigin( QWidget::WindowOrigin );
- }
+ if (ceData.widgetObjectTypes.contains("QPushButton")) {
+ widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundMode, QStyleWidgetActionRequestData(QWidget::NoBackground));
+ return;
+ }
+
+ if ( !(elementFlags & CEF_IsTopLevel) ) {
+ if ( !ceData.bgPixmap.isNull() ) {
+ widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundOrigin, QStyleWidgetActionRequestData(QWidget::WindowOrigin));
+ }
+ }
}
-void MetalStyle::unPolish( QWidget* w)
+void MetalStyle::unPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr )
{
-
- // the polish function sets some widgets to transparent mode and
- // some to translate background mode in order to get the full
- // benefit from the nice pixmaps in the color group.
-
- if (w->inherits("QPushButton")){
- w->setBackgroundMode( QWidget::PaletteButton );
- return;
- }
- if ( !w->isTopLevel() ) {
- if ( w->backgroundPixmap() )
- w->setBackgroundOrigin( QWidget::WidgetOrigin );
- }
-
+ // the polish function sets some widgets to transparent mode and
+ // some to translate background mode in order to get the full
+ // benefit from the nice pixmaps in the color group.
+
+ if (ceData.widgetObjectTypes.contains("QPushButton")) {
+ widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundMode, QStyleWidgetActionRequestData(QWidget::PaletteButton));
+ return;
+ }
+ if ( !(elementFlags & CEF_IsTopLevel) ) {
+ if ( !ceData.bgPixmap.isNull() ) {
+ widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundOrigin, QStyleWidgetActionRequestData(QWidget::WidgetOrigin));
+ }
+ }
}
void MetalStyle::drawPrimitive( PrimitiveElement pe,
QPainter *p,
+ QStyleControlElementData ceData,
+ ControlElementFlags elementFlags,
const QRect &r,
const QColorGroup &cg,
SFlags flags, const QStyleOption& opt ) const
@@ -170,13 +169,13 @@ void MetalStyle::drawPrimitive( PrimitiveElement pe,
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
flags & Style_Down, !( flags & Style_Horizontal ) );
drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowRight :PE_ArrowDown,
- p, r, cg, flags, opt );
+ p, ceData, elementFlags, r, cg, flags, opt );
break;
case PE_ScrollBarSubLine:
drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
flags & Style_Down, !( flags & Style_Horizontal ) );
drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp,
- p, r, cg, flags, opt );
+ p, ceData, elementFlags, r, cg, flags, opt );
break;
@@ -185,24 +184,24 @@ void MetalStyle::drawPrimitive( PrimitiveElement pe,
flags & Style_Horizontal );
break;
default:
- QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt );
+ QWindowsStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt );
break;
}
}
void MetalStyle::drawControl( ControlElement element,
QPainter *p,
- const QWidget *widget,
+ QStyleControlElementData ceData,
+ ControlElementFlags elementFlags,
const QRect &r,
const QColorGroup &cg,
SFlags how,
- const QStyleOption& opt ) const
+ const QStyleOption& opt,
+ const QWidget *widget ) const
{
switch( element ) {
case CE_PushButton:
{
- const QPushButton *btn;
- btn = (const QPushButton*)widget;
int x1, y1, x2, y2;
r.coords( &x1, &y1, &x2, &y2 );
@@ -212,14 +211,14 @@ void MetalStyle::drawControl( ControlElement element,
QBrush fill;
- if ( btn->isDown() )
+ if ( elementFlags & CEF_IsDown )
fill = cg.brush( QColorGroup::Mid );
- else if ( btn->isOn() )
+ else if ( elementFlags & CEF_IsOn )
fill = QBrush( cg.mid(), Dense4Pattern );
else
fill = cg.brush( QColorGroup::Button );
- if ( btn->isDefault() ) {
+ if ( elementFlags & CEF_IsDefault ) {
QPointArray a;
a.setPoints( 9,
x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
@@ -232,23 +231,23 @@ void MetalStyle::drawControl( ControlElement element,
y2 -= 2;
}
SFlags flags = Style_Default;
- if ( btn->isOn() )
+ if ( elementFlags & CEF_IsOn )
flags |= Style_On;
- if ( btn->isDown() )
+ if ( elementFlags & CEF_IsDown )
flags |= Style_Down;
- if ( !btn->isFlat() && !btn->isDown() )
+ if ( !(elementFlags & CEF_IsFlat) && !(elementFlags & CEF_IsDown) )
flags |= Style_Raised;
- drawPrimitive( PE_ButtonCommand, p,
+ drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags,
QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
cg, flags, opt );
- if ( btn->isMenuButton() ) {
+ if ( (elementFlags & CEF_IsMenuWidget) ) {
flags = Style_Default;
- if ( btn->isEnabled() )
+ if ( elementFlags & CEF_IsEnabled )
flags |= Style_Enabled;
int dx = ( y1 - y2 - 4 ) / 3;
- drawPrimitive( PE_ArrowDown, p,
+ drawPrimitive( PE_ArrowDown, p, ceData, elementFlags,
QRect(x2 - dx, dx, y1, y2 - y1),
cg, flags, opt );
}
@@ -258,8 +257,6 @@ void MetalStyle::drawControl( ControlElement element,
}
case CE_PushButtonLabel:
{
- const QPushButton *btn;
- btn = (const QPushButton*)widget;
int x, y, w, h;
r.rect( &x, &y, &w, &h );
@@ -267,9 +264,9 @@ void MetalStyle::drawControl( ControlElement element,
r.coords( &x1, &y1, &x2, &y2 );
int dx = 0;
int dy = 0;
- if ( btn->isMenuButton() )
+ if ( (elementFlags & CEF_IsMenuWidget) )
dx = ( y2 - y1 ) / 3;
- if ( btn->isOn() || btn->isDown() ) {
+ if ( (elementFlags & CEF_IsOn) || (elementFlags & CEF_IsDown) ) {
dx--;
dy--;
}
@@ -281,64 +278,62 @@ void MetalStyle::drawControl( ControlElement element,
h -= 4;
drawItem( p, QRect( x, y, w, h ),
AlignCenter|ShowPrefix,
- cg, btn->isEnabled(),
- btn->pixmap(), btn->text(), -1,
- (btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
+ cg, (elementFlags & CEF_IsEnabled),
+ (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text, -1,
+ ((elementFlags & CEF_IsDown) || (elementFlags & CEF_IsOn))? &cg.brightText() : &cg.buttonText() );
if ( dx || dy )
p->translate( -dx, -dy );
break;
}
default:
- QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
+ QWindowsStyle::drawControl( element, p, ceData, elementFlags, r, cg, how, opt, widget );
break;
}
}
void MetalStyle::drawComplexControl( ComplexControl cc,
QPainter *p,
- const QWidget *widget,
+ QStyleControlElementData ceData,
+ ControlElementFlags elementFlags,
const QRect &r,
const QColorGroup &cg,
SFlags how,
SCFlags sub,
SCFlags subActive,
- const QStyleOption& opt ) const
+ const QStyleOption& opt,
+ const QWidget *widget ) const
{
switch ( cc ) {
case CC_Slider:
{
- const QSlider *slider = ( const QSlider* ) widget;
- QRect handle = querySubControlMetrics( CC_Slider, widget,
- SC_SliderHandle, opt);
+ QRect handle = querySubControlMetrics( CC_Slider, ceData, elementFlags,
+ SC_SliderHandle, opt, widget);
if ( sub & SC_SliderGroove )
- QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
- SC_SliderGroove, subActive, opt );
+ QWindowsStyle::drawComplexControl( cc, p, ceData, elementFlags, r, cg, how,
+ SC_SliderGroove, subActive, opt, widget );
if ( (sub & SC_SliderHandle) && handle.isValid() )
drawMetalButton( p, handle.x(), handle.y(), handle.width(),
handle.height(), FALSE,
- slider->orientation() == QSlider::Horizontal);
+ ceData.orientation == QSlider::Horizontal);
break;
}
case CC_ComboBox:
{
- // not exactly correct...
- const QComboBox *cmb = ( const QComboBox* ) widget;
-
qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
- cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
+ (elementFlags & CEF_IsEnabled) ? &cg.brush( QColorGroup::Base ) :
&cg.brush( QColorGroup::Background ) );
drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
how & Style_Sunken, TRUE );
- drawPrimitive( PE_ArrowDown, p,
+ drawPrimitive( PE_ArrowDown, p, ceData, elementFlags,
QRect( r.x() + r.width() - 2 - 16 + 2,
r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
cg,
- cmb->isEnabled() ? Style_Enabled : Style_Default,
+ (elementFlags & CEF_IsEnabled) ? Style_Enabled : Style_Default,
opt );
break;
}
default:
- QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
- opt );
+ QWindowsStyle::drawComplexControl( cc, p, ceData, elementFlags, r, cg, how, sub, subActive,
+ opt, widget );
break;
}
}
@@ -473,13 +468,13 @@ void MetalStyle::drawMetalGradient( QPainter *p, int x, int y, int w, int h,
-int MetalStyle::pixelMetric( PixelMetric metric, const QWidget *w ) const
+int MetalStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *w ) const
{
switch ( metric ) {
case PM_MenuBarFrameWidth:
return 2;
default:
- return QWindowsStyle::pixelMetric( metric, w );
+ return QWindowsStyle::pixelMetric( metric, ceData, elementFlags, w );
}
}