From 0339b1b54bd3c20804badb4a2b5b9f9fb3db06bb Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 17 May 2017 15:38:42 +0300 Subject: [PATCH] Shrink dialogs column when enabling emoji sidebar. Try to hold the ratio between the chat width and the dialogs list width when the emoji sidebar is created by shrinking the left column. --- .../history/history_service_layout.cpp | 6 +++- .../history/history_service_layout.h | 2 ++ Telegram/SourceFiles/historywidget.cpp | 10 +++++- Telegram/SourceFiles/historywidget.h | 1 + Telegram/SourceFiles/mainwidget.cpp | 31 +++++++++++++++++-- 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/history/history_service_layout.cpp b/Telegram/SourceFiles/history/history_service_layout.cpp index 47d6572ba..aa745aacd 100644 --- a/Telegram/SourceFiles/history/history_service_layout.cpp +++ b/Telegram/SourceFiles/history/history_service_layout.cpp @@ -167,7 +167,7 @@ void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, i int left = st::msgServiceMargin.left(); int maxwidth = w; if (Adaptive::ChatWide()) { - maxwidth = qMin(maxwidth, int32(st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left())); + maxwidth = qMin(maxwidth, WideChatWidth()); } w = maxwidth - st::msgServiceMargin.left() - st::msgServiceMargin.left(); @@ -182,6 +182,10 @@ void paintPreparedDate(Painter &p, const QString &dateText, int dateTextWidth, i } // namepsace +int WideChatWidth() { + return st::msgMaxWidth + 2 * st::msgPhotoSkip + 2 * st::msgMargin.left(); +} + void ServiceMessagePainter::paint(Painter &p, const HistoryService *message, const PaintContext &context, int height) { int left = 0, width = 0; message->countPositionAndSize(left, width); diff --git a/Telegram/SourceFiles/history/history_service_layout.h b/Telegram/SourceFiles/history/history_service_layout.h index 80d9dba14..95311b48d 100644 --- a/Telegram/SourceFiles/history/history_service_layout.h +++ b/Telegram/SourceFiles/history/history_service_layout.h @@ -22,6 +22,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org namespace HistoryLayout { +int WideChatWidth(); + struct PaintContext { PaintContext(TimeMs ms, const QRect &clip, TextSelection selection) : ms(ms) diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 77a746f9e..7f0010c7b 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -3779,8 +3779,16 @@ int HistoryWidget::minimalWidthForTabbedSelectorSection() const { return st::windowMinWidth + tabbedSelectorSectionWidth(); } +bool HistoryWidget::willSwitchToTabbedSelectorWithWidth(int newWidth) const { + if (!AuthSession::Current().data().tabbedSelectorSectionEnabled()) { + return false; + } else if (_tabbedSectionUsed) { + return false; + } + return (newWidth >= minimalWidthForTabbedSelectorSection()); +} + void HistoryWidget::toggleTabbedSelectorMode() { - auto sectionEnabled = AuthSession::Current().data().tabbedSelectorSectionEnabled(); if (_tabbedSection) { AuthSession::Current().data().setTabbedSelectorSectionEnabled(false); AuthSession::Current().saveDataDelayed(kSaveTabbedSelectorSectionTimeoutMs); diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index ef4b9df5e..395d78d2c 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -202,6 +202,7 @@ public: QRect historyRect() const; int tabbedSelectorSectionWidth() const; int minimalWidthForTabbedSelectorSection() const; + bool willSwitchToTabbedSelectorWithWidth(int newWidth) const; void updateSendAction(History *history, SendAction::Type type, int32 progress = 0); void cancelSendAction(History *history, SendAction::Type type); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 10045eee2..8dee7ed14 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -35,6 +35,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org #include "apiwrap.h" #include "dialogswidget.h" #include "historywidget.h" +#include "history/history_service_layout.h" #include "overviewwidget.h" #include "lang.h" #include "boxes/add_contact_box.h" @@ -3192,11 +3193,12 @@ void MainWidget::handleAdaptiveLayoutUpdate() { void MainWidget::updateWindowAdaptiveLayout() { auto layout = _controller->computeColumnLayout(); + auto dialogsWidthRatio = _controller->dialogsWidthRatio().value(); // Check if we are in a single-column layout in a wide enough window // for the normal layout. If so, switch to the normal layout. if (layout.windowLayout == Adaptive::WindowLayout::OneColumn) { - auto chatWidth = layout.dialogsWidth; + auto chatWidth = layout.chatWidth; if (AuthSession::Current().data().tabbedSelectorSectionEnabled() && chatWidth >= _history->minimalWidthForTabbedSelectorSection()) { chatWidth -= _history->tabbedSelectorSectionWidth(); @@ -3205,10 +3207,35 @@ void MainWidget::updateWindowAdaptiveLayout() { // Switch layout back to normal in a wide enough window. layout.windowLayout = Adaptive::WindowLayout::Normal; layout.dialogsWidth = st::dialogsWidthMin; - _controller->dialogsWidthRatio().set(float64(layout.dialogsWidth) / layout.bodyWidth, true); + layout.chatWidth = layout.bodyWidth - layout.dialogsWidth; + dialogsWidthRatio = float64(layout.dialogsWidth) / layout.bodyWidth; } } + // Check if we are going to create the third column and shrink the + // dialogs widget to provide a wide enough chat history column. + // Don't shrink the column on the first call, when window is inited. + if (layout.windowLayout == Adaptive::WindowLayout::Normal + && _controller->window()->positionInited()) { + auto chatWidth = layout.chatWidth; + if (_history->willSwitchToTabbedSelectorWithWidth(chatWidth)) { + auto thirdColumnWidth = _history->tabbedSelectorSectionWidth(); + auto twoColumnsWidth = (layout.bodyWidth - thirdColumnWidth); + auto sameRatioChatWidth = twoColumnsWidth - qRound(dialogsWidthRatio * twoColumnsWidth); + auto desiredChatWidth = qMax(sameRatioChatWidth, HistoryLayout::WideChatWidth()); + chatWidth -= thirdColumnWidth; + auto extendChatBy = desiredChatWidth - chatWidth; + accumulate_min(extendChatBy, layout.dialogsWidth - st::dialogsWidthMin); + if (extendChatBy > 0) { + layout.dialogsWidth -= extendChatBy; + layout.chatWidth += extendChatBy; + dialogsWidthRatio = float64(layout.dialogsWidth) / layout.bodyWidth; + } + } + } + + _controller->dialogsWidthRatio().set(dialogsWidthRatio, true); + _dialogsWidth = layout.dialogsWidth; if (layout.windowLayout != Global::AdaptiveWindowLayout()) { Global::SetAdaptiveWindowLayout(layout.windowLayout);