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

📄 qdockarealayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    }    return result;}void QDockAreaLayoutInfo::fitItems(){#ifndef QT_NO_TABBAR    if (tabbed) {        return;    }#endif    QVector<QLayoutStruct> layout_struct_list(item_list.size()*2);    int j = 0;    int size = pick(o, rect.size());    int min_size = realMinSize(*this);    int max_size = realMaxSize(*this);    int last_index = -1;    bool prev_gap = false;    bool first = true;    for (int i = 0; i < item_list.size(); ++i) {        QDockAreaLayoutItem &item = item_list[i];        if (item.skip())            continue;        bool gap = item.gap;        if (!first && !gap && !prev_gap) {            QLayoutStruct &ls = layout_struct_list[j++];            ls.init();            ls.minimumSize = sep;            ls.maximumSize = sep;            ls.sizeHint = sep;            ls.empty = false;        }        if (item.keep_size) {            // Check if the item can keep its size, without violating size constraints            // of other items.            if (size < min_size) {                // There is too little space to keep this widget's size                item.keep_size = false;                min_size -= item.size;                min_size += pick(o, item.minimumSize());                min_size = qMax(0, min_size);            } else if (size > max_size) {                // There is too much space to keep this widget's size                item.keep_size = false;                max_size -= item.size;                max_size += pick(o, item.maximumSize());                max_size = qMin<int>(QWIDGETSIZE_MAX, max_size);            }        }        last_index = j;        QLayoutStruct &ls = layout_struct_list[j++];        ls.init();        ls.empty = false;        if (gap || item.keep_size) {            ls.minimumSize = ls.maximumSize = ls.sizeHint = item.size;            ls.expansive = false;            ls.stretch = 0;        } else {            ls.maximumSize = pick(o, item.maximumSize());            ls.expansive = item.expansive(o);            ls.minimumSize = pick(o, item.minimumSize());            ls.sizeHint = item.size == -1 ? pick(o, item.sizeHint()) : item.size;            ls.stretch = ls.expansive ? ls.sizeHint : 0;        }        item.keep_size = false;        prev_gap = gap;        first = false;    }    layout_struct_list.resize(j);    // If there is more space than the widgets can take (due to maximum size constraints),    // we detect it here and stretch the last widget to take up the rest of the space.    if (size > max_size && last_index != -1) {        layout_struct_list[last_index].maximumSize = QWIDGETSIZE_MAX;        layout_struct_list[last_index].expansive = true;    }    qGeomCalc(layout_struct_list, 0, j, pick(o, rect.topLeft()), size, 0);    j = 0;    prev_gap = false;    first = true;    for (int i = 0; i < item_list.size(); ++i) {        QDockAreaLayoutItem &item = item_list[i];        if (item.skip())            continue;        bool gap = item.gap;        if (!first && !gap && !prev_gap)            ++j;        const QLayoutStruct &ls = layout_struct_list.at(j++);        item.size = ls.size;        item.pos = ls.pos;        if (item.subinfo != 0) {            item.subinfo->rect = itemRect(i);            item.subinfo->fitItems();        }        prev_gap = gap;        first = false;    }}static QInternal::DockPosition dockPos(const QRect &rect, const QPoint &_pos,                                        Qt::Orientation o,                                        bool nestingEnabled,                                        QDockAreaLayoutInfo::TabMode tabMode){    if (tabMode == QDockAreaLayoutInfo::ForceTabs)        return QInternal::DockCount;    QPoint pos = _pos - rect.topLeft();    int x = pos.x();    int y = pos.y();    int w = rect.width();    int h = rect.height();    if (tabMode != QDockAreaLayoutInfo::NoTabs) {        // is it in the center?        if (nestingEnabled) {        /*             2/3                +--------------+                |              |                |   CCCCCCCC   |           2/3  |   CCCCCCCC   |                |   CCCCCCCC   |                |              |                +--------------+     */            QRect center(w/6, h/6, 2*w/3, 2*h/3);            if (center.contains(pos))                return QInternal::DockCount;        } else if (o == Qt::Horizontal) {        /*             2/3                +--------------+                |   CCCCCCCC   |                |   CCCCCCCC   |                |   CCCCCCCC   |                |   CCCCCCCC   |                |   CCCCCCCC   |                +--------------+     */            if (x > w/6 && x < w*5/6)                return QInternal::DockCount;        } else {        /*                +--------------+                |              |           2/3  |CCCCCCCCCCCCCC|                |CCCCCCCCCCCCCC|                |              |                +--------------+     */            if (y > h/6 && y < 5*h/6)                return QInternal::DockCount;        }    }    // not in the center. which edge?    if (nestingEnabled) {        if (o == Qt::Horizontal) {    /*       1/3  1/3 1/3            +------------+     (we've already ruled out the center)            |LLLLTTTTRRRR|            |LLLLTTTTRRRR|            |LLLLBBBBRRRR|            |LLLLBBBBRRRR|            +------------+    */            if (x < w/3)                return QInternal::LeftDock;            if (x > 2*w/3)                return QInternal::RightDock;            if (y < h/2)                return QInternal::TopDock;            return QInternal::BottomDock;        } else {    /*      +------------+     (we've already ruled out the center)        1/3 |TTTTTTTTTTTT|            |LLLLLLRRRRRR|        1/3 |LLLLLLRRRRRR|        1/3 |BBBBBBBBBBBB|            +------------+    */            if (y < h/3)                return QInternal::TopDock;            if (y > 2*h/3)                return QInternal::BottomDock;            if (x < w/2)                return QInternal::LeftDock;            return QInternal::RightDock;        }    } else {        if (o == Qt::Horizontal) {            return x < w/2                    ? QInternal::LeftDock                    : QInternal::RightDock;        } else {            return y < h/2                    ? QInternal::TopDock                    : QInternal::BottomDock;        }    }}QList<int> QDockAreaLayoutInfo::gapIndex(const QPoint& _pos,                        bool nestingEnabled, TabMode tabMode) const{    QList<int> result;    QRect item_rect;    int item_index = 0;#ifndef QT_NO_TABBAR    if (tabbed) {        item_rect = tabContentRect();    } else#endif    {        int pos = pick(o, _pos);        int last = -1;        for (int i = 0; i < item_list.size(); ++i) {            const QDockAreaLayoutItem &item = item_list.at(i);            if (item.skip())                continue;            last = i;            if (item.pos + item.size < pos)                continue;            if (item.subinfo != 0#ifndef QT_NO_TABBAR                && !item.subinfo->tabbed#endif                ) {                result = item.subinfo->gapIndex(_pos, nestingEnabled,                                                    tabMode);                result.prepend(i);                return result;            }            item_rect = itemRect(i);            item_index = i;            break;        }        if (item_rect.isNull()) {            result.append(last + 1);            return result;        }    }    Q_ASSERT(!item_rect.isNull());    QInternal::DockPosition dock_pos        = ::dockPos(item_rect, _pos, o, nestingEnabled, tabMode);    switch (dock_pos) {        case QInternal::LeftDock:            if (o == Qt::Horizontal)                result << item_index;            else                result << item_index << 0; // this subinfo doesn't exist yet, but insertGap()                                           // handles this by inserting it            break;        case QInternal::RightDock:            if (o == Qt::Horizontal)                result << item_index + 1;            else                result << item_index << 1;            break;        case QInternal::TopDock:            if (o == Qt::Horizontal)                result << item_index << 0;            else                result << item_index;            break;        case QInternal::BottomDock:            if (o == Qt::Horizontal)                result << item_index << 1;            else                result << item_index + 1;            break;        case  QInternal::DockCount:            result << (-item_index - 1) << 0;   // negative item_index means "on top of"                                                // -item_index - 1, insertGap()                                                // will insert a tabbed subinfo            break;        default:            break;    }    return result;}static inline int shrink(QLayoutStruct &ls, int delta){    if (ls.empty)        return 0;    int old_size = ls.size;    ls.size = qMax(ls.size - delta, ls.minimumSize);    return old_size - ls.size;}static inline int grow(QLayoutStruct &ls, int delta){    if (ls.empty)        return 0;    int old_size = ls.size;    ls.size = qMin(ls.size + delta, ls.maximumSize);    return ls.size - old_size;}static int separatorMove(QVector<QLayoutStruct> &list, int index, int delta, int sep){    // adjust sizes    int pos = -1;    for (int i = 0; i < list.size(); ++i) {        const QLayoutStruct &ls = list.at(i);        if (!ls.empty) {            pos = ls.pos;            break;        }    }    if (pos == -1)        return 0;    if (delta > 0) {        int growlimit = 0;        for (int i = 0; i<=index; ++i) {            const QLayoutStruct &ls = list.at(i);            if (ls.empty)                continue;            if (ls.maximumSize == QLAYOUTSIZE_MAX) {                growlimit = QLAYOUTSIZE_MAX;                break;            }            growlimit += ls.maximumSize - ls.size;        }        if (delta > growlimit)            delta = growlimit;        int d = 0;        for (int i = index + 1; d < delta && i < list.count(); ++i)            d += shrink(list[i], delta - d);        delta = d;        d = 0;        for (int i = index; d < delta && i >= 0; --i)            d += grow(list[i], delta - d);    } else if (delta < 0) {        int growlimit = 0;        for (int i = index + 1; i < list.count(); ++i) {            const QLayoutStruct &ls = list.at(i);            if (ls.empty)                continue;            if (ls.maximumSize == QLAYOUTSIZE_MAX) {                growlimit = QLAYOUTSIZE_MAX;                break;            }            growlimit += ls.maximumSize - ls.size;        }        if (-delta > growlimit)            delta = -growlimit;        int d = 0;        for (int i = index; d < -delta && i >= 0; --i)            d += shrink(list[i], -delta - d);        delta = -d;        d = 0;        for (int i = index + 1; d < -delta && i < list.count(); ++i)            d += grow(list[i], -delta - d);    }    // adjust positions    bool first = true;    for (int i = 0; i < list.size(); ++i) {        QLayoutStruct &ls = list[i];        if (ls.empty)            continue;        if (!first)            pos += sep;        ls.pos = pos;        pos += ls.size;        first = false;    }    return delta;}int QDockAreaLayoutInfo::separatorMove(int index, int delta, QVector<QLayoutStruct> *cache){#ifndef QT_NO_TABBAR    Q_ASSERT(!tabbed);#endif    if (cache->isEmpty()) {        QVector<QLayoutStruct> &list = *cache;        list.resize(item_list.size());        for (int i = 0; i < item_list.size(); ++i) {            const QDockAreaLayoutItem &item = item_list.at(i);            QLayoutStruct &ls = list[i];            Q_ASSERT(!item.gap);            if (item.skip()) {                ls.empty = true;            } else {                ls.empty = false;                ls.pos = item.pos;                ls.size = item.size;                ls.minimumSize = pick(o, item.minimumSize());                ls.maximumSize = pick(o, item.maximumSize());            }        }    }    QVector<QLayoutStruct> list = *cache;    delta = ::separatorMove(list, index, delta, sep);    for (int i = 0; i < item_list.size(); ++i) {        QDockAreaLayoutItem &item = item_list[i];        if (item.skip())            continue;        QLayoutStruct &ls = list[i];        item.size = ls.size;        item.pos = ls.pos;        if (item.subinfo != 0) {            item.subinfo->rect = itemRect(i);            item.subinfo->fitItems();        }    }    return delta;}void QDockAreaLayoutInfo::unnest(int index){    QDockAreaLayoutItem &item = item_list[index];    if (item.subinfo == 0)        return;    if (item.subinfo->item_list.count() > 1)        return;    Q_ASSERT(item.subinfo->item_list.count() != 0);    if (item.subinfo->item_list.count() == 1) {        QDockAreaLayoutItem &child = item.subinfo->item_list.first();        if (child.widgetItem != 0) {            item.widgetItem = child.widgetItem;            delete item.subinfo;            item.subinfo = 0;        } else if (child.subinfo != 0) {            QDockAreaLayoutInfo *tmp = item.subinfo;            item.subinfo = child.subinfo;

⌨️ 快捷键说明

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