mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Improve window extension by third column.
This commit is contained in:
@@ -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) {
|
||||
|
@@ -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) {
|
||||
}
|
||||
@@ -184,7 +187,7 @@ private:
|
||||
base::Timer _inactivePressTimer;
|
||||
|
||||
base::Observable<void> _dragFinished;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // namespace Window
|
||||
|
@@ -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());
|
||||
|
Reference in New Issue
Block a user