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

📄 qmainwindow.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void QMainWindow::setCorner(Qt::Corner corner, Qt::DockWidgetArea area){    bool valid = false;    switch (corner) {    case Qt::TopLeftCorner:        valid = (area == Qt::TopDockWidgetArea || area == Qt::LeftDockWidgetArea);        break;    case Qt::TopRightCorner:        valid = (area == Qt::TopDockWidgetArea || area == Qt::RightDockWidgetArea);        break;    case Qt::BottomLeftCorner:        valid = (area == Qt::BottomDockWidgetArea || area == Qt::LeftDockWidgetArea);        break;    case Qt::BottomRightCorner:        valid = (area == Qt::BottomDockWidgetArea || area == Qt::RightDockWidgetArea);        break;    }    Q_ASSERT_X(valid, "QMainWindow::setCorner", "'area' is not valid for 'corner'");    if (valid)        d_func()->layout->corners[corner] = area;}/*!    Returns the dock widget area that occupies the specified \a    corner.    \sa setCorner()*/Qt::DockWidgetArea QMainWindow::corner(Qt::Corner corner) const{ return d_func()->layout->corners[corner]; }#ifndef QT_NO_TOOLBAR/*!    Adds a toolbar break to the given \a area after all the other    objects that are present.*/void QMainWindow::addToolBarBreak(Qt::ToolBarArea area){ d_func()->layout->addToolBarBreak(area); }/*!    Inserts a toolbar break before the toolbar specified by \a before.*/void QMainWindow::insertToolBarBreak(QToolBar *before){ d_func()->layout->insertToolBarBreak(before); }/*!    Adds the \a toolbar into the specified \a area in this main    window. The \a toolbar is placed at the end of the current tool    bar block (i.e. line). If the main window already manages \a toolbar    then it will only move the toolbar to \a area.    \sa insertToolBar() addToolBarBreak() insertToolBarBreak()*/void QMainWindow::addToolBar(Qt::ToolBarArea area, QToolBar *toolbar){    Q_D(QMainWindow);    Q_ASSERT_X(toolbar->isAreaAllowed(area),               "QMainWIndow::addToolBar", "specified 'area' is not an allowed area");    disconnect(this, SIGNAL(iconSizeChanged(QSize)),               toolbar, SLOT(_q_updateIconSize(QSize)));    disconnect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),               toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));    d->layout->removeWidget(toolbar);    toolbar->d_func()->_q_updateIconSize(d->iconSize);    toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);    connect(this, SIGNAL(iconSizeChanged(QSize)),            toolbar, SLOT(_q_updateIconSize(QSize)));    connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),            toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));    d->layout->addToolBar(area, toolbar);    if (isVisible())        d->layout->relayout();}/*! \overload    Equivalent of calling addToolBar(Qt::TopToolBarArea, \a toolbar)*/void QMainWindow::addToolBar(QToolBar *toolbar){ addToolBar(Qt::TopToolBarArea, toolbar); }/*!    \overload    Creates a QToolBar object, setting its window title to \a title,    and inserts it into the top toolbar area.    \sa setWindowTitle()*/QToolBar *QMainWindow::addToolBar(const QString &title){    QToolBar *toolBar = new QToolBar(this);    toolBar->setWindowTitle(title);    addToolBar(toolBar);    return toolBar;}/* Removes the toolbar from the mainwindow so that it can be added again. Does not   explicitly hide the toolbar. */static void qt_remove_toolbar_from_layout(QToolBar *toolbar, QMainWindowPrivate *d){    if (toolbar) {        QObject::disconnect(d->q_ptr, SIGNAL(iconSizeChanged(QSize)),                   toolbar, SLOT(_q_updateIconSize(QSize)));        QObject::disconnect(d->q_ptr, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),                   toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));        d->layout->removeWidget(toolbar);    }}/*!    Inserts the \a toolbar into the area occupied by the \a before toolbar    so that it appears before it. For example, in normal left-to-right    layout operation, this means that \a toolbar will appear to the left    of the toolbar specified by \a before in a horizontal toolbar area.    \sa insertToolBarBreak() addToolBar() addToolBarBreak()*/void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar){    Q_D(QMainWindow);    Q_ASSERT_X(toolbar->isAreaAllowed(toolBarArea(before)),               "QMainWIndow::insertToolBar", "specified 'area' is not an allowed area");    qt_remove_toolbar_from_layout(toolbar, d);        toolbar->d_func()->_q_updateIconSize(d->iconSize);    toolbar->d_func()->_q_updateToolButtonStyle(d->toolButtonStyle);    connect(this, SIGNAL(iconSizeChanged(QSize)),            toolbar, SLOT(_q_updateIconSize(QSize)));    connect(this, SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)),            toolbar, SLOT(_q_updateToolButtonStyle(Qt::ToolButtonStyle)));    d->layout->insertToolBar(before, toolbar);    if (isVisible())        d->layout->relayout();}/*!    Removes the \a toolbar from the main window layout and hides    it. Note that the \a toolbar is \e not deleted.*/void QMainWindow::removeToolBar(QToolBar *toolbar){    if (toolbar) {        qt_remove_toolbar_from_layout(toolbar, d_func());        toolbar->hide();    }}/*!    Returns the Qt::ToolBarArea for \a toolbar. If \a toolbar has not    been added to the main window, this function returns zero.    \sa addToolBar() addToolBarBreak() Qt::ToolBarArea*/Qt::ToolBarArea QMainWindow::toolBarArea(QToolBar *toolbar) const{ return d_func()->layout->toolBarArea(toolbar); }#endif // QT_NO_TOOLBAR#ifndef QT_NO_DOCKWIDGET/*!    Adds the given \a dockwidget to the specified \a area.*/void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget){    Q_ASSERT_X(dockwidget->isAreaAllowed(area),               "QMainWindow::addDockWidget", "specified 'area' is not an allowed area");    Qt::Orientation orientation = Qt::Vertical;    switch (area) {    case Qt::TopDockWidgetArea:    case Qt::BottomDockWidgetArea:        orientation = Qt::Horizontal;        break;    default:        break;    }    addDockWidget(area, dockwidget, orientation);#ifdef Q_WS_MAC     //drawer support    extern bool qt_mac_is_macdrawer(const QWidget *); //qwidget_mac.cpp    if (qt_mac_is_macdrawer(dockwidget)) {        extern bool qt_mac_set_drawer_preferred_edge(QWidget *, Qt::DockWidgetArea); //qwidget_mac.cpp        qt_mac_set_drawer_preferred_edge(dockwidget, area);        if (dockwidget->isVisible()) {            dockwidget->hide();            dockwidget->show();        }    }#endif}/*!    Adds \a dockwidget into the given \a area in the direction    specified by the \a orientation.*/void QMainWindow::addDockWidget(Qt::DockWidgetArea area, QDockWidget *dockwidget,                                Qt::Orientation orientation){    // add a window to an area, placing done relative to the previous    Q_ASSERT_X(dockwidget->isAreaAllowed(area),               "QMainWindow::addDockWidget", "specified 'area' is not an allowed area");    d_func()->layout->addDockWidget(area, dockwidget, orientation);    if (isVisible())        d_func()->layout->relayout();}/*!    \fn void QMainWindow::splitDockWidget(QDockWidget *first, QDockWidget *second, Qt::Orientation orientation)    Splits the space covered by the \a first dock widget into two parts,    moves the \a first dock widget into the first part, and moves the    \a second dock widget into the second part.    The \a orientation specifies how the space is divided: A Qt::Horizontal    split places the second dock widget to the right of the first; a    Qt::Vertical split places the second dock widget below the first.    \e Note: The Qt::LayoutDirection influences the order of the dock widgets    in the two parts of the divided area. When right-to-left layout direction    is enabled, the placing of the dock widgets will be reversed.*/void QMainWindow::splitDockWidget(QDockWidget *after, QDockWidget *dockwidget,                                  Qt::Orientation orientation){    Q_ASSERT_X(dockwidget->isAreaAllowed(dockWidgetArea(after)),               "QMainWindow::splitDockWidget", "specified 'area' is not an allowed area");    d_func()->layout->splitDockWidget(after, dockwidget, orientation);    if (isVisible())        d_func()->layout->relayout();}/*!    Removes the \a dockwidget from the main window layout and hides    it. Note that the \a dockwidget is \e not deleted.*/void QMainWindow::removeDockWidget(QDockWidget *dockwidget){    if (dockwidget) {        d_func()->layout->removeRecursive(dockwidget);        dockwidget->hide();    }}/*!    Returns the Qt::DockWidgetArea for \a dockwidget. If \a dockwidget    has not been added to the main window, this function returns zero.    \sa addDockWidget() splitDockWidget() Qt::DockWidgetArea*/Qt::DockWidgetArea QMainWindow::dockWidgetArea(QDockWidget *dockwidget) const{ return d_func()->layout->dockWidgetArea(dockwidget); }#endif // QT_NO_DOCKWIDGET/*!    Saves the current state of this mainwindow's toolbars and    dockwidgets. The \a version number is stored as part of the data.    The \link QObject::objectName objectName\endlink property is used    to identify each QToolBar and QDockWidget.  You should make sure    that this property is unique for each QToolBar and QDockWidget you    add to the QMainWindow    To restore the saved state, pass the return value and \a version    number to restoreState().    \sa restoreState()*/QByteArray QMainWindow::saveState(int version) const{    QByteArray data;    QDataStream stream(&data, QIODevice::WriteOnly);    stream << QMainWindowLayout::VersionMarker;    stream << version;    d_func()->layout->saveState(stream);    return data;}/*!    Restores the \a state of this mainwindow's toolbars and    dockwidgets. The \a version number is compared with that stored    in \a state. If they do not match, the mainwindow's state is left    unchanged, and this function returns \c false; otherwise, the state    is restored, and this function returns \c true.    \sa saveState()*/bool QMainWindow::restoreState(const QByteArray &state, int version){    if (state.isEmpty())        return false;    QByteArray sd = state;    QDataStream stream(&sd, QIODevice::ReadOnly);    int marker, v;    stream >> marker;    stream >> v;    if (stream.status() != QDataStream::Ok || marker != QMainWindowLayout::VersionMarker || v != version)        return false;    bool restored = d_func()->layout->restoreState(stream);    if (isVisible())        QApplication::postEvent(this, new QResizeEvent(size(), size()));    return restored;}/*! \reimp */bool QMainWindow::event(QEvent *event){    Q_D(QMainWindow);#ifndef QT_NO_TOOLBAR    if (event->type() == QEvent::ToolBarChange) {        QList<QToolBar *> toolbars = qFindChildren<QToolBar *>(this);        QSize minimumSize = d->layout->minimumSize();        for (int i = 0; i < toolbars.size(); ++i) {            QToolBar *toolbar = toolbars.at(i);            toolbar->setVisible(!toolbar->isVisible());        }        QApplication::sendPostedEvents(this, QEvent::LayoutRequest);        QSize newMinimumSize = d->layout->minimumSize();        QSize delta = newMinimumSize - minimumSize;        resize(size() + delta);        return true;    } else#endif    if (event->type() == QEvent::StatusTip) {#ifndef QT_NO_STATUSBAR        if (QStatusBar *sb = d->layout->statusBar())            sb->showMessage(static_cast<QStatusTipEvent*>(event)->tip());        else#endif            static_cast<QStatusTipEvent*>(event)->ignore();        return true;    } else if (event->type() == QEvent::StyleChange) {        if (!d->explicitIconSize)            setIconSize(QSize());    }    return QWidget::event(event);}/*!    \reimp*/void QMainWindow::contextMenuEvent(QContextMenuEvent *event){    // only show the context menu for direct QDockWidget and QToolBar    // children    QWidget *child = childAt(event->pos());    while (child && child != this) {#ifndef QT_NO_DOCKWIDGET        if (QDockWidget *dw = qobject_cast<QDockWidget *>(child)) {            if (dw->parentWidget() != this)                return;            if (dw->widget()                && dw->widget()->geometry().contains(child->mapFrom(this, event->pos()))) {                // ignore the event if the mouse is over the QDockWidget contents                return;            }            break;        }#endif // QT_NO_DOCKWIDGET#ifndef QT_NO_TOOLBAR        if (QToolBar *tb = qobject_cast<QToolBar *>(child)) {            if (tb->parentWidget() != this)                return;            break;        }#endif        child = child->parentWidget();    }    if (child == this)        return;#ifndef QT_NO_MENU    QMenu *popup = createPopupMenu();    if (!popup)	return;    popup->exec(event->globalPos());    delete popup;    event->accept();#endif}#ifndef QT_NO_MENU/*!    This function is called to create a popup menu when the user    right-clicks on the menu bar, a toolbar or a dock widget. If you    want to create a custom popup menu, reimplement this function and    return the created popup menu. Ownership of the popup menu is    transferred to the caller.*/QMenu *QMainWindow::createPopupMenu(){    Q_D(QMainWindow);    QMenu *menu = 0;#ifndef QT_NO_DOCKWIDGET    QList<QDockWidget *> dockwidgets = qFindChildren<QDockWidget *>(this);    if (dockwidgets.size()) {        menu = new QMenu(this);        for (int i = 0; i < dockwidgets.size(); ++i) {            QDockWidget *dockWidget = dockwidgets.at(i);            if (dockWidget->parentWidget() == this                && d->layout->contains(dockWidget)) {                menu->addAction(dockwidgets.at(i)->toggleViewAction());            }        }        menu->addSeparator();    }#endif // QT_NO_DOCKWIDGET#ifndef QT_NO_TOOLBAR    QList<QToolBar *> toolbars = qFindChildren<QToolBar *>(this);    if (toolbars.size()) {        if (!menu)            menu = new QMenu(this);        for (int i = 0; i < toolbars.size(); ++i) {            QToolBar *toolBar = toolbars.at(i);            if (toolBar->parentWidget() == this                && d->layout->contains(toolBar)) {                menu->addAction(toolbars.at(i)->toggleViewAction());            }        }    }#endif    Q_UNUSED(d);    return menu;}#endif // QT_NO_MENU#endif // QT_NO_MAINWINDOW

⌨️ 快捷键说明

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