Add QObject* QStyleOption::styleObject
authorJ-P Nurmi <jpnurmi@digia.com>
Mon, 15 Oct 2012 12:10:58 +0000 (14:10 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 16 Oct 2012 13:29:15 +0000 (15:29 +0200)
The object is used, amongst other things, as a target for
sending style animation updates.

Change-Id: Ic210e7ae2111bc08b70331a3a2030a494919a06d
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
src/widgets/styles/qstyleoption.cpp
src/widgets/styles/qstyleoption.h

index 3017f30..8a469b4 100644 (file)
@@ -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<QWidget*>(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;
 }
 
@@ -312,6 +314,15 @@ QStyleOption &QStyleOption::operator=(const QStyleOption &other)
 */
 
 /*!
+    \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);
index 7ca0ca2..d88582a 100644 (file)
@@ -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);