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

📄 qdockwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void QDockWidget::setWidget(QWidget *widget){    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout());    layout->setWidget(QDockWidgetLayout::Content, widget);}/*!    \property QDockWidget::features    \brief whether the dock widget is movable, closable, and floatable    \sa DockWidgetFeature*/void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features){    Q_D(QDockWidget);    features &= DockWidgetFeatureMask;    if (d->features == features)        return;    d->features = features;    QDockWidgetLayout *layout        = qobject_cast<QDockWidgetLayout*>(this->layout());    layout->setVerticalTitleBar(features & DockWidgetVerticalTitleBar);    d->updateButtons();    d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable);    emit featuresChanged(d->features);    update();}QDockWidget::DockWidgetFeatures QDockWidget::features() const{    Q_D(const QDockWidget);    return d->features;}/*!    \property QDockWidget::floating    \brief whether the dock widget is floating    A floating dock widget is presented to the user as an independent    window "on top" of its parent QMainWindow, instead of being    docked in the QMainWindow.    \sa isWindow()*/void QDockWidget::setFloating(bool floating){    Q_D(QDockWidget);    // the initial click of a double-click may have started a drag...    if (d->state != 0)        d->endDrag(true);    QRect r = d->undockedGeometry;    if (floating && r.isNull()) {        QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout());        QRect titleArea = layout->titleArea();        int h = layout->verticalTitleBar ? titleArea.width() : titleArea.height();        QPoint p = mapToGlobal(QPoint(h, h));        r = QRect(p, size());    }    d->setWindowState(floating, false, floating ? r : QRect());}/*!    \property QDockWidget::allowedAreas    \brief areas where the dock widget may be placed    The default is Qt::AllDockWidgetAreas.    \sa Qt::DockWidgetArea*/void QDockWidget::setAllowedAreas(Qt::DockWidgetAreas areas){    Q_D(QDockWidget);    areas &= Qt::DockWidgetArea_Mask;    if (areas == d->allowedAreas)        return;    d->allowedAreas = areas;    emit allowedAreasChanged(d->allowedAreas);}Qt::DockWidgetAreas QDockWidget::allowedAreas() const{    Q_D(const QDockWidget);    return d->allowedAreas;}/*!    \fn bool QDockWidget::isAreaAllowed(Qt::DockWidgetArea area) const    Returns true if this dock widget can be placed in the given \a area;    otherwise returns false.*//*! \reimp */void QDockWidget::changeEvent(QEvent *event){    Q_D(QDockWidget);    QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout());    switch (event->type()) {    case QEvent::ModifiedChange:    case QEvent::WindowTitleChange:        update(layout->titleArea());#ifndef QT_NO_ACTION        d->fixedWindowTitle = qt_setWindowTitle_helperHelper(windowTitle(), this);        d->toggleViewAction->setText(d->fixedWindowTitle);#endif#ifndef QT_NO_TABBAR        {            QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget());            if (QMainWindowLayout *winLayout =                (win ? qobject_cast<QMainWindowLayout*>(win->layout()) : 0))                if (QDockAreaLayoutInfo *info =                    (winLayout ? winLayout->layoutState.dockAreaLayout.info(this) : 0))                    info->updateTabBar();        }#endif // QT_NO_TABBAR        break;    default:        break;    }    QWidget::changeEvent(event);}/*! \reimp */void QDockWidget::closeEvent(QCloseEvent *event){    QWidget::closeEvent(event);}/*! \reimp */void QDockWidget::paintEvent(QPaintEvent *event){    Q_UNUSED(event)    QDockWidgetLayout *layout        = qobject_cast<QDockWidgetLayout*>(this->layout());    bool customTitleBar = layout->widget(QDockWidgetLayout::TitleBar) != 0;    bool nativeDeco = layout->nativeWindowDeco();    if (!nativeDeco && !customTitleBar) {        QStylePainter p(this);        // ### Add PixelMetric to change spacers, so style may show border        // when not floating.        if (isFloating()) {            QStyleOptionFrame framOpt;            framOpt.init(this);            p.drawPrimitive(QStyle::PE_FrameDockWidget, framOpt);        }        // Title must be painted after the frame, since the areas overlap, and        // the title may wish to extend out to all sides (eg. XP style)        QStyleOptionDockWidgetV2 titleOpt;        initStyleOption(&titleOpt);        p.drawControl(QStyle::CE_DockWidgetTitle, titleOpt);    }}/*! \reimp */bool QDockWidget::event(QEvent *event){    Q_D(QDockWidget);    QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget());    QMainWindowLayout *layout = 0;    if (win != 0)        layout = qobject_cast<QMainWindowLayout*>(win->layout());    switch (event->type()) {#ifndef QT_NO_ACTION    case QEvent::Hide:        if (layout != 0)            layout->keepSize(this);        d->toggleViewAction->setChecked(false);        emit visibilityChanged(false);        break;    case QEvent::Show:        d->toggleViewAction->setChecked(true);        emit visibilityChanged(true);        break;#endif    case QEvent::ApplicationLayoutDirectionChange:    case QEvent::LayoutDirectionChange:    case QEvent::StyleChange:    case QEvent::ParentChange:        d->updateButtons();        break;    case QEvent::ZOrderChange: {        bool onTop = false;        if (win != 0) {            const QObjectList &siblings = win->children();            onTop = siblings.count() > 0 && siblings.last() == (QObject*)this;        }        if (!isFloating() && layout != 0 && onTop)            layout->raise(this);        break;    }    case QEvent::WindowActivate:    case QEvent::WindowDeactivate:        update(qobject_cast<QDockWidgetLayout *>(this->layout())->titleArea());        break;    case QEvent::ContextMenu:        if (d->state) {            event->accept();            return true;        }        break;        // return true after calling the handler since we don't want        // them to be passed onto the default handlers    case QEvent::MouseButtonPress:        d->mousePressEvent(static_cast<QMouseEvent *>(event));        return true;    case QEvent::MouseButtonDblClick:        d->mouseDoubleClickEvent(static_cast<QMouseEvent *>(event));        return true;    case QEvent::MouseMove:        d->mouseMoveEvent(static_cast<QMouseEvent *>(event));        return true;#ifdef Q_OS_WIN    case QEvent::Leave:        if (d->state != 0 && d->state->dragging && !d->state->nca) {            // This is a workaround for loosing the mouse on Vista.            QPoint pos = QCursor::pos();            QMouseEvent fake(QEvent::MouseMove, mapFromGlobal(pos), pos, Qt::NoButton,                             QApplication::mouseButtons(), QApplication::keyboardModifiers());            d->mouseMoveEvent(&fake);        }        break;#endif    case QEvent::MouseButtonRelease:        d->mouseReleaseEvent(static_cast<QMouseEvent *>(event));        return true;    case QEvent::NonClientAreaMouseMove:    case QEvent::NonClientAreaMouseButtonPress:    case QEvent::NonClientAreaMouseButtonRelease:    case QEvent::NonClientAreaMouseButtonDblClick:        d->nonClientAreaMouseEvent(static_cast<QMouseEvent*>(event));        return true;    case QEvent::Move:        d->moveEvent(static_cast<QMoveEvent*>(event));        break;    case QEvent::Resize:        // if the mainwindow is plugging us, we don't want to update undocked geometry        if (isFloating() && layout != 0 && layout->pluggingWidget != this)            d->undockedGeometry = geometry();        break;    default:        break;    }    return QWidget::event(event);}#ifndef QT_NO_ACTION/*!  Returns a checkable action that can be used to show or close this  dock widget.  The action's text is set to the dock widget's window title.  \sa QAction::text QWidget::windowTitle */QAction * QDockWidget::toggleViewAction() const{    Q_D(const QDockWidget);    return d->toggleViewAction;}#endif // QT_NO_ACTION/*!    \fn void QDockWidget::featuresChanged(QDockWidget::DockWidgetFeatures features)    This signal is emitted when the \l features property changes. The    \a features parameter gives the new value of the property.*//*!    \fn void QDockWidget::topLevelChanged(bool topLevel)    This signal is emitted when the \l floating property changes.    The \a topLevel parameter is true if the dock widget is now floating;    otherwise it is false.    \sa isWindow()*//*!    \fn void QDockWidget::allowedAreasChanged(Qt::DockWidgetAreas allowedAreas)    This signal is emitted when the \l allowedAreas property changes. The    \a allowedAreas parameter gives the new value of the property.*//*!    \fn void QDockWidget::visibilityChanged(bool visible)    \since 4.3    This signal is emitted when the dock widget becomes \a visible (or    invisible). This happens when the widget is hidden or shown, as    well as when it is docked in a tabbed dock area and its tab    becomes selected or unselected.*//*!    \fn void QDockWidget::dockLocationChanged(Qt::DockWidgetArea area)    \since 4.3    This signal is emitted when the dock widget is moved to another    dock \a area, or is moved to a different location in its current    dock area. This happens when the dock widget is moved    programmatically or is dragged to a new location by the user.*//*!    \since 4.3    Sets an arbitrary \a widget as the dock widget's title bar. If \a widget    is 0, the title bar widget is removed, but not deleted.    If a title bar widget is set, QDockWidget will not use native window    decorations when it is floated.    Here are some tips for implementing custom title bars:    \list    \i Mouse events that are not explicitly handled by the title bar widget       must be ignored by calling QMouseEvent::ignore(). These events then       propagate to the QDockWidget parent, which handles them in the usual       manner, moving when the title bar is dragged, docking and undocking       when it is double-clicked, etc.    \i When DockWidgetVerticalTitleBar is set on QDockWidget, the title       bar widget is repositioned accordingly. In resizeEvent(), the title       bar should check what orientation it should assume:       \code       QDockWidget *dockWidget = qobject_cast<QDockWidget*>(parentWidget());       if (dockWidget->features() & QDockWidget::DockWidgetVerticalTitleBar) {           // I need to be vertical       } else {           // I need to be horizontal       }       \endcode    \i The title bar widget must have a valid QWidget::sizeHint() and       QWidget::minimumSizeHint(). These functions should take into account       the current orientation of the title bar.    \endlist    Using qobject_cast as shown above, the title bar widget has full access    to its parent QDockWidget. Hence it can perform such operations as docking    and hiding in response to user actions.    \sa titleBarWidget() DockWidgetVerticalTitleBar*/void QDockWidget::setTitleBarWidget(QWidget *widget){    Q_D(QDockWidget);    QDockWidgetLayout *layout        = qobject_cast<QDockWidgetLayout*>(this->layout());    layout->setWidget(QDockWidgetLayout::TitleBar, widget);    d->updateButtons();}/*!    \since 4.3    Returns the custom title bar widget set on the QDockWidget, or 0 if no    custom title bar has been set.    \sa setTitleBarWidget()*/QWidget *QDockWidget::titleBarWidget() const{    QDockWidgetLayout *layout        = qobject_cast<QDockWidgetLayout*>(this->layout());    return layout->widget(QDockWidgetLayout::TitleBar);}#include "qdockwidget.moc"#include "moc_qdockwidget.cpp"#endif // QT_NO_DOCKWIDGET

⌨️ 快捷键说明

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