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

📄 q3dockarea.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*!    Removes the dock window \a w from the dock area. If \a    makeFloating is true, \a w gets floated, and if \a swap is true,    the orientation of \a w gets swapped. If \a fixNewLines is true    (the default) newlines in the area will be fixed.    You should never need to call this function yourself. Use    Q3DockWindow::dock() and Q3DockWindow::undock() instead.*/void Q3DockArea::removeDockWindow(Q3DockWindow *w, bool makeFloating, bool swap, bool fixNewLines){    w->removeEventFilter(this);    Q3DockWindow *dockWindow = 0;    int i = findDockWindow(w);    if (i == -1)        return;    dockWindow = dockWindows.at(i);    dockWindows.removeAt(i);    QList<Q3DockWindow *> lineStarts = layout->lineStarts();    if (fixNewLines && lineStarts.contains(dockWindow) && i < dockWindows.count())        dockWindows.at(i)->setNewLine(true);    if (makeFloating) {        QWidget *p = parentWidget() ? parentWidget() : window();        dockWindow->setParent(p, Qt::WType_Dialog | Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool);        dockWindow->move(0, 0);    }    if (swap)        dockWindow->resize(dockWindow->height(), dockWindow->width());    updateLayout();    if (dockWindows.isEmpty())        setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));}int Q3DockArea::findDockWindow(Q3DockWindow *w){    return dockWindows.indexOf(w);}void Q3DockArea::updateLayout(){    layout->invalidate();    layout->activate();}/*! \reimp */bool Q3DockArea::eventFilter(QObject *o, QEvent *e){    if (e->type() == QEvent::Close) {        if (qobject_cast<Q3DockWindow*>(o)) {            o->removeEventFilter(this);            QApplication::sendEvent(o, e);            if (((QCloseEvent*)e)->isAccepted())                removeDockWindow((Q3DockWindow*)o, false, false);            return true;        }    }    return false;}/*! \internal    Invalidates the offset of the next dock window in the dock area. */void Q3DockArea::invalidNextOffset(Q3DockWindow *dw){    int i = dockWindows.indexOf(dw);    if (i == -1 || i >= (int)dockWindows.count() - 1)        return;    if ((dw = dockWindows.at(++i)))        dw->setOffset(0);}/*!    \property Q3DockArea::count    \brief the number of dock windows in the dock area*/int Q3DockArea::count() const{    return dockWindows.count();}/*!    \property Q3DockArea::empty    \brief whether the dock area is empty*/bool Q3DockArea::isEmpty() const{    return dockWindows.isEmpty();}/*!    Returns a list of the dock windows in the dock area.*/QList<Q3DockWindow *> Q3DockArea::dockWindowList() const{    return dockWindows;}/*!    Lines up the dock windows in this dock area to minimize wasted    space. If \a keepNewLines is true, only space within lines is    cleaned up. If \a keepNewLines is false the number of lines might    be changed.*/void Q3DockArea::lineUp(bool keepNewLines){    for (int i = 0; i < dockWindows.size(); ++i) {        Q3DockWindow *dw = dockWindows.at(i);        dw->setOffset(0);        if (!keepNewLines)            dw->setNewLine(false);    }    layout->activate();}Q3DockArea::DockWindowData *Q3DockArea::dockWindowData(Q3DockWindow *w){    DockWindowData *data = new DockWindowData;    data->index = findDockWindow(w);    if (data->index == -1) {        delete data;        return 0;    }    QList<Q3DockWindow *> lineStarts = layout->lineStarts();    int i = -1;    for (int j = 0; j < dockWindows.size(); ++j) {        Q3DockWindow *dw = dockWindows.at(j);        if (lineStarts.contains(dw))            ++i;        if (dw == w)            break;    }    data->line = i;    data->offset = point_pos(QPoint(fix_x(w), w->y()), orientation());    data->area = this;    data->fixedExtent = w->fixedExtent();    return data;}void Q3DockArea::dockWindow(Q3DockWindow *dockWindow, DockWindowData *data){    if (!data)        return;    dockWindow->setParent(this);    dockWindow->move(0, 0);    dockWindow->installEventFilter(this);    dockWindow->dockArea = this;    dockWindow->updateGui();    if (dockWindows.isEmpty()) {        dockWindows.append(dockWindow);    } else {        QList<Q3DockWindow *> lineStarts = layout->lineStarts();        int index = 0;        if (lineStarts.count() > data->line)            index = dockWindows.indexOf(lineStarts.at(data->line));        if (index == -1)            index = 0;        bool firstTime = true;        int offset = data->offset;        for (int i = index; i < dockWindows.size(); ++i) {            Q3DockWindow *dw = dockWindows.at(i);            if (!firstTime && lineStarts.contains(dw))                break;            if (offset <                 point_pos(fix_pos(dw), orientation()) + size_extent(dw->size(), orientation()) / 2)                break;            index++;            firstTime = false;        }        if (index >= 0 && index < dockWindows.count() &&             dockWindows.at(index)->newLine() && lineOf(index) == data->line) {            dockWindows.at(index)->setNewLine(false);            dockWindow->setNewLine(true);        } else {            dockWindow->setNewLine(false);        }        dockWindows.insert(index, dockWindow);    }    dockWindow->show();    dockWindow->setFixedExtentWidth(data->fixedExtent.width());    dockWindow->setFixedExtentHeight(data->fixedExtent.height());    updateLayout();    setSizePolicy(QSizePolicy(orientation() == Qt::Horizontal ? QSizePolicy::Expanding : QSizePolicy::Minimum,                                orientation() == Qt::Vertical ? QSizePolicy::Expanding : QSizePolicy::Minimum));}/*!    Returns true if dock window \a dw could be docked into the dock    area; otherwise returns false.    \sa setAcceptDockWindow()*/bool Q3DockArea::isDockWindowAccepted(Q3DockWindow *dw){    if (!dw)        return false;    if (forbiddenWidgets.contains(dw))        return false;    Q3MainWindow *mw = qobject_cast<Q3MainWindow*>(parentWidget());    if (!mw)        return true;    if (!mw->hasDockWindow(dw))        return false;    if (!mw->isDockEnabled(this))        return false;    if (!mw->isDockEnabled(dw, this))        return false;    return true;}/*!    If \a accept is true, dock window \a dw can be docked in the dock    area. If \a accept is false, dock window \a dw cannot be docked in    the dock area.    \sa isDockWindowAccepted()*/void Q3DockArea::setAcceptDockWindow(Q3DockWindow *dw, bool accept){    if (accept)        forbiddenWidgets.removeAll(dw);    else if (forbiddenWidgets.contains(dw))        forbiddenWidgets.append(dw);}void Q3DockArea::invalidateFixedSizes(){    for (int i = 0; i < dockWindows.size(); ++i) {        Q3DockWindow *dw = dockWindows.at(i);        if (orientation() == Qt::Horizontal)            dw->setFixedExtentWidth(-1);        else            dw->setFixedExtentHeight(-1);    }}int Q3DockArea::maxSpace(int hint, Q3DockWindow *dw){    int index = findDockWindow(dw);    if (index == -1 || index + 1 >= (int)dockWindows.count()) {        if (orientation() == Qt::Horizontal)            return dw->width();        return dw->height();    }    Q3DockWindow *w = 0;    int i = 0;    do {        w = dockWindows.at(index + (++i));    } while (i + 1 < (int)dockWindows.count() && (!w || w->isHidden()));    if (!w || !w->isResizeEnabled() || i >= (int)dockWindows.count()) {        if (orientation() == Qt::Horizontal)            return dw->width();        return dw->height();    }    int min = 0;    Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(w);    if (orientation() == Qt::Horizontal) {        w->setFixedExtentWidth(-1);        if (!tb)            min = qMax(w->minimumSize().width(), w->minimumSizeHint().width());        else            min = w->sizeHint().width();    } else {        w->setFixedExtentHeight(-1);        if (!tb)            min = qMax(w->minimumSize().height(), w->minimumSizeHint().height());        else            min = w->sizeHint().height();    }    int diff = hint - (orientation() == Qt::Horizontal ? dw->width() : dw->height());    if ((orientation() == Qt::Horizontal ? w->width() : w->height()) - diff < min)        hint = (orientation() == Qt::Horizontal ? dw->width() : dw->height()) + (orientation() == Qt::Horizontal ? w->width() : w->height()) - min;    diff = hint - (orientation() == Qt::Horizontal ? dw->width() : dw->height());    if (orientation() == Qt::Horizontal)        w->setFixedExtentWidth(w->width() - diff);    else        w->setFixedExtentHeight(w->height() - diff);    return hint;}void Q3DockArea::setFixedExtent(int d, Q3DockWindow *dw){    QList<Q3DockWindow *> lst;    for (int i = 0; i < dockWindows.size(); ++i) {        Q3DockWindow *w = dockWindows.at(i);        if (w->isHidden())            continue;        if (orientation() == Qt::Horizontal) {            if (dw->y() != w->y())                continue;        } else {            if (dw->x() != w->x())                continue;        }        if (orientation() == Qt::Horizontal)            d = qMax(d, w->minimumHeight());        else            d = qMax(d, w->minimumWidth());        if (w->isResizeEnabled())            lst.append(w);    }    for (int i = 0; i < lst.size(); ++i) {        Q3DockWindow *w = lst.at(i);        if (orientation() == Qt::Horizontal)            w->setFixedExtentHeight(d);        else            w->setFixedExtentWidth(d);    }}bool Q3DockArea::isLastDockWindow(Q3DockWindow *dw){    int i = dockWindows.indexOf(dw);    if (i == -1 || i >= (int)dockWindows.count() - 1)        return true;    Q3DockWindow *w = 0;    if ((w = dockWindows.at(++i))) {        if (orientation() == Qt::Horizontal && dw->y() < w->y())            return true;        if (orientation() == Qt::Vertical && dw->x() < w->x())            return true;    } else {        return true;    }    return false;}#ifndef QT_NO_TEXTSTREAM/*!    \relates Q3DockArea    Writes the layout of the dock windows in dock area \a dockArea to    the text stream \a ts.*/QTextStream &operator<<(QTextStream &ts, const Q3DockArea &dockArea){    QString str;    QList<Q3DockWindow *> l = dockArea.dockWindowList();    for (int i = 0; i < l.size(); ++i) {        Q3DockWindow *dw = l.at(i);        str += QLatin1Char('[') + QString(dw->windowTitle()) + QLatin1Char(',') + QString::number((int)dw->offset()) +               QLatin1Char(',') + QString::number((int)dw->newLine()) + QLatin1Char(',') + QString::number(dw->fixedExtent().width()) +               QLatin1Char(',') + QString::number(dw->fixedExtent().height()) + QLatin1Char(',') + QString::number((int)!dw->isHidden()) + QLatin1Char(']');    }    ts << str << endl;    return ts;}/*!    \relates Q3DockArea    Reads the layout description of the dock windows in dock area \a    dockArea from the text stream \a ts and restores it. The layout    description must have been previously written by the operator<<()    function.*/QTextStream &operator>>(QTextStream &ts, Q3DockArea &dockArea){    QString s = ts.readLine();    QString name, offset, newLine, width, height, visible;    enum State { Pre, Name, Offset, NewLine, Width, Height, Visible, Post };    int state = Pre;    QChar c;    QList<Q3DockWindow *> l = dockArea.dockWindowList();    for (int i = 0; i < s.length(); ++i) {        c = s[i];        if (state == Pre && c == QLatin1Char('[')) {            state++;            continue;        }        if (c == QLatin1Char(',') &&             (state == Name || state == Offset || state == NewLine || state == Width || state == Height)) {            state++;            continue;        }        if (state == Visible && c == QLatin1Char(']')) {            for (int j = 0; j < l.size(); ++j) {                Q3DockWindow *dw = l.at(j);                if (QString(dw->windowTitle()) == name) {                    dw->setNewLine((bool)newLine.toInt());                    dw->setOffset(offset.toInt());                    dw->setFixedExtentWidth(width.toInt());                    dw->setFixedExtentHeight(height.toInt());                    if (!(bool)visible.toInt())                        dw->hide();                    else                        dw->show();                    break;                }            }            name = offset = newLine = width = height = visible = QLatin1String("");            state = Pre;            continue;        }        if (state == Name)            name += c;        else if (state == Offset)            offset += c;        else if (state == NewLine)            newLine += c;        else if (state == Width)            width += c;        else if (state == Height)            height += c;        else if (state == Visible)            visible += c;    }    dockArea.QWidget::layout()->invalidate();    dockArea.QWidget::layout()->activate();    return ts;}#endif#endif //QT_NO_MAINWINDOW

⌨️ 快捷键说明

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