/*! Resizes the top-level widget containing this widget. The event is in \a e. */ void QSizeGrip::mouseMoveEvent( QMouseEvent * e ) { if ( e->state() != LeftButton ) return; QWidget* tlw = qt_sizegrip_topLevelWidget(this); if ( tlw->testWState(WState_ConfigPending) ) return; QPoint np( e->globalPos() ); QWidget* ws = qt_sizegrip_workspace( this ); if ( ws ) { QPoint tmp( ws->mapFromGlobal( np ) ); if ( tmp.x() > ws->width() ) tmp.setX( ws->width() ); if ( tmp.y() > ws->height() ) tmp.setY( ws->height() ); np = ws->mapToGlobal( tmp ); } int w; int h = np.y() - p.y() + s.height(); if ( QApplication::reverseLayout() ) w = s.width() - ( np.x() - p.x() ); else w = np.x() - p.x() + s.width(); if ( w < 1 ) w = 1; if ( h < 1 ) h = 1; QSize ms( tlw->minimumSizeHint() ); ms = ms.expandedTo( minimumSize() ); if ( w < ms.width() ) w = ms.width(); if ( h < ms.height() ) h = ms.height(); if (QApplication::reverseLayout()) { tlw->resize( w, h ); if (tlw->size() == QSize(w,h)) tlw->move( tlw->x() + ( np.x()-p.x() ), tlw->y() ); } else { tlw->resize( w, h ); } #ifdef Q_WS_WIN MSG msg; while( PeekMessage( &msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE ) ) ; #endif QApplication::syncX(); if ( QApplication::reverseLayout() && tlw->size() == QSize(w,h) ) { s.rwidth() = tlw->size().width(); p.rx() = np.x(); } }
void CSizeGrip::updateMacSizer(bool hide) const { if (QApplication::closingDown() || !parent) return; QWidget *topLevelWindow = qt_sizegrip_topLevelWidget(const_cast<CSizeGrip *>(this)); if(topLevelWindow && topLevelWindow->isWindow()) QWidget::qt_mac_update_sizer(topLevelWindow, hide ? -1 : 1); }
/*! \reimp */ bool QSizeGrip::eventFilter( QObject *o, QEvent *e ) { if ( o == tlw ) { switch ( e->type() ) { #ifndef Q_WS_MAC /* The size grip goes no where on Mac OS X when you maximize! --Sam */ case QEvent::ShowMaximized: #endif case QEvent::ShowFullScreen: hide(); break; case QEvent::ShowNormal: show(); break; default: break; } } else if(o == this) { #if defined(Q_WS_MAC) switch(e->type()) { case QEvent::Hide: case QEvent::Show: if(!QApplication::closingDown() && parentWidget() && !qt_sizegrip_workspace(this)) { if(QWidget *w = qt_sizegrip_topLevelWidget(this)) { if(w->isTopLevel()) qt_mac_update_sizer(w, e->type() == QEvent::Hide ? -1 : 1); } } break; default: break; } #endif } return FALSE; }
/*! Primes the resize operation. The event is in \a e. */ void QSizeGrip::mousePressEvent( QMouseEvent * e ) { p = e->globalPos(); s = qt_sizegrip_topLevelWidget(this)->size(); }
/*! \fn void CSizeGrip::mouseMoveEvent(QMouseEvent * event) Resizes the top-level widget containing this widget. The mouse move event is passed in the \a event parameter. */ void CSizeGrip::mouseMoveEvent(QMouseEvent * e) { if (e->buttons() != Qt::LeftButton) { QWidget::mouseMoveEvent(e); return; } QWidget* tlw = qt_sizegrip_topLevelWidget(); if (!gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending)) return; #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && tlw->isTopLevel() && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) return; #endif #endif #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && GetSystemMenu(tlw->winId(), FALSE) != 0 && internalWinId() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { MSG msg; while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE)); return; } #endif #endif QPoint np(e->globalPos()); // Don't extend beyond the available geometry; bound to dyMax and dxMax. QSize ns; if (atBottom()) ns.rheight() = r.height() + qMin(np.y() - p.y(), dyMax); else ns.rheight() = r.height() - qMax(np.y() - p.y(), dyMax); if (atLeft()) ns.rwidth() = r.width() - qMax(np.x() - p.x(), dxMax); else ns.rwidth() = r.width() + qMin(np.x() - p.x(), dxMax); ns = QLayout::closestAcceptableSize(tlw, ns); QPoint p; QRect nr(p, ns); if (atBottom()) { if (atLeft()) nr.moveTopRight(r.topRight()); else nr.moveTopLeft(r.topLeft()); } else { if (atLeft()) nr.moveBottomRight(r.bottomRight()); else nr.moveBottomLeft(r.bottomLeft()); } ((CPObject*)tlw)->changeGeometrySize(nr.x(),nr.y(),nr.width(),nr.height()); }
/*! \fn void CSizeGrip::mousePressEvent(QMouseEvent * event) Receives the mouse press events for the widget, and primes the resize operation. The mouse press event is passed in the \a event parameter. */ void CSizeGrip::mousePressEvent(QMouseEvent * e) { ungrabGesture(Qt::TapAndHoldGesture); if (e->button() != Qt::LeftButton) { QWidget::mousePressEvent(e); return; } QWidget *tlw = qt_sizegrip_topLevelWidget(); p = e->globalPos(); gotMousePress = true; r = tlw->geometry(); #ifdef Q_WS_X11 #if QT_VERSION >= 0x050000 // Use a native X11 sizegrip for "real" top-level windows if supported. if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE)) && !(tlw->windowFlags() & Qt::X11BypassWindowManagerHint) && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.message_type = ATOM(_NET_WM_MOVERESIZE); xev.xclient.display = X11->display; xev.xclient.window = tlw->winId(); xev.xclient.format = 32; xev.xclient.data.l[0] = e->globalPos().x(); xev.xclient.data.l[1] = e->globalPos().y(); if (atBottom()) xev.xclient.data.l[2] = atLeft() ? 6 : 4; // bottomleft/bottomright else xev.xclient.data.l[2] = atLeft() ? 0 : 2; // topleft/topright xev.xclient.data.l[3] = Button1; xev.xclient.data.l[4] = 0; XUngrabPointer(X11->display, X11->time); XSendEvent(X11->display, QX11Info::appRootWindow(x11Info().screen()), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); return; } #endif #endif // Q_WS_X11 #ifdef Q_WS_WIN #if QT_VERSION >= 0x050000 if (tlw->isWindow() && !tlw->testAttribute(Qt::WA_DontShowOnScreen) && !qt_widget_private(tlw)->hasHeightForWidth()) { uint orientation = 0; if (atBottom()) orientation = atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT; else orientation = atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT; ReleaseCapture(); PostMessage(tlw->winId(), WM_SYSCOMMAND, orientation, 0); return; } #endif #endif // Q_WS_WIN // Find available desktop/workspace geometry. QRect availableGeometry; bool hasVerticalSizeConstraint = true; bool hasHorizontalSizeConstraint = true; if (tlw->isWindow()) availableGeometry = QApplication::desktop()->availableGeometry(tlw); else { const QWidget *tlwParent = tlw->parentWidget(); // Check if tlw is inside QAbstractScrollArea/QScrollArea. // If that's the case tlw->parentWidget() will return the viewport // and tlw->parentWidget()->parentWidget() will return the scroll area. #ifndef QT_NO_SCROLLAREA QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea *>(tlwParent->parentWidget()); if (scrollArea) { hasHorizontalSizeConstraint = scrollArea->horizontalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; hasVerticalSizeConstraint = scrollArea->verticalScrollBarPolicy() == Qt::ScrollBarAlwaysOff; } #endif // QT_NO_SCROLLAREA availableGeometry = tlwParent->contentsRect(); } // Find frame geometries, title bar height, and decoration sizes. const QRect frameGeometry = tlw->frameGeometry(); const int titleBarHeight = qMax(tlw->geometry().y() - frameGeometry.y(), 0); const int bottomDecoration = qMax(frameGeometry.height() - tlw->height() - titleBarHeight, 0); const int leftRightDecoration = qMax((frameGeometry.width() - tlw->width()) / 2, 0); // Determine dyMax depending on whether the sizegrip is at the bottom // of the widget or not. if (atBottom()) { if (hasVerticalSizeConstraint) dyMax = availableGeometry.bottom() - r.bottom() - bottomDecoration; else dyMax = INT_MAX; } else { if (hasVerticalSizeConstraint) dyMax = availableGeometry.y() - r.y() + titleBarHeight; else dyMax = -INT_MAX; } // In RTL mode, the size grip is to the left; find dxMax from the desktop/workspace // geometry, the size grip geometry and the width of the decoration. if (atLeft()) { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.x() - r.x() + leftRightDecoration; else dxMax = -INT_MAX; } else { if (hasHorizontalSizeConstraint) dxMax = availableGeometry.right() - r.right() - leftRightDecoration; else dxMax = INT_MAX; } }