diff options
author | Darrell Anderson <humanreadable@yahoo.com> | 2012-08-08 15:38:38 -0500 |
---|---|---|
committer | Darrell Anderson <humanreadable@yahoo.com> | 2012-08-08 15:38:38 -0500 |
commit | a236ea2ad383387255621fc8eaddc3c5d17f1e30 (patch) | |
tree | ecacdf1f8c9c02f545e06f8a430a145998fe11ea /src | |
parent | 92b8aca467ad650f9b77a5b6a0f56c27ecbfe80a (diff) | |
parent | 47132557a4c58d4ad69bc2898bb2bd9c424b3b64 (diff) | |
download | qt3-a236ea2ad383387255621fc8eaddc3c5d17f1e30.tar.gz qt3-a236ea2ad383387255621fc8eaddc3c5d17f1e30.zip |
Merge branch 'master' of http://scm.trinitydesktop.org/scm/git/qt3
Diffstat (limited to 'src')
27 files changed, 3003 insertions, 1637 deletions
diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index cd1573b..ef6571a 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -2147,7 +2147,7 @@ void qt_init_internal( int *argcptr, char **argv, for (i = 0; i < map->max_keypermod; i++) { if (map->modifiermap[mapIndex]) { KeySym sym = - XKeycodeToKeysym(appDpy, map->modifiermap[mapIndex], 0); + XkbKeycodeToKeysym(appDpy, map->modifiermap[mapIndex], 0, 0); if ( qt_alt_mask == 0 && ( sym == XK_Alt_L || sym == XK_Alt_R ) ) { qt_alt_mask = 1 << maskIndex; @@ -2177,7 +2177,7 @@ void qt_init_internal( int *argcptr, char **argv, for ( i = 0; i < map->max_keypermod; i++ ) { if ( map->modifiermap[ mapIndex ] ) { KeySym sym = - XKeycodeToKeysym( appDpy, map->modifiermap[ mapIndex ], 0 ); + XkbKeycodeToKeysym( appDpy, map->modifiermap[ mapIndex ], 0, 0 ); if ( sym == XK_Mode_switch ) { qt_mode_switch_remove_mask |= 1 << maskIndex; } diff --git a/src/kernel/qstyle.cpp b/src/kernel/qstyle.cpp index 8c150d5..fc4daa2 100644 --- a/src/kernel/qstyle.cpp +++ b/src/kernel/qstyle.cpp @@ -44,6 +44,10 @@ #include "qpainter.h" #include "qbitmap.h" #include "qpixmapcache.h" +#include "qframe.h" +#include "qlayout.h" +#include "qobjectlist.h" +#include "qwidgetlist.h" #include <limits.h> @@ -394,6 +398,10 @@ public: */ QStyle::QStyle() { + m_eventHandlerInstallationHook = NULL; + m_eventHandlerRemovalHook = NULL; + m_widgetActionRequestHook = NULL; + conditionalAcceleratorsEnabled = false; d = new QStylePrivate; } @@ -414,8 +422,6 @@ QStyle::~QStyle() style. Current supported values are Qt::WindowsStyle and Qt::MotifStyle. */ - - /*! Initializes the appearance of a widget. @@ -439,8 +445,9 @@ QStyle::~QStyle() \sa unPolish() */ -void QStyle::polish( QWidget*) -{ +void QStyle::polish( QWidget *widget ) { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + polish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); } /*! @@ -453,10 +460,62 @@ void QStyle::polish( QWidget*) \sa polish() */ -void QStyle::unPolish( QWidget*) -{ +void QStyle::unPolish( QWidget *widget ) { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + unPolish(ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); +} + +/*! + Initializes the appearance of a widget. + + This function is called for every widget at some point after it + has been fully created but just \e before it is shown the very + first time. + + Reasonable actions in this function might be to install a widget + event handler for the style. An example of highly unreasonable + use would be setting the geometry! With Qt 3.0's style engine + you will rarely need to write your own polish(); instead reimplement + drawItem(), drawPrimitive(), etc. + + The \a objectTypes object may provide enough information to + allow class-specific customizations. But be careful not to + hard-code things too much because new QStyle subclasses are + expected to work reasonably with all current and \e future + widgets. + + You may specify either a QWidget pointer or a custom pointer. + If a custom pointer is specified, you must be careful to intercept any event + handler installation/removal calls via setEventHandlerInstallationHook and + setEventHandlerRemovalHook. + + \sa unPolish() +*/ +void QStyle::polish( QStyleControlElementData ceData, ControlElementFlags, void *ptr ) { + if (ceData.widgetObjectTypes.contains("QWidget")) { + // Enable dynamic hide/show of accelerator shortcuts + QWidget* widget = reinterpret_cast<QWidget*>(ptr); + widget->installEventFilter(this); + } } +/*! + Undoes the initialization of a widget's appearance. + + This function is the counterpart to polish. It is called for every + polished widget when the style is dynamically changed. The former + style has to unpolish its settings before the new style can polish + them again. + + \sa polish() +*/ +void QStyle::unPolish( QStyleControlElementData ceData, ControlElementFlags, void *ptr ) { + if (ceData.widgetObjectTypes.contains("QWidget")) { + // Disable dynamic hide/show of accelerator shortcuts + QWidget* widget = reinterpret_cast<QWidget*>(ptr); + widget->installEventFilter(this); + } +} /*! \overload @@ -464,8 +523,10 @@ void QStyle::unPolish( QWidget*) \sa unPolish() */ -void QStyle::polish( QApplication*) -{ +void QStyle::polish( QApplication *app ) { + QStyleControlElementData ceData; + ceData.widgetObjectTypes = getObjectTypeListForObject(app); + applicationPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, QStyleOption()), app); } /*! @@ -475,8 +536,41 @@ void QStyle::polish( QApplication*) \sa polish() */ -void QStyle::unPolish( QApplication*) -{ +void QStyle::unPolish( QApplication *app ) { + QStyleControlElementData ceData; + ceData.widgetObjectTypes = getObjectTypeListForObject(app); + applicationUnPolish(ceData, getControlElementFlagsForObject(app, ceData.widgetObjectTypes, QStyleOption()), app); +} + +/*! + \overload + Late initialization of the QApplication object or other global application object. + + You may specify either a QApplication pointer or a custom pointer. + If a custom pointer is specified, you must be careful to intercept any event + handler installation/removal calls via setEventHandlerInstallationHook and + setEventHandlerRemovalHook. + + \sa unPolish() +*/ +void QStyle::applicationPolish( QStyleControlElementData, ControlElementFlags, void * ) { + // +} + +/*! + \overload + + Undoes the application polish. + + You may specify either a QApplication pointer or a custom pointer. + If a custom pointer is specified, you must be careful to intercept any event + handler installation/removal calls via setEventHandlerInstallationHook and + setEventHandlerRemovalHook. + + \sa polish() +*/ +void QStyle::applicationUnPolish( QStyleControlElementData, ControlElementFlags, void * ) { + // } /*! @@ -802,11 +896,14 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn void QStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, const QColorGroup &cg, SFlags flags, const QStyleOption& opt) const + \fn void QStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, const QStyleOption& opt) const Draws the style PrimitiveElement \a pe using the painter \a p in the area \a r. Colors are used from the color group \a cg. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The rect \a r should be in screen coordinates. The \a flags argument is used to control how the PrimitiveElement @@ -932,20 +1029,25 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn void QStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, const QStyleOption& opt) const + \fn void QStyle::drawControl( ControlElement element, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how, const QStyleOption& opt, const QWidget *widget) const Draws the ControlElement \a element using the painter \a p in the area \a r. Colors are used from the color group \a cg. The rect \a r should be in screen coordinates. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a how argument is used to control how the ControlElement is drawn. Multiple flags can be OR'ed together. See the table below for an explanation of which flags are used with the various ControlElements. The \a widget argument is a pointer to a QWidget or one of its - subclasses. The widget can be cast to the appropriate type based + subclasses. Note that usage of the widget argument is deprecated + in favor of specifying widget parameters via \a ceData and \a elementFlags. + The widget can be cast to the appropriate type based on the value of \a element. The \a opt argument can be used to pass extra information required when drawing the ControlElement. Note that \a opt may be the default value even for ControlElements @@ -1086,14 +1188,19 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn void QStyle::drawControlMask( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& opt) const + \fn void QStyle::drawControlMask( ControlElement element, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, const QStyleOption& opt, const QWidget *widget) const Draw a bitmask for the ControlElement \a element using the painter \a p in the area \a r. See drawControl() for an explanation of the use of the \a widget and \a opt arguments. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The rect \a r should be in screen coordinates. + \a widget is deprecated and should not be used. + \sa drawControl(), ControlElement */ @@ -1154,15 +1261,19 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn QRect QStyle::subRect( SubRect subrect, const QWidget *widget ) const; + \fn QRect QStyle::subRect( SubRect subrect, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget ) const; Returns the sub-area \a subrect for the \a widget in logical coordinates. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a widget argument is a pointer to a QWidget or one of its - subclasses. The widget can be cast to the appropriate type based - on the value of \a subrect. See the table below for the - appropriate \a widget casts: + subclasses. Note that usage of \a widget is deprecated in favor + of \a ceData and \a elementFlags. The widget can be cast to the + appropriate type based on the value of \a subrect. See the table + below for the appropriate \a widget casts: \table \header \i SubRect \i Widget Cast @@ -1282,7 +1393,7 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn void QStyle::drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const QStyleOption& opt ) const + \fn void QStyle::drawComplexControl( ComplexControl control, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how, SCFlags sub, SCFlags subActive, const QStyleOption& opt, const QWidget *widget ) const Draws the ComplexControl \a control using the painter \a p in the area \a r. Colors are used from the color group \a cg. The \a sub @@ -1295,6 +1406,9 @@ void QStyle::drawItem( QPainter *p, const QRect &r, coordinates into screen coordinates when using drawPrimitive() and drawControl(). + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a how argument is used to control how the ComplexControl is drawn. Multiple flags can OR'ed together. See the table below for an explanation of which flags are used with the various @@ -1302,11 +1416,13 @@ void QStyle::drawItem( QPainter *p, const QRect &r, The \a widget argument is a pointer to a QWidget or one of its subclasses. The widget can be cast to the appropriate type based - on the value of \a control. The \a opt argument can be used to - pass extra information required when drawing the ComplexControl. - Note that \a opt may be the default value even for ComplexControls - that can make use of the extra options. See the table below for - the appropriate \a widget and \a opt usage: + on the value of \a control. Note that usage of \a widget is + deprecated in favor of \a ceData and \a elementFlags. The \a opt + argument can be used to pass extra information required when + drawing the ComplexControl. Note that \a opt may be the default + value even for ComplexControls that can make use of the extra + options. See the table below for the appropriate \a widget and + \a opt usage: \table \header \i ComplexControl<br>\& Widget Cast @@ -1375,26 +1491,34 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn void QStyle::drawComplexControlMask( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& opt) const + \fn void QStyle::drawComplexControlMask( ComplexControl control, QPainter *p, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QRect &r, const QStyleOption& opt, const QWidget *widget) const Draw a bitmask for the ComplexControl \a control using the painter \a p in the area \a r. See drawComplexControl() for an explanation of the use of the \a widget and \a opt arguments. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The rect \a r should be in logical coordinates. Reimplementations of this function should use visualRect() to change the logical corrdinates into screen coordinates when using drawPrimitive() and drawControl(). + Note that usage of \a widget is deprecated in favor of \a ceData and \a elementFlags. + \sa drawComplexControl() ComplexControl */ /*! - \fn QRect QStyle::querySubControlMetrics( ComplexControl control, const QWidget *widget, SubControl subcontrol, const QStyleOption& opt = QStyleOption::Default ) const; + \fn QRect QStyle::querySubControlMetrics( ComplexControl control, QStyleControlElementData ceData, ControlElementFlags elementFlags, SubControl subcontrol, const QStyleOption& opt = QStyleOption::Default, const QWidget *widget = 0 ) const; Returns the rect for the SubControl \a subcontrol for \a widget in logical coordinates. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a widget argument is a pointer to a QWidget or one of its subclasses. The widget can be cast to the appropriate type based on the value of \a control. The \a opt argument can be used to @@ -1403,11 +1527,13 @@ void QStyle::drawItem( QPainter *p, const QRect &r, that can make use of the extra options. See drawComplexControl() for an explanation of the \a widget and \a opt arguments. + Note that usage of \a widget is deprecated in favor of \a ceData and \a elementFlags. + \sa drawComplexControl(), ComplexControl, SubControl */ /*! - \fn SubControl QStyle::querySubControl( ComplexControl control, const QWidget *widget, const QPoint &pos, const QStyleOption& opt = QStyleOption::Default ) const; + \fn SubControl QStyle::querySubControl( ComplexControl control, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QPoint &pos, const QStyleOption& opt = QStyleOption::Default, const QWidget *widget = 0 ) const; Returns the SubControl for \a widget at the point \a pos. The \a widget argument is a pointer to a QWidget or one of its @@ -1418,11 +1544,16 @@ void QStyle::drawItem( QPainter *p, const QRect &r, that can make use of the extra options. See drawComplexControl() for an explanation of the \a widget and \a opt arguments. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + Note that \a pos is passed in screen coordinates. When using querySubControlMetrics() to check for hits and misses, use visualRect() to change the logical coordinates into screen coordinates. + Note that usage of \a widget is deprecated in favor of \a ceData and \a elementFlags. + \sa drawComplexControl(), ComplexControl, SubControl, querySubControlMetrics() */ @@ -1528,14 +1659,20 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn int QStyle::pixelMetric( PixelMetric metric, const QWidget *widget = 0 ) const; + \fn int QStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; + + Returns the pixel metric for \a metric. + + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. - Returns the pixel metric for \a metric. The \a widget argument is - a pointer to a QWidget or one of its subclasses. The widget can be - cast to the appropriate type based on the value of \a metric. Note - that \a widget may be zero even for PixelMetrics that can make use - of \a widget. See the table below for the appropriate \a widget - casts: + The \a widget argument is a pointer to a QWidget or one of its + subclasses. The widget can be cast to the appropriate type based + on the value of \a metric. Note that \a widget may be zero even + for PixelMetrics that can make use of \a widget. Note also that + usage of \a widget is deprecated in favor of \a ceData and + \a elementFlags. See the table below for the appropriate + \a widget casts: \table \header \i PixelMetric \i Widget Cast @@ -1584,18 +1721,22 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn QSize QStyle::sizeFromContents( ContentsType contents, const QWidget *widget, const QSize &contentsSize, const QStyleOption& opt = QStyleOption::Default ) const; + \fn QSize QStyle::sizeFromContents( ContentsType contents, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QSize &contentsSize, const QStyleOption& opt = QStyleOption::Default, const QWidget *widget = 0 ) const; Returns the size of \a widget based on the contents size \a contentsSize. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a widget argument is a pointer to a QWidget or one of its subclasses. The widget can be cast to the appropriate type based on the value of \a contents. The \a opt argument can be used to pass extra information required when calculating the size. Note that \a opt may be the default value even for ContentsTypes that - can make use of the extra options. See the table below for the - appropriate \a widget and \a opt usage: + can make use of the extra options. Note that usage of \a widget + is deprecated in favor of \a ceData and \a elementFlags. See the + table below for the appropriate \a widget and \a opt usage: \table \header \i ContentsType \i Widget Cast \i Options \i Notes @@ -1770,12 +1911,18 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn int QStyle::styleHint( StyleHint stylehint, const QWidget *widget = 0, const QStyleOption &opt = QStyleOption::Default, QStyleHintReturn *returnData = 0 ) const; + \fn int QStyle::styleHint( StyleHint stylehint, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption &opt = QStyleOption::Default, QStyleHintReturn *returnData = 0, const QWidget *widget = 0 ) const; Returns the style hint \a stylehint for \a widget. Currently, \a widget, \a opt, and \a returnData are unused; they're included to allow for future enhancements. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + + Note that usage of \a widget is deprecated in favor of \a ceData + and \a elementFlags. + For an explanation of the return value see \l StyleHint. */ @@ -1811,10 +1958,13 @@ void QStyle::drawItem( QPainter *p, const QRect &r, */ /*! - \fn QPixmap QStyle::stylePixmap( StylePixmap stylepixmap, const QWidget *widget = 0, const QStyleOption& opt = QStyleOption::Default ) const; + \fn QPixmap QStyle::stylePixmap( StylePixmap stylepixmap, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption& opt = QStyleOption::Default, const QWidget *widget = 0 ) const; Returns a pixmap for \a stylepixmap. + \a ceData and \a elementFlags provide additional information about + the widget for which the PrimitiveElement is being drawn. + The \a opt argument can be used to pass extra information required when drawing the ControlElement. Note that \a opt may be the default value even for StylePixmaps that can make use of the extra @@ -1822,8 +1972,9 @@ void QStyle::drawItem( QPainter *p, const QRect &r, The \a widget argument is a pointer to a QWidget or one of its subclasses. The widget can be cast to the appropriate type based - on the value of \a stylepixmap. See the table below for the - appropriate \a widget casts: + on the value of \a stylepixmap. Note that usage of \a widget is + deprecated in favor of \a ceData and \a elementFlags.See the table + below for the appropriate \a widget casts: \table \header \i StylePixmap \i Widget Cast @@ -1847,11 +1998,33 @@ void QStyle::drawItem( QPainter *p, const QRect &r, function is provided to aid style implementors in supporting right-to-left mode. + Note that this function is deprecated in favor of visualRect( const QRect &logical, const QStyleControlElementData ceData, const ControlElementFlags elementFlags ); + \sa QApplication::reverseLayout() */ QRect QStyle::visualRect( const QRect &logical, const QWidget *w ) { - QRect boundingRect = w->rect(); + QStyleControlElementData ceData; + ceData.rect = w->rect(); + return visualRect(logical, ceData, CEF_None); +} + +/*! + \fn QRect QStyle::visualRect( const QRect &logical, const QStyleControlElementData ceData, const ControlElementFlags elementFlags ); + + Returns the rect \a logical in screen coordinates. The bounding + rect for the widget described by \a ceData and \a elementFlags + is used to perform the translation. This function is provided to + aid style implementors in supporting + right-to-left mode. + + \sa QApplication::reverseLayout() +*/ +QRect QStyle::visualRect( const QRect &logical, const QStyleControlElementData ceData, const ControlElementFlags elementFlags ) +{ + Q_UNUSED(elementFlags) + + QRect boundingRect = ceData.rect; QRect r = logical; if ( QApplication::reverseLayout() ) r.moveBy( 2*(boundingRect.right() - logical.right()) + @@ -1879,6 +2052,279 @@ QRect QStyle::visualRect( const QRect &logical, const QRect &boundingRect ) } /*! + \fn void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ); + + Intercepts events generated by \a source and sends them to \a handler via + the bool QStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ) virtual method. + + \sa void QStyle::removeObjectEventHandler( QObject* source, QStyle* handler ) + \sa bool QStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ) +*/ +void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) { + bool cbret = false; + if (m_eventHandlerInstallationHook) { + cbret = (*m_eventHandlerInstallationHook)(ceData, elementFlags, source, handler); + } + if (!cbret) { + if (ceData.widgetObjectTypes.contains("QObject")) { + QObject* o = reinterpret_cast<QObject*>(source); + o->installEventFilter(this); + m_objectEventSourceToHandlerMap[source] = handler; + m_objectEventSourceDataToHandlerMap[source] = ceData; + m_objectEventSourceFlagsToHandlerMap[source] = elementFlags; + } + } +} + +/*! + \fn void QStyle::removeObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ); + + Stops intercepting events generated by \a source. + + \sa void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) +*/ +void QStyle::removeObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) { + bool cbret = false; + if (m_eventHandlerRemovalHook) { + cbret = (*m_eventHandlerRemovalHook)(ceData, elementFlags, source, handler); + } + if (!cbret) { + if (ceData.widgetObjectTypes.contains("QObject")) { + QObject* o = reinterpret_cast<QObject*>(source); + m_objectEventSourceToHandlerMap.remove(source); + m_objectEventSourceDataToHandlerMap.remove(source); + m_objectEventSourceFlagsToHandlerMap.remove(source); + o->removeEventFilter(this); + } + } +} + +/*! + \fn void QStyle::setEventHandlerInstallationHook( EventHandlerInstallationHook hook ); + + Sets a callback function \a hook which will be called whenever a new intercept request + is made via the QStyle::installObjectEventHandler method. The callback function must + use this definition: bool callbackFunction( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ). + + \sa void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) +*/ +void QStyle::setEventHandlerInstallationHook( EventHandlerInstallationHook hook ) { + m_eventHandlerInstallationHook = hook; +} + +/*! + \fn void QStyle::setEventHandlerRemovalHook( EventHandlerRemovalHook hook ); + + Sets a callback function \a hook which will be called whenever a new intercept deactivation request + is made via the QStyle::removeObjectEventHandler method. The callback function must + use this definition: bool callbackFunction( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ). + + \sa void QStyle::removeObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) +*/ +void QStyle::setEventHandlerRemovalHook( EventHandlerRemovalHook hook ) { + m_eventHandlerRemovalHook = hook; +} + +/*! + \fn bool QStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); + + Override this virtual function to intercept events requested by a previous call to + QStyle::installObjectEventHandler. + + \sa void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) + \sa void QStyle::removeObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) +*/ +bool QStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ) { + Q_UNUSED(ceData); + Q_UNUSED(elementFlags); + Q_UNUSED(source); + Q_UNUSED(e); + return false; +} + +/*! + \fn bool QStyle::eventFilter(QObject *o, QEvent *e); + \internal +*/ +bool QStyle::eventFilter(QObject *o, QEvent *e) { + acceleratorKeypressEventMonitor(o, e); + + if (m_objectEventSourceToHandlerMap.contains(o)) { + QStyle* handler = m_objectEventSourceToHandlerMap[o]; + QStyleControlElementData ceData = m_objectEventSourceDataToHandlerMap[o]; + ControlElementFlags elementFlags = m_objectEventSourceFlagsToHandlerMap[o]; + bool ret = handler->objectEventHandler(ceData, elementFlags, o, e); + if (ret) { + return ret; + } + else { + return QObject::eventFilter(o, e); + } + } + else { + return QObject::eventFilter(o, e); + } +} + +/*! + \fn void QStyle::setWidgetActionRequestHook( WidgetActionRequestHook hook ); + + Sets a callback function \a hook which will be called whenever a new widget action request + is made via the QStyle::installObjectEventHandler method. The callback function must + use this definition: bool callbackFunction( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ). + + \sa void QStyle::installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ) +*/ +void QStyle::setWidgetActionRequestHook( WidgetActionRequestHook hook ) { + m_widgetActionRequestHook = hook; +} + +/*! + \fn bool widgetActionRequestHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request ); + + Handles widget action requests. Return FALSE to continue processing in base classes, TRUE to eat the request and halt processing. +*/ +bool QStyle::widgetActionRequest( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request, QStyleWidgetActionRequestData requestData ) { + bool cbret = false; + if (m_widgetActionRequestHook) { + cbret = (*m_widgetActionRequestHook)(ceData, elementFlags, source, request, requestData); + } + if (!cbret) { + if (ceData.widgetObjectTypes.contains("QWidget")) { + QWidget* widget = reinterpret_cast<QWidget*>(source); + if (request == WAR_Repaint) { + widget->repaint(FALSE); + } + else if (request == WAR_RepaintRect) { + widget->repaint(requestData.rect, FALSE); + } + else if (request == WAR_EnableMouseTracking) { + widget->setMouseTracking(TRUE); + } + else if (request == WAR_DisableMouseTracking) { + widget->setMouseTracking(FALSE); + } + else if (request == WAR_FrameSetStyle) { + QFrame* frame = dynamic_cast<QFrame*>(widget); + if (frame) { + frame->setFrameStyle(requestData.metric1); + } + } + else if (request == WAR_FrameSetLineWidth) { + QFrame* frame = dynamic_cast<QFrame*>(widget); + if (frame) { + frame->setLineWidth(requestData.metric1); + } + } + else if (request == WAR_SetLayoutMargin) { + QLayout* layout = widget->layout(); + if (layout) { + layout->setMargin(requestData.metric1); + } + } + else if (request == WAR_SetPalette) { + widget->setPalette(requestData.palette); + } + else if (request == WAR_SetBackgroundMode) { + widget->setBackgroundMode((Qt::BackgroundMode)requestData.metric1); + } + else if (request == WAR_SetFont) { + widget->setFont(requestData.font); + } + else if (request == WAR_RepaintAllAccelerators) { + QWidgetList *list = QApplication::topLevelWidgets(); + QWidgetListIt it( *list ); + QWidget * widget; + while ((widget=it.current()) != 0) { + ++it; + + QObjectList *l = widget->queryList("QWidget"); + QObjectListIt it2( *l ); + QWidget *w; + while ( (w = (QWidget*)it2.current()) != 0 ) { + ++it2; + if (w->isTopLevel() || !w->isVisible() || w->style().styleHint(SH_UnderlineAccelerator, QStyleControlElementData(), CEF_None, w)) { + l->removeRef(w); + } + } + + // Repaint all relevant widgets + it2.toFirst(); + while ( (w = (QWidget*)it2.current()) != 0 ) { + ++it2; + w->repaint(FALSE); + } + delete l; + } + delete list; + } + return true; + } + } + return true; +} + +void QStyle::acceleratorKeypressEventMonitor( QObject *o, QEvent *e ) { + if (styleHint(SH_HideUnderlineAcceleratorWhenAltUp, QStyleControlElementData(), CEF_None, QStyleOption::Default, NULL, NULL) != 0) { + QWidget *widget = dynamic_cast<QWidget*>(o); + if (widget) { + switch(e->type()) { + case QEvent::KeyPress: + if (((QKeyEvent*)e)->key() == Key_Alt) { + conditionalAcceleratorsEnabled = true; + widgetActionRequest(QStyleControlElementData(), CEF_None, o, WAR_RepaintAllAccelerators); + } + break; + case QEvent::KeyRelease: + if (((QKeyEvent*)e)->key() == Key_Alt) { + conditionalAcceleratorsEnabled = false; + widgetActionRequest(QStyleControlElementData(), CEF_None, o, WAR_RepaintAllAccelerators); + } + break; + default: + break; + } + } + } + else { + conditionalAcceleratorsEnabled = false; + } +} + +bool QStyle::acceleratorsShown() const { + if (styleHint(SH_HideUnderlineAcceleratorWhenAltUp, QStyleControlElementData(), CEF_None, QStyleOption::Default, NULL, NULL) != 0) { + return conditionalAcceleratorsEnabled; + } + else { + return true; + } +} + +QStyleWidgetActionRequestData::QStyleWidgetActionRequestData() { + // +} +QStyleWidgetActionRequestData::QStyleWidgetActionRequestData(int param1, int param2) { + metric1 = param1; + metric2 = param2; +} + +QStyleWidgetActionRequestData::QStyleWidgetActionRequestData(QPalette param) { + palette = param; +} + +QStyleWidgetActionRequestData::QStyleWidgetActionRequestData(QFont param) { + font = param; +} + +QStyleWidgetActionRequestData::QStyleWidgetActionRequestData(QRect param) { + rect = param; +} + +QStyleWidgetActionRequestData::~QStyleWidgetActionRequestData() { + // +} + +/*! \fn int QStyle::defaultFrameWidth() const \obsolete */ diff --git a/src/kernel/qstyle.h b/src/kernel/qstyle.h index 64152ed..bb2efbc 100644 --- a/src/kernel/qstyle.h +++ b/src/kernel/qstyle.h @@ -42,6 +42,11 @@ #ifndef QT_H #include "qobject.h" +#include "qpixmap.h" +#include "qcolor.h" +#include "qiconset.h" +#include "qtabbar.h" +#include "qtoolbutton.h" #endif // QT_H @@ -58,26 +63,26 @@ class QStyleOption { public: enum StyleOptionDefault { Default }; - QStyleOption(StyleOptionDefault=Default) : def(TRUE) {} + QStyleOption(StyleOptionDefault=Default) : def(TRUE), tb(NULL) {} // Note: we don't use default arguments since that is unnecessary // initialization. QStyleOption(int in1) : - def(FALSE), i1(in1) {} + def(FALSE), tb(NULL), i1(in1) {} QStyleOption(int in1, int in2) : - def(FALSE), i1(in1), i2(in2) {} + def(FALSE), tb(NULL), i1(in1), i2(in2) {} QStyleOption(int in1, int in2, int in3, int in4) : - def(FALSE), i1(in1), i2(in2), i3(in3), i4(in4) {} - QStyleOption(QMenuItem* m) : def(FALSE), mi(m) {} - QStyleOption(QMenuItem* m, int in1) : def(FALSE), mi(m), i1(in1) {} - QStyleOption(QMenuItem* m, int in1, int in2) : def(FALSE), mi(m), i1(in1), i2(in2) {} - QStyleOption(const QColor& c) : def(FALSE), cl(&c) {} + def(FALSE), tb(NULL), i1(in1), i2(in2), i3(in3), i4(in4) {} + QStyleOption(QMenuItem* m) : def(FALSE), mi(m), tb(NULL) {} + QStyleOption(QMenuItem* m, int in1) : def(FALSE), mi(m), tb(NULL), i1(in1) {} + QStyleOption(QMenuItem* m, int in1, int in2) : def(FALSE), mi(m), tb(NULL), i1(in1), i2(in2) {} + QStyleOption(const QColor& c) : def(FALSE), tb(NULL), cl(&c) {} QStyleOption(QTab* t) : def(FALSE), tb(t) {} - QStyleOption(QListViewItem* i) : def(FALSE), li(i) {} - QStyleOption(QCheckListItem* i) : def(FALSE), cli(i) {} - QStyleOption(Qt::ArrowType a) : def(FALSE), i1((int)a) {} - QStyleOption(const QRect& r) : def(FALSE), i1(r.x()), i2(r.y()), i3(r.width()),i4(r.height()){} - QStyleOption(QWidget *w) : def(FALSE), p1((void*)w) {} + QStyleOption(QListViewItem* i) : def(FALSE), tb(NULL), li(i) {} + QStyleOption(QCheckListItem* i) : def(FALSE), tb(NULL), cli(i) {} + QStyleOption(Qt::ArrowType a) : def(FALSE), tb(NULL), i1((int)a) {} + QStyleOption(const QRect& r) : def(FALSE), tb(NULL), i1(r.x()), i2(r.y()), i3(r.width()),i4(r.height()){} + QStyleOption(QWidget *w) : def(FALSE), tb(NULL), p1((void*)w) {} bool isDefault() const { return def; } @@ -121,6 +126,138 @@ private: class QStyleHintReturn; // not defined yet +typedef QMap<Q_UINT32, QSize> DialogButtonSizeMap; +typedef QMap<Q_INT32, Q_INT32> TabIdentifierIndexMap; + +class QStyleControlElementPopupMenuData { + public: + // +}; + +class QStyleControlElementTabBarData { + public: + int tabCount; + QTabBar::Shape shape; + TabIdentifierIndexMap identIndexMap; +}; + +class QStyleControlElementListViewData { + public: + bool rootDecorated; + int itemMargin; +}; + +class QStyleControlElementSpinWidgetData { + public: + Q_UINT32 buttonSymbols; + QRect upRect; + QRect downRect; + bool upEnabled; + bool downEnabled; +}; + +class QStyleControlElementTitleBarData { + public: + bool hasWindow; + bool usesActiveColor; + int windowState; + QString visibleText; +}; + +class QStyleControlElementDockWidgetData { + public: + bool hasDockArea; + bool closeEnabled; + Qt::Orientation areaOrientation; +}; + +class QStyleControlElementGenericWidgetData { + public: + QStringList widgetObjectTypes; + bool allDataPopulated; + Qt::WFlags wflags; + QPixmap bgPixmap; + QBrush bgBrush; + QColor bgColor; + QPoint bgOffset; + Qt::BackgroundMode backgroundMode; + QColor fgColor; + QColorGroup colorGroup; + QRect geometry; + QRect rect; + QPoint pos; + QPixmap icon; + QPalette palette; + QFont font; +}; + +class QStyleControlElementData { + public: + QStringList widgetObjectTypes; + bool allDataPopulated; + Qt::WFlags wflags; + QPixmap bgPixmap; + QBrush bgBrush; + QColor bgColor; + QPoint bgOffset; + Qt::BackgroundMode backgroundMode; + QPixmap fgPixmap; + QColor fgColor; + QColorGroup colorGroup; + QRect geometry; + QRect rect; + QPoint pos; + QPixmap icon; + QIconSet iconSet; + QString text; + Qt::Orientation orientation; + QColor activeItemPaletteBgColor; + QPalette palette; + int totalSteps; + int currentStep; + Q_UINT32 tickMarkSetting; + int tickInterval; + int minSteps; + int maxSteps; + int startStep; + int pageStep; + int lineStep; + int dlgVisibleButtons; + DialogButtonSizeMap dlgVisibleSizeHints; + QString progressText; + QString textLabel; + QFont font; + int percentageVisible; + QStyleControlElementDockWidgetData dwData; + QToolButton::TextPosition toolButtonTextPosition; + int popupDelay; + QStyleControlElementTitleBarData titleBarData; + QStyleControlElementSpinWidgetData spinWidgetData; + QStyleControlElementGenericWidgetData parentWidgetData; + QStyleControlElementGenericWidgetData viewportData; + QStyleControlElementListViewData listViewData; + QStyleControlElementTabBarData tabBarData; + Q_UINT32 comboBoxLineEditFlags; + Q_UINT32 frameStyle; + QRect sliderRect; +}; + +class QStyleWidgetActionRequestData { + public: + QStyleWidgetActionRequestData(); + QStyleWidgetActionRequestData(int metric1, int metric2=0); + QStyleWidgetActionRequestData(QPalette palette); + QStyleWidgetActionRequestData(QFont font); + QStyleWidgetActionRequestData(QRect rect); + ~QStyleWidgetActionRequestData(); + public: + int metric1; + int metric2; + QPalette palette; + QFont font; + QRect rect; +}; + class Q_EXPORT QStyle: public QObject { Q_OBJECT @@ -129,14 +266,64 @@ public: QStyle(); virtual ~QStyle(); + enum ControlElementFlags { + CEF_None = 0x00000000, + CEF_IsDefault = 0x00000001, + CEF_AutoDefault = 0x00000002, + CEF_IsActive = 0x00000004, + CEF_IsDown = 0x00000008, + CEF_IsOn = 0x00000010, + CEF_IsEnabled = 0x00000020, + CEF_BiState = 0x00000040, + CEF_HasFocus = 0x00000080, + CEF_IsMenuWidget = 0x00000100, + CEF_IsContainerEmpty = 0x00000200, + CEF_CenterIndicator = 0x00000400, + CEF_IndicatorFollowsStyle = 0x00000800, + CEF_UsesTextLabel = 0x00001000, + CEF_UsesBigPixmap = 0x00002000, + CEF_UseGenericParameters = 0x00004000, + CEF_HasParentWidget = 0x00008000, + CEF_HasPopupMenu = 0x00010000, + CEF_IsCheckable = 0x00020000, + CEF_HasFocusProxy = 0x00040000, + CEF_IsEditable = 0x00080000, + CEF_IsFlat = 0x00100000, + CEF_IsActiveWindow = 0x00200000, + CEF_IsTopLevel = 0x00400000, + CEF_IsVisible = 0x00800000, + }; + // New QStyle API - most of these should probably be pure virtual + // Old API + // DEPRECATED virtual void polish( QWidget * ); + + // New API + virtual void polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + + // Old API + // DEPRECATED virtual void unPolish( QWidget * ); + // New API + virtual void unPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + + // Old API + // DEPRECATED virtual void polish( QApplication * ); + + // New API + virtual void applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + + // Old API + // DEPRECATED virtual void unPolish( QApplication * ); + // New API + virtual void applicationUnPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + virtual void polish( QPalette & ); virtual void polishPopupMenu( QPopupMenu* ) = 0; @@ -151,7 +338,6 @@ public: const QPixmap *pixmap, const QString &text, int len = -1, const QColor *penColor = 0 ) const; - enum PrimitiveElement { PE_ButtonCommand, PE_ButtonDefault, @@ -252,8 +438,20 @@ public: }; typedef uint SFlags; + // Old API + // DEPRECATED + virtual void drawPrimitive( PrimitiveElement pe, + QPainter *p, + const QRect &r, + const QColorGroup &cg, + SFlags flags = Style_Default, + const QStyleOption& = QStyleOption::Default ) const = 0; + + // New API virtual void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -294,6 +492,8 @@ public: CE_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED virtual void drawControl( ControlElement element, QPainter *p, const QWidget *widget, @@ -301,12 +501,35 @@ public: const QColorGroup &cg, SFlags how = Style_Default, const QStyleOption& = QStyleOption::Default ) const = 0; + + // New API + virtual 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 *widget = 0 /* compat, will likely go away */ ) const = 0; + + // Old API + // DEPRECATED virtual void drawControlMask( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& = QStyleOption::Default ) const = 0; + // New API + virtual void drawControlMask( ControlElement element, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 /* compat, will likely go away */ ) const = 0; + enum SubRect { SR_PushButtonContents, SR_PushButtonFocusRect, @@ -347,8 +570,13 @@ public: SR_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED virtual QRect subRect( SubRect r, const QWidget *widget ) const = 0; + // New API + virtual QRect subRect( SubRect r, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget ) const = 0; + enum ComplexControl{ CC_SpinWidget, @@ -411,6 +639,8 @@ public: typedef uint SCFlags; + // Old API + // DEPRECATED virtual void drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, @@ -424,21 +654,70 @@ public: #endif SCFlags subActive = SC_None, const QStyleOption& = QStyleOption::Default ) const = 0; + + virtual void drawComplexControl( ComplexControl control, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags how = Style_Default, +#ifdef Q_QDOC + SCFlags sub = SC_All, +#else + SCFlags sub = (uint)SC_All, +#endif + SCFlags subActive = SC_None, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + + // Old API + // DEPRECATED virtual void drawComplexControlMask( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& = QStyleOption::Default ) const = 0; + // New API + virtual void drawComplexControlMask( ComplexControl control, + QPainter *p, + const QStyleControlElementData ceData, + const ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + + // Old API + // DEPRECATED virtual QRect querySubControlMetrics( ComplexControl control, const QWidget *widget, SubControl sc, const QStyleOption& = QStyleOption::Default ) const = 0; + + // New API + virtual QRect querySubControlMetrics( ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + SubControl sc, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + + // Old API + // DEPRECATED virtual SubControl querySubControl( ComplexControl control, const QWidget *widget, const QPoint &pos, const QStyleOption& = QStyleOption::Default ) const = 0; + // New API + virtual SubControl querySubControl( ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QPoint &pos, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + enum PixelMetric { PM_ButtonMargin, @@ -508,7 +787,15 @@ public: PM_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED + virtual int pixelMetric( PixelMetric metric, + const QWidget *widget = 0 ) const = 0; + + // New API virtual int pixelMetric( PixelMetric metric, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QWidget *widget = 0 ) const = 0; @@ -536,11 +823,20 @@ public: CT_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED virtual QSize sizeFromContents( ContentsType contents, const QWidget *widget, const QSize &contentsSize, const QStyleOption& = QStyleOption::Default ) const = 0; + virtual QSize sizeFromContents( ContentsType contents, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QSize &contentsSize, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + enum StyleHint { // ... // the general hints @@ -683,16 +979,30 @@ public: // when the mouse is over the button SH_ToolButton_Uses3D, + // bool - hide underlined accelerators uless Alt key is currently down + SH_HideUnderlineAcceleratorWhenAltUp, + // do not add any values below/greater than this SH_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED virtual int styleHint( StyleHint stylehint, const QWidget *widget = 0, const QStyleOption& = QStyleOption::Default, QStyleHintReturn* returnData = 0 ) const = 0; + // New API + virtual int styleHint( StyleHint stylehint, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& = QStyleOption::Default, + QStyleHintReturn* returnData = 0, + const QWidget *widget = 0 + ) const = 0; + enum StylePixmap { SP_TitleBarMinButton, @@ -711,39 +1021,86 @@ public: SP_CustomBase = 0xf0000000 }; + // Old API + // DEPRECATED virtual QPixmap stylePixmap( StylePixmap stylepixmap, const QWidget *widget = 0, const QStyleOption& = QStyleOption::Default ) const = 0; + virtual QPixmap stylePixmap( StylePixmap stylepixmap, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const = 0; + + // Old API + // DEPRECATED static QRect visualRect( const QRect &logical, const QWidget *w ); + // New API + static QRect visualRect( const QRect &logical, const QStyleControlElementData ceData, const ControlElementFlags elementFlags ); + static QRect visualRect( const QRect &logical, const QRect &bounding ); + // Object event handling API + typedef QMap<void*, QStyle*> ObjectEventSourceToHandlerMap; + typedef QMap<void*, QStyleControlElementData> ObjectEventSourceDataToHandlerMap; + typedef QMap<void*, ControlElementFlags> ObjectEventSourceFlagsToHandlerMap; + typedef bool (*EventHandlerInstallationHook)(QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler); + typedef bool (*EventHandlerRemovalHook)(QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler); + void installObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ); + void removeObjectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QStyle* handler ); + void setEventHandlerInstallationHook( EventHandlerInstallationHook ); + void setEventHandlerRemovalHook( EventHandlerRemovalHook hook ); + virtual bool objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); + + enum WidgetActionRequest { + WAR_Repaint, + WAR_RepaintRect, + WAR_EnableMouseTracking, + WAR_DisableMouseTracking, + WAR_FrameSetStyle, + WAR_FrameSetLineWidth, + WAR_SetLayoutMargin, + WAR_SetPalette, + WAR_SetBackgroundMode, + WAR_SetFont, + WAR_RepaintAllAccelerators + }; + typedef bool (*WidgetActionRequestHook)(QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request, QStyleWidgetActionRequestData requestData); + void setWidgetActionRequestHook( WidgetActionRequestHook ); + virtual bool widgetActionRequest( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, WidgetActionRequest request, QStyleWidgetActionRequestData requestData = QStyleWidgetActionRequestData() ); // Old 2.x QStyle API #ifndef QT_NO_COMPAT int defaultFrameWidth() const { - return pixelMetric( PM_DefaultFrameWidth ); + return pixelMetric( PM_DefaultFrameWidth, QStyleControlElementData(), CEF_None ); } void tabbarMetrics( const QWidget* t, int& hf, int& vf, int& ov ) const { - hf = pixelMetric( PM_TabBarTabHSpace, t ); - vf = pixelMetric( PM_TabBarTabVSpace, t ); - ov = pixelMetric( PM_TabBarBaseOverlap, t ); + hf = pixelMetric( PM_TabBarTabHSpace, QStyleControlElementData(), CEF_None, t ); + vf = pixelMetric( PM_TabBarTabVSpace, QStyleControlElementData(), CEF_None, t ); + ov = pixelMetric( PM_TabBarBaseOverlap, QStyleControlElementData(), CEF_None, t ); } QSize scrollBarExtent() const { - return QSize(pixelMetric(PM_ScrollBarExtent), - pixelMetric(PM_ScrollBarExtent)); + return QSize(pixelMetric(PM_ScrollBarExtent, QStyleControlElementData(), CEF_None), + pixelMetric(PM_ScrollBarExtent, QStyleControlElementData(), CEF_None)); } #endif +public: + virtual bool eventFilter( QObject *, QEvent * ); + bool acceleratorsShown() const; + +protected: + void acceleratorKeypressEventMonitor( QObject *, QEvent * ); private: QStylePrivate * d; @@ -752,7 +1109,22 @@ private: QStyle( const QStyle & ); QStyle& operator=( const QStyle & ); #endif + + EventHandlerInstallationHook m_eventHandlerInstallationHook; + EventHandlerRemovalHook m_eventHandlerRemovalHook; + WidgetActionRequestHook m_widgetActionRequestHook; + ObjectEventSourceToHandlerMap m_objectEventSourceToHandlerMap; + ObjectEventSourceDataToHandlerMap m_objectEventSourceDataToHandlerMap; + ObjectEventSourceFlagsToHandlerMap m_objectEventSourceFlagsToHandlerMap; + bool conditionalAcceleratorsEnabled; }; +inline QStyle::ControlElementFlags operator|(const QStyle::ControlElementFlags a, const QStyle::ControlElementFlags b) { return static_cast<QStyle::ControlElementFlags>(static_cast<int>(a) | static_cast<int>(b)); } +// inline QStyle::ControlElementFlags operator|=(QStyle::ControlElementFlags &a, const QStyle::ControlElementFlags b) { a = static_cast<QStyle::ControlElementFlags>(static_cast<int>(a) | static_cast<int>(b)); return a; } + +Q_EXPORT QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields=true); +Q_EXPORT QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, QStringList objectTypeList, const QStyleOption& opt, bool populateReliantFields=true); +Q_EXPORT QStringList getObjectTypeListForObject(const QObject* object); + #endif // QT_NO_STYLE #endif // QSTYLE_H diff --git a/src/kernel/qwidget.h b/src/kernel/qwidget.h index d20fe4d..9df9710 100644 --- a/src/kernel/qwidget.h +++ b/src/kernel/qwidget.h @@ -456,6 +456,9 @@ public: WState testWState( WState s ) const; WFlags testWFlags( WFlags f ) const; NFlags testNFlags( NFlags f ) const; + uint getWState() const; + WFlags getWFlags() const; + NFlags getNFlags() const; static QWidget * find( WId ); static QWidgetMapper *wmapper(); @@ -573,13 +576,10 @@ protected: bool destroyOldWindow = TRUE ); virtual void destroy( bool destroyWindow = TRUE, bool destroySubWindows = TRUE ); - uint getWState() const; virtual void setWState( uint ); void clearWState( uint n ); - WFlags getWFlags() const; virtual void setWFlags( WFlags ); void clearWFlags( WFlags n ); - NFlags getNFlags() const; virtual void setNFlags( NFlags ); void clearNFlags( NFlags n ); diff --git a/src/styles/qcdestyle.cpp b/src/styles/qcdestyle.cpp index d6621c0..3719462 100644 --- a/src/styles/qcdestyle.cpp +++ b/src/styles/qcdestyle.cpp @@ -87,7 +87,7 @@ QCDEStyle::~QCDEStyle() /*!\reimp */ -int QCDEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const +int QCDEStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { int ret; @@ -102,7 +102,7 @@ int QCDEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const ret = 13; break; default: - ret = QMotifStyle::pixelMetric( metric, widget ); + ret = QMotifStyle::pixelMetric( metric, ceData, elementFlags, widget ); break; } return ret; @@ -112,11 +112,13 @@ int QCDEStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const */ void QCDEStyle::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 ) { @@ -127,11 +129,11 @@ void QCDEStyle::drawControl( ControlElement element, &cg.brush( QColorGroup::Button ) ); else // other item p->fillRect( r, cg.brush( QColorGroup::Button ) ); - QCommonStyle::drawControl( element, p, widget, r, cg, how, opt ); + QCommonStyle::drawControl( element, p, ceData, elementFlags, r, cg, how, opt, widget ); break; } default: - QMotifStyle::drawControl( element, p, widget, r, cg, how, opt ); + QMotifStyle::drawControl( element, p, ceData, elementFlags, r, cg, how, opt, widget ); break; } @@ -142,6 +144,8 @@ void QCDEStyle::drawControl( ControlElement element, */ void QCDEStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -154,7 +158,7 @@ void QCDEStyle::drawPrimitive( PrimitiveElement pe, bool on = flags & Style_On; bool showUp = !( down ^ on ); QBrush fill = showUp || flags & Style_NoChange ? cg.brush( QColorGroup::Button ) : cg.brush( QColorGroup::Mid ); - qDrawShadePanel( p, r, cg, !showUp, pixelMetric( PM_DefaultFrameWidth ), &cg.brush( QColorGroup::Button ) ); + qDrawShadePanel( p, r, cg, !showUp, pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ), &cg.brush( QColorGroup::Button ) ); if ( !( flags & Style_Off ) ) { QPointArray a( 7 * 2 ); @@ -360,7 +364,7 @@ void QCDEStyle::drawPrimitive( PrimitiveElement pe, } break; default: - QMotifStyle::drawPrimitive( pe, p, r, cg, flags, opt ); + QMotifStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); } } diff --git a/src/styles/qcdestyle.h b/src/styles/qcdestyle.h index a94f620..3dee332 100644 --- a/src/styles/qcdestyle.h +++ b/src/styles/qcdestyle.h @@ -62,18 +62,22 @@ public: QCDEStyle( bool useHighlightCols = FALSE ); virtual ~QCDEStyle(); - int pixelMetric( PixelMetric metric, const QWidget *widget = 0 ) const; + int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index 6e89845..e46f264 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -49,9 +49,11 @@ #include "qpixmap.h" #include "qpushbutton.h" #include "qtabbar.h" +#include "qlineedit.h" #include "qscrollbar.h" #include "qtoolbutton.h" #include "qtoolbar.h" +#include "qcombobox.h" #include "qdockarea.h" #include "qheader.h" #include "qspinbox.h" @@ -135,6 +137,405 @@ static const char * const check_list_controller_xpm[] = { " ", " "}; +#include <nqmetaobject.h> + +QStringList getObjectTypeListForObject(const QObject* object) { + QStringList objectTypes; + + if (object) { + QMetaObject* objectMetaObject = object->metaObject(); + const char* name; + + while (objectMetaObject) { + name = objectMetaObject->className(); + objectTypes.append(QString(name)); + objectMetaObject = objectMetaObject->superClass(); + } + } + + return objectTypes; +} + +QStyle::ControlElementFlags getControlElementFlagsForObject(const QObject* object, QStringList objectTypeList, const QStyleOption& opt, bool populateReliantFields) { + QStyle::ControlElementFlags cef = (QStyle::ControlElementFlags)0; + + if (object) { + if (objectTypeList.contains("QPushButton")) { + const QPushButton *button = dynamic_cast<const QPushButton*>(object); + if (button) { + if (button->isDefault()) cef = cef | QStyle::CEF_IsDefault; + if (button->autoDefault()) cef = cef | QStyle::CEF_AutoDefault; + if (button->isMenuButton()) cef = cef | QStyle::CEF_IsMenuWidget; + if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState; + if (button->isFlat()) cef = cef | QStyle::CEF_IsFlat; + } + } + if (objectTypeList.contains("QToolButton")) { + const QToolButton *button = dynamic_cast<const QToolButton*>(object); + if (button) { + if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState; + if (button->usesTextLabel()) cef = cef | QStyle::CEF_UsesTextLabel; + if (button->usesBigPixmap()) cef = cef | QStyle::CEF_UsesBigPixmap; + if (button->popup()) cef = cef | QStyle::CEF_HasPopupMenu; + } + } + if (objectTypeList.contains("QButton")) { + const QButton *button = dynamic_cast<const QButton*>(object); + if (button) { + if (button->isDown()) cef = cef | QStyle::CEF_IsDown; + if (button->isOn()) cef = cef | QStyle::CEF_IsOn; + if (button->isEnabled()) cef = cef | QStyle::CEF_IsEnabled; + if (button->isToggleButton()) cef = cef | QStyle::CEF_BiState; + } + } + if (objectTypeList.contains("QTabBar")) { + const QTabBar *tb = dynamic_cast<const QTabBar*>(object); + QTab * t = opt.tab(); + if ((t) && (tb)) { + if (t->identifier() == tb->currentTab()) cef = cef | QStyle::CEF_IsActive; + } + } + if (objectTypeList.contains("QToolBox")) { + const QToolBox *tb = dynamic_cast<const QToolBox*>(object); + if (tb) { + if (!tb->currentItem()) cef = cef | QStyle::CEF_IsContainerEmpty; + } + } + if (objectTypeList.contains("QProgressBar")) { + const QProgressBar *pb = dynamic_cast<const QProgressBar*>(object); + if (pb) { + if (pb->centerIndicator()) cef = cef | QStyle::CEF_CenterIndicator; + if (pb->indicatorFollowsStyle()) cef = cef | QStyle::CEF_IndicatorFollowsStyle; + } + } + if (objectTypeList.contains("QPopupMenu")) { + const QPopupMenu *pm = dynamic_cast<const QPopupMenu*>(object); + if (pm) { + if (pm->isCheckable()) cef = cef | QStyle::CEF_IsCheckable; + } + } + if (objectTypeList.contains("QComboBox")) { + const QComboBox *cb = dynamic_cast<const QComboBox*>(object); + if (cb) { + if (cb->editable()) cef = cef | QStyle::CEF_IsEditable; + } + } + // Generic flags + const QWidget* widget = dynamic_cast<const QWidget*>(object); + if (widget) { + if (widget->parentWidget()) cef = cef | QStyle::CEF_HasParentWidget; + if (widget->focusProxy()) cef = cef | QStyle::CEF_HasFocusProxy; + if (widget->hasFocus()) cef = cef | QStyle::CEF_HasFocus; + if (populateReliantFields) { + if (widget->isActiveWindow()) cef = cef | QStyle::CEF_IsActiveWindow; + if (widget->isTopLevel()) cef = cef | QStyle::CEF_IsTopLevel; + if (widget->isVisible()) cef = cef | QStyle::CEF_IsVisible; + } + } + } + else { + cef = cef | QStyle::CEF_UseGenericParameters; + } + + return cef; +} + +QStyleControlElementData populateControlElementDataFromWidget(const QWidget* widget, const QStyleOption& opt, bool populateReliantFields) { + QStyleControlElementData ceData; + + if (widget) { + ceData.widgetObjectTypes = getObjectTypeListForObject(widget); + ceData.allDataPopulated = populateReliantFields; + const QPixmap* erasePixmap = widget->backgroundPixmap(); + if (erasePixmap) { + ceData.bgPixmap = *erasePixmap; + } + if (populateReliantFields) { + ceData.bgBrush = widget->backgroundBrush(); + } + ceData.wflags = widget->getWFlags(); + ceData.bgColor = widget->eraseColor(); + ceData.bgOffset = widget->backgroundOffset(); + ceData.backgroundMode = widget->backgroundMode(); + if (populateReliantFields) { + ceData.fgColor = widget->foregroundColor(); + ceData.colorGroup = widget->colorGroup(); + } + ceData.geometry = widget->geometry(); + ceData.rect = widget->rect(); + ceData.pos = widget->pos(); + const QPixmap* icon = widget->icon(); + if (icon) { + ceData.icon = *icon; + } + ceData.palette = widget->palette(); + ceData.font = widget->font(); + if (ceData.widgetObjectTypes.contains("QPushButton")) { + const QPushButton *button = dynamic_cast<const QPushButton*>(widget); + if (button) { + QIconSet* iconSet = 0; + const QPixmap* fgPixmap = 0; + iconSet = button->iconSet(); + fgPixmap = button->pixmap(); + if (iconSet) { + ceData.iconSet = *iconSet; + } + if (fgPixmap) { + ceData.fgPixmap = *fgPixmap; + } + } + } + if (ceData.widgetObjectTypes.contains("QToolButton")) { + const QToolButton *button = dynamic_cast<const QToolButton*>(widget); + if (button) { + const QPixmap* fgPixmap = 0; + ceData.iconSet = button->iconSet(); + fgPixmap = button->pixmap(); + if (fgPixmap) { + ceData.fgPixmap = *fgPixmap; + } + ceData.textLabel = button->textLabel(); + ceData.toolButtonTextPosition = button->textPosition(); + ceData.popupDelay = button->popupDelay(); + } + } + if (ceData.widgetObjectTypes.contains("QCheckBox")) { + const QCheckBox *button = dynamic_cast<const QCheckBox*>(widget); + if (button) { + const QPixmap* fgPixmap = 0; + fgPixmap = button->pixmap(); + if (fgPixmap) { + ceData.fgPixmap = *fgPixmap; + } + } + } + if (ceData.widgetObjectTypes.contains("QRadioButton")) { + const QRadioButton *button = dynamic_cast<const QRadioButton*>(widget); + if (button) { + const QPixmap* fgPixmap = 0; + fgPixmap = button->pixmap(); + if (fgPixmap) { + ceData.fgPixmap = *fgPixmap; + } + } + } + if (ceData.widgetObjectTypes.contains("QButton")) { + const QButton *button = dynamic_cast<const QButton*>(widget); + if (button) { + ceData.text = button->text(); + } + } + if (ceData.widgetObjectTypes.contains("QTabBar")) { + const QTabBar *tb = dynamic_cast<const QTabBar*>(widget); + if (tb) { + ceData.tabBarData.tabCount = tb->count(); + ceData.tabBarData.shape = tb->shape(); + ceData.tabBarData.identIndexMap.clear(); + const QTab* currentTab; + for (int i=0; i<tb->count(); ++i) { + currentTab = tb->tabAt(i); + if (currentTab) { + ceData.tabBarData.identIndexMap[currentTab->identifier()] = tb->indexOf(currentTab->identifier()); + } + } + } + } + if (ceData.widgetObjectTypes.contains("QToolBox")) { + const QToolBox *tb = dynamic_cast<const QToolBox*>(widget); + if (tb) { + const QWidget* currentItem = tb->currentItem(); + if (currentItem) { + ceData.activeItemPaletteBgColor = currentItem->paletteBackgroundColor(); + } + } + } + if (ceData.widgetObjectTypes.contains("QProgressBar")) { + const QProgressBar *pb = dynamic_cast<const QProgressBar*>(widget); + if (pb) { + ceData.currentStep = pb->progress(); + ceData.totalSteps = pb->totalSteps(); + ceData.progressText = pb->progressString(); + ceData.percentageVisible = pb->percentageVisible(); + } + } + if (ceData.widgetObjectTypes.contains("QHeader")) { + const QHeader *header = dynamic_cast<const QHeader*>(widget); + if (header) { + int section = opt.headerSection(); + QIconSet* iconSet = 0; + iconSet = header->iconSet(section); + ceData.textLabel = header->label(section); + if (iconSet) { + ceData.iconSet = *iconSet; + } + } + } + // Complex Controls + if (ceData.widgetObjectTypes.contains("QScrollBar")) { + const QScrollBar *sb = dynamic_cast<const QScrollBar*>(widget); + if (sb) { + ceData.orientation = sb->orientation(); + ceData.minSteps = sb->minValue(); + ceData.maxSteps = sb->maxValue(); + ceData.currentStep = sb->value(); + ceData.startStep = sb->sliderStart(); + ceData.lineStep = sb->lineStep(); + ceData.pageStep = sb->pageStep(); + if (populateReliantFields) { + ceData.sliderRect = sb->sliderRect(); + } + } + } + if (ceData.widgetObjectTypes.contains("QSlider")) { + const QSlider *sl = dynamic_cast<const QSlider*>(widget); + if (sl) { + ceData.orientation = sl->orientation(); + ceData.tickMarkSetting = sl->tickmarks(); + ceData.tickInterval = sl->tickInterval(); + ceData.currentStep = sl->value(); + ceData.startStep = sl->sliderStart(); + ceData.lineStep = sl->lineStep(); + ceData.pageStep = sl->pageStep(); + if (populateReliantFields) { + ceData.sliderRect = sl->sliderRect(); + } + } + } + if (ceData.widgetObjectTypes.contains("QDialogButtons")) { + const QDialogButtons *dlgbtns = dynamic_cast<const QDialogButtons*>(widget); + if (dlgbtns) { + ceData.orientation = dlgbtns->orientation(); + ceData.dlgVisibleButtons = dlgbtns->visibleButtons(); + QDialogButtons::Button btns[] = { QDialogButtons::All, QDialogButtons::Reject, QDialogButtons::Accept, QDialogButtons::Apply, QDialogButtons::Retry, QDialogButtons::Ignore, QDialogButtons::Abort, QDialogButtons::Help }; + for(unsigned int i = 0; i < (sizeof(btns)/sizeof(btns[0])); i++) { + if (ceData.dlgVisibleButtons & btns[i]) { + ceData.dlgVisibleSizeHints[btns[i]] = dlgbtns->sizeHint(btns[i]); + } + } + + } + } + if (ceData.widgetObjectTypes.contains("QTitleBar")) { + const QTitleBar *tb = dynamic_cast<const QTitleBar*>(widget); + if (tb) { + ceData.titleBarData.hasWindow = !!(tb->window()); + if (ceData.titleBarData.hasWindow) { + ceData.titleBarData.windowState = tb->window()->windowState(); + } + if (populateReliantFields) { + ceData.titleBarData.usesActiveColor = tb->usesActiveColor(); + } + ceData.titleBarData.visibleText = tb->visibleText(); + } + } + if (ceData.widgetObjectTypes.contains("QSpinWidget")) { + const QSpinWidget *sw = dynamic_cast<const QSpinWidget*>(widget); + if (sw) { + ceData.spinWidgetData.buttonSymbols = sw->buttonSymbols(); + ceData.spinWidgetData.upRect = sw->upRect(); + ceData.spinWidgetData.downRect = sw->downRect(); + ceData.spinWidgetData.upEnabled = sw->isUpEnabled(); + ceData.spinWidgetData.downEnabled = sw->isDownEnabled(); + } + } + if (ceData.widgetObjectTypes.contains("QListView")) { + const QListView *lv = dynamic_cast<const QListView*>(widget); + if (lv) { + ceData.listViewData.rootDecorated = lv->rootIsDecorated(); + ceData.listViewData.itemMargin = lv->itemMargin(); + QWidget* viewport = lv->viewport(); + if (viewport) { + ceData.viewportData.widgetObjectTypes = getObjectTypeListForObject(viewport); + ceData.viewportData.allDataPopulated = populateReliantFields; + const QPixmap* erasePixmap = viewport->backgroundPixmap(); + if (erasePixmap) { + ceData.viewportData.bgPixmap = *erasePixmap; + } + if (populateReliantFields) { + ceData.viewportData.bgBrush = viewport->backgroundBrush(); + } + ceData.viewportData.wflags = viewport->getWFlags(); + ceData.viewportData.bgColor = viewport->eraseColor(); + ceData.viewportData.bgOffset = viewport->backgroundOffset(); + ceData.viewportData.backgroundMode = viewport->backgroundMode(); + if (populateReliantFields) { + ceData.viewportData.fgColor = viewport->foregroundColor(); + ceData.viewportData.colorGroup = viewport->colorGroup(); + } + ceData.viewportData.geometry = viewport->geometry(); + ceData.viewportData.rect = viewport->rect(); + ceData.viewportData.pos = viewport->pos(); + const QPixmap* icon = viewport->icon(); + if (icon) { + ceData.viewportData.icon = *icon; + } + ceData.viewportData.palette = viewport->palette(); + ceData.viewportData.font = viewport->font(); + } + } + } + if (ceData.widgetObjectTypes.contains("QComboBox")) { + const QComboBox *cb = dynamic_cast<const QComboBox*>(widget); + if (cb) { + const QLineEdit* lineEdit = cb->lineEdit(); + if (lineEdit) { + ceData.comboBoxLineEditFlags = getControlElementFlagsForObject(lineEdit, ceData.widgetObjectTypes, QStyleOption::Default); + } + } + } + if (ceData.widgetObjectTypes.contains("QFrame")) { + const QFrame *frame = dynamic_cast<const QFrame*>(widget); + if (frame) { + ceData.frameStyle = frame->frameStyle(); + } + } + + const QWidget* parentWidget = widget->parentWidget(); + if (parentWidget) { + ceData.parentWidgetData.widgetObjectTypes = getObjectTypeListForObject(parentWidget); + ceData.parentWidgetData.allDataPopulated = populateReliantFields; + const QPixmap* erasePixmap = parentWidget->backgroundPixmap(); + if (erasePixmap) { + ceData.parentWidgetData.bgPixmap = *erasePixmap; + } + if (populateReliantFields) { + ceData.parentWidgetData.bgBrush = parentWidget->backgroundBrush(); + } + ceData.parentWidgetData.wflags = parentWidget->getWFlags(); + ceData.parentWidgetData.bgColor = parentWidget->eraseColor(); + ceData.parentWidgetData.bgOffset = parentWidget->backgroundOffset(); + ceData.parentWidgetData.backgroundMode = parentWidget->backgroundMode(); + if (populateReliantFields) { + ceData.parentWidgetData.fgColor = parentWidget->foregroundColor(); + ceData.parentWidgetData.colorGroup = parentWidget->colorGroup(); + } + ceData.parentWidgetData.geometry = parentWidget->geometry(); + ceData.parentWidgetData.rect = parentWidget->rect(); + ceData.parentWidgetData.pos = parentWidget->pos(); + const QPixmap* icon = parentWidget->icon(); + if (icon) { + ceData.parentWidgetData.icon = *icon; + } + ceData.parentWidgetData.palette = parentWidget->palette(); + ceData.parentWidgetData.font = parentWidget->font(); + + const QDockWindow * dw = dynamic_cast<const QDockWindow*>(parentWidget); + if (dw) { + if (dw->area()) { + ceData.dwData.hasDockArea = true; + ceData.dwData.areaOrientation = dw->area()->orientation(); + } + else { + ceData.dwData.hasDockArea = false; + } + ceData.dwData.closeEnabled = dw->isCloseEnabled(); + } + } + } + + return ceData; +} + /*! \reimp */ void QCommonStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, @@ -143,6 +544,32 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, SFlags flags, const QStyleOption& opt ) const { + const QWidget* widget = 0; + + // Determine if the request needs widget information and set widget appropriately + // FIXME + if ((pe == PE_CheckListController) || (pe == PE_CheckListExclusiveIndicator) || (pe == PE_CheckListIndicator)) { + QCheckListItem *item = opt.checkListItem(); + if (item) { + QListView *lv = item->listView(); + widget = dynamic_cast<QWidget*>(lv); + } + } + + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + drawPrimitive(pe, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, cg, flags, opt); +} + +/*! \reimp */ +void QCommonStyle::drawPrimitive( PrimitiveElement pe, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags flags, + const QStyleOption& opt ) const +{ activePainter = p; switch (pe) { @@ -152,7 +579,6 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, break; } case PE_CheckListExclusiveIndicator: { QCheckListItem *item = opt.checkListItem(); - QListView *lv = item->listView(); if(!item) return; int x = r.x(), y = r.y(); @@ -174,7 +600,7 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, if ( flags & Style_Enabled ) p->setPen( cg.text() ); else - p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ) ) ); + p->setPen( QPen( ceData.palette.color( QPalette::Disabled, QColorGroup::Text ) ) ); QPointArray a( QCOORDARRLEN(pts1), pts1 ); a.translate( x, y ); //p->setPen( cg.dark() ); @@ -205,21 +631,20 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, break; } case PE_CheckListIndicator: { QCheckListItem *item = opt.checkListItem(); - QListView *lv = item->listView(); if(!item) return; - int x = r.x(), y = r.y(), w = r.width(), h = r.width(), marg = lv->itemMargin(); + int x = r.x(), y = r.y(), w = r.width(), h = r.width(), marg = ceData.listViewData.itemMargin; if ( flags & Style_Enabled ) p->setPen( QPen( cg.text(), 2 ) ); else - p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ), + p->setPen( QPen( ceData.palette.color( QPalette::Disabled, QColorGroup::Text ), 2 ) ); bool parentControl = FALSE; if ( item->parent() && item->parent()->rtti() == 1 && ((QCheckListItem*) item->parent())->type() == QCheckListItem::Controller ) parentControl = TRUE; - if ( flags & Style_Selected && !lv->rootIsDecorated() && !parentControl ) { + if ( flags & Style_Selected && !ceData.listViewData.rootDecorated && !parentControl ) { p->fillRect( 0, 0, x + marg + w + 4, item->height(), cg.brush( QColorGroup::Highlight ) ); if ( item->isEnabled() ) @@ -322,7 +747,7 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, case PE_SpinWidgetPlus: case PE_SpinWidgetMinus: { p->save(); - int fw = pixelMetric( PM_DefaultFrameWidth, 0 ); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, 0 ); QRect br; br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2, r.height() - fw*2 ); @@ -353,7 +778,7 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, case PE_SpinWidgetUp: case PE_SpinWidgetDown: { - int fw = pixelMetric( PM_DefaultFrameWidth, 0 ); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, 0 ); QRect br; br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2, r.height() - fw*2 ); @@ -378,8 +803,8 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, int bsx = 0; int bsy = 0; if ( flags & Style_Sunken ) { - bsx = pixelMetric(PM_ButtonShiftHorizontal); - bsy = pixelMetric(PM_ButtonShiftVertical); + bsx = pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags); + bsy = pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags); } p->save(); p->translate( sx + bsx, sy + bsy ); @@ -464,21 +889,21 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, case PE_Panel: case PE_PanelPopup: { - int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth) + int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags) : opt.lineWidth(); qDrawShadePanel(p, r, cg, (flags & Style_Sunken), lw); break; } case PE_PanelDockWindow: { - int lw = opt.isDefault() ? pixelMetric(PM_DockWindowFrameWidth) + int lw = opt.isDefault() ? pixelMetric(PM_DockWindowFrameWidth, ceData, elementFlags) : opt.lineWidth(); qDrawShadePanel(p, r, cg, FALSE, lw); break; } case PE_PanelMenuBar: { - int lw = opt.isDefault() ? pixelMetric(PM_MenuBarFrameWidth) + int lw = opt.isDefault() ? pixelMetric(PM_MenuBarFrameWidth, ceData, elementFlags) : opt.lineWidth(); qDrawShadePanel(p, r, cg, FALSE, lw, &cg.brush(QColorGroup::Button)); @@ -565,7 +990,7 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, break; } case PE_PanelGroupBox: //We really do not need PE_GroupBoxFrame anymore, nasty holdover ### - drawPrimitive( PE_GroupBoxFrame, p, r, cg, flags, opt ); + drawPrimitive( PE_GroupBoxFrame, p, ceData, elementFlags, r, cg, flags, opt ); break; case PE_GroupBoxFrame: { #ifndef QT_NO_FRAME @@ -587,11 +1012,11 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, case PE_PanelLineEdit: case PE_PanelTabWidget: case PE_WindowFrame: - drawPrimitive( PE_Panel, p, r, cg, flags, opt ); + drawPrimitive( PE_Panel, p, ceData, elementFlags, r, cg, flags, opt ); break; case PE_RubberBand: - drawPrimitive(PE_FocusRect, p, r, cg, flags, opt); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, r, cg, flags, opt); break; default: break; @@ -600,6 +1025,25 @@ void QCommonStyle::drawPrimitive( PrimitiveElement pe, activePainter = 0; } +void qt_style_erase_region(QPainter* p, const QRegion& region, QStyleControlElementData ceData) { + QRegion reg = region; + + QPoint offset = ceData.bgOffset; + int ox = offset.x(); + int oy = offset.y(); + + QRegion origcr = p->clipRegion(); + p->setClipRegion(region); + if (!ceData.bgPixmap.isNull()) { + p->drawTiledPixmap(0, 0, ceData.geometry.width(), ceData.geometry.height(), ceData.bgPixmap, ox, oy); + } + else { + p->fillRect(ceData.rect, ceData.bgColor); + } + p->setClipRegion(origcr); + return; +} + /*! \reimp */ void QCommonStyle::drawControl( ControlElement element, QPainter *p, @@ -610,12 +1054,27 @@ void QCommonStyle::drawControl( ControlElement element, const QStyleOption& opt ) const { #if defined(QT_CHECK_STATE) - if (! widget) { - qWarning("QCommonStyle::drawControl: widget parameter cannot be zero!"); - return; - } + if (!widget) { + qWarning("QCommonStyle::drawControl: widget parameter cannot be zero!"); + return; + } #endif + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); + drawControl(element, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), r, cg, flags, opt, widget); +} + +/*! \reimp */ +void QCommonStyle::drawControl( ControlElement element, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags flags, + const QStyleOption& opt, + const QWidget *widget ) const +{ activePainter = p; switch (element) { @@ -625,18 +1084,18 @@ void QCommonStyle::drawControl( ControlElement element, reg = p->clipRegion(); else reg = r; - ((QWidget *)widget)->erase( reg ); + qt_style_erase_region(p, reg, ceData); break; } case CE_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; QRect br = r; - int dbi = pixelMetric(PM_ButtonDefaultIndicator, widget); + int dbi = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget); - if (button->isDefault() || button->autoDefault()) { - if ( button->isDefault()) - drawPrimitive(PE_ButtonDefault, p, br, cg, flags); + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) { + if (elementFlags & CEF_IsDefault) { + drawPrimitive(PE_ButtonDefault, p, ceData, elementFlags, br, cg, flags); + } br.setCoords(br.left() + dbi, br.top() + dbi, @@ -645,9 +1104,9 @@ void QCommonStyle::drawControl( ControlElement element, } p->save(); - p->setBrushOrigin( -widget->backgroundOffset().x(), - -widget->backgroundOffset().y() ); - drawPrimitive(PE_ButtonCommand, p, br, cg, flags); + p->setBrushOrigin( -ceData.bgOffset.x(), + -ceData.bgOffset.y() ); + drawPrimitive(PE_ButtonCommand, p, ceData, elementFlags, br, cg, flags); p->restore(); #endif break; @@ -656,43 +1115,42 @@ void QCommonStyle::drawControl( ControlElement element, case CE_PushButtonLabel: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; QRect ir = r; - if (button->isDown() || button->isOn()) { + if ((elementFlags & CEF_IsDown) || (elementFlags & CEF_IsOn)) { flags |= Style_Sunken; - ir.moveBy(pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget)); + ir.moveBy(pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget)); } - if (button->isMenuButton()) { - int mbi = pixelMetric(PM_MenuButtonIndicator, widget); + if (elementFlags & CEF_IsMenuWidget) { + int mbi = pixelMetric(PM_MenuButtonIndicator, ceData, elementFlags, widget); QRect ar(ir.right() - mbi, ir.y() + 2, mbi - 4, ir.height() - 4); - drawPrimitive(PE_ArrowDown, p, ar, cg, flags, opt); + drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, ar, cg, flags, opt); ir.setWidth(ir.width() - mbi); } int tf=AlignVCenter | ShowPrefix; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) tf |= NoAccel; #ifndef QT_NO_ICONSET - if ( button->iconSet() && ! button->iconSet()->isNull() ) { + if ( !ceData.iconSet.isNull() ) { QIconSet::Mode mode = - button->isEnabled() ? QIconSet::Normal : QIconSet::Disabled; - if ( mode == QIconSet::Normal && button->hasFocus() ) + (elementFlags & CEF_IsEnabled) ? QIconSet::Normal : QIconSet::Disabled; + if ( mode == QIconSet::Normal && (elementFlags & CEF_HasFocus) ) mode = QIconSet::Active; QIconSet::State state = QIconSet::Off; - if ( button->isToggleButton() && button->isOn() ) + if ( (elementFlags & CEF_BiState) && (elementFlags & CEF_IsOn) ) state = QIconSet::On; - QPixmap pixmap = button->iconSet()->pixmap( QIconSet::Small, mode, state ); + QPixmap pixmap = ceData.iconSet.pixmap( QIconSet::Small, mode, state ); int pixw = pixmap.width(); int pixh = pixmap.height(); //Center the icon if there is neither text nor pixmap - if ( button->text().isEmpty() && !button->pixmap() ) + if ( ceData.text.isEmpty() && ceData.fgPixmap.isNull() ) p->drawPixmap( ir.x() + ir.width() / 2 - pixw / 2, ir.y() + ir.height() / 2 - pixh / 2, pixmap ); else p->drawPixmap( ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2, pixmap ); @@ -700,66 +1158,62 @@ void QCommonStyle::drawControl( ControlElement element, ir.moveBy(pixw + 4, 0); ir.setWidth(ir.width() - (pixw + 4)); // left-align text if there is - if (!button->text().isEmpty()) + if (!ceData.text.isEmpty()) tf |= AlignLeft; - else if (button->pixmap()) + else if (!ceData.fgPixmap.isNull()) tf |= AlignHCenter; } else #endif //QT_NO_ICONSET tf |= AlignHCenter; drawItem(p, ir, tf, cg, - flags & Style_Enabled, button->pixmap(), button->text(), - button->text().length(), &(cg.buttonText()) ); + flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text, + ceData.text.length(), &(cg.buttonText()) ); if (flags & Style_HasFocus) - drawPrimitive(PE_FocusRect, p, subRect(SR_PushButtonFocusRect, widget), + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, subRect(SR_PushButtonFocusRect, ceData, elementFlags, widget), cg, flags); #endif break; } case CE_CheckBox: - drawPrimitive(PE_Indicator, p, r, cg, flags, opt); + drawPrimitive(PE_Indicator, p, ceData, elementFlags, r, cg, flags, opt); break; case CE_CheckBoxLabel: { #ifndef QT_NO_CHECKBOX - const QCheckBox *checkbox = (const QCheckBox *) widget; - int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg, - flags & Style_Enabled, checkbox->pixmap(), checkbox->text()); + flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text); if (flags & Style_HasFocus) { - QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, widget), widget); - drawPrimitive(PE_FocusRect, p, fr, cg, flags); + QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, ceData, elementFlags, widget), ceData, elementFlags); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags); } #endif break; } case CE_RadioButton: - drawPrimitive(PE_ExclusiveIndicator, p, r, cg, flags, opt); + drawPrimitive(PE_ExclusiveIndicator, p, ceData, elementFlags, r, cg, flags, opt); break; case CE_RadioButtonLabel: { #ifndef QT_NO_RADIOBUTTON - const QRadioButton *radiobutton = (const QRadioButton *) widget; - int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg, - flags & Style_Enabled, radiobutton->pixmap(), radiobutton->text()); + flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text); if (flags & Style_HasFocus) { - QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, widget), widget); - drawPrimitive(PE_FocusRect, p, fr, cg, flags); + QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, ceData, elementFlags, widget), ceData, elementFlags); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags); } #endif break; @@ -768,10 +1222,8 @@ void QCommonStyle::drawControl( ControlElement element, #ifndef QT_NO_TABBAR case CE_TabBarTab: { - const QTabBar * tb = (const QTabBar *) widget; - - if ( tb->shape() == QTabBar::TriangularAbove || - tb->shape() == QTabBar::TriangularBelow ) { + if ( ceData.tabBarData.shape == QTabBar::TriangularAbove || + ceData.tabBarData.shape == QTabBar::TriangularBelow ) { // triangular, above or below int y; int x; @@ -790,7 +1242,7 @@ void QCommonStyle::drawControl( ControlElement element, for ( i = 0; i < 5; i++ ) a.setPoint( 9-i, right - a.point( i ).x(), a.point( i ).y() ); - if ( tb->shape() == QTabBar::TriangularAbove ) + if ( ceData.tabBarData.shape == QTabBar::TriangularAbove ) for ( i = 0; i < 10; i++ ) a.setPoint( i, a.point(i).x(), r.height() - 1 - a.point( i ).y() ); @@ -813,22 +1265,21 @@ void QCommonStyle::drawControl( ControlElement element, if ( opt.isDefault() ) break; - const QTabBar * tb = (const QTabBar *) widget; QTab * t = opt.tab(); QRect tr = r; - if ( t->identifier() == tb->currentTab() ) + if (elementFlags & CEF_IsActive) tr.setBottom( tr.bottom() - - pixelMetric( QStyle::PM_DefaultFrameWidth, tb ) ); + pixelMetric( QStyle::PM_DefaultFrameWidth, ceData, elementFlags, widget ) ); int alignment = AlignCenter | ShowPrefix; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, t->text() ); if ( (flags & Style_HasFocus) && !t->text().isEmpty() ) - drawPrimitive( PE_FocusRect, p, r, cg ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, r, cg ); break; } #endif // QT_NO_TABBAR @@ -845,10 +1296,8 @@ void QCommonStyle::drawControl( ControlElement element, a.setPoint( 5, r.width() - 1, r.height() + 1 ); a.setPoint( 6, -1, r.height() + 1 ); - const QToolBox *tb = (const QToolBox*)widget; - - if ( flags & Style_Selected && tb->currentItem() ) - p->setBrush( tb->currentItem()->paletteBackgroundColor() ); + if ( flags & Style_Selected && !(elementFlags & CEF_IsContainerEmpty) ) + p->setBrush( ceData.activeItemPaletteBgColor ); else p->setBrush( cg.brush(QColorGroup::Background) ); @@ -869,32 +1318,31 @@ void QCommonStyle::drawControl( ControlElement element, #ifndef QT_NO_PROGRESSBAR case CE_ProgressBarContents: { - const QProgressBar *progressbar = (const QProgressBar *) widget; // Correct the highlight color if same as background, // or else we cannot see the progress... QColorGroup cgh = cg; if ( cgh.highlight() == cgh.background() ) - cgh.setColor( QColorGroup::Highlight, progressbar->palette().active().highlight() ); + cgh.setColor( QColorGroup::Highlight, ceData.palette.active().highlight() ); bool reverse = QApplication::reverseLayout(); int fw = 2; int w = r.width() - 2*fw; - if ( !progressbar->totalSteps() ) { + if ( !ceData.totalSteps ) { // draw busy indicator - int x = progressbar->progress() % (w * 2); + int x = ceData.currentStep % (w * 2); if (x > w) x = 2 * w - x; x = reverse ? r.right() - x : x + r.x(); p->setPen( QPen(cgh.highlight(), 4) ); p->drawLine(x, r.y() + 1, x, r.height() - fw); } else { - const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, widget); + const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, ceData, elementFlags, widget); int u; if ( unit_width > 1 ) u = (r.width()+unit_width/3) / unit_width; else u = w / unit_width; - int p_v = progressbar->progress(); - int t_s = progressbar->totalSteps() ? progressbar->totalSteps() : 1; + int p_v = ceData.currentStep; + int t_s = ceData.totalSteps ? ceData.totalSteps : 1; if ( u > 0 && p_v >= INT_MAX / u && t_s >= u ) { // scale down to something usable. @@ -917,7 +1365,7 @@ void QCommonStyle::drawControl( ControlElement element, int x0 = reverse ? r.right() - ((unit_width > 1) ? unit_width : fw) : r.x() + fw; for (int i=0; i<nu; i++) { - drawPrimitive( PE_ProgressBarChunk, p, + drawPrimitive( PE_ProgressBarChunk, p, ceData, elementFlags, QRect( x0+x, r.y(), unit_width, r.height() ), cgh, Style_Default, opt ); x += reverse ? -unit_width: unit_width; @@ -928,7 +1376,7 @@ void QCommonStyle::drawControl( ControlElement element, if (nu < tnu) { int pixels_left = w - (nu*unit_width); int offset = reverse ? x0+x+unit_width-pixels_left : x0+x; - drawPrimitive( PE_ProgressBarChunk, p, + drawPrimitive( PE_ProgressBarChunk, p, ceData, elementFlags, QRect( offset, r.y(), pixels_left, r.height() ), cgh, Style_Default, opt ); @@ -939,14 +1387,13 @@ void QCommonStyle::drawControl( ControlElement element, case CE_ProgressBarLabel: { - const QProgressBar *progressbar = (const QProgressBar *) widget; QColor penColor = cg.highlightedText(); QColor *pcolor = 0; - if ( progressbar->centerIndicator() && !progressbar->indicatorFollowsStyle() && - progressbar->progress()*2 >= progressbar->totalSteps() ) + if ( (elementFlags & CEF_CenterIndicator) && !(elementFlags & CEF_IndicatorFollowsStyle) && + ceData.currentStep*2 >= ceData.totalSteps ) pcolor = &penColor; drawItem(p, r, AlignCenter | SingleLine, cg, flags & Style_Enabled, 0, - progressbar->progressString(), -1, pcolor ); + ceData.progressText, -1, pcolor ); } break; #endif // QT_NO_PROGRESSBAR @@ -959,7 +1406,7 @@ void QCommonStyle::drawControl( ControlElement element, QMenuItem *mi = opt.menuItem(); int alignment = AlignCenter|ShowPrefix|DontClip|SingleLine; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; drawItem( p, r, alignment, cg, flags & Style_Enabled, mi->pixmap(), mi->text(), -1, @@ -971,7 +1418,6 @@ void QCommonStyle::drawControl( ControlElement element, #ifndef QT_NO_TOOLBUTTON case CE_ToolButtonLabel: { - const QToolButton *toolbutton = (const QToolButton *) widget; QRect rect = r; Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType(); @@ -979,8 +1425,8 @@ void QCommonStyle::drawControl( ControlElement element, int shiftX = 0; int shiftY = 0; if (flags & (Style_Down | Style_On)) { - shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget); - shiftY = pixelMetric(PM_ButtonShiftVertical, widget); + shiftX = pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget); + shiftY = pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget); } if (!opt.isDefault()) { @@ -994,45 +1440,45 @@ void QCommonStyle::drawControl( ControlElement element, } rect.moveBy(shiftX, shiftY); - drawPrimitive(pe, p, rect, cg, flags, opt); + drawPrimitive(pe, p, ceData, elementFlags, rect, cg, flags, opt); } else { - QColor btext = toolbutton->paletteForegroundColor(); + QColor btext = ceData.fgColor; - if (toolbutton->iconSet().isNull() && - ! toolbutton->text().isNull() && - ! toolbutton->usesTextLabel()) { + if (ceData.iconSet.isNull() && + ! ceData.text.isNull() && + ! (elementFlags & CEF_UsesTextLabel)) { int alignment = AlignCenter | ShowPrefix; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; rect.moveBy(shiftX, shiftY); drawItem(p, rect, alignment, cg, - flags & Style_Enabled, 0, toolbutton->text(), - toolbutton->text().length(), &btext); + flags & Style_Enabled, 0, ceData.text, + ceData.text.length(), &btext); } else { QPixmap pm; QIconSet::Size size = - toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small; + (elementFlags & CEF_UsesBigPixmap) ? QIconSet::Large : QIconSet::Small; QIconSet::State state = - toolbutton->isOn() ? QIconSet::On : QIconSet::Off; + (elementFlags & CEF_IsOn) ? QIconSet::On : QIconSet::Off; QIconSet::Mode mode; - if (! toolbutton->isEnabled()) + if (! (elementFlags & CEF_IsEnabled)) mode = QIconSet::Disabled; else if (flags & (Style_Down | Style_On) || ((flags & Style_Raised) && (flags & Style_AutoRaise))) mode = QIconSet::Active; else mode = QIconSet::Normal; - pm = toolbutton->iconSet().pixmap( size, mode, state ); + pm = ceData.iconSet.pixmap( size, mode, state ); - if ( toolbutton->usesTextLabel() ) { - p->setFont( toolbutton->font() ); + if (elementFlags & CEF_UsesTextLabel) { + p->setFont( ceData.font ); QRect pr = rect, tr = rect; int alignment = ShowPrefix; - if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) alignment |= NoAccel; - if ( toolbutton->textPosition() == QToolButton::Under ) { + if ( ceData.toolButtonTextPosition == QToolButton::Under ) { int fh = p->fontMetrics().height(); pr.addCoords( 0, 1, 0, -fh-3 ); tr.addCoords( 0, pr.bottom(), 0, -3 ); @@ -1050,8 +1496,8 @@ void QCommonStyle::drawControl( ControlElement element, tr.moveBy(shiftX, shiftY); drawItem( p, tr, alignment, cg, - flags & Style_Enabled, 0, toolbutton->textLabel(), - toolbutton->textLabel().length(), &btext); + flags & Style_Enabled, 0, ceData.textLabel, + ceData.textLabel.length(), &btext); } else { rect.moveBy(shiftX, shiftY); drawItem( p, rect, AlignCenter, cg, TRUE, &pm, QString::null ); @@ -1066,10 +1512,8 @@ void QCommonStyle::drawControl( ControlElement element, case CE_HeaderLabel: { QRect rect = r; - const QHeader* header = (const QHeader *) widget; - int section = opt.headerSection(); - QIconSet* icon = header->iconSet( section ); + QIconSet* icon = &ceData.iconSet; if ( icon ) { QPixmap pixmap = icon->pixmap( QIconSet::Small, flags & Style_Enabled ? @@ -1090,7 +1534,7 @@ void QCommonStyle::drawControl( ControlElement element, if (rect.isValid()) drawItem ( p, rect, AlignVCenter, cg, flags & Style_Enabled, - 0, header->label( section ), -1, &(cg.buttonText()) ); + 0, ceData.textLabel, -1, &(cg.buttonText()) ); } #endif // QT_NO_HEADER default: @@ -1100,13 +1544,27 @@ void QCommonStyle::drawControl( ControlElement element, activePainter = 0; } -/*! \reimp */ void QCommonStyle::drawControlMask( ControlElement control, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& opt ) const { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); + drawControlMask(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), r, opt, widget); +} + +/*! \reimp */ +void QCommonStyle::drawControlMask( ControlElement control, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& opt, + const QWidget *widget ) const +{ + Q_UNUSED(ceData); + Q_UNUSED(elementFlags); Q_UNUSED(widget); activePainter = p; @@ -1115,15 +1573,15 @@ void QCommonStyle::drawControlMask( ControlElement control, switch (control) { case CE_PushButton: - drawPrimitive(PE_ButtonCommand, p, r, cg, Style_Default, opt); + drawPrimitive(PE_ButtonCommand, p, ceData, elementFlags, r, cg, Style_Default, opt); break; case CE_CheckBox: - drawPrimitive(PE_IndicatorMask, p, r, cg, Style_Default, opt); + drawPrimitive(PE_IndicatorMask, p, ceData, elementFlags, r, cg, Style_Default, opt); break; case CE_RadioButton: - drawPrimitive(PE_ExclusiveIndicatorMask, p, r, cg, Style_Default, opt); + drawPrimitive(PE_ExclusiveIndicatorMask, p, ceData, elementFlags, r, cg, Style_Default, opt); break; default: @@ -1138,13 +1596,20 @@ void QCommonStyle::drawControlMask( ControlElement control, QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const { #if defined(QT_CHECK_STATE) - if (! widget) { - qWarning("QCommonStyle::subRect: widget parameter cannot be zero!"); - return QRect(); - } + if (! widget) { + qWarning("QCommonStyle::subRect: widget parameter cannot be zero!"); + return QRect(); + } #endif - QRect rect, wrect(widget->rect()); + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + return subRect(r, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); +} + +/*! \reimp */ +QRect QCommonStyle::subRect(SubRect r, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget) const +{ + QRect rect, wrect(ceData.rect); switch (r) { #ifndef QT_NO_DIALOGBUTTONS @@ -1175,22 +1640,21 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const else if(r == SR_DialogButtonAbort) srch = QDialogButtons::Abort; - const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, widget), - bheight = pixelMetric(PM_DialogButtonsButtonHeight, widget), - bspace = pixelMetric(PM_DialogButtonsSeparator, widget), - fw = pixelMetric(PM_DefaultFrameWidth, widget); - const QDialogButtons *dbtns = (const QDialogButtons *) widget; + const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, ceData, elementFlags, widget), + bheight = pixelMetric(PM_DialogButtonsButtonHeight, ceData, elementFlags, widget), + bspace = pixelMetric(PM_DialogButtonsSeparator, ceData, elementFlags, widget), + fw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget); int start = fw; - if(dbtns->orientation() == Horizontal) + if(ceData.orientation == Horizontal) start = wrect.right() - fw; QDialogButtons::Button btns[] = { QDialogButtons::All, QDialogButtons::Reject, QDialogButtons::Accept, //reverse order (right to left) QDialogButtons::Apply, QDialogButtons::Retry, QDialogButtons::Ignore, QDialogButtons::Abort, QDialogButtons::Help }; for(unsigned int i = 0, cnt = 0; i < (sizeof(btns)/sizeof(btns[0])); i++) { - if(dbtns->isButtonVisible(btns[i])) { - QSize szH = dbtns->sizeHint(btns[i]); + if (ceData.dlgVisibleButtons & btns[i]) { + QSize szH = ceData.dlgVisibleSizeHints[btns[i]]; int mwidth = QMAX(bwidth, szH.width()), mheight = QMAX(bheight, szH.height()); - if(dbtns->orientation() == Horizontal) { + if(ceData.orientation == Horizontal) { start -= mwidth; if(cnt) start -= bspace; @@ -1200,7 +1664,7 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const } cnt++; if(btns[i] == srch) { - if(dbtns->orientation() == Horizontal) + if(ceData.orientation == Horizontal) return QRect(start, wrect.bottom() - fw - mheight, mwidth, mheight); else return QRect(fw, start, mwidth, mheight); @@ -1208,7 +1672,7 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const } } if(r == SR_DialogButtonCustom) { - if(dbtns->orientation() == Horizontal) + if(ceData.orientation == Horizontal) return QRect(fw, fw, start - fw - bspace, wrect.height() - (fw*2)); else return QRect(fw, start, wrect.width() - (fw*2), wrect.height() - start - (fw*2)); @@ -1218,12 +1682,11 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_PushButtonContents: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; int dx1, dx2; - dx1 = pixelMetric(PM_DefaultFrameWidth, widget); - if (button->isDefault() || button->autoDefault()) - dx1 += pixelMetric(PM_ButtonDefaultIndicator, widget); + dx1 = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget); + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) + dx1 += pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget); dx2 = dx1 * 2; rect.setRect(wrect.x() + dx1, @@ -1237,14 +1700,13 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_PushButtonFocusRect: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; int dbw1 = 0, dbw2 = 0; - if (button->isDefault() || button->autoDefault()) { - dbw1 = pixelMetric(PM_ButtonDefaultIndicator, widget); + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) { + dbw1 = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget); dbw2 = dbw1 * 2; } - int dfw1 = pixelMetric(PM_DefaultFrameWidth, widget) * 2, + int dfw1 = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget) * 2, dfw2 = dfw1 * 2; rect.setRect(wrect.x() + dfw1 + dbw1, @@ -1257,16 +1719,16 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_CheckBoxIndicator: { - int h = pixelMetric( PM_IndicatorHeight, widget ); + int h = pixelMetric( PM_IndicatorHeight, ceData, elementFlags, widget ); rect.setRect(0, ( wrect.height() - h ) / 2, - pixelMetric( PM_IndicatorWidth, widget ), h ); + pixelMetric( PM_IndicatorWidth, ceData, elementFlags, widget ), h ); break; } case SR_CheckBoxContents: { #ifndef QT_NO_CHECKBOX - QRect ir = subRect(SR_CheckBoxIndicator, widget); + QRect ir = subRect(SR_CheckBoxIndicator, ceData, elementFlags, widget); rect.setRect(ir.right() + 6, wrect.y(), wrect.width() - ir.width() - 6, wrect.height()); #endif @@ -1276,23 +1738,22 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_CheckBoxFocusRect: { #ifndef QT_NO_CHECKBOX - const QCheckBox *checkbox = (const QCheckBox *) widget; - if ( !checkbox->pixmap() && checkbox->text().isEmpty() ) { - rect = subRect( SR_CheckBoxIndicator, widget ); + if ( ceData.fgPixmap.isNull() && ceData.text.isEmpty() ) { + rect = subRect( SR_CheckBoxIndicator, ceData, elementFlags, widget ); rect.addCoords( 1, 1, -1, -1 ); break; } - QRect cr = subRect(SR_CheckBoxContents, widget); + QRect cr = subRect(SR_CheckBoxContents, ceData, elementFlags, widget); // don't create a painter if we have an active one QPainter *p = 0; if (! activePainter) - p = new QPainter(checkbox); + p = new QPainter(widget); rect = itemRect((activePainter ? activePainter : p), cr, AlignLeft | AlignVCenter | ShowPrefix, - checkbox->isEnabled(), - checkbox->pixmap(), - checkbox->text()); + (elementFlags & CEF_IsEnabled), + (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, + ceData.text); delete p; @@ -1304,15 +1765,15 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_RadioButtonIndicator: { - int h = pixelMetric( PM_ExclusiveIndicatorHeight, widget ); + int h = pixelMetric( PM_ExclusiveIndicatorHeight, ceData, elementFlags, widget ); rect.setRect(0, ( wrect.height() - h ) / 2, - pixelMetric( PM_ExclusiveIndicatorWidth, widget ), h ); + pixelMetric( PM_ExclusiveIndicatorWidth, ceData, elementFlags, widget ), h ); break; } case SR_RadioButtonContents: { - QRect ir = subRect(SR_RadioButtonIndicator, widget); + QRect ir = subRect(SR_RadioButtonIndicator, ceData, elementFlags, widget); rect.setRect(ir.right() + 6, wrect.y(), wrect.width() - ir.width() - 6, wrect.height()); break; @@ -1321,23 +1782,22 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_RadioButtonFocusRect: { #ifndef QT_NO_RADIOBUTTON - const QRadioButton *radiobutton = (const QRadioButton *) widget; - if ( !radiobutton->pixmap() && radiobutton->text().isEmpty() ) { - rect = subRect( SR_RadioButtonIndicator, widget ); + if ( ceData.fgPixmap.isNull() && ceData.text.isEmpty() ) { + rect = subRect( SR_RadioButtonIndicator, ceData, elementFlags, widget ); rect.addCoords( 1, 1, -1, -1 ); break; } - QRect cr = subRect(SR_RadioButtonContents, widget); + QRect cr = subRect(SR_RadioButtonContents, ceData, elementFlags, widget); // don't create a painter if we have an active one QPainter *p = 0; if (! activePainter) - p = new QPainter(radiobutton); + p = new QPainter(widget); rect = itemRect((activePainter ? activePainter : p), cr, AlignLeft | AlignVCenter | ShowPrefix, - radiobutton->isEnabled(), - radiobutton->pixmap(), - radiobutton->text()); + (elementFlags & CEF_IsEnabled), + (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, + ceData.text); delete p; rect.addCoords( -3, -2, 3, 2 ); @@ -1347,21 +1807,20 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const } case SR_ComboBoxFocusRect: - rect.setRect(3, 3, widget->width()-6-16, widget->height()-6); + rect.setRect(3, 3, ceData.rect.width()-6-16, ceData.rect.height()-6); break; #ifndef QT_NO_SLIDER case SR_SliderFocusRect: { - const QSlider * sl = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl ); - int thickness = pixelMetric( PM_SliderControlThickness, sl ); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); - if ( sl->orientation() == Horizontal ) - rect.setRect( 0, tickOffset-1, sl->width(), thickness+2 ); + if ( ceData.orientation == Horizontal ) + rect.setRect( 0, tickOffset-1, ceData.rect.width(), thickness+2 ); else - rect.setRect( tickOffset-1, 0, thickness+2, sl->height() ); - rect = rect.intersect( sl->rect() ); // ## is this really necessary? + rect.setRect( tickOffset-1, 0, thickness+2, ceData.rect.height() ); + rect = rect.intersect( ceData.rect ); // ## is this really necessary? break; } #endif // QT_NO_SLIDER @@ -1369,18 +1828,16 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const #ifndef QT_NO_MAINWINDOW case SR_DockWindowHandleRect: { - if (! widget->parentWidget()) + if (!(elementFlags & CEF_HasParentWidget)) break; - const QDockWindow * dw = (const QDockWindow *) widget->parentWidget(); - - if ( !dw->area() || !dw->isCloseEnabled() ) - rect.setRect( 0, 0, widget->width(), widget->height() ); + if ( !ceData.dwData.hasDockArea || !ceData.dwData.closeEnabled ) + rect.setRect( 0, 0, ceData.rect.width(), ceData.rect.height() ); else { - if ( dw->area()->orientation() == Horizontal ) - rect.setRect(0, 15, widget->width(), widget->height() - 15); + if ( ceData.dwData.areaOrientation == Horizontal ) + rect.setRect(0, 15, ceData.rect.width(), ceData.rect.height() - 15); else - rect.setRect(0, 1, widget->width() - 15, widget->height() - 1); + rect.setRect(0, 1, ceData.rect.width() - 15, ceData.rect.height() - 1); } break; } @@ -1390,15 +1847,14 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_ProgressBarContents: { #ifndef QT_NO_PROGRESSBAR - QFontMetrics fm( ( widget ? widget->fontMetrics() : + QFontMetrics fm( ( (!(elementFlags & CEF_UseGenericParameters)) ? QFontMetrics(ceData.font) : QApplication::fontMetrics() ) ); - const QProgressBar *progressbar = (const QProgressBar *) widget; int textw = 0; - if (progressbar->percentageVisible()) + if (ceData.percentageVisible) textw = fm.width("100%") + 6; - if (progressbar->indicatorFollowsStyle() || - ! progressbar->centerIndicator()) + if ((elementFlags & CEF_IndicatorFollowsStyle) || + ! (elementFlags & CEF_CenterIndicator)) rect.setCoords(wrect.left(), wrect.top(), wrect.right() - textw, wrect.bottom()); else @@ -1410,15 +1866,14 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const case SR_ProgressBarLabel: { #ifndef QT_NO_PROGRESSBAR - QFontMetrics fm( ( widget ? widget->fontMetrics() : + QFontMetrics fm( ( (!(elementFlags & CEF_UseGenericParameters)) ? QFontMetrics(ceData.font) : QApplication::fontMetrics() ) ); - const QProgressBar *progressbar = (const QProgressBar *) widget; int textw = 0; - if (progressbar->percentageVisible()) + if (ceData.percentageVisible) textw = fm.width("100%") + 6; - if (progressbar->indicatorFollowsStyle() || - ! progressbar->centerIndicator()) + if ((elementFlags & CEF_IndicatorFollowsStyle) || + ! (elementFlags & CEF_CenterIndicator)) rect.setCoords(wrect.right() - textw, wrect.top(), wrect.right(), wrect.bottom()); else @@ -1428,7 +1883,7 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const } case SR_ToolButtonContents: - rect = querySubControlMetrics(CC_ToolButton, widget, SC_ToolButton); + rect = querySubControlMetrics(CC_ToolButton, ceData, elementFlags, SC_ToolButton, QStyleOption::Default, widget); break; case SR_ToolBoxTabContents: @@ -1448,17 +1903,17 @@ QRect QCommonStyle::subRect(SubRect r, const QWidget *widget) const /* I really need this and I don't want to expose it in QRangeControl.. */ -static int qPositionFromValue( const QRangeControl * rc, int logical_val, +static int qPositionFromValue( QStyleControlElementData ceData, int logical_val, int span ) { - if ( span <= 0 || logical_val < rc->minValue() || - rc->maxValue() <= rc->minValue() ) + if ( span <= 0 || logical_val < ceData.minSteps || + ceData.maxSteps <= ceData.minSteps ) return 0; - if ( logical_val > rc->maxValue() ) + if ( logical_val > ceData.maxSteps ) return span; - uint range = rc->maxValue() - rc->minValue(); - uint p = logical_val - rc->minValue(); + uint range = ceData.maxSteps - ceData.minSteps; + uint p = logical_val - ceData.minSteps; if ( range > (uint)INT_MAX/4096 ) { const int scale = 4096*2; @@ -1490,85 +1945,101 @@ void QCommonStyle::drawComplexControl( ComplexControl control, const QStyleOption& opt ) const { #if defined(QT_CHECK_STATE) - if (! widget) { - qWarning("QCommonStyle::drawComplexControl: widget parameter cannot be zero!"); - return; - } + if (! widget) { + qWarning("QCommonStyle::drawComplexControl: widget parameter cannot be zero!"); + return; + } #endif + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + drawComplexControl(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, cg, flags, controls, active, opt, widget); +} + +/*! \reimp */ +void QCommonStyle::drawComplexControl( ComplexControl control, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags flags, + SCFlags controls, + SCFlags active, + const QStyleOption& opt, + const QWidget *widget ) const +{ activePainter = p; switch (control) { #ifndef QT_NO_SCROLLBAR case CC_ScrollBar: { - const QScrollBar *scrollbar = (const QScrollBar *) widget; QRect addline, subline, addpage, subpage, slider, first, last; - bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue()); + bool maxedOut = (ceData.minSteps == ceData.maxSteps); - subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt); - addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt); - subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt); - addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt); - slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt); - first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt); - last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt); + subline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget); + addline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget); + subpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget); + addpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget); + slider = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget); + first = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarFirst, opt, widget); + last = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarLast, opt, widget); if ((controls & SC_ScrollBarSubLine) && subline.isValid()) - drawPrimitive(PE_ScrollBarSubLine, p, subline, cg, + drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarSubLine) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarAddLine) && addline.isValid()) - drawPrimitive(PE_ScrollBarAddLine, p, addline, cg, + drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarAddLine) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarSubPage) && subpage.isValid()) - drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg, + drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarSubPage) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarAddPage) && addpage.isValid()) - drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg, + drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarAddPage) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarFirst) && first.isValid()) - drawPrimitive(PE_ScrollBarFirst, p, first, cg, + drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarFirst) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarLast) && last.isValid()) - drawPrimitive(PE_ScrollBarLast, p, last, cg, + drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarLast) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); if ((controls & SC_ScrollBarSlider) && slider.isValid()) { - drawPrimitive(PE_ScrollBarSlider, p, slider, cg, + drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarSlider) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : 0)); // ### perhaps this should not be able to accept focus if maxedOut? - if (scrollbar->hasFocus()) { + if (elementFlags & CEF_HasFocus) { QRect fr(slider.x() + 2, slider.y() + 2, slider.width() - 5, slider.height() - 5); - drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default); } } @@ -1579,15 +2050,13 @@ void QCommonStyle::drawComplexControl( ComplexControl control, #ifndef QT_NO_TOOLBUTTON case CC_ToolButton: { - const QToolButton *toolbutton = (const QToolButton *) widget; - QColorGroup c = cg; - if ( toolbutton->backgroundMode() != PaletteButton ) + if ( ceData.backgroundMode != PaletteButton ) c.setBrush( QColorGroup::Button, - toolbutton->paletteBackgroundColor() ); + ceData.bgColor ); QRect button, menuarea; - button = visualRect( querySubControlMetrics(control, widget, SC_ToolButton, opt), widget ); - menuarea = visualRect( querySubControlMetrics(control, widget, SC_ToolButtonMenu, opt), widget ); + button = visualRect( querySubControlMetrics(control, ceData, elementFlags, SC_ToolButton, opt, widget), ceData, elementFlags ); + menuarea = visualRect( querySubControlMetrics(control, ceData, elementFlags, SC_ToolButtonMenu, opt, widget), ceData, elementFlags ); SFlags bflags = flags, mflags = flags; @@ -1599,27 +2068,26 @@ void QCommonStyle::drawComplexControl( ComplexControl control, if (controls & SC_ToolButton) { if (bflags & (Style_Down | Style_On | Style_Raised)) { - drawPrimitive(PE_ButtonTool, p, button, c, bflags, opt); - } else if ( toolbutton->parentWidget() && - toolbutton->parentWidget()->backgroundPixmap() && - ! toolbutton->parentWidget()->backgroundPixmap()->isNull() ) { + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, button, c, bflags, opt); + } else if ( (elementFlags & CEF_HasParentWidget) && + ! ceData.parentWidgetData.bgPixmap.isNull() ) { QPixmap pixmap = - *(toolbutton->parentWidget()->backgroundPixmap()); + ceData.parentWidgetData.bgPixmap; - p->drawTiledPixmap( r, pixmap, toolbutton->pos() ); + p->drawTiledPixmap( r, pixmap, ceData.pos ); } } if (controls & SC_ToolButtonMenu) { if (mflags & (Style_Down | Style_On | Style_Raised)) - drawPrimitive(PE_ButtonDropDown, p, menuarea, c, mflags, opt); - drawPrimitive(PE_ArrowDown, p, menuarea, c, mflags, opt); + drawPrimitive(PE_ButtonDropDown, p, ceData, elementFlags, menuarea, c, mflags, opt); + drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, menuarea, c, mflags, opt); } - if (toolbutton->hasFocus() && !toolbutton->focusProxy()) { - QRect fr = toolbutton->rect(); + if ((elementFlags & CEF_HasFocus) && !(elementFlags & CEF_HasFocusProxy)) { + QRect fr = ceData.rect; fr.addCoords(3, 3, -3, -3); - drawPrimitive(PE_FocusRect, p, fr, c); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, c); } break; @@ -1629,10 +2097,9 @@ void QCommonStyle::drawComplexControl( ComplexControl control, #ifndef QT_NO_TITLEBAR case CC_TitleBar: { - const QTitleBar *titlebar = (const QTitleBar *) widget; if ( controls & SC_TitleBarLabel ) { - QColorGroup cgroup = titlebar->usesActiveColor() ? - titlebar->palette().active() : titlebar->palette().inactive(); + QColorGroup cgroup = (ceData.titleBarData.usesActiveColor) ? + ceData.palette.active() : ceData.palette.inactive(); QColor left = cgroup.highlight(); QColor right = cgroup.base(); @@ -1642,27 +2109,27 @@ void QCommonStyle::drawComplexControl( ComplexControl control, double gS = left.green(); double bS = left.blue(); - const double rD = double(right.red() - rS) / titlebar->width(); - const double gD = double(right.green() - gS) / titlebar->width(); - const double bD = double(right.blue() - bS) / titlebar->width(); + const double rD = double(right.red() - rS) / ceData.rect.width(); + const double gD = double(right.green() - gS) / ceData.rect.width(); + const double bD = double(right.blue() - bS) / ceData.rect.width(); - const int w = titlebar->width(); + const int w = ceData.rect.width(); for ( int sx = 0; sx < w; sx++ ) { rS+=rD; gS+=gD; bS+=bD; p->setPen( QColor( (int)rS, (int)gS, (int)bS ) ); - p->drawLine( sx, 0, sx, titlebar->height() ); + p->drawLine( sx, 0, sx, ceData.rect.height() ); } } else { - p->fillRect( titlebar->rect(), left ); + p->fillRect( ceData.rect, left ); } - QRect ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarLabel ), widget ); + QRect ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarLabel, QStyleOption::Default, widget ), ceData, elementFlags ); p->setPen( cgroup.highlightedText() ); p->drawText(ir.x()+2, ir.y(), ir.width()-2, ir.height(), - AlignAuto | AlignVCenter | SingleLine, titlebar->visibleText() ); + AlignAuto | AlignVCenter | SingleLine, ceData.titleBarData.visibleText ); } QRect ir; @@ -1670,46 +2137,46 @@ void QCommonStyle::drawComplexControl( ComplexControl control, QPixmap pm; if ( controls & SC_TitleBarCloseButton ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarCloseButton ), widget ); + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarCloseButton, QStyleOption::Default, widget ), ceData, elementFlags ); down = active & SC_TitleBarCloseButton; if ( widget->testWFlags( WStyle_Tool ) #ifndef QT_NO_MAINWINDOW || ::qt_cast<QDockWindow*>(widget) #endif ) - pm = stylePixmap(SP_DockWindowCloseButton, widget); + pm = stylePixmap(SP_DockWindowCloseButton, ceData, elementFlags, QStyleOption::Default, widget); else - pm = stylePixmap(SP_TitleBarCloseButton, widget); - drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(), + pm = stylePixmap(SP_TitleBarCloseButton, ceData, elementFlags, QStyleOption::Default, widget); + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, ir, ceData.colorGroup, down ? Style_Down : Style_Raised); p->save(); if( down ) - p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null ); + p->translate( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, &pm, QString::null ); p->restore(); } - if ( titlebar->window() ) { + if ( ceData.titleBarData.hasWindow ) { if ( controls & SC_TitleBarMaxButton ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarMaxButton ), widget ); + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarMaxButton, QStyleOption::Default, widget ), ceData, elementFlags ); down = active & SC_TitleBarMaxButton; - pm = QPixmap(stylePixmap(SP_TitleBarMaxButton, widget)); - drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(), + pm = QPixmap(stylePixmap(SP_TitleBarMaxButton, ceData, elementFlags, QStyleOption::Default, widget)); + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, ir, ceData.colorGroup, down ? Style_Down : Style_Raised); p->save(); if( down ) - p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null ); + p->translate( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, &pm, QString::null ); p->restore(); } if ( controls & SC_TitleBarNormalButton || controls & SC_TitleBarMinButton ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarMinButton ), widget ); + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarMinButton, QStyleOption::Default, widget ), ceData, elementFlags ); QStyle::SubControl ctrl = (controls & SC_TitleBarNormalButton ? SC_TitleBarNormalButton : SC_TitleBarMinButton); @@ -1717,53 +2184,53 @@ void QCommonStyle::drawComplexControl( ComplexControl control, SP_TitleBarNormalButton : SP_TitleBarMinButton); down = active & ctrl; - pm = QPixmap(stylePixmap(spixmap, widget)); - drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(), + pm = QPixmap(stylePixmap(spixmap, ceData, elementFlags, QStyleOption::Default, widget)); + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, ir, ceData.colorGroup, down ? Style_Down : Style_Raised); p->save(); if( down ) - p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null ); + p->translate( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, &pm, QString::null ); p->restore(); } if ( controls & SC_TitleBarShadeButton ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarShadeButton ), widget ); + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarShadeButton, QStyleOption::Default, widget ), ceData, elementFlags ); down = active & SC_TitleBarShadeButton; - pm = QPixmap(stylePixmap(SP_TitleBarShadeButton, widget)); - drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(), + pm = QPixmap(stylePixmap(SP_TitleBarShadeButton, ceData, elementFlags, QStyleOption::Default, widget)); + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, ir, ceData.colorGroup, down ? Style_Down : Style_Raised); p->save(); if( down ) - p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null ); + p->translate( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, &pm, QString::null ); p->restore(); } if ( controls & SC_TitleBarUnshadeButton ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarUnshadeButton ), widget ); + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarUnshadeButton, QStyleOption::Default, widget ), ceData, elementFlags ); down = active & SC_TitleBarUnshadeButton; - pm = QPixmap(stylePixmap(SP_TitleBarUnshadeButton, widget)); - drawPrimitive(PE_ButtonTool, p, ir, titlebar->colorGroup(), + pm = QPixmap(stylePixmap(SP_TitleBarUnshadeButton, ceData, elementFlags, QStyleOption::Default, widget)); + drawPrimitive(PE_ButtonTool, p, ceData, elementFlags, ir, ceData.colorGroup, down ? Style_Down : Style_Raised); p->save(); if( down ) - p->translate( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, &pm, QString::null ); + p->translate( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, &pm, QString::null ); p->restore(); } } #ifndef QT_NO_WIDGET_TOPEXTRA if ( controls & SC_TitleBarSysMenu ) { - if ( titlebar->icon() ) { - ir = visualRect( querySubControlMetrics( CC_TitleBar, widget, SC_TitleBarSysMenu ), widget ); - drawItem( p, ir, AlignCenter, titlebar->colorGroup(), TRUE, titlebar->icon(), QString::null ); + if ( !ceData.icon.isNull() ) { + ir = visualRect( querySubControlMetrics( CC_TitleBar, ceData, elementFlags, SC_TitleBarSysMenu, QStyleOption::Default, widget ), ceData, elementFlags ); + drawItem( p, ir, AlignCenter, ceData.colorGroup, TRUE, (ceData.icon.isNull())?NULL:&ceData.icon, QString::null ); } } #endif @@ -1773,7 +2240,6 @@ void QCommonStyle::drawComplexControl( ComplexControl control, case CC_SpinWidget: { #ifndef QT_NO_SPINWIDGET - const QSpinWidget * sw = (const QSpinWidget *) widget; SFlags flags; PrimitiveElement pe; @@ -1787,15 +2253,15 @@ void QCommonStyle::drawComplexControl( ComplexControl control, flags |= Style_Sunken; } else flags |= Style_Raised; - if ( sw->buttonSymbols() == QSpinWidget::PlusMinus ) + if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus ) pe = PE_SpinWidgetPlus; else pe = PE_SpinWidgetUp; - QRect re = sw->upRect(); - QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled(); - drawPrimitive(PE_ButtonBevel, p, re, ucg, flags); - drawPrimitive(pe, p, re, ucg, flags); + QRect re = ceData.spinWidgetData.upRect; + QColorGroup ucg = ceData.spinWidgetData.upEnabled ? cg : ceData.palette.disabled(); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, re, ucg, flags); + drawPrimitive(pe, p, ceData, elementFlags, re, ucg, flags); } if ( controls & SC_SpinWidgetDown ) { @@ -1805,15 +2271,15 @@ void QCommonStyle::drawComplexControl( ComplexControl control, flags |= Style_Sunken; } else flags |= Style_Raised; - if ( sw->buttonSymbols() == QSpinWidget::PlusMinus ) + if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus ) pe = PE_SpinWidgetMinus; else pe = PE_SpinWidgetDown; - QRect re = sw->downRect(); - QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled(); - drawPrimitive(PE_ButtonBevel, p, re, dcg, flags); - drawPrimitive(pe, p, re, dcg, flags); + QRect re = ceData.spinWidgetData.downRect; + QColorGroup dcg = ceData.spinWidgetData.downEnabled ? cg : ceData.palette.disabled(); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, re, dcg, flags); + drawPrimitive(pe, p, ceData, elementFlags, re, dcg, flags); } #endif break; } @@ -1822,19 +2288,18 @@ void QCommonStyle::drawComplexControl( ComplexControl control, case CC_Slider: switch ( controls ) { case SC_SliderTickmarks: { - const QSlider * sl = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl ); - int ticks = sl->tickmarks(); - int thickness = pixelMetric( PM_SliderControlThickness, sl ); - int len = pixelMetric( PM_SliderLength, sl ); - int available = pixelMetric( PM_SliderSpaceAvailable, sl ); - int interval = sl->tickInterval(); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int ticks = ceData.tickMarkSetting; + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); + int available = pixelMetric( PM_SliderSpaceAvailable, ceData, elementFlags, widget ); + int interval = ceData.tickInterval; if ( interval <= 0 ) { - interval = sl->lineStep(); - if ( qPositionFromValue( sl, interval, available ) - - qPositionFromValue( sl, 0, available ) < 3 ) - interval = sl->pageStep(); + interval = ceData.lineStep; + if ( qPositionFromValue( ceData, interval, available ) - + qPositionFromValue( ceData, 0, available ) < 3 ) + interval = ceData.pageStep; } int fudge = len / 2; @@ -1842,12 +2307,12 @@ void QCommonStyle::drawComplexControl( ComplexControl control, if ( ticks & QSlider::Above ) { p->setPen( cg.foreground() ); - int v = sl->minValue(); + int v = ceData.minSteps; if ( !interval ) interval = 1; - while ( v <= sl->maxValue() + 1 ) { - pos = qPositionFromValue( sl, v, available ) + fudge; - if ( sl->orientation() == Horizontal ) + while ( v <= ceData.maxSteps + 1 ) { + pos = qPositionFromValue( ceData, v, available ) + fudge; + if ( ceData.orientation == Horizontal ) p->drawLine( pos, 0, pos, tickOffset-2 ); else p->drawLine( 0, pos, tickOffset-2, pos ); @@ -1857,12 +2322,12 @@ void QCommonStyle::drawComplexControl( ComplexControl control, if ( ticks & QSlider::Below ) { p->setPen( cg.foreground() ); - int v = sl->minValue(); + int v = ceData.minSteps; if ( !interval ) interval = 1; - while ( v <= sl->maxValue() + 1 ) { - pos = qPositionFromValue( sl, v, available ) + fudge; - if ( sl->orientation() == Horizontal ) + while ( v <= ceData.maxSteps + 1 ) { + pos = qPositionFromValue( ceData, v, available ) + fudge; + if ( ceData.orientation == Horizontal ) p->drawLine( pos, tickOffset+thickness+1, pos, tickOffset+thickness+1 + available-2 ); else @@ -1881,8 +2346,7 @@ void QCommonStyle::drawComplexControl( ComplexControl control, #ifndef QT_NO_LISTVIEW case CC_ListView: if ( controls & SC_ListView ) { - QListView *listview = (QListView*)widget; - p->fillRect( r, listview->viewport()->backgroundBrush() ); + p->fillRect( r, ceData.viewportData.bgBrush ); } break; #endif //QT_NO_LISTVIEW @@ -1893,7 +2357,6 @@ void QCommonStyle::drawComplexControl( ComplexControl control, activePainter = 0; } - /*! \reimp */ void QCommonStyle::drawComplexControlMask( ComplexControl control, QPainter *p, @@ -1901,14 +2364,28 @@ void QCommonStyle::drawComplexControlMask( ComplexControl control, const QRect &r, const QStyleOption& opt ) const { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + drawComplexControlMask(control, p, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), r, opt, widget); +} + +/*! \reimp */ +void QCommonStyle::drawComplexControlMask( ComplexControl control, + QPainter *p, + const QStyleControlElementData ceData, + const ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& opt, + const QWidget *widget ) const +{ Q_UNUSED(control); + Q_UNUSED(ceData); + Q_UNUSED(elementFlags); Q_UNUSED(widget); Q_UNUSED(opt); p->fillRect(r, color1); } - /*! \reimp */ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, const QWidget *widget, @@ -1916,24 +2393,36 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, const QStyleOption &opt ) const { #if defined(QT_CHECK_STATE) - if (! widget) { - qWarning("QCommonStyle::querySubControlMetrics: widget parameter cannot be zero!"); - return QRect(); - } + if (! widget) { + qWarning("QCommonStyle::querySubControlMetrics: widget parameter cannot be zero!"); + return QRect(); + } #endif + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption(), false); + return querySubControlMetrics(control, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), sc, opt, widget); +} + +/*! \reimp */ +QRect QCommonStyle::querySubControlMetrics( ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + SubControl sc, + const QStyleOption &opt, + const QWidget *widget ) const +{ switch ( control ) { case CC_SpinWidget: { - int fw = pixelMetric( PM_SpinBoxFrameWidth, widget); + int fw = pixelMetric( PM_SpinBoxFrameWidth, ceData, elementFlags, widget); QSize bs; - bs.setHeight( widget->height()/2 - fw ); + bs.setHeight( ceData.rect.height()/2 - fw ); if ( bs.height() < 8 ) bs.setHeight( 8 ); - bs.setWidth( QMIN( bs.height() * 8 / 5, widget->width() / 4 ) ); // 1.6 -approximate golden mean + bs.setWidth( QMIN( bs.height() * 8 / 5, ceData.rect.width() / 4 ) ); // 1.6 -approximate golden mean bs = bs.expandedTo( QApplication::globalStrut() ); int y = fw; int x, lx, rx; - x = widget->width() - y - bs.width(); + x = ceData.rect.width() - y - bs.width(); lx = fw; rx = x - fw; switch ( sc ) { @@ -1942,24 +2431,24 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, case SC_SpinWidgetDown: return QRect(x, y + bs.height(), bs.width(), bs.height()); case SC_SpinWidgetButtonField: - return QRect(x, y, bs.width(), widget->height() - 2*fw); + return QRect(x, y, bs.width(), ceData.rect.height() - 2*fw); case SC_SpinWidgetEditField: - return QRect(lx, fw, rx, widget->height() - 2*fw); + return QRect(lx, fw, rx, ceData.rect.height() - 2*fw); case SC_SpinWidgetFrame: - return widget->rect(); + return ceData.rect; default: break; } break; } case CC_ComboBox: { - int x = 0, y = 0, wi = widget->width(), he = widget->height(); + int x = 0, y = 0, wi = ceData.rect.width(), he = ceData.rect.height(); int xpos = x; xpos += wi - 2 - 16; switch ( sc ) { case SC_ComboBoxFrame: - return widget->rect(); + return ceData.rect; case SC_ComboBoxArrow: return QRect(xpos, y+2, 16, he-4); case SC_ComboBoxEditField: @@ -1973,21 +2462,20 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, #ifndef QT_NO_SCROLLBAR case CC_ScrollBar: { - const QScrollBar *scrollbar = (const QScrollBar *) widget; int sliderstart = 0; - int sbextent = pixelMetric(PM_ScrollBarExtent, widget); - int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ? - scrollbar->width() : scrollbar->height()) - (sbextent * 2); + int sbextent = pixelMetric(PM_ScrollBarExtent, ceData, elementFlags, widget); + int maxlen = ((ceData.orientation == Qt::Horizontal) ? + ceData.rect.width() : ceData.rect.height()) - (sbextent * 2); int sliderlen; - sliderstart = scrollbar->sliderStart(); + sliderstart = ceData.startStep; // calculate slider length - if (scrollbar->maxValue() != scrollbar->minValue()) { - uint range = scrollbar->maxValue() - scrollbar->minValue(); - sliderlen = (Q_LLONG(scrollbar->pageStep()) * maxlen) / (range + scrollbar->pageStep()); + if (ceData.maxSteps != ceData.minSteps) { + uint range = ceData.maxSteps - ceData.minSteps; + sliderlen = (Q_LLONG(ceData.pageStep) * maxlen) / (range + ceData.pageStep); - int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget ); + int slidermin = pixelMetric( PM_ScrollBarSliderMin, ceData, elementFlags, widget ); if ( sliderlen < slidermin || range > INT_MAX / 2 ) sliderlen = slidermin; if ( sliderlen > maxlen ) @@ -1997,44 +2485,44 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, switch (sc) { case SC_ScrollBarSubLine: // top/left button - if (scrollbar->orientation() == Qt::Horizontal) { - int buttonWidth = QMIN(scrollbar->width()/2, sbextent); + if (ceData.orientation == Qt::Horizontal) { + int buttonWidth = QMIN(ceData.rect.width()/2, sbextent); return QRect( 0, 0, buttonWidth, sbextent ); } else { - int buttonHeight = QMIN(scrollbar->height()/2, sbextent); + int buttonHeight = QMIN(ceData.rect.height()/2, sbextent); return QRect( 0, 0, sbextent, buttonHeight ); } case SC_ScrollBarAddLine: // bottom/right button - if (scrollbar->orientation() == Qt::Horizontal) { - int buttonWidth = QMIN(scrollbar->width()/2, sbextent); - return QRect( scrollbar->width() - buttonWidth, 0, buttonWidth, sbextent ); + if (ceData.orientation == Qt::Horizontal) { + int buttonWidth = QMIN(ceData.rect.width()/2, sbextent); + return QRect( ceData.rect.width() - buttonWidth, 0, buttonWidth, sbextent ); } else { - int buttonHeight = QMIN(scrollbar->height()/2, sbextent); - return QRect( 0, scrollbar->height() - buttonHeight, sbextent, buttonHeight ); + int buttonHeight = QMIN(ceData.rect.height()/2, sbextent); + return QRect( 0, ceData.rect.height() - buttonHeight, sbextent, buttonHeight ); } case SC_ScrollBarSubPage: // between top/left button and slider - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(sbextent, 0, sliderstart - sbextent, sbextent); return QRect(0, sbextent, sbextent, sliderstart - sbextent); case SC_ScrollBarAddPage: // between bottom/right button and slider - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(sliderstart + sliderlen, 0, maxlen - sliderstart - sliderlen + sbextent, sbextent); return QRect(0, sliderstart + sliderlen, sbextent, maxlen - sliderstart - sliderlen + sbextent); case SC_ScrollBarGroove: - if (scrollbar->orientation() == Qt::Horizontal) - return QRect(sbextent, 0, scrollbar->width() - sbextent * 2, - scrollbar->height()); - return QRect(0, sbextent, scrollbar->width(), - scrollbar->height() - sbextent * 2); + if (ceData.orientation == Qt::Horizontal) + return QRect(sbextent, 0, ceData.rect.width() - sbextent * 2, + ceData.rect.height()); + return QRect(0, sbextent, ceData.rect.width(), + ceData.rect.height() - sbextent * 2); case SC_ScrollBarSlider: - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(sliderstart, 0, sliderlen, sbextent); return QRect(0, sliderstart, sbextent, sliderlen); @@ -2046,24 +2534,23 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, #ifndef QT_NO_SLIDER case CC_Slider: { - const QSlider * sl = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl ); - int thickness = pixelMetric( PM_SliderControlThickness, sl ); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); switch ( sc ) { case SC_SliderHandle: { int sliderPos = 0; - int len = pixelMetric( PM_SliderLength, sl ); + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); - sliderPos = sl->sliderStart(); + sliderPos = ceData.startStep; - if ( sl->orientation() == Horizontal ) + if ( ceData.orientation == Horizontal ) return QRect( sliderPos, tickOffset, len, thickness ); return QRect( tickOffset, sliderPos, thickness, len ); } case SC_SliderGroove: { - if ( sl->orientation() == Horizontal ) - return QRect( 0, tickOffset, sl->width(), thickness ); - return QRect( tickOffset, 0, thickness, sl->height() ); } + if ( ceData.orientation == Horizontal ) + return QRect( 0, tickOffset, ceData.rect.width(), thickness ); + return QRect( tickOffset, 0, thickness, ceData.rect.height() ); } default: break; @@ -2073,18 +2560,17 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, #if !defined(QT_NO_TOOLBUTTON) && !defined(QT_NO_POPUPMENU) case CC_ToolButton: { - const QToolButton *toolbutton = (const QToolButton *) widget; - int mbi = pixelMetric(PM_MenuButtonIndicator, widget); + int mbi = pixelMetric(PM_MenuButtonIndicator, ceData, elementFlags, widget); - QRect rect = toolbutton->rect(); + QRect rect = ceData.rect; switch (sc) { case SC_ToolButton: - if (toolbutton->popup() && ! toolbutton->popupDelay()) + if ((elementFlags & CEF_HasPopupMenu) && ! ceData.popupDelay) rect.addCoords(0, 0, -mbi, 0); return rect; case SC_ToolButtonMenu: - if (toolbutton->popup() && ! toolbutton->popupDelay()) + if ((elementFlags & CEF_HasPopupMenu) && ! ceData.popupDelay) rect.addCoords(rect.width() - mbi, 0, 0, 0); return rect; @@ -2096,47 +2582,45 @@ QRect QCommonStyle::querySubControlMetrics( ComplexControl control, #ifndef QT_NO_TITLEBAR case CC_TitleBar: { - const QTitleBar *titlebar = (const QTitleBar *) widget; const int controlTop = 2; - const int controlHeight = widget->height() - controlTop * 2; + const int controlHeight = ceData.rect.height() - controlTop * 2; switch (sc) { case SC_TitleBarLabel: { - const QTitleBar *titlebar = (QTitleBar*)widget; - QRect ir( 0, 0, titlebar->width(), titlebar->height() ); - if ( titlebar->testWFlags( WStyle_Tool ) ) { - if ( titlebar->testWFlags( WStyle_SysMenu ) ) + QRect ir( 0, 0, ceData.rect.width(), ceData.rect.height() ); + if ( ceData.wflags & WStyle_Tool ) { + if ( ceData.wflags & WStyle_SysMenu ) ir.addCoords( 0, 0, -controlHeight-3, 0 ); - if ( titlebar->testWFlags( WStyle_MinMax ) ) + if ( ceData.wflags & WStyle_MinMax ) ir.addCoords( 0, 0, -controlHeight-2, 0 ); } else { - if ( titlebar->testWFlags( WStyle_SysMenu ) ) + if ( ceData.wflags & WStyle_SysMenu ) ir.addCoords( controlHeight+3, 0, -controlHeight-3, 0 ); - if ( titlebar->testWFlags( WStyle_Minimize ) ) + if ( ceData.wflags & WStyle_Minimize ) ir.addCoords( 0, 0, -controlHeight-2, 0 ); - if ( titlebar->testWFlags( WStyle_Maximize ) ) + if ( ceData.wflags & WStyle_Maximize ) ir.addCoords( 0, 0, -controlHeight-2, 0 ); } return ir; } case SC_TitleBarCloseButton: - return QRect( titlebar->width() - ( controlHeight + controlTop ), + return QRect( ceData.rect.width() - ( controlHeight + controlTop ), controlTop, controlHeight, controlHeight ); case SC_TitleBarMaxButton: case SC_TitleBarShadeButton: case SC_TitleBarUnshadeButton: - return QRect( titlebar->width() - ( ( controlHeight + controlTop ) * 2 ), + return QRect( ceData.rect.width() - ( ( controlHeight + controlTop ) * 2 ), controlTop, controlHeight, controlHeight ); case SC_TitleBarMinButton: case SC_TitleBarNormalButton: { int offset = controlHeight + controlTop; - if ( !titlebar->testWFlags( WStyle_Maximize ) ) + if ( !( ceData.wflags & WStyle_Maximize ) ) offset *= 2; else offset *= 3; - return QRect( titlebar->width() - offset, controlTop, controlHeight, controlHeight ); + return QRect( ceData.rect.width() - offset, controlTop, controlHeight, controlHeight ); } case SC_TitleBarSysMenu: @@ -2160,6 +2644,18 @@ QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control, const QPoint &pos, const QStyleOption& opt ) const { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, opt); + return querySubControl(control, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, opt), pos, opt, widget); +} + +/*! \reimp */ +QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QPoint &pos, + const QStyleOption& opt, + const QWidget *widget ) const +{ SubControl ret = SC_None; switch (control) { @@ -2180,8 +2676,8 @@ QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control, // we can do this because subcontrols were designed to be masks as well... while (ret == SC_None && ctrl <= SC_ScrollBarGroove) { - r = querySubControlMetrics(control, widget, - (QStyle::SubControl) ctrl, opt); + r = querySubControlMetrics(control, ceData, elementFlags, + (QStyle::SubControl) ctrl, opt, widget); if (r.isValid() && r.contains(pos)) ret = (QStyle::SubControl) ctrl; @@ -2194,27 +2690,26 @@ QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control, case CC_TitleBar: { #ifndef QT_NO_TITLEBAR - const QTitleBar *titlebar = (QTitleBar*)widget; QRect r; uint ctrl = SC_TitleBarLabel; // we can do this because subcontrols were designed to be masks as well... while (ret == SC_None && ctrl <= SC_TitleBarUnshadeButton) { - r = visualRect( querySubControlMetrics( control, widget, (QStyle::SubControl) ctrl, opt ), widget ); + r = visualRect( querySubControlMetrics( control, ceData, elementFlags, (QStyle::SubControl) ctrl, opt, widget ), ceData, elementFlags ); if (r.isValid() && r.contains(pos)) ret = (QStyle::SubControl) ctrl; ctrl <<= 1; } - if ( titlebar->window() ) { - if (titlebar->testWFlags( WStyle_Tool )) { + if ( ceData.titleBarData.hasWindow ) { + if ( ceData.wflags & WStyle_Tool ) { if ( ret == SC_TitleBarMinButton || ret == SC_TitleBarMaxButton ) { - if ( titlebar->window()->isMinimized() ) + if ( ceData.titleBarData.windowState & WindowMinimized ) ret = SC_TitleBarUnshadeButton; else ret = SC_TitleBarShadeButton; } - } else if ( ret == SC_TitleBarMinButton && titlebar->window()->isMinimized() ) { + } else if ( ret == SC_TitleBarMinButton && (ceData.titleBarData.windowState & WindowMinimized) ) { ret = QStyle::SC_TitleBarNormalButton; } } @@ -2233,6 +2728,13 @@ QStyle::SubControl QCommonStyle::querySubControl(ComplexControl control, /*! \reimp */ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const { + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + return pixelMetric(m, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), widget); +} + +/*! \reimp */ +int QCommonStyle::pixelMetric(PixelMetric m, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const +{ int ret; switch (m) { @@ -2250,20 +2752,17 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const ret = 16; break; case PM_TitleBarHeight: { - if ( widget ) { - if ( widget->testWFlags( WStyle_Tool ) ) { - ret = QMAX( widget->fontMetrics().lineSpacing(), 16 ); + if ( !(elementFlags & CEF_UseGenericParameters) ) { + if ( ceData.wflags & WStyle_Tool ) { + ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 16 ); #ifndef QT_NO_MAINWINDOW - } else if ( ::qt_cast<QDockWindow*>(widget) ) { - ret = QMAX( widget->fontMetrics().lineSpacing(), 13 ); + } else if ( ceData.widgetObjectTypes.contains("QDockWindow") ) { + ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 13 ); #endif } else { - ret = QMAX( widget->fontMetrics().lineSpacing(), 18 ); + ret = QMAX( QFontMetrics(ceData.font).lineSpacing(), 18 ); } - } else { - ret = 0; } - break; } case PM_ScrollBarSliderMin: ret = 9; @@ -2278,10 +2777,10 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const break; case PM_MenuButtonIndicator: - if (! widget) + if ( elementFlags & CEF_UseGenericParameters ) ret = 12; else - ret = QMAX(12, (widget->height() - 4) / 3); + ret = QMAX(12, (ceData.rect.height() - 4) / 3); break; case PM_ButtonShiftHorizontal: @@ -2304,11 +2803,10 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const #ifndef QT_NO_SCROLLBAR case PM_ScrollBarExtent: - if ( !widget ) { + if ( elementFlags & CEF_UseGenericParameters ) { ret = 16; } else { - const QScrollBar *bar = (const QScrollBar*)widget; - int s = bar->orientation() == Qt::Horizontal ? + int s = ceData.orientation == Qt::Horizontal ? QApplication::globalStrut().height() : QApplication::globalStrut().width(); ret = QMAX( 16, s ); @@ -2326,16 +2824,15 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const case PM_SliderTickmarkOffset: { - if (! widget) { + if ( elementFlags & CEF_UseGenericParameters ) { ret = 0; break; } - const QSlider * sl = (const QSlider *) widget; - int space = (sl->orientation() == Horizontal) ? sl->height() : - sl->width(); - int thickness = pixelMetric( PM_SliderControlThickness, sl ); - int ticks = sl->tickmarks(); + int space = (ceData.orientation == Horizontal) ? ceData.rect.height() : + ceData.rect.width(); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int ticks = ceData.tickMarkSetting; if ( ticks == QSlider::Both ) ret = (space - thickness) / 2; @@ -2348,11 +2845,10 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const case PM_SliderSpaceAvailable: { - const QSlider * sl = (const QSlider *) widget; - if ( sl->orientation() == Horizontal ) - ret = sl->width() - pixelMetric( PM_SliderLength, sl ); + if ( ceData.orientation == Horizontal ) + ret = ceData.rect.width() - pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); else - ret = sl->height() - pixelMetric( PM_SliderLength, sl ); + ret = ceData.rect.height() - pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); break; } #endif // QT_NO_SLIDER @@ -2402,9 +2898,8 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const #ifndef QT_NO_TABBAR case PM_TabBarTabVSpace: { - const QTabBar * tb = (const QTabBar *) widget; - if ( tb && ( tb->shape() == QTabBar::RoundedAbove || - tb->shape() == QTabBar::RoundedBelow ) ) + if ( ceData.widgetObjectTypes.contains("QTabBar") && ( ceData.tabBarData.shape == QTabBar::RoundedAbove || + ceData.tabBarData.shape == QTabBar::RoundedBelow ) ) ret = 10; else ret = 0; @@ -2457,31 +2952,43 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QWidget *widget) const return ret; } - /*! \reimp */ QSize QCommonStyle::sizeFromContents(ContentsType contents, const QWidget *widget, const QSize &contentsSize, const QStyleOption& opt ) const { - QSize sz(contentsSize); + QSize sz(contentsSize); #if defined(QT_CHECK_STATE) - if (! widget) { - qWarning("QCommonStyle::sizeFromContents: widget parameter cannot be zero!"); - return sz; - } + if (! widget) { + qWarning("QCommonStyle::sizeFromContents: widget parameter cannot be zero!"); + return sz; + } #endif + QStyleControlElementData ceData = populateControlElementDataFromWidget(widget, QStyleOption()); + return sizeFromContents(contents, ceData, getControlElementFlagsForObject(widget, ceData.widgetObjectTypes, QStyleOption()), contentsSize, opt, widget); +} + +/*! \reimp */ +QSize QCommonStyle::sizeFromContents(ContentsType contents, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QSize &contentsSize, + const QStyleOption& opt, + const QWidget *widget ) const +{ + QSize sz(contentsSize); + switch (contents) { #ifndef QT_NO_DIALOGBUTTONS case CT_DialogButtons: { - const QDialogButtons *dbtns = (const QDialogButtons *)widget; int w = contentsSize.width(), h = contentsSize.height(); - const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, widget), - bspace = pixelMetric(PM_DialogButtonsSeparator, widget), - bheight = pixelMetric(PM_DialogButtonsButtonHeight, widget); - if(dbtns->orientation() == Horizontal) { + const int bwidth = pixelMetric(PM_DialogButtonsButtonWidth, ceData, elementFlags, widget), + bspace = pixelMetric(PM_DialogButtonsSeparator, ceData, elementFlags, widget), + bheight = pixelMetric(PM_DialogButtonsButtonHeight, ceData, elementFlags, widget); + if(ceData.orientation == Horizontal) { if(!w) w = bwidth; } else { @@ -2492,10 +2999,10 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, QDialogButtons::Apply, QDialogButtons::Retry, QDialogButtons::Ignore, QDialogButtons::Abort, QDialogButtons::Help }; for(unsigned int i = 0, cnt = 0; i < (sizeof(btns)/sizeof(btns[0])); i++) { - if(dbtns->isButtonVisible(btns[i])) { - QSize szH = dbtns->sizeHint(btns[i]); + if (ceData.dlgVisibleButtons & btns[i]) { + QSize szH = ceData.dlgVisibleSizeHints[btns[i]]; int mwidth = QMAX(bwidth, szH.width()), mheight = QMAX(bheight, szH.height()); - if(dbtns->orientation() == Horizontal) + if(ceData.orientation == Horizontal) h = QMAX(h, mheight); else w = QMAX(w, mwidth); @@ -2503,30 +3010,29 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, if(cnt) w += bspace; cnt++; - if(dbtns->orientation() == Horizontal) + if(ceData.orientation == Horizontal) w += mwidth; else h += mheight; } } - const int fw = pixelMetric(PM_DefaultFrameWidth, widget) * 2; + const int fw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget) * 2; sz = QSize(w + fw, h + fw); break; } #endif //QT_NO_DIALOGBUTTONS case CT_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; int w = contentsSize.width(), h = contentsSize.height(), - bm = pixelMetric(PM_ButtonMargin, widget), - fw = pixelMetric(PM_DefaultFrameWidth, widget) * 2; + bm = pixelMetric(PM_ButtonMargin, ceData, elementFlags, widget), + fw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget) * 2; w += bm + fw; h += bm + fw; - if (button->isDefault() || button->autoDefault()) { - int dbw = pixelMetric(PM_ButtonDefaultIndicator, widget) * 2; + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) { + int dbw = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget) * 2; w += dbw; h += dbw; } @@ -2539,10 +3045,9 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, case CT_CheckBox: { #ifndef QT_NO_CHECKBOX - const QCheckBox *checkbox = (const QCheckBox *) widget; - QRect irect = subRect(SR_CheckBoxIndicator, widget); - int h = pixelMetric( PM_IndicatorHeight, widget ); - int margins = (!checkbox->pixmap() && checkbox->text().isEmpty()) ? 0 : 10; + QRect irect = subRect(SR_CheckBoxIndicator, ceData, elementFlags, widget); + int h = pixelMetric( PM_IndicatorHeight, ceData, elementFlags, widget ); + int margins = (ceData.fgPixmap.isNull() && ceData.text.isEmpty()) ? 0 : 10; sz += QSize(irect.right() + margins, 4 ); sz.setHeight( QMAX( sz.height(), h ) ); #endif @@ -2552,10 +3057,9 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, case CT_RadioButton: { #ifndef QT_NO_RADIOBUTTON - const QRadioButton *radiobutton = (const QRadioButton *) widget; - QRect irect = subRect(SR_RadioButtonIndicator, widget); - int h = pixelMetric( PM_ExclusiveIndicatorHeight, widget ); - int margins = (!radiobutton->pixmap() && radiobutton->text().isEmpty()) ? 0 : 10; + QRect irect = subRect(SR_RadioButtonIndicator, ceData, elementFlags, widget); + int h = pixelMetric( PM_ExclusiveIndicatorHeight, ceData, elementFlags, widget ); + int margins = (ceData.fgPixmap.isNull() && ceData.text.isEmpty()) ? 0 : 10; sz += QSize(irect.right() + margins, 4 ); sz.setHeight( QMAX( sz.height(), h ) ); #endif @@ -2570,7 +3074,7 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, case CT_ComboBox: { - int dfw = pixelMetric(PM_DefaultFrameWidth, widget) * 2; + int dfw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget) * 2; sz = QSize(sz.width() + dfw + 21, sz.height() + dfw ); break; } @@ -2581,8 +3085,7 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, if (opt.isDefault()) break; - const QPopupMenu *popup = (const QPopupMenu *) widget; - bool checkable = popup->isCheckable(); + bool checkable = (elementFlags & CEF_IsCheckable); QMenuItem *mi = opt.menuItem(); int maxpmw = opt.maxIconWidth(); int w = sz.width(), h = sz.height(); @@ -2600,7 +3103,7 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, if (mi->pixmap()) h = QMAX(h, mi->pixmap()->height() + 4); else - h = QMAX(h, popup->fontMetrics().height() + 8); + h = QMAX(h, QFontMetrics(ceData.font).height() + 8); if (mi->iconSet() != 0) h = QMAX(h, mi->iconSet()->pixmap(QIconSet::Small, @@ -2639,10 +3142,18 @@ QSize QCommonStyle::sizeFromContents(ContentsType contents, return sz; } +/*! \reimp */ +int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption &so, QStyleHintReturn *shr) const +{ + QStyleControlElementData ceData = populateControlElementDataFromWidget(w, QStyleOption(), false); + return styleHint(sh, ceData, getControlElementFlagsForObject(w, ceData.widgetObjectTypes, QStyleOption(), false), so, shr, w); +} /*! \reimp */ -int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption &, QStyleHintReturn *) const +int QCommonStyle::styleHint(StyleHint sh, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption &, QStyleHintReturn *, const QWidget * w) const { + Q_UNUSED(w); + int ret; switch (sh) { @@ -2656,7 +3167,7 @@ int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption break; case SH_GroupBox_TextLabelColor: - ret = (int) ( w ? w->paletteForegroundColor().rgb() : 0 ); + ret = (int) ( (!(elementFlags & CEF_UseGenericParameters)) ? ceData.fgColor.rgb() : 0 ); break; case SH_ListViewExpand_SelectMouseType: @@ -2709,6 +3220,10 @@ int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption ret = 1; break; + case SH_HideUnderlineAcceleratorWhenAltUp: + ret = 0; + break; + default: ret = 0; break; @@ -2718,10 +3233,16 @@ int QCommonStyle::styleHint(StyleHint sh, const QWidget * w, const QStyleOption } /*! \reimp */ -QPixmap QCommonStyle::stylePixmap(StylePixmap, const QWidget *, const QStyleOption&) const +QPixmap QCommonStyle::stylePixmap(StylePixmap sp, const QWidget *w, const QStyleOption &so) const { - return QPixmap(); + QStyleControlElementData ceData = populateControlElementDataFromWidget(w, QStyleOption()); + return stylePixmap(sp, ceData, getControlElementFlagsForObject(w, ceData.widgetObjectTypes, QStyleOption()), so, w); } +/*! \reimp */ +QPixmap QCommonStyle::stylePixmap(StylePixmap, QStyleControlElementData, ControlElementFlags, const QStyleOption&, const QWidget *) const +{ + return QPixmap(); +} #endif // QT_NO_STYLE diff --git a/src/styles/qcommonstyle.h b/src/styles/qcommonstyle.h index 3bed7b0..e6378e6 100644 --- a/src/styles/qcommonstyle.h +++ b/src/styles/qcommonstyle.h @@ -55,6 +55,8 @@ public: QCommonStyle(); ~QCommonStyle(); + // Old API + // DEPRECATED void drawPrimitive( PrimitiveElement pe, QPainter *p, const QRect &r, @@ -62,22 +64,63 @@ public: SFlags flags = Style_Default, const QStyleOption& = QStyleOption::Default ) const; + // New API + 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; + + // Old API + // DEPRECATED void drawControl( ControlElement element, - QPainter *p, - const QWidget *widget, - const QRect &r, - const QColorGroup &cg, - SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + QPainter *p, + const QWidget *widget, + const QRect &r, + const QColorGroup &cg, + SFlags how = Style_Default, + const QStyleOption& = QStyleOption::Default ) const; + // New API + 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 *widget = 0 ) const; + + // Old API + // DEPRECATED void drawControlMask( ControlElement element, - QPainter *p, - const QWidget *widget, - const QRect &r, - const QStyleOption& = QStyleOption::Default ) const; + QPainter *p, + const QWidget *widget, + const QRect &r, + const QStyleOption& = QStyleOption::Default ) const; + // New API + void drawControlMask( ControlElement element, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED QRect subRect( SubRect r, const QWidget *widget ) const; + // New API + QRect subRect( SubRect r, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget ) const; + + // Old API + // DEPRECATED void drawComplexControl( ComplexControl control, QPainter *p, const QWidget *widget, @@ -92,35 +135,111 @@ public: SCFlags subActive = SC_None, const QStyleOption& = QStyleOption::Default ) const; + // New API + void drawComplexControl( ComplexControl control, + QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QRect &r, + const QColorGroup &cg, + SFlags how = Style_Default, +#ifdef Q_QDOC + SCFlags sub = SC_All, +#else + SCFlags sub = (uint)SC_All, +#endif + SCFlags subActive = SC_None, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED void drawComplexControlMask( ComplexControl control, QPainter *p, const QWidget *widget, const QRect &r, const QStyleOption& = QStyleOption::Default ) const; + // New API + void drawComplexControlMask( ComplexControl control, + QPainter *p, + const QStyleControlElementData ceData, + const ControlElementFlags elementFlags, + const QRect &r, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED QRect querySubControlMetrics( ComplexControl control, const QWidget *widget, SubControl sc, const QStyleOption& = QStyleOption::Default ) const; + // New API + QRect querySubControlMetrics( ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + SubControl sc, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED SubControl querySubControl( ComplexControl control, const QWidget *widget, const QPoint &pos, const QStyleOption& = QStyleOption::Default ) const; + // New API + SubControl querySubControl( ComplexControl control, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QPoint &pos, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED int pixelMetric( PixelMetric m, const QWidget *widget = 0 ) const; + // New API + int pixelMetric( PixelMetric m, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED QSize sizeFromContents( ContentsType s, const QWidget *widget, const QSize &contentsSize, const QStyleOption& = QStyleOption::Default ) const; + // New API + QSize sizeFromContents( ContentsType s, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QSize &contentsSize, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; + + // Old API + // DEPRECATED int styleHint(StyleHint sh, const QWidget *, const QStyleOption &, QStyleHintReturn *) const; + // New API + int styleHint(StyleHint sh, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption &, QStyleHintReturn *, const QWidget * w) const; + + // Old API + // DEPRECATED QPixmap stylePixmap( StylePixmap sp, const QWidget *widget = 0, const QStyleOption& = QStyleOption::Default ) const; + // New API + QPixmap stylePixmap( StylePixmap sp, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; private: // Disabled copy constructor and operator= @@ -130,8 +249,6 @@ private: #endif }; - - #endif // QT_NO_STYLE #endif // QCOMMONSTYLE_H diff --git a/src/styles/qcompactstyle.cpp b/src/styles/qcompactstyle.cpp index 46b4df3..7c8d93b 100644 --- a/src/styles/qcompactstyle.cpp +++ b/src/styles/qcompactstyle.cpp @@ -55,7 +55,7 @@ QCompactStyle::QCompactStyle() } /*! \reimp */ -int QCompactStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) +int QCompactStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) { int ret; switch ( metric ) { @@ -68,7 +68,7 @@ int QCompactStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) ret = -1; break; default: - ret = QWindowsStyle::pixelMetric( metric, widget ); + ret = QWindowsStyle::pixelMetric( metric, ceData, elementFlags, widget ); break; } return ret; @@ -143,16 +143,15 @@ void drawPopupMenuItem( QPainter* p, bool checkable, } /*! \reimp */ -void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r, - const QColorGroup &g, SFlags flags, const QStyleOption& opt ) +void QCompactStyle::drawControl( ControlElement element, QPainter *p, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QRect &r, + const QColorGroup &g, SFlags flags, const QStyleOption& opt, const QWidget *widget ) { switch ( element ) { case CE_PopupMenuItem: { - if (! widget || opt.isDefault()) + if (! (elementFlags & CEF_HasWidget) || opt.isDefault()) break; - const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; @@ -160,7 +159,7 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWid int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = !(flags & Style_Enabled); - bool checkable = popupmenu->isCheckable(); + bool checkable = (elementFlags & CEF_IsCheckable); bool act = flags & Style_Active; int x, y, w, h; r.rect( &x, &y, &w, &h ); @@ -313,7 +312,7 @@ void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWid break; default: - QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt ); + QWindowsStyle::drawControl( element, p, ceData, elementFlags, r, g, flags, opt, widget ); break; } } diff --git a/src/styles/qcompactstyle.h b/src/styles/qcompactstyle.h index ea27cb4..2f9748b 100644 --- a/src/styles/qcompactstyle.h +++ b/src/styles/qcompactstyle.h @@ -58,10 +58,10 @@ class Q_EXPORT_STYLE_COMPACT QCompactStyle : public QWindowsStyle public: QCompactStyle(); - int pixelMetric( PixelMetric metric, const QWidget *widget = 0 ); + int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ); - void drawControl( ControlElement element, QPainter *p, const QWidget *w, const QRect &r, - const QColorGroup &cg, SFlags how = Style_Default, const QStyleOption& = QStyleOption::Default ); + 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 ); private: // Disabled copy constructor and operator= #if defined(Q_DISABLE_COPY) diff --git a/src/styles/qmotifplusstyle.cpp b/src/styles/qmotifplusstyle.cpp index 6cf56f3..86a2558 100644 --- a/src/styles/qmotifplusstyle.cpp +++ b/src/styles/qmotifplusstyle.cpp @@ -69,7 +69,9 @@ struct QMotifPlusStylePrivate scrollbarElement(0), lastElement(0), ref(1) { ; } - QGuardedPtr<QWidget> hoverWidget; + void* hoverWidget; + QStyleControlElementData hoverWidgetData; + QStyle::ControlElementFlags hoverWidgetFlags; bool hovering, sliderActive, mousePressed; int scrollbarElement, lastElement, ref; QPoint mousePos; @@ -176,58 +178,64 @@ void QMotifPlusStyle::polish(QPalette &) /*! \reimp */ -void QMotifPlusStyle::polish(QWidget *widget) +void QMotifPlusStyle::polish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr) { + if (ceData.widgetObjectTypes.contains("QWidget")) { #ifndef QT_NO_FRAME - if (::qt_cast<QFrame*>(widget) && ((QFrame *) widget)->frameStyle() == QFrame::Panel) - ((QFrame *) widget)->setFrameStyle(QFrame::WinPanel); + if ((ceData.widgetObjectTypes.contains("QFrame")) && (ceData.frameStyle == QFrame::Panel)) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetStyle, QStyleWidgetActionRequestData(QFrame::WinPanel)); + } #endif #ifndef QT_NO_MENUBAR - if (::qt_cast<QMenuBar*>(widget) && ((QMenuBar *) widget)->frameStyle() != QFrame::NoFrame) - ((QMenuBar *) widget)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); + if ((ceData.widgetObjectTypes.contains("QMenuBar")) && (ceData.frameStyle != QFrame::NoFrame)) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetStyle, QStyleWidgetActionRequestData(QFrame::StyledPanel | QFrame::Raised)); + } #endif #ifndef QT_NO_TOOLBAR - if (::qt_cast<QToolBar*>(widget)) - widget->layout()->setMargin(2); + if (ceData.widgetObjectTypes.contains("QToolBar")) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetLayoutMargin, QStyleWidgetActionRequestData(2)); + } #endif + } if (useHoveringHighlight) { - if (::qt_cast<QButton*>(widget) || ::qt_cast<QComboBox*>(widget)) - widget->installEventFilter(this); + if ((ceData.widgetObjectTypes.contains("QButton")) || (ceData.widgetObjectTypes.contains("QComboBox"))) { + installObjectEventHandler(ceData, elementFlags, ptr, this); + } - if (::qt_cast<QScrollBar*>(widget) || ::qt_cast<QSlider*>(widget)) { - widget->setMouseTracking(TRUE); - widget->installEventFilter(this); + if ((ceData.widgetObjectTypes.contains("QScrollBar")) || (ceData.widgetObjectTypes.contains("QSlider"))) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_EnableMouseTracking); + installObjectEventHandler(ceData, elementFlags, ptr, this); } } - QMotifStyle::polish(widget); + QMotifStyle::polish(ceData, elementFlags, ptr); } /*! \reimp */ -void QMotifPlusStyle::unPolish(QWidget *widget) +void QMotifPlusStyle::unPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr) { - widget->removeEventFilter(this); - QMotifStyle::unPolish(widget); + removeObjectEventHandler(ceData, elementFlags, ptr, this); + QMotifStyle::unPolish(ceData, elementFlags, ptr); } /*! \reimp */ -void QMotifPlusStyle::polish(QApplication *) +void QMotifPlusStyle::applicationPolish(QStyleControlElementData, ControlElementFlags, void *) { } /*! \reimp */ -void QMotifPlusStyle::unPolish(QApplication *) +void QMotifPlusStyle::applicationUnPolish(QStyleControlElementData, ControlElementFlags, void *) { } /*! \reimp */ -int QMotifPlusStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const +int QMotifPlusStyle::pixelMetric(PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const { int ret; @@ -259,7 +267,7 @@ int QMotifPlusStyle::pixelMetric(PixelMetric metric, const QWidget *widget) cons break; default: - ret = QMotifStyle::pixelMetric(metric, widget); + ret = QMotifStyle::pixelMetric(metric, ceData, elementFlags, widget); break; } @@ -270,6 +278,8 @@ int QMotifPlusStyle::pixelMetric(PixelMetric metric, const QWidget *widget) cons /*! \reimp */ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -303,11 +313,11 @@ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, break; case PE_SpinWidgetUp: - drawPrimitive(PE_ArrowUp, p, r, cg, flags, opt); + drawPrimitive(PE_ArrowUp, p, ceData, elementFlags, r, cg, flags, opt); break; case PE_SpinWidgetDown: - drawPrimitive(PE_ArrowDown, p, r, cg, flags, opt); + drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, r, cg, flags, opt); break; case PE_Indicator: @@ -632,7 +642,7 @@ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, } default: - QMotifStyle::drawPrimitive(pe, p, r, cg, flags, opt); + QMotifStyle::drawPrimitive(pe, p, ceData, elementFlags, r, cg, flags, opt); break; } } @@ -642,11 +652,13 @@ void QMotifPlusStyle::drawPrimitive( PrimitiveElement pe, */ void QMotifPlusStyle::drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget) const { if (widget == singleton->hoverWidget) flags |= Style_MouseOver; @@ -655,12 +667,11 @@ void QMotifPlusStyle::drawControl( ControlElement element, case CE_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; QRect br = r; - int dbi = pixelMetric(PM_ButtonDefaultIndicator, widget); + int dbi = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget); - if (button->isDefault() || button->autoDefault()) { - if (button->isDefault()) + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) { + if (elementFlags & CEF_IsDefault) drawMotifPlusShade(p, br, cg, TRUE, FALSE, &cg.brush(QColorGroup::Background)); @@ -673,9 +684,9 @@ void QMotifPlusStyle::drawControl( ControlElement element, if (flags & Style_HasFocus) br.addCoords(1, 1, -1, -1); p->save(); - p->setBrushOrigin( -button->backgroundOffset().x(), - -button->backgroundOffset().y() ); - drawPrimitive(PE_ButtonCommand, p, br, cg, flags); + p->setBrushOrigin( -ceData.bgOffset.x(), + -ceData.bgOffset.y() ); + drawPrimitive(PE_ButtonCommand, p, ceData, elementFlags, br, cg, flags); p->restore(); #endif break; @@ -684,23 +695,21 @@ void QMotifPlusStyle::drawControl( ControlElement element, case CE_CheckBoxLabel: { #ifndef QT_NO_CHECKBOX - const QCheckBox *checkbox = (const QCheckBox *) widget; - if (flags & Style_MouseOver) { - QRegion r(checkbox->rect()); - r -= visualRect(subRect(SR_CheckBoxIndicator, widget), widget); + QRegion r(ceData.rect); + r -= visualRect(subRect(SR_CheckBoxIndicator, ceData, elementFlags, widget), ceData, elementFlags); p->setClipRegion(r); - p->fillRect(checkbox->rect(), cg.brush(QColorGroup::Midlight)); + p->fillRect(ceData.rect, cg.brush(QColorGroup::Midlight)); p->setClipping(FALSE); } int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft; drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg, - flags & Style_Enabled, checkbox->pixmap(), checkbox->text()); + flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text); - if (checkbox->hasFocus()) { - QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, widget), widget); - drawPrimitive(PE_FocusRect, p, fr, cg, flags); + if (elementFlags & CEF_HasFocus) { + QRect fr = visualRect(subRect(SR_CheckBoxFocusRect, ceData, elementFlags, widget), ceData, elementFlags); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags); } #endif break; @@ -709,23 +718,21 @@ void QMotifPlusStyle::drawControl( ControlElement element, case CE_RadioButtonLabel: { #ifndef QT_NO_RADIOBUTTON - const QRadioButton *radiobutton = (const QRadioButton *) widget; - if (flags & Style_MouseOver) { - QRegion r(radiobutton->rect()); - r -= visualRect(subRect(SR_RadioButtonIndicator, widget), widget); + QRegion r(ceData.rect); + r -= visualRect(subRect(SR_RadioButtonIndicator, ceData, elementFlags, widget), ceData, elementFlags); p->setClipRegion(r); - p->fillRect(radiobutton->rect(), cg.brush(QColorGroup::Midlight)); + p->fillRect(ceData.rect, cg.brush(QColorGroup::Midlight)); p->setClipping(FALSE); } int alignment = QApplication::reverseLayout() ? AlignRight : AlignLeft; drawItem(p, r, alignment | AlignVCenter | ShowPrefix, cg, - flags & Style_Enabled, radiobutton->pixmap(), radiobutton->text()); + flags & Style_Enabled, (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text); - if (radiobutton->hasFocus()) { - QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, widget), widget); - drawPrimitive(PE_FocusRect, p, fr, cg, flags); + if (elementFlags & CEF_HasFocus) { + QRect fr = visualRect(subRect(SR_RadioButtonFocusRect, ceData, elementFlags, widget), ceData, elementFlags); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags); } #endif break; @@ -757,7 +764,6 @@ void QMotifPlusStyle::drawControl( ControlElement element, if (! widget || opt.isDefault()) break; - QPopupMenu *popupmenu = (QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; @@ -765,7 +771,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = ! (flags & Style_Enabled); - bool checkable = popupmenu->isCheckable(); + bool checkable = (elementFlags & CEF_IsCheckable); bool act = flags & Style_Active; int x, y, w, h; @@ -834,7 +840,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, if (act) cflags |= Style_On; - drawPrimitive(PE_CheckMark, p, vrect, cg, cflags); + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, vrect, cg, cflags); } } @@ -883,6 +889,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, QStyle::PrimitiveElement arrow = (QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight); vrect = visualRect( QRect(x + w - hh - 6, y + (hh / 2), hh, hh), r ); drawPrimitive(arrow, p, + ceData, elementFlags, vrect, cg, ((act && !dis) ? Style_Down : Style_Default) | @@ -895,16 +902,15 @@ void QMotifPlusStyle::drawControl( ControlElement element, case CE_TabBarTab: { #ifndef QT_NO_TABBAR - const QTabBar *tabbar = (const QTabBar *) widget; bool selected = flags & Style_Selected; - QColorGroup g = tabbar->colorGroup(); + QColorGroup g = ceData.colorGroup; QPen oldpen = p->pen(); QRect fr(r); if (! selected) { - if (tabbar->shape() == QTabBar::RoundedAbove || - tabbar->shape() == QTabBar::TriangularAbove) { + if (ceData.tabBarData.shape == QTabBar::RoundedAbove || + ceData.tabBarData.shape == QTabBar::TriangularAbove) { fr.setTop(fr.top() + 2); } else { fr.setBottom(fr.bottom() - 2); @@ -917,7 +923,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, (selected) ? cg.brush(QColorGroup::Button) : cg.brush(QColorGroup::Mid)); - if (tabbar->shape() == QTabBar::RoundedAbove) { + if (ceData.tabBarData.shape == QTabBar::RoundedAbove) { // "rounded" tabs on top fr.setBottom(fr.bottom() - 1); @@ -941,7 +947,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, p->setPen(black); p->drawLine(fr.right(), fr.top() + 1, fr.right(), fr.bottom() - 1); - } else if (tabbar->shape() == QTabBar::RoundedBelow) { + } else if (ceData.tabBarData.shape == QTabBar::RoundedBelow) { // "rounded" tabs on bottom fr.setTop(fr.top() + 1); @@ -987,7 +993,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, } } else // triangular drawing code - QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt); + QMotifStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget); p->setPen(oldpen); #endif @@ -995,7 +1001,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, } default: - QMotifStyle::drawControl(element, p, widget, r, cg, flags, opt); + QMotifStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget); break; } } @@ -1003,7 +1009,7 @@ void QMotifPlusStyle::drawControl( ControlElement element, /*! \reimp */ -QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const +QRect QMotifPlusStyle::subRect(SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const { QRect rect; @@ -1011,11 +1017,10 @@ QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const case SR_PushButtonFocusRect: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; - int dfi = pixelMetric(PM_ButtonDefaultIndicator, widget); + int dfi = pixelMetric(PM_ButtonDefaultIndicator, ceData, elementFlags, widget); - rect = button->rect(); - if (button->isDefault() || button->autoDefault()) + rect = ceData.rect; + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) rect.addCoords(dfi, dfi, -dfi, -dfi); #endif break; @@ -1023,38 +1028,36 @@ QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const case SR_CheckBoxIndicator: { - int h = pixelMetric( PM_IndicatorHeight ); - rect.setRect(( widget->rect().height() - h ) / 2, - ( widget->rect().height() - h ) / 2, - pixelMetric( PM_IndicatorWidth ), h ); + int h = pixelMetric( PM_IndicatorHeight, ceData, elementFlags ); + rect.setRect(( ceData.rect.height() - h ) / 2, + ( ceData.rect.height() - h ) / 2, + pixelMetric( PM_IndicatorWidth, ceData, elementFlags ), h ); break; } case SR_RadioButtonIndicator: { - int h = pixelMetric( PM_ExclusiveIndicatorHeight ); - rect.setRect( ( widget->rect().height() - h ) / 2, - ( widget->rect().height() - h ) / 2, - pixelMetric( PM_ExclusiveIndicatorWidth ), h ); + int h = pixelMetric( PM_ExclusiveIndicatorHeight, ceData, elementFlags ); + rect.setRect( ( ceData.rect.height() - h ) / 2, + ( ceData.rect.height() - h ) / 2, + pixelMetric( PM_ExclusiveIndicatorWidth, ceData, elementFlags ), h ); break; } case SR_CheckBoxFocusRect: case SR_RadioButtonFocusRect: - rect = widget->rect(); + rect = ceData.rect; break; case SR_ComboBoxFocusRect: { #ifndef QT_NO_COMBOBOX - const QComboBox *combobox = (const QComboBox *) widget; - - if (combobox->editable()) { - rect = querySubControlMetrics(CC_ComboBox, widget, - SC_ComboBoxEditField); + if (elementFlags & CEF_IsEditable) { + rect = querySubControlMetrics(CC_ComboBox, ceData, elementFlags, + SC_ComboBoxEditField, QStyleOption::Default, widget); rect.addCoords(-3, -3, 3, 3); } else - rect = combobox->rect(); + rect = ceData.rect; #endif break; } @@ -1062,21 +1065,20 @@ QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const case SR_SliderFocusRect: { #ifndef QT_NO_SLIDER - const QSlider *slider = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget ); - int thickness = pixelMetric( PM_SliderControlThickness, widget ); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); int x, y, wi, he; - if ( slider->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { x = 0; y = tickOffset; - wi = slider->width(); + wi = ceData.rect.width(); he = thickness; } else { x = tickOffset; y = 0; wi = thickness; - he = slider->height(); + he = ceData.rect.height(); } rect.setRect(x, y, wi, he); @@ -1085,7 +1087,7 @@ QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const } default: - rect = QMotifStyle::subRect(r, widget); + rect = QMotifStyle::subRect(r, ceData, elementFlags, widget); break; } @@ -1096,13 +1098,15 @@ QRect QMotifPlusStyle::subRect(SubRect r, const QWidget *widget) const /*! \reimp */ void QMotifPlusStyle::drawComplexControl(ComplexControl control, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, SCFlags controls, SCFlags active, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { if (widget == singleton->hoverWidget) flags |= Style_MouseOver; @@ -1111,17 +1115,16 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, case CC_ScrollBar: { #ifndef QT_NO_SCROLLBAR - const QScrollBar *scrollbar = (const QScrollBar *) widget; QRect addline, subline, addpage, subpage, slider, first, last; - bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue()); + bool maxedOut = (ceData.minSteps == ceData.maxSteps); - subline = querySubControlMetrics(control, widget, SC_ScrollBarSubLine, opt); - addline = querySubControlMetrics(control, widget, SC_ScrollBarAddLine, opt); - subpage = querySubControlMetrics(control, widget, SC_ScrollBarSubPage, opt); - addpage = querySubControlMetrics(control, widget, SC_ScrollBarAddPage, opt); - slider = querySubControlMetrics(control, widget, SC_ScrollBarSlider, opt); - first = querySubControlMetrics(control, widget, SC_ScrollBarFirst, opt); - last = querySubControlMetrics(control, widget, SC_ScrollBarLast, opt); + subline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget); + addline = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget); + subpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget); + addpage = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget); + slider = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarSlider, opt, widget); + first = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarFirst, opt, widget); + last = querySubControlMetrics(control, ceData, elementFlags, SC_ScrollBarLast, opt, widget); bool skipUpdate = FALSE; if (singleton->hovering) { @@ -1157,67 +1160,67 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, &cg.brush(QColorGroup::Mid)); if ((controls & SC_ScrollBarSubLine) && subline.isValid()) - drawPrimitive(PE_ScrollBarSubLine, p, subline, cg, + drawPrimitive(PE_ScrollBarSubLine, p, ceData, elementFlags, subline, cg, ((active == SC_ScrollBarSubLine || singleton->scrollbarElement == SC_ScrollBarSubLine) ? Style_MouseOver: Style_Default) | ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarSubLine) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarAddLine) && addline.isValid()) - drawPrimitive(PE_ScrollBarAddLine, p, addline, cg, + drawPrimitive(PE_ScrollBarAddLine, p, ceData, elementFlags, addline, cg, ((active == SC_ScrollBarAddLine || singleton->scrollbarElement == SC_ScrollBarAddLine) ? Style_MouseOver: Style_Default) | ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarAddLine) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarSubPage) && subpage.isValid()) - drawPrimitive(PE_ScrollBarSubPage, p, subpage, cg, + drawPrimitive(PE_ScrollBarSubPage, p, ceData, elementFlags, subpage, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarSubPage) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarAddPage) && addpage.isValid()) - drawPrimitive(PE_ScrollBarAddPage, p, addpage, cg, + drawPrimitive(PE_ScrollBarAddPage, p, ceData, elementFlags, addpage, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarAddPage) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarFirst) && first.isValid()) - drawPrimitive(PE_ScrollBarFirst, p, first, cg, + drawPrimitive(PE_ScrollBarFirst, p, ceData, elementFlags, first, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarFirst) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarLast) && last.isValid()) - drawPrimitive(PE_ScrollBarLast, p, last, cg, + drawPrimitive(PE_ScrollBarLast, p, ceData, elementFlags, last, cg, ((maxedOut) ? Style_Default : Style_Enabled) | ((active == SC_ScrollBarLast) ? Style_Down : Style_Default) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); if ((controls & SC_ScrollBarSlider) && slider.isValid()) { - drawPrimitive(PE_ScrollBarSlider, p, slider, cg, + drawPrimitive(PE_ScrollBarSlider, p, ceData, elementFlags, slider, cg, ((active == SC_ScrollBarSlider || singleton->scrollbarElement == SC_ScrollBarSlider) ? Style_MouseOver: Style_Default) | ((maxedOut) ? Style_Default : Style_Enabled) | - ((scrollbar->orientation() == Qt::Horizontal) ? + ((ceData.orientation == Qt::Horizontal) ? Style_Horizontal : Style_Default)); // ### perhaps this should not be able to accept focus if maxedOut? - if (scrollbar->hasFocus()) { + if (elementFlags & CEF_HasFocus) { QRect fr(slider.x() + 2, slider.y() + 2, slider.width() - 5, slider.height() - 5); - drawPrimitive(PE_FocusRect, p, fr, cg, Style_Default); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, Style_Default); } } #endif @@ -1227,27 +1230,25 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, case CC_ComboBox: { #ifndef QT_NO_COMBOBOX - const QComboBox *combobox = (const QComboBox *) widget; - QRect editfield, arrow; editfield = visualRect(querySubControlMetrics(CC_ComboBox, - combobox, + ceData, elementFlags, SC_ComboBoxEditField, - opt), widget); + opt, widget), ceData, elementFlags); arrow = visualRect(querySubControlMetrics(CC_ComboBox, - combobox, + ceData, elementFlags, SC_ComboBoxArrow, - opt), widget); + opt, widget), ceData, elementFlags); - if (combobox->editable()) { + if (elementFlags & CEF_IsEditable) { if (controls & SC_ComboBoxEditField && editfield.isValid()) { editfield.addCoords(-3, -3, 3, 3); - if (combobox->hasFocus()) + if (elementFlags & CEF_HasFocus) editfield.addCoords(1, 1, -1, -1); drawMotifPlusShade(p, editfield, cg, TRUE, FALSE, - (widget->isEnabled() ? + ((elementFlags & CEF_IsEnabled) ? &cg.brush(QColorGroup::Base) : &cg.brush(QColorGroup::Background))); } @@ -1261,12 +1262,12 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, if (active == SC_ComboBoxArrow) flags |= Style_Sunken; - drawPrimitive(PE_ArrowDown, p, arrow, cg, flags); + drawPrimitive(PE_ArrowDown, p, ceData, elementFlags, arrow, cg, flags); } } else { if (controls & SC_ComboBoxEditField && editfield.isValid()) { editfield.addCoords(-3, -3, 3, 3); - if (combobox->hasFocus()) + if (elementFlags & CEF_HasFocus) editfield.addCoords(1, 1, -1, -1); drawMotifPlusShade(p, editfield, cg, FALSE, (flags & Style_MouseOver)); @@ -1276,10 +1277,10 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, drawMotifPlusShade(p, arrow, cg, FALSE, (flags & Style_MouseOver)); } - if (combobox->hasFocus() || - (combobox->editable() && combobox->lineEdit()->hasFocus())) { - QRect fr = visualRect(subRect(SR_ComboBoxFocusRect, widget), widget); - drawPrimitive(PE_FocusRect, p, fr, cg, flags); + if ((elementFlags & CEF_HasFocus) || + ((elementFlags & CEF_IsEditable) && (ceData.comboBoxLineEditFlags & CEF_HasFocus))) { + QRect fr = visualRect(subRect(SR_ComboBoxFocusRect, ceData, elementFlags, widget), ceData, elementFlags); + drawPrimitive(PE_FocusRect, p, ceData, elementFlags, fr, cg, flags); } #endif break; @@ -1288,7 +1289,6 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, case CC_SpinWidget: { #ifndef QT_NO_SPINWIDGET - const QSpinWidget * sw = (const QSpinWidget *) widget; SFlags flags = Style_Default; if (controls & SC_SpinWidgetFrame) @@ -1300,14 +1300,14 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, flags |= Style_Down; PrimitiveElement pe; - if ( sw->buttonSymbols() == QSpinWidget::PlusMinus ) + if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus ) pe = PE_SpinWidgetPlus; else pe = PE_SpinWidgetUp; - QRect re = sw->upRect(); - QColorGroup ucg = sw->isUpEnabled() ? cg : sw->palette().disabled(); - drawPrimitive(pe, p, re, ucg, flags); + QRect re = ceData.spinWidgetData.upRect; + QColorGroup ucg = ceData.spinWidgetData.upEnabled ? cg : ceData.palette.disabled(); + drawPrimitive(pe, p, ceData, elementFlags, re, ucg, flags); } if (controls & SC_SpinWidgetDown) { @@ -1316,14 +1316,14 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, flags |= Style_Down; PrimitiveElement pe; - if ( sw->buttonSymbols() == QSpinWidget::PlusMinus ) + if ( ceData.spinWidgetData.buttonSymbols == QSpinWidget::PlusMinus ) pe = PE_SpinWidgetMinus; else pe = PE_SpinWidgetDown; - QRect re = sw->downRect(); - QColorGroup dcg = sw->isDownEnabled() ? cg : sw->palette().disabled(); - drawPrimitive(pe, p, re, dcg, flags); + QRect re = ceData.spinWidgetData.downRect; + QColorGroup dcg = ceData.spinWidgetData.downEnabled ? cg : ceData.palette.disabled(); + drawPrimitive(pe, p, ceData, elementFlags, re, dcg, flags); } #endif break; @@ -1332,21 +1332,20 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, case CC_Slider: { #ifndef QT_NO_SLIDER - const QSlider *slider = (const QSlider *) widget; bool mouseover = (flags & Style_MouseOver); - QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, - opt), - handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, - opt); + QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, + opt, widget), + handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, + opt, widget); if ((controls & SC_SliderGroove) && groove.isValid()) { drawMotifPlusShade(p, groove, cg, TRUE, FALSE, &cg.brush(QColorGroup::Mid)); if ( flags & Style_HasFocus ) { - QRect fr = subRect( SR_SliderFocusRect, widget ); - drawPrimitive( PE_FocusRect, p, fr, cg, flags ); + QRect fr = subRect( SR_SliderFocusRect, ceData, elementFlags, widget ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, cg, flags ); } } @@ -1356,9 +1355,9 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, flags |= Style_MouseOver; else flags &= ~Style_MouseOver; - drawPrimitive(PE_ButtonBevel, p, handle, cg, flags | Style_Raised); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, handle, cg, flags | Style_Raised); - if ( slider->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { QCOORD mid = handle.x() + handle.width() / 2; qDrawShadeLine( p, mid, handle.y() + 1, mid , handle.y() + handle.height() - 3, @@ -1372,15 +1371,15 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, } if (controls & SC_SliderTickmarks) - QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags, - SC_SliderTickmarks, active, opt); + QMotifStyle::drawComplexControl(control, p, ceData, elementFlags, r, cg, flags, + SC_SliderTickmarks, active, opt, widget); #endif break; } default: - QMotifStyle::drawComplexControl(control, p, widget, r, cg, flags, - controls, active, opt); + QMotifStyle::drawComplexControl(control, p, ceData, elementFlags, r, cg, flags, + controls, active, opt, widget); } } @@ -1388,22 +1387,24 @@ void QMotifPlusStyle::drawComplexControl(ComplexControl control, /*! \reimp */ QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl subcontrol, - const QStyleOption& opt) const + const QStyleOption& opt, + const QWidget *widget) const { switch (control) { case CC_SpinWidget: { - int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 ); + int fw = pixelMetric( PM_SpinBoxFrameWidth, ceData, elementFlags, 0 ); QSize bs; - bs.setHeight( (widget->height() + 1)/2 ); + bs.setHeight( (ceData.rect.height() + 1)/2 ); if ( bs.height() < 10 ) bs.setHeight( 10 ); bs.setWidth( bs.height() ); // 1.6 -approximate golden mean bs = bs.expandedTo( QApplication::globalStrut() ); int y = 0; int x, lx, rx, h; - x = widget->width() - y - bs.width(); + x = ceData.rect.width() - y - bs.width(); lx = fw; rx = x - fw * 2; h = bs.height() * 2; @@ -1418,7 +1419,7 @@ QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control, case SC_SpinWidgetEditField: return QRect(lx, fw, rx, h - 2*fw); case SC_SpinWidgetFrame: - return QRect( 0, 0, widget->width() - bs.width(), h); + return QRect( 0, 0, ceData.rect.width() - bs.width(), h); default: break; } @@ -1426,34 +1427,33 @@ QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control, #ifndef QT_NO_COMBOBOX case CC_ComboBox: { - const QComboBox *combobox = (const QComboBox *) widget; - if (combobox->editable()) { - int space = (combobox->height() - 13) / 2; + if (elementFlags & CEF_IsEditable) { + int space = (ceData.rect.height() - 13) / 2; switch (subcontrol) { case SC_ComboBoxFrame: return QRect(); case SC_ComboBoxEditField: { - QRect rect = widget->rect(); + QRect rect = ceData.rect; rect.setWidth(rect.width() - 13 - space * 2); rect.addCoords(3, 3, -3, -3); return rect; } case SC_ComboBoxArrow: - return QRect(combobox->width() - 13 - space * 2, 0, - 13 + space * 2, combobox->height()); + return QRect(ceData.rect.width() - 13 - space * 2, 0, + 13 + space * 2, ceData.rect.height()); default: break; // shouldn't get here } } else { - int space = (combobox->height() - 7) / 2; + int space = (ceData.rect.height() - 7) / 2; switch (subcontrol) { case SC_ComboBoxFrame: return QRect(); case SC_ComboBoxEditField: { - QRect rect = widget->rect(); + QRect rect = ceData.rect; rect.addCoords(3, 3, -3, -3); return rect; } case SC_ComboBoxArrow: // 12 wide, 7 tall - return QRect(combobox->width() - 12 - space, space, 12, 7); + return QRect(ceData.rect.width() - 12 - space, space, 12, 7); default: break; // shouldn't get here } } @@ -1464,14 +1464,13 @@ QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control, case CC_Slider: { if (subcontrol == SC_SliderHandle) { - const QSlider *slider = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget ); - int thickness = pixelMetric( PM_SliderControlThickness, widget ); - int len = pixelMetric( PM_SliderLength, widget ) + 2; - int sliderPos = slider->sliderStart(); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ) + 2; + int sliderPos = ceData.startStep; int motifBorder = 2; - if ( slider->orientation() == Horizontal ) + if ( ceData.orientation == Horizontal ) return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len, thickness - 2*motifBorder ); return QRect( tickOffset + motifBorder, sliderPos + motifBorder, @@ -1481,19 +1480,19 @@ QRect QMotifPlusStyle::querySubControlMetrics(ComplexControl control, #endif default: break; } - return QMotifStyle::querySubControlMetrics(control, widget, subcontrol, opt); + return QMotifStyle::querySubControlMetrics(control, ceData, elementFlags, subcontrol, opt, widget); } /*! \reimp */ -bool QMotifPlusStyle::eventFilter(QObject *object, QEvent *event) +bool QMotifPlusStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *event ) { switch(event->type()) { case QEvent::MouseButtonPress: { singleton->mousePressed = TRUE; - if (!::qt_cast<QSlider*>(object)) + if (!ceData.widgetObjectTypes.contains("QSlider")) break; singleton->sliderActive = TRUE; @@ -1504,50 +1503,52 @@ bool QMotifPlusStyle::eventFilter(QObject *object, QEvent *event) { singleton->mousePressed = FALSE; - if (!::qt_cast<QSlider*>(object)) + if (!ceData.widgetObjectTypes.contains("QSlider")) break; singleton->sliderActive = FALSE; - ((QWidget *) object)->repaint(FALSE); + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); break; } case QEvent::Enter: { - if (! object->isWidgetType()) + if (!ceData.widgetObjectTypes.contains("QWidget")) break; - singleton->hoverWidget = (QWidget *) object; - if (! singleton->hoverWidget->isEnabled()) { + singleton->hoverWidget = source; + singleton->hoverWidgetData = ceData; + singleton->hoverWidgetFlags = elementFlags; + if (!(singleton->hoverWidgetFlags & CEF_IsEnabled)) { singleton->hoverWidget = 0; break; } - singleton->hoverWidget->repaint(FALSE); + widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint); break; } case QEvent::Leave: { - if (object != singleton->hoverWidget) + if (source != singleton->hoverWidget) break; - QWidget *w = singleton->hoverWidget; + void *w = singleton->hoverWidget; singleton->hoverWidget = 0; - w->repaint(FALSE); + widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, w, WAR_Repaint); break; } case QEvent::MouseMove: { - if (! object->isWidgetType() || object != singleton->hoverWidget) + if ((!ceData.widgetObjectTypes.contains("QWidget")) || source != singleton->hoverWidget) break; - if (!::qt_cast<QScrollBar*>(object) && ! ::qt_cast<QSlider*>(object)) + if ((!ceData.widgetObjectTypes.contains("QScrollBar")) && (!ceData.widgetObjectTypes.contains("QSlider"))) break; singleton->mousePos = ((QMouseEvent *) event)->pos(); if (! singleton->mousePressed) { singleton->hovering = TRUE; - singleton->hoverWidget->repaint(FALSE); + widgetActionRequest(singleton->hoverWidgetData, singleton->hoverWidgetFlags, singleton->hoverWidget, WAR_Repaint); singleton->hovering = FALSE; } @@ -1558,15 +1559,17 @@ bool QMotifPlusStyle::eventFilter(QObject *object, QEvent *event) break; } - return QMotifStyle::eventFilter(object, event); + return QMotifStyle::objectEventHandler(ceData, elementFlags, source, event); } /*! \reimp */ int QMotifPlusStyle::styleHint(StyleHint hint, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QStyleOption &opt, - QStyleHintReturn *returnData) const + QStyleHintReturn *returnData, + const QWidget *widget) const { int ret; switch (hint) { @@ -1574,7 +1577,7 @@ int QMotifPlusStyle::styleHint(StyleHint hint, ret = 1; break; default: - ret = QMotifStyle::styleHint(hint, widget, opt, returnData); + ret = QMotifStyle::styleHint(hint, ceData, elementFlags, opt, returnData, widget); break; } return ret; diff --git a/src/styles/qmotifplusstyle.h b/src/styles/qmotifplusstyle.h index b1908de..24de609 100644 --- a/src/styles/qmotifplusstyle.h +++ b/src/styles/qmotifplusstyle.h @@ -63,14 +63,16 @@ public: virtual ~QMotifPlusStyle(); void polish(QPalette &pal); - void polish(QWidget *widget); - void unPolish(QWidget*widget); + void polish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); + void unPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); - void polish(QApplication *app); - void unPolish(QApplication *app); + void applicationPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); + void applicationUnPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -78,17 +80,20 @@ public: void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - QRect subRect(SubRect r, const QWidget *widget) const; + QRect subRect(SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const; void drawComplexControl(ComplexControl control, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, @@ -98,20 +103,22 @@ public: SCFlags controls = (uint)SC_All, #endif SCFlags active = SC_None, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; QRect querySubControlMetrics(ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl subcontrol, - const QStyleOption& = QStyleOption::Default) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0) const; - int pixelMetric(PixelMetric metric, const QWidget *widget = 0) const; + int pixelMetric(PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0) const; - int styleHint(StyleHint sh, const QWidget *, const QStyleOption & = QStyleOption::Default, - QStyleHintReturn* = 0) const; + int styleHint(StyleHint sh, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption & = QStyleOption::Default, + QStyleHintReturn* = 0, const QWidget * = 0) const; -protected: - bool eventFilter(QObject *, QEvent *); + bool objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); private: diff --git a/src/styles/qmotifstyle.cpp b/src/styles/qmotifstyle.cpp index d6a1644..4c6a0c8 100644 --- a/src/styles/qmotifstyle.cpp +++ b/src/styles/qmotifstyle.cpp @@ -171,9 +171,9 @@ void QMotifStyle::polish( QPalette& pal ) \internal Keep QStyle::polish() visible. */ -void QMotifStyle::polish( QWidget* w ) +void QMotifStyle::polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr ) { - QStyle::polish(w); + QStyle::polish(ceData, elementFlags, ptr); } /*! @@ -181,9 +181,9 @@ void QMotifStyle::polish( QWidget* w ) \internal Keep QStyle::polish() visible. */ -void QMotifStyle::polish( QApplication* a ) +void QMotifStyle::applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr ) { - QStyle::polish(a); + QStyle::applicationPolish(ceData, elementFlags, ptr); } static void rot(QPointArray& a, int n) @@ -204,6 +204,8 @@ static void rot(QPointArray& a, int n) */ void QMotifStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -251,7 +253,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, case PE_ButtonTool: case PE_HeaderSection: qDrawShadePanel( p, r, cg, bool(flags & (Style_Down | Style_On )), - pixelMetric(PM_DefaultFrameWidth), + pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags), &cg.brush(QColorGroup::Button) ); break; @@ -268,7 +270,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, r.x(), r.y() + r.height() - 1); } else qDrawShadePanel( p, r, cg, !showUp, - pixelMetric(PM_DefaultFrameWidth), &fill ); + pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags), &fill ); #endif break; } @@ -509,7 +511,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, case PE_SpinWidgetMinus: { p->save(); - int fw = pixelMetric( PM_DefaultFrameWidth ); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ); QRect br; br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2, r.height() - fw*2 ); @@ -547,7 +549,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, case PE_SpinWidgetDown: { p->save(); - int fw = pixelMetric( PM_DefaultFrameWidth ); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ); QRect br; br.setRect( r.x() + fw, r.y() + fw, r.width() - fw*2, r.height() - fw*2 ); @@ -576,8 +578,8 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, int bsx = 0; int bsy = 0; if ( flags & Style_Sunken ) { - bsx = pixelMetric(PM_ButtonShiftHorizontal); - bsy = pixelMetric(PM_ButtonShiftVertical); + bsx = pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags); + bsy = pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags); } p->translate( sx + bsx, sy + bsy ); p->setPen( cg.buttonText() ); @@ -665,7 +667,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, case PE_DockWindowResizeHandle: { const int motifOffset = 10; - int sw = pixelMetric( PM_SplitterWidth ); + int sw = pixelMetric( PM_SplitterWidth, ceData, elementFlags ); if ( flags & Style_Horizontal ) { QCOORD yPos = r.y() + r.height() / 2; QCOORD kPos = r.width() - motifOffset - sw; @@ -694,7 +696,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, const int markH = 6; int posX = r.x() + ( r.width() - markW ) / 2 - 1; int posY = r.y() + ( r.height() - markH ) / 2; - int dfw = pixelMetric(PM_DefaultFrameWidth); + int dfw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags); if (dfw < 2) { // Could do with some optimizing/caching... @@ -736,12 +738,12 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, case PE_ScrollBarSubLine: drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp), - p, r, cg, Style_Enabled | flags); + p, ceData, elementFlags, r, cg, Style_Enabled | flags); break; case PE_ScrollBarAddLine: drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown), - p, r, cg, Style_Enabled | flags); + p, ceData, elementFlags, r, cg, Style_Enabled | flags); break; case PE_ScrollBarSubPage: @@ -750,7 +752,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, break; case PE_ScrollBarSlider: - drawPrimitive(PE_ButtonBevel, p, r, cg, + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, (flags | Style_Raised) & ~Style_Down); break; @@ -760,7 +762,7 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, break; default: - QCommonStyle::drawPrimitive( pe, p, r, cg, flags, opt ); + QCommonStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; } } @@ -770,40 +772,40 @@ void QMotifStyle::drawPrimitive( PrimitiveElement pe, */ void QMotifStyle::drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch( element ) { case CE_PushButton: { #ifndef QT_NO_PUSHBUTTON int diw, x1, y1, x2, y2; - const QPushButton *btn; QColorGroup newCg = cg; - btn = ( const QPushButton * )widget; p->setPen( cg.foreground() ); p->setBrush( QBrush( cg.button(), NoBrush ) ); - diw = pixelMetric( PM_ButtonDefaultIndicator ); + diw = pixelMetric( PM_ButtonDefaultIndicator, ceData, elementFlags ); r.coords( &x1, &y1, &x2, &y2 ); - if ( btn->isDefault() || btn->autoDefault() ) { + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } QBrush fill; - if ( btn->isDown() ) + if ( elementFlags & CEF_IsDown ) fill = newCg.brush( QColorGroup::Mid ); - else if ( btn->isOn() ) + else if ( elementFlags & CEF_IsOn ) fill = QBrush( newCg.mid(), Dense4Pattern ); else fill = newCg.brush( QColorGroup::Button ); newCg.setBrush( QColorGroup::Button, fill ); - if ( btn->isDefault() ) { + if ( elementFlags & CEF_IsDefault ) { if ( diw == 0 ) { QPointArray a; a.setPoints( 9, @@ -819,17 +821,17 @@ void QMotifStyle::drawControl( ControlElement element, qDrawShadePanel( p, r, newCg, TRUE ); } } - if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) { + if ( !( elementFlags & CEF_IsFlat ) || ( elementFlags & CEF_IsOn ) || ( elementFlags & CEF_IsDown ) ) { QRect tmp( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ); SFlags flags = Style_Default; - if ( btn->isOn()) + if ( elementFlags & CEF_IsOn ) flags |= Style_On; - if (btn->isDown()) + if ( elementFlags & CEF_IsDown ) flags |= Style_Down; p->save(); - p->setBrushOrigin( -widget->backgroundOffset().x(), - -widget->backgroundOffset().y() ); - drawPrimitive( PE_ButtonCommand, p, + p->setBrushOrigin( -ceData.bgOffset.x(), + -ceData.bgOffset.y() ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, tmp, newCg, flags ); p->restore(); @@ -843,47 +845,46 @@ void QMotifStyle::drawControl( ControlElement element, case CE_TabBarTab: { #ifndef QT_NO_TABBAR - if ( !widget || !widget->parentWidget() || !opt.tab() ) + if ( (elementFlags & CEF_UseGenericParameters) || !(elementFlags & CEF_HasParentWidget) || !opt.tab() ) break; - const QTabBar * tb = (const QTabBar *) widget; const QTab * t = opt.tab(); - int dfw = pixelMetric( PM_DefaultFrameWidth, tb ); + int dfw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); bool selected = flags & Style_Selected; int o = dfw > 1 ? 1 : 0; bool lastTab = FALSE; QRect r2( r ); - if ( tb->shape() == QTabBar::RoundedAbove ) { - if ( styleHint( SH_TabBar_Alignment, tb ) == AlignRight && - tb->indexOf( t->identifier() ) == tb->count()-1 ) + if ( ceData.tabBarData.shape == QTabBar::RoundedAbove ) { + if ( styleHint( SH_TabBar_Alignment, ceData, elementFlags, QStyleOption::Default, 0, widget ) == AlignRight && + ceData.tabBarData.identIndexMap[t->identifier()] == ceData.tabBarData.tabCount-1 ) lastTab = TRUE; if ( o ) { - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); p->drawLine( r2.left(), r2.bottom()-1, r2.right(), r2.bottom()-1 ); if ( r2.left() == 0 ) - p->drawPoint( tb->rect().bottomLeft() ); + p->drawPoint( ceData.rect.bottomLeft() ); } else { - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); } if ( selected ) { p->fillRect( QRect( r2.left()+1, r2.bottom()-o, r2.width()-3, 2), - tb->palette().active().brush( QColorGroup::Background )); - p->setPen( tb->colorGroup().background() ); + ceData.palette.active().brush( QColorGroup::Background )); + p->setPen( ceData.colorGroup.background() ); // p->drawLine( r2.left()+1, r2.bottom(), r2.right()-2, r2.bottom() ); // if (o) // p->drawLine( r2.left()+1, r2.bottom()-1, r2.right()-2, r2.bottom()-1 ); p->drawLine( r2.left()+1, r2.bottom(), r2.left()+1, r2.top()+2 ); - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); } else { - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); r2.setRect( r2.left() + 2, r2.top() + 2, r2.width() - 4, r2.height() - 2 ); } @@ -900,7 +901,7 @@ void QMotifStyle::drawControl( ControlElement element, r2.right() - 2, r2.top()+1 ); } - p->setPen( tb->colorGroup().dark() ); + p->setPen( ceData.colorGroup.dark() ); p->drawLine( r2.right() - 1, r2.top() + 2, r2.right() - 1, r2.bottom() - 1 + (selected ? o : -o)); if ( o ) { @@ -910,19 +911,19 @@ void QMotifStyle::drawControl( ControlElement element, (selected ? (lastTab ? 0:1):1+o)); p->drawPoint( r2.right() - 1, r2.top() + 1 ); } - } else if ( tb->shape() == QTabBar::RoundedBelow ) { - if ( styleHint( SH_TabBar_Alignment, tb ) == AlignLeft && - tb->indexOf( t->identifier() ) == tb->count()-1 ) + } else if ( ceData.tabBarData.shape == QTabBar::RoundedBelow ) { + if ( styleHint( SH_TabBar_Alignment, ceData, elementFlags, QStyleOption::Default, 0, widget ) == AlignLeft && + ceData.tabBarData.identIndexMap[t->identifier()] == ceData.tabBarData.tabCount-1 ) lastTab = TRUE; if ( selected ) { p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-3, 1), - tb->palette().active().brush( QColorGroup::Background )); - p->setPen( tb->colorGroup().background() ); + ceData.palette.active().brush( QColorGroup::Background )); + p->setPen( ceData.colorGroup.background() ); // p->drawLine( r2.left()+1, r2.top(), r2.right()-2, r2.top() ); p->drawLine( r2.left()+1, r2.top(), r2.left()+1, r2.bottom()-2 ); - p->setPen( tb->colorGroup().dark() ); + p->setPen( ceData.colorGroup.dark() ); } else { - p->setPen( tb->colorGroup().dark() ); + p->setPen( ceData.colorGroup.dark() ); p->drawLine( r2.left(), r2.top(), r2.right(), r2.top() ); p->drawLine( r2.left() + 1, r2.top() + 1, r2.right() - (lastTab ? 0 : 2), @@ -946,14 +947,14 @@ void QMotifStyle::drawControl( ControlElement element, r2.left() + 2, r2.bottom() ); } - p->setPen( tb->colorGroup().light() ); + p->setPen( ceData.colorGroup.light() ); p->drawLine( r2.left(), r2.top() + (selected ? 0 : 2), r2.left(), r2.bottom() - 2 ); p->drawLine( r2.left() + 1, r2.top() + (selected ? 0 : 2), r2.left() + 1, r2.bottom() - 3 ); } else { - QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt ); + QCommonStyle::drawControl( element, p, ceData, elementFlags, r, cg, flags, opt, widget ); } #endif break; @@ -966,32 +967,31 @@ void QMotifStyle::drawControl( ControlElement element, case CE_ProgressBarLabel: { #ifndef QT_NO_PROGRESSBAR - const QProgressBar * pb = (const QProgressBar *) widget; - const int unit_width = pixelMetric( PM_ProgressBarChunkWidth, pb ); + const int unit_width = pixelMetric( PM_ProgressBarChunkWidth, ceData, elementFlags, widget ); int u = r.width() / unit_width; - int p_v = pb->progress(); - int t_s = pb->totalSteps(); - if ( u > 0 && pb->progress() >= INT_MAX / u && t_s >= u ) { + int p_v = ceData.currentStep; + int t_s = ceData.totalSteps; + if ( u > 0 && ceData.currentStep >= INT_MAX / u && t_s >= u ) { // scale down to something usable. p_v /= u; t_s /= u; } - if ( pb->percentageVisible() && pb->totalSteps() ) { + if ( ceData.percentageVisible && ceData.totalSteps ) { int nu = ( u * p_v + t_s/2 ) / t_s; int x = unit_width * nu; - if (pb->indicatorFollowsStyle() || pb->centerIndicator()) { + if ((elementFlags & CEF_IndicatorFollowsStyle) || (elementFlags & CEF_CenterIndicator)) { p->setPen( cg.highlightedText() ); p->setClipRect( r.x(), r.y(), x, r.height() ); - p->drawText( r, AlignCenter | SingleLine, pb->progressString() ); + p->drawText( r, AlignCenter | SingleLine, ceData.progressText ); - if ( pb->progress() != pb->totalSteps() ) { + if ( ceData.currentStep != ceData.totalSteps ) { p->setClipRect( r.x() + x, r.y(), r.width() - x, r.height() ); p->setPen( cg.highlight() ); - p->drawText( r, AlignCenter | SingleLine, pb->progressString() ); + p->drawText( r, AlignCenter | SingleLine, ceData.progressText ); } } else { p->setPen( cg.text() ); - p->drawText( r, AlignCenter | SingleLine, pb->progressString() ); + p->drawText( r, AlignCenter | SingleLine, ceData.progressText ); } } #endif @@ -1001,10 +1001,9 @@ void QMotifStyle::drawControl( ControlElement element, #ifndef QT_NO_POPUPMENU case CE_PopupMenuItem: { - if (! widget || opt.isDefault()) + if ((elementFlags & CEF_UseGenericParameters) || opt.isDefault()) break; - const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; @@ -1012,7 +1011,7 @@ void QMotifStyle::drawControl( ControlElement element, int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = ! (flags & Style_Enabled); - bool checkable = popupmenu->isCheckable(); + bool checkable = (elementFlags & CEF_IsCheckable); bool act = flags & Style_Active; int x, y, w, h; @@ -1034,7 +1033,7 @@ void QMotifStyle::drawControl( ControlElement element, int pw = motifItemFrame; if ( act && !dis ) { // active item frame - if (pixelMetric( PM_DefaultFrameWidth ) > 1) + if (pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ) > 1) qDrawShadePanel( p, x, y, w, h, cg, FALSE, pw, &cg.brush( QColorGroup::Button ) ); else @@ -1086,7 +1085,7 @@ void QMotifStyle::drawControl( ControlElement element, if (act) cflags |= Style_On; - drawPrimitive(PE_CheckMark, p, + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, QRect(xvis, y+motifItemFrame, mw, mh), cg, cflags); } @@ -1140,11 +1139,11 @@ void QMotifStyle::drawControl( ControlElement element, QRect vr = visualRect( QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y+h/2-dim/2, dim, dim), r ); if ( act ) - drawPrimitive(arrow, p, vr, cg, + drawPrimitive(arrow, p, ceData, elementFlags, vr, cg, (Style_Down | (dis ? Style_Default : Style_Enabled)) ); else - drawPrimitive(arrow, p, vr, cg, + drawPrimitive(arrow, p, ceData, elementFlags, vr, cg, (dis ? Style_Default : Style_Enabled)); } @@ -1159,12 +1158,12 @@ void QMotifStyle::drawControl( ControlElement element, &cg.brush(QColorGroup::Button) ); else // other item p->fillRect( r, cg.brush(QColorGroup::Button) ); - QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt ); + QCommonStyle::drawControl( element, p, ceData, elementFlags, r, cg, flags, opt, widget ); break; } default: - QCommonStyle::drawControl( element, p, widget, r, cg, flags, opt ); + QCommonStyle::drawControl( element, p, ceData, elementFlags, r, cg, flags, opt, widget ); break; } } @@ -1220,20 +1219,22 @@ static void get_combo_parameters( const QRect &r, */ void QMotifStyle::drawComplexControl( ComplexControl control, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, SCFlags sub, SCFlags subActive, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch ( control ) { case CC_SpinWidget: { SCFlags drawSub = SC_None; if ( sub & SC_SpinWidgetFrame ) qDrawShadePanel( p, r, cg, TRUE, - pixelMetric( PM_DefaultFrameWidth) ); + pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ) ); if ( sub & SC_SpinWidgetUp || sub & SC_SpinWidgetDown ) { if ( sub & SC_SpinWidgetUp ) @@ -1241,20 +1242,18 @@ void QMotifStyle::drawComplexControl( ComplexControl control, if ( sub & SC_SpinWidgetDown ) drawSub |= SC_SpinWidgetDown; - QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, - drawSub, subActive, opt ); + QCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, + drawSub, subActive, opt, widget ); } break; } case CC_Slider: { #ifndef QT_NO_SLIDER - const QSlider * slider = (const QSlider *) widget; - - QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, - opt), - handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, - opt); + QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, + opt, widget), + handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, + opt, widget); if ((sub & SC_SliderGroove) && groove.isValid()) { qDrawShadePanel( p, groove, cg, TRUE, 2, @@ -1262,15 +1261,15 @@ void QMotifStyle::drawComplexControl( ComplexControl control, if ( flags & Style_HasFocus ) { - QRect fr = subRect( SR_SliderFocusRect, widget ); - drawPrimitive( PE_FocusRect, p, fr, cg ); + QRect fr = subRect( SR_SliderFocusRect, ceData, elementFlags, widget ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, cg ); } } if (( sub & SC_SliderHandle ) && handle.isValid()) { - drawPrimitive( PE_ButtonBevel, p, handle, cg ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, handle, cg ); - if ( slider->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { QCOORD mid = handle.x() + handle.width() / 2; qDrawShadeLine( p, mid, handle.y(), mid, handle.y() + handle.height() - 2, @@ -1284,9 +1283,9 @@ void QMotifStyle::drawComplexControl( ComplexControl control, } if ( sub & SC_SliderTickmarks ) - QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, + QCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, SC_SliderTickmarks, subActive, - opt ); + opt, widget ); #endif break; } @@ -1296,12 +1295,12 @@ void QMotifStyle::drawComplexControl( ComplexControl control, if ( sub & SC_ComboBoxArrow ) { const QComboBox * cb = (const QComboBox *) widget; int awh, ax, ay, sh, sy, dh, ew; - int fw = pixelMetric( PM_DefaultFrameWidth, cb); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, cb); - drawPrimitive( PE_ButtonCommand, p, r, cg, flags ); - QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow, - opt ), cb ); - drawPrimitive( PE_ArrowDown, p, ar, cg, flags | Style_Enabled ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, r, cg, flags ); + QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, SC_ComboBoxArrow, + opt, cb ), ceData, elementFlags ); + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, ar, cg, flags | Style_Enabled ); QRect tr = r; tr.addCoords( fw, fw, -fw, -fw ); @@ -1316,16 +1315,16 @@ void QMotifStyle::drawComplexControl( ComplexControl control, p->drawLine( ar.x()+awh-1, sy+1, ar.x()+awh-1, sy+sh-1 ); if ( cb->hasFocus() ) { - QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb ); - drawPrimitive( PE_FocusRect, p, re, cg ); + QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, ceData, elementFlags, cb ), ceData, elementFlags ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, re, cg ); } } if ( sub & SC_ComboBoxEditField ) { QComboBox * cb = (QComboBox *) widget; if ( cb->editable() ) { - QRect er = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, - SC_ComboBoxEditField ), cb ); + QRect er = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxEditField, cb ), ceData, elementFlags ); er.addCoords( -1, -1, 1, 1); qDrawShadePanel( p, er, cg, TRUE, 1, &cg.brush( QColorGroup::Button )); @@ -1340,11 +1339,11 @@ void QMotifStyle::drawComplexControl( ComplexControl control, if (sub == (SC_ScrollBarAddLine | SC_ScrollBarSubLine | SC_ScrollBarAddPage | SC_ScrollBarSubPage | SC_ScrollBarFirst | SC_ScrollBarLast | SC_ScrollBarSlider)) - qDrawShadePanel(p, widget->rect(), cg, TRUE, - pixelMetric(PM_DefaultFrameWidth, widget), + qDrawShadePanel(p, ceData.rect, cg, TRUE, + pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget), &cg.brush(QColorGroup::Mid)); - QCommonStyle::drawComplexControl(control, p, widget, r, cg, flags, sub, - subActive, opt); + QCommonStyle::drawComplexControl(control, p, ceData, elementFlags, r, cg, flags, sub, + subActive, opt, widget); break; } @@ -1352,7 +1351,7 @@ void QMotifStyle::drawComplexControl( ComplexControl control, case CC_ListView: { if ( sub & SC_ListView ) { - QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt ); + QCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, sub, subActive, opt, widget ); } if ( sub & ( SC_ListViewBranch | SC_ListViewExpand ) ) { if (opt.isDefault()) @@ -1455,14 +1454,14 @@ void QMotifStyle::drawComplexControl( ComplexControl control, #endif // QT_NO_LISTVIEW default: - QCommonStyle::drawComplexControl( control, p, widget, r, cg, flags, - sub, subActive, opt ); + QCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, + sub, subActive, opt, widget ); } } /*! \reimp */ -int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const +int QMotifStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { int ret; @@ -1519,9 +1518,9 @@ int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const #ifndef QT_NO_SLIDER const QSlider * sl = (const QSlider *) widget; if ( sl->orientation() == Horizontal ) - ret = sl->width() - pixelMetric( PM_SliderLength, sl ) - 6; + ret = sl->width() - pixelMetric( PM_SliderLength, ceData, elementFlags, sl ) - 6; else - ret = sl->height() - pixelMetric( PM_SliderLength, sl ) - 6; + ret = sl->height() - pixelMetric( PM_SliderLength, ceData, elementFlags, sl ) - 6; #endif break; } @@ -1540,7 +1539,7 @@ int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const break; default: - ret = QCommonStyle::pixelMetric( metric, widget ); + ret = QCommonStyle::pixelMetric( metric, ceData, elementFlags, widget ); break; } return ret; @@ -1550,24 +1549,26 @@ int QMotifStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const /*!\reimp */ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch ( control ) { case CC_SpinWidget: { - if ( !widget ) + if ( elementFlags & CEF_UseGenericParameters ) return QRect(); - int fw = pixelMetric( PM_SpinBoxFrameWidth, 0 ); + int fw = pixelMetric( PM_SpinBoxFrameWidth, ceData, elementFlags, 0 ); QSize bs; - bs.setHeight( widget->height()/2 ); + bs.setHeight( ceData.rect.height()/2 ); if ( bs.height() < 8 ) bs.setHeight( 8 ); - bs.setWidth( QMIN( bs.height() * 8 / 5, widget->width() / 4 ) ); // 1.6 -approximate golden mean + bs.setWidth( QMIN( bs.height() * 8 / 5, ceData.rect.width() / 4 ) ); // 1.6 -approximate golden mean bs = bs.expandedTo( QApplication::globalStrut() ); int y = 0; int x, lx, rx; - x = widget->width() - y - bs.width(); + x = ceData.rect.width() - y - bs.width(); lx = fw; rx = x - fw * 2; switch ( sc ) { @@ -1576,12 +1577,12 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, case SC_SpinWidgetDown: return QRect(x, y + bs.height(), bs.width(), bs.height()); case SC_SpinWidgetButtonField: - return QRect(x, y, bs.width(), widget->height() - 2*fw); + return QRect(x, y, bs.width(), ceData.rect.height() - 2*fw); case SC_SpinWidgetEditField: - return QRect(lx, fw, rx, widget->height() - 2*fw); + return QRect(lx, fw, rx, ceData.rect.height() - 2*fw); case SC_SpinWidgetFrame: return QRect( 0, 0, - widget->width() - bs.width(), widget->height() ); + ceData.rect.width() - bs.width(), ceData.rect.height() ); default: break; } @@ -1590,14 +1591,13 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, #ifndef QT_NO_SLIDER case CC_Slider: { if (sc == SC_SliderHandle) { - const QSlider * sl = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, sl ); - int thickness = pixelMetric( PM_SliderControlThickness, sl ); - int sliderPos = sl->sliderStart(); - int len = pixelMetric( PM_SliderLength, sl ); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget ); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int sliderPos = ceData.startStep; + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); int motifBorder = 3; - if ( sl->orientation() == Horizontal ) + if ( ceData.orientation == Horizontal ) return QRect( sliderPos + motifBorder, tickOffset + motifBorder, len, thickness - 2*motifBorder ); return QRect( tickOffset + motifBorder, sliderPos + motifBorder, @@ -1608,25 +1608,24 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, #ifndef QT_NO_SCROLLBAR case CC_ScrollBar: { - if (! widget) + if (elementFlags & CEF_UseGenericParameters) return QRect(); - const QScrollBar *scrollbar = (const QScrollBar *) widget; - int sliderstart = scrollbar->sliderStart(); - int sbextent = pixelMetric(PM_ScrollBarExtent, widget); - int fw = pixelMetric(PM_DefaultFrameWidth, widget); + int sliderstart = ceData.startStep; + int sbextent = pixelMetric(PM_ScrollBarExtent, ceData, elementFlags, widget); + int fw = pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags, widget); int buttonw = sbextent - (fw * 2); int buttonh = sbextent - (fw * 2); - int maxlen = ((scrollbar->orientation() == Qt::Horizontal) ? - scrollbar->width() : scrollbar->height()) - + int maxlen = ((ceData.orientation == Qt::Horizontal) ? + ceData.rect.width() : ceData.rect.height()) - (buttonw * 2) - (fw * 2); int sliderlen; // calculate slider length - if (scrollbar->maxValue() != scrollbar->minValue()) { - uint range = scrollbar->maxValue() - scrollbar->minValue(); - sliderlen = (scrollbar->pageStep() * maxlen) / - (range + scrollbar->pageStep()); + if (ceData.maxSteps != ceData.minSteps) { + uint range = ceData.maxSteps - ceData.minSteps; + sliderlen = (ceData.pageStep * maxlen) / + (range + ceData.pageStep); if ( sliderlen < 9 || range > INT_MAX/2 ) sliderlen = 9; @@ -1638,47 +1637,47 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, switch (sc) { case SC_ScrollBarSubLine: // top/left button - if (scrollbar->orientation() == Qt::Horizontal) { - if ( scrollbar->width()/2 < sbextent ) - buttonw = scrollbar->width()/2 - (fw*2); + if (ceData.orientation == Qt::Horizontal) { + if ( ceData.rect.width()/2 < sbextent ) + buttonw = ceData.rect.width()/2 - (fw*2); return QRect(fw, fw, buttonw, buttonh); } else { - if ( scrollbar->height()/2 < sbextent ) - buttonh = scrollbar->height()/2 - (fw*2); + if ( ceData.rect.height()/2 < sbextent ) + buttonh = ceData.rect.height()/2 - (fw*2); return QRect(fw, fw, buttonw, buttonh); } case SC_ScrollBarAddLine: // bottom/right button - if (scrollbar->orientation() == Qt::Horizontal) { - if ( scrollbar->width()/2 < sbextent ) - buttonw = scrollbar->width()/2 - (fw*2); - return QRect(scrollbar->width() - buttonw - fw, fw, + if (ceData.orientation == Qt::Horizontal) { + if ( ceData.rect.width()/2 < sbextent ) + buttonw = ceData.rect.width()/2 - (fw*2); + return QRect(ceData.rect.width() - buttonw - fw, fw, buttonw, buttonh); } else { - if ( scrollbar->height()/2 < sbextent ) - buttonh = scrollbar->height()/2 - (fw*2); - return QRect(fw, scrollbar->height() - buttonh - fw, + if ( ceData.rect.height()/2 < sbextent ) + buttonh = ceData.rect.height()/2 - (fw*2); + return QRect(fw, ceData.rect.height() - buttonh - fw, buttonw, buttonh); } case SC_ScrollBarSubPage: - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(buttonw + fw, fw, sliderstart - buttonw - fw, buttonw); return QRect(fw, buttonw + fw, buttonw, sliderstart - buttonw - fw); case SC_ScrollBarAddPage: - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(sliderstart + sliderlen, fw, maxlen - sliderstart - sliderlen + buttonw + fw, buttonw); return QRect(fw, sliderstart + sliderlen, buttonw, maxlen - sliderstart - sliderlen + buttonw + fw); case SC_ScrollBarGroove: - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(buttonw + fw, fw, maxlen, buttonw); return QRect(fw, buttonw + fw, buttonw, maxlen); case SC_ScrollBarSlider: - if (scrollbar->orientation() == Qt::Horizontal) + if (ceData.orientation == Qt::Horizontal) return QRect(sliderstart, fw, sliderlen, buttonw); return QRect(fw, sliderstart, buttonw, sliderlen); @@ -1693,18 +1692,16 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, switch ( sc ) { case SC_ComboBoxArrow: { - const QComboBox * cb = (const QComboBox *) widget; int ew, awh, sh, dh, ax, ay, sy; - int fw = pixelMetric( PM_DefaultFrameWidth, cb ); - QRect cr = cb->rect(); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); + QRect cr = ceData.rect; cr.addCoords( fw, fw, -fw, -fw ); get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy ); return QRect( ax, ay, awh, awh ); } case SC_ComboBoxEditField: { - const QComboBox * cb = (const QComboBox *) widget; - int fw = pixelMetric( PM_DefaultFrameWidth, cb ); - QRect rect = cb->rect(); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); + QRect rect = ceData.rect; rect.addCoords( fw, fw, -fw, -fw ); int ew = get_combo_extra_width( rect.height(), rect.width() ); rect.addCoords( 1, 1, -1-ew, -1 ); @@ -1717,15 +1714,17 @@ QRect QMotifStyle::querySubControlMetrics( ComplexControl control, #endif default: break; } - return QCommonStyle::querySubControlMetrics( control, widget, sc, opt ); + return QCommonStyle::querySubControlMetrics( control, ceData, elementFlags, sc, opt, widget ); } /*!\reimp */ QSize QMotifStyle::sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { QSize sz(contentsSize); @@ -1733,10 +1732,9 @@ QSize QMotifStyle::sizeFromContents( ContentsType contents, case CT_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; - sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt); - if ((button->isDefault() || button->autoDefault()) && - sz.width() < 80 && ! button->pixmap()) + sz = QCommonStyle::sizeFromContents(contents, ceData, elementFlags, contentsSize, opt, widget); + if (((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) && + sz.width() < 80 && ceData.fgPixmap.isNull()) sz.setWidth(80); #endif break; @@ -1745,11 +1743,10 @@ QSize QMotifStyle::sizeFromContents( ContentsType contents, case CT_PopupMenuItem: { #ifndef QT_NO_POPUPMENU - if (! widget || opt.isDefault()) + if ((elementFlags & CEF_UseGenericParameters) || opt.isDefault()) break; - const QPopupMenu *popup = (QPopupMenu *) widget; - bool checkable = popup->isCheckable(); + bool checkable = (elementFlags & CEF_IsCheckable); QMenuItem *mi = opt.menuItem(); int maxpmw = opt.maxIconWidth(); int w = sz.width(), h = sz.height(); @@ -1794,7 +1791,7 @@ QSize QMotifStyle::sizeFromContents( ContentsType contents, } default: - sz = QCommonStyle::sizeFromContents( contents, widget, contentsSize, opt ); + sz = QCommonStyle::sizeFromContents( contents, ceData, elementFlags, contentsSize, opt, widget ); break; } @@ -1803,21 +1800,21 @@ QSize QMotifStyle::sizeFromContents( ContentsType contents, /*!\reimp */ -QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const +QRect QMotifStyle::subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { QRect rect; - QRect wrect = widget->rect(); + QRect wrect = ceData.rect; switch ( r ) { case SR_SliderFocusRect: - rect = QCommonStyle::subRect( r, widget ); + rect = QCommonStyle::subRect( r, ceData, elementFlags, widget ); rect.addCoords( 2, 2, -2, -2 ); break; case SR_ComboBoxFocusRect: { int awh, ax, ay, sh, sy, dh, ew; - int fw = pixelMetric( PM_DefaultFrameWidth, widget ); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); QRect tr = wrect; tr.addCoords( fw, fw, -fw, -fw ); @@ -1829,17 +1826,16 @@ QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const case SR_DockWindowHandleRect: { #ifndef QT_NO_MAINWINDOW - if ( !widget || !widget->parent() ) + if ( (elementFlags & CEF_UseGenericParameters) || !(elementFlags & CEF_HasParentWidget) ) break; - const QDockWindow * dw = (const QDockWindow *) widget->parent(); - if ( !dw->area() || !dw->isCloseEnabled() ) - rect.setRect( 0, 0, widget->width(), widget->height() ); + if ( !ceData.dwData.hasDockArea || !ceData.dwData.closeEnabled ) + rect.setRect( 0, 0, ceData.rect.width(), ceData.rect.height() ); else { - if ( dw->area()->orientation() == Horizontal ) - rect.setRect(2, 15, widget->width()-2, widget->height() - 15); + if ( ceData.dwData.areaOrientation == Horizontal ) + rect.setRect(2, 15, ceData.rect.width()-2, ceData.rect.height() - 15); else - rect.setRect(0, 2, widget->width() - 15, widget->height() - 2); + rect.setRect(0, 2, ceData.rect.width() - 15, ceData.rect.height() - 2); } #endif break; @@ -1849,15 +1845,14 @@ QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const case SR_ProgressBarContents: { #ifndef QT_NO_PROGRESSBAR - QFontMetrics fm( ( widget ? widget->fontMetrics() : + QFontMetrics fm( ( (!(elementFlags & CEF_UseGenericParameters)) ? QFontMetrics(ceData.font) : QApplication::fontMetrics() ) ); - const QProgressBar *progressbar = (const QProgressBar *) widget; int textw = 0; - if (progressbar->percentageVisible()) + if (ceData.percentageVisible) textw = fm.width("100%") + 6; - if (progressbar->indicatorFollowsStyle() || - progressbar->centerIndicator()) + if ((elementFlags & CEF_IndicatorFollowsStyle) || + (elementFlags & CEF_CenterIndicator)) rect = wrect; else rect.setCoords(wrect.left(), wrect.top(), @@ -1869,15 +1864,14 @@ QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const case SR_ProgressBarLabel: { #ifndef QT_NO_PROGRESSBAR - QFontMetrics fm( ( widget ? widget->fontMetrics() : + QFontMetrics fm( ( (!(elementFlags & CEF_UseGenericParameters)) ? QFontMetrics(ceData.font) : QApplication::fontMetrics() ) ); - const QProgressBar *progressbar = (const QProgressBar *) widget; int textw = 0; - if (progressbar->percentageVisible()) + if (ceData.percentageVisible) textw = fm.width("100%") + 6; - if (progressbar->indicatorFollowsStyle() || - progressbar->centerIndicator()) + if ((elementFlags & CEF_IndicatorFollowsStyle) || + (elementFlags & CEF_CenterIndicator)) rect = wrect; else rect.setCoords(wrect.right() - textw, wrect.top(), @@ -1889,7 +1883,7 @@ QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const case SR_CheckBoxContents: { #ifndef QT_NO_CHECKBOX - QRect ir = subRect(SR_CheckBoxIndicator, widget); + QRect ir = subRect(SR_CheckBoxIndicator, ceData, elementFlags, widget); rect.setRect(ir.right() + 10, wrect.y(), wrect.width() - ir.width() - 10, wrect.height()); #endif @@ -1898,14 +1892,14 @@ QRect QMotifStyle::subRect( SubRect r, const QWidget *widget ) const case SR_RadioButtonContents: { - QRect ir = subRect(SR_RadioButtonIndicator, widget); + QRect ir = subRect(SR_RadioButtonIndicator, ceData, elementFlags, widget); rect.setRect(ir.right() + 10, wrect.y(), wrect.width() - ir.width() - 10, wrect.height()); break; } default: - rect = QCommonStyle::subRect( r, widget ); + rect = QCommonStyle::subRect( r, ceData, elementFlags, widget ); } return rect; @@ -2228,8 +2222,10 @@ static const char *const question_xpm[] = { \reimp */ QPixmap QMotifStyle::stylePixmap(StylePixmap sp, - const QWidget *widget, - const QStyleOption& opt) const + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& opt, + const QWidget *widget) const { #ifndef QT_NO_IMAGEIO_XPM switch (sp) { @@ -2306,15 +2302,17 @@ QPixmap QMotifStyle::stylePixmap(StylePixmap sp, } #endif - return QCommonStyle::stylePixmap(sp, widget, opt); + return QCommonStyle::stylePixmap(sp, ceData, elementFlags, opt, widget); } /*! \reimp */ int QMotifStyle::styleHint(StyleHint hint, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QStyleOption &opt, - QStyleHintReturn *returnData) const + QStyleHintReturn *returnData, + const QWidget *widget) const { int ret; @@ -2348,7 +2346,7 @@ int QMotifStyle::styleHint(StyleHint hint, break; default: - ret = QCommonStyle::styleHint(hint, widget, opt, returnData); + ret = QCommonStyle::styleHint(hint, ceData, elementFlags, opt, returnData, widget); break; } diff --git a/src/styles/qmotifstyle.h b/src/styles/qmotifstyle.h index c26337c..213795f 100644 --- a/src/styles/qmotifstyle.h +++ b/src/styles/qmotifstyle.h @@ -67,14 +67,16 @@ public: bool useHighlightColors() const; void polish( QPalette& ); - void polish( QWidget* ); - void polish( QApplication* ); + void polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + void applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); void polishPopupMenu( QPopupMenu* ); // new style API void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -82,15 +84,18 @@ public: void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; void drawComplexControl( ComplexControl control, QPainter *p, - const QWidget* widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect& r, const QColorGroup& cg, SFlags how = Style_Default, @@ -100,26 +105,31 @@ public: SCFlags sub = (uint)SC_All, #endif SCFlags subActive = SC_None, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget* widget = 0 ) const; QRect querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - int pixelMetric( PixelMetric metric, const QWidget *widget = 0 ) const; + int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; QSize sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - QRect subRect( SubRect r, const QWidget *widget ) const; + QRect subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const; - QPixmap stylePixmap(StylePixmap, const QWidget * = 0, const QStyleOption& = QStyleOption::Default) const; + QPixmap stylePixmap(StylePixmap, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption& = QStyleOption::Default, const QWidget * = 0) const; - int styleHint(StyleHint sh, const QWidget *, const QStyleOption & = QStyleOption::Default, - QStyleHintReturn* = 0) const; + int styleHint(StyleHint sh, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption & = QStyleOption::Default, + QStyleHintReturn* = 0, const QWidget * = 0) const; private: bool highlightCols; diff --git a/src/styles/qplatinumstyle.cpp b/src/styles/qplatinumstyle.cpp index 19c12a7..ff583e0 100644 --- a/src/styles/qplatinumstyle.cpp +++ b/src/styles/qplatinumstyle.cpp @@ -86,6 +86,8 @@ QPlatinumStyle::~QPlatinumStyle() */ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -98,7 +100,7 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, // sunken... if ( flags & Style_Sunken ) flags ^= Style_Sunken; - drawPrimitive( PE_ButtonBevel, p, r, cg, flags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, r, cg, flags, opt ); break; } case PE_ButtonTool: @@ -115,7 +117,7 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, fill = myCG.brush( QColorGroup::Button ); myCG.setBrush( QColorGroup::Mid, fill ); - drawPrimitive( PE_ButtonBevel, p, r, myCG, flags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, r, myCG, flags, opt ); break; } case PE_ButtonBevel: @@ -450,7 +452,7 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, } case PE_Indicator: { - drawPrimitive( PE_ButtonBevel, p, QRect(r.x(), r.y(), + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect(r.x(), r.y(), r.width() - 2, r.height()), cg, flags ); p->fillRect( r.x() + r.width() - 2, r.y(), 2, r.height(), @@ -606,14 +608,14 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, } case PE_ScrollBarAddLine: { - drawPrimitive( PE_ButtonBevel, p, r, cg, + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Sunken : Style_Raised) ); p->setPen( cg.shadow() ); p->drawRect( r ); drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowRight - : PE_ArrowDown), p, QRect(r.x() + 2, + : PE_ArrowDown), p, ceData, elementFlags, QRect(r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4), @@ -622,14 +624,14 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, } case PE_ScrollBarSubLine: { - drawPrimitive( PE_ButtonBevel, p, r, cg, + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Sunken : Style_Raised) ); p->setPen( cg.shadow() ); p->drawRect( r ); drawPrimitive( ((flags & Style_Horizontal) ? PE_ArrowLeft - : PE_ArrowUp ), p, QRect(r.x() + 2, + : PE_ArrowUp ), p, ceData, elementFlags, QRect(r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4), @@ -715,14 +717,14 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, { QPoint bo = p->brushOrigin(); p->setBrushOrigin( r.topLeft() ); - drawPrimitive( PE_ButtonBevel, p, r, cg, Style_Raised ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, r, cg, Style_Raised ); p->setBrushOrigin( bo ); drawRiffles( p, r.x(), r.y(), r.width(), r.height(), cg, flags & Style_Horizontal ); p->setPen( cg.shadow() ); p->drawRect( r ); if ( flags & Style_HasFocus ) { - drawPrimitive( PE_FocusRect, p, QRect(r.x() + 2, r.y() + 2, + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, QRect(r.x() + 2, r.y() + 2, r.width() - 5, r.height() - 5 ), cg, flags ); @@ -730,7 +732,7 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, break; } default: - QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt ); + QWindowsStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; } @@ -740,36 +742,36 @@ void QPlatinumStyle::drawPrimitive( PrimitiveElement pe, */ void QPlatinumStyle::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: { #ifndef QT_NO_PUSHBUTTON QColorGroup myCg( cg ); - const QPushButton *btn; int x1, y1, x2, y2; bool useBevelButton; SFlags flags; flags = Style_Default; - btn = (const QPushButton*)widget; - p->setBrushOrigin( -widget->backgroundOffset().x(), - -widget->backgroundOffset().y() ); + p->setBrushOrigin( -ceData.bgOffset.x(), + -ceData.bgOffset.y() ); // take care of the flags based on what we know... - if ( btn->isDown() ) + if ( elementFlags & CEF_IsDown ) flags |= Style_Down; - if ( btn->isOn() ) + if ( elementFlags & CEF_IsOn ) flags |= Style_On; - if ( btn->isEnabled() ) + if ( elementFlags & CEF_IsEnabled ) flags |= Style_Enabled; - if ( btn->isDefault() ) + if ( elementFlags & CEF_IsDefault ) flags |= Style_Default; - if (! btn->isFlat() && !(flags & Style_Down)) + if (! ( elementFlags & CEF_IsFlat ) && !(flags & Style_Down)) flags |= Style_Raised; r.coords( &x1, &y1, &x2, &y2 ); @@ -778,28 +780,28 @@ void QPlatinumStyle::drawControl( ControlElement element, p->setBrush( QBrush(cg.button(), NoBrush) ); QBrush fill; - if ( btn->isDown() ) { + if ( elementFlags & CEF_IsDown ) { fill = cg.brush( QColorGroup::Dark ); // this could be done differently, but this // makes a down Bezel drawn correctly... myCg.setBrush( QColorGroup::Mid, fill ); - } else if ( btn->isOn() ) { + } else if ( elementFlags & CEF_IsOn ) { fill = QBrush( cg.mid(), Dense4Pattern ); myCg.setBrush( QColorGroup::Mid, fill ); } // to quote the old QPlatinumStlye drawPushButton... // small or square image buttons as well as toggle buttons are // bevel buttons (what a heuristic....) - if ( btn->isToggleButton() - || ( btn->pixmap() && - (btn->width() * btn->height() < 1600 || - QABS( btn->width() - btn->height()) < 10 )) ) + if ( ( elementFlags & CEF_BiState ) + || ( (!ceData.fgPixmap.isNull()) && + (ceData.rect.width() * ceData.rect.height() < 1600 || + QABS( ceData.rect.width() - ceData.rect.height()) < 10 )) ) useBevelButton = TRUE; else useBevelButton = FALSE; - int diw = pixelMetric( PM_ButtonDefaultIndicator, widget ); - if ( btn->isDefault() ) { + int diw = pixelMetric( PM_ButtonDefaultIndicator, ceData, elementFlags, widget ); + if ( elementFlags & CEF_IsDefault ) { x1 += 1; y1 += 1; x2 -= 1; @@ -814,37 +816,37 @@ void QPlatinumStyle::drawControl( ControlElement element, cg2.setColor( QColorGroup::Button, cg.mid() ); if ( useBevelButton ) { - drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, myFlags, opt ); } else { - drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1, + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), cg2, myFlags, opt ); } } - if ( btn->isDefault() || btn->autoDefault() ) { + if ( ( elementFlags & CEF_IsDefault ) || ( elementFlags & CEF_AutoDefault ) ) { x1 += diw; y1 += diw; x2 -= diw; y2 -= diw; } - if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) { + if ( (!( elementFlags & CEF_IsFlat )) || ( elementFlags & CEF_IsOn ) || ( elementFlags & CEF_IsDown ) ) { if ( useBevelButton ) { // fix for toggle buttons... if ( flags & (Style_Down | Style_On) ) flags |= Style_Sunken; - drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, flags, opt ); } else { - drawPrimitive( PE_ButtonCommand, p, QRect( x1, y1, + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1 ), myCg, flags, opt ); @@ -860,16 +862,14 @@ void QPlatinumStyle::drawControl( ControlElement element, case CE_PushButtonLabel: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *btn; bool on; int x, y, w, h; SFlags flags; flags = Style_Default; - btn = (const QPushButton*)widget; - on = btn->isDown() || btn->isOn(); + on = (( elementFlags & CEF_IsDown ) || ( elementFlags & CEF_IsOn )); r.rect( &x, &y, &w, &h ); - if ( btn->isMenuButton() ) { - int dx = pixelMetric( PM_MenuButtonIndicator, widget ); + if ( elementFlags & CEF_IsMenuWidget ) { + int dx = pixelMetric( PM_MenuButtonIndicator, ceData, elementFlags, widget ); QColorGroup g = cg; int xx = x + w - dx - 4; @@ -884,23 +884,23 @@ void QPlatinumStyle::drawControl( ControlElement element, p->setPen( g.light() ); p->drawLine( xx + 2, yy + 2, xx + 2, yy + hh - 2 ); } - if ( btn->isEnabled() ) + if ( elementFlags & CEF_IsEnabled ) flags |= Style_Enabled; - drawPrimitive( PE_ArrowDown, p, QRect(x + w - dx - 1, y + 2, + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, QRect(x + w - dx - 1, y + 2, dx, h - 4), g, flags, opt ); w -= dx; } #ifndef QT_NO_ICONSET - if ( btn->iconSet() && !btn->iconSet()->isNull() ) { - QIconSet::Mode mode = btn->isEnabled() + if ( !ceData.iconSet.isNull() ) { + QIconSet::Mode mode = ( elementFlags & CEF_IsEnabled ) ? QIconSet::Normal : QIconSet::Disabled; - if ( mode == QIconSet::Normal && btn->hasFocus() ) + if ( mode == QIconSet::Normal && ( elementFlags & CEF_HasFocus ) ) mode = QIconSet::Active; QIconSet::State state = QIconSet::Off; - if ( btn->isToggleButton() && btn->isOn() ) + if ( ( elementFlags & CEF_BiState ) && ( elementFlags & CEF_IsOn ) ) state = QIconSet::On; - QPixmap pixmap = btn->iconSet()->pixmap( QIconSet::Small, + QPixmap pixmap = ceData.iconSet.pixmap( QIconSet::Small, mode, state ); int pixw = pixmap.width(); int pixh = pixmap.height(); @@ -911,19 +911,19 @@ void QPlatinumStyle::drawControl( ControlElement element, #endif drawItem( p, QRect( x, y, w, h ), AlignCenter | ShowPrefix, - btn->colorGroup(), btn->isEnabled(), - btn->pixmap(), btn->text(), -1, - on ? &btn->colorGroup().brightText() - : &btn->colorGroup().buttonText() ); - if ( btn->hasFocus() ) - drawPrimitive( PE_FocusRect, p, - subRect(SR_PushButtonFocusRect, widget), + ceData.colorGroup, ( elementFlags & CEF_IsEnabled ), + (ceData.fgPixmap.isNull())?NULL:&ceData.fgPixmap, ceData.text, -1, + on ? &ceData.colorGroup.brightText() + : &ceData.colorGroup.buttonText() ); + if ( elementFlags & CEF_HasFocus ) + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, + subRect(SR_PushButtonFocusRect, ceData, elementFlags, widget), cg, flags ); break; #endif } default: - QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt ); + QWindowsStyle::drawControl( element, p, ceData, elementFlags, r, cg, how, opt, widget ); break; } } @@ -932,13 +932,15 @@ void QPlatinumStyle::drawControl( ControlElement element, */ void QPlatinumStyle::drawComplexControl( ComplexControl control, 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 ( control ) { case CC_ComboBox: @@ -1010,8 +1012,8 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, p->drawPoint( x + w - 3, y + h - 3 ); if ( sub & SC_ComboBoxArrow ) { - QRect rTmp = querySubControlMetrics( CC_ComboBox, widget, - SC_ComboBoxArrow, opt ); + QRect rTmp = querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxArrow, opt, widget ); int xx = rTmp.x(), yy = rTmp.y(), ww = rTmp.width(), @@ -1078,21 +1080,19 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, } #ifndef QT_NO_COMBOBOX if ( sub & SC_ComboBoxEditField ) { - const QComboBox *cmb; - cmb = (const QComboBox*)widget; // sadly this is pretty much the windows code, except // for the first fillRect call... QRect re = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, - widget, - SC_ComboBoxEditField ), - widget ); - if ( cmb->hasFocus() && !cmb->editable() ) + ceData, elementFlags, + SC_ComboBoxEditField, QStyleOption::Default, widget ), + ceData, elementFlags ); + if ( ( elementFlags & CEF_HasFocus ) && (!( elementFlags & CEF_IsEditable )) ) p->fillRect( re.x() + 1, re.y() + 1, re.width() - 2, re.height() - 2, cg.brush( QColorGroup::Highlight ) ); - if ( cmb->hasFocus() ) { + if ( elementFlags & CEF_HasFocus ) { p->setPen( cg.highlightedText() ); p->setBackgroundColor( cg.highlight() ); } else { @@ -1100,16 +1100,16 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, p->setBackgroundColor( cg.background() ); } - if ( cmb->hasFocus() && !cmb->editable() ) { + if ( ( elementFlags & CEF_HasFocus ) && (!( elementFlags & CEF_IsEditable )) ) { QRect re = - QStyle::visualRect( subRect( SR_ComboBoxFocusRect, - cmb ), - widget ); - drawPrimitive( PE_FocusRect, p, re, cg, + QStyle::visualRect( subRect( SR_ComboBoxFocusRect, ceData, elementFlags, + widget ), + ceData, elementFlags ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); } - if ( cmb->editable() ) { + if ( elementFlags & CEF_IsEditable ) { // need this for the moment... // was the code in comboButton rect QRect ir( x + 3, y + 3, @@ -1128,15 +1128,14 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, case CC_Slider: { #ifndef QT_NO_SLIDER - const QSlider *slider = (const QSlider *) widget; - int thickness = pixelMetric( PM_SliderControlThickness, widget ); - int len = pixelMetric( PM_SliderLength, widget ); - int ticks = slider->tickmarks(); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); + int ticks = ceData.tickMarkSetting; - QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, - opt), - handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, - opt); + QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, + opt, widget), + handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, + opt, widget); if ((sub & SC_SliderGroove) && groove.isValid()) { p->fillRect( groove, cg.brush(QColorGroup::Background) ); @@ -1149,16 +1148,16 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, if ( ticks & QSlider::Below ) mid -= len / 8; - if ( slider->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { x = 0; y = groove.y() + mid - 3; - w = slider->width(); + w = ceData.rect.width(); h = 7; } else { x = groove.x() + mid - 3; y = 0; w = 7; - h = slider->height(); + h = ceData.rect.height(); } p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark )); @@ -1209,7 +1208,7 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, // ### end slider groove if ( how & Style_HasFocus ) - drawPrimitive( PE_FocusRect, p, groove, cg ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, groove, cg ); } if ((sub & SC_SliderHandle) && handle.isValid()) { @@ -1224,7 +1223,7 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, int mx = handle.width() / 2; int my = handle.height() / 2; - if ( slider->orientation() == Vertical ) { + if ( ceData.orientation == Vertical ) { // Background QBrush oldBrush = p->brush(); p->setBrush( cg.brush( QColorGroup::Button ) ); @@ -1303,15 +1302,15 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, } if ( sub & SC_SliderTickmarks ) - QCommonStyle::drawComplexControl( control, p, widget, r, + QCommonStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, how, SC_SliderTickmarks, - subActive, opt ); + subActive, opt, widget ); #endif break; } default: - QWindowsStyle::drawComplexControl( control, p, widget, r, cg, - how, sub, subActive, opt ); + QWindowsStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, + how, sub, subActive, opt, widget ); break; } } @@ -1321,18 +1320,18 @@ void QPlatinumStyle::drawComplexControl( ComplexControl control, /*!\reimp */ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch( control ) { #ifndef QT_NO_COMBOBOX case CC_ComboBox: - const QComboBox *cb; - cb = (const QComboBox *)widget; switch( sc ) { case SC_ComboBoxArrow: { - QRect ir = cb->rect(); + QRect ir = ceData.rect; int xx; if( QApplication::reverseLayout() ) xx = ir.x(); @@ -1346,22 +1345,20 @@ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, #endif #ifndef QT_NO_SCROLLBAR case CC_ScrollBar: { - const QScrollBar *sb; - sb = (const QScrollBar *)widget; - int sliderStart = sb->sliderStart(); - int sbextent = pixelMetric( PM_ScrollBarExtent, widget ); - int maxlen = ((sb->orientation() == Qt::Horizontal) ? - sb->width() : sb->height()) - ( sbextent * 2 ); + int sliderStart = ceData.startStep; + int sbextent = pixelMetric( PM_ScrollBarExtent, ceData, elementFlags, widget ); + int maxlen = ((ceData.orientation == Qt::Horizontal) ? + ceData.rect.width() : ceData.rect.height()) - ( sbextent * 2 ); int sliderlen; // calculate length - if ( sb->maxValue() != sb->minValue() ) { - uint range = sb->maxValue() - sb->minValue(); - sliderlen = ( sb->pageStep() * maxlen ) / - ( range + sb->pageStep() ); + if ( ceData.maxSteps != ceData.minSteps ) { + uint range = ceData.maxSteps - ceData.minSteps; + sliderlen = ( ceData.pageStep * maxlen ) / + ( range + ceData.pageStep ); - int slidermin = pixelMetric( PM_ScrollBarSliderMin, widget ); + int slidermin = pixelMetric( PM_ScrollBarSliderMin, ceData, elementFlags, widget ); if ( sliderlen < slidermin || range > INT_MAX / 2 ) sliderlen = slidermin; if ( sliderlen > maxlen ) @@ -1372,33 +1369,33 @@ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, switch ( sc ) { case SC_ScrollBarSubLine: - if ( sb->orientation() == Qt::Horizontal ) { - int buttonw = QMIN( sb->width() / 2, sbextent ); - return QRect( sb->width() - 2 * buttonw, 0, buttonw, sbextent ); + if ( ceData.orientation == Qt::Horizontal ) { + int buttonw = QMIN( ceData.rect.width() / 2, sbextent ); + return QRect( ceData.rect.width() - 2 * buttonw, 0, buttonw, sbextent ); } else { - int buttonh = QMIN( sb->height() / 2, sbextent ); - return QRect( 0, sb->height() - 2 * buttonh, sbextent, buttonh ); + int buttonh = QMIN( ceData.rect.height() / 2, sbextent ); + return QRect( 0, ceData.rect.height() - 2 * buttonh, sbextent, buttonh ); } case SC_ScrollBarAddLine: - if ( sb->orientation() == Qt::Horizontal ) { - int buttonw = QMIN( sb->width() / 2, sbextent ); - return QRect( sb->width() - buttonw, 0, sbextent, buttonw ); + if ( ceData.orientation == Qt::Horizontal ) { + int buttonw = QMIN( ceData.rect.width() / 2, sbextent ); + return QRect( ceData.rect.width() - buttonw, 0, sbextent, buttonw ); } else { - int buttonh = QMIN( sb->height() / 2, sbextent ); - return QRect(0, sb->height() - buttonh, sbextent, buttonh ); + int buttonh = QMIN( ceData.rect.height() / 2, sbextent ); + return QRect(0, ceData.rect.height() - buttonh, sbextent, buttonh ); } case SC_ScrollBarSubPage: - if ( sb->orientation() == Qt::Horizontal ) + if ( ceData.orientation == Qt::Horizontal ) return QRect( 1, 0, sliderStart, sbextent ); return QRect( 0, 1, sbextent, sliderStart ); case SC_ScrollBarAddPage: - if ( sb->orientation() == Qt::Horizontal ) + if ( ceData.orientation == Qt::Horizontal ) return QRect( sliderStart + sliderlen, 0, maxlen - sliderStart - sliderlen, sbextent ); return QRect( 0, sliderStart + sliderlen, sbextent, maxlen - sliderStart - sliderlen ); case SC_ScrollBarGroove: - if ( sb->orientation() == Qt::Horizontal ) - return QRect( 1, 0, sb->width() - sbextent * 2, sb->height() ); - return QRect( 0, 1, sb->width(), sb->height() - sbextent * 2 ); + if ( ceData.orientation == Qt::Horizontal ) + return QRect( 1, 0, ceData.rect.width() - sbextent * 2, ceData.rect.height() ); + return QRect( 0, 1, ceData.rect.width(), ceData.rect.height() - sbextent * 2 ); default: break; } @@ -1406,13 +1403,11 @@ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, #endif #ifndef QT_NO_SLIDER case CC_Slider: { - - const QSlider *slider = (const QSlider *) widget; - int tickOffset = pixelMetric( PM_SliderTickmarkOffset, widget); - int thickness = pixelMetric( PM_SliderControlThickness, widget); + int tickOffset = pixelMetric( PM_SliderTickmarkOffset, ceData, elementFlags, widget); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget); int mid = thickness / 2; - int ticks = slider->tickmarks(); - int len = pixelMetric( PM_SliderLength, widget ); + int ticks = ceData.tickMarkSetting; + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); switch ( sc ) { case SC_SliderGroove: @@ -1420,9 +1415,9 @@ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, mid += len / 8; if ( ticks & QSlider::Below ) mid -= len / 8; - if ( slider->orientation() == QSlider::Horizontal ) - return QRect( 0, tickOffset, slider->width(), thickness ); - return QRect( tickOffset, 0, thickness, slider->height() ); + if ( ceData.orientation == QSlider::Horizontal ) + return QRect( 0, tickOffset, ceData.rect.width(), thickness ); + return QRect( tickOffset, 0, thickness, ceData.rect.height() ); default: break; } @@ -1431,13 +1426,13 @@ QRect QPlatinumStyle::querySubControlMetrics( ComplexControl control, default: break; } - return QWindowsStyle::querySubControlMetrics( control, widget, sc, opt ); + return QWindowsStyle::querySubControlMetrics( control, ceData, elementFlags, sc, opt, widget ); } /*!\reimp */ -int QPlatinumStyle::pixelMetric( PixelMetric metric, +int QPlatinumStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { int ret; @@ -1466,7 +1461,7 @@ int QPlatinumStyle::pixelMetric( PixelMetric metric, ret = -1; break; default: - ret = QWindowsStyle::pixelMetric( metric, widget ); + ret = QWindowsStyle::pixelMetric( metric, ceData, elementFlags, widget ); break; } return ret; @@ -1474,19 +1469,19 @@ int QPlatinumStyle::pixelMetric( PixelMetric metric, /*!\reimp */ -QRect QPlatinumStyle::subRect( SubRect r, const QWidget *widget ) const +QRect QPlatinumStyle::subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { QRect rect; switch ( r ) { case SR_ComboBoxFocusRect: { - QRect tmpR = widget->rect(); + QRect tmpR = ceData.rect; rect = QRect( tmpR.x() + 4, tmpR.y() + 4, tmpR.width() - 8 - 16, tmpR.height() - 8 ); break; } default: - rect = QWindowsStyle::subRect( r, widget ); + rect = QWindowsStyle::subRect( r, ceData, elementFlags, widget ); break; } return rect; diff --git a/src/styles/qplatinumstyle.h b/src/styles/qplatinumstyle.h index 8c83aea..6bf409f 100644 --- a/src/styles/qplatinumstyle.h +++ b/src/styles/qplatinumstyle.h @@ -65,6 +65,8 @@ public: // new Style Stuff void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -72,15 +74,18 @@ public: void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; void drawComplexControl( ComplexControl control, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, @@ -90,16 +95,19 @@ public: SCFlags sub = (uint)SC_All, #endif SCFlags subActive = SC_None, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; QRect querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - int pixelMetric( PixelMetric metric, const QWidget *widget = 0 ) const; + int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; - QRect subRect( SubRect r, const QWidget *widget ) const; + QRect subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const; protected: QColor mixedColor(const QColor &, const QColor &) const; diff --git a/src/styles/qsgistyle.cpp b/src/styles/qsgistyle.cpp index 1bfc113..a66fcda 100644 --- a/src/styles/qsgistyle.cpp +++ b/src/styles/qsgistyle.cpp @@ -65,7 +65,7 @@ struct SliderLastPosition { SliderLastPosition() : rect(0,-1,0,-1), slider(0) {} QRect rect; - const QSlider* slider; + const void* slider; }; #endif @@ -74,7 +74,7 @@ struct ScrollbarLastPosition { ScrollbarLastPosition() : rect( 0,-1, 0,-1 ), scrollbar(0) {} QRect rect; - const QScrollBar *scrollbar; + const void* scrollbar; }; #endif @@ -86,7 +86,7 @@ public: { } - const QWidget *hotWidget; + const void* hotWidget; QPoint mousePos; #ifndef QT_NO_SCROLLBAR ScrollbarLastPosition lastScrollbarRect; @@ -136,10 +136,10 @@ QSGIStyle::~QSGIStyle() bold italic font for menu options. */ void -QSGIStyle::polish( QApplication* app) +QSGIStyle::applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr ) { isApplicationStyle = 1; - QMotifStyle::polish( app ); + QMotifStyle::polish( ceData, elementFlags, ptr ); QPalette pal = QApplication::palette(); // check this on SGI-Boxes @@ -181,7 +181,7 @@ QSGIStyle::polish( QApplication* app) /*! \reimp */ void -QSGIStyle::unPolish( QApplication* /* app */ ) +QSGIStyle::applicationUnPolish( QStyleControlElementData, ControlElementFlags, void * ) { QFont f = QApplication::font(); QApplication::setFont( f, TRUE ); // get rid of the special fonts for special widget classes @@ -194,9 +194,9 @@ QSGIStyle::unPolish( QApplication* /* app */ ) hovering. */ void -QSGIStyle::polish( QWidget* w ) +QSGIStyle::polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr ) { - QMotifStyle::polish(w); + QMotifStyle::polish(ceData, elementFlags, ptr); if ( !isApplicationStyle ) { QPalette sgiPal = QApplication::palette(); @@ -214,7 +214,7 @@ QSGIStyle::polish( QWidget* w ) sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().base() ); } - if ( ::qt_cast<QLineEdit*>(w) || ::qt_cast<QTextEdit*>(w) ) { + if ( (ceData.widgetObjectTypes.contains("QLineEdit")) || (ceData.widgetObjectTypes.contains("QTextEdit")) ) { // different basecolor and highlighting in Q(Multi)LineEdit sgiPal.setColor( QColorGroup::Base, QColor(211,181,181) ); sgiPal.setColor( QPalette::Active, QColorGroup::Highlight, sgiPal.active().midlight() ); @@ -224,89 +224,89 @@ QSGIStyle::polish( QWidget* w ) sgiPal.setColor( QPalette::Disabled, QColorGroup::Highlight, sgiPal.disabled().midlight() ); sgiPal.setColor( QPalette::Disabled, QColorGroup::HighlightedText, sgiPal.disabled().text() ); - } else if ( ::qt_cast<QMenuBar*>(w) || ::qt_cast<QToolBar*>(w) ) { + } else if ( (ceData.widgetObjectTypes.contains("QMenuBar")) || (ceData.widgetObjectTypes.contains("QToolBar")) ) { sgiPal.setColor( QColorGroup::Button, sgiPal.active().midlight() ); } - w->setPalette( sgiPal ); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetPalette, QStyleWidgetActionRequestData(sgiPal)); } - if ( ::qt_cast<QButton*>(w) || ::qt_cast<QSlider*>(w) || ::qt_cast<QScrollBar*>(w) ) { - w->installEventFilter( this ); - w->setMouseTracking( TRUE ); + if ( (ceData.widgetObjectTypes.contains("QButton")) || (ceData.widgetObjectTypes.contains("QSlider")) || (ceData.widgetObjectTypes.contains("QScrollBar")) ) { + installObjectEventHandler(ceData, elementFlags, ptr, this); + widgetActionRequest(ceData, elementFlags, ptr, WAR_EnableMouseTracking); #ifndef QT_NO_SCROLLBAR - if ( ::qt_cast<QScrollBar*>(w) ) - w->setBackgroundMode( QWidget::NoBackground ); + if ( ceData.widgetObjectTypes.contains("QScrollBar") ) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundMode, QStyleWidgetActionRequestData(QWidget::NoBackground)); + } #endif - } else if ( ::qt_cast<QComboBox*>(w) ) { + } else if ( ceData.widgetObjectTypes.contains("QComboBox") ) { QFont f = QApplication::font(); f.setBold( TRUE ); f.setItalic( TRUE ); - w->setFont( f ); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetFont, QStyleWidgetActionRequestData(f)); #ifndef QT_NO_MENUBAR - } else if ( ::qt_cast<QMenuBar*>(w) ) { - ((QFrame*) w)->setFrameStyle(QFrame::StyledPanel | QFrame::Raised); - w->setBackgroundMode( QWidget::PaletteBackground ); + } else if ( ceData.widgetObjectTypes.contains("QMenuBar") ) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetStyle, QStyleWidgetActionRequestData(QFrame::StyledPanel | QFrame::Raised)); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundMode, QStyleWidgetActionRequestData(QWidget::PaletteBackground)); QFont f = QApplication::font(); f.setBold( TRUE ); f.setItalic( TRUE ); - w->setFont( f ); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetFont, QStyleWidgetActionRequestData(f)); #endif #ifndef QT_NO_POPUPMENU - } else if ( ::qt_cast<QPopupMenu*>(w) ) { - ((QFrame*) w)->setLineWidth( pixelMetric( PM_DefaultFrameWidth ) + 1 ); + } else if ( ceData.widgetObjectTypes.contains("QPopupMenu") ) { + QStyleWidgetActionRequestData requestData; + widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetLineWidth, QStyleWidgetActionRequestData(pixelMetric( PM_DefaultFrameWidth, QStyleControlElementData(), CEF_None ) + 1)); QFont f = QApplication::font(); f.setBold( TRUE ); f.setItalic( TRUE ); - w->setFont( f ); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetFont, QStyleWidgetActionRequestData(f)); #endif - } else if ( ::qt_cast<QToolBar*>(w) || w->inherits("QToolBarSeparator") ) { - w->setBackgroundMode( QWidget::PaletteBackground ); + } else if ( (ceData.widgetObjectTypes.contains("QToolBar")) || (ceData.widgetObjectTypes.contains("QToolBarSeparator")) ) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetBackgroundMode, QStyleWidgetActionRequestData(QWidget::PaletteBackground)); } } /*! \reimp */ void -QSGIStyle::unPolish( QWidget* w ) +QSGIStyle::unPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr ) { - if ( ::qt_cast<QButton*>(w) || ::qt_cast<QSlider*>(w) || ::qt_cast<QScrollBar*>(w) ) { - w->removeEventFilter( this ); + if ( (ceData.widgetObjectTypes.contains("QButton")) || (ceData.widgetObjectTypes.contains("QSlider")) || (ceData.widgetObjectTypes.contains("QScrollBar")) ) { + removeObjectEventHandler(ceData, elementFlags, ptr, this); #ifndef QT_NO_POPUPMENU - } else if ( ::qt_cast<QPopupMenu*>(w) ) { - ((QFrame*)w)->setLineWidth( pixelMetric( PM_DefaultFrameWidth ) ); - w->setFont( QApplication::font() ); + } else if ( ceData.widgetObjectTypes.contains("QPopupMenu") ) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_FrameSetLineWidth, QStyleWidgetActionRequestData(pixelMetric( PM_DefaultFrameWidth, QStyleControlElementData(), CEF_None ))); + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetFont, QStyleWidgetActionRequestData(QApplication::font())); #endif #if !defined(QT_NO_MENUBAR) || !defined(QT_NO_COMBOBOX) - } else if ( ::qt_cast<QMenuBar*>(w) || ::qt_cast<QComboBox*>(w) ) { - w->setFont( QApplication::font() ); + } else if ( (ceData.widgetObjectTypes.contains("QMenuBar")) || (ceData.widgetObjectTypes.contains("QComboBox")) ) { + widgetActionRequest(ceData, elementFlags, ptr, WAR_SetFont, QStyleWidgetActionRequestData(QApplication::font())); #endif } } /*! \reimp */ -bool QSGIStyle::eventFilter( QObject* o, QEvent* e ) +bool QSGIStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ) { - if ( !o->isWidgetType() || e->type() == QEvent::Paint ) - return QMotifStyle::eventFilter( o, e ); - - QWidget *widget = (QWidget*)o; + if ( (!(ceData.widgetObjectTypes.contains("QWidget"))) || (e->type() == QEvent::Paint) ) + return QMotifStyle::objectEventHandler( ceData, elementFlags, source, e ); switch ( e->type() ) { case QEvent::MouseButtonPress: { #ifndef QT_NO_SCROLLBAR - if ( ::qt_cast<QScrollBar*>(widget) ) { - d->lastScrollbarRect.rect = ((QScrollBar*)widget)->sliderRect(); - d->lastScrollbarRect.scrollbar = ((QScrollBar*)widget); - widget->repaint( FALSE ); + if (ceData.widgetObjectTypes.contains("QScrollBar")) { + d->lastScrollbarRect.rect = ceData.sliderRect; + d->lastScrollbarRect.scrollbar = source; + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); } else #endif { #ifndef QT_NO_SLIDER - if ( ::qt_cast<QSlider*>(widget) ) { - d->lastSliderRect.rect = ((QSlider*)widget)->sliderRect(); - d->lastSliderRect.slider = ((QSlider*)widget); - widget->repaint( FALSE ); + if (ceData.widgetObjectTypes.contains("QSlider")) { + d->lastSliderRect.rect = ceData.sliderRect; + d->lastSliderRect.slider = source; + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); } #endif } @@ -317,52 +317,52 @@ bool QSGIStyle::eventFilter( QObject* o, QEvent* e ) { if ( 0 ) { #ifndef QT_NO_SCROLLBAR - } else if ( ::qt_cast<QScrollBar*>(widget) ) { + } else if (ceData.widgetObjectTypes.contains("QScrollBar")) { QRect oldRect = d->lastScrollbarRect.rect; d->lastScrollbarRect.rect = QRect( 0, -1, 0, -1 ); - widget->repaint( oldRect, FALSE ); + widgetActionRequest(ceData, elementFlags, source, WAR_RepaintRect, QStyleWidgetActionRequestData(oldRect)); #endif #ifndef QT_NO_SLIDER - } else if ( ::qt_cast<QSlider*>(widget) ) { + } else if (ceData.widgetObjectTypes.contains("QSlider")) { QRect oldRect = d->lastSliderRect.rect; d->lastSliderRect.rect = QRect( 0, -1, 0, -1 ); - widget->repaint( oldRect, FALSE ); + widgetActionRequest(ceData, elementFlags, source, WAR_RepaintRect, QStyleWidgetActionRequestData(oldRect)); #endif } } break; case QEvent::MouseMove: - if ( !widget->isActiveWindow() ) + if ( !(elementFlags & CEF_IsActiveWindow) ) break; if ( ((QMouseEvent*)e)->button() ) break; - d->hotWidget = widget; + d->hotWidget = source; d->mousePos = ((QMouseEvent*)e)->pos(); - widget->repaint( FALSE ); + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); break; case QEvent::Enter: - if ( !widget->isActiveWindow() ) + if ( !(elementFlags & CEF_IsActiveWindow) ) break; - d->hotWidget = widget; - widget->repaint( FALSE ); + d->hotWidget = source; + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); break; case QEvent::Leave: - if ( !widget->isActiveWindow() ) + if ( !(elementFlags & CEF_IsActiveWindow) ) break; - if ( widget == d->hotWidget) { + if ( source == d->hotWidget) { d->hotWidget = 0; - widget->repaint( FALSE ); + widgetActionRequest(ceData, elementFlags, source, WAR_Repaint); } break; default: break; } - return QMotifStyle::eventFilter( o, e ); + return QMotifStyle::objectEventHandler( ceData, elementFlags, source, e ); } static const int sgiItemFrame = 2; // menu item frame width @@ -375,7 +375,7 @@ static const int sgiTabSpacing = 12; // space between text and tab static const int sgiCheckMarkSpace = 20; /*! \reimp */ -int QSGIStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const +int QSGIStyle::pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { switch ( metric ) { case PM_DefaultFrameWidth: @@ -401,7 +401,7 @@ int QSGIStyle::pixelMetric( PixelMetric metric, const QWidget *widget ) const default: break; } - return QMotifStyle::pixelMetric( metric, widget ); + return QMotifStyle::pixelMetric( metric, ceData, elementFlags, widget ); } static void drawPanel( QPainter *p, int x, int y, int w, int h, @@ -552,6 +552,8 @@ static void get_combo_parameters( const QRect &r, /*! \reimp */ void QSGIStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -562,7 +564,7 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, const int w = r.width(); const int h = r.height(); const bool sunken = flags & ( Style_Sunken | Style_Down | Style_On ); - const int defaultFrameWidth = pixelMetric( PM_DefaultFrameWidth ); + const int defaultFrameWidth = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ); bool hot = ( flags & Style_MouseOver ) && ( flags & Style_Enabled ); switch ( pe ) { @@ -588,7 +590,7 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, case PE_ButtonBevel: case PE_ButtonTool: { - drawPrimitive( PE_ButtonCommand, p, QRect( x+1, y+1, w-2, h-2 ), cg, flags, opt ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, QRect( x+1, y+1, w-2, h-2 ), cg, flags, opt ); QPen oldPen = p->pen(); QPointArray a; @@ -642,11 +644,11 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, QRect er = r; er.addCoords( 1, 1, -1, -1 ); int iflags = flags & ~Style_On; - drawPrimitive( PE_ButtonBevel, p, er, cg, iflags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, er, cg, iflags, opt ); if ( !(flags & QStyle::Style_Off) ) { er = r; er.addCoords( 1, 2, 1, 1 ); - drawPrimitive( PE_CheckMark, p, er, cg, flags, opt ); + drawPrimitive( PE_CheckMark, p, ceData, elementFlags, er, cg, flags, opt ); } } break; @@ -795,17 +797,17 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, case PE_ScrollBarSubLine: if ( !r.contains( d->mousePos ) && !(flags & Style_Active) ) flags &= ~Style_MouseOver; - drawPrimitive( PE_ButtonCommand, p, r, cg, flags, opt ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, r, cg, flags, opt ); drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp), - p, r, cg, Style_Enabled | flags); + p, ceData, elementFlags, r, cg, Style_Enabled | flags); break; case PE_ScrollBarAddLine: if ( !r.contains( d->mousePos ) ) flags &= ~Style_MouseOver; - drawPrimitive( PE_ButtonCommand, p, r, cg, flags, opt ); + drawPrimitive( PE_ButtonCommand, p, ceData, elementFlags, r, cg, flags, opt ); drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown), - p, r, cg, Style_Enabled | flags); + p, ceData, elementFlags, r, cg, Style_Enabled | flags); break; case PE_ScrollBarSubPage: @@ -825,7 +827,7 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, QPixmap pm( r.width(), r.height() ); QPainter bp( &pm ); - drawPrimitive(PE_ButtonBevel, &bp, QRect(0,0,r.width(),r.height()), cg, flags | Style_Enabled | Style_Raised); + drawPrimitive(PE_ButtonBevel, &bp, ceData, elementFlags, QRect(0,0,r.width(),r.height()), cg, flags | Style_Enabled | Style_Raised); if ( flags & Style_Horizontal ) { const int sliderM = r.width() / 2; if ( r.width() > 20 ) { @@ -853,7 +855,7 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, case PE_Splitter: { const int motifOffset = 10; - int sw = pixelMetric( PM_SplitterWidth ); + int sw = pixelMetric( PM_SplitterWidth, ceData, elementFlags ); if ( flags & Style_Horizontal ) { int xPos = x + w/2; int kPos = motifOffset; @@ -862,7 +864,7 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, qDrawShadeLine( p, xPos, kPos + kSize - 1 , xPos, h, cg ); - drawPrimitive( PE_ButtonBevel, p, QRect(xPos-sw/2+1, kPos, kSize, kSize+1), cg, flags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect(xPos-sw/2+1, kPos, kSize, kSize+1), cg, flags, opt ); qDrawShadeLine( p, xPos+2, 0, xPos, kPos, cg ); } else { int yPos = y + h/2; @@ -870,14 +872,14 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, int kSize = sw - 2; qDrawShadeLine( p, 0, yPos, kPos, yPos, cg ); - drawPrimitive( PE_ButtonBevel, p, QRect( kPos, yPos-sw/2+1, kSize+1, kSize ), cg, flags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect( kPos, yPos-sw/2+1, kSize+1, kSize ), cg, flags, opt ); qDrawShadeLine( p, kPos + kSize+1, yPos, w, yPos, cg ); } } break; default: - QMotifStyle::drawPrimitive( pe, p, r, cg, flags, opt ); + QMotifStyle::drawPrimitive( pe, p, ceData, elementFlags, r, cg, flags, opt ); break; } } @@ -885,11 +887,13 @@ void QSGIStyle::drawPrimitive( PrimitiveElement pe, /*! \reimp */ void QSGIStyle::drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { if ( widget == d->hotWidget ) flags |= Style_MouseOver; @@ -898,17 +902,16 @@ void QSGIStyle::drawControl( ControlElement element, case CE_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *btn = (QPushButton*)widget; int x1, y1, x2, y2; r.coords( &x1, &y1, &x2, &y2 ); p->setPen( cg.foreground() ); p->setBrush( QBrush( cg.button(),Qt::NoBrush ) ); - p->setBrushOrigin( -widget->backgroundOffset().x(), - -widget->backgroundOffset().y() ); + p->setBrushOrigin( -ceData.bgOffset.x(), + -ceData.bgOffset.y() ); - int diw = pixelMetric( QStyle::PM_ButtonDefaultIndicator ); - if ( btn->isDefault() || btn->autoDefault() ) { + int diw = pixelMetric( QStyle::PM_ButtonDefaultIndicator, ceData, elementFlags ); + if ( ( elementFlags & CEF_IsDefault ) || ( elementFlags & CEF_AutoDefault ) ) { x1 += diw; y1 += diw; x2 -= diw; @@ -916,7 +919,7 @@ void QSGIStyle::drawControl( ControlElement element, } QPointArray a; - if ( btn->isDefault() ) { + if ( elementFlags & CEF_IsDefault ) { if ( diw == 0 ) { a.setPoints( 9, x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1, @@ -928,13 +931,13 @@ void QSGIStyle::drawControl( ControlElement element, x2 -= 2; y2 -= 2; } else { - qDrawShadePanel( p, btn->rect(), cg, TRUE ); + qDrawShadePanel( p, ceData.rect, cg, TRUE ); } } QBrush fill = cg.brush( QColorGroup::Button ); - if ( !btn->isFlat() || btn->isOn() || btn->isDown() ) - drawPrimitive( PE_ButtonBevel, p, QRect( x1, y1, x2-x1+1, y2-y1+1 ), cg, flags, opt ); + if ( (!( elementFlags & CEF_IsFlat )) || ( elementFlags & CEF_IsOn ) || ( elementFlags & CEF_IsDown ) ) + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, QRect( x1, y1, x2-x1+1, y2-y1+1 ), cg, flags, opt ); if ( p->brush().style() != Qt::NoBrush ) p->setBrush( Qt::NoBrush ); @@ -945,16 +948,15 @@ void QSGIStyle::drawControl( ControlElement element, case CE_PopupMenuItem: { #ifndef QT_NO_POPUPMENU - if (! widget || opt.isDefault()) + if ( ( elementFlags & CEF_UseGenericParameters ) || opt.isDefault()) break; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; - const QPopupMenu *popupmenu = (const QPopupMenu *) widget; int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = ! (flags & Style_Enabled); - bool checkable = popupmenu->isCheckable(); + bool checkable = ( elementFlags & CEF_IsCheckable ); bool act = flags & Style_Active; int x, y, w, h; @@ -973,7 +975,7 @@ void QSGIStyle::drawControl( ControlElement element, int pw = sgiItemFrame; if ( act && !dis ) { - if ( pixelMetric( PM_DefaultFrameWidth ) > 1 ) + if ( pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags ) > 1 ) drawPanel( p, x, y, w, h, cg, FALSE, pw, &cg.brush( QColorGroup::Light ) ); else @@ -1024,12 +1026,12 @@ void QSGIStyle::drawControl( ControlElement element, if ( mi->isChecked() ) { QRect er( x+sgiItemFrame+1, y+sgiItemFrame+3, - pixelMetric(PM_IndicatorWidth), - pixelMetric(PM_IndicatorHeight) ); + pixelMetric(PM_IndicatorWidth, ceData, elementFlags), + pixelMetric(PM_IndicatorHeight, ceData, elementFlags) ); er.addCoords( 1, 1, -1, -1 ); - drawPrimitive( PE_ButtonBevel, p, er, cg, cflags, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, er, cg, cflags, opt ); er.addCoords( 0, 1, 1, 1 ); - drawPrimitive( PE_CheckMark, p, er, cg, cflags | Style_On, opt ); + drawPrimitive( PE_CheckMark, p, ceData, elementFlags, er, cg, cflags | Style_On, opt ); } } } @@ -1082,7 +1084,7 @@ void QSGIStyle::drawControl( ControlElement element, } if ( mi->popup() ) { int dim = (h-2*sgiItemFrame) / 2; - drawPrimitive( PE_ArrowRight, p, QRect( x+w-sgiArrowHMargin-sgiItemFrame-dim, y+h/2-dim/2, dim, dim ), cg, flags ); + drawPrimitive( PE_ArrowRight, p, ceData, elementFlags, QRect( x+w-sgiArrowHMargin-sgiItemFrame-dim, y+h/2-dim/2, dim, dim ), cg, flags ); } #endif } @@ -1128,11 +1130,11 @@ void QSGIStyle::drawControl( ControlElement element, break; case CE_CheckBox: - QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt ); + QMotifStyle::drawControl( element, p, ceData, elementFlags, r, cg, flags, opt, widget ); break; default: - QMotifStyle::drawControl( element, p, widget, r, cg, flags, opt ); + QMotifStyle::drawControl( element, p, ceData, elementFlags, r, cg, flags, opt, widget ); break; } } @@ -1140,13 +1142,15 @@ void QSGIStyle::drawControl( ControlElement element, /*! \reimp */ void QSGIStyle::drawComplexControl( ComplexControl control, QPainter *p, - const QWidget* widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect& r, const QColorGroup& cg, SFlags flags, SCFlags sub, SCFlags subActive, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget* widget ) const { if ( widget == d->hotWidget ) flags |= Style_MouseOver; @@ -1155,33 +1159,31 @@ void QSGIStyle::drawComplexControl( ComplexControl control, case CC_Slider: { #ifndef QT_NO_SLIDER - const QSlider * slider = (const QSlider *) widget; - - QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, - opt), - handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, - opt); + QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, + opt, widget), + handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, + opt, widget); if ((sub & SC_SliderGroove) && groove.isValid()) { QRegion region( groove ); if ( ( sub & SC_SliderHandle ) && handle.isValid() ) region = region.subtract( handle ); - if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() ) + if ( d->lastSliderRect.slider == widget && d->lastSliderRect.rect.isValid() ) region = region.subtract( d->lastSliderRect.rect ); p->setClipRegion( region ); QRect grooveTop = groove; grooveTop.addCoords( 1, 1, -1, -1 ); - drawPrimitive( PE_ButtonBevel, p, grooveTop, cg, flags & ~Style_MouseOver, opt ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, grooveTop, cg, flags & ~Style_MouseOver, opt ); if ( flags & Style_HasFocus ) { - QRect fr = subRect( SR_SliderFocusRect, widget ); - drawPrimitive( PE_FocusRect, p, fr, cg, flags & ~Style_MouseOver ); + QRect fr = subRect( SR_SliderFocusRect, ceData, elementFlags, widget ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, fr, cg, flags & ~Style_MouseOver ); } - if ( d->lastSliderRect.slider == slider && d->lastSliderRect.rect.isValid() ) { + if ( d->lastSliderRect.slider == widget && d->lastSliderRect.rect.isValid() ) { if ( ( sub & SC_SliderHandle ) && handle.isValid() ) { - region = widget->rect(); + region = ceData.rect; region = region.subtract( handle ); p->setClipRegion( region ); } else { @@ -1195,9 +1197,9 @@ void QSGIStyle::drawComplexControl( ComplexControl control, if (( sub & SC_SliderHandle ) && handle.isValid()) { if ( flags & Style_MouseOver && !handle.contains( d->mousePos ) && subActive != SC_SliderHandle ) flags &= ~Style_MouseOver; - drawPrimitive( PE_ButtonBevel, p, handle, cg, flags ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, handle, cg, flags ); - if ( slider->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { QCOORD mid = handle.x() + handle.width() / 2; qDrawShadeLine( p, mid, handle.y(), mid, handle.y() + handle.height() - 2, @@ -1211,50 +1213,48 @@ void QSGIStyle::drawComplexControl( ComplexControl control, } if ( sub & SC_SliderTickmarks ) - QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags, + QMotifStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, SC_SliderTickmarks, subActive, - opt ); + opt, widget ); #endif break; } case CC_ComboBox: { #ifndef QT_NO_COMBOBOX - const QComboBox * cb = (QComboBox *) widget; - if (sub & SC_ComboBoxFrame) { QRect fr = - QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, - SC_ComboBoxFrame ), cb ); - drawPrimitive( PE_ButtonBevel, p, fr, cg, flags ); + QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxFrame, QStyleOption::Default, widget ), ceData, elementFlags ); + drawPrimitive( PE_ButtonBevel, p, ceData, elementFlags, fr, cg, flags ); } if ( sub & SC_ComboBoxArrow ) { p->save(); QRect er = - QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, SC_ComboBoxArrow ), cb ); + QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, SC_ComboBoxArrow, QStyleOption::Default, widget ), ceData, elementFlags ); er.addCoords( 0, 3, 0, 0 ); - drawPrimitive( PE_ArrowDown, p, er, cg, flags | Style_Enabled, opt ); + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, er, cg, flags | Style_Enabled, opt ); int awh, ax, ay, sh, sy, dh, ew; - get_combo_parameters( widget->rect(), ew, awh, ax, ay, sh, dh, sy ); + get_combo_parameters( ceData.rect, ew, awh, ax, ay, sh, dh, sy ); QBrush arrow = cg.brush( QColorGroup::Dark ); p->fillRect( ax, sy-1, awh, sh, arrow ); p->restore(); - if ( cb->hasFocus() ) { - QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), cb ); - drawPrimitive( PE_FocusRect, p, re, cg ); + if ( elementFlags & CEF_HasFocus ) { + QRect re = QStyle::visualRect( subRect( SR_ComboBoxFocusRect, ceData, elementFlags, widget ), ceData, elementFlags ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, re, cg ); } } if ( sub & SC_ComboBoxEditField ) { - if ( cb->editable() ) { + if ( elementFlags & CEF_IsEditable ) { QRect er = - QStyle::visualRect( querySubControlMetrics( CC_ComboBox, cb, - SC_ComboBoxEditField ), cb ); + QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxEditField, QStyleOption::Default, widget ), ceData, elementFlags ); er.addCoords( -1, -1, 1, 1); qDrawShadePanel( p, QRect( er.x()-1, er.y()-1, er.width()+2, er.height()+2 ), @@ -1269,27 +1269,26 @@ void QSGIStyle::drawComplexControl( ComplexControl control, case CC_ScrollBar: { #ifndef QT_NO_SCROLLBAR - QScrollBar *scrollbar = (QScrollBar*)widget; - bool maxedOut = (scrollbar->minValue() == scrollbar->maxValue()); + bool maxedOut = (ceData.minSteps == ceData.maxSteps); if ( maxedOut ) flags &= ~Style_Enabled; - QRect handle = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSlider, opt ), widget ); + QRect handle = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, ceData, elementFlags, SC_ScrollBarSlider, opt, widget ), ceData, elementFlags ); if ( sub & SC_ScrollBarGroove ) { } if ( sub & SC_ScrollBarAddLine ) { - QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddLine, opt ), widget ); - drawPrimitive( PE_ScrollBarAddLine, p, er, cg, flags, opt ); + QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, ceData, elementFlags, SC_ScrollBarAddLine, opt, widget ), ceData, elementFlags ); + drawPrimitive( PE_ScrollBarAddLine, p, ceData, elementFlags, er, cg, flags, opt ); } if ( sub & SC_ScrollBarSubLine ) { - QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubLine, opt ), widget ); - drawPrimitive( PE_ScrollBarSubLine, p, er, cg, flags, opt ); + QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, ceData, elementFlags, SC_ScrollBarSubLine, opt, widget ), ceData, elementFlags ); + drawPrimitive( PE_ScrollBarSubLine, p, ceData, elementFlags, er, cg, flags, opt ); } if ( sub & SC_ScrollBarAddPage ) { - QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarAddPage, opt ), widget ); + QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, ceData, elementFlags, SC_ScrollBarAddPage, opt, widget ), ceData, elementFlags ); QRegion region( er ); - if ( d->lastScrollbarRect.scrollbar == scrollbar && + if ( d->lastScrollbarRect.scrollbar == widget && d->lastScrollbarRect.rect.isValid() && er.intersects( d->lastScrollbarRect.rect ) ) { region = region.subtract( d->lastScrollbarRect.rect ); @@ -1300,9 +1299,9 @@ void QSGIStyle::drawComplexControl( ComplexControl control, p->setClipRegion( region ); } - drawPrimitive( PE_ScrollBarAddPage, p, er, cg, flags & ~Style_MouseOver, opt ); + drawPrimitive( PE_ScrollBarAddPage, p, ceData, elementFlags, er, cg, flags & ~Style_MouseOver, opt ); - if ( d->lastScrollbarRect.scrollbar == scrollbar && + if ( d->lastScrollbarRect.scrollbar == widget && d->lastScrollbarRect.rect.isValid() && er.intersects( d->lastScrollbarRect.rect ) ) { if ( sub & SC_ScrollBarSlider && handle.isValid() ) { @@ -1317,9 +1316,9 @@ void QSGIStyle::drawComplexControl( ComplexControl control, p->setClipping( FALSE ); } if ( sub & SC_ScrollBarSubPage ) { - QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, widget, SC_ScrollBarSubPage, opt ), widget ); + QRect er = QStyle::visualRect( querySubControlMetrics( CC_ScrollBar, ceData, elementFlags, SC_ScrollBarSubPage, opt, widget ), ceData, elementFlags ); QRegion region( er ); - if ( d->lastScrollbarRect.scrollbar == scrollbar && + if ( d->lastScrollbarRect.scrollbar == widget && d->lastScrollbarRect.rect.isValid() && er.intersects( d->lastScrollbarRect.rect ) ) { region = region.subtract( d->lastScrollbarRect.rect ); @@ -1329,8 +1328,8 @@ void QSGIStyle::drawComplexControl( ComplexControl control, region = region.subtract( handle ); p->setClipRegion( region ); } - drawPrimitive( PE_ScrollBarSubPage, p, er, cg, flags & ~Style_MouseOver, opt ); - if ( d->lastScrollbarRect.scrollbar == scrollbar && + drawPrimitive( PE_ScrollBarSubPage, p, ceData, elementFlags, er, cg, flags & ~Style_MouseOver, opt ); + if ( d->lastScrollbarRect.scrollbar == widget && d->lastScrollbarRect.rect.isValid() && er.intersects( d->lastScrollbarRect.rect ) ) { if ( sub & SC_ScrollBarSlider && handle.isValid() ) { @@ -1349,14 +1348,14 @@ void QSGIStyle::drawComplexControl( ComplexControl control, if ( subActive == SC_ScrollBarSlider ) flags |= Style_Active; - drawPrimitive( PE_ScrollBarSlider, p, handle, cg, flags, opt ); + drawPrimitive( PE_ScrollBarSlider, p, ceData, elementFlags, handle, cg, flags, opt ); } #endif } break; default: - QMotifStyle::drawComplexControl( control, p, widget, r, cg, flags, sub, subActive, opt ); +// QMotifStyle::drawComplexControl( control, p, ceData, elementFlags, r, cg, flags, sub, subActive, opt, widget ); break; } } @@ -1364,9 +1363,11 @@ void QSGIStyle::drawComplexControl( ComplexControl control, /*!\reimp */ QSize QSGIStyle::sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { QSize sz(contentsSize); @@ -1374,15 +1375,14 @@ QSize QSGIStyle::sizeFromContents( ContentsType contents, case CT_PopupMenuItem: { #ifndef QT_NO_POPUPMENU - if (! widget || opt.isDefault()) + if ((elementFlags & CEF_UseGenericParameters) || opt.isDefault()) break; QMenuItem *mi = opt.menuItem(); - sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize, - opt ); + sz = QMotifStyle::sizeFromContents( contents, ceData, elementFlags, contentsSize, + opt, widget ); // SGI checkmark items needs a bit more room - const QPopupMenu *popup = (QPopupMenu *) widget; - if ( popup && popup->isCheckable() ) + if ( elementFlags & CEF_IsCheckable ) sz.setWidth( sz.width() + 8 ); // submenu indicator needs a bit more room if (mi->popup()) @@ -1395,7 +1395,7 @@ QSize QSGIStyle::sizeFromContents( ContentsType contents, break; default: - sz = QMotifStyle::sizeFromContents( contents, widget, contentsSize, opt ); + sz = QMotifStyle::sizeFromContents( contents, ceData, elementFlags, contentsSize, opt, widget ); break; } @@ -1403,7 +1403,7 @@ QSize QSGIStyle::sizeFromContents( ContentsType contents, } /*! \reimp */ -QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const +QRect QSGIStyle::subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const { QRect rect; @@ -1411,8 +1411,8 @@ QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const case SR_ComboBoxFocusRect: { int awh, ax, ay, sh, sy, dh, ew; - int fw = pixelMetric( PM_DefaultFrameWidth, widget ); - QRect tr = widget->rect(); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); + QRect tr = ceData.rect; tr.addCoords( fw, fw, -fw, -fw ); get_combo_parameters( tr, ew, awh, ax, ay, sh, dh, sy ); @@ -1420,7 +1420,7 @@ QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const } break; default: - return QMotifStyle::subRect( r, widget ); + return QMotifStyle::subRect( r, ceData, elementFlags, widget ); } return rect; @@ -1428,27 +1428,29 @@ QRect QSGIStyle::subRect( SubRect r, const QWidget *widget ) const /*! \reimp */ QRect QSGIStyle::querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sub, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch ( control ) { case CC_ComboBox: switch ( sub ) { case SC_ComboBoxFrame: - return widget->rect(); + return ceData.rect; case SC_ComboBoxArrow: { int ew, awh, sh, dh, ax, ay, sy; - int fw = pixelMetric( PM_DefaultFrameWidth, widget ); - QRect cr = widget->rect(); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); + QRect cr = ceData.rect; cr.addCoords( fw, fw, -fw, -fw ); get_combo_parameters( cr, ew, awh, ax, ay, sh, dh, sy ); return QRect( ax, ay, awh, awh ); } case SC_ComboBoxEditField: { - int fw = pixelMetric( PM_DefaultFrameWidth, widget ); - QRect rect = widget->rect(); + int fw = pixelMetric( PM_DefaultFrameWidth, ceData, elementFlags, widget ); + QRect rect = ceData.rect; rect.addCoords( fw, fw, -fw, -fw ); int ew = get_combo_extra_width( rect.height() ); rect.addCoords( 1, 1, -1-ew, -1 ); @@ -1459,10 +1461,10 @@ QRect QSGIStyle::querySubControlMetrics( ComplexControl control, } break; case CC_ScrollBar: - return QCommonStyle::querySubControlMetrics( control, widget, sub, opt ); + return QCommonStyle::querySubControlMetrics( control, ceData, elementFlags, sub, opt, widget ); default: break; } - return QMotifStyle::querySubControlMetrics( control, widget, sub, opt ); + return QMotifStyle::querySubControlMetrics( control, ceData, elementFlags, sub, opt, widget ); } #endif // QT_NO_STYLE_SGI diff --git a/src/styles/qsgistyle.h b/src/styles/qsgistyle.h index addb7d7..0afacd6 100644 --- a/src/styles/qsgistyle.h +++ b/src/styles/qsgistyle.h @@ -67,13 +67,15 @@ public: #if !defined(Q_NO_USING_KEYWORD) using QMotifStyle::polish; #endif - void polish( QWidget* ); - void unPolish( QWidget* ); - void polish( QApplication* ); - void unPolish( QApplication* ); + void polish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + void unPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + void applicationPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); + void applicationUnPolish( QStyleControlElementData ceData, ControlElementFlags elementFlags, void * ); void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -81,15 +83,18 @@ public: void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags how = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; void drawComplexControl( ComplexControl control, QPainter *p, - const QWidget* widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect& r, const QColorGroup& cg, SFlags how = Style_Default, @@ -99,23 +104,27 @@ public: SCFlags sub = (uint)SC_All, #endif SCFlags subActive = SC_None, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget* widget = 0 ) const; - int pixelMetric( PixelMetric metric, const QWidget *widget = 0 ) const; + int pixelMetric( PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; QSize sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - QRect subRect( SubRect r, const QWidget *widget ) const; + QRect subRect( SubRect r, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget ) const; QRect querySubControlMetrics( ComplexControl control, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, SubControl sc, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; -protected: - bool eventFilter( QObject*, QEvent*); + bool objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); private: QSGIStylePrivate *d; diff --git a/src/styles/qwindowsstyle.cpp b/src/styles/qwindowsstyle.cpp index 4e6e586..ec05b80 100644 --- a/src/styles/qwindowsstyle.cpp +++ b/src/styles/qwindowsstyle.cpp @@ -66,10 +66,6 @@ #include "qobjectlist.h" #include "qmenubar.h" -#if defined(Q_WS_WIN) -#include "qt_windows.h" -#endif - #include <limits.h> @@ -99,99 +95,42 @@ class QWindowsStyle::Private : public QObject public: Private(QWindowsStyle *parent); - bool hasSeenAlt(const QWidget *widget) const; - bool altDown() const { return alt_down; } - -protected: - bool eventFilter(QObject *o, QEvent *e); + bool objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); private: - QPtrList<QWidget> seenAlt; - bool alt_down; int menuBarTimer; }; QWindowsStyle::Private::Private(QWindowsStyle *parent) -: QObject(parent, "QWindowsStylePrivate"), alt_down(FALSE), menuBarTimer(0) +: QObject(parent, "QWindowsStylePrivate"), menuBarTimer(0) { } -// Returns true if the toplevel parent of \a widget has seen the Alt-key -bool QWindowsStyle::Private::hasSeenAlt(const QWidget *widget) const -{ - widget = widget->topLevelWidget(); - return seenAlt.contains(widget); -} - // Records Alt- and Focus events -bool QWindowsStyle::Private::eventFilter(QObject *o, QEvent *e) +bool QWindowsStyle::Private::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags, void* source, QEvent *e ) { - if (!o->isWidgetType()) - return QObject::eventFilter(o, e); + if (!(ceData.widgetObjectTypes.contains("QWidget"))) { + return TRUE; + } - QWidget *widget = ::qt_cast<QWidget*>(o); + QWidget *widget = reinterpret_cast<QWidget*>(source); switch(e->type()) { - case QEvent::KeyPress: - if (((QKeyEvent*)e)->key() == Key_Alt) { - widget = widget->topLevelWidget(); - - // Alt has been pressed - find all widgets that care - QObjectList *l = widget->queryList("QWidget"); - QObjectListIt it( *l ); - QWidget *w; - while ( (w = (QWidget*)it.current()) != 0 ) { - ++it; - if (w->isTopLevel() || !w->isVisible() || - w->style().styleHint(SH_UnderlineAccelerator, w)) - l->removeRef(w); - } - // Update states before repainting - seenAlt.append(widget); - alt_down = TRUE; - - // Repaint all relevant widgets - it.toFirst(); - while ( (w = (QWidget*)it.current()) != 0 ) { - ++it; - w->repaint(FALSE); - } - delete l; - } - break; - case QEvent::KeyRelease: - if (((QKeyEvent*)e)->key() == Key_Alt) { - widget = widget->topLevelWidget(); - - // Update state - alt_down = FALSE; - // Repaint only menubars - QObjectList *l = widget->queryList("QMenuBar"); - QObjectListIt it( *l ); - QMenuBar *menuBar; - while ( (menuBar = (QMenuBar*)it.current()) != 0) { - ++it; - menuBar->repaint(FALSE); - } - } - break; case QEvent::FocusIn: case QEvent::FocusOut: { // Menubars toggle based on focus - QMenuBar *menuBar = ::qt_cast<QMenuBar*>(o); + QMenuBar *menuBar = ::qt_cast<QMenuBar*>(widget); if (menuBar && !menuBarTimer) // delayed repaint to avoid flicker menuBarTimer = menuBar->startTimer(0); } break; case QEvent::Close: // Reset widget when closing - seenAlt.removeRef(widget); - seenAlt.removeRef(widget->topLevelWidget()); break; case QEvent::Timer: { - QMenuBar *menuBar = ::qt_cast<QMenuBar*>(o); + QMenuBar *menuBar = ::qt_cast<QMenuBar*>(widget); QTimerEvent *te = (QTimerEvent*)e; if (menuBar && te->timerId() == menuBarTimer) { menuBar->killTimer(te->timerId()); @@ -205,7 +144,7 @@ bool QWindowsStyle::Private::eventFilter(QObject *o, QEvent *e) break; } - return QObject::eventFilter(o, e); + return TRUE; } /*! @@ -234,32 +173,40 @@ QWindowsStyle::~QWindowsStyle() } /*! \reimp */ -void QWindowsStyle::polish(QApplication *app) +bool QWindowsStyle::objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ) { + if (d) { + return d->objectEventHandler(ceData, elementFlags, source, e); + } + return TRUE; +} + +/*! \reimp */ +void QWindowsStyle::applicationPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr) { // We only need the overhead when shortcuts are sometimes hidden - if (!styleHint(SH_UnderlineAccelerator, 0)) { + if (styleHint(SH_UnderlineAccelerator, QStyleControlElementData(), CEF_None, 0) && styleHint(SH_HideUnderlineAcceleratorWhenAltUp, QStyleControlElementData(), CEF_None, 0)) { d = new Private(this); - app->installEventFilter(d); + installObjectEventHandler(ceData, elementFlags, ptr, this); } } /*! \reimp */ -void QWindowsStyle::unPolish(QApplication *) +void QWindowsStyle::applicationUnPolish(QStyleControlElementData, ControlElementFlags, void *) { delete d; d = 0; } /*! \reimp */ -void QWindowsStyle::polish(QWidget *widget) +void QWindowsStyle::polish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr) { - QCommonStyle::polish(widget); + QCommonStyle::polish(ceData, elementFlags, ptr); } /*! \reimp */ -void QWindowsStyle::unPolish(QWidget *widget) +void QWindowsStyle::unPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *ptr) { - QCommonStyle::polish(widget); + QCommonStyle::polish(ceData, elementFlags, ptr); } /*! \reimp */ @@ -271,6 +218,8 @@ void QWindowsStyle::polish( QPalette &pal ) /*! \reimp */ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, @@ -315,31 +264,6 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, p->fillRect(r, fill); break; } -#if defined(Q_WS_WIN) - case PE_HeaderArrow: - p->save(); - if ( flags & Style_Up ) { // invert logic to follow Windows style guide - QPointArray pa( 3 ); - p->setPen( cg.light() ); - p->drawLine( r.x() + r.width(), r.y(), r.x() + r.width() / 2, r.height() ); - p->setPen( cg.dark() ); - pa.setPoint( 0, r.x() + r.width() / 2, r.height() ); - pa.setPoint( 1, r.x(), r.y() ); - pa.setPoint( 2, r.x() + r.width(), r.y() ); - p->drawPolyline( pa ); - } else { - QPointArray pa( 3 ); - p->setPen( cg.light() ); - pa.setPoint( 0, r.x(), r.height() ); - pa.setPoint( 1, r.x() + r.width(), r.height() ); - pa.setPoint( 2, r.x() + r.width() / 2, r.y() ); - p->drawPolyline( pa ); - p->setPen( cg.dark() ); - p->drawLine( r.x(), r.height(), r.x() + r.width() / 2, r.y() ); - } - p->restore(); - break; -#endif case PE_ButtonDefault: p->setPen(cg.shadow()); @@ -507,7 +431,7 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, case PE_Panel: case PE_PanelPopup: { - int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth) + int lw = opt.isDefault() ? pixelMetric(PM_DefaultFrameWidth, ceData, elementFlags) : opt.lineWidth(); if (lw == 2) { @@ -518,7 +442,7 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, } qDrawWinPanel(p, r, popupCG, flags & Style_Sunken); } else { - QCommonStyle::drawPrimitive(pe, p, r, cg, flags, opt); + QCommonStyle::drawPrimitive(pe, p, ceData, elementFlags, r, cg, flags, opt); } break; } @@ -572,13 +496,13 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, p->setBrush( cg.brush( QColorGroup::Button ) ); p->drawRect( r ); } else - drawPrimitive(PE_ButtonBevel, p, r, cg, flags | Style_Raised); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, flags | Style_Raised); } else - drawPrimitive(PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) | + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Down : Style_Raised)); drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp), - p, r, cg, flags); + p, ceData, elementFlags, r, cg, flags); break; case PE_ScrollBarAddLine: @@ -588,13 +512,13 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, p->setBrush( cg.brush( QColorGroup::Button ) ); p->drawRect( r ); } else - drawPrimitive(PE_ButtonBevel, p, r, cg, flags | Style_Raised); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, flags | Style_Raised); } else - drawPrimitive(PE_ButtonBevel, p, r, cg, (flags & Style_Enabled) | + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, (flags & Style_Enabled) | ((flags & Style_Down) ? Style_Down : Style_Raised)); drawPrimitive(((flags & Style_Horizontal) ? PE_ArrowRight : PE_ArrowDown), - p, r, cg, flags); + p, ceData, elementFlags, r, cg, flags); break; case PE_ScrollBarAddPage: @@ -632,7 +556,7 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, p->setBackgroundMode(OpaqueMode); p->drawRect(r); } else - drawPrimitive(PE_ButtonBevel, p, r, cg, Style_Enabled | Style_Raised); + drawPrimitive(PE_ButtonBevel, p, ceData, elementFlags, r, cg, Style_Enabled | Style_Raised); break; case PE_WindowFrame: @@ -674,8 +598,8 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, p->save(); if ( flags & Style_Down ) - p->translate( pixelMetric( PM_ButtonShiftHorizontal ), - pixelMetric( PM_ButtonShiftVertical ) ); + p->translate( pixelMetric( PM_ButtonShiftHorizontal, ceData, elementFlags ), + pixelMetric( PM_ButtonShiftVertical, ceData, elementFlags ) ); if ( flags & Style_Enabled ) { a.translate( r.x() + r.width() / 2, r.y() + r.height() / 2 ); @@ -694,7 +618,7 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, } p->restore(); } else - QCommonStyle::drawPrimitive(pe, p, r, cg, flags, opt); + QCommonStyle::drawPrimitive(pe, p, ceData, elementFlags, r, cg, flags, opt); } } @@ -704,33 +628,34 @@ void QWindowsStyle::drawPrimitive( PrimitiveElement pe, */ void QWindowsStyle::drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch (element) { #ifndef QT_NO_TABBAR case CE_TabBarTab: { - if ( !widget || !widget->parentWidget() || !opt.tab() ) + if ( ( elementFlags & CEF_UseGenericParameters ) || (!( elementFlags & CEF_HasParentWidget )) || !opt.tab() ) break; - const QTabBar * tb = (const QTabBar *) widget; const QTab * t = opt.tab(); bool selected = flags & Style_Selected; - bool lastTab = (tb->indexOf( t->identifier() ) == tb->count()-1) ? + bool lastTab = (ceData.tabBarData.identIndexMap[t->identifier()] == ceData.tabBarData.tabCount-1) ? TRUE : FALSE; QRect r2( r ); - if ( tb->shape() == QTabBar::RoundedAbove ) { + if ( ceData.tabBarData.shape == QTabBar::RoundedAbove ) { p->setPen( cg.midlight() ); p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() ); p->setPen( cg.light() ); p->drawLine( r2.left(), r2.bottom()-1, r2.right(), r2.bottom()-1 ); if ( r2.left() == 0 ) - p->drawPoint( tb->rect().bottomLeft() ); + p->drawPoint( ceData.rect.bottomLeft() ); if ( selected ) { p->fillRect( QRect( r2.left()+1, r2.bottom()-1, r2.width()-3, 2), @@ -774,9 +699,9 @@ void QWindowsStyle::drawControl( ControlElement element, x2++; p->drawLine( x2, r2.top() + 2, x2, r2.bottom() - (selected ? (lastTab ? 0:1) :2)); - } else if ( tb->shape() == QTabBar::RoundedBelow ) { - bool rightAligned = styleHint( SH_TabBar_Alignment, tb ) == AlignRight; - bool firstTab = tb->indexOf( t->identifier() ) == 0; + } else if ( ceData.tabBarData.shape == QTabBar::RoundedBelow ) { + bool rightAligned = styleHint( SH_TabBar_Alignment, ceData, elementFlags, QStyleOption::Default, 0, widget ) == AlignRight; + bool firstTab = ceData.tabBarData.identIndexMap[t->identifier()] == 0; if ( selected ) { p->fillRect( QRect( r2.left()+1, r2.top(), r2.width()-3, 1), cg.brush( QColorGroup::Background )); @@ -823,7 +748,7 @@ void QWindowsStyle::drawControl( ControlElement element, p->drawLine( r2.left(), r2.top() + (selected ? 0 : 2), r2.left(), r2.bottom() - 2 ); } else { - QCommonStyle::drawControl(element, p, widget, r, cg, flags, opt); + QCommonStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget); } break; } @@ -838,10 +763,9 @@ void QWindowsStyle::drawControl( ControlElement element, #ifndef QT_NO_POPUPMENU case CE_PopupMenuItem: { - if (! widget || opt.isDefault()) + if (( elementFlags & CEF_UseGenericParameters ) || opt.isDefault()) break; - const QPopupMenu *popupmenu = (const QPopupMenu *) widget; QMenuItem *mi = opt.menuItem(); if ( !mi ) break; @@ -849,7 +773,7 @@ void QWindowsStyle::drawControl( ControlElement element, int tab = opt.tabWidth(); int maxpmw = opt.maxIconWidth(); bool dis = !(flags&Style_Enabled); - bool checkable = popupmenu->isCheckable(); + bool checkable = ( elementFlags & CEF_IsCheckable ); bool act = flags & Style_Active; int x, y, w, h; @@ -937,7 +861,7 @@ void QWindowsStyle::drawControl( ControlElement element, if (act) cflags |= Style_On; - drawPrimitive(PE_CheckMark, p, + drawPrimitive(PE_CheckMark, p, ceData, elementFlags, visualRect( QRect(xp, y + windowsItemFrame, checkcol - 2*windowsItemFrame, h - 2*windowsItemFrame), r ), cg, cflags); @@ -973,8 +897,9 @@ void QWindowsStyle::drawControl( ControlElement element, if ( !s.isNull() ) { // draw text int t = s.find( '\t' ); int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine; - if (!styleHint(SH_UnderlineAccelerator, widget)) + if ((!styleHint(SH_UnderlineAccelerator, ceData, elementFlags, QStyleOption::Default, 0, widget)) || ((styleHint(SH_HideUnderlineAcceleratorWhenAltUp, ceData, elementFlags, QStyleOption::Default, 0, widget)) && (!acceleratorsShown()))) { text_flags |= NoAccel; + } text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft ); if ( t >= 0 ) { // draw tab text int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1; @@ -1014,10 +939,10 @@ void QWindowsStyle::drawControl( ControlElement element, if ( act ) { QColorGroup g2 = cg; g2.setColor( QColorGroup::ButtonText, g2.highlightedText() ); - drawPrimitive(arrow, p, vrect, + drawPrimitive(arrow, p, ceData, elementFlags, vrect, g2, dis ? Style_Default : Style_Enabled); } else { - drawPrimitive(arrow, p, vrect, + drawPrimitive(arrow, p, ceData, elementFlags, vrect, cg, dis ? Style_Default : Style_Enabled ); } } @@ -1042,17 +967,17 @@ void QWindowsStyle::drawControl( ControlElement element, qDrawShadeRect( p, r.x(), r.y(), r.width(), r.height(), cg, active && down, 1, 0, &b ); if ( active && down ) { - pr.moveBy( pixelMetric(PM_ButtonShiftHorizontal, widget), - pixelMetric(PM_ButtonShiftVertical, widget) ); + pr.moveBy( pixelMetric(PM_ButtonShiftHorizontal, ceData, elementFlags, widget), + pixelMetric(PM_ButtonShiftVertical, ceData, elementFlags, widget) ); p->setBrushOrigin(p->brushOrigin() - QPoint(1,1)); } } - QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt); + QCommonStyle::drawControl(element, p, ceData, elementFlags, pr, cg, flags, opt, widget); break; } default: - QCommonStyle::drawControl(element, p, widget, r, cg, flags, opt); + QCommonStyle::drawControl(element, p, ceData, elementFlags, r, cg, flags, opt, widget); } } @@ -1060,7 +985,7 @@ void QWindowsStyle::drawControl( ControlElement element, /*! \reimp */ -int QWindowsStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const +int QWindowsStyle::pixelMetric(PixelMetric metric, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QWidget *widget) const { int ret; @@ -1085,10 +1010,9 @@ int QWindowsStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const // equally between the tickmark regions. case PM_SliderControlThickness: { - const QSlider * sl = (const QSlider *) widget; - int space = (sl->orientation() == Horizontal) ? sl->height() - : sl->width(); - int ticks = sl->tickmarks(); + int space = (ceData.orientation == Horizontal) ? ceData.rect.height() + : ceData.rect.width(); + int ticks = ceData.tickMarkSetting; int n = 0; if ( ticks & QSlider::Above ) n++; if ( ticks & QSlider::Below ) n++; @@ -1099,7 +1023,7 @@ int QWindowsStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const int thick = 6; // Magic constant to get 5 + 16 + 5 if ( ticks != QSlider::Both && ticks != QSlider::NoMarks ) - thick += pixelMetric( PM_SliderLength, sl ) / 4; + thick += pixelMetric( PM_SliderLength, ceData, elementFlags, widget ) / 4; space -= thick; //### the two sides may be unequal in size @@ -1114,46 +1038,12 @@ int QWindowsStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const ret = 0; break; -#if defined(Q_WS_WIN) - case PM_TitleBarHeight: - if ( widget && ( widget->testWFlags( WStyle_Tool ) || ::qt_cast<QDockWindow*>(widget) ) ) { - // MS always use one less than they say -#if defined(Q_OS_TEMP) - ret = GetSystemMetrics( SM_CYCAPTION ) - 1; -#else - ret = GetSystemMetrics( SM_CYSMCAPTION ) - 1; -#endif - } else { - ret = GetSystemMetrics( SM_CYCAPTION ) - 1; - } - break; - - case PM_ScrollBarExtent: - { -#ifndef Q_OS_TEMP - NONCLIENTMETRICS ncm; - ncm.cbSize = sizeof(NONCLIENTMETRICS); - if ( SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0 ) ) - ret = QMAX( ncm.iScrollHeight, ncm.iScrollWidth ); - else -#endif - ret = QCommonStyle::pixelMetric( metric, widget ); - } - break; -#endif - case PM_SplitterWidth: ret = QMAX( 6, QApplication::globalStrut().width() ); break; -#if defined(Q_WS_WIN) - case PM_MDIFrameWidth: - ret = GetSystemMetrics(SM_CYFRAME); - break; -#endif - default: - ret = QCommonStyle::pixelMetric(metric, widget); + ret = QCommonStyle::pixelMetric(metric, ceData, elementFlags, widget); break; } @@ -1165,9 +1055,11 @@ int QWindowsStyle::pixelMetric(PixelMetric metric, const QWidget *widget) const \reimp */ QSize QWindowsStyle::sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { QSize sz(contentsSize); @@ -1175,15 +1067,14 @@ QSize QWindowsStyle::sizeFromContents( ContentsType contents, case CT_PushButton: { #ifndef QT_NO_PUSHBUTTON - const QPushButton *button = (const QPushButton *) widget; - sz = QCommonStyle::sizeFromContents(contents, widget, contentsSize, opt); + sz = QCommonStyle::sizeFromContents(contents, ceData, elementFlags, contentsSize, opt, widget); int w = sz.width(), h = sz.height(); int defwidth = 0; - if (button->isDefault() || button->autoDefault()) - defwidth = 2*pixelMetric( PM_ButtonDefaultIndicator, widget ); + if ((elementFlags & CEF_IsDefault) || (elementFlags & CEF_AutoDefault)) + defwidth = 2*pixelMetric( PM_ButtonDefaultIndicator, ceData, elementFlags, widget ); - if (w < 80+defwidth && !button->pixmap()) + if (w < 80+defwidth && ceData.fgPixmap.isNull()) w = 80+defwidth; if (h < 23+defwidth) h = 23+defwidth; @@ -1196,11 +1087,10 @@ QSize QWindowsStyle::sizeFromContents( ContentsType contents, case CT_PopupMenuItem: { #ifndef QT_NO_POPUPMENU - if (! widget || opt.isDefault()) + if (( elementFlags & CEF_UseGenericParameters ) || opt.isDefault()) break; - const QPopupMenu *popup = (const QPopupMenu *) widget; - bool checkable = popup->isCheckable(); + bool checkable = ( elementFlags & CEF_IsCheckable ); QMenuItem *mi = opt.menuItem(); int maxpmw = opt.maxIconWidth(); int w = sz.width(), h = sz.height(); @@ -1218,7 +1108,7 @@ QSize QWindowsStyle::sizeFromContents( ContentsType contents, if (mi->pixmap()) h = QMAX(h, mi->pixmap()->height() + 2*windowsItemFrame); else if (! mi->text().isNull()) - h = QMAX(h, popup->fontMetrics().height() + 2*windowsItemVMargin + + h = QMAX(h, QFontMetrics(ceData.font).height() + 2*windowsItemVMargin + 2*windowsItemFrame); if (mi->iconSet() != 0) @@ -1256,7 +1146,7 @@ QSize QWindowsStyle::sizeFromContents( ContentsType contents, } default: - sz = QCommonStyle::sizeFromContents(contents, widget, sz, opt); + sz = QCommonStyle::sizeFromContents(contents, ceData, elementFlags, sz, opt, widget); break; } @@ -1556,8 +1446,10 @@ static const char *const question_xpm[] = { \reimp */ QPixmap QWindowsStyle::stylePixmap(StylePixmap stylepixmap, - const QWidget *widget, - const QStyleOption& opt) const + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& opt, + const QWidget *widget) const { #ifndef QT_NO_IMAGEIO_XPM switch (stylepixmap) { @@ -1587,26 +1479,28 @@ QPixmap QWindowsStyle::stylePixmap(StylePixmap stylepixmap, break; } #endif //QT_NO_IMAGEIO_XPM - return QCommonStyle::stylePixmap(stylepixmap, widget, opt); + return QCommonStyle::stylePixmap(stylepixmap, ceData, elementFlags, opt, widget); } /*!\reimp */ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags, SCFlags sub, SCFlags subActive, - const QStyleOption& opt ) const + const QStyleOption& opt, + const QWidget *widget ) const { switch (ctrl) { #ifndef QT_NO_LISTVIEW case CC_ListView: { if ( sub & SC_ListView ) { - QCommonStyle::drawComplexControl( ctrl, p, widget, r, cg, flags, sub, subActive, opt ); + QCommonStyle::drawComplexControl( ctrl, p, ceData, elementFlags, r, cg, flags, sub, subActive, opt, widget ); } if ( sub & ( SC_ListViewBranch | SC_ListViewExpand ) ) { if (opt.isDefault()) @@ -1769,13 +1663,13 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, if ( sub & SC_ComboBoxArrow ) { SFlags flags = Style_Default; - qDrawWinPanel( p, r, cg, TRUE, widget->isEnabled() ? + qDrawWinPanel( p, r, cg, TRUE, ( elementFlags & CEF_IsEnabled ) ? &cg.brush( QColorGroup::Base ): &cg.brush( QColorGroup::Background ) ); QRect ar = - QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, - SC_ComboBoxArrow ), widget ); + QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxArrow, QStyleOption::Default, widget ), ceData, elementFlags ); if ( subActive == SC_ComboBoxArrow ) { p->setPen( cg.dark() ); p->setBrush( cg.brush( QColorGroup::Button ) ); @@ -1785,25 +1679,24 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, &cg.brush( QColorGroup::Button ) ); ar.addCoords( 2, 2, -2, -2 ); - if ( widget->isEnabled() ) + if ( elementFlags & CEF_IsEnabled ) flags |= Style_Enabled; if ( subActive == SC_ComboBoxArrow ) { flags |= Style_Sunken; } - drawPrimitive( PE_ArrowDown, p, ar, cg, flags ); + drawPrimitive( PE_ArrowDown, p, ceData, elementFlags, ar, cg, flags ); } if ( sub & SC_ComboBoxEditField ) { - const QComboBox * cb = (const QComboBox *) widget; QRect re = - QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, - SC_ComboBoxEditField ), widget ); - if ( cb->hasFocus() && !cb->editable() ) + QStyle::visualRect( querySubControlMetrics( CC_ComboBox, ceData, elementFlags, + SC_ComboBoxEditField, QStyleOption::Default, widget ), ceData, elementFlags ); + if ( ( elementFlags & CEF_HasFocus ) && (!( elementFlags & CEF_IsEditable )) ) p->fillRect( re.x(), re.y(), re.width(), re.height(), cg.brush( QColorGroup::Highlight ) ); - if ( cb->hasFocus() ) { + if ( elementFlags & CEF_HasFocus ) { p->setPen( cg.highlightedText() ); p->setBackgroundColor( cg.highlight() ); @@ -1812,10 +1705,10 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, p->setBackgroundColor( cg.background() ); } - if ( cb->hasFocus() && !cb->editable() ) { + if ( ( elementFlags & CEF_HasFocus ) && (!( elementFlags & CEF_IsEditable )) ) { QRect re = - QStyle::visualRect( subRect( SR_ComboBoxFocusRect, cb ), widget ); - drawPrimitive( PE_FocusRect, p, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); + QStyle::visualRect( subRect( SR_ComboBoxFocusRect, ceData, elementFlags, widget ), ceData, elementFlags ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, re, cg, Style_FocusAtBorder, QStyleOption(cg.highlight())); } } @@ -1825,15 +1718,14 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, #ifndef QT_NO_SLIDER case CC_Slider: { - const QSlider *sl = (const QSlider *) widget; - int thickness = pixelMetric( PM_SliderControlThickness, widget ); - int len = pixelMetric( PM_SliderLength, widget ); - int ticks = sl->tickmarks(); + int thickness = pixelMetric( PM_SliderControlThickness, ceData, elementFlags, widget ); + int len = pixelMetric( PM_SliderLength, ceData, elementFlags, widget ); + int ticks = ceData.tickMarkSetting; - QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove, - opt), - handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle, - opt); + QRect groove = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderGroove, + opt, widget), + handle = querySubControlMetrics(CC_Slider, ceData, elementFlags, SC_SliderHandle, + opt, widget); if ((sub & SC_SliderGroove) && groove.isValid()) { int mid = thickness / 2; @@ -1844,7 +1736,7 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, mid -= len / 8; p->setPen( cg.shadow() ); - if ( sl->orientation() == Horizontal ) { + if ( ceData.orientation == Horizontal ) { qDrawWinPanel( p, groove.x(), groove.y() + mid - 2, groove.width(), 4, cg, TRUE ); p->drawLine( groove.x() + 1, groove.y() + mid - 1, @@ -1859,9 +1751,9 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, } if (sub & SC_SliderTickmarks) - QCommonStyle::drawComplexControl(ctrl, p, widget, r, cg, flags, + QCommonStyle::drawComplexControl(ctrl, p, ceData, elementFlags, r, cg, flags, SC_SliderTickmarks, subActive, - opt ); + opt, widget ); if ( sub & SC_SliderHandle ) { // 4444440 @@ -1887,15 +1779,15 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, int y1 = y; int y2 = y+he-1; - Orientation orient = sl->orientation(); - bool tickAbove = sl->tickmarks() == QSlider::Above; - bool tickBelow = sl->tickmarks() == QSlider::Below; + Orientation orient = ceData.orientation; + bool tickAbove = ceData.tickMarkSetting == QSlider::Above; + bool tickBelow = ceData.tickMarkSetting == QSlider::Below; p->fillRect( x, y, wi, he, cg.brush( QColorGroup::Background ) ); if ( flags & Style_HasFocus ) { - QRect re = subRect( SR_SliderFocusRect, sl ); - drawPrimitive( PE_FocusRect, p, re, cg ); + QRect re = subRect( SR_SliderFocusRect, ceData, elementFlags, widget ); + drawPrimitive( PE_FocusRect, p, ceData, elementFlags, re, cg ); } if ( (tickAbove && tickBelow) || (!tickAbove && !tickBelow) ) { @@ -2032,8 +1924,8 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, #endif // QT_NO_SLIDER default: - QCommonStyle::drawComplexControl( ctrl, p, widget, r, cg, flags, sub, - subActive, opt ); + QCommonStyle::drawComplexControl( ctrl, p, ceData, elementFlags, r, cg, flags, sub, + subActive, opt, widget ); break; } } @@ -2041,9 +1933,11 @@ void QWindowsStyle::drawComplexControl( ComplexControl ctrl, QPainter *p, /*! \reimp */ int QWindowsStyle::styleHint( StyleHint hint, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QStyleOption &opt, - QStyleHintReturn *returnData ) const + QStyleHintReturn *returnData, + const QWidget *widget ) const { int ret; @@ -2063,11 +1957,6 @@ int QWindowsStyle::styleHint( StyleHint hint, break; case SH_ItemView_ChangeHighlightOnFocus: -#if defined(Q_WS_WIN) - if ( qWinVersion() != WV_95 && qWinVersion() != WV_NT ) - ret = 1; - else -#endif ret = 0; break; @@ -2075,59 +1964,8 @@ int QWindowsStyle::styleHint( StyleHint hint, ret = 0; break; -#if defined(Q_WS_WIN) - case SH_UnderlineAccelerator: - ret = 1; - if ( qWinVersion() != WV_95 && qWinVersion() != WV_98 && qWinVersion() != WV_NT ) { - BOOL cues; - SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0); - ret = cues ? 1 : 0; - // Do nothing if we always paint underlines - if (!ret && widget && d) { - QMenuBar *menuBar = ::qt_cast<QMenuBar*>(widget); - QPopupMenu *popupMenu = 0; - if (!menuBar) - popupMenu = ::qt_cast<QPopupMenu*>(widget); - - // If we paint a menubar draw underlines if it has focus, or if alt is down, - // or if a popup menu belonging to the menubar is active and paints underlines - if (menuBar) { - if (menuBar->hasFocus()) { - ret = 1; - } else if (d->altDown()) { - ret = 1; - } else if (qApp->focusWidget() && qApp->focusWidget()->isPopup()) { - popupMenu = ::qt_cast<QPopupMenu*>(qApp->focusWidget()); - QMenuData *pm = popupMenu ? (QMenuData*)popupMenu->qt_cast("QMenuData") : 0; - if (pm && ((FriendlyMenuData*)pm)->parentMenu == menuBar) { - if (d->hasSeenAlt(menuBar)) - ret = 1; - } - } - // If we paint a popup menu draw underlines if the respective menubar does - } else if (popupMenu) { - QMenuData *pm = (QMenuData*)popupMenu->qt_cast("QMenuData"); - while (pm) { - if (((FriendlyMenuData*)pm)->isMenuBar) { - menuBar = (QMenuBar*)pm; - if (d->hasSeenAlt(menuBar)) - ret = 1; - break; - } - pm = ((FriendlyMenuData*)pm)->parentMenu; - } - // Otherwise draw underlines if the toplevel widget has seen an alt-press - } else if (d->hasSeenAlt(widget)) { - ret = 1; - } - } - - } - break; -#endif - default: - ret = QCommonStyle::styleHint(hint, widget, opt, returnData); + ret = QCommonStyle::styleHint(hint, ceData, elementFlags, opt, returnData, widget); break; } @@ -2135,7 +1973,7 @@ int QWindowsStyle::styleHint( StyleHint hint, } /*! \reimp */ -QRect QWindowsStyle::subRect(SubRect r, const QWidget *widget) const +QRect QWindowsStyle::subRect(SubRect r, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget) const { QRect rect; @@ -2143,15 +1981,15 @@ QRect QWindowsStyle::subRect(SubRect r, const QWidget *widget) const #ifndef QT_NO_SLIDER case SR_SliderFocusRect: { - rect = widget->rect(); + rect = ceData.rect; break; } #endif // QT_NO_SLIDER case SR_ToolBoxTabContents: - rect = widget->rect(); + rect = ceData.rect; break; default: - rect = QCommonStyle::subRect( r, widget ); + rect = QCommonStyle::subRect( r, ceData, elementFlags, widget ); break; } diff --git a/src/styles/qwindowsstyle.h b/src/styles/qwindowsstyle.h index 5ad82b0..d768a04 100644 --- a/src/styles/qwindowsstyle.h +++ b/src/styles/qwindowsstyle.h @@ -61,11 +61,11 @@ public: QWindowsStyle(); ~QWindowsStyle(); - void polish(QApplication*); - void unPolish(QApplication*); + void applicationPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); + void applicationUnPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); - void polish(QWidget*); - void unPolish(QWidget*); + void polish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); + void unPolish(QStyleControlElementData ceData, ControlElementFlags elementFlags, void *); void polish( QPalette & ); @@ -74,6 +74,8 @@ public: // new stuff void drawPrimitive( PrimitiveElement pe, QPainter *p, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, @@ -81,15 +83,18 @@ public: void drawControl( ControlElement element, QPainter *p, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect &r, const QColorGroup &cg, SFlags flags = Style_Default, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; void drawComplexControl( ComplexControl control, QPainter* p, - const QWidget* widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QRect& r, const QColorGroup& cg, SFlags flags = Style_Default, @@ -99,25 +104,33 @@ public: SCFlags sub = (uint)SC_All, #endif SCFlags subActive = SC_None, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget* widget = 0 ) const; int pixelMetric( PixelMetric metric, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QWidget *widget = 0 ) const; QSize sizeFromContents( ContentsType contents, - const QWidget *widget, + QStyleControlElementData ceData, + ControlElementFlags elementFlags, const QSize &contentsSize, - const QStyleOption& = QStyleOption::Default ) const; + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - int styleHint(StyleHint sh, const QWidget *, const QStyleOption & = QStyleOption::Default, - QStyleHintReturn* = 0) const; + int styleHint(StyleHint sh, QStyleControlElementData ceData, ControlElementFlags elementFlags, const QStyleOption & = QStyleOption::Default, + QStyleHintReturn* = 0, const QWidget* = 0) const; QPixmap stylePixmap( StylePixmap stylepixmap, - const QWidget *widget = 0, - const QStyleOption& = QStyleOption::Default ) const; + QStyleControlElementData ceData, + ControlElementFlags elementFlags, + const QStyleOption& = QStyleOption::Default, + const QWidget *widget = 0 ) const; - QRect subRect( SubRect r, const QWidget *widget ) const; + QRect subRect( SubRect r, const QStyleControlElementData ceData, const ControlElementFlags elementFlags, const QWidget *widget ) const; + bool objectEventHandler( QStyleControlElementData ceData, ControlElementFlags elementFlags, void* source, QEvent *e ); private: class Private; diff --git a/src/tools/qglobal.h b/src/tools/qglobal.h index 44e6bbf..a62d19a 100644 --- a/src/tools/qglobal.h +++ b/src/tools/qglobal.h @@ -41,11 +41,11 @@ #ifndef QGLOBAL_H #define QGLOBAL_H -#define QT_VERSION_STR "3.4.0" +#define QT_VERSION_STR "3.5.0" /* QT_VERSION is (major << 16) + (minor << 8) + patch. */ -#define QT_VERSION 0x030400 +#define QT_VERSION 0x030500 /* The operating system, must be one of: (Q_OS_x) diff --git a/src/widgets/qdialogbuttons.cpp b/src/widgets/qdialogbuttons.cpp index 787a406..39f6d67 100644 --- a/src/widgets/qdialogbuttons.cpp +++ b/src/widgets/qdialogbuttons.cpp @@ -150,6 +150,12 @@ QDialogButtons::isButtonVisible(Button button) const return ((int)(d->visible & button)) == button; } +Q_UINT32 +QDialogButtons::visibleButtons() const +{ + return d->visible; +} + void QDialogButtons::addWidget(QWidget *w) { diff --git a/src/widgets/qdialogbuttons_p.h b/src/widgets/qdialogbuttons_p.h index 73bbfee..56c34c2 100644 --- a/src/widgets/qdialogbuttons_p.h +++ b/src/widgets/qdialogbuttons_p.h @@ -72,6 +72,7 @@ public: inline void hideButton(Button b) { setButtonVisible(b, FALSE); } virtual void setButtonVisible(Button, bool visible); bool isButtonVisible(Button) const; + Q_UINT32 visibleButtons() const; void addWidget(QWidget *); diff --git a/src/widgets/qgroupbox.cpp b/src/widgets/qgroupbox.cpp index 6097ece..7ffcb2a 100644 --- a/src/widgets/qgroupbox.cpp +++ b/src/widgets/qgroupbox.cpp @@ -364,8 +364,9 @@ void QGroupBox::paintEvent( QPaintEvent *event ) if(va & AlignTop) r.moveBy(0, fm.descent()); QColor pen( (QRgb) style().styleHint(QStyle::SH_GroupBox_TextLabelColor, this ) ); - if (!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) + if ((!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) || ((style().styleHint(QStyle::SH_HideUnderlineAcceleratorWhenAltUp, this)) && (!style().acceleratorsShown()))) { va |= NoAccel; + } style().drawItem( &paint, r, ShowPrefix | AlignHCenter | va, colorGroup(), isEnabled(), 0, str, -1, ownPalette() ? 0 : &pen ); paint.setClipRegion( event->region().subtract( r ) ); // clip everything but title diff --git a/src/widgets/qlabel.cpp b/src/widgets/qlabel.cpp index 40f2b38..ff2e7bc 100644 --- a/src/widgets/qlabel.cpp +++ b/src/widgets/qlabel.cpp @@ -838,8 +838,9 @@ void QLabel::drawContents( QPainter *p ) } #endif int alignment = align; - if ((align & ShowPrefix) && !style().styleHint(QStyle::SH_UnderlineAccelerator, this)) + if ((align & ShowPrefix) && ((!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) || ((style().styleHint(QStyle::SH_HideUnderlineAcceleratorWhenAltUp, this)) && (!style().acceleratorsShown())))) { alignment |= NoAccel; + } // ordinary text or pixmap label style().drawItem( p, cr, alignment, colorGroup(), isEnabled(), pix, ltext ); diff --git a/src/widgets/qtabbar.cpp b/src/widgets/qtabbar.cpp index fca4957..383285d 100644 --- a/src/widgets/qtabbar.cpp +++ b/src/widgets/qtabbar.cpp @@ -335,7 +335,7 @@ private: */ QTabBar::QTabBar( QWidget * parent, const char *name ) - : QWidget( parent, name, WNoAutoErase | WNoMousePropagation ) + : QWidget( parent, name, WNoAutoErase | WNoMousePropagation ), l(NULL) { d = new QTabPrivate; d->pressed = 0; @@ -839,7 +839,10 @@ void QTabBar::show() int QTabBar::currentTab() const { - const QTab * t = l->getLast(); + const QTab * t = 0; + if (l) { + t = l->getLast(); + } return t ? t->id : -1; } @@ -965,10 +968,12 @@ void QTabBar::keyPressEvent( QKeyEvent * e ) QTab * QTabBar::tab( int id ) const { - QTab * t; - for( t = l->first(); t; t = l->next() ) - if ( t && t->id == id ) - return t; + if (l) { + QTab * t; + for( t = l->first(); t; t = l->next() ) + if ( t && t->id == id ) + return t; + } return 0; } @@ -982,7 +987,8 @@ QTab * QTabBar::tab( int id ) const QTab * QTabBar::tabAt( int index ) const { QTab * t; - t = lstatic->at( index ); + QPtrList<QTab> internalList = *lstatic; + t = internalList.at( index ); return t; } @@ -996,8 +1002,9 @@ QTab * QTabBar::tabAt( int index ) const int QTabBar::indexOf( int id ) const { QTab * t; + QPtrList<QTab> internalList = *lstatic; int idx = 0; - for( t = lstatic->first(); t; t = lstatic->next() ) { + for( t = internalList.first(); t; t = internalList.next() ) { if ( t && t->id == id ) return idx; idx++; @@ -1014,7 +1021,10 @@ int QTabBar::indexOf( int id ) const */ int QTabBar::count() const { - return l->count(); + if (l) { + return l->count(); + } + return 0; } diff --git a/src/widgets/qtoolbox.cpp b/src/widgets/qtoolbox.cpp index 64fc148..b48f416 100644 --- a/src/widgets/qtoolbox.cpp +++ b/src/widgets/qtoolbox.cpp @@ -240,8 +240,9 @@ void QToolBoxButton::drawButton( QPainter *p ) fill = &cg.color( QPalette::foregroundRoleFromMode( tb->backgroundMode() ) ); int alignment = AlignLeft | AlignVCenter | ShowPrefix; - if (!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) + if ((!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) || ((style().styleHint(QStyle::SH_HideUnderlineAcceleratorWhenAltUp, this)) && (!style().acceleratorsShown()))) { alignment |= NoAccel; + } style().drawItem( p, tr, alignment, cg, isEnabled(), 0, txt, -1, fill ); |