From 3172811ca784c7bdaa02ad4e0a59a8f0ef381280 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sat, 24 Oct 2020 16:21:00 +0200 Subject: [PATCH] Add mobile mode which improves scrolling --- resources/qml/MatrixText.qml | 2 +- src/UserSettingsPage.cpp | 21 +++++++++++++++++++++ src/UserSettingsPage.h | 6 ++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/resources/qml/MatrixText.qml b/resources/qml/MatrixText.qml index f1ccf561..a5781c73 100644 --- a/resources/qml/MatrixText.qml +++ b/resources/qml/MatrixText.qml @@ -6,7 +6,7 @@ TextEdit { textFormat: TextEdit.RichText readOnly: true wrapMode: Text.Wrap - selectByMouse: true + selectByMouse: !Settings.mobileMode color: colors.text onLinkActivated: { if (/^https:\/\/matrix.to\/#\/(@.*)$/.test(link)) { diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 5558b246..6fd31de3 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -75,6 +75,7 @@ UserSettings::load() decryptSidebar_ = settings.value("user/decrypt_sidebar", true).toBool(); shareKeysWithTrustedUsers_ = settings.value("user/share_keys_with_trusted_users", true).toBool(); + mobileMode_ = settings.value("user/mobile_mode", false).toBool(); emojiFont_ = settings.value("user/emoji_font_family", "default").toString(); baseFontSize_ = settings.value("user/font_size", QFont().pointSizeF()).toDouble(); presence_ = @@ -123,6 +124,16 @@ UserSettings::setStartInTray(bool state) save(); } +void +UserSettings::setMobileMode(bool state) +{ + if (state == mobileMode_) + return; + mobileMode_ = state; + emit mobileModeChanged(state); + save(); +} + void UserSettings::setGroupView(bool state) { @@ -389,6 +400,7 @@ UserSettings::save() settings.setValue("avatar_circles", avatarCircles_); settings.setValue("decrypt_sidebar", decryptSidebar_); settings.setValue("share_keys_with_trusted_users", shareKeysWithTrustedUsers_); + settings.setValue("mobile_mode", mobileMode_); settings.setValue("font_size", baseFontSize_); settings.setValue("typing_notifications", typingNotifications_); settings.setValue("minor_events", sortByImportance_); @@ -470,6 +482,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge desktopNotifications_ = new Toggle{this}; alertOnNotification_ = new Toggle{this}; useStunServer_ = new Toggle{this}; + mobileMode_ = new Toggle{this}; scaleFactorCombo_ = new QComboBox{this}; fontSizeCombo_ = new QComboBox{this}; fontSelectionCombo_ = new QFontComboBox{this}; @@ -637,6 +650,9 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge formLayout_->addRow(uiLabel_); formLayout_->addRow(new HorizontalLine{this}); + boxWrap(tr("Mobile mode"), + mobileMode_, + tr("Will prevent text selection in the timeline to make scrolling easier.")); #if !defined(Q_OS_MAC) boxWrap(tr("Scale factor"), scaleFactorCombo_, @@ -728,6 +744,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setStartInTray(!disabled); }); + connect(mobileMode_, &Toggle::toggled, this, [this](bool disabled) { + settings_->setMobileMode(!disabled); + }); + connect(groupViewToggle_, &Toggle::toggled, this, [this](bool disabled) { settings_->setGroupView(!disabled); }); @@ -820,6 +840,7 @@ UserSettingsPage::showEvent(QShowEvent *) typingNotifications_->setState(!settings_->typingNotifications()); sortByImportance_->setState(!settings_->sortByImportance()); timelineButtonsToggle_->setState(!settings_->buttonsInTimeline()); + mobileMode_->setState(!settings_->mobileMode()); readReceipts_->setState(!settings_->readReceipts()); markdown_->setState(!settings_->markdown()); desktopNotifications_->setState(!settings_->hasDesktopNotifications()); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index 37355602..ffe98542 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -67,6 +67,7 @@ class UserSettings : public QObject decryptSidebarChanged) Q_PROPERTY(int timelineMaxWidth READ timelineMaxWidth WRITE setTimelineMaxWidth NOTIFY timelineMaxWidthChanged) + Q_PROPERTY(bool mobileMode READ mobileMode WRITE setMobileMode NOTIFY mobileModeChanged) Q_PROPERTY(double fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(QString font READ font WRITE setFontFamily NOTIFY fontChanged) Q_PROPERTY( @@ -99,6 +100,7 @@ public: void setEnlargeEmojiOnlyMessages(bool state); void setTray(bool state); void setStartInTray(bool state); + void setMobileMode(bool mode); void setFontSize(double size); void setFontFamily(QString family); void setEmojiFontFamily(QString family); @@ -130,6 +132,7 @@ public: bool typingNotifications() const { return typingNotifications_; } bool sortByImportance() const { return sortByImportance_; } bool buttonsInTimeline() const { return buttonsInTimeline_; } + bool mobileMode() const { return mobileMode_; } bool readReceipts() const { return readReceipts_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; } bool hasAlertOnNotification() const { return hasAlertOnNotification_; } @@ -163,6 +166,7 @@ signals: void avatarCirclesChanged(bool state); void decryptSidebarChanged(bool state); void timelineMaxWidthChanged(int state); + void mobileModeChanged(bool mode); void fontSizeChanged(double state); void fontChanged(QString state); void emojiFontChanged(QString state); @@ -193,6 +197,7 @@ private: bool avatarCircles_; bool decryptSidebar_; bool shareKeysWithTrustedUsers_; + bool mobileMode_; int timelineMaxWidth_; double baseFontSize_; QString font_; @@ -256,6 +261,7 @@ private: Toggle *useStunServer_; Toggle *decryptSidebar_; Toggle *shareKeysWithTrustedUsers_; + Toggle *mobileMode_; QLabel *deviceFingerprintValue_; QLabel *deviceIdValue_;