diff --git a/accountitemdelegate.cpp b/accountitemdelegate.cpp index 01fe1403fd0d5b6a6b2495faac0c02c8736bb767..351a2308fcaa992f8662234e72fc1a25af3b548f 100644 --- a/accountitemdelegate.cpp +++ b/accountitemdelegate.cpp @@ -65,6 +65,7 @@ AccountItemDelegate::paint(QPainter* painter, QFont font(painter->font()); font.setPointSize(fontSize_); + QPen pen(painter->pen()); // is it the add account row? @@ -82,7 +83,12 @@ AccountItemDelegate::paint(QPainter* painter, opt.decorationPosition = QStyleOptionViewItem::Left; opt.decorationAlignment = Qt::AlignCenter; - QRect rectAvatar(dy_ + rect.left(), rect.top() + dy_, avatarSize_, avatarSize_); + QRect rectAvatar( + leftPadding_ + rect.left(), + rect.top() + topPadding_, + avatarSize_, + avatarSize_ + ); drawDecoration(painter, opt, rectAvatar, QPixmap::fromImage(index.data(AccountListModel::Role::Picture).value<QImage>()) .scaled(avatarSize_, avatarSize_, Qt::KeepAspectRatio, Qt::SmoothTransformation)); @@ -102,8 +108,8 @@ AccountItemDelegate::paint(QPainter* painter, painter->setPen(pen); - QRect rectTexts(dx_ + rect.left() + dx_ + avatarSize_, - rect.top(), + QRect rectTexts(leftPadding_ + rect.left() + leftPadding_ + avatarSize_, + rect.top() + topPadding_ / 2, rect.width(), rect.height() / 2); @@ -112,13 +118,13 @@ AccountItemDelegate::paint(QPainter* painter, if (name.isValid()) { font.setItalic(false); - font.setBold(true); + font.setBold(false); pen.setColor(RingTheme::lightBlack_); painter->setPen(pen); painter->setFont(font); QFontMetrics fontMetrics(font); QString nameStr = fontMetrics.elidedText(name.value<QString>(), Qt::ElideRight, - rectTexts.width() - avatarSize_ - dx_); + rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2); painter->drawText(rectTexts, Qt::AlignVCenter | Qt::AlignLeft, nameStr); } @@ -134,9 +140,9 @@ AccountItemDelegate::paint(QPainter* painter, QFontMetrics fontMetrics(font); if (!idStr.isNull()) { idStr = fontMetrics.elidedText(idStr, Qt::ElideRight, - rectTexts.width() - avatarSize_ - dx_ * 2); - painter->drawText(QRect(dx_ + rect.left() + dx_ + avatarSize_, - rect.top() + dy_ * 3, + rectTexts.width() - avatarSize_ - leftPadding_ - rightPadding_ * 2); + painter->drawText(QRect(leftPadding_ + rect.left() + leftPadding_ + avatarSize_, + rect.top() + topPadding_ * 3, rect.width(), rect.height() / 2), Qt::AlignBottom | Qt::AlignLeft, idStr); diff --git a/accountitemdelegate.h b/accountitemdelegate.h index c14502e8c776ff0bbb9ff789b268c39a9d4c8a1f..f65052fdeeed1e84eab5a1ee52b48b53e25c2198 100644 --- a/accountitemdelegate.h +++ b/accountitemdelegate.h @@ -33,8 +33,10 @@ protected: private: constexpr static int fontSize_ = 10; const QFont font_ = QFont("Arial", fontSize_); - constexpr static int dy_ = 6; - constexpr static int dx_ = 12; + constexpr static int topPadding_ = 6; + constexpr static int bottomPadding_ = 6; + constexpr static int leftPadding_ = 12; + constexpr static int rightPadding_ = 12; constexpr static int avatarSize_ = 36; constexpr static int cellHeight_ = 48; }; diff --git a/conversationitemdelegate.cpp b/conversationitemdelegate.cpp index 2a31b7da724315c90cc843bd45b859f880433fd5..8763d103aa9422dd0bc8ddc6f126f5ec16eaf2e4 100644 --- a/conversationitemdelegate.cpp +++ b/conversationitemdelegate.cpp @@ -28,6 +28,7 @@ #include "ringthemeutils.h" #include "utils.h" #include "lrcinstance.h" +#include "mainwindow.h" #include <ciso646> @@ -126,7 +127,7 @@ ConversationItemDelegate::paint(QPainter* painter using namespace lrc::api; auto type = Utils::toEnum<profile::Type>( - index.data(static_cast<int>(SmartListModel::Role::ContactType)).value<int>() + index.data(static_cast<int>(SmartListModel::Role::ContactType)).value<int>() ); switch (type) { case profile::Type::RING: @@ -165,15 +166,22 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, QPen pen(painter->pen()); painter->setPen(pen); - auto leftMargin = dx_ + sizeImage_ + dx_ / 2; + int infoTextWidthModifier = 0; + auto scalingRatio = MainWindow::instance().getCurrentScalingRatio(); + if (scalingRatio > 1.0) { + font.setPointSize(fontSize_ - 1); + infoTextWidthModifier = 12; + } + + auto leftMargin = dx_ + sizeImage_ + dx_; auto rightMargin = dx_; - auto topMargin = 0; - auto bottomMargin = 12; + auto topMargin = 4; + auto bottomMargin = 8; QRect rectName1(rect.left() + leftMargin, rect.top() + topMargin, - rect.width() - leftMargin - infoTextWidth_, - rect.height() / 2); + rect.width() - leftMargin - infoTextWidth_ - infoTextWidthModifier, + rect.height() / 2 - 2); QRect rectName2(rectName1.left(), rectName1.top() + rectName1.height(), @@ -182,8 +190,8 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, QRect rectInfo1(rectName1.left() + rectName1.width(), rect.top() + topMargin, - infoTextWidth_ - rightMargin, - rect.height() / 2); + infoTextWidth_ - rightMargin + infoTextWidthModifier, + rect.height() / 2 - 2); QRect rectInfo2(rectInfo1.left(), rectInfo1.top() + rectInfo1.height(), @@ -196,7 +204,7 @@ ConversationItemDelegate::paintRingConversationItem(QPainter* painter, QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>(); if (!nameStr.isNull()) { font.setItalic(false); - font.setBold(true); + font.setBold(false); pen.setColor(RingTheme::lightBlack_); painter->setPen(pen); painter->setFont(font); @@ -276,18 +284,18 @@ ConversationItemDelegate::paintRingInviteConversationItem(QPainter* painter, QPen pen(painter->pen()); painter->setPen(pen); - auto leftMargin = dx_ + sizeImage_ + dx_ / 2; + auto leftMargin = dx_ + sizeImage_ + dx_; auto rightMargin = dx_; if (option.state & QStyle::State_MouseOver) { rightMargin = infoTextWidth_ - dx_ * 2; } - auto topMargin = 0; - auto bottomMargin = 12; + auto topMargin = 4; + auto bottomMargin = 8; QRect rectName1(rect.left() + leftMargin, rect.top() + topMargin, rect.width() - leftMargin - rightMargin, - rect.height() / 2); + rect.height() / 2 - 2); QRect rectName2(rectName1.left(), rectName1.top() + rectName1.height(), @@ -300,7 +308,7 @@ ConversationItemDelegate::paintRingInviteConversationItem(QPainter* painter, QString nameStr = index.data(static_cast<int>(SmartListModel::Role::DisplayName)).value<QString>(); if (!nameStr.isNull()) { font.setItalic(false); - font.setBold(true); + font.setBold(false); pen.setColor(RingTheme::lightBlack_); painter->setPen(pen); painter->setFont(font); diff --git a/currentaccountcombobox.cpp b/currentaccountcombobox.cpp index a5689121640fcda98677f322b564bf404ea81eb4..2187aa5f17d28a076e7f273a9b1a7b0f6550e849 100644 --- a/currentaccountcombobox.cpp +++ b/currentaccountcombobox.cpp @@ -75,7 +75,7 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) { Q_UNUSED(e); - QPoint p(12, 2); + QPoint avatarTopLeft(16, 2); QPainter painter(this); painter.setRenderHints((QPainter::Antialiasing | QPainter::TextAntialiasing), true); @@ -83,10 +83,6 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) opt.init(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter); - // create box in which to draw avatar and presence indicator - QRect avatarRect(2, 2, cellHeight_, cellHeight_); // [screen awareness] - QRect comboBoxRect(cellHeight_ + p.x() + 2, 4, this->width() - cellHeight_ + p.x(), cellHeight_- 10); // [screen awareness] - // define and set the two fonts QFont fontPrimary = painter.font(); QFont fontSecondary = painter.font(); @@ -94,19 +90,18 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) fontPrimary.setPointSize(11); fontPrimary.setWeight(QFont::ExtraLight); fontSecondary.setPointSize(10); - painter.setFont(fontPrimary); QFontMetrics fontMetricPrimary(fontPrimary); QFontMetrics fontMetricSecondary(fontSecondary); - painter.drawPixmap(p, currentAccountAvatarImage_); + painter.drawPixmap(avatarTopLeft, currentAccountAvatarImage_); // fill in presence indicator if account is registered auto accountStatus = LRCInstance::getCurrentAccountInfo().status; if (accountStatus == lrc::api::account::Status::REGISTERED) { // paint the presence indicator circle QPainterPath outerCircle, innerCircle; - QPointF presenceCenter(40.0 + p.x(), 40.0); + QPointF presenceCenter(40.0 + avatarTopLeft.x(), 40.0); qreal outerCircleRadius = cellHeight_/6.5; qreal innerCircleRadius = outerCircleRadius * 0.75; outerCircle.addEllipse(presenceCenter, outerCircleRadius, outerCircleRadius); @@ -115,9 +110,16 @@ CurrentAccountComboBox::paintEvent(QPaintEvent* e) painter.fillPath(innerCircle, RingTheme::presenceGreen_); } + QRect comboBoxRect( + cellHeight_ + avatarTopLeft.x() + 10 + 2, + 6, + this->width() - cellHeight_, + cellHeight_ - 10); // [screen awareness] + // write primary and secondary account identifiers to combobox label QString primaryAccountID = QString::fromStdString(Utils::bestNameForAccount(LRCInstance::getCurrentAccountInfo())); - painter.setPen(Qt::black); + painter.setFont(fontPrimary); + painter.setPen(RingTheme::lightBlack_); primaryAccountID = fontMetricPrimary.elidedText(primaryAccountID, Qt::ElideRight, comboBoxRect.width() - elidConst - (popupPresent ? 0 : 2 * gearSize_)); painter.drawText(comboBoxRect, Qt::AlignLeft, primaryAccountID); diff --git a/mainwindow.cpp b/mainwindow.cpp index 82c1b57a287b7282679bddd05980bcea2eca0034..369be0eeaa912cf5a7877bcf2ca88c3f1f8a9c82 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -350,16 +350,21 @@ MainWindow::show() QMainWindow::show(); disconnect(screenChangedConnection_); screenChangedConnection_ = connect(windowHandle(), &QWindow::screenChanged, - [this](QScreen* screen) { - Q_UNUSED(screen); - adjustSize(); - updateGeometry(); - update(); - // a little delay won't hurt ;) - QTimer::singleShot(100, this, - [this] { - qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI(); - }); + this, &MainWindow::slotScreenChanged); +} + +void +MainWindow::slotScreenChanged(QScreen* screen) +{ + Q_UNUSED(screen); + adjustSize(); + updateGeometry(); + update(); + currentScalingRatio_ = screen->logicalDotsPerInchX() / 96; + // a little delay won't hurt ;) + QTimer::singleShot(100, this, + [this] { + qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI(); }); } @@ -369,3 +374,9 @@ MainWindow::resizeEvent(QResizeEvent* event) Q_UNUSED(event); qobject_cast<NavWidget*>(ui->navStack->currentWidget())->updateCustomUI(); } + +float +MainWindow::getCurrentScalingRatio() +{ + return currentScalingRatio_; +} \ No newline at end of file diff --git a/mainwindow.h b/mainwindow.h index e2bce37a6844daaed26bea0d597453dfaddff591..f622347bfe4c16c5e6a05f1237a42bf0abb34f77 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -53,8 +53,8 @@ public: } void createThumbBar(); bool init(); - void show(); + float getCurrentScalingRatio(); protected: bool nativeEvent(const QByteArray& eventType, void* message, long* result); @@ -70,6 +70,7 @@ private slots: void onIncomingCall(Call* call); void switchNormalMaximize(); void notificationClicked(); + void slotScreenChanged(QScreen* screen); private: explicit MainWindow(QWidget* parent = 0); @@ -79,6 +80,7 @@ private: ScreenEnum lastScr_; int lastAccountCount_; Qt::WindowFlags flags_; + float currentScalingRatio_; void readSettingsFromRegistry();