From 05c2113350a8abbb1df844a2b1d1befb95a93f5e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 15 Oct 2012 14:10:58 +0200 Subject: Add QObject* QStyleOption::styleObject The object is used, amongst other things, as a target for sending style animation updates. Change-Id: Ic210e7ae2111bc08b70331a3a2030a494919a06d Reviewed-by: Gabriel de Dietrich Reviewed-by: Jens Bache-Wiig --- src/widgets/styles/qstyleoption.cpp | 20 ++++++++++++++++---- src/widgets/styles/qstyleoption.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/widgets/styles/qstyleoption.cpp b/src/widgets/styles/qstyleoption.cpp index 3017f30470..8a469b496d 100644 --- a/src/widgets/styles/qstyleoption.cpp +++ b/src/widgets/styles/qstyleoption.cpp @@ -155,7 +155,7 @@ QT_BEGIN_NAMESPACE QStyleOption::QStyleOption(int version, int type) : version(version), type(type), state(QStyle::State_None), - direction(QApplication::layoutDirection()), fontMetrics(QFont()) + direction(QApplication::layoutDirection()), fontMetrics(QFont()), styleObject(0) { } @@ -171,8 +171,8 @@ QStyleOption::~QStyleOption() \fn void QStyleOption::initFrom(const QWidget *widget) \since 4.1 - Initializes the \l state, \l direction, \l rect, \l palette, and - \l fontMetrics member variables based on the specified \a widget. + Initializes the \l state, \l direction, \l rect, \l palette, \l fontMetrics + and \l styleObject member variables based on the specified \a widget. This is a convenience function; the member variables can also be initialized manually. @@ -227,6 +227,7 @@ void QStyleOption::init(const QWidget *widget) rect = widget->rect(); palette = widget->palette(); fontMetrics = widget->fontMetrics(); + styleObject = const_cast(widget); } /*! @@ -235,7 +236,7 @@ void QStyleOption::init(const QWidget *widget) QStyleOption::QStyleOption(const QStyleOption &other) : version(Version), type(Type), state(other.state), direction(other.direction), rect(other.rect), fontMetrics(other.fontMetrics), - palette(other.palette) + palette(other.palette), styleObject(other.styleObject) { } @@ -249,6 +250,7 @@ QStyleOption &QStyleOption::operator=(const QStyleOption &other) rect = other.rect; fontMetrics = other.fontMetrics; palette = other.palette; + styleObject = other.styleObject; return *this; } @@ -311,6 +313,15 @@ QStyleOption &QStyleOption::operator=(const QStyleOption &other) \sa initFrom() */ +/*! + \variable QStyleOption::styleObject + \brief the object being styled + + The built-in styles support the following types: QWidget, QGraphicsObject and QQuickItem. + + \sa initFrom() +*/ + /*! \variable QStyleOption::rect \brief the area that should be used for various calculations and painting @@ -4056,6 +4067,7 @@ QDebug operator<<(QDebug debug, const QStyleOption &option) debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight"); debug << ',' << option.state; debug << ',' << option.rect; + debug << ',' << option.styleObject; debug << ')'; #else Q_UNUSED(option); diff --git a/src/widgets/styles/qstyleoption.h b/src/widgets/styles/qstyleoption.h index 7ca0ca2bf3..d88582a9f8 100644 --- a/src/widgets/styles/qstyleoption.h +++ b/src/widgets/styles/qstyleoption.h @@ -89,6 +89,7 @@ public: QRect rect; QFontMetrics fontMetrics; QPalette palette; + QObject *styleObject; QStyleOption(int version = QStyleOption::Version, int type = SO_Default); QStyleOption(const QStyleOption &other); -- cgit v1.2.3