Skip to content

Commit

Permalink
Add compact mode option to settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKotato committed Dec 20, 2019
1 parent 8a3dc4d commit 753faf3
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 32 deletions.
2 changes: 2 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion Telegram/Resources/langs/rewrites/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "Компактный список чатов"
}
6 changes: 3 additions & 3 deletions Telegram/SourceFiles/core/kotato_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 9 additions & 4 deletions Telegram/SourceFiles/dialogs/dialogs_inner_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dialogs::IndexedList*> list) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions Telegram/SourceFiles/dialogs/dialogs_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -930,9 +930,9 @@ void RowPainter::paint(
active,
unreadMuted,
mentionMuted,
cDialogListLines());
DialogListLines());
};
if (cDialogListLines() == 1) {
if (DialogListLines() == 1) {
paintOneLineRow(
p,
row,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -1077,9 +1077,9 @@ void RowPainter::paint(
active,
unreadMuted,
mentionMuted,
cDialogListLines());
DialogListLines());
};
if (cDialogListLines() == 1) {
if (DialogListLines() == 1) {
paintOneLineRow(
p,
row,
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions Telegram/SourceFiles/dialogs/dialogs_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ 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);

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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SourceFiles/dialogs/dialogs_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}

Expand Down
11 changes: 10 additions & 1 deletion Telegram/SourceFiles/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,13 @@ void ClearCustomScales() {
gInterfaceScales.clear();
}

int gDialogListLines = 2;
rpl::variable<int> gDialogListLines = 2;
void SetDialogListLines(int lines) {
gDialogListLines = lines;
}
int DialogListLines() {
return gDialogListLines.current();
}
rpl::producer<int> DialogListLinesChanges() {
return gDialogListLines.changes();
}
5 changes: 4 additions & 1 deletion Telegram/SourceFiles/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> DialogListLinesChanges();
14 changes: 14 additions & 0 deletions Telegram/SourceFiles/settings/settings_kotato.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ void SetupKotatoChats(not_null<Ui::VerticalLayout*> 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(),
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/window/window_peer_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/window/window_session_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 753faf3

Please sign in to comment.