src/gui/kernel/qapplication_mac.mm
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
--- a/src/gui/kernel/qapplication_mac.mm	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/gui/kernel/qapplication_mac.mm	Fri Apr 16 15:50:13 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -227,8 +227,29 @@
 
 static void qt_mac_read_fontsmoothing_settings()
 {
-    NSInteger appleFontSmoothing = [[NSUserDefaults standardUserDefaults] integerForKey:@"AppleFontSmoothing"];
-    qt_applefontsmoothing_enabled = (appleFontSmoothing > 0);
+    qt_applefontsmoothing_enabled = true;
+    int w = 10, h = 10;
+    QImage image(w, h, QImage::Format_RGB32);
+    image.fill(0xffffffff);
+    QPainter p(&image);
+    p.drawText(0, h, "X\\");
+    p.end();
+
+    const int *bits = (const int *) ((const QImage &) image).bits();
+    int bpl = image.bytesPerLine() / 4;
+    for (int y=0; y<w; ++y) {
+        for (int x=0; x<h; ++x) {
+            int r = qRed(bits[x]);
+            int g = qGreen(bits[x]);
+            int b = qBlue(bits[x]);
+            if (r != g || r != b) {
+                qt_applefontsmoothing_enabled = true;
+                return;
+            }
+        }
+        bits += bpl;
+    }
+    qt_applefontsmoothing_enabled = false;
 }
 
 Q_GUI_EXPORT bool qt_mac_execute_apple_script(const char *script, long script_len, AEDesc *ret) {
@@ -772,11 +793,11 @@
             qt_post_window_change_event(glWidget);
             it->lastUpdateWidget = widget;
         } else if (it->lastUpdateWidget == widget) {
-            // Update the gl wigets that the widget intersected the last time around, 
-            // and that we are not intersecting now. This prevents paint errors when the 
+            // Update the gl wigets that the widget intersected the last time around,
+            // and that we are not intersecting now. This prevents paint errors when the
             // intersecting widget leaves a gl widget.
             qt_post_window_change_event(glWidget);
-            it->lastUpdateWidget = 0;            
+            it->lastUpdateWidget = 0;
         }
     }
 #else
@@ -808,8 +829,8 @@
     // Post a kEventQtRequestWindowChange event. This event is semi-public,
     // don't remove this line!
     qt_event_request_window_change();
-    
-    // Post update request on gl widgets unconditionally. 
+
+    // Post update request on gl widgets unconditionally.
     if (qt_widget_private(widget)->isGLWidget == true) {
         qt_post_window_change_event(widget);
         return;
@@ -1214,8 +1235,6 @@
     if (QApplication::desktopSettingsAware())
         QApplicationPrivate::qt_mac_apply_settings();
 
-    qt_mac_read_fontsmoothing_settings();
-
     // Cocoa application delegate
 #ifdef QT_MAC_USE_COCOA
     NSApplication *cocoaApp = [NSApplication sharedApplication];
@@ -1253,6 +1272,7 @@
     }
    priv->native_modal_dialog_active = false;
 
+   qt_mac_read_fontsmoothing_settings();
 }
 
 void qt_release_apple_event_handler()
@@ -1705,7 +1725,7 @@
             // kEventMouseWheelMoved events if we dont eat this event
             // (actually two events; one for horizontal and one for vertical).
             // As a results of this, and to make sure we dont't receive duplicate events,
-            // we try to detect when this happend by checking the 'compatibilityEvent'. 
+            // we try to detect when this happend by checking the 'compatibilityEvent'.
             SInt32 mdelt = 0;
             GetEventParameter(event, kEventParamMouseWheelSmoothHorizontalDelta, typeSInt32, 0,
                               sizeof(mdelt), 0, &mdelt);
@@ -2123,6 +2143,7 @@
             }
 
             if (wheel_deltaX || wheel_deltaY) {
+#ifndef QT_NO_WHEELEVENT
                 if (wheel_deltaX) {
                     QWheelEvent qwe(plocal, p, wheel_deltaX, buttons, modifiers, Qt::Horizontal);
                     QApplication::sendSpontaneousEvent(widget, &qwe);
@@ -2145,6 +2166,7 @@
                             handled_event = false;
                     }
                 }
+#endif // QT_NO_WHEELEVENT
             } else {
 #ifdef QMAC_SPEAK_TO_ME
                 const int speak_keys = Qt::AltModifier | Qt::ShiftModifier;
@@ -2576,7 +2598,7 @@
     if (QApplicationPrivate::popupWidgets->isEmpty()) {  // this was the last popup
         delete QApplicationPrivate::popupWidgets;
         QApplicationPrivate::popupWidgets = 0;
-        
+
         // Special case for Tool windows: since they are activated and deactived together
         // with a normal window they never become the QApplicationPrivate::active_window.
         QWidget *appFocusWidget = QApplication::focusWidget();
@@ -2697,6 +2719,7 @@
     return QApplicationPrivate::keyboard_input_time;
 }
 
+#ifndef QT_NO_WHEELEVENT
 void QApplication::setWheelScrollLines(int n)
 {
     QApplicationPrivate::wheel_scroll_lines = n;
@@ -2706,6 +2729,7 @@
 {
     return QApplicationPrivate::wheel_scroll_lines;
 }
+#endif
 
 void QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable)
 {
@@ -2868,9 +2892,11 @@
                             QApplication::cursorFlashTime()).toInt();
         QApplication::setCursorFlashTime(num);
 
+#ifndef QT_NO_WHEELEVENT
         num = settings.value(QLatin1String("wheelScrollLines"),
                             QApplication::wheelScrollLines()).toInt();
         QApplication::setWheelScrollLines(num);
+#endif
 
         QString colorspec = settings.value(QLatin1String("colorSpec"),
                                             QVariant(QLatin1String("default"))).toString();