From d8b89e2ef0a1a650a4bc249025ad6987cbf2176d Mon Sep 17 00:00:00 2001 From: lkito Date: Tue, 19 May 2020 23:04:38 +0400 Subject: Added an optional feature to show bigger emoji-only messages with 3 or less emoji --- src/UserSettingsPage.cpp | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'src/UserSettingsPage.cpp') diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 6af08e12..36fd768c 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -58,6 +58,8 @@ UserSettings::load() isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool(); isMessageHoverHighlightEnabled_ = settings.value("user/timeline/message_hover_highlight", false).toBool(); + isEnlargeEmojiOnlyMessagesEnabled_ = + settings.value("user/timeline/enlarge_emoji_only_msg", false).toBool(); isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); sortByImportance_ = settings.value("user/sort_by_unread", true).toBool(); @@ -168,6 +170,7 @@ UserSettings::save() settings.beginGroup("timeline"); settings.setValue("buttons", isButtonsInTimelineEnabled_); settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_); + settings.setValue("enlarge_emoji_only_msg", isEnlargeEmojiOnlyMessagesEnabled_); settings.endGroup(); settings.setValue("avatar_circles", avatarCircles_); @@ -231,22 +234,23 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge general_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); general_->setFont(font); - trayToggle_ = new Toggle{this}; - startInTrayToggle_ = new Toggle{this}; - avatarCircles_ = new Toggle{this}; - decryptSidebar_ = new Toggle(this); - groupViewToggle_ = new Toggle{this}; - timelineButtonsToggle_ = new Toggle{this}; - typingNotifications_ = new Toggle{this}; - messageHoverHighlight_ = new Toggle{this}; - sortByImportance_ = new Toggle{this}; - readReceipts_ = new Toggle{this}; - markdownEnabled_ = new Toggle{this}; - desktopNotifications_ = new Toggle{this}; - scaleFactorCombo_ = new QComboBox{this}; - fontSizeCombo_ = new QComboBox{this}; - fontSelectionCombo_ = new QComboBox{this}; - emojiFontSelectionCombo_ = new QComboBox{this}; + trayToggle_ = new Toggle{this}; + startInTrayToggle_ = new Toggle{this}; + avatarCircles_ = new Toggle{this}; + decryptSidebar_ = new Toggle(this); + groupViewToggle_ = new Toggle{this}; + timelineButtonsToggle_ = new Toggle{this}; + typingNotifications_ = new Toggle{this}; + messageHoverHighlight_ = new Toggle{this}; + enlargeEmojiOnlyMessages_ = new Toggle{this}; + sortByImportance_ = new Toggle{this}; + readReceipts_ = new Toggle{this}; + markdownEnabled_ = new Toggle{this}; + desktopNotifications_ = new Toggle{this}; + scaleFactorCombo_ = new QComboBox{this}; + fontSizeCombo_ = new QComboBox{this}; + fontSelectionCombo_ = new QComboBox{this}; + emojiFontSelectionCombo_ = new QComboBox{this}; if (!settings_->isTrayEnabled()) startInTrayToggle_->setDisabled(true); @@ -350,6 +354,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge boxWrap(tr("Send messages as Markdown"), markdownEnabled_); boxWrap(tr("Desktop notifications"), desktopNotifications_); boxWrap(tr("Highlight message on hover"), messageHoverHighlight_); + boxWrap(tr("Large Emoji in timeline"), enlargeEmojiOnlyMessages_); formLayout_->addRow(uiLabel_); formLayout_->addRow(new HorizontalLine{this}); @@ -472,6 +477,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setMessageHoverHighlight(!isDisabled); }); + connect(enlargeEmojiOnlyMessages_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setEnlargeEmojiOnlyMessages(!isDisabled); + }); + connect( sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys); @@ -505,6 +514,7 @@ UserSettingsPage::showEvent(QShowEvent *) markdownEnabled_->setState(!settings_->isMarkdownEnabled()); desktopNotifications_->setState(!settings_->hasDesktopNotifications()); messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled()); + enlargeEmojiOnlyMessages_->setState(!settings_->isEnlargeEmojiOnlyMessagesEnabled()); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); deviceFingerprintValue_->setText( -- cgit 1.5.1 From 60ad6ce2772b1ce3b7d012e5b8767248d150f646 Mon Sep 17 00:00:00 2001 From: lkito Date: Sat, 23 May 2020 17:15:46 +0400 Subject: Added an option to have descriptions for user settings. --- src/UserSettingsPage.cpp | 74 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 15 deletions(-) (limited to 'src/UserSettingsPage.cpp') diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 36fd768c..c151cad2 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -327,11 +327,15 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge sessionKeysLayout->addWidget(sessionKeysExportBtn, 0, Qt::AlignRight); sessionKeysLayout->addWidget(sessionKeysImportBtn, 0, Qt::AlignRight); - auto boxWrap = [this, &font](QString labelText, QWidget *field) { + auto boxWrap = [this, &font](QString labelText, QWidget *field, QString tooltipText = "") { auto label = new QLabel{labelText, this}; label->setFont(font); label->setMargin(OptionMargin); + if (!tooltipText.isEmpty()) { + label->setToolTip(tooltipText); + } + auto layout = new QHBoxLayout; layout->addWidget(field, 0, Qt::AlignRight); @@ -340,26 +344,66 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge formLayout_->addRow(general_); formLayout_->addRow(new HorizontalLine{this}); - boxWrap(tr("Minimize to tray"), trayToggle_); - boxWrap(tr("Start in tray"), startInTrayToggle_); + boxWrap( + tr("Minimize to tray"), + trayToggle_, + tr("Keep the application running in the background after closing the client window.")); + boxWrap(tr("Start in tray"), + startInTrayToggle_, + tr("Start the application in the background without showing the client window.")); formLayout_->addRow(new HorizontalLine{this}); - boxWrap(tr("Circular Avatars"), avatarCircles_); - boxWrap(tr("Group's sidebar"), groupViewToggle_); - boxWrap(tr("Decrypt messages in sidebar"), decryptSidebar_); - boxWrap(tr("Show buttons in timeline"), timelineButtonsToggle_); - boxWrap(tr("Typing notifications"), typingNotifications_); - boxWrap(tr("Sort rooms by unreads"), sortByImportance_); + boxWrap(tr("Circular Avatars"), + avatarCircles_, + tr("Change the appearance of user avatars in chats.\nOFF - square, ON - Circle.")); + boxWrap(tr("Group's sidebar"), + groupViewToggle_, + tr("Show a column containing groups and tags next to the room list.")); + boxWrap(tr("Decrypt messages in sidebar"), + decryptSidebar_, + tr("Decrypt the messages shown in the sidebar.\nOnly affects messages in " + "encrypted chats.")); + boxWrap(tr("Show buttons in timeline"), + timelineButtonsToggle_, + tr("Show buttons to quickly reply, react or access additional options next to each " + "message.")); + boxWrap(tr("Typing notifications"), + typingNotifications_, + tr("Show who is typing in a room.\nThis will also enable or disable sending typing " + "notifications to others.")); + boxWrap( + tr("Sort rooms by unreads"), + sortByImportance_, + tr( + "Display rooms with new messages first.\nIf this is off, the list of rooms will only " + "be sorted by the timestamp of the last message in a room.\nIf this is on, rooms which " + "have active notifications (the small circle with a number in it) will be sorted on " + "top. Rooms, that you have muted, will still be sorted by timestamp, since you don't " + "seem to consider them as important as the other rooms.")); formLayout_->addRow(new HorizontalLine{this}); - boxWrap(tr("Read receipts"), readReceipts_); - boxWrap(tr("Send messages as Markdown"), markdownEnabled_); - boxWrap(tr("Desktop notifications"), desktopNotifications_); - boxWrap(tr("Highlight message on hover"), messageHoverHighlight_); - boxWrap(tr("Large Emoji in timeline"), enlargeEmojiOnlyMessages_); + boxWrap(tr("Read receipts"), + readReceipts_, + tr("Show if your message was read.\nStatus is displayed next to timestamps.")); + boxWrap( + tr("Send messages as Markdown"), + markdownEnabled_, + tr("Allow using markdown in messages.\nWhen disabled, all messages are sent as a plain " + "text.")); + boxWrap(tr("Desktop notifications"), + desktopNotifications_, + tr("Notify about received message when the client is not currently focused.")); + boxWrap(tr("Highlight message on hover"), + messageHoverHighlight_, + tr("Change the background color of messages when you hover over them.")); + boxWrap(tr("Large Emoji in timeline"), + enlargeEmojiOnlyMessages_, + tr("Make font size larger if messages with only a few emojis are displayed.")); formLayout_->addRow(uiLabel_); formLayout_->addRow(new HorizontalLine{this}); #if !defined(Q_OS_MAC) - boxWrap(tr("Scale factor"), scaleFactorCombo_); + boxWrap(tr("Scale factor"), + scaleFactorCombo_, + tr("Change the scale factor of the whole user interface.")); #else scaleFactorCombo_->hide(); #endif -- cgit 1.5.1 From f452bdf2b01ca6c39bdb3ecd4f61ec1eb1eef211 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 26 May 2020 22:27:05 +0200 Subject: Make settings update immediately in qml and allow limiting timeline width Limiting improves readability on wide monitors. The immediate update of the settings is done by just exposing settings as properties and then setting the settings as a context property. --- resources/qml/Avatar.qml | 4 +- resources/qml/Reactions.qml | 8 +- resources/qml/TimelineRow.qml | 8 +- resources/qml/TimelineView.qml | 33 ++----- resources/qml/delegates/TextMessage.qml | 2 +- src/UserSettingsPage.cpp | 169 ++++++++++++++++++++++++++++++++ src/UserSettingsPage.h | 149 +++++++++++++--------------- src/timeline/TimelineViewManager.cpp | 1 + 8 files changed, 259 insertions(+), 115 deletions(-) (limited to 'src/UserSettingsPage.cpp') diff --git a/resources/qml/Avatar.qml b/resources/qml/Avatar.qml index ed065270..465a8e1c 100644 --- a/resources/qml/Avatar.qml +++ b/resources/qml/Avatar.qml @@ -6,7 +6,7 @@ Rectangle { id: avatar width: 48 height: 48 - radius: settings.avatar_circles ? height/2 : 3 + radius: settings.avatarCircles ? height/2 : 3 property alias url: img.source property string displayName @@ -39,7 +39,7 @@ Rectangle { anchors.fill: parent width: avatar.width height: avatar.height - radius: settings.avatar_circles ? height/2 : 3 + radius: settings.avatarCircles ? height/2 : 3 } } } diff --git a/resources/qml/Reactions.qml b/resources/qml/Reactions.qml index cb15b723..f42e8612 100644 --- a/resources/qml/Reactions.qml +++ b/resources/qml/Reactions.qml @@ -30,7 +30,7 @@ Flow { TextMetrics { id: textMetrics - font.family: settings.emoji_font_family + font.family: settings.emojiFont elide: Text.ElideRight elideWidth: 150 text: reaction.text @@ -40,14 +40,14 @@ Flow { anchors.baseline: reactionCounter.baseline id: reactionText text: textMetrics.elidedText + (textMetrics.elidedText == textMetrics.text ? "" : "…") - font.family: settings.emoji_font_family + font.family: settings.emojiFont color: reaction.hovered ? colors.highlight : colors.text maximumLineCount: 1 } Rectangle { id: divider - height: reactionCounter.implicitHeight * 1.4 + height: Math.floor(reactionCounter.implicitHeight * 1.4) width: 1 color: reaction.hovered ? colors.highlight : colors.text } @@ -64,7 +64,7 @@ Flow { background: Rectangle { anchors.centerIn: parent implicitWidth: reaction.implicitWidth - implicitHeight: reaction.implicitHeight + height: reaction.implicitHeight border.color: (reaction.hovered || model.selfReacted )? colors.highlight : colors.text color: colors.base border.width: 1 diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index 42791e0b..c8e6eb09 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -25,13 +25,13 @@ MouseArea { messageContextMenu.show(model.id, model.type, model.isEncrypted, row) } Rectangle { - color: (timelineSettings.message_hover_highlight && parent.containsMouse) ? colors.base : "transparent" + color: (settings.isMessageHoverHighlightEnabled && parent.containsMouse) ? colors.base : "transparent" anchors.fill: row } RowLayout { id: row - anchors.leftMargin: avatarSize + 4 + anchors.leftMargin: avatarSize + 16 anchors.left: parent.left anchors.right: parent.right @@ -78,7 +78,7 @@ MouseArea { } ImageButton { - visible: timelineSettings.buttons + visible: settings.buttonsInTimeline Layout.alignment: Qt.AlignRight | Qt.AlignTop Layout.preferredHeight: 16 width: 16 @@ -94,7 +94,7 @@ MouseArea { onClicked: chat.model.replyAction(model.id) } ImageButton { - visible: timelineSettings.buttons + visible: settings.buttonsInTimeline Layout.alignment: Qt.AlignRight | Qt.AlignTop Layout.preferredHeight: 16 width: 16 diff --git a/resources/qml/TimelineView.qml b/resources/qml/TimelineView.qml index 145a82ce..08130033 100644 --- a/resources/qml/TimelineView.qml +++ b/resources/qml/TimelineView.qml @@ -3,7 +3,6 @@ import QtQuick.Controls 2.3 import QtQuick.Layouts 1.2 import QtGraphicalEffects 1.0 import QtQuick.Window 2.2 -import Qt.labs.settings 1.0 import im.nheko 1.0 @@ -21,22 +20,6 @@ Page { id: fontMetrics } - Settings { - id: settings - category: "user" - property bool avatar_circles: true - property string emoji_font_family: "default" - property double font_size: Qt.application.font.pointSize - } - - Settings { - id: timelineSettings - category: "user/timeline" - property bool buttons: true - property bool message_hover_highlight: false - property bool enlarge_emoji_only_msg: false - } - Menu { id: messageContextMenu modal: true @@ -102,7 +85,7 @@ Page { BusyIndicator { visible: running anchors.centerIn: parent - running: timelineManager.isInitialSync + running: timelineManager.isInitialSync height: 200 width: 200 z: 3 @@ -113,12 +96,12 @@ Page { visible: timelineManager.timeline != null - cacheBuffer: 500 + cacheBuffer: 400 - anchors.left: parent.left - anchors.right: parent.right + anchors.horizontalCenter: parent.horizontalCenter anchors.top: parent.top anchors.bottom: chatFooter.top + width: parent.width anchors.leftMargin: 4 anchors.rightMargin: scrollbar.width @@ -160,7 +143,7 @@ Page { id: scrollbar parent: chat.parent anchors.top: chat.top - anchors.left: chat.right + anchors.right: chat.right anchors.bottom: chat.bottom } @@ -175,7 +158,8 @@ Page { id: wrapper property Item section - width: chat.width + anchors.horizontalCenter: parent.horizontalCenter + width: (settings.timelineMaxWidth > 100 && (parent.width - settings.timelineMaxWidth) > 32) ? settings.timelineMaxWidth : (parent.width - 32) height: section ? section.height + timelinerow.height : timelinerow.height color: "transparent" @@ -245,7 +229,8 @@ Page { } Row { height: userName.height - spacing: 4 + spacing: 8 + Avatar { width: avatarSize height: avatarSize diff --git a/resources/qml/delegates/TextMessage.qml b/resources/qml/delegates/TextMessage.qml index d17723f3..b3c45c36 100644 --- a/resources/qml/delegates/TextMessage.qml +++ b/resources/qml/delegates/TextMessage.qml @@ -6,5 +6,5 @@ MatrixText { width: parent ? parent.width : undefined height: isReply ? Math.min(chat.height / 8, implicitHeight) : undefined clip: true - font.pointSize: (timelineSettings.enlarge_emoji_only_msg && model.data.isOnlyEmoji > 0 && model.data.isOnlyEmoji < 4) ? settings.font_size * 3 : settings.font_size + font.pointSize: (settings.enlargeEmojiOnlyMessages && model.data.isOnlyEmoji > 0 && model.data.isOnlyEmoji < 4) ? settings.fontSize * 3 : settings.fontSize } diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index c151cad2..393b4861 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -56,6 +57,7 @@ UserSettings::load() isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool(); isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool(); + timelineMaxWidth_ = settings.value("user/timeline/max_width", 0).toInt(); isMessageHoverHighlightEnabled_ = settings.value("user/timeline/message_hover_highlight", false).toBool(); isEnlargeEmojiOnlyMessagesEnabled_ = @@ -73,34 +75,183 @@ UserSettings::load() applyTheme(); } +void +UserSettings::setMessageHoverHighlight(bool state) +{ + if (state == isMessageHoverHighlightEnabled_) + return; + isMessageHoverHighlightEnabled_ = state; + emit messageHoverHighlightChanged(state); + save(); +} +void +UserSettings::setEnlargeEmojiOnlyMessages(bool state) +{ + if (state == isEnlargeEmojiOnlyMessagesEnabled_) + return; + isEnlargeEmojiOnlyMessagesEnabled_ = state; + emit enlargeEmojiOnlyMessagesChanged(state); + save(); +} +void +UserSettings::setTray(bool state) +{ + if (state == isTrayEnabled_) + return; + isTrayEnabled_ = state; + emit trayChanged(state); + save(); +} + +void +UserSettings::setStartInTray(bool state) +{ + if (state == isStartInTrayEnabled_) + return; + isStartInTrayEnabled_ = state; + emit startInTrayChanged(state); + save(); +} + +void +UserSettings::setGroupView(bool state) +{ + if (isGroupViewEnabled_ != state) + emit groupViewStateChanged(state); + + isGroupViewEnabled_ = state; + save(); +} + +void +UserSettings::setMarkdownEnabled(bool state) +{ + if (state == isMarkdownEnabled_) + return; + isMarkdownEnabled_ = state; + emit markdownChanged(state); + save(); +} + +void +UserSettings::setReadReceipts(bool state) +{ + if (state == isReadReceiptsEnabled_) + return; + isReadReceiptsEnabled_ = state; + emit readReceiptsChanged(state); + save(); +} + +void +UserSettings::setTypingNotifications(bool state) +{ + if (state == isTypingNotificationsEnabled_) + return; + isTypingNotificationsEnabled_ = state; + emit typingNotificationsChanged(state); + save(); +} + +void +UserSettings::setSortByImportance(bool state) +{ + if (state == sortByImportance_) + return; + sortByImportance_ = state; + emit roomSortingChanged(state); + save(); +} + +void +UserSettings::setButtonsInTimeline(bool state) +{ + if (state == isButtonsInTimelineEnabled_) + return; + isButtonsInTimelineEnabled_ = state; + emit buttonInTimelineChanged(state); + save(); +} + +void +UserSettings::setTimelineMaxWidth(int state) +{ + if (state == timelineMaxWidth_) + return; + timelineMaxWidth_ = state; + emit timelineMaxWidthChanged(state); + save(); +} + +void +UserSettings::setDesktopNotifications(bool state) +{ + if (state == hasDesktopNotifications_) + return; + hasDesktopNotifications_ = state; + emit desktopNotificationsChanged(state); + save(); +} + +void +UserSettings::setAvatarCircles(bool state) +{ + if (state == avatarCircles_) + return; + avatarCircles_ = state; + emit avatarCirclesChanged(state); + save(); +} + +void +UserSettings::setDecryptSidebar(bool state) +{ + if (state == decryptSidebar_) + return; + decryptSidebar_ = state; + emit decryptSidebarChanged(state); + save(); +} void UserSettings::setFontSize(double size) { + if (size == baseFontSize_) + return; baseFontSize_ = size; + emit fontSizeChanged(size); save(); } void UserSettings::setFontFamily(QString family) { + if (family == font_) + return; font_ = family; + emit fontChanged(family); save(); } void UserSettings::setEmojiFontFamily(QString family) { + if (family == emojiFont_) + return; emojiFont_ = family; + emit emojiFontChanged(family); save(); } void UserSettings::setTheme(QString theme) { + if (theme == theme) + return; theme_ = theme; save(); applyTheme(); + emit themeChanged(theme); } void @@ -171,6 +322,7 @@ UserSettings::save() settings.setValue("buttons", isButtonsInTimelineEnabled_); settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_); settings.setValue("enlarge_emoji_only_msg", isEnlargeEmojiOnlyMessagesEnabled_); + settings.setValue("max_width", timelineMaxWidth_); settings.endGroup(); settings.setValue("avatar_circles", avatarCircles_); @@ -187,6 +339,8 @@ UserSettings::save() settings.setValue("emoji_font_family", emojiFont_); settings.endGroup(); + + settings.sync(); } HorizontalLine::HorizontalLine(QWidget *parent) @@ -251,6 +405,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge fontSizeCombo_ = new QComboBox{this}; fontSelectionCombo_ = new QComboBox{this}; emojiFontSelectionCombo_ = new QComboBox{this}; + timelineMaxWidthSpin_ = new QSpinBox{this}; if (!settings_->isTrayEnabled()) startInTrayToggle_->setDisabled(true); @@ -295,6 +450,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge int themeIndex = themeCombo_->findText(themeStr); themeCombo_->setCurrentIndex(themeIndex); + timelineMaxWidthSpin_->setMinimum(0); + timelineMaxWidthSpin_->setMaximum(100'000'000); + timelineMaxWidthSpin_->setSingleStep(10); + auto encryptionLabel_ = new QLabel{tr("ENCRYPTION"), this}; encryptionLabel_->setFixedHeight(encryptionLabel_->minimumHeight() + LayoutTopMargin); encryptionLabel_->setAlignment(Qt::AlignBottom); @@ -366,6 +525,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge timelineButtonsToggle_, tr("Show buttons to quickly reply, react or access additional options next to each " "message.")); + boxWrap(tr("Limit width of timeline"), + timelineMaxWidthSpin_, + tr("Set the max width of messages in the timeline (in pixels). This can help " + "readability on wide screen, when Nheko is maximised")); boxWrap(tr("Typing notifications"), typingNotifications_, tr("Show who is typing in a room.\nThis will also enable or disable sending typing " @@ -525,6 +688,11 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setEnlargeEmojiOnlyMessages(!isDisabled); }); + connect(timelineMaxWidthSpin_, + qOverload(&QSpinBox::valueChanged), + this, + [this](int newValue) { settings_->setTimelineMaxWidth(newValue); }); + connect( sessionKeysImportBtn, &QPushButton::clicked, this, &UserSettingsPage::importSessionKeys); @@ -560,6 +728,7 @@ UserSettingsPage::showEvent(QShowEvent *) messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled()); enlargeEmojiOnlyMessages_->setState(!settings_->isEnlargeEmojiOnlyMessagesEnabled()); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); + timelineMaxWidthSpin_->setValue(settings_->timelineMaxWidth()); deviceFingerprintValue_->setText( utils::humanReadableFingerprint(olm::client()->identity_keys().ed25519)); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index f80c2b2b..cade8c22 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -27,6 +27,7 @@ class Toggle; class QLabel; class QFormLayout; class QComboBox; +class QSpinBox; class QHBoxLayout; class QVBoxLayout; @@ -38,6 +39,39 @@ class UserSettings : public QObject { Q_OBJECT + Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) + Q_PROPERTY(bool isMessageHoverHighlightEnabled READ isMessageHoverHighlightEnabled WRITE + setMessageHoverHighlight NOTIFY messageHoverHighlightChanged) + Q_PROPERTY(bool enlargeEmojiOnlyMessages READ isEnlargeEmojiOnlyMessagesEnabled WRITE + setEnlargeEmojiOnlyMessages NOTIFY enlargeEmojiOnlyMessagesChanged) + Q_PROPERTY(bool trayEnabled READ isTrayEnabled WRITE setTray NOTIFY trayChanged) + Q_PROPERTY(bool startInTrayEnabled READ isStartInTrayEnabled WRITE setStartInTray NOTIFY + startInTrayChanged) + Q_PROPERTY(bool groupViewEnabled READ isGroupViewEnabled WRITE setGroupView NOTIFY + groupViewStateChanged) + Q_PROPERTY( + bool markdown READ isMarkdownEnabled WRITE setMarkdownEnabled NOTIFY markdownChanged) + Q_PROPERTY(bool typingNotifications READ isTypingNotificationsEnabled WRITE + setTypingNotifications NOTIFY typingNotificationsChanged) + Q_PROPERTY(bool sortByImportance READ isSortByImportanceEnabled WRITE setSortByImportance + NOTIFY roomSortingChanged) + Q_PROPERTY(bool buttonsInTimeline READ isButtonsInTimelineEnabled WRITE setButtonsInTimeline + NOTIFY buttonInTimelineChanged) + Q_PROPERTY(bool readReceipts READ isReadReceiptsEnabled WRITE setReadReceipts NOTIFY + readReceiptsChanged) + Q_PROPERTY(bool desktopNotifications READ hasDesktopNotifications WRITE + setDesktopNotifications NOTIFY desktopNotificationsChanged) + Q_PROPERTY(bool avatarCircles READ isAvatarCirclesEnabled WRITE setAvatarCircles NOTIFY + avatarCirclesChanged) + Q_PROPERTY(bool decryptSidebar READ isDecryptSidebarEnabled WRITE setDecryptSidebar NOTIFY + decryptSidebarChanged) + Q_PROPERTY(int timelineMaxWidth READ timelineMaxWidth WRITE setTimelineMaxWidth NOTIFY + timelineMaxWidthChanged) + Q_PROPERTY(double fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) + Q_PROPERTY(QString font READ font WRITE setFontFamily NOTIFY fontChanged) + Q_PROPERTY( + QString emojiFont READ emojiFont WRITE setEmojiFontFamily NOTIFY emojiFontChanged) + public: UserSettings(); @@ -45,88 +79,23 @@ public: void load(); void applyTheme(); void setTheme(QString theme); - void setMessageHoverHighlight(bool state) - { - isMessageHoverHighlightEnabled_ = state; - save(); - } - void setEnlargeEmojiOnlyMessages(bool state) - { - isEnlargeEmojiOnlyMessagesEnabled_ = state; - save(); - } - void setTray(bool state) - { - isTrayEnabled_ = state; - save(); - } - - void setStartInTray(bool state) - { - isStartInTrayEnabled_ = state; - save(); - } - + void setMessageHoverHighlight(bool state); + void setEnlargeEmojiOnlyMessages(bool state); + void setTray(bool state); + void setStartInTray(bool state); void setFontSize(double size); void setFontFamily(QString family); void setEmojiFontFamily(QString family); - - void setGroupView(bool state) - { - if (isGroupViewEnabled_ != state) - emit groupViewStateChanged(state); - - isGroupViewEnabled_ = state; - save(); - } - - void setMarkdownEnabled(bool state) - { - isMarkdownEnabled_ = state; - save(); - } - - void setReadReceipts(bool state) - { - isReadReceiptsEnabled_ = state; - save(); - } - - void setTypingNotifications(bool state) - { - isTypingNotificationsEnabled_ = state; - save(); - } - - void setSortByImportance(bool state) - { - sortByImportance_ = state; - emit roomSortingChanged(); - } - - void setButtonsInTimeline(bool state) - { - isButtonsInTimelineEnabled_ = state; - save(); - } - - void setDesktopNotifications(bool state) - { - hasDesktopNotifications_ = state; - save(); - } - - void setAvatarCircles(bool state) - { - avatarCircles_ = state; - save(); - } - - void setDecryptSidebar(bool state) - { - decryptSidebar_ = state; - save(); - } + void setGroupView(bool state); + void setMarkdownEnabled(bool state); + void setReadReceipts(bool state); + void setTypingNotifications(bool state); + void setSortByImportance(bool state); + void setButtonsInTimeline(bool state); + void setTimelineMaxWidth(int state); + void setDesktopNotifications(bool state); + void setAvatarCircles(bool state); + void setDecryptSidebar(bool state); QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } bool isMessageHoverHighlightEnabled() const { return isMessageHoverHighlightEnabled_; } @@ -145,13 +114,30 @@ public: bool isButtonsInTimelineEnabled() const { return isButtonsInTimelineEnabled_; } bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; } + int timelineMaxWidth() const { return timelineMaxWidth_; } double fontSize() const { return baseFontSize_; } QString font() const { return font_; } QString emojiFont() const { return emojiFont_; } signals: void groupViewStateChanged(bool state); - void roomSortingChanged(); + void roomSortingChanged(bool state); + void themeChanged(QString state); + void messageHoverHighlightChanged(bool state); + void enlargeEmojiOnlyMessagesChanged(bool state); + void trayChanged(bool state); + void startInTrayChanged(bool state); + void markdownChanged(bool state); + void typingNotificationsChanged(bool state); + void buttonInTimelineChanged(bool state); + void readReceiptsChanged(bool state); + void desktopNotificationsChanged(bool state); + void avatarCirclesChanged(bool state); + void decryptSidebarChanged(bool state); + void timelineMaxWidthChanged(int state); + void fontSizeChanged(double state); + void fontChanged(QString state); + void emojiFontChanged(QString state); private: // Default to system theme if QT_QPA_PLATFORMTHEME var is set. @@ -173,6 +159,7 @@ private: bool hasDesktopNotifications_; bool avatarCircles_; bool decryptSidebar_; + int timelineMaxWidth_; double baseFontSize_; QString font_; QString emojiFont_; @@ -238,5 +225,7 @@ private: QComboBox *fontSelectionCombo_; QComboBox *emojiFontSelectionCombo_; + QSpinBox *timelineMaxWidthSpin_; + int sideMargin_ = 0; }; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index b9565be8..89882e9d 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -88,6 +88,7 @@ TimelineViewManager::TimelineViewManager(QSharedPointer userSettin #endif container->setMinimumSize(200, 200); view->rootContext()->setContextProperty("timelineManager", this); + view->rootContext()->setContextProperty("settings", settings.data()); updateColorPalette(); view->engine()->addImageProvider("MxcImage", imgProvider); view->engine()->addImageProvider("colorimage", colorImgProvider); -- cgit 1.5.1 From 6b60ff77135c3717159f760e82f14841c50816aa Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 26 May 2020 22:53:21 +0200 Subject: Rename settings to be more consistent --- resources/qml/TimelineRow.qml | 2 +- src/ChatPage.cpp | 8 +- src/MainWindow.cpp | 4 +- src/RoomInfoListItem.cpp | 2 +- src/UserSettingsPage.cpp | 178 +++++++++++++++++------------------ src/UserSettingsPage.h | 84 ++++++++--------- src/timeline/TimelineViewManager.cpp | 12 +-- 7 files changed, 142 insertions(+), 148 deletions(-) (limited to 'src/UserSettingsPage.cpp') diff --git a/resources/qml/TimelineRow.qml b/resources/qml/TimelineRow.qml index c8e6eb09..528dce85 100644 --- a/resources/qml/TimelineRow.qml +++ b/resources/qml/TimelineRow.qml @@ -25,7 +25,7 @@ MouseArea { messageContextMenu.show(model.id, model.type, model.isEncrypted, row) } Rectangle { - color: (settings.isMessageHoverHighlightEnabled && parent.containsMouse) ? colors.base : "transparent" + color: (settings.messageHoverHighlight && parent.containsMouse) ? colors.base : "transparent" anchors.fill: row } RowLayout { diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 90abc63e..2b55b91e 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -255,7 +255,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) text_input_, &TextInputWidget::startedTyping, this, &ChatPage::sendTypingNotifications); connect(typingRefresher_, &QTimer::timeout, this, &ChatPage::sendTypingNotifications); connect(text_input_, &TextInputWidget::stoppedTyping, this, [this]() { - if (!userSettings_->isTypingNotificationsEnabled()) + if (!userSettings_->typingNotifications()) return; typingRefresher_->stop(); @@ -482,7 +482,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) activateWindow(); }); - setGroupViewState(userSettings_->isGroupViewEnabled()); + setGroupViewState(userSettings_->groupView()); connect(userSettings_.data(), &UserSettings::groupViewStateChanged, @@ -1207,7 +1207,7 @@ ChatPage::unbanUser(QString userid, QString reason) void ChatPage::sendTypingNotifications() { - if (!userSettings_->isTypingNotificationsEnabled()) + if (!userSettings_->typingNotifications()) return; http::client()->start_typing( @@ -1343,7 +1343,7 @@ ChatPage::hideSideBars() void ChatPage::showSideBars() { - if (userSettings_->isGroupViewEnabled()) + if (userSettings_->groupView()) communitiesList_->show(); sideBar_->show(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index c6abdca2..cc1d868b 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -148,7 +148,7 @@ MainWindow::MainWindow(QWidget *parent) QSettings settings; - trayIcon_->setVisible(userSettings_->isTrayEnabled()); + trayIcon_->setVisible(userSettings_->tray()); if (hasActiveUser()) { QString token = settings.value("auth/access_token").toString(); @@ -286,7 +286,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (!qApp->isSavingSession() && isVisible() && pageSupportsTray() && - userSettings_->isTrayEnabled()) { + userSettings_->tray()) { event->ignore(); hide(); } diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index ad774360..f234b59b 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -451,7 +451,7 @@ RoomInfoListItem::calculateImportance() const // returns ImportanceDisabled or Invite if (isInvite()) { return Invite; - } else if (!settings->isSortByImportanceEnabled()) { + } else if (!settings->sortByImportance()) { return ImportanceDisabled; } else if (unreadHighlightedMsgCount_) { return NewMentions; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 393b4861..38b76404 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -52,53 +52,53 @@ void UserSettings::load() { QSettings settings; - isTrayEnabled_ = settings.value("user/window/tray", false).toBool(); - hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool(); - isStartInTrayEnabled_ = settings.value("user/window/start_in_tray", false).toBool(); - isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); - isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", true).toBool(); - timelineMaxWidth_ = settings.value("user/timeline/max_width", 0).toInt(); - isMessageHoverHighlightEnabled_ = + tray_ = settings.value("user/window/tray", false).toBool(); + hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool(); + startInTray_ = settings.value("user/window/start_in_tray", false).toBool(); + groupView_ = settings.value("user/group_view", true).toBool(); + buttonsInTimeline_ = settings.value("user/timeline/buttons", true).toBool(); + timelineMaxWidth_ = settings.value("user/timeline/max_width", 0).toInt(); + messageHoverHighlight_ = settings.value("user/timeline/message_hover_highlight", false).toBool(); - isEnlargeEmojiOnlyMessagesEnabled_ = + enlargeEmojiOnlyMessages_ = settings.value("user/timeline/enlarge_emoji_only_msg", false).toBool(); - isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool(); - isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); - sortByImportance_ = settings.value("user/sort_by_unread", true).toBool(); - isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); - theme_ = settings.value("user/theme", defaultTheme_).toString(); - font_ = settings.value("user/font_family", "default").toString(); - avatarCircles_ = settings.value("user/avatar_circles", true).toBool(); - decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); - emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); - baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); + markdown_ = settings.value("user/markdown_enabled", true).toBool(); + typingNotifications_ = settings.value("user/typing_notifications", true).toBool(); + sortByImportance_ = settings.value("user/sort_by_unread", true).toBool(); + readReceipts_ = settings.value("user/read_receipts", true).toBool(); + theme_ = settings.value("user/theme", defaultTheme_).toString(); + font_ = settings.value("user/font_family", "default").toString(); + avatarCircles_ = settings.value("user/avatar_circles", true).toBool(); + decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); + emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); + baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); applyTheme(); } void UserSettings::setMessageHoverHighlight(bool state) { - if (state == isMessageHoverHighlightEnabled_) + if (state == messageHoverHighlight_) return; - isMessageHoverHighlightEnabled_ = state; + messageHoverHighlight_ = state; emit messageHoverHighlightChanged(state); save(); } void UserSettings::setEnlargeEmojiOnlyMessages(bool state) { - if (state == isEnlargeEmojiOnlyMessagesEnabled_) + if (state == enlargeEmojiOnlyMessages_) return; - isEnlargeEmojiOnlyMessagesEnabled_ = state; + enlargeEmojiOnlyMessages_ = state; emit enlargeEmojiOnlyMessagesChanged(state); save(); } void UserSettings::setTray(bool state) { - if (state == isTrayEnabled_) + if (state == tray_) return; - isTrayEnabled_ = state; + tray_ = state; emit trayChanged(state); save(); } @@ -106,9 +106,9 @@ UserSettings::setTray(bool state) void UserSettings::setStartInTray(bool state) { - if (state == isStartInTrayEnabled_) + if (state == startInTray_) return; - isStartInTrayEnabled_ = state; + startInTray_ = state; emit startInTrayChanged(state); save(); } @@ -116,19 +116,19 @@ UserSettings::setStartInTray(bool state) void UserSettings::setGroupView(bool state) { - if (isGroupViewEnabled_ != state) + if (groupView_ != state) emit groupViewStateChanged(state); - isGroupViewEnabled_ = state; + groupView_ = state; save(); } void -UserSettings::setMarkdownEnabled(bool state) +UserSettings::setMarkdown(bool state) { - if (state == isMarkdownEnabled_) + if (state == markdown_) return; - isMarkdownEnabled_ = state; + markdown_ = state; emit markdownChanged(state); save(); } @@ -136,9 +136,9 @@ UserSettings::setMarkdownEnabled(bool state) void UserSettings::setReadReceipts(bool state) { - if (state == isReadReceiptsEnabled_) + if (state == readReceipts_) return; - isReadReceiptsEnabled_ = state; + readReceipts_ = state; emit readReceiptsChanged(state); save(); } @@ -146,9 +146,9 @@ UserSettings::setReadReceipts(bool state) void UserSettings::setTypingNotifications(bool state) { - if (state == isTypingNotificationsEnabled_) + if (state == typingNotifications_) return; - isTypingNotificationsEnabled_ = state; + typingNotifications_ = state; emit typingNotificationsChanged(state); save(); } @@ -166,9 +166,9 @@ UserSettings::setSortByImportance(bool state) void UserSettings::setButtonsInTimeline(bool state) { - if (state == isButtonsInTimelineEnabled_) + if (state == buttonsInTimeline_) return; - isButtonsInTimelineEnabled_ = state; + buttonsInTimeline_ = state; emit buttonInTimelineChanged(state); save(); } @@ -314,25 +314,25 @@ UserSettings::save() settings.beginGroup("user"); settings.beginGroup("window"); - settings.setValue("tray", isTrayEnabled_); - settings.setValue("start_in_tray", isStartInTrayEnabled_); + settings.setValue("tray", tray_); + settings.setValue("start_in_tray", startInTray_); settings.endGroup(); settings.beginGroup("timeline"); - settings.setValue("buttons", isButtonsInTimelineEnabled_); - settings.setValue("message_hover_highlight", isMessageHoverHighlightEnabled_); - settings.setValue("enlarge_emoji_only_msg", isEnlargeEmojiOnlyMessagesEnabled_); + settings.setValue("buttons", buttonsInTimeline_); + settings.setValue("message_hover_highlight", messageHoverHighlight_); + settings.setValue("enlarge_emoji_only_msg", enlargeEmojiOnlyMessages_); settings.setValue("max_width", timelineMaxWidth_); settings.endGroup(); settings.setValue("avatar_circles", avatarCircles_); settings.setValue("decrypt_sidebar", decryptSidebar_); settings.setValue("font_size", baseFontSize_); - settings.setValue("typing_notifications", isTypingNotificationsEnabled_); + settings.setValue("typing_notifications", typingNotifications_); settings.setValue("minor_events", sortByImportance_); - settings.setValue("read_receipts", isReadReceiptsEnabled_); - settings.setValue("group_view", isGroupViewEnabled_); - settings.setValue("markdown_enabled", isMarkdownEnabled_); + settings.setValue("read_receipts", readReceipts_); + settings.setValue("group_view", groupView_); + settings.setValue("markdown_enabled", markdown_); settings.setValue("desktop_notifications", hasDesktopNotifications_); settings.setValue("theme", theme()); settings.setValue("font_family", font_); @@ -399,7 +399,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge enlargeEmojiOnlyMessages_ = new Toggle{this}; sortByImportance_ = new Toggle{this}; readReceipts_ = new Toggle{this}; - markdownEnabled_ = new Toggle{this}; + markdown_ = new Toggle{this}; desktopNotifications_ = new Toggle{this}; scaleFactorCombo_ = new QComboBox{this}; fontSizeCombo_ = new QComboBox{this}; @@ -407,7 +407,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge emojiFontSelectionCombo_ = new QComboBox{this}; timelineMaxWidthSpin_ = new QSpinBox{this}; - if (!settings_->isTrayEnabled()) + if (!settings_->tray()) startInTrayToggle_->setDisabled(true); avatarCircles_->setFixedSize(64, 48); @@ -548,7 +548,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge tr("Show if your message was read.\nStatus is displayed next to timestamps.")); boxWrap( tr("Send messages as Markdown"), - markdownEnabled_, + markdown_, tr("Allow using markdown in messages.\nWhen disabled, all messages are sent as a plain " "text.")); boxWrap(tr("Desktop notifications"), @@ -629,63 +629,63 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge connect(emojiFontSelectionCombo_, static_cast(&QComboBox::activated), [this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); }); - connect(trayToggle_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setTray(!isDisabled); - if (isDisabled) { + connect(trayToggle_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setTray(!disabled); + if (disabled) { startInTrayToggle_->setDisabled(true); } else { startInTrayToggle_->setEnabled(true); } - emit trayOptionChanged(!isDisabled); + emit trayOptionChanged(!disabled); }); - connect(startInTrayToggle_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setStartInTray(!isDisabled); + connect(startInTrayToggle_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setStartInTray(!disabled); }); - connect(groupViewToggle_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setGroupView(!isDisabled); + connect(groupViewToggle_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setGroupView(!disabled); }); - connect(decryptSidebar_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setDecryptSidebar(!isDisabled); + connect(decryptSidebar_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setDecryptSidebar(!disabled); emit decryptSidebarChanged(); }); - connect(avatarCircles_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setAvatarCircles(!isDisabled); + connect(avatarCircles_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setAvatarCircles(!disabled); }); - connect(markdownEnabled_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setMarkdownEnabled(!isDisabled); + connect(markdown_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setMarkdown(!disabled); }); - connect(typingNotifications_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setTypingNotifications(!isDisabled); + connect(typingNotifications_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setTypingNotifications(!disabled); }); - connect(sortByImportance_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setSortByImportance(!isDisabled); + connect(sortByImportance_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setSortByImportance(!disabled); }); - connect(timelineButtonsToggle_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setButtonsInTimeline(!isDisabled); + connect(timelineButtonsToggle_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setButtonsInTimeline(!disabled); }); - connect(readReceipts_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setReadReceipts(!isDisabled); + connect(readReceipts_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setReadReceipts(!disabled); }); - connect(desktopNotifications_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setDesktopNotifications(!isDisabled); + connect(desktopNotifications_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setDesktopNotifications(!disabled); }); - connect(messageHoverHighlight_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setMessageHoverHighlight(!isDisabled); + connect(messageHoverHighlight_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setMessageHoverHighlight(!disabled); }); - connect(enlargeEmojiOnlyMessages_, &Toggle::toggled, this, [this](bool isDisabled) { - settings_->setEnlargeEmojiOnlyMessages(!isDisabled); + connect(enlargeEmojiOnlyMessages_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setEnlargeEmojiOnlyMessages(!disabled); }); connect(timelineMaxWidthSpin_, @@ -714,19 +714,19 @@ UserSettingsPage::showEvent(QShowEvent *) utils::restoreCombobox(themeCombo_, settings_->theme()); // FIXME: Toggle treats true as "off" - trayToggle_->setState(!settings_->isTrayEnabled()); - startInTrayToggle_->setState(!settings_->isStartInTrayEnabled()); - groupViewToggle_->setState(!settings_->isGroupViewEnabled()); - decryptSidebar_->setState(!settings_->isDecryptSidebarEnabled()); - avatarCircles_->setState(!settings_->isAvatarCirclesEnabled()); - typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); - sortByImportance_->setState(!settings_->isSortByImportanceEnabled()); - timelineButtonsToggle_->setState(!settings_->isButtonsInTimelineEnabled()); - readReceipts_->setState(!settings_->isReadReceiptsEnabled()); - markdownEnabled_->setState(!settings_->isMarkdownEnabled()); + trayToggle_->setState(!settings_->tray()); + startInTrayToggle_->setState(!settings_->startInTray()); + groupViewToggle_->setState(!settings_->groupView()); + decryptSidebar_->setState(!settings_->decryptSidebar()); + avatarCircles_->setState(!settings_->avatarCircles()); + typingNotifications_->setState(!settings_->typingNotifications()); + sortByImportance_->setState(!settings_->sortByImportance()); + timelineButtonsToggle_->setState(!settings_->buttonsInTimeline()); + readReceipts_->setState(!settings_->readReceipts()); + markdown_->setState(!settings_->markdown()); desktopNotifications_->setState(!settings_->hasDesktopNotifications()); - messageHoverHighlight_->setState(!settings_->isMessageHoverHighlightEnabled()); - enlargeEmojiOnlyMessages_->setState(!settings_->isEnlargeEmojiOnlyMessagesEnabled()); + messageHoverHighlight_->setState(!settings_->messageHoverHighlight()); + enlargeEmojiOnlyMessages_->setState(!settings_->enlargeEmojiOnlyMessages()); deviceIdValue_->setText(QString::fromStdString(http::client()->device_id())); timelineMaxWidthSpin_->setValue(settings_->timelineMaxWidth()); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index cade8c22..fb807067 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -40,30 +40,27 @@ class UserSettings : public QObject Q_OBJECT Q_PROPERTY(QString theme READ theme WRITE setTheme NOTIFY themeChanged) - Q_PROPERTY(bool isMessageHoverHighlightEnabled READ isMessageHoverHighlightEnabled WRITE + Q_PROPERTY(bool messageHoverHighlight READ messageHoverHighlight WRITE setMessageHoverHighlight NOTIFY messageHoverHighlightChanged) - Q_PROPERTY(bool enlargeEmojiOnlyMessages READ isEnlargeEmojiOnlyMessagesEnabled WRITE + Q_PROPERTY(bool enlargeEmojiOnlyMessages READ enlargeEmojiOnlyMessages WRITE setEnlargeEmojiOnlyMessages NOTIFY enlargeEmojiOnlyMessagesChanged) - Q_PROPERTY(bool trayEnabled READ isTrayEnabled WRITE setTray NOTIFY trayChanged) - Q_PROPERTY(bool startInTrayEnabled READ isStartInTrayEnabled WRITE setStartInTray NOTIFY - startInTrayChanged) - Q_PROPERTY(bool groupViewEnabled READ isGroupViewEnabled WRITE setGroupView NOTIFY - groupViewStateChanged) + Q_PROPERTY(bool tray READ tray WRITE setTray NOTIFY trayChanged) + Q_PROPERTY(bool startInTray READ startInTray WRITE setStartInTray NOTIFY startInTrayChanged) + Q_PROPERTY(bool groupView READ groupView WRITE setGroupView NOTIFY groupViewStateChanged) + Q_PROPERTY(bool markdown READ markdown WRITE setMarkdown NOTIFY markdownChanged) + Q_PROPERTY(bool typingNotifications READ typingNotifications WRITE setTypingNotifications + NOTIFY typingNotificationsChanged) + Q_PROPERTY(bool sortByImportance READ sortByImportance WRITE setSortByImportance NOTIFY + roomSortingChanged) + Q_PROPERTY(bool buttonsInTimeline READ buttonsInTimeline WRITE setButtonsInTimeline NOTIFY + buttonInTimelineChanged) Q_PROPERTY( - bool markdown READ isMarkdownEnabled WRITE setMarkdownEnabled NOTIFY markdownChanged) - Q_PROPERTY(bool typingNotifications READ isTypingNotificationsEnabled WRITE - setTypingNotifications NOTIFY typingNotificationsChanged) - Q_PROPERTY(bool sortByImportance READ isSortByImportanceEnabled WRITE setSortByImportance - NOTIFY roomSortingChanged) - Q_PROPERTY(bool buttonsInTimeline READ isButtonsInTimelineEnabled WRITE setButtonsInTimeline - NOTIFY buttonInTimelineChanged) - Q_PROPERTY(bool readReceipts READ isReadReceiptsEnabled WRITE setReadReceipts NOTIFY - readReceiptsChanged) + bool readReceipts READ readReceipts WRITE setReadReceipts NOTIFY readReceiptsChanged) Q_PROPERTY(bool desktopNotifications READ hasDesktopNotifications WRITE setDesktopNotifications NOTIFY desktopNotificationsChanged) - Q_PROPERTY(bool avatarCircles READ isAvatarCirclesEnabled WRITE setAvatarCircles NOTIFY - avatarCirclesChanged) - Q_PROPERTY(bool decryptSidebar READ isDecryptSidebarEnabled WRITE setDecryptSidebar NOTIFY + Q_PROPERTY( + bool avatarCircles READ avatarCircles WRITE setAvatarCircles NOTIFY avatarCirclesChanged) + Q_PROPERTY(bool decryptSidebar READ decryptSidebar WRITE setDecryptSidebar NOTIFY decryptSidebarChanged) Q_PROPERTY(int timelineMaxWidth READ timelineMaxWidth WRITE setTimelineMaxWidth NOTIFY timelineMaxWidthChanged) @@ -87,7 +84,7 @@ public: void setFontFamily(QString family); void setEmojiFontFamily(QString family); void setGroupView(bool state); - void setMarkdownEnabled(bool state); + void setMarkdown(bool state); void setReadReceipts(bool state); void setTypingNotifications(bool state); void setSortByImportance(bool state); @@ -98,21 +95,18 @@ public: void setDecryptSidebar(bool state); QString theme() const { return !theme_.isEmpty() ? theme_ : defaultTheme_; } - bool isMessageHoverHighlightEnabled() const { return isMessageHoverHighlightEnabled_; } - bool isEnlargeEmojiOnlyMessagesEnabled() const - { - return isEnlargeEmojiOnlyMessagesEnabled_; - } - bool isTrayEnabled() const { return isTrayEnabled_; } - bool isStartInTrayEnabled() const { return isStartInTrayEnabled_; } - bool isGroupViewEnabled() const { return isGroupViewEnabled_; } - bool isAvatarCirclesEnabled() const { return avatarCircles_; } - bool isDecryptSidebarEnabled() const { return decryptSidebar_; } - bool isMarkdownEnabled() const { return isMarkdownEnabled_; } - bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } - bool isSortByImportanceEnabled() const { return sortByImportance_; } - bool isButtonsInTimelineEnabled() const { return isButtonsInTimelineEnabled_; } - bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } + bool messageHoverHighlight() const { return messageHoverHighlight_; } + bool enlargeEmojiOnlyMessages() const { return enlargeEmojiOnlyMessages_; } + bool tray() const { return tray_; } + bool startInTray() const { return startInTray_; } + bool groupView() const { return groupView_; } + bool avatarCircles() const { return avatarCircles_; } + bool decryptSidebar() const { return decryptSidebar_; } + bool markdown() const { return markdown_; } + bool typingNotifications() const { return typingNotifications_; } + bool sortByImportance() const { return sortByImportance_; } + bool buttonsInTimeline() const { return buttonsInTimeline_; } + bool readReceipts() const { return readReceipts_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; } int timelineMaxWidth() const { return timelineMaxWidth_; } double fontSize() const { return baseFontSize_; } @@ -146,16 +140,16 @@ private: ? "light" : "system"; QString theme_; - bool isMessageHoverHighlightEnabled_; - bool isEnlargeEmojiOnlyMessagesEnabled_; - bool isTrayEnabled_; - bool isStartInTrayEnabled_; - bool isGroupViewEnabled_; - bool isMarkdownEnabled_; - bool isTypingNotificationsEnabled_; + bool messageHoverHighlight_; + bool enlargeEmojiOnlyMessages_; + bool tray_; + bool startInTray_; + bool groupView_; + bool markdown_; + bool typingNotifications_; bool sortByImportance_; - bool isButtonsInTimelineEnabled_; - bool isReadReceiptsEnabled_; + bool buttonsInTimeline_; + bool readReceipts_; bool hasDesktopNotifications_; bool avatarCircles_; bool decryptSidebar_; @@ -212,7 +206,7 @@ private: Toggle *enlargeEmojiOnlyMessages_; Toggle *sortByImportance_; Toggle *readReceipts_; - Toggle *markdownEnabled_; + Toggle *markdown_; Toggle *desktopNotifications_; Toggle *avatarCircles_; Toggle *decryptSidebar_; diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 89882e9d..30abe506 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -19,7 +19,7 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) void TimelineViewManager::updateEncryptedDescriptions() { - auto decrypt = settings->isDecryptSidebarEnabled(); + auto decrypt = settings->decryptSidebar(); QHash>::iterator i; for (i = models.begin(); i != models.end(); ++i) { auto ptr = i.value(); @@ -114,7 +114,7 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms) const auto &room_model = models.value(QString::fromStdString(room_id)); room_model->addEvents(room.timeline); - if (ChatPage::instance()->userSettings()->isTypingNotificationsEnabled()) { + if (ChatPage::instance()->userSettings()->typingNotifications()) { std::vector typing; typing.reserve(room.ephemeral.typing.size()); for (const auto &user : room.ephemeral.typing) { @@ -134,7 +134,7 @@ TimelineViewManager::addRoom(const QString &room_id) { if (!models.contains(room_id)) { QSharedPointer newRoom(new TimelineModel(this, room_id)); - newRoom->setDecryptDescription(settings->isDecryptSidebarEnabled()); + newRoom->setDecryptDescription(settings->decryptSidebar()); connect(newRoom.data(), &TimelineModel::newEncryptedImage, @@ -218,7 +218,7 @@ TimelineViewManager::queueTextMessage(const QString &msg) mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); - if (settings->isMarkdownEnabled()) { + if (settings->markdown()) { text.formatted_body = utils::markdownToHtml(msg).toStdString(); // Don't send formatted_body, when we don't need to @@ -246,7 +246,7 @@ TimelineViewManager::queueTextMessage(const QString &msg) // NOTE(Nico): rich replies always need a formatted_body! text.format = "org.matrix.custom.html"; - if (settings->isMarkdownEnabled()) + if (settings->markdown()) text.formatted_body = utils::getFormattedQuoteBody(related, utils::markdownToHtml(msg)) .toStdString(); @@ -269,7 +269,7 @@ TimelineViewManager::queueEmoteMessage(const QString &msg) mtx::events::msg::Emote emote; emote.body = msg.trimmed().toStdString(); - if (html != msg.trimmed().toHtmlEscaped() && settings->isMarkdownEnabled()) { + if (html != msg.trimmed().toHtmlEscaped() && settings->markdown()) { emote.formatted_body = html.toStdString(); emote.format = "org.matrix.custom.html"; } -- cgit 1.5.1 From 43d2ebc0958d364ff24ae70920a3edeef7d0ce72 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 5 Jun 2020 23:34:00 +0200 Subject: Fix Qt5.15 issues fixes #214 --- src/LoginPage.cpp | 2 +- src/RegisterPage.cpp | 8 ++++---- src/UserSettingsPage.cpp | 10 +++++----- src/Utils.cpp | 4 ++-- src/dialogs/CreateRoom.cpp | 4 ++-- src/dialogs/ReadReceipts.cpp | 10 ++++++---- src/ui/Avatar.cpp | 1 + src/ui/InfoMessage.cpp | 1 + src/ui/Painter.h | 3 ++- 9 files changed, 24 insertions(+), 19 deletions(-) (limited to 'src/UserSettingsPage.cpp') diff --git a/src/LoginPage.cpp b/src/LoginPage.cpp index 4ed08901..9a920d1d 100644 --- a/src/LoginPage.cpp +++ b/src/LoginPage.cpp @@ -133,7 +133,7 @@ LoginPage::LoginPage(QWidget *parent) form_layout_->addLayout(matrixidLayout_); form_layout_->addWidget(password_input_); - form_layout_->addWidget(deviceName_, Qt::AlignHCenter, nullptr); + form_layout_->addWidget(deviceName_, Qt::AlignHCenter); form_layout_->addLayout(serverLayout_); button_layout_ = new QHBoxLayout(); diff --git a/src/RegisterPage.cpp b/src/RegisterPage.cpp index e57961ef..b8fe93b5 100644 --- a/src/RegisterPage.cpp +++ b/src/RegisterPage.cpp @@ -107,10 +107,10 @@ RegisterPage::RegisterPage(QWidget *parent) tr("A server that allows registration. Since matrix is decentralized, you need to first " "find a server you can register on or host your own.")); - form_layout_->addWidget(username_input_, Qt::AlignHCenter, nullptr); - form_layout_->addWidget(password_input_, Qt::AlignHCenter, nullptr); - form_layout_->addWidget(password_confirmation_, Qt::AlignHCenter, nullptr); - form_layout_->addWidget(server_input_, Qt::AlignHCenter, nullptr); + form_layout_->addWidget(username_input_, Qt::AlignHCenter); + form_layout_->addWidget(password_input_, Qt::AlignHCenter); + form_layout_->addWidget(password_confirmation_, Qt::AlignHCenter); + form_layout_->addWidget(server_input_, Qt::AlignHCenter); button_layout_ = new QHBoxLayout(); button_layout_->setSpacing(0); diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 38b76404..dfd99069 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -612,22 +612,22 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge topLayout_->addWidget(versionInfo); connect(themeCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &text) { settings_->setTheme(text.toLower()); emit themeChanged(); }); connect(scaleFactorCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [](const QString &factor) { utils::setScaleFactor(factor.toFloat()); }); connect(fontSizeCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &size) { settings_->setFontSize(size.trimmed().toDouble()); }); connect(fontSelectionCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &family) { settings_->setFontFamily(family.trimmed()); }); connect(emojiFontSelectionCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &family) { settings_->setEmojiFontFamily(family.trimmed()); }); connect(trayToggle_, &Toggle::toggled, this, [this](bool disabled) { settings_->setTray(!disabled); diff --git a/src/Utils.cpp b/src/Utils.cpp index d539eac5..26ea124c 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -142,13 +142,13 @@ utils::descriptiveTime(const QDateTime &then) const auto days = then.daysTo(now); if (days == 0) - return then.time().toString(Qt::DefaultLocaleShortDate); + return QLocale::system().toString(then.time(), QLocale::ShortFormat); else if (days < 2) return QString(QCoreApplication::translate("descriptiveTime", "Yesterday")); else if (days < 7) return then.toString("dddd"); - return then.date().toString(Qt::DefaultLocaleShortDate); + return QLocale::system().toString(then.date(), QLocale::ShortFormat); } DescInfo diff --git a/src/dialogs/CreateRoom.cpp b/src/dialogs/CreateRoom.cpp index 06676d3d..be5b4638 100644 --- a/src/dialogs/CreateRoom.cpp +++ b/src/dialogs/CreateRoom.cpp @@ -112,7 +112,7 @@ CreateRoom::CreateRoom(QWidget *parent) }); connect(visibilityCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &text) { if (text == "Private") { request_.visibility = mtx::requests::Visibility::Private; @@ -122,7 +122,7 @@ CreateRoom::CreateRoom(QWidget *parent) }); connect(presetCombo_, - static_cast(&QComboBox::activated), + static_cast(&QComboBox::currentTextChanged), [this](const QString &text) { if (text == "Private Chat") { request_.preset = mtx::requests::Preset::PrivateChat; diff --git a/src/dialogs/ReadReceipts.cpp b/src/dialogs/ReadReceipts.cpp index 970d9125..7dcffc28 100644 --- a/src/dialogs/ReadReceipts.cpp +++ b/src/dialogs/ReadReceipts.cpp @@ -75,15 +75,17 @@ ReceiptItem::dateFormat(const QDateTime &then) const auto days = then.daysTo(now); if (days == 0) - return tr("Today %1").arg(then.time().toString(Qt::DefaultLocaleShortDate)); + return tr("Today %1") + .arg(QLocale::system().toString(then.time(), QLocale::ShortFormat)); else if (days < 2) - return tr("Yesterday %1").arg(then.time().toString(Qt::DefaultLocaleShortDate)); + return tr("Yesterday %1") + .arg(QLocale::system().toString(then.time(), QLocale::ShortFormat)); else if (days < 7) return QString("%1 %2") .arg(then.toString("dddd")) - .arg(then.time().toString(Qt::DefaultLocaleShortDate)); + .arg(QLocale::system().toString(then.time(), QLocale::ShortFormat)); - return then.toString(Qt::DefaultLocaleShortDate); + return QLocale::system().toString(then.time(), QLocale::ShortFormat); } ReadReceipts::ReadReceipts(QWidget *parent) diff --git a/src/ui/Avatar.cpp b/src/ui/Avatar.cpp index cb77d1a8..70ebfcf2 100644 --- a/src/ui/Avatar.cpp +++ b/src/ui/Avatar.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "AvatarProvider.h" diff --git a/src/ui/InfoMessage.cpp b/src/ui/InfoMessage.cpp index 27bc0a5f..0b69564d 100644 --- a/src/ui/InfoMessage.cpp +++ b/src/ui/InfoMessage.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/src/ui/Painter.h b/src/ui/Painter.h index 4d227a5a..2bb0981b 100644 --- a/src/ui/Painter.h +++ b/src/ui/Painter.h @@ -3,6 +3,7 @@ #include #include #include +#include #include class Painter : public QPainter @@ -163,5 +164,5 @@ public: private: Painter &_painter; - QPainter::RenderHints hints_ = 0; + QPainter::RenderHints hints_ = {}; }; -- cgit 1.5.1