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>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSRequiresAquaSystemAppearance</key>
<true/>
</dict>
</plist>

View file

@ -77,13 +77,11 @@ void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &transla
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
painter->resetTransform();
resetPainterTransform(painter);
QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform);
painter->translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
painter->rotate(angle);
painter->translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
QFont f;
f.setPixelSize(fontSize);

View file

@ -49,3 +49,8 @@ void AbstractGraphicsItem::paintNumberEllipse(int number,
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

View file

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

View file

@ -1,4 +1,5 @@
#include "counter_general.h"
#include "abstractgraphicsitem.h"
#include "pixmapgenerator.h"
#include <QPainter>
@ -28,7 +29,7 @@ void GeneralCounter::paint(QPainter *painter, const QStyleOptionGraphicsItem * /
QPixmap pixmap = CounterPixmapGenerator::generatePixmap(translatedHeight, name, hovered);
painter->save();
painter->resetTransform();
resetPainterTransform(painter);
painter->drawPixmap(QPoint(0, 0), pixmap);
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);
QPixmapCache::insert("handCounter" + QString::number(translatedSize.width()), cachedPixmap);
}
painter->resetTransform();
resetPainterTransform(painter);
painter->drawPixmap(cachedPixmap.rect(), cachedPixmap, cachedPixmap.rect());
painter->restore();

View file

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

View file

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

View file

@ -173,7 +173,7 @@ void PlayerListWidget::setActivePlayer(int playerId)
while (i.hasNext()) {
i.next();
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);
}
}

View file

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

View file

@ -10,6 +10,7 @@
#include "tab_supervisor.h"
#include "tab_userlists.h"
#include "user_context_menu.h"
#include <QApplication>
#include <QCheckBox>
#include <QHBoxLayout>
#include <QHeaderView>
@ -23,6 +24,7 @@
#include <QRadioButton>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QWidget>
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)
{
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