From 86888ee71349cb416e79940e3b369e047cf7492a Mon Sep 17 00:00:00 2001 From: Joseph Donofry Date: Fri, 26 Jul 2019 17:44:44 -0400 Subject: [PATCH] Fix bug with emoji font setting and clean linting --- src/ChatPage.cpp | 22 +++++++++++----------- src/ChatPage.h | 3 ++- src/UserSettingsPage.cpp | 2 +- src/UserSettingsPage.h | 2 -- src/Utils.cpp | 23 +++++++++++++++++++++++ src/Utils.h | 3 +++ src/timeline/TimelineItem.cpp | 27 ++------------------------- src/timeline/TimelineItem.h | 1 - 8 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index deefec14..18188429 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -90,13 +90,13 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) connect(sidebarActions_, &SideBarActions::joinRoom, this, &ChatPage::joinRoom); connect(sidebarActions_, &SideBarActions::createRoom, this, &ChatPage::createRoom); - user_info_widget_ = new UserInfoWidget(sideBar_); - //user_mentions_widget_ = new UserMentionsWidget(sideBar_); - room_list_ = new RoomList(sideBar_); + user_info_widget_ = new UserInfoWidget(sideBar_); + // user_mentions_widget_ = new UserMentionsWidget(sideBar_); + room_list_ = new RoomList(sideBar_); connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom); sideBarLayout_->addWidget(user_info_widget_); - //sideBarLayout_->addWidget(user_mentions_widget_); + // sideBarLayout_->addWidget(user_mentions_widget_); sideBarLayout_->addWidget(room_list_); sideBarLayout_->addWidget(sidebarActions_); @@ -159,7 +159,8 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) 1000, "", "highlight", - [this, mentionsPos](const mtx::responses::Notifications &res, mtx::http::RequestErr err) { + [this, mentionsPos](const mtx::responses::Notifications &res, + mtx::http::RequestErr err) { if (err) { nhlog::net()->warn("failed to retrieve notifications: {} ({})", err->matrix_error.error, @@ -218,8 +219,6 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) } }); - - connect(room_list_, &RoomList::roomChanged, this, [this](const QString &roomid) { QStringList users; @@ -1007,10 +1006,11 @@ ChatPage::showNotificationsDialog(const mtx::responses::Notifications &res, cons nhlog::db()->warn("error while sending desktop notification: {}", e.what()); } } - notifDialog->setGeometry(widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2); - //notifDialog->move(widgetPos.x(), widgetPos.y()); - //notifDialog->setFixedWidth(width() / 10); - //notifDialog->setFixedHeight(height() / 2); + notifDialog->setGeometry( + widgetPos.x() - (width() / 10), widgetPos.y() + 25, width() / 5, height() / 2); + // notifDialog->move(widgetPos.x(), widgetPos.y()); + // notifDialog->setFixedWidth(width() / 10); + // notifDialog->setFixedHeight(height() / 2); notifDialog->raise(); notifDialog->show(); } diff --git a/src/ChatPage.h b/src/ChatPage.h index b2f04b02..3c97ba25 100644 --- a/src/ChatPage.h +++ b/src/ChatPage.h @@ -89,7 +89,8 @@ signals: void messageReply(const RelatedInfo &related); void notificationsRetrieved(const mtx::responses::Notifications &); - void highlightedNotifsRetrieved(const mtx::responses::Notifications &, const QPoint widgetPos); + void highlightedNotifsRetrieved(const mtx::responses::Notifications &, + const QPoint widgetPos); void uploadFailed(const QString &msg); void imageUploaded(const QString &roomid, diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 1ac3f738..49cb2c1f 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -239,7 +239,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge fontSizeOptionLayout->addWidget(fontSizeLabel); fontSizeOptionLayout->addWidget(fontSizeCombo_, 0, Qt::AlignRight); - auto fontFamilyOptionLayout = new QHBoxLayout; + auto fontFamilyOptionLayout = new QHBoxLayout; auto emojiFontFamilyOptionLayout = new QHBoxLayout; fontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); emojiFontFamilyOptionLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 8b782213..ffff1e20 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -96,7 +96,6 @@ public: QString font() const { return font_; } QString emojiFont() const { return emojiFont_; } - signals: void groupViewStateChanged(bool state); @@ -111,7 +110,6 @@ private: double baseFontSize_; QString font_; QString emojiFont_; - }; class HorizontalLine : public QFrame diff --git a/src/Utils.cpp b/src/Utils.cpp index 863de79e..d6b092b1 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -26,6 +26,29 @@ utils::localUser() return settings.value("auth/user_id").toString(); } +QString +utils::replaceEmoji(const QString &body) +{ + QString fmtBody = ""; + + QVector utf32_string = body.toUcs4(); + + QSettings settings; + QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); + + for (auto &code : utf32_string) { + // TODO: Be more precise here. + if (code > 9000) + fmtBody += + QString("") + + QString::fromUcs4(&code, 1) + ""; + else + fmtBody += QString::fromUcs4(&code, 1); + } + + return fmtBody; +} + void utils::setScaleFactor(float factor) { diff --git a/src/Utils.h b/src/Utils.h index a840a187..756dc1e3 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -34,6 +34,9 @@ namespace utils { using TimelineEvent = mtx::events::collections::TimelineEvents; +QString +replaceEmoji(const QString &body); + QString localUser(); diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp index cf5d68c6..54011279 100644 --- a/src/timeline/TimelineItem.cpp +++ b/src/timeline/TimelineItem.cpp @@ -650,7 +650,7 @@ TimelineItem::markReceived(bool isEncrypted) void TimelineItem::generateBody(const QString &body) { - body_ = new TextLabel(replaceEmoji(body), this); + body_ = new TextLabel(utils::replaceEmoji(body), this); body_->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction); connect(body_, &TextLabel::userProfileTriggered, this, [](const QString &user_id) { @@ -727,7 +727,7 @@ TimelineItem::generateUserName(const QString &user_id, const QString &displaynam userName_ = new QLabel(this); userName_->setFont(usernameFont); - userName_->setText(replaceEmoji(fm.elidedText(sender, Qt::ElideRight, 500))); + userName_->setText(utils::replaceEmoji(fm.elidedText(sender, Qt::ElideRight, 500))); userName_->setToolTip(user_id); userName_->setToolTipDuration(1500); userName_->setAttribute(Qt::WA_Hover); @@ -773,29 +773,6 @@ TimelineItem::generateTimestamp(const QDateTime &time) QString(" %1 ").arg(time.toString("HH:mm"))); } -QString -TimelineItem::replaceEmoji(const QString &body) -{ - QString fmtBody = ""; - - QVector utf32_string = body.toUcs4(); - - QSettings settings; - QString userFontFamily = settings.value("user/emoji_font_family", "emoji").toString(); - - for (auto &code : utf32_string) { - // TODO: Be more precise here. - if (code > 9000) - fmtBody += - QString("") + - QString::fromUcs4(&code, 1) + ""; - else - fmtBody += QString::fromUcs4(&code, 1); - } - - return fmtBody; -} - void TimelineItem::setupAvatarLayout(const QString &userName) { diff --git a/src/timeline/TimelineItem.h b/src/timeline/TimelineItem.h index e2b1cda4..c0dab6b8 100644 --- a/src/timeline/TimelineItem.h +++ b/src/timeline/TimelineItem.h @@ -276,7 +276,6 @@ private: QFutureWatcher *colorGenerating_; - QString replaceEmoji(const QString &body); QString event_id_; mtx::events::MessageType message_type_; QString room_id_;