Improve window extension by third column.
This commit is contained in:
parent
cf977cb41a
commit
c872cd76e1
|
@ -78,6 +78,7 @@ QByteArray AuthSessionData::serialize() const {
|
||||||
0,
|
0,
|
||||||
1000000));
|
1000000));
|
||||||
stream << qint32(_variables.thirdColumnWidth.current());
|
stream << qint32(_variables.thirdColumnWidth.current());
|
||||||
|
stream << qint32(_variables.thirdSectionExtendedBy);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -101,6 +102,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
|
||||||
qint32 smallDialogsList = 0;
|
qint32 smallDialogsList = 0;
|
||||||
float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current();
|
float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current();
|
||||||
int thirdColumnWidth = _variables.thirdColumnWidth.current();
|
int thirdColumnWidth = _variables.thirdColumnWidth.current();
|
||||||
|
int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy;
|
||||||
stream >> selectorTab;
|
stream >> selectorTab;
|
||||||
stream >> lastSeenWarningSeen;
|
stream >> lastSeenWarningSeen;
|
||||||
if (!stream.atEnd()) {
|
if (!stream.atEnd()) {
|
||||||
|
@ -145,6 +147,9 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
|
||||||
|
|
||||||
stream >> value;
|
stream >> value;
|
||||||
thirdColumnWidth = value;
|
thirdColumnWidth = value;
|
||||||
|
|
||||||
|
stream >> value;
|
||||||
|
thirdSectionExtendedBy = value;
|
||||||
}
|
}
|
||||||
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()"));
|
||||||
|
@ -179,6 +184,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
|
||||||
_variables.smallDialogsList = smallDialogsList;
|
_variables.smallDialogsList = smallDialogsList;
|
||||||
_variables.dialogsWidthRatio = dialogsWidthRatio;
|
_variables.dialogsWidthRatio = dialogsWidthRatio;
|
||||||
_variables.thirdColumnWidth = thirdColumnWidth;
|
_variables.thirdColumnWidth = thirdColumnWidth;
|
||||||
|
_variables.thirdSectionExtendedBy = thirdSectionExtendedBy;
|
||||||
if (_variables.thirdSectionInfoEnabled) {
|
if (_variables.thirdSectionInfoEnabled) {
|
||||||
_variables.tabbedSelectorSectionEnabled = false;
|
_variables.tabbedSelectorSectionEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,12 @@ public:
|
||||||
return _thirdSectionInfoEnabledValue.events_starting_with(
|
return _thirdSectionInfoEnabledValue.events_starting_with(
|
||||||
thirdSectionInfoEnabled());
|
thirdSectionInfoEnabled());
|
||||||
}
|
}
|
||||||
|
int thirdSectionExtendedBy() const {
|
||||||
|
return _variables.thirdSectionExtendedBy;
|
||||||
|
}
|
||||||
|
void setThirdSectionExtendedBy(int savedValue) {
|
||||||
|
_variables.thirdSectionExtendedBy = savedValue;
|
||||||
|
}
|
||||||
bool tabbedReplacedWithInfo() const {
|
bool tabbedReplacedWithInfo() const {
|
||||||
return _tabbedReplacedWithInfo;
|
return _tabbedReplacedWithInfo;
|
||||||
}
|
}
|
||||||
|
@ -342,6 +348,7 @@ private:
|
||||||
base::flat_set<PeerId> groupStickersSectionHidden;
|
base::flat_set<PeerId> groupStickersSectionHidden;
|
||||||
bool thirdSectionInfoEnabled = true; // per-window
|
bool thirdSectionInfoEnabled = true; // per-window
|
||||||
bool smallDialogsList = false; // per-window
|
bool smallDialogsList = false; // per-window
|
||||||
|
int thirdSectionExtendedBy = -1; // per-window
|
||||||
rpl::variable<float64> dialogsWidthRatio
|
rpl::variable<float64> dialogsWidthRatio
|
||||||
= kDefaultDialogsWidthRatio; // per-window
|
= kDefaultDialogsWidthRatio; // per-window
|
||||||
rpl::variable<int> thirdColumnWidth
|
rpl::variable<int> thirdColumnWidth
|
||||||
|
|
|
@ -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);
|
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 desktop = QDesktopWidget().availableGeometry(this);
|
||||||
auto newWidth = qMin(width() + addToWidth, desktop.width());
|
auto inner = geometry();
|
||||||
auto newLeft = qMin(x(), desktop.x() + desktop.width() - newWidth);
|
auto innerRight = (inner.x() + inner.width() + extendBy);
|
||||||
if (x() != newLeft || width() != newWidth) {
|
auto desktopRight = (desktop.x() + desktop.width());
|
||||||
setGeometry(newLeft, y(), newWidth, height());
|
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 {
|
} else {
|
||||||
updateControlsGeometry();
|
updateControlsGeometry();
|
||||||
}
|
}
|
||||||
|
return addToWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
|
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
|
||||||
|
|
|
@ -76,8 +76,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void showRightColumn(object_ptr<TWidget> widget);
|
void showRightColumn(object_ptr<TWidget> widget);
|
||||||
bool canExtendWidthBy(int addToWidth);
|
int maximalExtendBy() const;
|
||||||
void tryToExtendWidthBy(int addToWidth);
|
bool canExtendNoMove(int extendBy) const;
|
||||||
|
|
||||||
|
// Returns how much could the window get extended.
|
||||||
|
int tryToExtendWidthBy(int addToWidth);
|
||||||
|
|
||||||
virtual void updateTrayMenu(bool force = false) {
|
virtual void updateTrayMenu(bool force = false) {
|
||||||
}
|
}
|
||||||
|
@ -184,7 +187,7 @@ private:
|
||||||
base::Timer _inactivePressTimer;
|
base::Timer _inactivePressTimer;
|
||||||
|
|
||||||
base::Observable<void> _dragFinished;
|
base::Observable<void> _dragFinished;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Window
|
} // namespace Window
|
||||||
|
|
|
@ -167,12 +167,9 @@ Controller::ShrinkResult Controller::shrinkDialogsAndThirdColumns(
|
||||||
|
|
||||||
bool Controller::canShowThirdSection() const {
|
bool Controller::canShowThirdSection() const {
|
||||||
auto currentLayout = computeColumnLayout();
|
auto currentLayout = computeColumnLayout();
|
||||||
auto extendBy = minimalThreeColumnWidth()
|
auto minimalExtendBy = minimalThreeColumnWidth()
|
||||||
- currentLayout.bodyWidth;
|
- currentLayout.bodyWidth;
|
||||||
if (extendBy <= 0) {
|
return (minimalExtendBy <= window()->maximalExtendBy());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return window()->canExtendWidthBy(extendBy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Controller::canShowThirdSectionWithoutResize() const {
|
bool Controller::canShowThirdSectionWithoutResize() const {
|
||||||
|
@ -197,14 +194,35 @@ void Controller::resizeForThirdSection() {
|
||||||
Auth().data().setTabbedSelectorSectionEnabled(false);
|
Auth().data().setTabbedSelectorSectionEnabled(false);
|
||||||
Auth().data().setThirdSectionInfoEnabled(false);
|
Auth().data().setThirdSectionInfoEnabled(false);
|
||||||
|
|
||||||
auto extendBy = qMax(
|
auto wanted = countThirdColumnWidthFromRatio(layout.bodyWidth);
|
||||||
minimalThreeColumnWidth() - layout.bodyWidth,
|
auto minimal = st::columnMinimalWidthThird;
|
||||||
countThirdColumnWidthFromRatio(layout.bodyWidth));
|
auto extendBy = wanted;
|
||||||
auto newBodyWidth = layout.bodyWidth + extendBy;
|
auto extendedBy = [&] {
|
||||||
auto currentRatio = Auth().data().dialogsWidthRatio();
|
// Best - extend by third column without moving the window.
|
||||||
Auth().data().setDialogsWidthRatio(
|
// Next - extend by minimal third column without moving.
|
||||||
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
// Next - show third column inside the window without moving.
|
||||||
window()->tryToExtendWidthBy(extendBy);
|
// 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(
|
Auth().data().setTabbedSelectorSectionEnabled(
|
||||||
tabbedSelectorSectionEnabled);
|
tabbedSelectorSectionEnabled);
|
||||||
|
@ -218,11 +236,16 @@ void Controller::closeThirdSection() {
|
||||||
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
|
if (layout.windowLayout == Adaptive::WindowLayout::ThreeColumn) {
|
||||||
auto noResize = window()->isFullScreen()
|
auto noResize = window()->isFullScreen()
|
||||||
|| window()->isMaximized();
|
|| window()->isMaximized();
|
||||||
|
auto savedValue = Auth().data().thirdSectionExtendedBy();
|
||||||
|
auto extendedBy = (savedValue == -1)
|
||||||
|
? layout.thirdWidth
|
||||||
|
: savedValue;
|
||||||
auto newBodyWidth = noResize
|
auto newBodyWidth = noResize
|
||||||
? layout.bodyWidth
|
? layout.bodyWidth
|
||||||
: (layout.bodyWidth - layout.thirdWidth);
|
: (layout.bodyWidth - extendedBy);
|
||||||
auto currentRatio = Auth().data().dialogsWidthRatio();
|
auto currentRatio = Auth().data().dialogsWidthRatio();
|
||||||
Auth().data().setDialogsWidthRatio((currentRatio * layout.bodyWidth) / newBodyWidth);
|
Auth().data().setDialogsWidthRatio(
|
||||||
|
(currentRatio * layout.bodyWidth) / newBodyWidth);
|
||||||
newWindowSize = QSize(
|
newWindowSize = QSize(
|
||||||
window()->width() + (newBodyWidth - layout.bodyWidth),
|
window()->width() + (newBodyWidth - layout.bodyWidth),
|
||||||
window()->height());
|
window()->height());
|
||||||
|
|
Loading…
Reference in New Issue