From 753faf3a41e19b09024757a6a412d8253b0ab376 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Wed, 13 Nov 2019 19:14:03 +0300 Subject: [PATCH] Add compact mode option to settings menu --- Telegram/Resources/langs/lang.strings | 2 ++ Telegram/Resources/langs/rewrites/ru.json | 3 ++- Telegram/SourceFiles/core/kotato_settings.cpp | 6 ++--- .../dialogs/dialogs_inner_widget.cpp | 13 ++++++---- .../SourceFiles/dialogs/dialogs_layout.cpp | 24 +++++++++---------- Telegram/SourceFiles/dialogs/dialogs_row.cpp | 12 +++++----- .../SourceFiles/dialogs/dialogs_widget.cpp | 4 ++-- Telegram/SourceFiles/settings.cpp | 11 ++++++++- Telegram/SourceFiles/settings.h | 5 +++- .../SourceFiles/settings/settings_kotato.cpp | 14 +++++++++++ .../SourceFiles/window/window_peer_menu.cpp | 2 +- .../window/window_session_controller.cpp | 2 +- 12 files changed, 66 insertions(+), 32 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index dafcb82dee..ff2b42142c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2325,4 +2325,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_user_status_unaccessible" = "account inaccessible"; +"ktg_settings_chat_list_compact" = "Compact chat list"; + // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index cb1cf53c19..11f871b8b4 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -80,5 +80,6 @@ "ktg_outdated_now": "Чтобы приложение Kotatogram могло получать обновления.", "ktg_mac_menu_show": "Показать Kotatogram", "ktg_manage_peer_subscribers": "Подписчики", - "ktg_user_status_unaccessible": "аккаунт недоступен" + "ktg_user_status_unaccessible": "аккаунт недоступен", + "ktg_settings_chat_list_compact": "Компактный список чатов" } diff --git a/Telegram/SourceFiles/core/kotato_settings.cpp b/Telegram/SourceFiles/core/kotato_settings.cpp index 680cd94ff5..a01dad7911 100644 --- a/Telegram/SourceFiles/core/kotato_settings.cpp +++ b/Telegram/SourceFiles/core/kotato_settings.cpp @@ -217,7 +217,7 @@ bool Manager::readCustomFile() { if (settingsChatListLinesIt != settings.constEnd()) { const auto settingsChatListLines = (*settingsChatListLinesIt).toInt(); if (settingsChatListLines >= 1 || settingsChatListLines <= 2) { - cSetDialogListLines(settingsChatListLines); + SetDialogListLines(settingsChatListLines); } } return true; @@ -254,7 +254,7 @@ void Manager::writeDefaultFile() { settings.insert(qsl("show_chat_id"), cShowChatId()); settings.insert(qsl("net_speed_boost"), QJsonValue(QJsonValue::Null)); settings.insert(qsl("show_phone_in_drawer"), cShowPhoneInDrawer()); - settings.insert(qsl("chat_list_lines"), cDialogListLines()); + settings.insert(qsl("chat_list_lines"), DialogListLines()); auto settingsScales = QJsonArray(); settings.insert(qsl("scales"), settingsScales); @@ -307,7 +307,7 @@ void Manager::writeCurrentSettings() { settings.insert(qsl("show_chat_id"), cShowChatId()); settings.insert(qsl("net_speed_boost"), cNetSpeedBoost()); settings.insert(qsl("show_phone_in_drawer"), cShowPhoneInDrawer()); - settings.insert(qsl("chat_list_lines"), cDialogListLines()); + settings.insert(qsl("chat_list_lines"), DialogListLines()); auto settingsScales = QJsonArray(); auto currentScales = cInterfaceScales(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp index 35a577dcc8..e24d891215 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp @@ -54,11 +54,11 @@ constexpr auto kHashtagResultsLimit = 5; constexpr auto kStartReorderThreshold = 30; inline int DialogsRowHeight() { - return (cDialogListLines() == 1 ? st::dialogsImportantBarHeight : st::dialogsRowHeight); + return (DialogListLines() == 1 ? st::dialogsImportantBarHeight : st::dialogsRowHeight); } inline int DialogsPhotoSize() { - return (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); + return (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); } int FixedOnTopDialogsCount(not_null list) { @@ -209,6 +209,11 @@ InnerWidget::InnerWidget( refresh(); }, lifetime()); + DialogListLinesChanges( + ) | rpl::start_with_next([=] { + refresh(); + }, lifetime()); + subscribe(Window::Theme::Background(), [=](const Window::Theme::BackgroundUpdate &data) { if (data.paletteChanged()) { Layout::clearUnreadBadgesCache(); @@ -295,7 +300,7 @@ void InnerWidget::refreshWithCollapsedRows(bool toTop) { ? (*list->begin())->folder() : nullptr; const auto inMainMenu = session().settings().archiveInMainMenu(); - if (archive && (session().settings().archiveCollapsed() || inMainMenu || cDialogListLines() == 1)) { + if (archive && (session().settings().archiveCollapsed() || inMainMenu || DialogListLines() == 1)) { if (_selected && _selected->folder() == archive) { _selected = nullptr; } @@ -2162,7 +2167,7 @@ bool InnerWidget::needCollapsedRowsRefresh() const { const auto collapsedHasArchive = !_collapsedRows.empty() && (_collapsedRows.back()->folder != nullptr); const auto archiveIsCollapsed = (archive != nullptr) - && (session().settings().archiveCollapsed() || cDialogListLines() == 1); + && (session().settings().archiveCollapsed() || DialogListLines() == 1); const auto archiveIsInMainMenu = (archive != nullptr) && session().settings().archiveInMainMenu(); return archiveIsInMainMenu diff --git a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp index 16133ce358..0f851172c7 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_layout.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_layout.cpp @@ -85,7 +85,7 @@ void PaintNarrowCounter( ? QString::number(unreadCount) : QString(); const auto allowDigits = displayMentionBadge ? 1 : 3; - auto unreadRight = st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); + auto unreadRight = st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); auto unreadTop = (lines == 1 ? st::dialogsPadding.y() : st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight); @@ -99,7 +99,7 @@ void PaintNarrowCounter( } if (displayMentionBadge) { auto counter = qsl("@"); - auto unreadRight = st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) - skipBeforeMention; + auto unreadRight = st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) - skipBeforeMention; auto unreadTop = (lines == 1 ? st::dialogsPadding.y() : st::dialogsPadding.y() + st::dialogsPhotoSize - st::dialogsUnreadHeight); @@ -831,7 +831,7 @@ void RowPainter::paint( ? history->hasUnreadMentions() : false; const auto displayUnreadCounter = [&] { - if (fullWidth < st::columnMinimalWidthLeft && cDialogListLines() == 1) { + if (fullWidth < st::columnMinimalWidthLeft && DialogListLines() == 1) { return false; } @@ -865,7 +865,7 @@ void RowPainter::paint( | (allowUserOnline ? Flag::AllowUserOnline : Flag(0)) | (peer && peer->isSelf() ? Flag::SavedMessages : Flag(0)); const auto paintItemCallback = [&](int nameleft, int namewidth) { - const auto texttop = (cDialogListLines() == 1 + const auto texttop = (DialogListLines() == 1 ? st::dialogsPadding.y() : st::dialogsPadding.y() + st::msgNameFont->height @@ -885,7 +885,7 @@ void RowPainter::paint( selected, unreadMuted, mentionMuted); - if (cDialogListLines() > 1 || flags & Flag::SearchResult) { + if (DialogListLines() > 1 || flags & Flag::SearchResult) { const auto &color = active ? st::dialogsTextFgServiceActive : (selected @@ -930,9 +930,9 @@ void RowPainter::paint( active, unreadMuted, mentionMuted, - cDialogListLines()); + DialogListLines()); }; - if (cDialogListLines() == 1) { + if (DialogListLines() == 1) { paintOneLineRow( p, row, @@ -1029,7 +1029,7 @@ void RowPainter::paint( | (showSavedMessages ? Flag::SavedMessages : Flag(0))/* // #feed | (row->searchInChat().feed() ? Flag::FeedSearchResult : Flag(0))*/; const auto paintItemCallback = [&](int nameleft, int namewidth) { - const auto texttop = (cDialogListLines() == 1 + const auto texttop = (DialogListLines() == 1 ? st::dialogsPadding.y() : st::dialogsPadding.y() + st::msgNameFont->height @@ -1049,7 +1049,7 @@ void RowPainter::paint( unreadMuted, mentionMuted); - if (cDialogListLines() > 1 || flags & Flag::SearchResult) { + if (DialogListLines() > 1 || flags & Flag::SearchResult) { const auto itemRect = QRect( nameleft, texttop, @@ -1077,9 +1077,9 @@ void RowPainter::paint( active, unreadMuted, mentionMuted, - cDialogListLines()); + DialogListLines()); }; - if (cDialogListLines() == 1) { + if (DialogListLines() == 1) { paintOneLineRow( p, row, @@ -1115,7 +1115,7 @@ void RowPainter::paint( } QRect RowPainter::sendActionAnimationRect(int animationWidth, int animationHeight, int fullWidth, bool textUpdated) { - auto nameleft = st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPhotoPadding; + auto nameleft = st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPhotoPadding; auto namewidth = fullWidth - nameleft - st::dialogsPadding.x(); auto texttop = st::dialogsPadding.y() + st::msgNameFont->height + st::dialogsSkip; return QRect(nameleft, texttop, textUpdated ? namewidth : animationWidth, animationHeight); diff --git a/Telegram/SourceFiles/dialogs/dialogs_row.cpp b/Telegram/SourceFiles/dialogs/dialogs_row.cpp index c25fcc67dc..6f152b9e29 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_row.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_row.cpp @@ -146,7 +146,7 @@ void BasicRow::PaintOnlineFrame( q, 0, 0, - (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize)); + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize)); PainterHighQualityEnabler hq(q); q.setCompositionMode(QPainter::CompositionMode_Source); @@ -154,7 +154,7 @@ void BasicRow::PaintOnlineFrame( const auto size = st::dialogsOnlineBadgeSize; const auto stroke = st::dialogsOnlineBadgeStroke; const auto skip = st::dialogsOnlineBadgeSkip; - const auto edge = st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); + const auto edge = st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize); const auto shrink = (size / 2) * (1. - data->online); auto pen = QPen(Qt::transparent); @@ -182,13 +182,13 @@ void BasicRow::paintUserpic( const auto online = _onlineUserpic ? _onlineUserpic->animation.value(_online ? 1. : 0.) : (_online ? 1. : 0.); - if (!allowOnline || cDialogListLines() == 1 || online == 0.) { + if (!allowOnline || DialogListLines() == 1 || online == 0.) { peer->paintUserpicLeft( p, st::dialogsPadding.x(), st::dialogsPadding.y(), fullWidth, - (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize)); + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize)); if (!allowOnline || !_online) { _onlineUserpic = nullptr; } @@ -197,8 +197,8 @@ void BasicRow::paintUserpic( ensureOnlineUserpic(); if (_onlineUserpic->frame.isNull()) { _onlineUserpic->frame = QImage( - (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) * cRetinaFactor(), - (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) * cRetinaFactor(), + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) * cRetinaFactor(), + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) * cRetinaFactor(), QImage::Format_ARGB32_Premultiplied); _onlineUserpic->frame.setDevicePixelRatio(cRetinaFactor()); } diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index f91996961e..38802a0b3b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -1446,7 +1446,7 @@ void Widget::updateControlsGeometry() { _forwardCancel->moveToLeft(0, filterAreaTop); filterAreaTop += st::dialogsForwardHeight; } - auto smallLayoutWidth = (st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPadding.x()); + auto smallLayoutWidth = (st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPadding.x()); auto smallLayoutRatio = (width() < st::columnMinimalWidthLeft) ? (st::columnMinimalWidthLeft - width()) / float64(st::columnMinimalWidthLeft - smallLayoutWidth) : 0.; auto filterLeft = st::dialogsFilterPadding.x() + _mainMenuToggle->width() + st::dialogsFilterPadding.x(); auto filterRight = (Global::LocalPasscode() ? (st::dialogsFilterPadding.x() + _lockUnlock->width()) : st::dialogsFilterSkip) + st::dialogsFilterPadding.x(); @@ -1668,7 +1668,7 @@ void Widget::onCancelSearchInChat() { void Widget::onDialogMoved(int movedFrom, int movedTo) { int32 st = _scroll->scrollTop(); if (st > movedTo && st < movedFrom) { - _scroll->scrollToY(st + (cDialogListLines() == 1 ? st::dialogsImportantBarHeight : st::dialogsRowHeight)); + _scroll->scrollToY(st + (DialogListLines() == 1 ? st::dialogsImportantBarHeight : st::dialogsRowHeight)); } } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index 666671020e..7d5ce13185 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -263,4 +263,13 @@ void ClearCustomScales() { gInterfaceScales.clear(); } -int gDialogListLines = 2; \ No newline at end of file +rpl::variable gDialogListLines = 2; +void SetDialogListLines(int lines) { + gDialogListLines = lines; +} +int DialogListLines() { + return gDialogListLines.current(); +} +rpl::producer DialogListLinesChanges() { + return gDialogListLines.changes(); +} diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index 4d6466a576..389724f7d8 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -226,4 +226,7 @@ DeclareRefSetting(ScaleVector, InterfaceScales); bool HasCustomScales(); bool AddCustomScale(int scale); void ClearCustomScales(); -DeclareSetting(int, DialogListLines); + +void SetDialogListLines(int lines); +[[nodiscard]] int DialogListLines(); +[[nodiscard]] rpl::producer DialogListLinesChanges(); \ No newline at end of file diff --git a/Telegram/SourceFiles/settings/settings_kotato.cpp b/Telegram/SourceFiles/settings/settings_kotato.cpp index f96bc4a19c..7ec6e77216 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.cpp +++ b/Telegram/SourceFiles/settings/settings_kotato.cpp @@ -110,6 +110,20 @@ void SetupKotatoChats(not_null container) { KotatoSettings::Write(); }, container->lifetime()); + AddButton( + container, + tr::ktg_settings_chat_list_compact(), + st::settingsButton + )->toggleOn( + rpl::single(DialogListLines() == 1) + )->toggledValue( + ) | rpl::filter([](bool enabled) { + return (enabled != (DialogListLines() == 1)); + }) | rpl::start_with_next([](bool enabled) { + SetDialogListLines(enabled ? 1 : 2); + KotatoSettings::Write(); + }, container->lifetime()); + AddButton( container, tr::ktg_settings_always_show_scheduled(), diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 6c62b05db3..93accb46ad 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -620,7 +620,7 @@ void FolderFiller::addTogglesForArchive() { return; } const auto controller = _controller; - if (cDialogListLines() != 1) { + if (DialogListLines() != 1) { const auto hidden = (controller->session().settings().archiveCollapsed()); const auto text = hidden ? tr::lng_context_archive_expand(tr::now) diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 8627fd2c64..f8a881d0cc 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -309,7 +309,7 @@ bool SessionController::isGifPausedAtLeastFor(GifPauseReason reason) const { } int SessionController::dialogsSmallColumnWidth() const { - return st::dialogsPadding.x() + (cDialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPadding.x(); + return st::dialogsPadding.x() + (DialogListLines() == 1 ? st::dialogsUnreadHeight : st::dialogsPhotoSize) + st::dialogsPadding.x(); } int SessionController::minimalThreeColumnWidth() const {