diff --git a/accountitemdelegate.cpp b/accountitemdelegate.cpp index 351a2308fcaa992f8662234e72fc1a25af3b548f..015e35f7b255e15b099a52a85efd701d860356f2 100644 --- a/accountitemdelegate.cpp +++ b/accountitemdelegate.cpp @@ -26,6 +26,7 @@ #include "accountlistmodel.h" #include "ringthemeutils.h" #include "lrcinstance.h" +#include "mainwindow.h" #undef REGISTERED @@ -63,8 +64,18 @@ AccountItemDelegate::paint(QPainter* painter, QRect &rect = opt.rect; - QFont font(painter->font()); - font.setPointSize(fontSize_); + // define and set the two fonts + QFont fontPrimary = painter->font(); + QFont fontSecondary = painter->font(); + fontPrimary.setWeight(QFont::ExtraLight); + auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); + if (scalingRatio > 1.0) { + fontPrimary.setPointSize(fontSize_ - 1); + fontSecondary.setPointSize(fontSize_ - 2); + } else { + fontPrimary.setPointSize(fontSize_); + fontSecondary.setPointSize(fontSize_ - 1); + } QPen pen(painter->pen()); @@ -72,8 +83,8 @@ AccountItemDelegate::paint(QPainter* painter, if (index.row() == LRCInstance::accountModel().getAccountList().size()) { pen.setColor(RingTheme::lightBlack_); painter->setPen(pen); - painter->setFont(font); - QFontMetrics fontMetrics(font); + painter->setFont(fontPrimary); + QFontMetrics fontMetrics(fontPrimary); painter->drawText(rect, Qt::AlignVCenter | Qt::AlignHCenter, tr("Add Account") + "+"); return; } @@ -117,12 +128,12 @@ AccountItemDelegate::paint(QPainter* painter, QVariant name = index.data(static_cast<int>(AccountListModel::Role::Alias)); if (name.isValid()) { - font.setItalic(false); - font.setBold(false); + fontPrimary.setItalic(false); + fontPrimary.setBold(false); pen.setColor(RingTheme::lightBlack_); painter->setPen(pen); - painter->setFont(font); - QFontMetrics fontMetrics(font); + painter->setFont(fontPrimary); + QFontMetrics fontMetrics(fontPrimary); QString nameStr = fontMetrics.elidedText(name.value<QString>(), Qt::ElideRight, rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2); painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr); @@ -132,12 +143,12 @@ AccountItemDelegate::paint(QPainter* painter, QString idStr = index.data(static_cast<int>(AccountListModel::Role::Username)).value<QString>(); if (idStr != name.toString()) { - font.setItalic(false); - font.setBold(false); + fontSecondary.setItalic(false); + fontSecondary.setBold(false); pen.setColor(RingTheme::grey_); painter->setPen(pen); - painter->setFont(font); - QFontMetrics fontMetrics(font); + painter->setFont(fontSecondary); + QFontMetrics fontMetrics(fontSecondary); if (!idStr.isNull()) { idStr = fontMetrics.elidedText(idStr, Qt::ElideRight, rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2); diff --git a/accountitemdelegate.h b/accountitemdelegate.h index f65052fdeeed1e84eab5a1ee52b48b53e25c2198..d30d1986b8f11bc41ea2b75fe2489cd46708c6f4 100644 --- a/accountitemdelegate.h +++ b/accountitemdelegate.h @@ -31,7 +31,7 @@ protected: QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; private: - constexpr static int fontSize_ = 10; + constexpr static int fontSize_ = 11; const QFont font_ = QFont("Arial", fontSize_); constexpr static int topPadding_ = 6; constexpr static int bottomPadding_ = 6; diff --git a/conversationitemdelegate.cpp b/conversationitemdelegate.cpp index 8763d103aa9422dd0bc8ddc6f126f5ec16eaf2e4..30ce4cb40f3c939f9fc8884fa10a40489b693e21 100644 --- a/conversationitemdelegate.cpp +++ b/conversationitemdelegate.cpp @@ -162,15 +162,18 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, { Q_UNUSED(option); QFont font(painter->font()); - font.setPointSize(fontSize_); QPen pen(painter->pen()); painter->setPen(pen); int infoTextWidthModifier = 0; + int infoText2HeightModifier = 0; auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); if (scalingRatio > 1.0) { - font.setPointSize(fontSize_ - 1); + font.setPointSize(fontSize_ - 2); infoTextWidthModifier = 12; + infoText2HeightModifier = 2; + } else { + font.setPointSize(fontSize_); } auto leftMargin = dx_ + sizeImage_ + dx_; @@ -194,9 +197,9 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, rect.height() / 2 - 2); QRect rectInfo2(rectInfo1.left(), - rectInfo1.top() + rectInfo1.height(), + rectInfo1.top() + rectInfo1.height() - infoText2HeightModifier, rectInfo1.width(), - rectInfo1.height() - bottomMargin); + rectInfo1.height() - bottomMargin + infoText2HeightModifier); QFontMetrics fontMetrics(font); @@ -240,6 +243,7 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, QString interactionStr = index.data(static_cast<int>(SmartListModel::Role::LastInteraction)).value<QString>(); if (!interactionStr.isNull()) { painter->save(); + font.setWeight(QFont::ExtraLight); interactionStr = interactionStr.simplified(); auto type = Utils::toEnum<lrc::api::interaction::Type>(index .data(static_cast<int>(SmartListModel::Role::LastInteractionType)) @@ -263,7 +267,7 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, QFont emojiMsgFont(QStringLiteral("Segoe UI Emoji")); emojiMsgFont.setItalic(false); emojiMsgFont.setBold(false); - emojiMsgFont.setPointSize(fontSize_); + emojiMsgFont.setPointSize(scalingRatio > 1.0 ? fontSize_ - 2 : fontSize_); painter->setOpacity(0.7); painter->setFont(emojiMsgFont); } diff --git a/conversationitemdelegate.h b/conversationitemdelegate.h index 249d77bac8351f7c0912e7a72295b58a42565db3..f8778456a9139c6ec3c18093c3efd31573c7c340 100644 --- a/conversationitemdelegate.h +++ b/conversationitemdelegate.h @@ -42,7 +42,7 @@ private: constexpr static int cellHeight_ = 60; constexpr static int dy_ = 6; constexpr static int dx_ = 12; - constexpr static int fontSize_ = 10; + constexpr static int fontSize_ = 11; constexpr static int infoTextWidth_ = 144; mutable std::map<int, bool> highlightMap_; diff --git a/currentaccountcombobox.cpp b/currentaccountcombobox.cpp index 2187aa5f17d28a076e7f273a9b1a7b0f6550e849..feefccd849784bcf5e20bbc7bc3eb3ac2850925c 100644 --- a/currentaccountcombobox.cpp +++ b/currentaccountcombobox.cpp @@ -18,16 +18,16 @@ **************************************************************************/ #include "currentaccountcombobox.h" -#include <accountitemdelegate.h> -#include "pixbufmanipulator.h" +#include <QPixmap> +#include <QMouseEvent> + +#include "accountitemdelegate.h" +#include "pixbufmanipulator.h" #include "utils.h" #include "ringthemeutils.h" #include "lrcinstance.h" -#include <QPixmap> - -#include "callwidget.h" -#include "ui_callwidget.h" +#include "mainwindow.h" #undef REGISTERED @@ -86,10 +86,15 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) // define and set the two fonts QFont fontPrimary = painter.font(); QFont fontSecondary = painter.font(); - - fontPrimary.setPointSize(11); fontPrimary.setWeight(QFont::ExtraLight); - fontSecondary.setPointSize(10); + auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); + if (scalingRatio > 1.0) { + fontPrimary.setPointSize(10); + fontSecondary.setPointSize(9); + } else { + fontPrimary.setPointSize(11); + fontSecondary.setPointSize(10); + } QFontMetrics fontMetricPrimary(fontPrimary); QFontMetrics fontMetricSecondary(fontSecondary); diff --git a/mainwindow.cpp b/mainwindow.cpp index 369be0eeaa912cf5a7877bcf2ca88c3f1f8a9c82..5b3a03f9bf7330aae644a6adb377d3db915f5dfc 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -149,15 +149,6 @@ MainWindow::MainWindow(QWidget* parent) : } lastScr_ = startScreen; - - activeChangedConnection_ = connect(windowHandle(), &QWindow::activeChanged, - [this]() { - auto screenNumber = qApp->desktop()->screenNumber(); - QScreen* screen = qApp->screens().at(screenNumber); - windowHandle()->setScreen(nullptr); - windowHandle()->setScreen(screen); - }); - } MainWindow::~MainWindow() @@ -351,12 +342,23 @@ MainWindow::show() disconnect(screenChangedConnection_); screenChangedConnection_ = connect(windowHandle(), &QWindow::screenChanged, this, &MainWindow::slotScreenChanged); + disconnect(activeChangedConnection_); + activeChangedConnection_ = connect(windowHandle(), &QWindow::activeChanged, + [this]() { + auto screenNumber = qApp->desktop()->screenNumber(); + windowHandle()->setScreen(nullptr); + QScreen* screen = qApp->screens().at(screenNumber); + windowHandle()->setScreen(screen); + }); + auto screenNumber = qApp->desktop()->screenNumber(); + QScreen* screen = qApp->screens().at(screenNumber); + currentScalingRatio_ = screen->logicalDotsPerInchX() / 96; + qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI(); } void MainWindow::slotScreenChanged(QScreen* screen) { - Q_UNUSED(screen); adjustSize(); updateGeometry(); update();