From 69429dcfc35d449c78b346bdce536f17d926c755 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 30 Oct 2012 22:41:50 -0500 Subject: [PATCH] Add new style primatives for enhanced third party style compatibility --- src/kernel/qapplication.cpp | 31 ++++++++++++ src/kernel/qapplication.h | 1 + src/kernel/qstyle.h | 7 +++ src/styles/qcommonstyle.cpp | 3 ++ src/styles/qcompactstyle.cpp | 74 ++++++++++++++++++++------- src/styles/qcompactstyle.h | 9 ++++ src/styles/qmotifplusstyle.cpp | 41 +++++++++++---- src/styles/qmotifstyle.cpp | 46 +++++++++++------ src/styles/qsgistyle.cpp | 36 +++++++++----- src/styles/qwindowsstyle.cpp | 91 +++++++++++++++++++++++----------- 10 files changed, 254 insertions(+), 85 deletions(-) diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index 0478cf1..51aa247 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -1847,6 +1847,37 @@ QPalette QApplication::palette(const QWidget* w) return *app_pal; } +QPalette QApplication::palette(QStringList objectTypeList) +{ +#if defined(QT_CHECK_STATE) + if ( !qApp ) + qWarning( "QApplication::palette: This function can only be " + "called after the QApplication object has been created" ); +#endif + if ( !app_pal ) { + if ( !qt_std_pal ) + qt_create_std_palette(); + app_pal = new QPalette( *qt_std_pal ); + qt_fix_tooltips(); + } + + if ( (objectTypeList.count() > 0) && app_palettes ) { + QPalette* wp = app_palettes->find( objectTypeList[objectTypeList.count()-1] ); + if ( wp ) { + return *wp; + } + QAsciiDictIterator it( *app_palettes ); + const char* name; + while ( (name=it.currentKey()) != 0 ) { + if ( objectTypeList.contains(name) ) { + return *it.current(); + } + ++it; + } + } + return *app_pal; +} + /*! Changes the default application palette to \a palette. If \a informWidgets is TRUE, then existing widgets are informed about the diff --git a/src/kernel/qapplication.h b/src/kernel/qapplication.h index 39f7858..c34ff45 100644 --- a/src/kernel/qapplication.h +++ b/src/kernel/qapplication.h @@ -113,6 +113,7 @@ public: static void setGlobalMouseTracking( bool enable ); #ifndef QT_NO_PALETTE static QPalette palette( const QWidget* = 0 ); + static QPalette palette( QStringList ); static void setPalette( const QPalette &, bool informWidgets=FALSE, const char* className = 0 ); #endif diff --git a/src/kernel/qstyle.h b/src/kernel/qstyle.h index 27dbb07..5731f8f 100644 --- a/src/kernel/qstyle.h +++ b/src/kernel/qstyle.h @@ -458,6 +458,11 @@ public: PE_HeaderSectionMenu, + PE_PanelScrollBar, + PE_MenuItemIndicatorFrame, + PE_MenuItemIndicatorIconFrame, + PE_MenuItemIndicatorCheck, + // do not add any values below/greater this PE_CustomBase = 0xf000000 }; @@ -830,6 +835,8 @@ public: PM_MenuBarItemSpacing, PM_ToolBarItemSpacing, + PM_ArrowSize, + // do not add any values below/greater than this PM_CustomBase = 0xf0000000 }; diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index 2614bbf..3a1a8d8 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -2870,6 +2870,9 @@ int QCommonStyle::pixelMetric(PixelMetric m, QStyleControlElementData ceData, Co case PM_TabBarScrollButtonWidth: ret = 16; break; + case PM_ArrowSize: + ret = 7; + break; default: ret = 0; break; diff --git a/src/styles/qcompactstyle.cpp b/src/styles/qcompactstyle.cpp index 7c7e0f5..5b83f0e 100644 --- a/src/styles/qcompactstyle.cpp +++ b/src/styles/qcompactstyle.cpp @@ -189,13 +189,7 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, QStyleCont return; if ( mi->isChecked() ) { - if ( act && !dis ) { - qDrawShadePanel( p, x, y, checkcol, h, - g, TRUE, 1, &g.brush( QColorGroup::Button ) ); - } else { - qDrawShadePanel( p, x, y, checkcol, h, - g, TRUE, 1, &g.brush( QColorGroup::Midlight ) ); - } + drawPrimitive( PE_MenuItemIndicatorFrame, p, ceData, elementFlags, QRect(x, y, checkcol, h), itemg, flags, opt ); } else if ( !act ) { p->fillRect(x, y, checkcol , h, g.brush( QColorGroup::Button )); @@ -214,7 +208,7 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, QStyleCont int pixh = pixmap.height(); if ( act && !dis ) { if ( !mi->isChecked() ) - qDrawShadePanel( p, x, y, checkcol, h, g, FALSE, 1, &g.brush( QColorGroup::Button ) ); + drawPrimitive( PE_MenuItemIndicatorIconFrame, p, ceData, elementFlags, QRect(x, y, checkcol, h), itemg, flags, opt ); } QRect cr( x, y, checkcol, h ); QRect pmr( 0, 0, pixw, pixh ); @@ -226,18 +220,8 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, QStyleCont g.brush( QColorGroup::Button ); p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill); } else if ( checkable ) { // just "checking"... - int mw = checkcol + motifItemFrame; - int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { - - SFlags cflags = Style_Default; - if (! dis) - cflags |= Style_Enabled; - if (act) - cflags |= Style_On; - - drawPrimitive( PE_CheckMark, p, ceData, elementFlags, QRect(x + motifItemFrame + 2, y + motifItemFrame, - mw, mh), itemg, cflags, opt ); + drawPrimitive( PE_MenuItemIndicatorCheck, p, ceData, elementFlags, QRect(x, y, checkcol, h), itemg, flags, opt ); } } @@ -319,4 +303,56 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, QStyleCont } } +/*! \reimp */ +void QCompactStyle::drawPrimitive( PrimitiveElement pe, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags flags, + const QStyleOption& opt ) const +{ + bool dis = !(flags & Style_Enabled); + bool act = flags & Style_Active; + + int x, y, w, h; + r.rect( &x, &y, &w, &h ); + + switch (pe) { + case PE_MenuItemIndicatorFrame: + { + if ( act && !dis ) { + qDrawShadePanel( p, x, y, w, h, cg, TRUE, 1, &cg.brush( QColorGroup::Button ) ); + } else { + qDrawShadePanel( p, x, y, w, h, cg, TRUE, 1, &cg.brush( QColorGroup::Midlight ) ); + } + } + break; + case PE_MenuItemIndicatorIconFrame: + { + qDrawShadePanel( p, x, y, w, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) ); + } + break; + case PE_MenuItemIndicatorCheck: + { + int mw = w + motifItemFrame; + int mh = h - 2*motifItemFrame; + + SFlags cflags = Style_Default; + if (! dis) { + cflags |= Style_Enabled; + } + if (act) { + cflags |= Style_On; + } + + drawPrimitive( PE_CheckMark, p, ceData, elementFlags, QRect(x + motifItemFrame + 2, y + motifItemFrame, mw, mh), cg, cflags, opt ); + } + break; + default: + break; + } +} + #endif diff --git a/src/styles/qcompactstyle.h b/src/styles/qcompactstyle.h index 2f9748b..3b209cf 100644 --- a/src/styles/qcompactstyle.h +++ b/src/styles/qcompactstyle.h @@ -60,6 +60,15 @@ public: int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ); + void drawPrimitive( PrimitiveElement pe, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags flags = Style_Default, + const QStyleOption& = QStyleOption::Default ) const; + void drawControl( ControlElement element, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, const QStyleOption& = QStyleOption::Default, const QWidget *w = 0 ); diff --git a/src/styles/qmotifplusstyle.cpp b/src/styles/qmotifplusstyle.cpp index 72e28a8..86db691 100644 --- a/src/styles/qmotifplusstyle.cpp +++ b/src/styles/qmotifplusstyle.cpp @@ -282,6 +282,9 @@ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, SFlags flags, const QStyleOption& opt ) const { + bool dis = ! (flags & Style_Enabled); + bool act = flags & Style_Active; + switch (pe) { case PE_HeaderSection: @@ -638,6 +641,28 @@ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, break; } + case PE_PanelScrollBar: + { + drawMotifPlusShade(p, r, cg, TRUE, FALSE, &cg.brush(QColorGroup::Mid)); + break; + } + + case PE_MenuItemIndicatorCheck: + { + int x, y, w, h; + r.rect(&x, &y, &w, &h); + QRect vrect = visualRect( QRect( x+2, y+2, w, h-2 ), r ); + + SFlags cflags = Style_Default; + if (! dis) + cflags |= Style_Enabled; + if (act) + cflags |= Style_On; + + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, vrect, cg, cflags); + break; + } + default: QMotifStyle::drawPrimitive(pe, p, ceData, elementFlags, r, cg, flags, opt); break; @@ -828,13 +853,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, } else if (checkable) { if (mi->isChecked()) { - SFlags cflags = Style_Default; - if (! dis) - cflags |= Style_Enabled; - if (act) - cflags |= Style_On; - - drawPrimitive(PE_CheckMark, p, ceData, elementFlags, vrect, cg, cflags); + drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, QRect(x, y, checkcol, h), cg, flags); } } @@ -1147,8 +1166,12 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, if (controls == (SC_ScrollBarAddLine | SC_ScrollBarSubLine | SC_ScrollBarAddPage | SC_ScrollBarSubPage | SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider)) - drawMotifPlusShade(p, widget->rect(), cg, TRUE, FALSE, - &cg.brush(QColorGroup::Mid)); + drawPrimitive(PE_PanelScrollBar, p, ceData, elementFlags, ceData.rect, cg, + ((maxedOut) ? Style_Default : Style_Enabled) | + ((active == SC_ScrollBarLast) ? + Style_Down : Style_Default) | + ((ceData.orientation == Qt::Horizontal) ? + Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarSubLine) && subline.isValid()) drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg, diff --git a/src/styles/qmotifstyle.cpp b/src/styles/qmotifstyle.cpp index e91e0d0..422dacb 100644 --- a/src/styles/qmotifstyle.cpp +++ b/src/styles/qmotifstyle.cpp @@ -211,6 +211,9 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, SFlags flags, const QStyleOption& opt ) const { + bool dis = ! (flags & Style_Enabled); + bool act = flags & Style_Active; + switch( pe ) { #ifndef QT_NO_LISTVIEW case PE_CheckListExclusiveIndicator: { @@ -761,6 +764,30 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, r.height() - 4, cg.brush(QColorGroup::Highlight)); break; + case PE_PanelScrollBar: + qDrawShadePanel(p, r, cg, TRUE, + pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags), + &cg.brush(QColorGroup::Mid)); + break; + + case PE_MenuItemIndicatorCheck: + { + int x, y, w, h; + r.rect( &x, &y, &w, &h ); + QRect vrect = visualRect( QRect( x+motifItemFrame, y+motifItemFrame, w, h-2*motifItemFrame ), r ); + int xvis = vrect.x(); + int mw = w; + int mh = h - 2*motifItemFrame; + + SFlags cflags = Style_Default; + if (! dis) + cflags |= Style_Enabled; + if (act) + cflags |= Style_On; + + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, QRect(xvis, y+motifItemFrame, mw, mh), cg, cflags); + } + default: QCommonStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; @@ -1076,18 +1103,8 @@ void QMotifStyle::drawControl( ControlElement element, p->drawPixmap( pmr.topLeft(), pixmap ); } else if ( checkable ) { // just "checking"... - int mw = checkcol; - int mh = h - 2*motifItemFrame; if ( mi->isChecked() ) { - SFlags cflags = Style_Default; - if (! dis) - cflags |= Style_Enabled; - if (act) - cflags |= Style_On; - - drawPrimitive(PE_CheckMark, p, ceData, elementFlags, - QRect(xvis, y+motifItemFrame, mw, mh), - cg, cflags); + drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, QRect(x, y, checkcol, h), cg, flags); } } @@ -1339,9 +1356,10 @@ void QMotifStyle::drawComplexControl( ComplexControl control, if (sub == (SC_ScrollBarAddLine | SC_ScrollBarSubLine | SC_ScrollBarAddPage | SC_ScrollBarSubPage | SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider)) - qDrawShadePanel(p, ceData.rect, cg, TRUE, - pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget), - &cg.brush(QColorGroup::Mid)); + drawPrimitive(PE_PanelScrollBar, p, ceData, elementFlags, ceData.rect, cg, + ((ceData.orientation == Qt::Horizontal) ? + Style_Horizontal : Style_Default)); + QCommonStyle::drawComplexControl(control, p, ceData, elementFlags, r, cg, flags, sub, subActive, opt, widget); break; diff --git a/src/styles/qsgistyle.cpp b/src/styles/qsgistyle.cpp index a66fcda..b65100c 100644 --- a/src/styles/qsgistyle.cpp +++ b/src/styles/qsgistyle.cpp @@ -567,6 +567,9 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, const int defaultFrameWidth = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ); bool hot = ( flags & Style_MouseOver ) && ( flags & Style_Enabled ); + bool dis = ! (flags & Style_Enabled); + bool act = flags & Style_Active; + switch ( pe ) { case PE_ButtonCommand: { @@ -878,6 +881,25 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, } break; + case PE_MenuItemIndicatorCheck: + { + int x, y, w, h; + r.rect(&x, &y, &w, &h); + + SFlags cflags = Style_Default; + if (! dis) + cflags |= Style_Enabled; + if (act) + cflags |= Style_On; + + QRect er( x+sgiItemFrame+1, y+sgiItemFrame+3, pixelMetric(PM_IndicatorWidth, ceData, elementFlags), pixelMetric(PM_IndicatorHeight, ceData, elementFlags) ); + er.addCoords( 1, 1, -1, -1 ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, er, cg, cflags, opt ); + er.addCoords( 0, 1, 1, 1 ); + drawPrimitive( PE_CheckMark, p, ceData, elementFlags, er, cg, cflags | Style_On, opt ); + } + break; + default: QMotifStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; @@ -1018,20 +1040,8 @@ void QSGIStyle::drawControl( ControlElement element, p->drawPixmap( pmr.topLeft(), pixmap ); } else { if ( checkable ) { - SFlags cflags = Style_Default; - if (! dis) - cflags |= Style_Enabled; - if (act) - cflags |= Style_On; - if ( mi->isChecked() ) { - QRect er( x+sgiItemFrame+1, y+sgiItemFrame+3, - pixelMetric(PM_IndicatorWidth, ceData, elementFlags), - pixelMetric(PM_IndicatorHeight, ceData, elementFlags) ); - er.addCoords( 1, 1, -1, -1 ); - drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, er, cg, cflags, opt ); - er.addCoords( 0, 1, 1, 1 ); - drawPrimitive( PE_CheckMark, p, ceData, elementFlags, er, cg, cflags | Style_On, opt ); + drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, QRect(x, y, w, h), cg, flags); } } } diff --git a/src/styles/qwindowsstyle.cpp b/src/styles/qwindowsstyle.cpp index 4bdb421..578b32f 100644 --- a/src/styles/qwindowsstyle.cpp +++ b/src/styles/qwindowsstyle.cpp @@ -225,6 +225,9 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, SFlags flags, const QStyleOption& opt ) const { + bool dis = !(flags & Style_Enabled); + bool act = flags & Style_Active; + QRect rr( r ); switch (pe) { case PE_ButtonCommand: @@ -568,6 +571,60 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, } break; + case PE_MenuItemIndicatorFrame: + { + int x, y, w, h; + r.rect( &x, &y, &w, &h ); + + QRect vrect = visualRect( QRect( x, y, w, h ), r ); + int xvis = vrect.x(); + + if ( act && !dis ) { + qDrawShadePanel( p, xvis, y, w, h, cg, TRUE, 1, &cg.brush( QColorGroup::Button ) ); + } + else { + QBrush fill( cg.light(), Dense4Pattern ); + // set the brush origin for the hash pattern to the x/y coordinate + // of the menu item's checkmark... this way, the check marks have + // a consistent look + QPoint origin = p->brushOrigin(); + p->setBrushOrigin( xvis, y ); + qDrawShadePanel( p, xvis, y, w, h, cg, TRUE, 1, &fill ); + // restore the previous brush origin + p->setBrushOrigin( origin ); + } + } + break; + + case PE_MenuItemIndicatorIconFrame: + { + int x, y, w, h; + r.rect( &x, &y, &w, &h ); + + QRect vrect = visualRect( QRect( x, y, w, h ), r ); + int xvis = vrect.x(); + + qDrawShadePanel( p, xvis, y, w, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) ); + } + break; + + case PE_MenuItemIndicatorCheck: + { + int x, y, w, h; + r.rect( &x, &y, &w, &h ); + + int xp = x + windowsItemFrame; + + SFlags cflags = Style_Default; + if (! dis) + cflags |= Style_Enabled; + if (act) + cflags |= Style_On; + + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, visualRect( QRect(xp, y + windowsItemFrame, w - 2*windowsItemFrame, h - 2*windowsItemFrame), r ), cg, cflags); + } + break; + default: if (pe >= PE_ArrowUp && pe <= PE_ArrowLeft) { QPointArray a; @@ -809,21 +866,7 @@ void QWindowsStyle::drawControl( ControlElement element, QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r ); int xvis = vrect.x(); if ( mi->isChecked() ) { - if ( act && !dis ) - qDrawShadePanel( p, xvis, y, checkcol, h, - cg, TRUE, 1, &cg.brush( QColorGroup::Button ) ); - else { - QBrush fill( cg.light(), Dense4Pattern ); - // set the brush origin for the hash pattern to the x/y coordinate - // of the menu item's checkmark... this way, the check marks have - // a consistent look - QPoint origin = p->brushOrigin(); - p->setBrushOrigin( xvis, y ); - qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, - &fill ); - // restore the previous brush origin - p->setBrushOrigin( origin ); - } + drawPrimitive(PE_MenuItemIndicatorFrame, p, ceData, elementFlags, QRect(x, y, checkcol, h), cg, flags); } else if (! act) p->fillRect(xvis, y, checkcol , h, cg.brush( QColorGroup::Button )); @@ -839,8 +882,7 @@ void QWindowsStyle::drawControl( ControlElement element, int pixw = pixmap.width(); int pixh = pixmap.height(); if ( act && !dis && !mi->isChecked() ) - qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, - &cg.brush( QColorGroup::Button ) ); + drawPrimitive(PE_MenuItemIndicatorIconFrame, p, ceData, elementFlags, QRect(x, y, checkcol, h), cg, flags); QRect pmr( 0, 0, pixw, pixh ); pmr.moveCenter( vrect.center() ); p->setPen( cg.text() ); @@ -851,20 +893,9 @@ void QWindowsStyle::drawControl( ControlElement element, cg.brush( QColorGroup::Button )); int xp = xpos + checkcol + 1; p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill); - } else if ( checkable ) { // just "checking"... + } else if ( checkable ) { // just "checking"... if ( mi->isChecked() ) { - int xp = xpos + windowsItemFrame; - - SFlags cflags = Style_Default; - if (! dis) - cflags |= Style_Enabled; - if (act) - cflags |= Style_On; - - drawPrimitive(PE_CheckMark, p, ceData, elementFlags, - visualRect( QRect(xp, y + windowsItemFrame, - checkcol - 2*windowsItemFrame, - h - 2*windowsItemFrame), r ), cg, cflags); + drawPrimitive(PE_MenuItemIndicatorCheck, p, ceData, elementFlags, QRect(x, y, checkcol, h), cg, flags); } }