Cocoa: Implement widget palettes.
Add roles to QPLatformTheme::Palette, map QWidget subclasses to those. Port Qt4 widget palette creation code to use the QPLatformTheme::Palette roles. Palette entries are disabled in this commit, this will be fixed later. Change-Id: I07babe3d7c76d306efc4ea4813c7161fdf36227f Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
This commit is contained in:
parent
9d5e721e96
commit
930a90d978
@ -86,6 +86,19 @@ public:
|
||||
enum Palette {
|
||||
SystemPalette,
|
||||
ToolTipPalette,
|
||||
ToolButtonPalette,
|
||||
ButtonPalette,
|
||||
HeaderPalette,
|
||||
ComboBoxPalette,
|
||||
ItemViewPalette,
|
||||
MessageBoxLabelPelette,
|
||||
TabBarPalette,
|
||||
LabelPalette,
|
||||
GroupBoxPalette,
|
||||
MenuPalette,
|
||||
MenuBarPalette,
|
||||
TextEditPalette,
|
||||
TextLineEditPalette,
|
||||
NPalettes
|
||||
};
|
||||
|
||||
|
@ -42,12 +42,14 @@
|
||||
#ifndef QCOCOASYSTEMSETTINGS_H
|
||||
#define QCOCOASYSTEMSETTINGS_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtGui/qpalette.h>
|
||||
#include <QtGui/qplatformtheme_qpa.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QPalette * qt_mac_createSystemPalette();
|
||||
QHash<QPlatformTheme::Palette, QPalette*> qt_mac_createRolePalettes();
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
@ -41,9 +41,10 @@
|
||||
|
||||
#include "qcocoasystemsettings.h"
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
#include <QtCore/private/qcore_mac_p.h>
|
||||
|
||||
#include <Carbon/Carbon.h>
|
||||
|
||||
QColor qt_mac_colorFromCGColor(CGColorRef cgcolor)
|
||||
{
|
||||
QColor pc;
|
||||
@ -143,3 +144,86 @@ QPalette * qt_mac_createSystemPalette()
|
||||
return palette;
|
||||
}
|
||||
|
||||
|
||||
struct QMacPaletteMap {
|
||||
inline QMacPaletteMap(QPlatformTheme::Palette p, ThemeBrush a, ThemeBrush i) :
|
||||
paletteRole(p), active(a), inactive(i) { }
|
||||
|
||||
QPlatformTheme::Palette paletteRole;
|
||||
ThemeBrush active, inactive;
|
||||
};
|
||||
|
||||
static QMacPaletteMap mac_widget_colors[] = {
|
||||
// TODO (msorvig): Fix/match palette behavior with Qt 4 and enable.
|
||||
//
|
||||
// QMacPaletteMap(QPlatformTheme::ToolButtonPalette, kThemeTextColorBevelButtonActive, kThemeTextColorBevelButtonInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::ButtonPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::HeaderPalette, kThemeTextColorPushButtonActive, kThemeTextColorPushButtonInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::ComboBoxPalette, kThemeTextColorPopupButtonActive, kThemeTextColorPopupButtonInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::ItemViewPalette, kThemeTextColorListView, kThemeTextColorDialogInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::MessageBoxLabelPelette, kThemeTextColorAlertActive, kThemeTextColorAlertInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::TabBarPalette, kThemeTextColorTabFrontActive, kThemeTextColorTabFrontInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::LabelPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::GroupBoxPalette, kThemeTextColorPlacardActive, kThemeTextColorPlacardInactive),
|
||||
// QMacPaletteMap(QPlatformTheme::MenuPalette, kThemeTextColorPopupLabelActive, kThemeTextColorPopupLabelInactive),
|
||||
// ### TODO: The zeros below gives white-on-black text.
|
||||
// QMacPaletteMap(QPlatformTheme::TextEditPalette, 0, 0),
|
||||
// QMacPaletteMap(QPlatformTheme::TextLineEditPalette, 0, 0),
|
||||
QMacPaletteMap(QPlatformTheme::NPalettes, 0, 0) };
|
||||
|
||||
QHash<QPlatformTheme::Palette, QPalette*> qt_mac_createRolePalettes()
|
||||
{
|
||||
QHash<QPlatformTheme::Palette, QPalette*> palettes;
|
||||
QColor qc;
|
||||
for (int i = 0; mac_widget_colors[i].paletteRole != QPlatformTheme::NPalettes; i++) {
|
||||
QPalette pal;
|
||||
if (mac_widget_colors[i].active != 0) {
|
||||
qc = qt_mac_colorForThemeTextColor(mac_widget_colors[i].active);
|
||||
pal.setColor(QPalette::Active, QPalette::Text, qc);
|
||||
pal.setColor(QPalette::Active, QPalette::WindowText, qc);
|
||||
pal.setColor(QPalette::Active, QPalette::HighlightedText, qc);
|
||||
qc = qt_mac_colorForThemeTextColor(mac_widget_colors[i].inactive);
|
||||
pal.setColor(QPalette::Inactive, QPalette::Text, qc);
|
||||
pal.setColor(QPalette::Disabled, QPalette::Text, qc);
|
||||
pal.setColor(QPalette::Inactive, QPalette::WindowText, qc);
|
||||
pal.setColor(QPalette::Disabled, QPalette::WindowText, qc);
|
||||
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, qc);
|
||||
pal.setColor(QPalette::Disabled, QPalette::HighlightedText, qc);
|
||||
}
|
||||
if (mac_widget_colors[i].paletteRole == QPlatformTheme::MenuPalette) {
|
||||
qc = qt_mac_colorForThemeTextColor(kThemeTextColorMenuItemActive);
|
||||
pal.setBrush(QPalette::ButtonText, qc);
|
||||
qc = qt_mac_colorForThemeTextColor(kThemeTextColorMenuItemSelected);
|
||||
pal.setBrush(QPalette::HighlightedText, qc);
|
||||
qc = qt_mac_colorForThemeTextColor(kThemeTextColorMenuItemDisabled);
|
||||
pal.setBrush(QPalette::Disabled, QPalette::Text, qc);
|
||||
} else if ((mac_widget_colors[i].paletteRole == QPlatformTheme::ButtonPalette)
|
||||
|| (mac_widget_colors[i].paletteRole == QPlatformTheme::HeaderPalette)) {
|
||||
pal.setColor(QPalette::Disabled, QPalette::ButtonText,
|
||||
pal.color(QPalette::Disabled, QPalette::Text));
|
||||
pal.setColor(QPalette::Inactive, QPalette::ButtonText,
|
||||
pal.color(QPalette::Inactive, QPalette::Text));
|
||||
pal.setColor(QPalette::Active, QPalette::ButtonText,
|
||||
pal.color(QPalette::Active, QPalette::Text));
|
||||
} else if (mac_widget_colors[i].paletteRole == QPlatformTheme::ItemViewPalette) {
|
||||
pal.setBrush(QPalette::Active, QPalette::Highlight,
|
||||
qt_mac_colorForTheme(kThemeBrushAlternatePrimaryHighlightColor));
|
||||
qc = qt_mac_colorForThemeTextColor(kThemeTextColorMenuItemSelected);
|
||||
pal.setBrush(QPalette::Active, QPalette::HighlightedText, qc);
|
||||
pal.setBrush(QPalette::Inactive, QPalette::Text,
|
||||
pal.brush(QPalette::Active, QPalette::Text));
|
||||
pal.setBrush(QPalette::Inactive, QPalette::HighlightedText,
|
||||
pal.brush(QPalette::Active, QPalette::Text));
|
||||
} else if (mac_widget_colors[i].paletteRole == QPlatformTheme::TextEditPalette) {
|
||||
pal.setBrush(QPalette::Inactive, QPalette::Text,
|
||||
pal.brush(QPalette::Active, QPalette::Text));
|
||||
pal.setBrush(QPalette::Inactive, QPalette::HighlightedText,
|
||||
pal.brush(QPalette::Active, QPalette::Text));
|
||||
} else if (mac_widget_colors[i].paletteRole == QPlatformTheme::TextLineEditPalette) {
|
||||
pal.setBrush(QPalette::Disabled, QPalette::Base,
|
||||
pal.brush(QPalette::Active, QPalette::Base));
|
||||
}
|
||||
palettes.insert(mac_widget_colors[i].paletteRole, new QPalette(pal));
|
||||
}
|
||||
return palettes;
|
||||
}
|
||||
|
@ -42,8 +42,7 @@
|
||||
#ifndef QPLATFORMTHEME_COCOA_H
|
||||
#define QPLATFORMTHEME_COCOA_H
|
||||
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtGui/QPlatformTheme>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -66,6 +65,7 @@ public:
|
||||
QVariant themeHint(ThemeHint hint) const;
|
||||
private:
|
||||
mutable QPalette *m_systemPalette;
|
||||
mutable QHash<QPlatformTheme::Palette, QPalette*> m_palettes;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -109,8 +109,11 @@ const QPalette *QCocoaTheme::palette(Palette type) const
|
||||
if (type == SystemPalette) {
|
||||
if (!m_systemPalette)
|
||||
m_systemPalette = qt_mac_createSystemPalette();
|
||||
|
||||
return m_systemPalette;
|
||||
} else {
|
||||
if (m_palettes.isEmpty())
|
||||
m_palettes = qt_mac_createRolePalettes();
|
||||
return m_palettes.value(type, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -131,8 +131,11 @@ QApplicationPrivate *QApplicationPrivate::self = 0;
|
||||
static void initSystemPalette()
|
||||
{
|
||||
if (!QApplicationPrivate::sys_pal)
|
||||
if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette())
|
||||
if (const QPalette *themePalette = QGuiApplicationPrivate::platformTheme()->palette()) {
|
||||
QApplicationPrivate::setSystemPalette(*themePalette);
|
||||
QApplicationPrivate::initializeWidgetPaletteHash();
|
||||
}
|
||||
|
||||
if (!QApplicationPrivate::sys_pal && QApplicationPrivate::app_style)
|
||||
QApplicationPrivate::setSystemPalette(QApplicationPrivate::app_style->standardPalette());
|
||||
}
|
||||
|
@ -289,8 +289,33 @@ void QApplicationPrivate::cleanupMultitouch_sys()
|
||||
{
|
||||
}
|
||||
|
||||
static void setPossiblePalette(const QPalette *palette, const char *className)
|
||||
{
|
||||
if (palette == 0)
|
||||
return;
|
||||
QApplicationPrivate::setPalette_helper(*palette, className, false);
|
||||
}
|
||||
|
||||
|
||||
void QApplicationPrivate::initializeWidgetPaletteHash()
|
||||
{
|
||||
QPlatformTheme *platformTheme = QGuiApplicationPrivate::platformTheme();
|
||||
if (!platformTheme)
|
||||
return;
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::ToolButtonPalette), "QToolButton");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::ButtonPalette), "QAbstractButton");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::HeaderPalette), "QHeaderView");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::HeaderPalette), "Q3Header");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::ItemViewPalette), "QAbstractItemView");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::MessageBoxLabelPelette), "QMessageBoxLabel");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::TabBarPalette), "QTabBar");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::LabelPalette), "QLabel");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::GroupBoxPalette), "QGroupBox");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuPalette), "QMenu");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::MenuBarPalette), "QMenuBar");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextEdit");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::TextEditPalette), "QTextControl");
|
||||
setPossiblePalette(platformTheme->palette(QPlatformTheme::TextLineEditPalette), "QLineEdit");
|
||||
}
|
||||
|
||||
#ifndef QT_NO_WHEELEVENT
|
||||
|
Loading…
Reference in New Issue
Block a user