⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsizegrip.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    QWidget *tlw = qt_sizegrip_topLevelWidget(this);    d->p = e->globalPos();    d->gotMousePress = true;    d->r = tlw->geometry();#ifdef Q_WS_X11    // Use a native X11 sizegrip for "real" top-level windows if supported.    if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))) {        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 (d->atBottom())            xev.xclient.data.l[2] = d->atLeft() ? 6 : 4; // bottomleft/bottomright        else            xev.xclient.data.l[2] = d->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 // Q_WS_X11    // 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 (d->atBottom()) {        if (hasVerticalSizeConstraint)            d->dyMax = availableGeometry.bottom() - d->r.bottom() - bottomDecoration;        else            d->dyMax = INT_MAX;    } else {        if (hasVerticalSizeConstraint)            d->dyMax = availableGeometry.y() - d->r.y() + titleBarHeight;        else            d->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 (d->atLeft()) {        if (hasHorizontalSizeConstraint)            d->dxMax = availableGeometry.x() - d->r.x() + leftRightDecoration;        else            d->dxMax = -INT_MAX;    } else {        if (hasHorizontalSizeConstraint)            d->dxMax = availableGeometry.right() - d->r.right() - leftRightDecoration;        else            d->dxMax = INT_MAX;    }}/*!    \fn void QSizeGrip::mouseMoveEvent(QMouseEvent * event)    Resizes the top-level widget containing this widget. The mouse    move event is passed in the \a event parameter.*/void QSizeGrip::mouseMoveEvent(QMouseEvent * e){    if (e->buttons() != Qt::LeftButton) {        QWidget::mouseMoveEvent(e);        return;    }    Q_D(QSizeGrip);    QWidget* tlw = qt_sizegrip_topLevelWidget(this);    if (!d->gotMousePress || tlw->testAttribute(Qt::WA_WState_ConfigPending))        return;#ifdef Q_WS_X11    if (tlw->isWindow() && X11->isSupportedByWM(ATOM(_NET_WM_MOVERESIZE))        && tlw->isTopLevel())        return;#endif#ifdef Q_WS_WIN    if (tlw->isWindow() && ::GetSystemMenu(tlw->winId(), FALSE) != 0) {        MSG msg;        while(PeekMessage(&msg, winId(), WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));        return;    }#endif    QPoint np(e->globalPos());    // Don't extend beyond the available geometry; bound to dyMax and dxMax.    QSize ns;    if (d->atBottom())        ns.rheight() = d->r.height() + qMin(np.y() - d->p.y(), d->dyMax);    else        ns.rheight() = d->r.height() - qMax(np.y() - d->p.y(), d->dyMax);    if (d->atLeft())        ns.rwidth() = d->r.width() - qMax(np.x() - d->p.x(), d->dxMax);    else        ns.rwidth() = d->r.width() + qMin(np.x() - d->p.x(), d->dxMax);    ns = ns.expandedTo(tlw->minimumSize()).expandedTo(tlw->minimumSizeHint()).boundedTo(tlw->maximumSize());    QPoint p;    QRect nr(p, ns);    if (d->atBottom()) {        if (d->atLeft())            nr.moveTopRight(d->r.topRight());        else            nr.moveTopLeft(d->r.topLeft());    } else {        if (d->atLeft())            nr.moveBottomRight(d->r.bottomRight());        else            nr.moveBottomLeft(d->r.bottomLeft());    }    tlw->setGeometry(nr);}/*!  \reimp*/void QSizeGrip::mouseReleaseEvent(QMouseEvent *mouseEvent){    if (mouseEvent->button() == Qt::LeftButton) {        Q_D(QSizeGrip);        d->gotMousePress = false;        d->p = QPoint();    } else {        QWidget::mouseReleaseEvent(mouseEvent);    }}/*!  \reimp*/void QSizeGrip::moveEvent(QMoveEvent * /*moveEvent*/){    Q_D(QSizeGrip);    // We're inside a resize operation; no update necessary.    if (!d->p.isNull())        return;    d->m_corner = d->corner();#if !defined(QT_NO_CURSOR) && !defined(Q_WS_MAC)    setCursor(d->m_corner == Qt::TopLeftCorner || d->m_corner == Qt::BottomRightCorner              ? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);#endif}/*!  \reimp*/void QSizeGrip::showEvent(QShowEvent *showEvent){#ifdef Q_WS_MAC    d_func()->updateMacSizer(false);#endif    QWidget::showEvent(showEvent);}/*!  \reimp*/void QSizeGrip::hideEvent(QHideEvent *hideEvent){#ifdef Q_WS_MAC    d_func()->updateMacSizer(true);#endif    QWidget::hideEvent(hideEvent);}/*! \reimp */void QSizeGrip::setVisible(bool visible){    Q_D(QSizeGrip);    d->hiddenByUser = !visible;    QWidget::setVisible(visible);}/*! \reimp */bool QSizeGrip::eventFilter(QObject *o, QEvent *e){    Q_D(QSizeGrip);    if (d->hiddenByUser || e->type() != QEvent::WindowStateChange)        return QWidget::eventFilter(o, e);    QWidget *tlw = qt_sizegrip_topLevelWidget(this);    if (o != tlw)        return QWidget::eventFilter(o, e);    QWidget::setVisible((tlw->windowState() &                             (Qt::WindowFullScreen#ifndef Q_WS_MAC                              | Qt::WindowMaximized#endif                              ))==0);    return false;}/*!    \reimp*/bool QSizeGrip::event(QEvent *event){    return QWidget::event(event);}#ifdef Q_WS_WIN/*! \reimp */bool QSizeGrip::winEvent( MSG *m, long *result ){    if (m->message != WM_LBUTTONDOWN)        return QWidget::winEvent(m, result);    // toplevel windows use the native size grip on Windows    QWidget *w = qt_sizegrip_topLevelWidget(this);    if (!w->isWindow())        return QWidget::winEvent(m, result);    Q_D(QSizeGrip);    uint orientation = 0;    if (d->atBottom())        orientation = d->atLeft() ? SZ_SIZEBOTTOMLEFT : SZ_SIZEBOTTOMRIGHT;    else        orientation = d->atLeft() ? SZ_SIZETOPLEFT : SZ_SIZETOPRIGHT;    QT_WA_INLINE(PostMessageW(w->winId(), WM_SYSCOMMAND, orientation, 0),                 PostMessageA(w->winId(), WM_SYSCOMMAND, orientation, 0));    return true;}#endif#endif //QT_NO_SIZEGRIP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -