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

📄 qdockwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
            return;        if (qobject_cast<QMainWindow*>(q->parentWidget()) == 0)            return;        if (isAnimating())            return;        if (state != 0)            return;        initDrag(event->pos(), false);        if (state == 0)            return;        state->ctrlDrag = event->modifiers() & Qt::ControlModifier;    }#endif // !defined(QT_NO_MAINWINDOW)}void QDockWidgetPrivate::mouseDoubleClickEvent(QMouseEvent *event){    Q_Q(QDockWidget);    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());    if (!layout->nativeWindowDeco()) {        QRect titleArea = layout->titleArea();        if (event->button() != Qt::LeftButton)            return;        if (!titleArea.contains(event->pos()))            return;        if (!::hasFeature(q, QDockWidget::DockWidgetFloatable))            return;        _q_toggleTopLevel();    }}void QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event){#if !defined(QT_NO_MAINWINDOW)    Q_Q(QDockWidget);    if (!state)        return;    QDockWidgetLayout *dwlayout        = qobject_cast<QDockWidgetLayout*>(q->layout());    QMainWindowLayout *mwlayout        = qobject_cast<QMainWindowLayout*>(q->parentWidget()->layout());    if (!dwlayout->nativeWindowDeco()) {        if (!state->dragging            && mwlayout->pluggingWidget == 0            && (event->pos() - state->pressPos).manhattanLength()                > QApplication::startDragDistance()) {            startDrag();#ifdef Q_OS_WIN            grabMouseWhileInWindow();#else            q->grabMouse();#endif        }    }    if (state->dragging && !state->nca) {        QPoint pos = event->globalPos() - state->pressPos;        q->move(pos);        if (!state->ctrlDrag)            mwlayout->hover(state->widgetItem, event->globalPos());    }#endif // !defined(QT_NO_MAINWINDOW)}void QDockWidgetPrivate::mouseReleaseEvent(QMouseEvent *event){#if !defined(QT_NO_MAINWINDOW)    if (event->button() != Qt::LeftButton)        return;    if (!state)        return;    if (state->nca)        return;    endDrag();#endif // !defined(QT_NO_MAINWINDOW)}void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event){    Q_Q(QDockWidget);    int fw = q->style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, q);    QRect geo = q->geometry();    QRect titleRect = q->frameGeometry();#ifdef Q_WS_MAC    if ((features & QDockWidget::DockWidgetVerticalTitleBar)) {        titleRect.setTop(geo.top());        titleRect.setBottom(geo.bottom());        titleRect.setRight(geo.left() - 1);    } else#endif    {        titleRect.setLeft(geo.left());        titleRect.setRight(geo.right());        titleRect.setBottom(geo.top() - 1);        titleRect.adjust(0, fw, 0, 0);    }    switch (event->type()) {        case QEvent::NonClientAreaMouseButtonPress:            if (!titleRect.contains(event->globalPos()))                break;            if (state != 0)                break;            if (qobject_cast<QMainWindow*>(q->parentWidget()) == 0)                break;            if (isAnimating())                break;            initDrag(event->pos(), true);            if (state == 0)                break;#ifdef Q_OS_WIN            // On Windows, NCA mouse events don't contain modifier info            state->ctrlDrag = GetKeyState(VK_CONTROL) & 0x8000;#else            state->ctrlDrag = event->modifiers() & Qt::ControlModifier;#endif            startDrag();            break;        case QEvent::NonClientAreaMouseMove:            if (state == 0 || !state->dragging)                break;            if (state->nca) {                endDrag();            }#ifdef Q_OS_MAC            else { // workaround for lack of mouse-grab on Mac                QMainWindowLayout *layout                    = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());                Q_ASSERT(layout != 0);                q->move(event->globalPos() - state->pressPos);                if (!state->ctrlDrag)                    layout->hover(state->widgetItem, event->globalPos());            }#endif            break;        case QEvent::NonClientAreaMouseButtonRelease:#ifdef Q_OS_MAC                        if (state)                                endDrag();#endif                        break;        case QEvent::NonClientAreaMouseButtonDblClick:            _q_toggleTopLevel();            break;        default:            break;    }}void QDockWidgetPrivate::moveEvent(QMoveEvent *event){    Q_Q(QDockWidget);    if (state == 0 || !state->dragging || !state->nca || !q->isWindow())        return;    // When the native window frame is being dragged, all we get is these mouse    // move events.    if (state->ctrlDrag)        return;    QMainWindowLayout *layout        = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());    Q_ASSERT(layout != 0);    QPoint globalMousePos = event->pos() + state->pressPos;    layout->hover(state->widgetItem, globalMousePos);}void QDockWidgetPrivate::unplug(const QRect &rect){    Q_Q(QDockWidget);    QRect r = rect;    r.moveTopLeft(q->mapToGlobal(QPoint(0, 0)));#ifndef Q_WS_X11    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());    r.adjust(0, layout->titleHeight(), 0, 0);#endif    setWindowState(true, true, r);}void QDockWidgetPrivate::plug(const QRect &rect){    setWindowState(false, false, rect);}void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect &rect){    Q_Q(QDockWidget);    bool wasFloating = q->isFloating();    bool hidden = q->isHidden();    if (q->isVisible())        q->hide();    Qt::WindowFlags flags = floating ? Qt::Tool : Qt::Widget;    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(q->layout());    bool nativeDeco = floating && layout->widget(QDockWidgetLayout::TitleBar) == 0;#if defined(Q_WS_X11) || defined(Q_WS_QWS)    nativeDeco = false;#endif    if (nativeDeco) {        flags |= Qt::CustomizeWindowHint | Qt::WindowTitleHint;        if (hasFeature(q, QDockWidget::DockWidgetClosable))            flags |= Qt::WindowSystemMenuHint;    } else {        flags |= Qt::FramelessWindowHint;    }    if (unplug)        flags |= Qt::X11BypassWindowManagerHint;    q->setWindowFlags(flags);#ifdef Q_WS_MAC    if (floating && nativeDeco && (q->features() & QDockWidget::DockWidgetVerticalTitleBar)) {        ChangeWindowAttributes(HIViewGetWindow(HIViewRef(q->winId())), kWindowSideTitlebarAttribute, 0);    }#endif    if (!rect.isNull())        q->setGeometry(rect);    updateButtons();    if (!hidden)        q->show();    if (floating != wasFloating)        emit q->topLevelChanged(floating);    resizer->setActive(QWidgetResizeHandler::Resize, !unplug && floating && !nativeDeco);}/*!    \class QDockWidget    \brief The QDockWidget class provides a widget that can be docked    inside a QMainWindow or floated as a top-level window on the    desktop.    \ingroup application    QDockWidget provides the concept of dock widgets, also know as    tool palettes or utility windows.  Dock windows are secondary    windows placed in the \e {dock widget area} around the    \l{QMainWindow::centralWidget()}{central widget} in a    QMainWindow.    \image mainwindow-docks.png    Dock windows can be moved inside their current area, moved into    new areas and floated (e.g. undocked) by the end-user.  The    QDockWidget API allows the programmer to restrict the dock widgets    ability to move, float and close, as well as the areas in which    they can be placed.    \section1 Appearance    A QDockWidget consists of a title bar and the content area.  The    title bar displays the dock widgets \link QWidget::windowTitle()    window title\endlink, a \e float button and a \e close button.    Depending on the state of the QDockWidget, the \e float and \e    close buttons may be either disabled or not shown at all.    The visual appearance of the title bar and buttons is dependent    on the \l{QStyle}{style} in use.    A QDockWidget acts as a wrapper for its child widget, set with setWidget().    Custom size hints, minimum and maximum sizes and size policies should be    implemented in the child widget. QDockWidget will respect them, adjusting    its own constraints to include the frame and title. Size constraints    should not be set on the QDockWidget itself, because they change depending    on wether it is docked; a docked QDockWidget has no frame and a smaller title    bar.    \sa QMainWindow, {Dock Widgets Example}*//*!    \enum QDockWidget::DockWidgetFeature    \value DockWidgetClosable   The dock widget can be closed.    \value DockWidgetMovable    The dock widget can be moved between docks                                by the user.    \value DockWidgetFloatable  The dock widget can be detached from the                                main window, and floated as an independent                                window.    \value DockWidgetVerticalTitleBar The dock widget displays a vertical title                                  bar on its left side. This can be used to                                  increase the amount of vertical space in                                  a QMainWindow.    \value AllDockWidgetFeatures  (Deprecated) The dock widget can be closed, moved,                                  and floated. Since new features might be added in future                                  releases, the look and behavior of dock widgets might                                  change if you use this flag. Please specify individual                                  flags instead.    \value NoDockWidgetFeatures   The dock widget cannot be closed, moved,                                  or floated.    \omitvalue DockWidgetFeatureMask    \omitvalue Reserved*//*!    \property QDockWidget::windowTitle    \internal*//*!    Constructs a QDockWidget with parent \a parent and window flags \a    flags. The dock widget will be placed in the left dock widget    area.*/QDockWidget::QDockWidget(QWidget *parent, Qt::WindowFlags flags)    : QWidget(*new QDockWidgetPrivate, parent, flags){    Q_D(QDockWidget);    d->init();}/*!    Constructs a QDockWidget with parent \a parent and window flags \a    flags. The dock widget will be placed in the left dock widget    area.    The window title is set to \a title. This title is used when the    QDockWidget is docked and undocked. It is also used in the context    menu provided by QMainWindow.    \sa setWindowTitle()*/QDockWidget::QDockWidget(const QString &title, QWidget *parent, Qt::WindowFlags flags)    : QWidget(*new QDockWidgetPrivate, parent, flags){    Q_D(QDockWidget);    d->init();    setWindowTitle(title);}/*!    Destroys the dock widget.*/QDockWidget::~QDockWidget(){ }/*!    Returns the widget for the dock widget. This function returns zero    if the widget has not been set.    \sa setWidget()*/QWidget *QDockWidget::widget() const{    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout());    return layout->widget(QDockWidgetLayout::Content);}/*!    Sets the widget for the dock widget to \a widget.    \sa widget()*/

⌨️ 快捷键说明

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