Persist sidebar sizes

This commit is contained in:
Nicolas Werner 2021-06-12 14:07:32 +02:00
parent 1d80f5d0b4
commit 4985e1f536
No known key found for this signature in database
GPG Key ID: C8D75E610773F2D9
4 changed files with 62 additions and 6 deletions

View File

@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="user-friends" class="svg-inline--fa fa-user-friends fa-w-20" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M192 256c61.9 0 112-50.1 112-112S253.9 32 192 32 80 82.1 80 144s50.1 112 112 112zm76.8 32h-8.3c-20.8 10-43.9 16-68.5 16s-47.6-6-68.5-16h-8.3C51.6 288 0 339.6 0 403.2V432c0 26.5 21.5 48 48 48h288c26.5 0 48-21.5 48-48v-28.8c0-63.6-51.6-115.2-115.2-115.2zM480 256c53 0 96-43 96-96s-43-96-96-96-96 43-96 96 43 96 96 96zm48 32h-3.8c-13.9 4.8-28.6 8-44.2 8s-30.3-3.2-44.2-8H432c-20.4 0-39.2 5.9-55.7 15.4 24.4 26.3 39.7 61.2 39.7 99.8v38.4c0 2.2-.5 4.3-.6 6.4H592c26.5 0 48-21.5 48-48 0-61.9-50.1-112-112-112z"></path></svg>

After

Width:  |  Height:  |  Size: 747 B

View File

@ -25,7 +25,7 @@ Rectangle {
minimumWidth: communitiesList.avatarSize * 4 + Nheko.paddingMedium * 2
collapsedWidth: communitiesList.avatarSize + 2 * Nheko.paddingMedium
preferredWidth: collapsedWidth
preferredWidth: Settings.communityListWidth >= minimumWidth ? Settings.communityListWidth : collapsedWidth
maximumWidth: communitiesList.avatarSize * 10 + 2 * Nheko.paddingMedium
CommunitiesList {
@ -34,14 +34,22 @@ Rectangle {
collapsed: parent.collapsed
}
Binding {
target: Settings
property: 'communityListWidth'
value: communityListC.preferredWidth
when: !adaptiveView.singlePageMode
delayed: true
}
}
AdaptiveLayoutElement {
id: roomListC
minimumWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
preferredWidth: Nheko.avatarSize * 5 + Nheko.paddingSmall * 2
maximumWidth: Nheko.avatarSize * 10 + Nheko.paddingSmall * 2
minimumWidth: roomlist.avatarSize * 4 + Nheko.paddingSmall * 2
preferredWidth: Settings.roomListWidth >= minimumWidth ? Settings.roomListWidth : roomlist.avatarSize * 5 + Nheko.paddingSmall * 2
maximumWidth: roomlist.avatarSize * 10 + Nheko.paddingSmall * 2
collapsedWidth: roomlist.avatarSize + 2 * Nheko.paddingMedium
RoomList {
@ -50,6 +58,14 @@ Rectangle {
collapsed: parent.collapsed
}
Binding {
target: Settings
property: 'roomListWidth'
value: roomListC.preferredWidth
when: !adaptiveView.singlePageMode
delayed: true
}
}
AdaptiveLayoutElement {

View File

@ -64,10 +64,14 @@ void
UserSettings::load(std::optional<QString> profile)
{
QSettings settings;
tray_ = settings.value("user/window/tray", false).toBool();
tray_ = settings.value("user/window/tray", false).toBool();
startInTray_ = settings.value("user/window/start_in_tray", false).toBool();
roomListWidth_ = settings.value("user/sidebar/room_list_width", -1).toInt();
communityListWidth_ = settings.value("user/sidebar/community_list_width", -1).toInt();
hasDesktopNotifications_ = settings.value("user/desktop_notifications", true).toBool();
hasAlertOnNotification_ = settings.value("user/alert_on_notification", false).toBool();
startInTray_ = settings.value("user/window/start_in_tray", false).toBool();
groupView_ = settings.value("user/group_view", true).toBool();
hiddenTags_ = settings.value("user/hidden_tags", QStringList{}).toStringList();
buttonsInTimeline_ = settings.value("user/timeline/buttons", true).toBool();
@ -248,6 +252,24 @@ UserSettings::setTimelineMaxWidth(int state)
emit timelineMaxWidthChanged(state);
save();
}
void
UserSettings::setCommunityListWidth(int state)
{
if (state == communityListWidth_)
return;
communityListWidth_ = state;
emit communityListWidthChanged(state);
save();
}
void
UserSettings::setRoomListWidth(int state)
{
if (state == roomListWidth_)
return;
roomListWidth_ = state;
emit roomListWidthChanged(state);
save();
}
void
UserSettings::setDesktopNotifications(bool state)
@ -571,6 +593,11 @@ UserSettings::save()
settings.setValue("start_in_tray", startInTray_);
settings.endGroup(); // window
settings.beginGroup("sidebar");
settings.setValue("community_list_width", communityListWidth_);
settings.setValue("room_list_width", roomListWidth_);
settings.endGroup(); // window
settings.beginGroup("timeline");
settings.setValue("buttons", buttonsInTimeline_);
settings.setValue("message_hover_highlight", messageHoverHighlight_);

View File

@ -61,6 +61,10 @@ class UserSettings : public QObject
NOTIFY privacyScreenTimeoutChanged)
Q_PROPERTY(int timelineMaxWidth READ timelineMaxWidth WRITE setTimelineMaxWidth NOTIFY
timelineMaxWidthChanged)
Q_PROPERTY(
int roomListWidth READ roomListWidth WRITE setRoomListWidth NOTIFY roomListWidthChanged)
Q_PROPERTY(int communityListWidth READ communityListWidth WRITE setCommunityListWidth NOTIFY
communityListWidthChanged)
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)
@ -129,6 +133,8 @@ public:
void setSortByImportance(bool state);
void setButtonsInTimeline(bool state);
void setTimelineMaxWidth(int state);
void setCommunityListWidth(int state);
void setRoomListWidth(int state);
void setDesktopNotifications(bool state);
void setAlertOnNotification(bool state);
void setAvatarCircles(bool state);
@ -178,6 +184,8 @@ public:
return hasDesktopNotifications() || hasAlertOnNotification();
}
int timelineMaxWidth() const { return timelineMaxWidth_; }
int communityListWidth() const { return communityListWidth_; }
int roomListWidth() const { return roomListWidth_; }
double fontSize() const { return baseFontSize_; }
QString font() const { return font_; }
QString emojiFont() const
@ -227,6 +235,8 @@ signals:
void privacyScreenChanged(bool state);
void privacyScreenTimeoutChanged(int state);
void timelineMaxWidthChanged(int state);
void roomListWidthChanged(int state);
void communityListWidthChanged(int state);
void mobileModeChanged(bool mode);
void fontSizeChanged(double state);
void fontChanged(QString state);
@ -276,6 +286,8 @@ private:
bool shareKeysWithTrustedUsers_;
bool mobileMode_;
int timelineMaxWidth_;
int roomListWidth_;
int communityListWidth_;
double baseFontSize_;
QString font_;
QString emojiFont_;