Improve window extension by third column.

This commit is contained in:
John Preston 2017-11-16 20:43:52 +04:00
parent cf977cb41a
commit c872cd76e1
5 changed files with 79 additions and 25 deletions

View File

@ -78,6 +78,7 @@ QByteArray AuthSessionData::serialize() const {
0,
1000000));
stream << qint32(_variables.thirdColumnWidth.current());
stream << qint32(_variables.thirdSectionExtendedBy);
}
return result;
}
@ -101,6 +102,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
qint32 smallDialogsList = 0;
float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current();
int thirdColumnWidth = _variables.thirdColumnWidth.current();
int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy;
stream >> selectorTab;
stream >> lastSeenWarningSeen;
if (!stream.atEnd()) {
@ -145,6 +147,9 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
stream >> value;
thirdColumnWidth = value;
stream >> value;
thirdSectionExtendedBy = value;
}
if (stream.status() != QDataStream::Ok) {
LOG(("App Error: Bad data for AuthSessionData::constructFromSerialized()"));
@ -179,6 +184,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
_variables.smallDialogsList = smallDialogsList;
_variables.dialogsWidthRatio = dialogsWidthRatio;
_variables.thirdColumnWidth = thirdColumnWidth;
_variables.thirdSectionExtendedBy = thirdSectionExtendedBy;
if (_variables.thirdSectionInfoEnabled) {
_variables.tabbedSelectorSectionEnabled = false;
}

View File

@ -170,6 +170,12 @@ public:
return _thirdSectionInfoEnabledValue.events_starting_with(
thirdSectionInfoEnabled());
}
int thirdSectionExtendedBy() const {
return _variables.thirdSectionExtendedBy;
}
void setThirdSectionExtendedBy(int savedValue) {
_variables.thirdSectionExtendedBy = savedValue;
}
bool tabbedReplacedWithInfo() const {
return _tabbedReplacedWithInfo;
}
@ -342,6 +348,7 @@ private:
base::flat_set<PeerId> groupStickersSectionHidden;
bool thirdSectionInfoEnabled = true; // per-window
bool smallDialogsList = false; // per-window
int thirdSectionExtendedBy = -1; // per-window
rpl::variable<float64> dialogsWidthRatio
= kDefaultDialogsWidthRatio; // per-window
rpl::variable<int> thirdColumnWidth

View File

@ -369,20 +369,35 @@ void MainWindow::showRightColumn(object_ptr<TWidget> widget) {
}
}
bool MainWindow::canExtendWidthBy(int addToWidth) {
int MainWindow::maximalExtendBy() const {
auto desktop = QDesktopWidget().availableGeometry(this);
return (width() + addToWidth) <= desktop.width();
return std::max(desktop.width() - geometry().width(), 0);
}
void MainWindow::tryToExtendWidthBy(int addToWidth) {
bool MainWindow::canExtendNoMove(int extendBy) const {
auto desktop = QDesktopWidget().availableGeometry(this);
auto newWidth = qMin(width() + addToWidth, desktop.width());
auto newLeft = qMin(x(), desktop.x() + desktop.width() - newWidth);
if (x() != newLeft || width() != newWidth) {
setGeometry(newLeft, y(), newWidth, height());
auto inner = geometry();
auto innerRight = (inner.x() + inner.width() + extendBy);
auto desktopRight = (desktop.x() + desktop.width());
return innerRight <= desktopRight;
}
int MainWindow::tryToExtendWidthBy(int addToWidth) {
auto desktop = QDesktopWidget().availableGeometry(this);
auto inner = geometry();
accumulate_min(
addToWidth,
std::max(desktop.width() - inner.width(), 0));
auto newWidth = inner.width() + addToWidth;
auto newLeft = std::min(
inner.x(),
desktop.x() + desktop.width() - newWidth);
if (inner.x() != newLeft || inner.width() != newWidth) {
setGeometry(newLeft, inner.y(), newWidth, inner.height());
} else {
updateControlsGeometry();
}
return addToWidth;
}
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {

View File

@ -76,8 +76,11 @@ public:
}
void showRightColumn(object_ptr<TWidget> widget);
bool canExtendWidthBy(int addToWidth);
void tryToExtendWidthBy(int addToWidth);
int maximalExtendBy() const;
bool canExtendNoMove(int extendBy) const;
// Returns how much could the window get extended.
int tryToExtendWidthBy(int addToWidth);
virtual void updateTrayMenu(bool force = false) {
}

View File

@ -167,12 +167,9 @@ Controller::ShrinkResult Controller::shrinkDialogsAndThirdColumns(
bool Controller::canShowThirdSection() const {
auto currentLayout = computeColumnLayout();
auto extendBy = minimalThreeColumnWidth()
auto minimalExtendBy = minimalThreeColumnWidth()
- currentLayout.bodyWidth;
if (extendBy <= 0) {
return true;
}
return window()->canExtendWidthBy(extendBy);
return (minimalExtendBy <= window()->maximalExtendBy());
}
bool Controller::canShowThirdSectionWithoutResize() const {
@ -197,14 +194,35 @@ void Controller::resizeForThirdSection() {
Auth().data().setTabbedSelectorSectionEnabled(false);
Auth().data().setThirdSectionInfoEnabled(false);
auto extendBy = qMax(
minimalThreeColumnWidth() - layout.bodyWidth,
countThirdColumnWidthFromRatio(layout.bodyWidth));
auto newBodyWidth = layout.bodyWidth + extendBy;
auto currentRatio = Auth().data().dialogsWidthRatio();
Auth().data().setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth);
window()->tryToExtendWidthBy(extendBy);
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
auto minimal = st::columnMinimalWidthThird;
auto extendBy = wanted;
auto extendedBy = [&] {
// Best - extend by third column without moving the window.
// Next - extend by minimal third column without moving.
// Next - show third column inside the window without moving.
// Last - extend with moving.
if (window()->canExtendNoMove(wanted)) {
return window()->tryToExtendWidthBy(wanted);
} else if (window()->canExtendNoMove(minimal)) {
extendBy = minimal;
return window()->tryToExtendWidthBy(minimal);
} else if (layout.bodyWidth >= minimalThreeColumnWidth()) {
return 0;
}
return window()->tryToExtendWidthBy(minimal);
}();
if (extendedBy) {
if (extendBy != Auth().data().thirdColumnWidth()) {
Auth().data().setThirdColumnWidth(extendBy);
}
auto newBodyWidth = layout.bodyWidth + extendedBy;
auto currentRatio = Auth().data().dialogsWidthRatio();
Auth().data().setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth);
}
auto savedValue = (extendedBy == extendBy) ? -1 : extendedBy;
Auth().data().setThirdSectionExtendedBy(savedValue);
Auth().data().setTabbedSelectorSectionEnabled(
tabbedSelectorSectionEnabled);
@ -218,11 +236,16 @@ void Controller::closeThirdSection() {
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
auto noResize = window()->isFullScreen()
|| window()->isMaximized();
auto savedValue = Auth().data().thirdSectionExtendedBy();
auto extendedBy = (savedValue == -1)
? layout.thirdWidth
: savedValue;
auto newBodyWidth = noResize
? layout.bodyWidth
: (layout.bodyWidth - layout.thirdWidth);
: (layout.bodyWidth - extendedBy);
auto currentRatio = Auth().data().dialogsWidthRatio();
Auth().data().setDialogsWidthRatio((currentRatio * layout.bodyWidth) / newBodyWidth);
Auth().data().setDialogsWidthRatio(
(currentRatio * layout.bodyWidth) / newBodyWidth);
newWindowSize = QSize(
window()->width() + (newBodyWidth - layout.bodyWidth),
window()->height());