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

📄 qtoolbararealayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** 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 <QWidgetItem>#include <QToolBar>#include <QStyleOption>#include <qdebug.h>#include "qtoolbararealayout_p.h"#include "qmainwindowlayout_p.h"#include "qwidgetanimator_p.h"#include "qtoolbarlayout_p.h"#include "qtoolbar_p.h"/******************************************************************************** QToolBarAreaLayoutItem*/#ifndef QT_NO_TOOLBARQSize QToolBarAreaLayoutItem::minimumSize() const{    if (skip())        return QSize(0, 0);    return qSmartMinSize(static_cast<QWidgetItem*>(widgetItem));}QSize QToolBarAreaLayoutItem::sizeHint() const{    if (skip())        return QSize(0, 0);    QWidget *wid = widgetItem->widget();    QSize s = wid->sizeHint().expandedTo(wid->minimumSizeHint());    if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)        s.setWidth(0);    if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)        s.setHeight(0);    s = s.boundedTo(wid->maximumSize())        .expandedTo(wid->minimumSize());    return s;}bool QToolBarAreaLayoutItem::skip() const{    if (gap)        return false;    return widgetItem == 0 || widgetItem->isEmpty();}/******************************************************************************** QToolBarAreaLayoutLine*/QToolBarAreaLayoutLine::QToolBarAreaLayoutLine(Qt::Orientation orientation)    : o(orientation){}QSize QToolBarAreaLayoutLine::sizeHint() const{    int a = 0, b = 0;    for (int i = 0; i < toolBarItems.count(); ++i) {        const QToolBarAreaLayoutItem &item = toolBarItems.at(i);        if (item.skip())            continue;        QSize sh = item.sizeHint();        a += pick(o, sh);        b = qMax(b, perp(o, sh));    }    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;    return result;}QSize QToolBarAreaLayoutLine::minimumSize() const{    int a = 0, b = 0;    for (int i = 0; i < toolBarItems.count(); ++i) {        const QToolBarAreaLayoutItem &item = toolBarItems[i];        if (item.skip())            continue;        QSize ms = item.minimumSize();        a += pick(o, ms);        b = qMax(b, perp(o, ms));    }    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;    return result;}void QToolBarAreaLayoutLine::fitLayout(){    int last = -1;    int min = pick(o, minimumSize());    int space = pick(o, rect.size());    int extra = qMax(0, space - min);    for (int i = 0; i < toolBarItems.count(); ++i) {        QToolBarAreaLayoutItem &item = toolBarItems[i];        if (item.skip())            continue;        int itemMin = pick(o, item.minimumSize());        int itemHint = pick(o, item.sizeHint());        int itemExtra = qMin(itemHint - itemMin, extra);        item.size = itemMin + itemExtra;        extra -= itemExtra;        last = i;    }    // calculate the positions from the sizes    int pos = 0;    for (int i = 0; i < toolBarItems.count(); ++i) {        QToolBarAreaLayoutItem &item = toolBarItems[i];        if (item.skip())            continue;        item.pos = pos;        if (i == last) // stretch the last item to the end of the line            item.size = qMax(0, pick(o, rect.size()) - item.pos);        pos += item.size;    }}bool QToolBarAreaLayoutLine::skip() const{    for (int i = 0; i < toolBarItems.count(); ++i) {        if (!toolBarItems.at(i).skip())            return false;    }    return true;}/******************************************************************************** QToolBarAreaLayoutInfo*/QToolBarAreaLayoutInfo::QToolBarAreaLayoutInfo(QInternal::DockPosition pos)    : dockPos(pos){    switch (pos) {        case QInternal::LeftDock:        case QInternal::RightDock:            o = Qt::Vertical;            break;        case QInternal::TopDock:        case QInternal::BottomDock:            o = Qt::Horizontal;            break;        default:            o = Qt::Horizontal;            break;    }}QSize QToolBarAreaLayoutInfo::sizeHint() const{    int a = 0, b = 0;    for (int i = 0; i < lines.count(); ++i) {        const QToolBarAreaLayoutLine &l = lines.at(i);        if (l.skip())            continue;        QSize hint = l.sizeHint();        a = qMax(a, pick(o, hint));        b += perp(o, hint);    }    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;    return result;}QSize QToolBarAreaLayoutInfo::minimumSize() const{    int a = 0, b = 0;    for (int i = 0; i < lines.count(); ++i) {        const QToolBarAreaLayoutLine &l = lines.at(i);        if (l.skip())            continue;        QSize m = l.minimumSize();        a = qMax(a, pick(o, m));        b += perp(o, m);    }    QSize result;    rpick(o, result) = a;    rperp(o, result) = b;    return result;}void QToolBarAreaLayoutInfo::fitLayout(){    int b = 0;    bool reverse = dockPos == QInternal::RightDock || dockPos == QInternal::BottomDock;    int i = reverse ? lines.count() - 1 : 0;    for (;;) {        if (reverse && i < 0 || !reverse && i == lines.count())            break;        QToolBarAreaLayoutLine &l = lines[i];        if (!l.skip()) {            if (o == Qt::Horizontal) {                l.rect.setLeft(rect.left());                l.rect.setRight(rect.right());                l.rect.setTop(b + rect.top());                b += l.sizeHint().height();                l.rect.setBottom(b - 1 + rect.top());            } else {                l.rect.setTop(rect.top());                l.rect.setBottom(rect.bottom());                l.rect.setLeft(b + rect.left());                b += l.sizeHint().width();                l.rect.setRight(b - 1 + rect.left());            }            l.fitLayout();        }        i += reverse ? -1 : 1;    }}void QToolBarAreaLayoutInfo::insertToolBar(QToolBar *before, QToolBar *toolBar){    toolBar->setOrientation(o);    if (before == 0) {        if (lines.isEmpty())            lines.append(QToolBarAreaLayoutLine(o));        lines.last().toolBarItems.append(new QWidgetItem(toolBar));        return;    }    for (int j = 0; j < lines.count(); ++j) {        QToolBarAreaLayoutLine &line = lines[j];        for (int k = 0; k < line.toolBarItems.count(); ++k) {            if (line.toolBarItems.at(k).widgetItem->widget() == before) {                line.toolBarItems.insert(k, new QWidgetItem(toolBar));                return;            }        }    }}void QToolBarAreaLayoutInfo::removeToolBar(QToolBar *toolBar){    for (int j = 0; j < lines.count(); ++j) {        QToolBarAreaLayoutLine &line = lines[j];        for (int k = 0; k < line.toolBarItems.count(); ++k) {            QToolBarAreaLayoutItem &item = line.toolBarItems[k];            if (item.widgetItem->widget() == toolBar) {                delete item.widgetItem;                item.widgetItem = 0;                line.toolBarItems.removeAt(k);                if (line.toolBarItems.isEmpty() && j < lines.count() - 1)                    lines.removeAt(j);                return;            }        }    }}void QToolBarAreaLayoutInfo::insertToolBarBreak(QToolBar *before){    if (before == 0) {        if (!lines.isEmpty() && lines.last().toolBarItems.isEmpty())            return;        lines.append(QToolBarAreaLayoutLine(o));        return;    }    for (int j = 0; j < lines.count(); ++j) {        QToolBarAreaLayoutLine &line = lines[j];        for (int k = 0; k < line.toolBarItems.count(); ++k) {            if (line.toolBarItems.at(k).widgetItem->widget() == before) {                if (k == 0)                    return;                QToolBarAreaLayoutLine newLine(o);                newLine.toolBarItems = line.toolBarItems.mid(k);                line.toolBarItems = line.toolBarItems.mid(0, k);                lines.insert(j + 1, newLine);                return;            }        }    }}void QToolBarAreaLayoutInfo::removeToolBarBreak(QToolBar *before){    for (int j = 0; j < lines.count(); ++j) {        const QToolBarAreaLayoutLine &line = lines.at(j);        for (int k = 0; k < line.toolBarItems.count(); ++k) {            if (line.toolBarItems.at(k).widgetItem->widget() == before) {                if (k != 0)                    return;                if (j == 0)                    return;                lines[j - 1].toolBarItems += lines[j].toolBarItems;                lines.removeAt(j);                return;            }        }    }}QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const{    int p = pick(o, pos);

⌨️ 快捷键说明

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