diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-09-30 13:24:36 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-09-30 13:24:36 +0300 |
commit | 9038c950aef4a59cc9f928541cb20b010be9a8df (patch) | |
tree | 504b717640347d041253a3067248e5311da96da6 | |
parent | Remove obsolete font/size setting (diff) | |
download | nheko-9038c950aef4a59cc9f928541cb20b010be9a8df.tar.xz |
Remove pixel value from fonts
29 files changed, 77 insertions, 108 deletions
diff --git a/src/CommunitiesListItem.cpp b/src/CommunitiesListItem.cpp index 0fad6624..324482d3 100644 --- a/src/CommunitiesListItem.cpp +++ b/src/CommunitiesListItem.cpp @@ -84,7 +84,7 @@ CommunitiesListItem::paintEvent(QPaintEvent *) if (avatar_.isNull()) { QFont font; - font.setPixelSize(conf::roomlist::fonts::communityBubble); + font.setPointSizeF(font.pointSizeF() * 1.3); p.setFont(font); p.drawLetterAvatar(utils::firstChar(resolveName()), @@ -142,4 +142,4 @@ CommunitiesListItem::updateTooltip() QString name = resolveName(); setToolTip(name + tr(" (community)")); } -} \ No newline at end of file +} diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 4ec9373e..f702832f 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -125,7 +125,6 @@ LoginPage::LoginPage(QWidget *parent) button_layout_->addStretch(1); QFont font; - font.setPixelSize(conf::fontSize); error_label_ = new QLabel(this); error_label_->setFont(font); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 55eb2679..b441978f 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -58,8 +58,7 @@ MainWindow::MainWindow(QWidget *parent) restoreWindowSize(); - QFont font("Open Sans"); - font.setPixelSize(conf::fontSize); + QFont font; font.setStyleStrategy(QFont::PreferAntialias); setFont(font); diff --git a/src/QuickSwitcher.cpp b/src/QuickSwitcher.cpp index 07460efb..eb79a427 100644 --- a/src/QuickSwitcher.cpp +++ b/src/QuickSwitcher.cpp @@ -64,7 +64,7 @@ QuickSwitcher::QuickSwitcher(QWidget *parent) setMaximumWidth(450); QFont font; - font.setPixelSize(20); + font.setPointSizeF(font.pointSizeF() * 1.5); roomSearch_ = new RoomSearchInput(this); roomSearch_->setFont(font); diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index 0bfaa82d..fdb0f43a 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -97,7 +97,6 @@ RegisterPage::RegisterPage(QWidget *parent) button_layout_->setMargin(0); QFont font; - font.setPixelSize(conf::fontSize); error_label_ = new QLabel(this); error_label_->setFont(font); diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index ed3b081c..8b29085a 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -56,23 +56,19 @@ RoomInfoListItem::init(QWidget *parent) ripple_overlay_->setClipPath(path); ripple_overlay_->setClipping(true); - font_.setPixelSize(conf::fontSize - 1); - usernameFont_ = font_; + bubbleFont_ = font_; + bubbleFont_.setPointSizeF(font_.pointSizeF() * 1.3); - bubbleFont_ = font_; - bubbleFont_.setPixelSize(conf::roomlist::fonts::bubble); - - unreadCountFont_.setPixelSize(conf::roomlist::fonts::badge); + unreadCountFont_.setPointSizeF(font_.pointSizeF() * 0.8); unreadCountFont_.setBold(true); + bubbleDiameter_ = QFontMetrics(unreadCountFont_).averageCharWidth() * 3; timestampFont_ = font_; - timestampFont_.setPixelSize(conf::roomlist::fonts::timestamp); timestampFont_.setBold(false); headingFont_ = font_; - headingFont_.setPixelSize(conf::roomlist::fonts::heading); headingFont_.setWeight(60); menu_ = new Menu(this); diff --git a/src/SuggestionsPopup.cpp b/src/SuggestionsPopup.cpp index 5ea78460..952d2ef3 100644 --- a/src/SuggestionsPopup.cpp +++ b/src/SuggestionsPopup.cpp @@ -42,9 +42,6 @@ UserItem::UserItem(QWidget *parent, const QString &user_id) : PopupItem(parent) , userId_{user_id} { - QFont font; - font.setPixelSize(conf::popup::font); - auto displayName = Cache::displayName(ChatPage::instance()->currentRoom(), userId_); avatar_->setSize(conf::popup::avatar); @@ -55,7 +52,6 @@ UserItem::UserItem(QWidget *parent, const QString &user_id) avatar_->setLetter(QChar(displayName.at(1))); userName_ = new QLabel(displayName, this); - userName_->setFont(font); topLayout_->addWidget(avatar_); topLayout_->addWidget(userName_, 1); diff --git a/src/TopRoomBar.cpp b/src/TopRoomBar.cpp index a5d264c7..f2afb9a1 100644 --- a/src/TopRoomBar.cpp +++ b/src/TopRoomBar.cpp @@ -32,7 +32,7 @@ TopRoomBar::TopRoomBar(QWidget *parent) : QWidget(parent) , buttonSize_{32} { - setFixedHeight(60); + setFixedHeight(56); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(8); @@ -46,15 +46,15 @@ TopRoomBar::TopRoomBar(QWidget *parent) textLayout_->setSpacing(0); textLayout_->setContentsMargins(0, 0, 0, 0); - QFont roomFont("Open Sans SemiBold"); - roomFont.setPixelSize(conf::topRoomBar::fonts::roomName); + QFont roomFont; + roomFont.setPointSizeF(roomFont.pointSizeF() * 1.2); + roomFont.setWeight(QFont::Medium); nameLabel_ = new QLabel(this); nameLabel_->setFont(roomFont); nameLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); - QFont descriptionFont("Open Sans"); - descriptionFont.setPixelSize(conf::topRoomBar::fonts::roomDescription); + QFont descriptionFont; topicLabel_ = new TextLabel(this); topicLabel_->setLineWrapMode(QTextEdit::NoWrap); diff --git a/src/TypingDisplay.cpp b/src/TypingDisplay.cpp index 6b731740..3cd7b2a2 100644 --- a/src/TypingDisplay.cpp +++ b/src/TypingDisplay.cpp @@ -15,7 +15,6 @@ TypingDisplay::TypingDisplay(QWidget *parent) , offset_{conf::textInput::height} { QFont f; - f.setPixelSize(conf::typingNotificationFontSize); setFont(f); setFixedHeight(QFontMetrics(font()).height() + RECT_PADDING); diff --git a/src/UserInfoWidget.cpp b/src/UserInfoWidget.cpp index 0677b9cb..d62cea22 100644 --- a/src/UserInfoWidget.cpp +++ b/src/UserInfoWidget.cpp @@ -30,7 +30,7 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) , user_id_("@user:homeserver.org") , logoutButtonSize_{20} { - setFixedHeight(60); + setFixedHeight(56); topLayout_ = new QHBoxLayout(this); topLayout_->setSpacing(0); @@ -38,28 +38,25 @@ UserInfoWidget::UserInfoWidget(QWidget *parent) avatarLayout_ = new QHBoxLayout(); textLayout_ = new QVBoxLayout(); + textLayout_->setSpacing(2); + textLayout_->setContentsMargins(10, 5, 10, 5); userAvatar_ = new Avatar(this); userAvatar_->setObjectName("userAvatar"); userAvatar_->setLetter(QChar('?')); userAvatar_->setSize(45); - QFont nameFont("Open Sans SemiBold"); - nameFont.setPixelSize(conf::userInfoWidget::fonts::displayName); + QFont nameFont; + nameFont.setPointSizeF(nameFont.pointSizeF() * 1.2); + nameFont.setWeight(QFont::Medium); displayNameLabel_ = new QLabel(this); displayNameLabel_->setFont(nameFont); displayNameLabel_->setObjectName("displayNameLabel"); - displayNameLabel_->setStyleSheet("padding: 0 9px; margin-bottom: -10px;"); displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop); - QFont useridFont("Open Sans"); - useridFont.setPixelSize(conf::userInfoWidget::fonts::userid); - userIdLabel_ = new QLabel(this); - userIdLabel_->setFont(useridFont); userIdLabel_->setObjectName("userIdLabel"); - userIdLabel_->setStyleSheet("padding: 0 8px 8px 8px;"); userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); avatarLayout_->addWidget(userAvatar_); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 3f1a33f9..c9b9fb82 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -282,7 +282,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge encryptionLayout_->addWidget(new HorizontalLine{this}); encryptionLayout_->addLayout(sessionKeysLayout); - font.setWeight(65); + font.setWeight(QFont::Medium); auto encryptionLabel_ = new QLabel(tr("ENCRYPTION"), this); encryptionLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); diff --git a/src/dialogs/CreateRoom.cpp b/src/dialogs/CreateRoom.cpp index 46ba5a35..078a3038 100644 --- a/src/dialogs/CreateRoom.cpp +++ b/src/dialogs/CreateRoom.cpp @@ -19,12 +19,12 @@ CreateRoom::CreateRoom(QWidget *parent) setWindowModality(Qt::WindowModal); setAttribute(Qt::WA_DeleteOnClose, true); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); setMinimumHeight(conf::modals::MIN_WIDGET_HEIGHT); - setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - + setMinimumWidth(QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * conf::modals::WIDGET_MARGIN); auto layout = new QVBoxLayout(this); @@ -43,7 +43,7 @@ CreateRoom::CreateRoom(QWidget *parent) buttonLayout->addWidget(confirmBtn_); QFont font; - font.setPixelSize(conf::headerFontSize); + font.setPointSizeF(font.pointSizeF() * 1.3); nameInput_ = new TextField(this); nameInput_->setLabel(tr("Name")); diff --git a/src/dialogs/MemberList.cpp b/src/dialogs/MemberList.cpp index dae4fc86..f4167143 100644 --- a/src/dialogs/MemberList.cpp +++ b/src/dialogs/MemberList.cpp @@ -81,13 +81,13 @@ MemberList::MemberList(const QString &room_id, QWidget *parent) list_->setSelectionMode(QAbstractItemView::NoSelection); list_->setSpacing(5); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); setMinimumHeight(list_->sizeHint().height() * 2); setMinimumWidth(std::max(list_->sizeHint().width() + 4 * conf::modals::WIDGET_MARGIN, - QFontMetrics(doubleFont).averageCharWidth() * 30 - + QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * conf::modals::WIDGET_MARGIN)); QFont font; diff --git a/src/dialogs/ReadReceipts.cpp b/src/dialogs/ReadReceipts.cpp index d0bfd36c..dc4145db 100644 --- a/src/dialogs/ReadReceipts.cpp +++ b/src/dialogs/ReadReceipts.cpp @@ -104,13 +104,13 @@ ReadReceipts::ReadReceipts(QWidget *parent) userList_->setSelectionMode(QAbstractItemView::NoSelection); userList_->setSpacing(conf::modals::TEXT_SPACING); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); setMinimumHeight(userList_->sizeHint().height() * 2); setMinimumWidth(std::max(userList_->sizeHint().width() + 4 * conf::modals::WIDGET_MARGIN, - QFontMetrics(doubleFont).averageCharWidth() * 30 - + QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * conf::modals::WIDGET_MARGIN)); QFont font; diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index c4bb7af5..c192bd3d 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -48,9 +48,9 @@ EditModal::EditModal(const QString &roomId, QWidget *parent) setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setWindowModality(Qt::WindowModal); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); - setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.4); + setMinimumWidth(QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); auto layout = new QVBoxLayout(this); @@ -169,10 +169,10 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) setWindowModality(Qt::WindowModal); setAttribute(Qt::WA_DeleteOnClose, true); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5); - setMinimumWidth(QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); + setMinimumWidth(QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); auto layout = new QVBoxLayout(this); @@ -180,7 +180,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) layout->setContentsMargins(WIDGET_MARGIN, TOP_WIDGET_MARGIN, WIDGET_MARGIN, WIDGET_MARGIN); QFont font; - font.setWeight(65); + font.setWeight(QFont::Medium); font.setPointSizeF(font.pointSizeF() * 1.2); auto settingsLabel = new QLabel(tr("Settings").toUpper(), this); settingsLabel->setFont(font); @@ -356,7 +356,7 @@ RoomSettings::RoomSettings(const QString &room_id, QWidget *parent) } roomNameLabel_ = new QLabel(QString::fromStdString(info_.name), this); - roomNameLabel_->setFont(doubleFont); + roomNameLabel_->setFont(largeFont); auto membersLabel = new QLabel(tr("%n member(s)", "", info_.member_count), this); diff --git a/src/dialogs/UserProfile.cpp b/src/dialogs/UserProfile.cpp index 14aa6819..27182711 100644 --- a/src/dialogs/UserProfile.cpp +++ b/src/dialogs/UserProfile.cpp @@ -171,12 +171,12 @@ UserProfile::UserProfile(QWidget *parent) setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setWindowModality(Qt::WindowModal); - QFont doubleFont; - doubleFont.setPointSizeF(doubleFont.pointSizeF() * 2); + QFont largeFont; + largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5); setMinimumWidth( std::max(devices_->sizeHint().width() + 4 * WIDGET_MARGIN, - QFontMetrics(doubleFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN)); + QFontMetrics(largeFont).averageCharWidth() * 30 - 2 * WIDGET_MARGIN)); setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); vlayout->setSpacing(WIDGET_SPACING); diff --git a/src/emoji/Category.cpp b/src/emoji/Category.cpp index c1b526f2..fbfbf4fc 100644 --- a/src/emoji/Category.cpp +++ b/src/emoji/Category.cpp @@ -67,8 +67,8 @@ Category::Category(QString category, std::vector<Emoji> emoji, QWidget *parent) itemModel_->appendRow(item); } - QFont font("Open Sans SemiBold"); - font.setPixelSize(conf::fontSize); + QFont font; + font.setWeight(QFont::Medium); category_ = new QLabel(category, this); category_->setFont(font); diff --git a/src/emoji/ItemDelegate.cpp b/src/emoji/ItemDelegate.cpp index 2cc838e3..50a1b7ed 100644 --- a/src/emoji/ItemDelegate.cpp +++ b/src/emoji/ItemDelegate.cpp @@ -42,7 +42,6 @@ ItemDelegate::paint(QPainter *painter, auto emoji = index.data(Qt::UserRole).toString(); QFont font("Emoji One"); - font.setPixelSize(19); painter->setFont(font); painter->drawText(viewOption.rect, Qt::AlignCenter, emoji); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index 9558c397..ec07d437 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -155,9 +155,8 @@ TimelineItem::init() userName_ = nullptr; body_ = nullptr; - font_.setPixelSize(conf::fontSize); usernameFont_ = font_; - usernameFont_.setWeight(60); + usernameFont_.setWeight(QFont::Medium); QFontMetrics fm(font_); @@ -216,9 +215,11 @@ TimelineItem::init() mainLayout_->setContentsMargins(conf::timeline::headerLeftMargin, 0, 0, 0); mainLayout_->setSpacing(0); - QFont timestampFont; - timestampFont.setPixelSize(conf::timeline::fonts::indicator); - QFontMetrics tsFm(timestampFont); + timestampFont_.setPointSizeF(timestampFont_.pointSizeF() * 0.9); + timestampFont_.setFamily("Monospace"); + timestampFont_.setStyleHint(QFont::Monospace); + + QFontMetrics tsFm(timestampFont_); statusIndicator_ = new StatusIndicator(this); statusIndicator_->setFixedWidth(tsFm.height() - tsFm.leading()); @@ -662,13 +663,8 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam void TimelineItem::generateTimestamp(const QDateTime &time) { - QFont timestampFont; - timestampFont.setFamily("Monospace"); - timestampFont.setStyleHint(QFont::Monospace); - timestampFont.setPixelSize(conf::timeline::fonts::timestamp); - timestamp_ = new QLabel(this); - timestamp_->setFont(timestampFont); + timestamp_->setFont(timestampFont_); timestamp_->setText( QString("<span style=\"color: #999\"> %1 </span>").arg(time.toString("HH:mm"))); } @@ -683,9 +679,7 @@ TimelineItem::replaceEmoji(const QString &body) for (auto &code : utf32_string) { // TODO: Be more precise here. if (code > 9000) - fmtBody += QString("<span style=\"font-family: Emoji " - "One; font-size: %1px\">") - .arg(conf::emojiSize) + + fmtBody += QString("<span style=\"font-family: Emoji One;\">") + QString::fromUcs4(&code, 1) + "</span>"; else fmtBody += QString::fromUcs4(&code, 1); diff --git a/src/timeline/TimelineItem.h b/src/timeline/TimelineItem.h index ae486257..d24909d6 100644 --- a/src/timeline/TimelineItem.h +++ b/src/timeline/TimelineItem.h @@ -278,6 +278,7 @@ private: QFont font_; QFont usernameFont_; + QFont timestampFont_; StatusIndicator *statusIndicator_; diff --git a/src/timeline/TimelineView.cpp b/src/timeline/TimelineView.cpp index 90e116c1..07de25b6 100644 --- a/src/timeline/TimelineView.cpp +++ b/src/timeline/TimelineView.cpp @@ -519,7 +519,6 @@ TimelineView::init() // Height of the typing display. QFont f; - f.setPixelSize(conf::typingNotificationFontSize); const int bottomMargin = QFontMetrics(f).height() + 6; scroll_layout_ = new QVBoxLayout(scroll_widget_); diff --git a/src/timeline/widgets/AudioItem.cpp b/src/timeline/widgets/AudioItem.cpp index 0c4bf9e4..72332174 100644 --- a/src/timeline/widgets/AudioItem.cpp +++ b/src/timeline/widgets/AudioItem.cpp @@ -159,8 +159,7 @@ void AudioItem::resizeEvent(QResizeEvent *event) { QFont font; - font.setPixelSize(12); - font.setWeight(80); + font.setWeight(QFont::Medium); QFontMetrics fm(font); const int computedWidth = std::min( @@ -180,8 +179,7 @@ AudioItem::paintEvent(QPaintEvent *event) painter.setRenderHint(QPainter::Antialiasing); QFont font; - font.setPixelSize(12); - font.setWeight(80); + font.setWeight(QFont::Medium); QFontMetrics fm(font); @@ -225,7 +223,7 @@ AudioItem::paintEvent(QPaintEvent *event) painter.drawText(QPoint(textStartX, textStartY), elidedText); // Draw the filesize. - font.setWeight(50); + font.setWeight(QFont::Normal); painter.setFont(font); painter.setPen(QPen(textColor_)); painter.drawText(QPoint(textStartX, textStartY + 1.5 * fm.ascent()), readableFileSize_); diff --git a/src/timeline/widgets/FileItem.cpp b/src/timeline/widgets/FileItem.cpp index 850941ae..e97554e2 100644 --- a/src/timeline/widgets/FileItem.cpp +++ b/src/timeline/widgets/FileItem.cpp @@ -150,8 +150,7 @@ void FileItem::resizeEvent(QResizeEvent *event) { QFont font; - font.setPixelSize(12); - font.setWeight(80); + font.setWeight(QFont::Medium); QFontMetrics fm(font); const int computedWidth = std::min( @@ -171,8 +170,7 @@ FileItem::paintEvent(QPaintEvent *event) painter.setRenderHint(QPainter::Antialiasing); QFont font; - font.setPixelSize(12); - font.setWeight(80); + font.setWeight(QFont::Medium); QFontMetrics fm(font); @@ -210,7 +208,7 @@ FileItem::paintEvent(QPaintEvent *event) painter.drawText(QPoint(textStartX, textStartY), elidedText); // Draw the filesize. - font.setWeight(50); + font.setWeight(QFont::Normal); painter.setFont(font); painter.setPen(QPen(textColor_)); painter.drawText(QPoint(textStartX, textStartY + 1.5 * fm.ascent()), readableFileSize_); diff --git a/src/timeline/widgets/ImageItem.cpp b/src/timeline/widgets/ImageItem.cpp index 4c68d683..f06b9a5b 100644 --- a/src/timeline/widgets/ImageItem.cpp +++ b/src/timeline/widgets/ImageItem.cpp @@ -183,8 +183,7 @@ ImageItem::paintEvent(QPaintEvent *event) QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); - QFont font("Open Sans"); - font.setPixelSize(conf::fontSize); + QFont font; QFontMetrics metrics(font); const int fontHeight = metrics.height() + metrics.ascent(); @@ -223,9 +222,9 @@ ImageItem::paintEvent(QPaintEvent *event) QString elidedText = metrics.elidedText(text_, Qt::ElideRight, width_ - 10); - font.setWeight(80); + font.setWeight(QFont::Medium); painter.setFont(font); - painter.setPen(QPen(QColor("white"))); + painter.setPen(QPen(QColor(Qt::white))); textRegion_.adjust(5, 0, 5, 0); painter.drawText(textRegion_, Qt::AlignVCenter, elidedText); diff --git a/src/timeline/widgets/VideoItem.cpp b/src/timeline/widgets/VideoItem.cpp index daf181b2..4b5dc022 100644 --- a/src/timeline/widgets/VideoItem.cpp +++ b/src/timeline/widgets/VideoItem.cpp @@ -50,7 +50,6 @@ VideoItem::VideoItem(const mtx::events::RoomEvent<mtx::events::msg::Video> &even label_->setMargin(0); label_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction); label_->setOpenExternalLinks(true); - label_->setStyleSheet(QString("font-size: %1px;").arg(conf::fontSize)); layout->addWidget(label_); } diff --git a/src/ui/FlatButton.cpp b/src/ui/FlatButton.cpp index 45a7683e..a828f582 100644 --- a/src/ui/FlatButton.cpp +++ b/src/ui/FlatButton.cpp @@ -218,7 +218,7 @@ FlatButton::setFontSize(qreal size) font_size_ = size; QFont f(font()); - f.setPixelSize(size); + f.setPointSizeF(size); setFont(f); update(); diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp index 3151bedf..e107b18f 100644 --- a/src/ui/InfoMessage.cpp +++ b/src/ui/InfoMessage.cpp @@ -1,5 +1,5 @@ -#include "InfoMessage.h" #include "Config.h" +#include "InfoMessage.h" #include <QDateTime> #include <QPainter> @@ -12,18 +12,16 @@ constexpr int HMargin = 20; InfoMessage::InfoMessage(QWidget *parent) : QWidget{parent} { - font_.setWeight(60); - font_.setPixelSize(conf::timeline::fonts::dateSeparator); + initFont(); } InfoMessage::InfoMessage(QString msg, QWidget *parent) : QWidget{parent} , msg_{msg} { - font_.setWeight(60); - font_.setPixelSize(conf::timeline::fonts::dateSeparator); + initFont(); - QFontMetrics fm{font_}; + QFontMetrics fm{font()}; width_ = fm.width(msg_) + HPadding * 2; height_ = fm.ascent() + 2 * VPadding; @@ -35,7 +33,7 @@ InfoMessage::paintEvent(QPaintEvent *) { QPainter p(this); p.setRenderHint(QPainter::Antialiasing); - p.setFont(font_); + p.setFont(font()); // Center the box horizontally & vertically. auto textRegion = QRectF(width() / 2 - width_ / 2, HMargin, width_, height_); @@ -54,8 +52,7 @@ InfoMessage::paintEvent(QPaintEvent *) DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent) : InfoMessage{parent} { - auto now = QDateTime::currentDateTime(); - auto days = now.daysTo(datetime); + auto now = QDateTime::currentDateTime(); QString fmt; @@ -64,14 +61,9 @@ DateSeparator::DateSeparator(QDateTime datetime, QWidget *parent) else fmt = QString("ddd d MMMM"); - if (days == 0) - msg_ = tr("Today"); - else if (std::abs(days) == 1) - msg_ = tr("Yesterday"); - else - msg_ = datetime.toString(fmt); + msg_ = datetime.toString(fmt); - QFontMetrics fm{font_}; + QFontMetrics fm{font()}; width_ = fm.width(msg_) + HPadding * 2; height_ = fm.ascent() + 2 * VPadding; diff --git a/src/ui/InfoMessage.h b/src/ui/InfoMessage.h index 58f98b0c..f8f457e3 100644 --- a/src/ui/InfoMessage.h +++ b/src/ui/InfoMessage.h @@ -25,12 +25,17 @@ public: protected: void paintEvent(QPaintEvent *event) override; + void initFont() + { + QFont f; + f.setWeight(QFont::Medium); + setFont(f); + } int width_; int height_; QString msg_; - QFont font_; QDateTime datetime_; diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 7e2f359a..c4582085 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -76,7 +76,7 @@ TextField::setLabelFontSize(qreal size) if (label_) { QFont font(label_->font()); - font.setPixelSize(size); + font.setPointSizeF(size); label_->setFont(font); label_->update(); } |