105 Q_Q(
const QSizeGrip);
106 QWidget *tlw = qt_sizegrip_topLevelWidget(
const_cast<QSizeGrip *>(q));
107 const QPoint sizeGripPos = q->mapTo(tlw, QPoint(0, 0));
108 bool isAtBottom = sizeGripPos.y() >= tlw->height() / 2;
109 bool isAtLeft = sizeGripPos.x() <= tlw->width() / 2;
111 return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner;
113 return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner;
212void QSizeGrip::paintEvent(QPaintEvent *event)
216 QStylePainter painter(
this);
217 QStyleOptionSizeGrip opt;
219 opt.corner = d->m_corner;
220 painter.drawControl(QStyle::CE_SizeGrip, opt);
254void QSizeGrip::mousePressEvent(QMouseEvent * e)
256 if (e->button() != Qt::LeftButton) {
257 QWidget::mousePressEvent(e);
262 QWidget *tlw = qt_sizegrip_topLevelWidget(
this);
263 d->p = e->globalPosition().toPoint();
264 d->gotMousePress =
true;
265 d->r = tlw->geometry();
268 d->m_platformSizeGrip =
false;
270 && tlw->windowHandle()
271 && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint)
272 && !tlw->testAttribute(Qt::WA_DontShowOnScreen)
273 && !tlw->hasHeightForWidth()
274 && usePlatformSizeGrip(tlw)) {
275 QPlatformWindow *platformWindow = tlw->windowHandle()->handle();
276 const Qt::Edges edges = edgesFromCorner(d->m_corner);
277 d->m_platformSizeGrip = platformWindow->startSystemResize(edges);
280 if (d->m_platformSizeGrip)
284 QRect availableGeometry;
285 bool hasVerticalSizeConstraint =
true;
286 bool hasHorizontalSizeConstraint =
true;
287 if (tlw->isWindow()) {
288 if (QGuiApplicationPrivate::platformTheme()->themeHint(QPlatformTheme::InteractiveResizeAcrossScreens).toBool())
289 availableGeometry = tlw->screen()->availableVirtualGeometry();
291 availableGeometry = QWidgetPrivate::availableScreenGeometry(tlw);
294 const QWidget *tlwParent = tlw->parentWidget();
298#if QT_CONFIG(scrollarea)
299 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget());
301 hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
302 hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff;
305 availableGeometry = tlwParent->contentsRect();
309 const QRect frameGeometry = tlw->frameGeometry();
310 const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0);
311 const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0);
312 const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0);
317 if (hasVerticalSizeConstraint)
318 d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration;
322 if (hasVerticalSizeConstraint)
323 d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight;
331 if (hasHorizontalSizeConstraint)
332 d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration;
336 if (hasHorizontalSizeConstraint)
337 d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration;
349void QSizeGrip::mouseMoveEvent(QMouseEvent * e)
352 if (e->buttons() != Qt::LeftButton || d->m_platformSizeGrip) {
353 QWidget::mouseMoveEvent(e);
357 QWidget* tlw = qt_sizegrip_topLevelWidget(
this);
358 if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))
361 QPoint np(e->globalPosition().toPoint());
366 ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax);
368 ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax);
371 ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax);
373 ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax);
375 ns = QLayout::closestAcceptableSize(tlw, ns);
381 nr.moveTopRight(d->r.topRight());
383 nr.moveTopLeft(d->r.topLeft());
386 nr.moveBottomRight(d->r.bottomRight());
388 nr.moveBottomLeft(d->r.bottomLeft());
391 tlw->setGeometry(nr);
450bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
453 if (d->isExplicitlyHidden()
454 || e->type() != QEvent::WindowStateChange
456 return QWidget::eventFilter(o, e);
458 Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
459 sizeGripNotVisibleState |= Qt::WindowMaximized;
461 setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState));
462 setAttribute(Qt::WA_WState_ExplicitShowHide,
false);
463 return QWidget::eventFilter(o, e);