diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-01-09 21:57:41 +0200 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-01-09 21:57:41 +0200 |
commit | 53f670096cb2865e16b626be7b2baa769c089715 (patch) | |
tree | 0573d8d2e56f3dec36b3f372027cdc2da86410c7 | |
parent | Add make install and make uninstall rules to cmake (#196) (diff) | |
download | nheko-53f670096cb2865e16b626be7b2baa769c089715.tar.xz |
Make group's sidebar visible through an option
-rw-r--r-- | include/ChatPage.h | 2 | ||||
-rw-r--r-- | include/UserSettingsPage.h | 19 | ||||
-rw-r--r-- | src/ChatPage.cc | 20 | ||||
-rw-r--r-- | src/UserSettingsPage.cc | 32 |
4 files changed, 67 insertions, 6 deletions
diff --git a/include/ChatPage.h b/include/ChatPage.h index 754ee0f4..01fb4c50 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -119,6 +119,8 @@ private: void loadStateFromCache(); void deleteConfigs(); void resetUI(); + //! Decides whether or not to hide the group's sidebar. + void setGroupViewState(bool isEnabled); template<class Collection> Memberships getMemberships(const std::vector<Collection> &events) const; diff --git a/include/UserSettingsPage.h b/include/UserSettingsPage.h index adaa3956..6c825a83 100644 --- a/include/UserSettingsPage.h +++ b/include/UserSettingsPage.h @@ -29,8 +29,10 @@ constexpr int OptionMargin = 6; constexpr int LayoutTopMargin = 50; constexpr int LayoutBottomMargin = LayoutTopMargin; -class UserSettings +class UserSettings : public QObject { + Q_OBJECT + public: UserSettings(); @@ -50,14 +52,28 @@ public: save(); }; + void setGroupView(bool state) + { + if (isGroupViewEnabled_ != state) + emit groupViewStateChanged(state); + + isGroupViewEnabled_ = state; + save(); + }; + QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } bool isTrayEnabled() const { return isTrayEnabled_; } bool isOrderingEnabled() const { return isOrderingEnabled_; } + bool isGroupViewEnabled() const { return isGroupViewEnabled_; } + +signals: + void groupViewStateChanged(bool state); private: QString theme_; bool isTrayEnabled_; bool isOrderingEnabled_; + bool isGroupViewEnabled_; }; class HorizontalLine : public QFrame @@ -97,6 +113,7 @@ private: Toggle *trayToggle_; Toggle *roomOrderToggle_; + Toggle *groupViewToggle_; QComboBox *themeCombo_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 3a78e1cc..ebdec835 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -369,6 +369,13 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, } }); + setGroupViewState(userSettings_->isGroupViewEnabled()); + + connect(userSettings_.data(), + &UserSettings::groupViewStateChanged, + this, + &ChatPage::setGroupViewState); + AvatarProvider::init(client); instance_ = this; @@ -919,4 +926,17 @@ ChatPage::showReadReceipts(const QString &event_id) receiptsModal_->fadeIn(); } +void +ChatPage::setGroupViewState(bool isEnabled) +{ + if (!isEnabled) { + communitiesList_->communityChanged("world"); + communitiesSideBar_->hide(); + + return; + } + + communitiesSideBar_->show(); +} + ChatPage::~ChatPage() {} diff --git a/src/UserSettingsPage.cc b/src/UserSettingsPage.cc index 82cf23a7..17668c3d 100644 --- a/src/UserSettingsPage.cc +++ b/src/UserSettingsPage.cc @@ -33,9 +33,10 @@ void UserSettings::load() { QSettings settings; - isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); - isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); - theme_ = settings.value("user/theme", "light").toString(); + isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); + isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); + isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); + theme_ = settings.value("user/theme", "light").toString(); applyTheme(); } @@ -82,6 +83,7 @@ UserSettings::save() settings.endGroup(); settings.setValue("room_ordering", isOrderingEnabled_); + settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("theme", theme()); settings.endGroup(); } @@ -139,6 +141,17 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge orderRoomLayout->addWidget(orderLabel); orderRoomLayout->addWidget(roomOrderToggle_, 0, Qt::AlignBottom | Qt::AlignRight); + auto groupViewLayout = new QHBoxLayout; + groupViewLayout->setContentsMargins(0, OptionMargin, 0, OptionMargin); + auto groupViewLabel = new QLabel(tr("Group's sidebar"), this); + groupViewToggle_ = new Toggle(this); + groupViewToggle_->setActiveColor(QColor("#38A3D8")); + groupViewToggle_->setInactiveColor(QColor("gray")); + groupViewLabel->setStyleSheet("font-size: 15px;"); + + groupViewLayout->addWidget(groupViewLabel); + groupViewLayout->addWidget(groupViewToggle_, 0, Qt::AlignBottom | Qt::AlignRight); + auto themeOptionLayout_ = new QHBoxLayout; themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); auto themeLabel_ = new QLabel(tr("App theme"), this); @@ -164,6 +177,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(orderRoomLayout); mainLayout_->addWidget(new HorizontalLine(this)); + mainLayout_->addLayout(groupViewLayout); + mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addLayout(themeOptionLayout_); mainLayout_->addWidget(new HorizontalLine(this)); @@ -184,6 +199,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge settings_->setRoomOrdering(!isDisabled); }); + connect(groupViewToggle_, &Toggle::toggled, this, [=](bool isDisabled) { + settings_->setGroupView(!isDisabled); + }); + connect(backBtn_, &QPushButton::clicked, this, [=]() { settings_->save(); emit moveBack(); @@ -194,8 +213,11 @@ void UserSettingsPage::showEvent(QShowEvent *) { restoreThemeCombo(); - trayToggle_->setState(!settings_->isTrayEnabled()); // Treats true as "off" - roomOrderToggle_->setState(!settings_->isOrderingEnabled()); // Treats true as "off" + + // FIXME: Toggle treats true as "off" + trayToggle_->setState(!settings_->isTrayEnabled()); + roomOrderToggle_->setState(!settings_->isOrderingEnabled()); + groupViewToggle_->setState(!settings_->isGroupViewEnabled()); } void |