summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qsizegrip.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qsizegrip.cpp')
-rw-r--r--src/widgets/widgets/qsizegrip.cpp109
1 files changed, 53 insertions, 56 deletions
diff --git a/src/widgets/widgets/qsizegrip.cpp b/src/widgets/widgets/qsizegrip.cpp
index 2a4b4a0ad4..2500983450 100644
--- a/src/widgets/widgets/qsizegrip.cpp
+++ b/src/widgets/widgets/qsizegrip.cpp
@@ -1,59 +1,25 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qsizegrip.h"
#include "qapplication.h"
#include "qevent.h"
-#include "qpainter.h"
+#include "qstylepainter.h"
#include "qwindow.h"
#include <qpa/qplatformwindow.h>
#include "qstyle.h"
#include "qstyleoption.h"
#include "qlayout.h"
#include "qdebug.h"
-#include <QDesktopWidget>
#include <private/qwidget_p.h>
-#include <private/qdesktopwidget_p.h>
+#include "private/qapplication_p.h"
+#include <qpa/qplatformtheme.h>
#include <QtWidgets/qabstractscrollarea.h>
+#include <QtCore/qpointer.h>
+
QT_BEGIN_NAMESPACE
static QWidget *qt_sizegrip_topLevelWidget(QWidget* w)
@@ -109,7 +75,7 @@ public:
void _q_showIfNotHidden()
{
Q_Q(QSizeGrip);
- bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
+ bool showSizeGrip = !isExplicitlyHidden();
updateTopLevelWidget();
if (tlw && showSizeGrip) {
Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
@@ -173,6 +139,10 @@ Qt::Corner QSizeGripPrivate::corner() const
On some platforms the size grip automatically hides itself when the
window is shown full screen or maximised.
+ \note On macOS, size grips are no longer part of the human interface
+ guideline, and won't show unless used in a QMdiSubWindow. Set another
+ style on size grips that you want to be visible in main windows.
+
\table 50%
\row \li \inlineimage fusion-statusbar-sizegrip.png Screenshot of a Fusion style size grip
\li A size grip widget at the bottom-right corner of a main window, shown in the
@@ -229,9 +199,8 @@ QSizeGrip::~QSizeGrip()
QSize QSizeGrip::sizeHint() const
{
QStyleOption opt(0);
- opt.init(this);
- return (style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this).
- expandedTo(QApplication::globalStrut()));
+ opt.initFrom(this);
+ return style()->sizeFromContents(QStyle::CT_SizeGrip, &opt, QSize(13, 13), this);
}
/*!
@@ -245,11 +214,11 @@ void QSizeGrip::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
Q_D(QSizeGrip);
- QPainter painter(this);
+ QStylePainter painter(this);
QStyleOptionSizeGrip opt;
- opt.init(this);
+ opt.initFrom(this);
opt.corner = d->m_corner;
- style()->drawControl(QStyle::CE_SizeGrip, &opt, &painter, this);
+ painter.drawControl(QStyle::CE_SizeGrip, opt);
}
/*!
@@ -260,6 +229,29 @@ void QSizeGrip::paintEvent(QPaintEvent *event)
parameter.
*/
+static Qt::Edges edgesFromCorner(Qt::Corner corner)
+{
+ switch (corner) {
+ case Qt::TopLeftCorner: return Qt::TopEdge | Qt::LeftEdge;
+ case Qt::TopRightCorner: return Qt::TopEdge | Qt::RightEdge;
+ case Qt::BottomLeftCorner: return Qt::BottomEdge | Qt::LeftEdge;
+ case Qt::BottomRightCorner: return Qt::BottomEdge | Qt::RightEdge;
+ }
+ return Qt::Edges{};
+}
+
+static bool usePlatformSizeGrip(const QWidget *tlw)
+{
+ const QString &platformName = QGuiApplication::platformName();
+ if (platformName.contains(u"xcb")) // ### FIXME QTBUG-69716
+ return false;
+ if (tlw->testAttribute(Qt::WA_TranslucentBackground)
+ && platformName == u"windows") {
+ return false; // QTBUG-90628, flicker when using translucency
+ }
+ return true;
+}
+
void QSizeGrip::mousePressEvent(QMouseEvent * e)
{
if (e->button() != Qt::LeftButton) {
@@ -269,7 +261,7 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e)
Q_D(QSizeGrip);
QWidget *tlw = qt_sizegrip_topLevelWidget(this);
- d->p = e->globalPos();
+ d->p = e->globalPosition().toPoint();
d->gotMousePress = true;
d->r = tlw->geometry();
@@ -279,10 +271,11 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e)
&& tlw->windowHandle()
&& !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
&& !tlw->testAttribute(Qt::WA_DontShowOnScreen)
- && !tlw->hasHeightForWidth()) {
+ && !tlw->hasHeightForWidth()
+ && usePlatformSizeGrip(tlw)) {
QPlatformWindow *platformWindow = tlw->windowHandle()->handle();
- const QPoint topLevelPos = mapTo(tlw, e->pos());
- d->m_platformSizeGrip = platformWindow && platformWindow->startSystemResize(topLevelPos, d->m_corner);
+ const Qt::Edges edges = edgesFromCorner(d->m_corner);
+ d->m_platformSizeGrip = platformWindow->startSystemResize(edges);
}
if (d->m_platformSizeGrip)
@@ -292,8 +285,12 @@ void QSizeGrip::mousePressEvent(QMouseEvent * e)
QRect availableGeometry;
bool hasVerticalSizeConstraint = true;
bool hasHorizontalSizeConstraint = true;
- if (tlw->isWindow())
- availableGeometry = QDesktopWidgetPrivate::availableGeometry(tlw);
+ if (tlw->isWindow()) {
+ if (QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::InteractiveResizeAcrossScreens).toBool())
+ availableGeometry = tlw->screen()->availableVirtualGeometry();
+ else
+ availableGeometry = QWidgetPrivate::availableScreenGeometry(tlw);
+ }
else {
const QWidget *tlwParent = tlw->parentWidget();
// Check if tlw is inside QAbstractScrollArea/QScrollArea.
@@ -362,7 +359,7 @@ void QSizeGrip::mouseMoveEvent(QMouseEvent * e)
if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))
return;
- QPoint np(e->globalPos());
+ QPoint np(e->globalPosition().toPoint());
// Don't extend beyond the available geometry; bound to dyMax and dxMax.
QSize ns;
@@ -454,7 +451,7 @@ void QSizeGrip::setVisible(bool visible)
bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
{
Q_D(QSizeGrip);
- if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
+ if (d->isExplicitlyHidden()
|| e->type() != QEvent::WindowStateChange
|| o != d->tlw) {
return QWidget::eventFilter(o, e);