diff options
Diffstat (limited to 'src/gui/kernel/qwindow.cpp')
-rw-r--r-- | src/gui/kernel/qwindow.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index dad1b6ba2d..c099ec9692 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1051,6 +1051,71 @@ void QWindow::lower() } /*! + \brief Start a system-specific resize operation + \since 5.15 + + Calling this will start an interactive resize operation on the window by platforms + that support it. The actual behavior may vary depending on the platform. Usually, + it will make the window resize so that its edge follows the mouse cursor. + + On platforms that support it, this method of resizing windows is preferred over + \c setGeometry, because it allows a more native look-and-feel of resizing windows, e.g. + letting the window manager snap this window against other windows, or special resizing + behavior with animations when dragged to the edge of the screen. + + \a edges should either be a single edge, or two adjacent edges (a corner). Other values + are not allowed. + + Returns true if the operation was supported by the system. +*/ +bool QWindow::startSystemResize(Qt::Edges edges) +{ + Q_D(QWindow); + if (Q_UNLIKELY(!isVisible() || !d->platformWindow || d->maximumSize == d->minimumSize)) + return false; + + const bool isSingleEdge = edges == Qt::TopEdge || edges == Qt::RightEdge || edges == Qt::BottomEdge || edges == Qt::LeftEdge; + const bool isCorner = + edges == (Qt::TopEdge | Qt::LeftEdge) || + edges == (Qt::TopEdge | Qt::RightEdge) || + edges == (Qt::BottomEdge | Qt::RightEdge) || + edges == (Qt::BottomEdge | Qt::LeftEdge); + + if (Q_UNLIKELY(!isSingleEdge && !isCorner)) { + qWarning() << "Invalid edges" << edges << "passed to QWindow::startSystemResize, ignoring."; + return false; + } + + return d->platformWindow->startSystemResize(edges); +} + +/*! + \brief Start a system-specific move operation + \since 5.15 + + Calling this will start an interactive move operation on the window by platforms + that support it. The actual behavior may vary depending on the platform. Usually, + it will make the window follow the mouse cursor until a mouse button is released. + + On platforms that support it, this method of moving windows is preferred over + \c setPosition, because it allows a more native look-and-feel of moving windows, e.g. + letting the window manager snap this window against other windows, or special tiling + or resizing behavior with animations when dragged to the edge of the screen. + Furthermore, on some platforms such as Wayland, \c setPosition is not supported, so + this is the only way the application can influence its position. + + Returns true if the operation was supported by the system. +*/ +bool QWindow::startSystemMove() +{ + Q_D(QWindow); + if (Q_UNLIKELY(!isVisible() || !d->platformWindow)) + return false; + + return d->platformWindow->startSystemMove(); +} + +/*! \property QWindow::opacity \brief The opacity of the window in the windowing system. \since 5.1 @@ -1793,7 +1858,10 @@ void QWindow::setFramePosition(const QPoint &point) The position is in relation to the virtualGeometry() of its screen. - \sa position() + For interactively moving windows, see startSystemMove(). For interactively + resizing windows, see startSystemResize(). + + \sa position(), startSystemMove() */ void QWindow::setPosition(const QPoint &pt) { @@ -1830,6 +1898,8 @@ void QWindow::setPosition(int posx, int posy) set the size of the window, excluding any window frame, to a QSize constructed from width \a w and height \a h + For interactively resizing windows, see startSystemResize(). + \sa size(), geometry() */ void QWindow::resize(int w, int h) |