diff options
Diffstat (limited to 'examples/themes/wood.cpp')
-rw-r--r-- | examples/themes/wood.cpp | 364 |
1 files changed, 195 insertions, 169 deletions
diff --git a/examples/themes/wood.cpp b/examples/themes/wood.cpp index 2d17060..f5fa72a 100644 --- a/examples/themes/wood.cpp +++ b/examples/themes/wood.cpp @@ -769,156 +769,171 @@ NorwegianWoodStyle::NorwegianWoodStyle() : QWindowsStyle() /*! Reimplementation from QStyle */ -void NorwegianWoodStyle::polish( QApplication *app) +void NorwegianWoodStyle::applicationPolish( QStyleControlElementData ceData, ControlElementFlags, void *ptr ) { + if (ceData.widgetObjectTypes.contains("QApplication")) { + QApplication *app = reinterpret_cast<QApplication*>(ptr); - oldPalette = app->palette(); - - // we simply create a nice QColorGroup with a couple of fancy wood - // pixmaps here and apply to it all widgets - - QImage img(button_xpm); - QImage orig = img; - orig.detach(); - QPixmap button; - button.convertFromImage(img); - - - int i; - for (i=0; i<img.numColors(); i++) { - QRgb rgb = img.color(i); - QColor c(rgb); - rgb = c.dark(120).rgb(); - img.setColor(i,rgb); - } - QPixmap mid; - mid.convertFromImage(img); - - img = orig; - img.detach(); - for (i=0; i<img.numColors(); i++) { - QRgb rgb = img.color(i); - QColor c(rgb); - rgb = c.light().rgb(); - img.setColor(i,rgb); - } - QPixmap light; - light.convertFromImage(img); - - img = orig; - img.detach(); - for (i=0; i<img.numColors(); i++) { - QRgb rgb = img.color(i); - QColor c(rgb); - rgb = c.dark(180).rgb(); - img.setColor(i,rgb); - } - QPixmap dark; - dark.convertFromImage(img); - - - QImage bgimage(polish_xpm); - QPixmap background; - background.convertFromImage(bgimage); - - img = bgimage; - img.detach(); - for (i=0; i<img.numColors(); i++) { - QRgb rgb = img.color(i); - QColor c(rgb); - rgb = c.dark(180).rgb(); - img.setColor(i,rgb); - } - sunkenDark = new QPixmap; - sunkenDark->convertFromImage(img); - - - img = bgimage; - img.detach(); - for (i=0; i<img.numColors(); i++) { - QRgb rgb = img.color(i); - QColor c(rgb); - rgb = c.light(130).rgb(); - img.setColor(i,rgb); - } - sunkenLight= new QPixmap; - sunkenLight->convertFromImage(img); - - - - QPalette op(QColor(212,140,95)); - // 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, - QColor(236,182,120), - QBrush(op.active().background(), background) - ); - 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, - QColor(236,182,120), - QBrush(op.disabled().background(), background) - ); - - app->setPalette(QPalette(active, disabled, active), TRUE ); - + oldPalette = app->palette(); + + // we simply create a nice QColorGroup with a couple of fancy wood + // pixmaps here and apply to it all widgets + + QImage img(button_xpm); + QImage orig = img; + orig.detach(); + QPixmap button; + button.convertFromImage(img); + + + int i; + for (i=0; i<img.numColors(); i++) { + QRgb rgb = img.color(i); + QColor c(rgb); + rgb = c.dark(120).rgb(); + img.setColor(i,rgb); + } + QPixmap mid; + mid.convertFromImage(img); + + img = orig; + img.detach(); + for (i=0; i<img.numColors(); i++) { + QRgb rgb = img.color(i); + QColor c(rgb); + rgb = c.light().rgb(); + img.setColor(i,rgb); + } + QPixmap light; + light.convertFromImage(img); + + img = orig; + img.detach(); + for (i=0; i<img.numColors(); i++) { + QRgb rgb = img.color(i); + QColor c(rgb); + rgb = c.dark(180).rgb(); + img.setColor(i,rgb); + } + QPixmap dark; + dark.convertFromImage(img); + + + QImage bgimage(polish_xpm); + QPixmap background; + background.convertFromImage(bgimage); + + img = bgimage; + img.detach(); + for (i=0; i<img.numColors(); i++) { + QRgb rgb = img.color(i); + QColor c(rgb); + rgb = c.dark(180).rgb(); + img.setColor(i,rgb); + } + sunkenDark = new QPixmap; + sunkenDark->convertFromImage(img); + + + img = bgimage; + img.detach(); + for (i=0; i<img.numColors(); i++) { + QRgb rgb = img.color(i); + QColor c(rgb); + rgb = c.light(130).rgb(); + img.setColor(i,rgb); + } + sunkenLight= new QPixmap; + sunkenLight->convertFromImage(img); + + + + QPalette op(QColor(212,140,95)); + // 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, + QColor(236,182,120), + QBrush(op.active().background(), background) + ); + 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, + QColor(236,182,120), + QBrush(op.disabled().background(), background) + ); + + app->setPalette(QPalette(active, disabled, active), TRUE ); + } } -void NorwegianWoodStyle::unPolish( QApplication *app) +void NorwegianWoodStyle::applicationUnPolish( QStyleControlElementData ceData, ControlElementFlags, void *ptr ) { - app->setPalette(oldPalette, TRUE); + if (ceData.widgetObjectTypes.contains("QApplication")) { + QApplication *app = reinterpret_cast<QApplication*>(ptr); + + app->setPalette(oldPalette, TRUE); + } } /*! Reimplementation from QStyle */ -void NorwegianWoodStyle::polish( QWidget* w) +void NorwegianWoodStyle::polish( QStyleControlElementData ceData, ControlElementFlags, void *ptr ) { + if (ceData.widgetObjectTypes.contains("QWidget")) { + QWidget *w = reinterpret_cast<QWidget*>(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->isTopLevel() ) { - if ( w->inherits("QPushButton") - || w->inherits("QToolButton") - || w->inherits("QComboBox") ) { - w->setAutoMask( TRUE ); - return; + // 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->isTopLevel() ) { + if ( w->inherits("QPushButton") + || w->inherits("QToolButton") + || w->inherits("QComboBox") ) { + w->setAutoMask( TRUE ); + return; + } + if ( w->backgroundPixmap() ) + w->setBackgroundOrigin( QWidget::WindowOrigin ); + } } - if ( w->backgroundPixmap() ) - w->setBackgroundOrigin( QWidget::WindowOrigin ); - } } -void NorwegianWoodStyle::unPolish( QWidget* w) +void NorwegianWoodStyle::unPolish( QStyleControlElementData ceData, ControlElementFlags, 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->isTopLevel() ) { - if ( w->inherits("QPushButton") - || w->inherits("QToolButton") - || w->inherits("QComboBox") ) { - w->setAutoMask( FALSE ); - return; + if (ceData.widgetObjectTypes.contains("QWidget")) { + QWidget *w = reinterpret_cast<QWidget*>(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->isTopLevel() ) { + if ( w->inherits("QPushButton") + || w->inherits("QToolButton") + || w->inherits("QComboBox") ) { + w->setAutoMask( FALSE ); + return; + } + if ( w->backgroundPixmap() ) + w->setBackgroundOrigin( QWidget::WidgetOrigin ); + } } - if ( w->backgroundPixmap() ) - w->setBackgroundOrigin( QWidget::WidgetOrigin ); - } } void NorwegianWoodStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, const QStyleOption& opt ) const @@ -970,28 +985,30 @@ void NorwegianWoodStyle::drawPrimitive( PrimitiveElement pe, } case PE_ScrollBarAddLine: if ( flags & Style_Horizontal ) - drawSemicircleButton( p, r, PointRight, flags & Style_Down, cg ); + drawSemicircleButton( p, ceData, elementFlags, r, PointRight, flags & Style_Down, cg ); else - drawSemicircleButton( p, r, PointDown, flags & Style_Down, cg ); + drawSemicircleButton( p, ceData, elementFlags, r, PointDown, flags & Style_Down, cg ); break; case PE_ScrollBarSubLine: if ( flags & Style_Horizontal ) - drawSemicircleButton( p, r, PointLeft, flags & Style_Down, cg ); + drawSemicircleButton( p, ceData, elementFlags, r, PointLeft, flags & Style_Down, cg ); else - drawSemicircleButton( p, r, PointUp, flags & Style_Down, cg ); + drawSemicircleButton( p, ceData, elementFlags, r, PointUp, flags & Style_Down, cg ); break; default: - QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt ); + QWindowsStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; } } void NorwegianWoodStyle::drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, - SFlags how, const QStyleOption& opt ) const + SFlags how, const QStyleOption& opt, + const QWidget *widget ) const { switch( element ) { case CE_PushButton: @@ -1033,7 +1050,7 @@ void NorwegianWoodStyle::drawControl( ControlElement element, y2 -= 2; } - drawPrimitive( PE_ButtonCommand, p, + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1), myCg, flags, opt ); @@ -1052,7 +1069,7 @@ void NorwegianWoodStyle::drawControl( ControlElement element, flags = Style_Default; if ( btn->isEnabled() ) flags |= Style_Enabled; - drawPrimitive( PE_ArrowDown, p, + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, QRect( x2 - dx, dx, y1, y2 - y1), myCg, flags, opt ); } @@ -1092,16 +1109,18 @@ void NorwegianWoodStyle::drawControl( ControlElement element, break; } default: - QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt ); + QWindowsStyle::drawControl( element, p, ceData, elementFlags, r, cg, how, opt, widget ); break; } } void NorwegianWoodStyle::drawControlMask( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch( element ) { case CE_PushButton: @@ -1113,20 +1132,22 @@ void NorwegianWoodStyle::drawControlMask( ControlElement element, break; } default: - QWindowsStyle::drawControlMask( element, p, widget, r, opt ); + QWindowsStyle::drawControlMask( element, p, ceData, elementFlags, r, opt, widget ); break; } } void NorwegianWoodStyle::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_ComboBox: @@ -1135,15 +1156,15 @@ void NorwegianWoodStyle::drawComplexControl( ComplexControl cc, cmb = (const QComboBox*)widget; int awh, ax, ay, sh, sy, dh, ew; - get_combo_parameters( subRect(SR_PushButtonContents, widget), + get_combo_parameters( subRect(SR_PushButtonContents, ceData, elementFlags, widget), ew, awh, ax, ay, sh, dh, sy ); - drawPrimitive( PE_ButtonCommand, p, r, cg, Style_Raised, opt ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, r, cg, Style_Raised, opt ); QStyle *mstyle = QStyleFactory::create( "Motif" ); if ( mstyle ) - mstyle->drawPrimitive( PE_ArrowDown, p, + mstyle->drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, QRect(ax, ay, awh, awh), cg, how, opt ); else - drawPrimitive( PE_ArrowDown, p, + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, QRect(ax, ay, awh, awh), cg, how, opt ); QPen oldPen = p->pen(); @@ -1156,8 +1177,8 @@ void NorwegianWoodStyle::drawComplexControl( ComplexControl cc, p->setPen( oldPen ); if ( cmb->editable() ) { - QRect r( querySubControlMetrics(CC_ComboBox, widget, - SC_ComboBoxEditField, opt) ); + QRect r( querySubControlMetrics(CC_ComboBox, ceData, elementFlags, + SC_ComboBoxEditField, opt, widget) ); qDrawShadePanel( p, r, cg, TRUE, 1, &cg.brush(QColorGroup::Button) ); } @@ -1165,17 +1186,19 @@ void NorwegianWoodStyle::drawComplexControl( ComplexControl cc, 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; } } void NorwegianWoodStyle::drawComplexControlMask( ComplexControl control, QPainter *p, - const QWidget *widget, + const QStyleControlElementData ceData, + const ControlElementFlags elementFlags, const QRect &r, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch ( control ) { case CC_ComboBox: @@ -1187,15 +1210,17 @@ void NorwegianWoodStyle::drawComplexControlMask( ComplexControl control, break; } default: - QWindowsStyle::drawComplexControlMask( control, p, widget, r, opt ); + QWindowsStyle::drawComplexControlMask( control, p, ceData, elementFlags, r, opt, widget ); break; } } QRect NorwegianWoodStyle::querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { QRect rect; switch ( control ) { @@ -1204,15 +1229,15 @@ QRect NorwegianWoodStyle::querySubControlMetrics( ComplexControl control, switch( sc ) { case SC_ComboBoxEditField: { - rect = subRect( SR_PushButtonContents, widget ); + rect = subRect( SR_PushButtonContents, ceData, elementFlags, widget ); int ew = get_combo_extra_width( rect.height(), 0 ); rect.setRect( rect.x() + 1, rect.y() + 1, rect.width() - 2 - ew, rect.height() - 2 ); break; } default: - rect = QWindowsStyle::querySubControlMetrics( control, widget, - sc, opt ); + rect = QWindowsStyle::querySubControlMetrics( control, ceData, elementFlags, + sc, opt, widget ); break; } break; @@ -1237,21 +1262,21 @@ QRect NorwegianWoodStyle::querySubControlMetrics( ComplexControl control, rect.setRect( b, b, w - 2 * b, w - 2 * b ); break; default: - rect = QWindowsStyle::querySubControlMetrics( control, widget, - sc, opt ); + rect = QWindowsStyle::querySubControlMetrics( control, ceData, elementFlags, + sc, opt, widget ); break; } break; } default: - rect = QWindowsStyle::querySubControlMetrics( control, widget, - sc, opt ); + rect = QWindowsStyle::querySubControlMetrics( control, ceData, elementFlags, + sc, opt, widget ); break; } return rect; } -QRect NorwegianWoodStyle::subRect( SubRect sr, const QWidget * widget ) const +QRect NorwegianWoodStyle::subRect( SubRect sr, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget * widget ) const { QRect r; switch ( sr ) { @@ -1276,14 +1301,14 @@ QRect NorwegianWoodStyle::subRect( SubRect sr, const QWidget * widget ) const } case SR_ComboBoxFocusRect: { - r = subRect( SR_PushButtonContents, widget ); + r = subRect( SR_PushButtonContents, ceData, elementFlags, widget ); int ew = get_combo_extra_width( r.height() ); r.setRect( r.x() + 1, r.y() + 1, r.width() - 2 - ew, r.height() - 2 ); break; } default: - r = QWindowsStyle::subRect( sr, widget ); + r = QWindowsStyle::subRect( sr, ceData, elementFlags, widget ); break; } return r; @@ -1358,11 +1383,12 @@ static void get_combo_parameters( const QRect &r, static inline int buttonthickness( int d ) { return d > 20 ? 5 : ( d < 10 ? 2: 3 ); } -void NorwegianWoodStyle::drawSemicircleButton( QPainter *p, const QRect &r, +void NorwegianWoodStyle::drawSemicircleButton( QPainter *p, QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, int dir, bool sunken, const QColorGroup &g ) const { - int b = pixelMetric( PM_ScrollBarExtent ) > 20 ? 3 : 2; + int b = pixelMetric( PM_ScrollBarExtent, ceData, elementFlags ) > 20 ? 3 : 2; QRegion extrn( r.x(), r.y(), r.width(), r.height(), QRegion::Ellipse ); QRegion intern( r.x()+b, r.y()+b, r.width()-2*b, r.height()-2*b, QRegion::Ellipse ); |