Skip to content

Commit e931b85

Browse files
committed
core/window: add min/max size to FloatingWindow
1 parent 05ed9ff commit e931b85

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/window/floatingwindow.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
#include <qqmlengine.h>
55
#include <qqmllist.h>
66
#include <qquickitem.h>
7+
#include <qtmetamacros.h>
78
#include <qtypes.h>
89

910
#include "proxywindow.hpp"
1011
#include "windowinterface.hpp"
1112

13+
void ProxyFloatingWindow::connectWindow() {
14+
this->ProxyWindowBase::connectWindow();
15+
16+
this->window->setMinimumSize(this->bMinimumSize);
17+
this->window->setMaximumSize(this->bMaximumSize);
18+
}
19+
1220
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
1321
if (!this->window->isVisible()) {
1422
this->ProxyWindowBase::trySetWidth(implicitWidth);
@@ -21,6 +29,16 @@ void ProxyFloatingWindow::trySetHeight(qint32 implicitHeight) {
2129
}
2230
}
2331

32+
void ProxyFloatingWindow::onMinimumSizeChanged() {
33+
if (this->window) this->window->setMinimumSize(this->bMinimumSize);
34+
emit this->minimumSizeChanged();
35+
}
36+
37+
void ProxyFloatingWindow::onMaximumSizeChanged() {
38+
if (this->window) this->window->setMaximumSize(this->bMaximumSize);
39+
emit this->maximumSizeChanged();
40+
}
41+
2442
// FloatingWindowInterface
2543

2644
FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
@@ -40,6 +58,9 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
4058
QObject::connect(this->window, &ProxyWindowBase::colorChanged, this, &FloatingWindowInterface::colorChanged);
4159
QObject::connect(this->window, &ProxyWindowBase::maskChanged, this, &FloatingWindowInterface::maskChanged);
4260
QObject::connect(this->window, &ProxyWindowBase::surfaceFormatChanged, this, &FloatingWindowInterface::surfaceFormatChanged);
61+
62+
QObject::connect(this->window, &ProxyFloatingWindow::minimumSizeChanged, this, &FloatingWindowInterface::minimumSizeChanged);
63+
QObject::connect(this->window, &ProxyFloatingWindow::maximumSizeChanged, this, &FloatingWindowInterface::maximumSizeChanged);
4364
// clang-format on
4465
}
4566

src/window/floatingwindow.hpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
#include <qobject.h>
4+
#include <qproperty.h>
5+
#include <qsize.h>
46
#include <qtmetamacros.h>
57

68
#include "proxywindow.hpp"
@@ -12,15 +14,46 @@ class ProxyFloatingWindow: public ProxyWindowBase {
1214
public:
1315
explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
1416

17+
void connectWindow() override;
18+
1519
// Setting geometry while the window is visible makes the content item shrink but not the window
1620
// which is awful so we disable it for floating windows.
1721
void trySetWidth(qint32 implicitWidth) override;
1822
void trySetHeight(qint32 implicitHeight) override;
23+
24+
signals:
25+
void minimumSizeChanged();
26+
void maximumSizeChanged();
27+
28+
private:
29+
void onMinimumSizeChanged();
30+
void onMaximumSizeChanged();
31+
32+
public:
33+
Q_OBJECT_BINDABLE_PROPERTY(
34+
ProxyFloatingWindow,
35+
QSize,
36+
bMinimumSize,
37+
&ProxyFloatingWindow::onMinimumSizeChanged
38+
);
39+
40+
Q_OBJECT_BINDABLE_PROPERTY(
41+
ProxyFloatingWindow,
42+
QSize,
43+
bMaximumSize,
44+
&ProxyFloatingWindow::onMaximumSizeChanged
45+
);
1946
};
2047

2148
///! Standard toplevel operating system window that looks like any other application.
2249
class FloatingWindowInterface: public WindowInterface {
2350
Q_OBJECT;
51+
// clang-format off
52+
/// Minimum window size given to the window system.
53+
Q_PROPERTY(QSize minimumSize READ default WRITE default NOTIFY minimumSizeChanged BINDABLE bindableMinimumSize);
54+
/// Maximum window size given to the window system.
55+
Q_PROPERTY(QSize maximumSize READ default WRITE default NOTIFY maximumSizeChanged BINDABLE bindableMaximumSize);
56+
// clang-format on
2457
QML_NAMED_ELEMENT(FloatingWindow);
2558

2659
public:
@@ -65,6 +98,13 @@ class FloatingWindowInterface: public WindowInterface {
6598
[[nodiscard]] QQmlListProperty<QObject> data() override;
6699
// NOLINTEND
67100

101+
QBindable<QSize> bindableMinimumSize() { return &this->window->bMinimumSize; }
102+
QBindable<QSize> bindableMaximumSize() { return &this->window->bMaximumSize; }
103+
104+
signals:
105+
void minimumSizeChanged();
106+
void maximumSizeChanged();
107+
68108
private:
69109
ProxyFloatingWindow* window;
70110
};

0 commit comments

Comments
 (0)