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

📄 qmainwindowlayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qmainwindowlayout_p.h"#include "qdockarealayout_p.h"#ifndef QT_NO_MAINWINDOW#include "qdockwidget.h"#include "qdockwidget_p.h"#include "qtoolbar_p.h"#include "qmainwindow.h"#include "qmainwindowlayout_p.h"#include "qtoolbar.h"#include "qtoolbarlayout_p.h"#include "qwidgetanimator_p.h"#include "qrubberband.h"#include "qdockwidget_p.h"#include "qtabbar_p.h"#include <qapplication.h>#include <qstatusbar.h>#include <qstring.h>#include <qstyle.h>#include <qvarlengtharray.h>#include <qstack.h>#include <qmap.h>#include <qtimer.h>#include <qdebug.h>#include <private/qlayoutengine_p.h>#ifdef Q_WS_MAC#include <private/qcore_mac_p.h>#endif#if 0/******************************************************************************** debug*/#include <stdio.h>#include <QTextStream>static QTextStream qout(stderr, QIODevice::WriteOnly);#ifndef QT_NO_DOCKWIDGETvoid dumpLayout(const QDockAreaLayoutInfo &layout, QString indent);void dumpLayout(const QDockAreaLayoutItem &item, QString indent){    qout << indent << "QDockAreaLayoutItem: "            << "pos: " << item.pos << " size:" << item.size            << " gap:" << item.gap << '\n';    if (item.widgetItem != 0) {        qout << indent << "widget: "            << item.widgetItem->widget()->metaObject()->className()            << ' ' << item.widgetItem->widget()->windowTitle() << '\n';    } else if (item.subinfo != 0) {        qout << indent << "subinfo:\n";        dumpLayout(*item.subinfo, indent + QLatin1String("  "));    }    qout.flush();}void dumpLayout(const QDockAreaLayoutInfo &layout, QString indent){    qout << indent << "QDockAreaLayoutInfo: "            << layout.rect.left() << ','            << layout.rect.top() << ' '            << layout.rect.width() << 'x'            << layout.rect.height()            << " orient:" << layout.o            << " tabbed:" << layout.tabbed            << " tbshape:" << layout.tabBarShape << '\n';    for (int i = 0; i < layout.item_list.count(); ++i) {        qout << indent << "Item: " << i << '\n';        dumpLayout(layout.item_list.at(i), indent + QLatin1String("  "));    }    qout.flush();};void dumpLayout(const QDockAreaLayout &layout, QString indent){    qout << indent << "QDockAreaLayout: "            << layout.rect.left() << ','            << layout.rect.top() << ' '            << layout.rect.width() << 'x'            << layout.rect.height() << '\n';    for (int i = 0; i < QInternal::DockCount; ++i) {        qout << indent << "Dock area: " << i << '\n';        dumpLayout(layout.docks[i], indent + QLatin1String("  "));    }    qout.flush();};#endif // QT_NO_DOCKWIDGET#endif // 0/******************************************************************************** QMainWindowLayoutState*/// we deal with all the #ifndefferry here so QMainWindowLayout code is cleanQMainWindowLayoutState::QMainWindowLayoutState(QMainWindow *win)    :#ifndef QT_NO_TOOLBAR    toolBarAreaLayout(win),#endif#ifndef QT_NO_DOCKWIDGET    dockAreaLayout(win)#else    centralWidgetItem(0)#endif{    mainWindow = win;}QSize QMainWindowLayoutState::sizeHint() const{    QSize result(0, 0);#ifndef QT_NO_DOCKWIDGET    result = dockAreaLayout.sizeHint();#else    if (centralWidgetItem != 0)        result = centralWidgetItem->sizeHint();#endif#ifndef QT_NO_TOOLBAR    result = toolBarAreaLayout.sizeHint(result);#endif // QT_NO_TOOLBAR    return result;}QSize QMainWindowLayoutState::minimumSize() const{    QSize result(0, 0);#ifndef QT_NO_DOCKWIDGET    result = dockAreaLayout.minimumSize();#else    if (centralWidgetItem != 0)        result = centralWidgetItem->minimumSize();#endif#ifndef QT_NO_TOOLBAR    result = toolBarAreaLayout.minimumSize(result);#endif // QT_NO_TOOLBAR    return result;}void QMainWindowLayoutState::apply(bool animated){#ifndef QT_NO_TOOLBAR    toolBarAreaLayout.apply(animated);#endif#ifndef QT_NO_DOCKWIDGET//    dumpLayout(dockAreaLayout, QString());    dockAreaLayout.apply(animated);#else    if (centralWidgetItem != 0) {        QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());        Q_ASSERT(layout != 0);        layout->widgetAnimator->animate(centralWidgetItem->widget(), centralWidgetRect, animated);    }#endif}void QMainWindowLayoutState::fitLayout(){    QRect r;#ifdef QT_NO_TOOLBAR    r = rect;#else    toolBarAreaLayout.rect = rect;    r = toolBarAreaLayout.fitLayout();#endif // QT_NO_TOOLBAR#ifndef QT_NO_DOCKWIDGET    dockAreaLayout.rect = r;    dockAreaLayout.fitLayout();#else    centralWidgetRect = r;#endif}void QMainWindowLayoutState::deleteAllLayoutItems(){#ifndef QT_NO_TOOLBAR    toolBarAreaLayout.deleteAllLayoutItems();#endif#ifndef QT_NO_DOCKWIDGET    dockAreaLayout.deleteAllLayoutItems();#endif}void QMainWindowLayoutState::deleteCentralWidgetItem(){#ifndef QT_NO_DOCKWIDGET    delete dockAreaLayout.centralWidgetItem;    dockAreaLayout.centralWidgetItem = 0;#else    delete centralWidgetItem;    centralWidgetItem = 0;#endif}QLayoutItem *QMainWindowLayoutState::itemAt(int index, int *x) const{#ifndef QT_NO_TOOLBAR    if (QLayoutItem *ret = toolBarAreaLayout.itemAt(x, index))        return ret;#endif#ifndef QT_NO_DOCKWIDGET    if (QLayoutItem *ret = dockAreaLayout.itemAt(x, index))        return ret;#else    if (centralWidgetItem != 0 && (*x)++ == index)        return centralWidgetItem;#endif    return 0;}QLayoutItem *QMainWindowLayoutState::takeAt(int index, int *x){#ifndef QT_NO_TOOLBAR    if (QLayoutItem *ret = toolBarAreaLayout.takeAt(x, index))        return ret;#endif#ifndef QT_NO_DOCKWIDGET    if (QLayoutItem *ret = dockAreaLayout.takeAt(x, index))        return ret;#else    if (centralWidgetItem != 0 && (*x)++ == index) {        QLayoutItem *ret = centralWidgetItem;        centralWidgetItem = 0;        return ret;    }#endif    return 0;}QList<int> QMainWindowLayoutState::indexOf(QWidget *widget) const{    QList<int> result;#ifndef QT_NO_TOOLBAR    // is it a toolbar?    if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {        result = toolBarAreaLayout.indexOf(toolBar);        if (!result.isEmpty())            result.prepend(0);        return result;    }#endif#ifndef QT_NO_DOCKWIDGET    // is it a dock widget?    if (QDockWidget *dockWidget = qobject_cast<QDockWidget *>(widget)) {        result = dockAreaLayout.indexOf(dockWidget);        if (!result.isEmpty())            result.prepend(1);        return result;    }#endif //QT_NO_DOCKWIDGET    return result;}bool QMainWindowLayoutState::contains(QWidget *widget) const{#ifndef QT_NO_DOCKWIDGET    if (dockAreaLayout.centralWidgetItem != 0 && dockAreaLayout.centralWidgetItem->widget() == widget)        return true;    if (!dockAreaLayout.indexOf(widget).isEmpty())        return true;#else    if (centralWidgetItem != 0 && centralWidgetItem->widget() == widget)        return true;#endif#ifndef QT_NO_TOOLBAR    if (!toolBarAreaLayout.indexOf(widget).isEmpty())        return true;#endif    return false;}void QMainWindowLayoutState::setCentralWidget(QWidget *widget){    QLayoutItem *item = 0;    if (widget != 0)        item = new QWidgetItem(widget);#ifndef QT_NO_DOCKWIDGET    dockAreaLayout.centralWidgetItem = item;#else    centralWidgetItem = item;#endif}QWidget *QMainWindowLayoutState::centralWidget() const{    QLayoutItem *item = 0;#ifndef QT_NO_DOCKWIDGET    item = dockAreaLayout.centralWidgetItem;#else    item = centralWidgetItem;#endif    if (item != 0)        return item->widget();    return 0;}QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget,                                            const QPoint &pos) const{    QList<int> result;#ifndef QT_NO_TOOLBAR    // is it a toolbar?    if (qobject_cast<QToolBar*>(widget) != 0) {        result = toolBarAreaLayout.gapIndex(pos);        if (!result.isEmpty())            result.prepend(0);        return result;    }#endif#ifndef QT_NO_DOCKWIDGET    // is it a dock widget?    if (qobject_cast<QDockWidget *>(widget) != 0) {        result = dockAreaLayout.gapIndex(pos);        if (!result.isEmpty())            result.prepend(1);        return result;    }#endif //QT_NO_DOCKWIDGET    return result;}bool QMainWindowLayoutState::insertGap(QList<int> path, QLayoutItem *item){    if (path.isEmpty())        return false;    int i = path.takeFirst();#ifndef QT_NO_TOOLBAR    if (i == 0) {        Q_ASSERT(qobject_cast<QToolBar*>(item->widget()) != 0);        return toolBarAreaLayout.insertGap(path, item);    }#endif#ifndef QT_NO_DOCKWIDGET    if (i == 1) {        Q_ASSERT(qobject_cast<QDockWidget*>(item->widget()) != 0);        return dockAreaLayout.insertGap(path, item);    }#endif //QT_NO_DOCKWIDGET    return false;}void QMainWindowLayoutState::remove(QList<int> path){    int i = path.takeFirst();#ifndef QT_NO_TOOLBAR    if (i == 0)        toolBarAreaLayout.remove(path);#endif#ifndef QT_NO_DOCKWIDGET    if (i == 1)        dockAreaLayout.remove(path);#endif //QT_NO_DOCKWIDGET}void QMainWindowLayoutState::clear(){#ifndef QT_NO_TOOLBAR    toolBarAreaLayout.clear();#endif#ifndef QT_NO_DOCKWIDGET    dockAreaLayout.clear();#else    centralWidgetRect = QRect(0, 0, -1, -1);#endif    rect = QRect(0, 0, -1, -1);}bool QMainWindowLayoutState::isValid() const{    return rect.isValid();}QLayoutItem *QMainWindowLayoutState::item(QList<int> path){    int i = path.takeFirst();#ifndef QT_NO_TOOLBAR    if (i == 0)        return toolBarAreaLayout.item(path).widgetItem;#endif#ifndef QT_NO_DOCKWIDGET    if (i == 1)        return dockAreaLayout.item(path).widgetItem;#endif //QT_NO_DOCKWIDGET    return 0;}QRect QMainWindowLayoutState::itemRect(QList<int> path) const{    int i = path.takeFirst();#ifndef QT_NO_TOOLBAR    if (i == 0)        return toolBarAreaLayout.itemRect(path);#endif#ifndef QT_NO_DOCKWIDGET    if (i == 1)        return dockAreaLayout.itemRect(path);#endif //QT_NO_DOCKWIDGET    return QRect();}QRect QMainWindowLayoutState::gapRect(QList<int> path) const{    int i = path.takeFirst();#ifndef QT_NO_TOOLBAR    if (i == 0)        return toolBarAreaLayout.itemRect(path);#endif#ifndef QT_NO_DOCKWIDGET    if (i == 1)        return dockAreaLayout.gapRect(path);

⌨️ 快捷键说明

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