From 2965014a4372eb0d37b05e16a8ac61aa9ac93e96 Mon Sep 17 00:00:00 2001 From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> Date: Thu, 3 Jan 2019 20:33:56 -0500 Subject: [PATCH] ui: cleanup fonts and margins in account selection and smartlist Change-Id: Ie05aff10c54eb60466668d24a8a72300d251febd --- accountitemdelegate.cpp | 22 ++++++++++++++-------- accountitemdelegate.h | 6 ++++-- conversationitemdelegate.cpp | 36 ++++++++++++++++++++++-------------- currentaccountcombobox.cpp | 20 +++++++++++--------- mainwindow.cpp | 31 +++++++++++++++++++++---------- mainwindow.h | 4 +++- 6 files changed, 75 insertions(+), 44 deletions(-) diff --git a/accountitemdelegate.cpp b/accountitemdelegate.cpp index 01fe140..351a230 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 c14502e..f65052f 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 2a31b7d..8763d10 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 a568912..2187aa5 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 82c1b57..369be0e 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 e2bce37..f622347 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(); -- GitLab