Make group's sidebar visible through an option

This commit is contained in:
Konstantinos Sideris 2018-01-09 21:57:41 +02:00
parent 3d321622bb
commit 53f670096c
4 changed files with 67 additions and 6 deletions

View file

@ -119,6 +119,8 @@ private:
void loadStateFromCache(); void loadStateFromCache();
void deleteConfigs(); void deleteConfigs();
void resetUI(); void resetUI();
//! Decides whether or not to hide the group's sidebar.
void setGroupViewState(bool isEnabled);
template<class Collection> template<class Collection>
Memberships getMemberships(const std::vector<Collection> &events) const; Memberships getMemberships(const std::vector<Collection> &events) const;

View file

@ -29,8 +29,10 @@ constexpr int OptionMargin = 6;
constexpr int LayoutTopMargin = 50; constexpr int LayoutTopMargin = 50;
constexpr int LayoutBottomMargin = LayoutTopMargin; constexpr int LayoutBottomMargin = LayoutTopMargin;
class UserSettings class UserSettings : public QObject
{ {
Q_OBJECT
public: public:
UserSettings(); UserSettings();
@ -50,14 +52,28 @@ public:
save(); save();
}; };
void setGroupView(bool state)
{
if (isGroupViewEnabled_ != state)
emit groupViewStateChanged(state);
isGroupViewEnabled_ = state;
save();
};
QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; } QString theme() const { return !theme_.isEmpty() ? theme_ : "light"; }
bool isTrayEnabled() const { return isTrayEnabled_; } bool isTrayEnabled() const { return isTrayEnabled_; }
bool isOrderingEnabled() const { return isOrderingEnabled_; } bool isOrderingEnabled() const { return isOrderingEnabled_; }
bool isGroupViewEnabled() const { return isGroupViewEnabled_; }
signals:
void groupViewStateChanged(bool state);
private: private:
QString theme_; QString theme_;
bool isTrayEnabled_; bool isTrayEnabled_;
bool isOrderingEnabled_; bool isOrderingEnabled_;
bool isGroupViewEnabled_;
}; };
class HorizontalLine : public QFrame class HorizontalLine : public QFrame
@ -97,6 +113,7 @@ private:
Toggle *trayToggle_; Toggle *trayToggle_;
Toggle *roomOrderToggle_; Toggle *roomOrderToggle_;
Toggle *groupViewToggle_;
QComboBox *themeCombo_; QComboBox *themeCombo_;

View file

@ -369,6 +369,13 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
} }
}); });
setGroupViewState(userSettings_->isGroupViewEnabled());
connect(userSettings_.data(),
&UserSettings::groupViewStateChanged,
this,
&ChatPage::setGroupViewState);
AvatarProvider::init(client); AvatarProvider::init(client);
instance_ = this; instance_ = this;
@ -919,4 +926,17 @@ ChatPage::showReadReceipts(const QString &event_id)
receiptsModal_->fadeIn(); receiptsModal_->fadeIn();
} }
void
ChatPage::setGroupViewState(bool isEnabled)
{
if (!isEnabled) {
communitiesList_->communityChanged("world");
communitiesSideBar_->hide();
return;
}
communitiesSideBar_->show();
}
ChatPage::~ChatPage() {} ChatPage::~ChatPage() {}

View file

@ -33,9 +33,10 @@ void
UserSettings::load() UserSettings::load()
{ {
QSettings settings; QSettings settings;
isTrayEnabled_ = settings.value("user/window/tray", true).toBool(); isTrayEnabled_ = settings.value("user/window/tray", true).toBool();
isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool(); isOrderingEnabled_ = settings.value("user/room_ordering", true).toBool();
theme_ = settings.value("user/theme", "light").toString(); isGroupViewEnabled_ = settings.value("user/group_view", true).toBool();
theme_ = settings.value("user/theme", "light").toString();
applyTheme(); applyTheme();
} }
@ -82,6 +83,7 @@ UserSettings::save()
settings.endGroup(); settings.endGroup();
settings.setValue("room_ordering", isOrderingEnabled_); settings.setValue("room_ordering", isOrderingEnabled_);
settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("theme", theme()); settings.setValue("theme", theme());
settings.endGroup(); settings.endGroup();
} }
@ -139,6 +141,17 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
orderRoomLayout->addWidget(orderLabel); orderRoomLayout->addWidget(orderLabel);
orderRoomLayout->addWidget(roomOrderToggle_, 0, Qt::AlignBottom | Qt::AlignRight); 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; auto themeOptionLayout_ = new QHBoxLayout;
themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin); themeOptionLayout_->setContentsMargins(0, OptionMargin, 0, OptionMargin);
auto themeLabel_ = new QLabel(tr("App theme"), this); auto themeLabel_ = new QLabel(tr("App theme"), this);
@ -164,6 +177,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(orderRoomLayout); mainLayout_->addLayout(orderRoomLayout);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(groupViewLayout);
mainLayout_->addWidget(new HorizontalLine(this));
mainLayout_->addLayout(themeOptionLayout_); mainLayout_->addLayout(themeOptionLayout_);
mainLayout_->addWidget(new HorizontalLine(this)); mainLayout_->addWidget(new HorizontalLine(this));
@ -184,6 +199,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setRoomOrdering(!isDisabled); settings_->setRoomOrdering(!isDisabled);
}); });
connect(groupViewToggle_, &Toggle::toggled, this, [=](bool isDisabled) {
settings_->setGroupView(!isDisabled);
});
connect(backBtn_, &QPushButton::clicked, this, [=]() { connect(backBtn_, &QPushButton::clicked, this, [=]() {
settings_->save(); settings_->save();
emit moveBack(); emit moveBack();
@ -194,8 +213,11 @@ void
UserSettingsPage::showEvent(QShowEvent *) UserSettingsPage::showEvent(QShowEvent *)
{ {
restoreThemeCombo(); 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 void