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

📄 qtoolbararealayout.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                        r.setRight(line.rect.right());                        r.setTop(line.rect.top() + item.pos);                        r.setBottom(line.rect.top() + item.pos + item.size - 1);                    }                }                QWidget *widget = item.widgetItem->widget();                if (QToolBar *toolBar = qobject_cast<QToolBar*>(widget)) {                    QToolBarLayout *tbl = qobject_cast<QToolBarLayout*>(toolBar->layout());                    if (tbl->expanded) {                        QPoint tr = r.topRight();                        QSize size = tbl->expandedSize(r.size());                        r.setSize(size);                        r.moveTopRight(tr);                        if (r.bottom() > rect.bottom())                            r.moveBottom(rect.bottom());                        if (r.right() > rect.right())                            r.moveRight(rect.right());                        if (r.left() < 0)                            r.moveLeft(0);                        if (r.top() < 0)                            r.moveTop(0);                    }                }                QRect geo = r;                if (visible && dock.o == Qt::Horizontal)                    geo = QStyle::visualRect(dir, line.rect, geo);                layout->widgetAnimator->animate(widget, geo, animate);            }        }    }}bool QToolBarAreaLayout::toolBarBreak(QToolBar *toolBar) const{    for (int i = 0; i < QInternal::DockCount; ++i) {        const QToolBarAreaLayoutInfo &dock = docks[i];        for (int j = 0; j < dock.lines.count(); ++j) {            const QToolBarAreaLayoutLine &line = dock.lines.at(j);            for (int k = 0; k < line.toolBarItems.count(); ++k) {                if (line.toolBarItems.at(k).widgetItem->widget() == toolBar)                    return j > 0 && k == 0;            }        }    }    return false;}void QToolBarAreaLayout::getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const{    for (int i = 0; i < QInternal::DockCount; ++i) {        const QToolBarAreaLayoutInfo &dock = docks[i];        for (int j = 0; j < dock.lines.count(); ++j) {            const QToolBarAreaLayoutLine &line = dock.lines.at(j);            for (int k = 0; k < line.toolBarItems.count(); ++k) {                if (line.toolBarItems.at(k).widgetItem->widget() == toolBar) {                    if (line.toolBarItems.count() == 1)                        option->positionWithinLine = QStyleOptionToolBar::OnlyOne;                    else if (k == 0)                        option->positionWithinLine = QStyleOptionToolBar::Beginning;                    else if (k == line.toolBarItems.count() - 1)                        option->positionWithinLine = QStyleOptionToolBar::End;                    else                        option->positionWithinLine = QStyleOptionToolBar::Middle;                    if (dock.lines.count() == 1)                        option->positionOfLine = QStyleOptionToolBar::OnlyOne;                    else if (j == 0)                        option->positionOfLine = QStyleOptionToolBar::Beginning;                    else if (j == dock.lines.count() - 1)                        option->positionOfLine = QStyleOptionToolBar::End;                    else                        option->positionOfLine = QStyleOptionToolBar::Middle;                    return;                }            }        }    }}QList<int> QToolBarAreaLayout::indexOf(QWidget *toolBar) const{    QList<int> result;    bool found = false;    for (int i = 0; i < QInternal::DockCount; ++i) {        const QToolBarAreaLayoutInfo &dock = docks[i];        for (int j = 0; j < dock.lines.count(); ++j) {            const QToolBarAreaLayoutLine &line = dock.lines.at(j);            for (int k = 0; k < line.toolBarItems.count(); ++k) {                const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);                if (!item.gap && item.widgetItem->widget() == toolBar) {                    found = true;                    result.prepend(k);                    break;                }            }            if (found) {                result.prepend(j);                break;            }        }        if (found) {            result.prepend(i);            break;        }    }    return result;}QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const{    Qt::LayoutDirection dir = mainWindow->layoutDirection();    for (int i = 0; i < QInternal::DockCount; ++i) {        QPoint p = pos;        if (docks[i].o == Qt::Horizontal)            p = QStyle::visualPos(dir, docks[i].rect, p);        QList<int> result = docks[i].gapIndex(p);        if (!result.isEmpty()) {            result.prepend(i);            return result;        }    }    return QList<int>();}bool QToolBarAreaLayout::insertGap(QList<int> path, QLayoutItem *item){    Q_ASSERT(!path.isEmpty());    int i = path.takeFirst();    Q_ASSERT(i >= 0 && i < QInternal::DockCount);    return docks[i].insertGap(path, item);}void QToolBarAreaLayout::remove(QList<int> path){    docks[path.at(0)].lines[path.at(1)].toolBarItems.removeAt(path.at(2));}void QToolBarAreaLayout::clear(){    for (int i = 0; i < QInternal::DockCount; ++i)        docks[i].clear();    rect = QRect(0, 0, -1, -1);}QToolBarAreaLayoutItem &QToolBarAreaLayout::item(QList<int> path){    Q_ASSERT(path.count() == 3);    Q_ASSERT(path.at(0) >= 0 && path.at(0) < QInternal::DockCount);    QToolBarAreaLayoutInfo &info = docks[path.at(0)];    Q_ASSERT(path.at(1) >= 0 && path.at(1) < info.lines.count());    QToolBarAreaLayoutLine &line = info.lines[path.at(1)];    Q_ASSERT(path.at(2) >= 0 && path.at(2) < line.toolBarItems.count());    return line.toolBarItems[path.at(2)];}QRect QToolBarAreaLayout::itemRect(QList<int> path) const{    int i = path.takeFirst();    QRect r = docks[i].itemRect(path);    if (docks[i].o == Qt::Horizontal)        r = QStyle::visualRect(mainWindow->layoutDirection(),                                docks[i].rect, r);    return r;}QLayoutItem *QToolBarAreaLayout::plug(QList<int> path){    QToolBarAreaLayoutItem &item = this->item(path);    Q_ASSERT(item.gap);    Q_ASSERT(item.widgetItem != 0);    item.gap = false;    return item.widgetItem;}QLayoutItem *QToolBarAreaLayout::unplug(QList<int> path){    QToolBarAreaLayoutItem &item = this->item(path);    Q_ASSERT(!item.gap);    item.gap = true;    return item.widgetItem;}static QRect unpackRect(uint geom0, uint geom1, bool *floating){    *floating = geom0 & 1;    if (!*floating)        return QRect();    geom0 >>= 1;    int x = (int)(geom0 & 0x0000ffff) - 0x7FFF;    int y = (int)(geom1 & 0x0000ffff) - 0x7FFF;    geom0 >>= 16;    geom1 >>= 16;    int w = geom0 & 0x0000ffff;    int h = geom1 & 0x0000ffff;    return QRect(x, y, w, h);}static void packRect(uint *geom0, uint *geom1, const QRect &rect, bool floating){    *geom0 = 0;    *geom1 = 0;    if (!floating)        return;    // The 0x7FFF is half of 0xFFFF. We add it so we can handle negative coordinates on    // dual monitors. It's subtracted when unpacking.    *geom0 |= qMax(0, rect.width()) & 0x0000ffff;    *geom1 |= qMax(0, rect.height()) & 0x0000ffff;    *geom0 <<= 16;    *geom1 <<= 16;    *geom0 |= qMax(0, rect.x() + 0x7FFF) & 0x0000ffff;    *geom1 |= qMax(0, rect.y() + 0x7FFF) & 0x0000ffff;    // yeah, we chop one bit off the width, but it still has a range up to 32512    *geom0 <<= 1;    *geom0 |= 1;}void QToolBarAreaLayout::saveState(QDataStream &stream) const{    // save toolbar state    stream << (uchar) ToolBarStateMarkerEx;    int lineCount = 0;    for (int i = 0; i < QInternal::DockCount; ++i)        lineCount += docks[i].lines.count();    stream << lineCount;    for (int i = 0; i < QInternal::DockCount; ++i) {        const QToolBarAreaLayoutInfo &dock = docks[i];        for (int j = 0; j < dock.lines.count(); ++j) {            const QToolBarAreaLayoutLine &line = dock.lines.at(j);            stream << i << line.toolBarItems.count();            for (int k = 0; k < line.toolBarItems.count(); ++k) {                const QToolBarAreaLayoutItem &item = line.toolBarItems.at(k);                QWidget *widget = const_cast<QLayoutItem*>(item.widgetItem)->widget();                QString objectName = widget->objectName();                if (objectName.isEmpty()) {                    qWarning("QMainWindow::saveState(): 'objectName' not set for QToolBar %p '%s'",                                widget, widget->windowTitle().toLocal8Bit().constData());                }                stream << objectName;                stream << (uchar) !widget->isHidden();                stream << item.pos;                stream << item.size;                uint geom0, geom1;                packRect(&geom0, &geom1, widget->geometry(), widget->isWindow());                stream << geom0 << geom1;            }        }    }}bool QToolBarAreaLayout::restoreState(QDataStream &stream, const QList<QToolBar*> &_toolBars, uchar tmarker){    QList<QToolBar*> toolBars = _toolBars;    int lines;    stream >> lines;    for (int j = 0; j < lines; ++j) {        int pos;        stream >> pos;        if (pos < 0 || pos >= QInternal::DockCount)            return false;        int cnt;        stream >> cnt;        QToolBarAreaLayoutInfo &dock = docks[pos];        QToolBarAreaLayoutLine line(dock.o);        for (int k = 0; k < cnt; ++k) {            QToolBarAreaLayoutItem item;            QString objectName;            stream >> objectName;            uchar shown;            stream >> shown;            stream >> item.pos;            stream >> item.size;            /*               4.3.0 added floating toolbars, but failed to add the ability to restore them.               We need to store there geometry (four ints). We cannot change the format in a               patch release (4.3.1) by adding ToolBarStateMarkerEx2 to signal extra data. So               for now we'll pack it in the two legacy ints we no longer used in Qt4.3.0.               In 4.4, we should add ToolBarStateMarkerEx2 and fix this properly.            */            QRect rect;            bool floating = false;            uint geom0, geom1;            stream >> geom0;            if (tmarker == ToolBarStateMarkerEx) {                stream >> geom1;                rect = unpackRect(geom0, geom1, &floating);            }            QToolBar *toolBar = 0;            for (int x = 0; x < toolBars.count(); ++x) {                if (toolBars.at(x)->objectName() == objectName) {                    toolBar = toolBars.takeAt(x);                    break;                }            }            if (toolBar == 0) {                continue;            }            item.widgetItem = new QWidgetItem(toolBar);            toolBar->setOrientation(floating ? Qt::Horizontal : dock.o);            toolBar->setVisible(shown);            toolBar->d_func()->setWindowState(floating, true, rect);            line.toolBarItems.append(item);        }        dock.lines.append(line);    }    return stream.status() == QDataStream::Ok;}bool QToolBarAreaLayout::isEmpty() const{    for (int i = 0; i < QInternal::DockCount; ++i) {        if (!docks[i].lines.isEmpty())            return false;    }    return true;}#endif // QT_NO_TOOLBAR

⌨️ 快捷键说明

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