Cocoa: Implement QPlatformTheme:palette()
authorMorten Johan Sorvig <morten.sorvig@nokia.com>
Thu, 23 Feb 2012 07:50:28 +0000 (08:50 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 1 Mar 2012 12:55:49 +0000 (13:55 +0100)
Causes a new test failure in QGraphicsProxyWidget::updateAndDelete,
expand the EXPECT_FAIL to cover that one as well.

Change-Id: If9da757206445d17510c4fac82a559de7b8c0563
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
src/plugins/platforms/cocoa/cocoa.pro
src/plugins/platforms/cocoa/qcocoasystemsettings.h [new file with mode: 0644]
src/plugins/platforms/cocoa/qcocoasystemsettings.mm [new file with mode: 0644]
src/plugins/platforms/cocoa/qcocoatheme.h
src/plugins/platforms/cocoa/qcocoatheme.mm
tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp

index 45dd352..ce87de2 100644 (file)
@@ -27,6 +27,7 @@ OBJECTIVE_SOURCES += main.mm \
     qcocoafiledialoghelper.mm \
     qcocoafontdialoghelper.mm \
     qcocoacursor.mm \
+    qcocoasystemsettings.mm \
 
 HEADERS += qcocoaintegration.h \
     qcocoatheme.h \
@@ -51,6 +52,7 @@ HEADERS += qcocoaintegration.h \
     qcocoafiledialoghelper.h \
     qcocoafontdialoghelper.h \
     qcocoacursor.h \
+    qcocoasystemsettings.h \
 
 FORMS += $$PWD/../../../widgets/dialogs/qfiledialog.ui
 RESOURCES += qcocoaresources.qrc
diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.h b/src/plugins/platforms/cocoa/qcocoasystemsettings.h
new file mode 100644 (file)
index 0000000..84a66d7
--- /dev/null
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QCOCOASYSTEMSETTINGS_H
+#define QCOCOASYSTEMSETTINGS_H
+
+#include <QtCore/qglobal.h>
+#include <QtGui/qpalette.h>
+
+QT_BEGIN_NAMESPACE
+
+QPalette * qt_mac_createSystemPalette();
+
+QT_END_NAMESPACE
+
+#endif
diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm
new file mode 100644 (file)
index 0000000..5170c0b
--- /dev/null
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qcocoasystemsettings.h"
+
+#include <Carbon/Carbon.h>
+#include <QtCore/private/qcore_mac_p.h>
+
+QColor qt_mac_colorFromCGColor(CGColorRef cgcolor)
+{
+    QColor pc;
+    CGColorSpaceModel model = CGColorSpaceGetModel(CGColorGetColorSpace(cgcolor));
+    const CGFloat *components = CGColorGetComponents(cgcolor);
+    if (model == kCGColorSpaceModelRGB) {
+        pc.setRgbF(components[0], components[1], components[2], components[3]);
+    } else if (model == kCGColorSpaceModelCMYK) {
+        pc.setCmykF(components[0], components[1], components[2], components[3]);
+    } else if (model == kCGColorSpaceModelMonochrome) {
+        pc.setRgbF(components[0], components[0], components[0], components[1]);
+    } else {
+        // Colorspace we can't deal with.
+        qWarning("Qt: qcolorFromCGColor: cannot convert from colorspace model: %d", model);
+        Q_ASSERT(false);
+    }
+    return pc;
+}
+
+QColor qt_mac_colorForTheme(ThemeBrush brush)
+{
+    QCFType<CGColorRef> cgClr = 0;
+    HIThemeBrushCreateCGColor(brush, &cgClr);
+    return qt_mac_colorFromCGColor(cgClr);
+}
+
+QColor qt_mac_colorForThemeTextColor(ThemeTextColor themeColor)
+{
+    // No GetThemeTextColor in 64-bit mode, use hardcoded values:
+    switch (themeColor) {
+    case kThemeTextColorAlertActive:
+    case kThemeTextColorTabFrontActive:
+    case kThemeTextColorBevelButtonActive:
+    case kThemeTextColorListView:
+    case kThemeTextColorPlacardActive:
+    case kThemeTextColorPopupButtonActive:
+    case kThemeTextColorPopupLabelActive:
+    case kThemeTextColorPushButtonActive:
+        return Qt::black;
+    case kThemeTextColorAlertInactive:
+    case kThemeTextColorDialogInactive:
+    case kThemeTextColorPlacardInactive:
+        return QColor(69, 69, 69, 255);
+    case kThemeTextColorPopupButtonInactive:
+    case kThemeTextColorPopupLabelInactive:
+    case kThemeTextColorPushButtonInactive:
+    case kThemeTextColorTabFrontInactive:
+    case kThemeTextColorBevelButtonInactive:
+        return QColor(127, 127, 127, 255);
+    default:
+        return QColor(0, 0, 0, 255); // ### TODO: Sample color like Qt 4.
+    }
+}
+
+QPalette * qt_mac_createSystemPalette()
+{
+    QColor qc;
+
+    // Standard palette initialization (copied from Qt 4 styles)
+    QColor background = QColor(0xd4, 0xd0, 0xc8); // win 2000 grey
+    QColor light(background.lighter());
+    QColor dark(background.darker());
+    QColor mid(Qt::gray);
+    QPalette *palette = new QPalette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
+
+    palette->setBrush(QPalette::Disabled, QPalette::WindowText, dark);
+    palette->setBrush(QPalette::Disabled, QPalette::Text, dark);
+    palette->setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
+    palette->setBrush(QPalette::Disabled, QPalette::Base, background);
+    palette->setColor(QPalette::Disabled, QPalette::Dark, QColor(191, 191, 191));
+    palette->setColor(QPalette::Active, QPalette::Dark, QColor(191, 191, 191));
+    palette->setColor(QPalette::Inactive, QPalette::Dark, QColor(191, 191, 191));
+
+    // System palette initialization:
+    palette->setBrush( QPalette::Active, QPalette::Highlight, qt_mac_colorForTheme(kThemeBrushPrimaryHighlightColor) );
+    palette->setBrush( QPalette::Inactive, QPalette::Highlight, qt_mac_colorForTheme(kThemeBrushSecondaryHighlightColor) );
+
+    palette->setBrush( QPalette::Disabled, QPalette::Highlight, qt_mac_colorForTheme(kThemeBrushSecondaryHighlightColor) );
+    palette->setBrush( QPalette::Active, QPalette::Shadow, qt_mac_colorForTheme(kThemeBrushButtonActiveDarkShadow) );
+
+    palette->setBrush( QPalette::Inactive, QPalette::Shadow, qt_mac_colorForTheme(kThemeBrushButtonInactiveDarkShadow) );
+    palette->setBrush( QPalette::Disabled, QPalette::Shadow, qt_mac_colorForTheme(kThemeBrushButtonInactiveDarkShadow) );
+
+    qc = qt_mac_colorForThemeTextColor(kThemeTextColorDialogActive);
+    palette->setColor(QPalette::Active, QPalette::Text, qc);
+    palette->setColor(QPalette::Active, QPalette::WindowText, qc);
+    palette->setColor(QPalette::Active, QPalette::HighlightedText, qc);
+
+    qc = qt_mac_colorForThemeTextColor(kThemeTextColorDialogInactive);
+    palette->setColor(QPalette::Inactive, QPalette::Text, qc);
+    palette->setColor(QPalette::Inactive, QPalette::WindowText, qc);
+    palette->setColor(QPalette::Inactive, QPalette::HighlightedText, qc);
+    palette->setColor(QPalette::Disabled, QPalette::Text, qc);
+    palette->setColor(QPalette::Disabled, QPalette::WindowText, qc);
+    palette->setColor(QPalette::Disabled, QPalette::HighlightedText, qc);
+    palette->setBrush(QPalette::ToolTipBase, QColor(255, 255, 199));
+    return palette;
+}
+
index a7dc973..fa235b6 100644 (file)
@@ -48,6 +48,7 @@
 
 QT_BEGIN_NAMESPACE
 
+class QPalette;
 class QCocoaTheme : public QPlatformTheme
 {
 public:
@@ -60,7 +61,11 @@ public:
     bool usePlatformNativeDialog(DialogType dialogType) const;
     QPlatformDialogHelper *createPlatformDialogHelper(DialogType dialogType) const;
 
+    const QPalette *palette(Palette type = SystemPalette) const;
+
     QVariant themeHint(ThemeHint hint) const;
+private:
+    mutable QPalette *m_systemPalette;
 };
 
 QT_END_NAMESPACE
index 0fef323..6b0e04a 100644 (file)
 #include "qcocoacolordialoghelper.h"
 #include "qcocoafiledialoghelper.h"
 #include "qcocoafontdialoghelper.h"
+#include "qcocoasystemsettings.h"
 
 QT_BEGIN_NAMESPACE
 
 QCocoaTheme::QCocoaTheme()
+    :m_systemPalette(0)
 {
 
 }
 
 QCocoaTheme::~QCocoaTheme()
 {
-
+    delete m_systemPalette;
 }
 
 QPlatformMenu *QCocoaTheme::createPlatformMenu(QMenu *menu) const
@@ -102,6 +104,17 @@ QPlatformDialogHelper * QCocoaTheme::createPlatformDialogHelper(DialogType dialo
     }
 }
 
+const QPalette *QCocoaTheme::palette(Palette type) const
+{
+    if (type == SystemPalette) {
+        if (!m_systemPalette)
+            m_systemPalette = qt_mac_createSystemPalette();
+
+        return m_systemPalette;
+    }
+    return 0;
+}
+
 QVariant QCocoaTheme::themeHint(ThemeHint hint) const
 {
     switch (hint) {
index ca5b992..843b584 100644 (file)
@@ -3379,10 +3379,11 @@ void tst_QGraphicsProxyWidget::updateAndDelete()
     // Update and hide.
     proxy->update();
     proxy->hide();
-    QTRY_COMPARE(view.npaints, 1);
 #ifdef Q_OS_MAC
-    QEXPECT_FAIL("", "QTBUG-23700", Continue);
+    QEXPECT_FAIL("", "QTBUG-23700", Abort);
 #endif
+
+    QTRY_COMPARE(view.npaints, 1);
     QCOMPARE(view.paintEventRegion, expectedRegion);
 
     proxy->show();