Skip to content

Commit

Permalink
Switch layout to Normal in a wide enough window.
Browse files Browse the repository at this point in the history
A lot of people didn't know how to bring the dialogs column back
after it was gone in a wide single column MainWindow.

Now we switch to a two column layout if the window allows it,
preserving the emoji / stickers / GIFs section in case it is shown.
  • Loading branch information
john-preston committed May 13, 2017
1 parent 565b56f commit 8d02d81
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/historywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3735,8 +3735,12 @@ void HistoryWidget::updateTabbedSelectorSectionShown() {
orderWidgets();
}

int HistoryWidget::tabbedSelectorSectionWidth() const {
return st::emojiPanWidth;
}

int HistoryWidget::minimalWidthForTabbedSelectorSection() const {
return st::windowMinWidth + st::emojiPanWidth;
return st::windowMinWidth + tabbedSelectorSectionWidth();
}

void HistoryWidget::toggleTabbedSelectorMode() {
Expand Down
3 changes: 2 additions & 1 deletion Telegram/SourceFiles/historywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ class HistoryWidget : public TWidget, public RPCSender, private base::Subscriber
void unreadCountChanged(History *history);

QRect historyRect() const;
int tabbedSelectorSectionWidth() const;
int minimalWidthForTabbedSelectorSection() const;

void updateSendAction(History *history, SendAction::Type type, int32 progress = 0);
void cancelSendAction(History *history, SendAction::Type type);
Expand Down Expand Up @@ -480,7 +482,6 @@ private slots:
void toggleTabbedSelectorMode();
void updateTabbedSelectorSectionShown();
void recountChatWidth();
int minimalWidthForTabbedSelectorSection() const;
void setReportSpamStatus(DBIPeerReportSpamStatus status);

void animationCallback();
Expand Down
14 changes: 14 additions & 0 deletions Telegram/SourceFiles/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3160,6 +3160,7 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) {
Local::writeUserSettings();
} else if (e->type() == QEvent::MouseMove && _resizingSide) {
auto newWidth = mouseLeft() - _resizingSideShift;
accumulate_max(newWidth, _controller->dialogsSmallColumnWidth());
_controller->dialogsWidthRatio().set(float64(newWidth) / width(), true);
}
} else if (e->type() == QEvent::FocusIn) {
Expand Down Expand Up @@ -3191,6 +3192,19 @@ void MainWidget::handleAdaptiveLayoutUpdate() {

void MainWidget::updateWindowAdaptiveLayout() {
auto layout = _controller->computeColumnLayout();
if (layout.windowLayout == Adaptive::WindowLayout::OneColumn) {
auto chatWidth = layout.dialogsWidth;
if (AuthSession::Current().data().tabbedSelectorSectionEnabled()
&& chatWidth >= _history->minimalWidthForTabbedSelectorSection()) {
chatWidth -= _history->tabbedSelectorSectionWidth();
}
if (chatWidth >= st::dialogsWidthMin + st::windowMinWidth) {
// 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);
}
}
_dialogsWidth = layout.dialogsWidth;
if (layout.windowLayout != Global::AdaptiveWindowLayout()) {
Global::SetAdaptiveWindowLayout(layout.windowLayout);
Expand Down
6 changes: 5 additions & 1 deletion Telegram/SourceFiles/window/window_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ bool Controller::isGifPausedAtLeastFor(GifPauseReason reason) const {
return (static_cast<int>(_gifPauseReasons) >= 2 * static_cast<int>(reason)) || !window()->isActive();
}

int Controller::dialogsSmallColumnWidth() const {
return st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x();
}

Controller::ColumnLayout Controller::computeColumnLayout() {
auto layout = Adaptive::WindowLayout::OneColumn;

Expand Down Expand Up @@ -94,7 +98,7 @@ Controller::ColumnLayout Controller::computeColumnLayout() {
if (forceWideDialogs()) {
dialogsWidth = st::dialogsWidthMin;
} else {
dialogsWidth = st::dialogsPadding.x() + st::dialogsPhotoSize + st::dialogsPadding.x();
dialogsWidth = dialogsSmallColumnWidth();
}
} else {
layout = Adaptive::WindowLayout::Normal;
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/window_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Controller {
Adaptive::WindowLayout windowLayout;
};
ColumnLayout computeColumnLayout();
int dialogsSmallColumnWidth() const;
bool provideChatWidth(int requestedWidth);

base::Variable<float64> &dialogsWidthRatio() {
Expand Down

0 comments on commit 8d02d81

Please sign in to comment.