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 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;

View file

@ -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_;

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);
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() {}

View file

@ -35,6 +35,7 @@ UserSettings::load()
QSettings settings;
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