macOS: Fix qt5.12 scale issues and dark mode (#3588)

* Maybe fix QT 5.12 scale.

* Use Palette colors
This commit is contained in:
Rob Blanckaert 2019-02-24 10:05:09 -08:00 committed by GitHub
parent e68305d7bf
commit 45b16ba78d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 32 additions and 21 deletions

View file

@ -34,7 +34,5 @@
<string>${MACOSX_BUNDLE_COPYRIGHT}</string> <string>${MACOSX_BUNDLE_COPYRIGHT}</string>
<key>NSHighResolutionCapable</key> <key>NSHighResolutionCapable</key>
<true/> <true/>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
</dict> </dict>
</plist> </plist>

View file

@ -77,13 +77,11 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
painter->resetTransform(); resetPainterTransform(painter);
QTransform pixmapTransform; painter->translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); painter->rotate(angle);
pixmapTransform.rotate(angle); painter->translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform);
QFont f; QFont f;
f.setPixelSize(fontSize); f.setPixelSize(fontSize);
@ -313,4 +311,4 @@ QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change,
return value; return value;
} else } else
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);
} }

View file

@ -49,3 +49,8 @@ void AbstractGraphicsItem::paintNumberEllipse(int number,
painter->restore(); painter->restore();
} }
void resetPainterTransform(QPainter *painter)
{
painter->resetTransform();
painter->setTransform(painter->deviceTransform().inverted());
}

View file

@ -26,4 +26,6 @@ public:
} }
}; };
void resetPainterTransform(QPainter *painter);
#endif #endif

View file

@ -34,7 +34,7 @@ ChatView::ChatView(const TabSupervisor *_tabSupervisor,
mentionFormat.setFontWeight(QFont::Bold); mentionFormat.setFontWeight(QFont::Bold);
mentionFormatOtherUser.setFontWeight(QFont::Bold); mentionFormatOtherUser.setFontWeight(QFont::Bold);
mentionFormatOtherUser.setForeground(Qt::blue); mentionFormatOtherUser.setForeground(palette().link());
mentionFormatOtherUser.setAnchor(true); mentionFormatOtherUser.setAnchor(true);
viewport()->setCursor(Qt::IBeamCursor); viewport()->setCursor(Qt::IBeamCursor);
@ -60,7 +60,11 @@ QTextCursor ChatView::prepareBlock(bool same)
} else { } else {
QTextBlockFormat blockFormat; QTextBlockFormat blockFormat;
if ((evenNumber = !evenNumber)) if ((evenNumber = !evenNumber))
blockFormat.setBackground(palette().alternateBase()); blockFormat.setBackground(palette().window());
else
blockFormat.setBackground(palette().base());
blockFormat.setForeground(palette().text());
blockFormat.setBottomMargin(4); blockFormat.setBottomMargin(4);
cursor.insertBlock(blockFormat); cursor.insertBlock(blockFormat);
} }
@ -95,7 +99,7 @@ void ChatView::appendCardTag(QTextCursor &cursor, const QString &cardName)
{ {
QTextCharFormat oldFormat = cursor.charFormat(); QTextCharFormat oldFormat = cursor.charFormat();
QTextCharFormat anchorFormat = oldFormat; QTextCharFormat anchorFormat = oldFormat;
anchorFormat.setForeground(Qt::blue); anchorFormat.setForeground(palette().link());
anchorFormat.setAnchor(true); anchorFormat.setAnchor(true);
anchorFormat.setAnchorHref("card://" + cardName); anchorFormat.setAnchorHref("card://" + cardName);
anchorFormat.setFontItalic(true); anchorFormat.setFontItalic(true);
@ -112,10 +116,10 @@ void ChatView::appendUrlTag(QTextCursor &cursor, QString url)
QTextCharFormat oldFormat = cursor.charFormat(); QTextCharFormat oldFormat = cursor.charFormat();
QTextCharFormat anchorFormat = oldFormat; QTextCharFormat anchorFormat = oldFormat;
anchorFormat.setForeground(Qt::blue); anchorFormat.setForeground(palette().link());
anchorFormat.setAnchor(true); anchorFormat.setAnchor(true);
anchorFormat.setAnchorHref(url); anchorFormat.setAnchorHref(url);
anchorFormat.setUnderlineColor(Qt::blue); anchorFormat.setUnderlineColor(palette().link().color());
anchorFormat.setFontUnderline(true); anchorFormat.setFontUnderline(true);
cursor.setCharFormat(anchorFormat); cursor.setCharFormat(anchorFormat);

View file

@ -1,4 +1,5 @@
#include "counter_general.h" #include "counter_general.h"
#include "abstractgraphicsitem.h"
#include "pixmapgenerator.h" #include "pixmapgenerator.h"
#include <QPainter> #include <QPainter>
@ -28,7 +29,7 @@ void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /
QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered); QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
painter->save(); painter->save();
painter->resetTransform(); resetPainterTransform(painter);
painter->drawPixmap(QPoint(0, 0), pixmap); painter->drawPixmap(QPoint(0, 0), pixmap);
if (value) { if (value) {

View file

@ -33,7 +33,7 @@ void HandCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
cachedPixmap = QPixmap("theme:hand").scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation); cachedPixmap = QPixmap("theme:hand").scaled(translatedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap); QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
} }
painter->resetTransform(); resetPainterTransform(painter);
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect()); painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
painter->restore(); painter->restore();

View file

@ -48,7 +48,7 @@ void PhaseButton::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*op
painter->setPen(Qt::gray); painter->setPen(Qt::gray);
painter->drawRect(0, 0, static_cast<int>(width - 1), static_cast<int>(width - 1)); painter->drawRect(0, 0, static_cast<int>(width - 1), static_cast<int>(width - 1));
painter->save(); painter->save();
painter->resetTransform(); resetPainterTransform(painter);
painter->drawPixmap(iconPixmap.rect().translated(static_cast<int>(round(3 * scaleFactor)), painter->drawPixmap(iconPixmap.rect().translated(static_cast<int>(round(3 * scaleFactor)),
static_cast<int>(round(3 * scaleFactor))), static_cast<int>(round(3 * scaleFactor))),
iconPixmap, iconPixmap.rect()); iconPixmap, iconPixmap.rect());

View file

@ -1,6 +1,7 @@
#ifndef PHASESTOOLBAR_H #ifndef PHASESTOOLBAR_H
#define PHASESTOOLBAR_H #define PHASESTOOLBAR_H
#include "abstractgraphicsitem.h"
#include <QFrame> #include <QFrame>
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QList> #include <QList>

View file

@ -173,7 +173,7 @@ void PlayerListWidget::setActivePlayer(int playerId)
while (i.hasNext()) { while (i.hasNext()) {
i.next(); i.next();
QTreeWidgetItem *twi = i.value(); QTreeWidgetItem *twi = i.value();
QColor c = i.key() == playerId ? QColor(150, 255, 150) : Qt::white; QColor c = i.key() == playerId ? QColor(150, 255, 150) : palette().base().color();
twi->setBackground(4, c); twi->setBackground(4, c);
} }
} }

View file

@ -110,7 +110,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
} }
painter->save(); painter->save();
painter->resetTransform(); resetPainterTransform(painter);
painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0); painter->translate((translatedSize.width() - cachedPixmap.width()) / 2.0, 0);
painter->drawPixmap(translatedRect, cachedPixmap, cachedPixmap.rect()); painter->drawPixmap(translatedRect, cachedPixmap, cachedPixmap.rect());
painter->restore(); painter->restore();
@ -120,7 +120,7 @@ void PlayerTarget::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*o
QRectF translatedNameRect = painter->combinedTransform().mapRect(nameRect); QRectF translatedNameRect = painter->combinedTransform().mapRect(nameRect);
painter->save(); painter->save();
painter->resetTransform(); resetPainterTransform(painter);
QString name = QString::fromStdString(info->name()); QString name = QString::fromStdString(info->name());
if (name.size() > 13) if (name.size() > 13)

View file

@ -10,6 +10,7 @@
#include "tab_supervisor.h" #include "tab_supervisor.h"
#include "tab_userlists.h" #include "tab_userlists.h"
#include "user_context_menu.h" #include "user_context_menu.h"
#include <QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QHeaderView> #include <QHeaderView>
@ -23,6 +24,7 @@
#include <QRadioButton> #include <QRadioButton>
#include <QSpinBox> #include <QSpinBox>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWidget>
BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent) : QDialog(parent) BanDialog::BanDialog(const ServerInfo_User &info, QWidget *parent) : QDialog(parent)
{ {
@ -296,7 +298,7 @@ void UserListTWI::setUserInfo(const ServerInfo_User &_userInfo)
void UserListTWI::setOnline(bool online) void UserListTWI::setOnline(bool online)
{ {
setData(0, Qt::UserRole + 1, online); setData(0, Qt::UserRole + 1, online);
setData(2, Qt::ForegroundRole, online ? QBrush() : QBrush(Qt::gray)); setData(2, Qt::ForegroundRole, online ? qApp->palette().brush(QPalette::WindowText) : QBrush(Qt::gray));
} }
bool UserListTWI::operator<(const QTreeWidgetItem &other) const bool UserListTWI::operator<(const QTreeWidgetItem &other) const