Fix some palette issues under OSX
This commit is contained in:
committed by
craig.p.drummond
parent
33d8421457
commit
1aba806904
@@ -27,6 +27,9 @@ if (NOT ENABLE_UBUNTU)
|
||||
set(SUPPORT_SRCS ${SUPPORT_SRCS} windowmanager.cpp)
|
||||
set(SUPPORT_MOC_HDRS ${SUPPORT_MOC_HDRS} windowmanager.h)
|
||||
endif (NOT WIN32)
|
||||
if (APPLE)
|
||||
set(SUPPORT_SRCS ${SUPPORT_SRCS} osxstyle.cpp)
|
||||
endif (APPLE)
|
||||
|
||||
if (ENABLE_KDE_SUPPORT)
|
||||
include_directories(${KDE4_INCLUDES})
|
||||
|
||||
@@ -39,6 +39,9 @@
|
||||
#include "gtkstyle.h"
|
||||
#include "action.h"
|
||||
#include "utils.h"
|
||||
#ifdef Q_OS_MAC
|
||||
#include "osxstyle.h"
|
||||
#endif
|
||||
#include <QHBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
@@ -202,13 +205,22 @@ void FancyTabProxyStyle::drawControl(ControlElement element, const QStyleOption
|
||||
if (!selected && GtkStyle::isActive()) {
|
||||
GtkStyle::drawSelection(styleOpt, p, (fader*1.0)/150.0);
|
||||
} else {
|
||||
#ifdef Q_OS_MAC
|
||||
OSXStyle::self()->drawSelection(styleOpt, p, selected ? 1.0 : (fader*1.0)/150.0);
|
||||
#else
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOpt, p, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int textFlags = Qt::AlignTop | Qt::AlignVCenter;
|
||||
#ifdef Q_OS_MAC
|
||||
p->setPen(selected && option->state&State_Active
|
||||
? OSXStyle::self()->viewPalette().highlightedText().color() : OSXStyle::self()->viewPalette().foreground().color());
|
||||
#else
|
||||
p->setPen(selected && option->state&State_Active
|
||||
? QApplication::palette().highlightedText().color() : QApplication::palette().foreground().color());
|
||||
#endif
|
||||
|
||||
drawIcon(v3Opt->icon, iconRect, p, v3Opt->iconSize,
|
||||
selected && option->state&State_Active);
|
||||
@@ -490,7 +502,11 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex, bool gtkStyle) const
|
||||
if (!selected && gtkStyle) {
|
||||
GtkStyle::drawSelection(styleOpt, painter, tabs[tabIndex]->fader()/150.0);
|
||||
} else {
|
||||
#ifdef Q_OS_MAC
|
||||
OSXStyle::self()->drawSelection(styleOpt, painter, selected ? 1.0 : tabs[tabIndex]->fader()/150.0);
|
||||
#else
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &styleOpt, painter, 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -500,7 +516,12 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex, bool gtkStyle) const
|
||||
QRect tabIconRect(tabTextRect);
|
||||
tabIconRect.adjust(+4, +4, -4, -4);
|
||||
tabTextRect.translate(0, -2);
|
||||
painter->setPen(selected ? palette().highlightedText().color() : palette().foreground().color());
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
painter->setPen(selected ? OSXStyle::self()->viewPalette().highlightedText().color() : OSXStyle::self()->viewPalette().foreground().color());
|
||||
#else
|
||||
painter->setPen(selected ? QApplication::palette().highlightedText().color() : palette().foreground().color());
|
||||
#endif
|
||||
int textFlags = Qt::AlignCenter | Qt::AlignBottom;
|
||||
painter->drawText(tabTextRect, textFlags, tabText);
|
||||
|
||||
|
||||
66
support/osxstyle.cpp
Normal file
66
support/osxstyle.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Cantata
|
||||
*
|
||||
* Copyright (c) 2011-2014 Craig Drummond <craig.p.drummond@gmail.com>
|
||||
*
|
||||
* ----
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "osxstyle.h"
|
||||
#include "globalstatic.h"
|
||||
#include <QApplication>
|
||||
#include <QStyle>
|
||||
#include <QTreeWidget>
|
||||
#include <QPainter>
|
||||
|
||||
GLOBAL_STATIC(OSXStyle, instance)
|
||||
|
||||
OSXStyle::OSXStyle()
|
||||
: view(0)
|
||||
{
|
||||
}
|
||||
|
||||
const QPalette & OSXStyle::viewPalette()
|
||||
{
|
||||
return viewWidget()->palette();
|
||||
}
|
||||
|
||||
void OSXStyle::drawSelection(QStyleOptionViewItemV4 opt, QPainter *painter, double opacity)
|
||||
{
|
||||
opt.palette=viewPalette();
|
||||
if (opacity<0.999) {
|
||||
QColor col(opt.palette.highlight().color());
|
||||
col.setAlphaF(opacity);
|
||||
opt.palette.setColor(opt.palette.currentColorGroup(), QPalette::Highlight, col);
|
||||
}
|
||||
QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, viewWidget());
|
||||
}
|
||||
|
||||
QColor OSXStyle::monoIconColor()
|
||||
{
|
||||
return QColor(96, 96, 96);
|
||||
}
|
||||
|
||||
QTreeWidget * OSXStyle::viewWidget()
|
||||
{
|
||||
if (!view) {
|
||||
view=new QTreeWidget();
|
||||
view->ensurePolished();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
51
support/osxstyle.h
Normal file
51
support/osxstyle.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Cantata
|
||||
*
|
||||
* Copyright (c) 2011-2014 Craig Drummond <craig.p.drummond@gmail.com>
|
||||
*
|
||||
* ----
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef OSXSTYLE_H
|
||||
#define OSXSTYLE_H
|
||||
|
||||
#include <QStyleOptionViewItemV4>
|
||||
|
||||
class QPalette;
|
||||
class QTreeWidget;
|
||||
class QPainter;
|
||||
class QColor;
|
||||
|
||||
class OSXStyle
|
||||
{
|
||||
public:
|
||||
static OSXStyle * self();
|
||||
|
||||
OSXStyle();
|
||||
const QPalette & viewPalette();
|
||||
void drawSelection(QStyleOptionViewItemV4 opt, QPainter *painter, double opacity);
|
||||
QColor monoIconColor();
|
||||
|
||||
private:
|
||||
QTreeWidget * viewWidget();
|
||||
|
||||
private:
|
||||
QTreeWidget *view;
|
||||
};
|
||||
|
||||
#endif // OSXSTYLE_H
|
||||
@@ -37,14 +37,12 @@
|
||||
#if !defined Q_OS_WIN && !defined Q_OS_MAC && !defined ENABLE_UBUNTU
|
||||
#include "support/gtkstyle.h"
|
||||
#endif
|
||||
#ifdef Q_OS_MAC
|
||||
#include "support/osxstyle.h"
|
||||
#endif
|
||||
|
||||
GLOBAL_STATIC(Icons, instance)
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
static const QColor macMonoIconCol(96, 96, 96);
|
||||
static const QColor macMonoIconColSel(240, 240, 240);
|
||||
#endif
|
||||
|
||||
static QList<int> constStdSizes=QList<int>() << 16 << 22 << 32 << 48;
|
||||
|
||||
static const int constDarkLimit=80;
|
||||
@@ -486,8 +484,8 @@ void Icons::initSidebarIcons()
|
||||
if (Settings::self()->monoSidebarIcons()) {
|
||||
monoSb=true;
|
||||
#ifdef Q_OS_MAC
|
||||
QColor textCol=macMonoIconCol;
|
||||
QColor highlightedTexCol=macMonoIconColSel;
|
||||
QColor textCol=OSXStyle::self()->monoIconColor();
|
||||
QColor highlightedTexCol=OSXStyle::self()->viewPalette().highlightedText().color();
|
||||
#else
|
||||
QColor textCol=QApplication::palette().color(QPalette::Active, QPalette::WindowText);
|
||||
QColor highlightedTexCol=QApplication::palette().color(QPalette::Active, QPalette::HighlightedText);
|
||||
@@ -552,7 +550,7 @@ void Icons::initToolbarIcons(const QColor &toolbarText)
|
||||
#endif
|
||||
bool rtl=QApplication::isRightToLeft();
|
||||
#ifdef Q_OS_MAC
|
||||
QColor col=macMonoIconCol;
|
||||
QColor col=OSXStyle::self()->monoIconColor();
|
||||
#else
|
||||
QColor col=GtkStyle::symbolicColor();
|
||||
#endif
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
#include "support/squeezedtextlabel.h"
|
||||
#include "support/utils.h"
|
||||
#include "support/localize.h"
|
||||
#ifdef Q_OS_MAC
|
||||
#include "support/osxstyle.h"
|
||||
#endif
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
#include <QProxyStyle>
|
||||
@@ -156,22 +159,27 @@ void PosSlider::updateStyleSheet()
|
||||
int lineWidth=maximumHeight()>12 ? 2 : 1;
|
||||
|
||||
QString boderFormat=QLatin1String("QSlider::groove:horizontal { border: %1px solid rgba(%2, %3, %4, %5); "
|
||||
"background: solid rgba(%6, %7, %8, %9); "
|
||||
"border-radius: %10px } ");
|
||||
"background: solid rgba(%2, %3, %4, %6); "
|
||||
"border-radius: %7px } ");
|
||||
QString fillFormat=QLatin1String("QSlider::")+QLatin1String(isRightToLeft() ? "add" : "sub")+
|
||||
QLatin1String("-page:horizontal {border: %1px solid palette(highlight); "
|
||||
"background: solid palette(highlight); "
|
||||
"border-radius: %2px; margin: %3px;}")+
|
||||
QLatin1String("-page:horizontal {border: %1px solid rgb(%3, %4, %5); "
|
||||
"background: solid rgb(%3, %4, %5); "
|
||||
"border-radius: %1px; margin: %2px;}")+
|
||||
QLatin1String("QSlider::")+QLatin1String(isRightToLeft() ? "add" : "sub")+
|
||||
QLatin1String("-page:horizontal:disabled {border: 0px; background: solid rgba(0, 0, 0, 0)}");
|
||||
QLabel lbl(parentWidget());
|
||||
lbl.ensurePolished();
|
||||
QColor textColor=lbl.palette().color(QPalette::Active, QPalette::Text);
|
||||
#ifdef Q_OS_MAC
|
||||
QColor fillColor=OSXStyle::self()->viewPalette().highlight().color();
|
||||
#else
|
||||
QColor fillColor=palette().highlight().color();
|
||||
#endif
|
||||
int alpha=textColor.value()<32 ? 96 : 64;
|
||||
|
||||
setStyleSheet(boderFormat.arg(lineWidth).arg(textColor.red()).arg(textColor.green()).arg(textColor.blue()).arg(alpha)
|
||||
.arg(textColor.red()).arg(textColor.green()).arg(textColor.blue()).arg(alpha/4).arg(lineWidth*2)+
|
||||
fillFormat.arg(lineWidth).arg(lineWidth).arg(lineWidth*2));
|
||||
.arg(alpha/4).arg(lineWidth*2)+
|
||||
fillFormat.arg(lineWidth).arg(lineWidth*2).arg(fillColor.red()).arg(fillColor.green()).arg(fillColor.blue()));
|
||||
}
|
||||
|
||||
void PosSlider::mouseMoveEvent(QMouseEvent *e)
|
||||
|
||||
Reference in New Issue
Block a user