From 6ecee3c9790678d34b6d159a10d509d0f9244bc8 Mon Sep 17 00:00:00 2001
From: Harald Fernengel <harald.fernengel@nokia.com>
Date: Wed, 3 Mar 2010 15:38:43 +0100
Subject: Introduce a setAttribute_internal helper

This allows to switch certain attributes on or off without copy/pasting
lots of code. Used to switch off mutually exclusive attributes, e.g. the
Mac*Size attributes, or Maemo's portrait/landscape attributes.

Reviewed-by: Robert Griebl
---
 src/gui/kernel/qwidget.cpp | 50 +++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp
index 7fdee2b..14fecb0 100644
--- a/src/gui/kernel/qwidget.cpp
+++ b/src/gui/kernel/qwidget.cpp
@@ -10294,6 +10294,29 @@ const QPixmap *QWidget::icon() const
 
 #endif // QT3_SUPPORT
 
+ /*!
+  \internal
+
+  This just sets the corresponding attribute bit to 1 or 0
+ */
+static void setAttribute_internal(Qt::WidgetAttribute attribute, bool on, QWidgetData *data,
+                                  QWidgetPrivate *d)
+{
+    if (attribute < int(8*sizeof(uint))) {
+        if (on)
+            data->widget_attributes |= (1<<attribute);
+        else
+            data->widget_attributes &= ~(1<<attribute);
+    } else {
+        const int x = attribute - 8*sizeof(uint);
+        const int int_off = x / (8*sizeof(uint));
+        if (on)
+            d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
+        else
+            d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
+    }
+}
+
 /*!
     Sets the attribute \a attribute on this widget if \a on is true;
     otherwise clears the attribute.
@@ -10320,19 +10343,7 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
     }
 #endif
 
-    if (attribute < int(8*sizeof(uint))) {
-        if (on)
-            data->widget_attributes |= (1<<attribute);
-        else
-            data->widget_attributes &= ~(1<<attribute);
-    } else {
-        const int x = attribute - 8*sizeof(uint);
-        const int int_off = x / (8*sizeof(uint));
-        if (on)
-            d->high_attributes[int_off] |= (1<<(x-(int_off*8*sizeof(uint))));
-        else
-            d->high_attributes[int_off] &= ~(1<<(x-(int_off*8*sizeof(uint))));
-    }
+    setAttribute_internal(attribute, on, data, d);
 
     switch (attribute) {
 
@@ -10391,14 +10402,11 @@ void QWidget::setAttribute(Qt::WidgetAttribute attribute, bool on)
 #ifdef Q_WS_MAC
         {
             // We can only have one of these set at a time
-            static const int MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize,
-                                            Qt::WA_MacMiniSize, 0 };
-            for (int i = 0; MacSizes[i] != 0; ++i) {
-                if (MacSizes[i] == attribute)
-                    continue;
-                int macsize_x = MacSizes[i] - 8*sizeof(uint);
-                int macsize_int_off = macsize_x / (8*sizeof(uint));
-                d->high_attributes[macsize_int_off] &= ~(1<<(macsize_x-(macsize_int_off*8*sizeof(uint))));
+            const Qt::WidgetAttribute MacSizes[] = { Qt::WA_MacNormalSize, Qt::WA_MacSmallSize,
+                                                     Qt::WA_MacMiniSize };
+            for (int i = 0; i < 3; ++i) {
+                if (MacSizes[i] != attribute)
+                    setAttribute_internal(MacSizes[i], false, data, d);
             }
             d->macUpdateSizeAttribute();
         }
-- 
cgit v0.12