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

📄 qdockarealayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** 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 "QtGui/qwidget.h"#include "QtGui/qtabbar.h"#include "QtGui/qstyle.h"#include "QtCore/qvariant.h"#include "qdockarealayout_p.h"#include "qdockwidget.h"#include "qmainwindow.h"#include "qwidgetanimator_p.h"#include "qmainwindowlayout_p.h"#include "qdockwidget_p.h"#include <private/qlayoutengine_p.h>#include <qdebug.h>#include <qpainter.h>#include <qstyleoption.h>#ifndef QT_NO_DOCKWIDGETenum { StateFlagVisible = 1, StateFlagFloating = 2 };/******************************************************************************** QDockAreaLayoutItem*/QDockAreaLayoutItem::QDockAreaLayoutItem(QLayoutItem *_widgetItem)    : widgetItem(_widgetItem), subinfo(0), pos(0), size(-1), gap(false),        keep_size(false){}QDockAreaLayoutItem::QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo)    : widgetItem(0), subinfo(_subinfo), pos(0), size(-1), gap(false),        keep_size(false){}QDockAreaLayoutItem::QDockAreaLayoutItem(const QDockAreaLayoutItem &other)    : widgetItem(other.widgetItem), subinfo(0), pos(other.pos),        size(other.size), gap(other.gap), keep_size(other.keep_size){    if (other.subinfo != 0)        subinfo = new QDockAreaLayoutInfo(*other.subinfo);    Q_ASSERT(widgetItem == 0 || subinfo == 0);}QDockAreaLayoutItem::~QDockAreaLayoutItem(){    delete subinfo;}bool QDockAreaLayoutItem::skip() const{    if (gap)        return false;    if (widgetItem != 0)        return widgetItem->isEmpty();    if (subinfo != 0) {        for (int i = 0; i < subinfo->item_list.count(); ++i) {            if (!subinfo->item_list.at(i).skip())                return false;        }    }    return true;}QSize QDockAreaLayoutItem::minimumSize() const{    if (widgetItem != 0)        return widgetItem->minimumSize();    if (subinfo != 0)        return subinfo->minimumSize();    return QSize(0, 0);}QSize QDockAreaLayoutItem::maximumSize() const{    if (widgetItem != 0)        return widgetItem->maximumSize();    if (subinfo != 0)        return subinfo->maximumSize();    return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);}bool QDockAreaLayoutItem::expansive(Qt::Orientation o) const{    if (gap)        return false;    if (widgetItem != 0)        return ((widgetItem->expandingDirections() & o) == o);    if (subinfo != 0)        return subinfo->expansive(o);    return false;}QSize QDockAreaLayoutItem::sizeHint() const{    if (widgetItem != 0)        return widgetItem->sizeHint();    if (subinfo != 0)        return subinfo->sizeHint();    return QSize(-1, -1);}QDockAreaLayoutItem    &QDockAreaLayoutItem::operator = (const QDockAreaLayoutItem &other){    widgetItem = other.widgetItem;    if (other.subinfo == 0)        subinfo = 0;    else        subinfo = new QDockAreaLayoutInfo(*other.subinfo);    pos = other.pos;    size = other.size;    gap = other.gap;    return *this;}/******************************************************************************** QDockAreaLayoutInfo*/#ifndef QT_NO_TABBARstatic quintptr tabId(const QDockAreaLayoutItem &item){    if (item.widgetItem == 0)        return 0;    return reinterpret_cast<quintptr>(item.widgetItem->widget());}#endifQDockAreaLayoutInfo::QDockAreaLayoutInfo()    : sep(0), dockPos(QInternal::LeftDock), o(Qt::Horizontal), rect(0, 0, -1, -1), mainWindow(0)#ifndef QT_NO_TABBAR    , tabbed(false), tabBar(0), tabBarShape(QTabBar::RoundedSouth)#endif{}QDockAreaLayoutInfo::QDockAreaLayoutInfo(int _sep, QInternal::DockPosition _dockPos,                                            Qt::Orientation _o, int tbshape,                                            QMainWindow *window)    : sep(_sep), dockPos(_dockPos), o(_o), rect(0, 0, -1, -1), mainWindow(window)#ifndef QT_NO_TABBAR    , tabbed(false), tabBar(0), tabBarShape(static_cast<QTabBar::Shape>(tbshape))#endif{#ifdef QT_NO_TABBAR    Q_UNUSED(tbshape);#endif}QSize QDockAreaLayoutInfo::size() const{    return isEmpty() ? QSize(0, 0) : rect.size();}void QDockAreaLayoutInfo::clear(){    item_list.clear();    rect = QRect(0, 0, -1, -1);#ifndef QT_NO_TABBAR    tabbed = false;    tabBar = 0;#endif}bool QDockAreaLayoutInfo::isEmpty() const{    return next(-1) == -1;}QSize QDockAreaLayoutInfo::minimumSize() const{    if (isEmpty())        return QSize(0, 0);    int a = 0, b = 0;    bool first = true;    for (int i = 0; i < item_list.size(); ++i) {        const QDockAreaLayoutItem &item = item_list.at(i);        if (item.skip())            continue;        QSize min_size = item.minimumSize();#ifndef QT_NO_TABBAR        if (tabbed) {            a = qMax(a, pick(o, min_size));        } else#endif        {            if (!first)                a += sep;            a += pick(o, min_size);        }        b = qMax(b, perp(o, min_size));        first = false;    }    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;#ifndef QT_NO_TABBAR    if (tabbed) {        QSize tbm = tabBarMinimumSize();        switch (tabBarShape) {            case QTabBar::RoundedNorth:            case QTabBar::RoundedSouth:                result.rheight() += tbm.height();                result.rwidth() = qMax(tbm.width(), result.width());                break;            case QTabBar::RoundedEast:            case QTabBar::RoundedWest:                result.rheight() = qMax(tbm.height(), result.height());                result.rwidth() += tbm.width();                break;            default:                break;        }    }#endif // QT_NO_TABBAR    return result;}QSize QDockAreaLayoutInfo::maximumSize() const{    if (isEmpty())        return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);    int a = 0, b = QWIDGETSIZE_MAX;#ifndef QT_NO_TABBAR    if (tabbed)        a = QWIDGETSIZE_MAX;#endif    int min_perp = 0;    bool first = true;    for (int i = 0; i < item_list.size(); ++i) {        const QDockAreaLayoutItem &item = item_list.at(i);        if (item.skip())            continue;        QSize max_size = item.maximumSize();        min_perp = qMax(min_perp, perp(o, item.minimumSize()));#ifndef QT_NO_TABBAR        if (tabbed) {            a = qMin(a, pick(o, max_size));        } else#endif        {            if (!first)                a += sep;            a += pick(o, max_size);        }        b = qMin(b, perp(o, max_size));        a = qMin(a, int(QWIDGETSIZE_MAX));        b = qMin(b, int(QWIDGETSIZE_MAX));        first = false;    }    b = qMax(b, min_perp);    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;#ifndef QT_NO_TABBAR    if (tabbed) {        QSize tbh = tabBarSizeHint();        switch (tabBarShape) {            case QTabBar::RoundedNorth:            case QTabBar::RoundedSouth:                result.rheight() += tbh.height();                break;            case QTabBar::RoundedEast:            case QTabBar::RoundedWest:                result.rwidth() += tbh.width();                break;            default:                break;        }    }#endif // QT_NO_TABBAR    return result;}QSize QDockAreaLayoutInfo::sizeHint() const{    if (isEmpty())        return QSize(0, 0);    int a = 0, b = 0;    bool prev_gap = false;    bool first = true;    int min_perp = 0;    int max_perp = QWIDGETSIZE_MAX;    for (int i = 0; i < item_list.size(); ++i) {        const QDockAreaLayoutItem &item = item_list.at(i);        if (item.skip())            continue;        bool gap = item.gap;        QSize size_hint = item.sizeHint();        min_perp = qMax(min_perp, perp(o, item.minimumSize()));        max_perp = qMin(max_perp, perp(o, item.maximumSize()));#ifndef QT_NO_TABBAR        if (tabbed) {            a = qMax(a, gap ? item.size : pick(o, size_hint));        } else#endif        {            if (!first && !gap && !prev_gap)                a += sep;            a += gap ? item.size : pick(o, size_hint);        }        b = qMax(b, perp(o, size_hint));        prev_gap = gap;        first = false;    }    max_perp = qMax(max_perp, min_perp);    b = qMax(b, min_perp);    b = qMin(b, max_perp);    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;#ifndef QT_NO_TABBAR    if (tabbed) {        QSize tbh = tabBarSizeHint();        switch (tabBarShape) {            case QTabBar::RoundedNorth:            case QTabBar::RoundedSouth:                result.rheight() += tbh.height();                result.rwidth() = qMax(tbh.width(), result.width());                break;            case QTabBar::RoundedEast:            case QTabBar::RoundedWest:                result.rheight() = qMax(tbh.height(), result.height());                result.rwidth() += tbh.width();                break;            default:                break;        }    }#endif // QT_NO_TABBAR    return result;}bool QDockAreaLayoutInfo::expansive(Qt::Orientation o) const{    for (int i = 0; i < item_list.size(); ++i) {        if (item_list.at(i).expansive(o))            return true;    }    return false;}/* QDockAreaLayoutInfo::maximumSize() doesn't return the real max size. For example,   if the layout is empty, it returns QWIDGETSIZE_MAX. This is so that empty dock areas   don't constrain the size of the QMainWindow, but sometimes we really need to know the   maximum size. Also, these functions take into account widgets that want to keep their   size (f.ex. when they are hidden and then shown, they should not change size).*/static int realMinSize(const QDockAreaLayoutInfo &info){    int result = 0;    bool first = true;    for (int i = 0; i < info.item_list.size(); ++i) {        const QDockAreaLayoutItem &item = info.item_list.at(i);        if (item.skip())            continue;        int min = 0;        if (item.keep_size && item.size != -1)            min = item.size;        else            min = pick(info.o, item.minimumSize());        if (!first)            result += info.sep;        result += min;        first = false;    }    return result;}static int realMaxSize(const QDockAreaLayoutInfo &info){    int result = 0;    bool first = true;    for (int i = 0; i < info.item_list.size(); ++i) {        const QDockAreaLayoutItem &item = info.item_list.at(i);        if (item.skip())            continue;        int max = 0;        if (item.keep_size && item.size != -1)            max = item.size;        else            max = pick(info.o, item.maximumSize());        if (!first)            result += info.sep;        result += max;        if (result >= QWIDGETSIZE_MAX)            return QWIDGETSIZE_MAX;        first = false;

⌨️ 快捷键说明

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