Allow small dialogs list with three columns.

This commit is contained in:
John Preston 2017-09-19 21:59:10 +03:00
parent 5c4daeee4c
commit c0e780a28f
8 changed files with 66 additions and 55 deletions

View File

@ -46,7 +46,7 @@ AuthSessionData::Variables::Variables()
} }
QByteArray AuthSessionData::serialize() const { QByteArray AuthSessionData::serialize() const {
auto size = sizeof(qint32) * 8; auto size = sizeof(qint32) * 10;
for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) { for (auto i = _variables.soundOverrides.cbegin(), e = _variables.soundOverrides.cend(); i != e; ++i) {
size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value()); size += Serialize::stringSize(i.key()) + Serialize::stringSize(i.value());
} }
@ -72,6 +72,7 @@ QByteArray AuthSessionData::serialize() const {
stream << quint64(peerId); stream << quint64(peerId);
} }
stream << qint32(_variables.thirdSectionInfoEnabled ? 1 : 0); stream << qint32(_variables.thirdSectionInfoEnabled ? 1 : 0);
stream << qint32(_variables.smallDialogsList ? 1 : 0);
} }
return result; return result;
} }
@ -92,6 +93,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
QMap<QString, QString> soundOverrides; QMap<QString, QString> soundOverrides;
base::flat_set<PeerId> groupStickersSectionHidden; base::flat_set<PeerId> groupStickersSectionHidden;
qint32 thirdSectionInfoEnabled = 0; qint32 thirdSectionInfoEnabled = 0;
qint32 smallDialogsList = 0;
stream >> selectorTab; stream >> selectorTab;
stream >> lastSeenWarningSeen; stream >> lastSeenWarningSeen;
if (!stream.atEnd()) { if (!stream.atEnd()) {
@ -127,6 +129,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
} }
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> thirdSectionInfoEnabled; stream >> thirdSectionInfoEnabled;
stream >> smallDialogsList;
} }
if (stream.status() != QDataStream::Ok) { if (stream.status() != QDataStream::Ok) {
LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()")); LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()"));
@ -158,6 +161,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
} }
_variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden); _variables.groupStickersSectionHidden = std::move(groupStickersSectionHidden);
_variables.thirdSectionInfoEnabled = thirdSectionInfoEnabled; _variables.thirdSectionInfoEnabled = thirdSectionInfoEnabled;
_variables.smallDialogsList = smallDialogsList;
} }
void AuthSessionData::setTabbedSelectorSectionEnabled(bool enabled) { void AuthSessionData::setTabbedSelectorSectionEnabled(bool enabled) {

View File

@ -110,6 +110,12 @@ public:
return _thirdSectionInfoEnabledValue.events_starting_with( return _thirdSectionInfoEnabledValue.events_starting_with(
thirdSectionInfoEnabled()); thirdSectionInfoEnabled());
} }
void setSmallDialogsList(bool enabled) {
_variables.smallDialogsList = enabled;
}
bool smallDialogsList() const {
return _variables.smallDialogsList;
}
void setLastTimeVideoPlayedAt(TimeMs time) { void setLastTimeVideoPlayedAt(TimeMs time) {
_lastTimeVideoPlayedAt = time; _lastTimeVideoPlayedAt = time;
} }
@ -164,6 +170,7 @@ private:
RectPart floatPlayerCorner; RectPart floatPlayerCorner;
base::flat_set<PeerId> groupStickersSectionHidden; base::flat_set<PeerId> groupStickersSectionHidden;
bool thirdSectionInfoEnabled = false; bool thirdSectionInfoEnabled = false;
bool smallDialogsList = false;
}; };
base::Variable<bool> _contactsLoaded = { false }; base::Variable<bool> _contactsLoaded = { false };

View File

@ -236,7 +236,6 @@ namespace Adaptive {
enum class WindowLayout { enum class WindowLayout {
OneColumn, OneColumn,
SmallColumn,
Normal, Normal,
ThreeColumn, ThreeColumn,
}; };
@ -417,10 +416,6 @@ inline bool OneColumn() {
return Global::AdaptiveWindowLayout() == WindowLayout::OneColumn; return Global::AdaptiveWindowLayout() == WindowLayout::OneColumn;
} }
inline bool SmallColumn() {
return Global::AdaptiveWindowLayout() == WindowLayout::SmallColumn;
}
inline bool Normal() { inline bool Normal() {
return Global::AdaptiveWindowLayout() == WindowLayout::Normal; return Global::AdaptiveWindowLayout() == WindowLayout::Normal;
} }

View File

@ -131,7 +131,7 @@ infoProfileSeparatorPadding: margins(
infoProfileSkip); infoProfileSkip);
infoIconFg: menuIconFg; infoIconFg: menuIconFg;
infoIconPosition: point(28px, 8px); infoIconPosition: point(28px, 4px);
infoIconInformation: icon {{ "info_information", infoIconFg }}; infoIconInformation: icon {{ "info_information", infoIconFg }};
infoIconMembers: icon {{ "info_members", infoIconFg }}; infoIconMembers: icon {{ "info_members", infoIconFg }};
infoIconNotifications: icon {{ "info_notifications", infoIconFg }}; infoIconNotifications: icon {{ "info_notifications", infoIconFg }};

View File

@ -395,9 +395,13 @@ void CoverLine::refreshStatusText() {
} }
void CoverLine::refreshNameGeometry(int newWidth) { void CoverLine::refreshNameGeometry(int newWidth) {
_name->resizeToWidth(newWidth auto nameWidth = newWidth
- st::infoProfileNameLeft - st::infoProfileNameLeft
- st::infoProfileNameRight); - st::infoProfileNameRight;
if (_toggle) {
nameWidth -= _toggle->width() + st::infoProfileToggleRight;
}
_name->resizeToWidth(nameWidth);
_name->moveToLeft( _name->moveToLeft(
st::infoProfileNameLeft, st::infoProfileNameLeft,
st::infoProfileNameTop, st::infoProfileNameTop,
@ -405,9 +409,13 @@ void CoverLine::refreshNameGeometry(int newWidth) {
} }
void CoverLine::refreshStatusGeometry(int newWidth) { void CoverLine::refreshStatusGeometry(int newWidth) {
_status->resizeToWidth(newWidth auto statusWidth = newWidth
- st::infoProfileStatusLeft - st::infoProfileStatusLeft
- st::infoProfileStatusRight); - st::infoProfileStatusRight;
if (_toggle) {
statusWidth -= _toggle->width() + st::infoProfileToggleRight;
}
_status->resizeToWidth(statusWidth);
_status->moveToLeft( _status->moveToLeft(
st::infoProfileStatusLeft, st::infoProfileStatusLeft,
st::infoProfileStatusTop, st::infoProfileStatusTop,

View File

@ -3410,7 +3410,7 @@ void MainWidget::resizeEvent(QResizeEvent *e) {
void MainWidget::updateControlsGeometry() { void MainWidget::updateControlsGeometry() {
updateWindowAdaptiveLayout(); updateWindowAdaptiveLayout();
if (!Adaptive::SmallColumn()) { if (_controller->dialogsWidthRatio().value() > 0) {
_a_dialogsWidth.finish(); _a_dialogsWidth.finish();
} }
if (!_a_dialogsWidth.animating()) { if (!_a_dialogsWidth.animating()) {
@ -3510,14 +3510,21 @@ void MainWidget::updateControlsGeometry() {
} }
void MainWidget::updateDialogsWidthAnimated() { void MainWidget::updateDialogsWidthAnimated() {
if (!Adaptive::SmallColumn()) { if (_controller->dialogsWidthRatio().value() > 0) {
return; return;
} }
auto dialogsWidth = _dialogsWidth; auto dialogsWidth = _dialogsWidth;
updateWindowAdaptiveLayout(); updateWindowAdaptiveLayout();
if (Adaptive::SmallColumn() && (_dialogsWidth != dialogsWidth || _a_dialogsWidth.animating())) { if (!_controller->dialogsWidthRatio().value()
&& (_dialogsWidth != dialogsWidth
|| _a_dialogsWidth.animating())) {
_dialogs->startWidthAnimation(); _dialogs->startWidthAnimation();
_a_dialogsWidth.start([this] { updateControlsGeometry(); }, dialogsWidth, _dialogsWidth, st::dialogsWidthDuration, anim::easeOutCirc); _a_dialogsWidth.start(
[this] { updateControlsGeometry(); },
dialogsWidth,
_dialogsWidth,
st::dialogsWidthDuration,
anim::easeOutCirc);
updateControlsGeometry(); updateControlsGeometry();
} }
} }
@ -3563,14 +3570,17 @@ bool MainWidget::eventFilter(QObject *o, QEvent *e) {
_resizingSideShift = mouseLeft() - (Adaptive::OneColumn() ? 0 : _dialogsWidth); _resizingSideShift = mouseLeft() - (Adaptive::OneColumn() ? 0 : _dialogsWidth);
} else if (e->type() == QEvent::MouseButtonRelease) { } else if (e->type() == QEvent::MouseButtonRelease) {
_resizingSide = false; _resizingSide = false;
if (!Adaptive::OneColumn()) { if (!Adaptive::OneColumn()
_controller->dialogsWidthRatio().set(float64(_dialogsWidth) / width(), true); && _controller->dialogsWidthRatio().value() > 0) {
_controller->dialogsWidthRatio().set(
float64(_dialogsWidth) / width(),
true);
} }
Local::writeUserSettings(); Local::writeUserSettings();
} else if (e->type() == QEvent::MouseMove && _resizingSide) { } else if (e->type() == QEvent::MouseMove && _resizingSide) {
auto newWidth = mouseLeft() - _resizingSideShift; auto newWidth = mouseLeft() - _resizingSideShift;
accumulate_max(newWidth, _controller->dialogsSmallColumnWidth()); auto newRatio = (newWidth < st::dialogsWidthMin / 2) ? 0. : float64(newWidth) / width();
_controller->dialogsWidthRatio().set(float64(newWidth) / width(), true); _controller->dialogsWidthRatio().set(newRatio, true);
} }
} else if (e->type() == QEvent::FocusIn) { } else if (e->type() == QEvent::FocusIn) {
if (auto widget = qobject_cast<QWidget*>(o)) { if (auto widget = qobject_cast<QWidget*>(o)) {
@ -3655,7 +3665,12 @@ void MainWidget::updateWindowAdaptiveLayout() {
_controller->dialogsWidthRatio().set(dialogsWidthRatio, true); _controller->dialogsWidthRatio().set(dialogsWidthRatio, true);
_dialogsWidth = layout.dialogsWidth; auto useSmallColumnWidth = !Adaptive::OneColumn()
&& !dialogsWidthRatio
&& !_controller->forceWideDialogs();
_dialogsWidth = useSmallColumnWidth
? _controller->dialogsSmallColumnWidth()
: layout.dialogsWidth;
if (layout.windowLayout != Global::AdaptiveWindowLayout()) { if (layout.windowLayout != Global::AdaptiveWindowLayout()) {
Global::SetAdaptiveWindowLayout(layout.windowLayout); Global::SetAdaptiveWindowLayout(layout.windowLayout);
Adaptive::Changed().notify(true); Adaptive::Changed().notify(true);

View File

@ -73,20 +73,22 @@ int Controller::minimalThreeColumnWidth() const {
+ st::columnMinimalWidthThird; + st::columnMinimalWidthThird;
} }
bool Controller::forceWideDialogs() const {
if (dialogsListDisplayForced().value()) {
return true;
} else if (dialogsListFocused().value()) {
return true;
}
return !App::main()->isMainSectionShown();
}
Controller::ColumnLayout Controller::computeColumnLayout() const { Controller::ColumnLayout Controller::computeColumnLayout() const {
auto layout = Adaptive::WindowLayout::OneColumn; auto layout = Adaptive::WindowLayout::OneColumn;
auto bodyWidth = window()->bodyWidget()->width(); auto bodyWidth = window()->bodyWidget()->width();
auto dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value()); auto dialogsWidth = 0, chatWidth = 0, thirdWidth = 0;
auto chatWidth = bodyWidth - dialogsWidth;
auto thirdWidth = 0;
accumulate_max(chatWidth, st::columnMinimalWidthMain);
dialogsWidth = bodyWidth - chatWidth;
auto useOneColumnLayout = [this, bodyWidth, dialogsWidth] { auto useOneColumnLayout = [this, bodyWidth] {
if (dialogsWidth < st::dialogsPadding.x() && Adaptive::OneColumn()) {
return true;
}
auto minimalNormal = st::columnMinimalWidthLeft auto minimalNormal = st::columnMinimalWidthLeft
+ st::columnMinimalWidthMain; + st::columnMinimalWidthMain;
if (bodyWidth < minimalNormal) { if (bodyWidth < minimalNormal) {
@ -95,14 +97,6 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
return false; return false;
}; };
auto useSmallColumnLayout = [this, dialogsWidth] {
// Used if useOneColumnLayout() == false.
if (dialogsWidth < st::dialogsWidthMin / 2) {
return true;
}
return false;
};
auto useNormalLayout = [this, bodyWidth] { auto useNormalLayout = [this, bodyWidth] {
// Used if useSmallColumnLayout() == false. // Used if useSmallColumnLayout() == false.
if (bodyWidth < minimalThreeColumnWidth()) { if (bodyWidth < minimalThreeColumnWidth()) {
@ -117,28 +111,15 @@ Controller::ColumnLayout Controller::computeColumnLayout() const {
if (useOneColumnLayout()) { if (useOneColumnLayout()) {
dialogsWidth = chatWidth = bodyWidth; dialogsWidth = chatWidth = bodyWidth;
} else if (useSmallColumnLayout()) {
layout = Adaptive::WindowLayout::SmallColumn;
auto forceWideDialogs = [this] {
if (dialogsListDisplayForced().value()) {
return true;
} else if (dialogsListFocused().value()) {
return true;
}
return !App::main()->isMainSectionShown();
};
if (forceWideDialogs()) {
dialogsWidth = st::dialogsWidthMin;
} else {
dialogsWidth = dialogsSmallColumnWidth();
}
chatWidth = bodyWidth - dialogsWidth;
} else if (useNormalLayout()) { } else if (useNormalLayout()) {
layout = Adaptive::WindowLayout::Normal; layout = Adaptive::WindowLayout::Normal;
dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value());
accumulate_max(dialogsWidth, st::columnMinimalWidthLeft); accumulate_max(dialogsWidth, st::columnMinimalWidthLeft);
accumulate_min(dialogsWidth, bodyWidth - st::columnMinimalWidthMain);
chatWidth = bodyWidth - dialogsWidth; chatWidth = bodyWidth - dialogsWidth;
} else { } else {
layout = Adaptive::WindowLayout::ThreeColumn; layout = Adaptive::WindowLayout::ThreeColumn;
dialogsWidth = qRound(bodyWidth * dialogsWidthRatio().value());
accumulate_max(dialogsWidth, st::columnMinimalWidthLeft); accumulate_max(dialogsWidth, st::columnMinimalWidthLeft);
thirdWidth = st::columnMinimalWidthThird; thirdWidth = st::columnMinimalWidthThird;
accumulate_min( accumulate_min(
@ -184,7 +165,7 @@ void Controller::resizeForThirdSection() {
auto extendBy = st::columnMinimalWidthThird; auto extendBy = st::columnMinimalWidthThird;
auto newBodyWidth = layout.bodyWidth + extendBy; auto newBodyWidth = layout.bodyWidth + extendBy;
dialogsWidthRatio().set( dialogsWidthRatio().set(
float64(layout.dialogsWidth) / newBodyWidth, (dialogsWidthRatio().value() * layout.bodyWidth) / newBodyWidth,
true); true);
window()->tryToExtendWidthBy(extendBy); window()->tryToExtendWidthBy(extendBy);
@ -204,7 +185,7 @@ void Controller::closeThirdSection() {
? layout.bodyWidth ? layout.bodyWidth
: (layout.bodyWidth - layout.thirdWidth); : (layout.bodyWidth - layout.thirdWidth);
dialogsWidthRatio().set( dialogsWidthRatio().set(
float64(layout.dialogsWidth) / newBodyWidth, (dialogsWidthRatio().value() * layout.bodyWidth) / newBodyWidth,
true); true);
newWindowSize = QSize( newWindowSize = QSize(
window()->width() + (newBodyWidth - layout.bodyWidth), window()->width() + (newBodyWidth - layout.bodyWidth),

View File

@ -83,6 +83,7 @@ public:
}; };
ColumnLayout computeColumnLayout() const; ColumnLayout computeColumnLayout() const;
int dialogsSmallColumnWidth() const; int dialogsSmallColumnWidth() const;
bool forceWideDialogs() const;
void updateColumnLayout(); void updateColumnLayout();
bool canShowThirdSection() const; bool canShowThirdSection() const;
bool canShowThirdSectionWithoutResize() const; bool canShowThirdSectionWithoutResize() const;