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

📄 qworkspace.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    QPoint wpos(maxRect.left(), maxRect.top());    bool firstPass = true;    do {        if (y + w->height() > maxRect.bottom()) {            overlap = -1;        } else if(x + w->width() > maxRect.right()) {            overlap = -2;        } else {            overlap = 0;            r1.setRect(x, y, w->width(), w->height());            QWidget *l;            QList<QWidget *>::Iterator it(widgets.begin());            while (it != widgets.end()) {                l = *it;                ++it;                if (maxWindow == l)                    r2 = maxRestore;                else                    r2.setRect(l->x(), l->y(), l->width(), l->height());                if (r2.intersects(r1)) {                    r2.setCoords(qMax(r1.left(), r2.left()),                                 qMax(r1.top(), r2.top()),                                 qMin(r1.right(), r2.right()),                                 qMin(r1.bottom(), r2.bottom())                                );                    overlap += (r2.right() - r2.left()) *                               (r2.bottom() - r2.top());                }            }        }        if (overlap == 0) {            wpos = QPoint(x, y);            break;        }        if (firstPass) {            firstPass = false;            minOverlap = overlap;        } else if (overlap >= 0 && overlap < minOverlap) {            minOverlap = overlap;            wpos = QPoint(x, y);        }        if (overlap > 0) {            possible = maxRect.right();            if (possible - w->width() > x) possible -= w->width();            QWidget *l;            QList<QWidget *>::Iterator it(widgets.begin());            while (it != widgets.end()) {                l = *it;                ++it;                if (maxWindow == l)                    r2 = maxRestore;                else                    r2.setRect(l->x(), l->y(), l->width(), l->height());                if((y < r2.bottom()) && (r2.top() < w->height() + y)) {                    if(r2.right() > x)                        possible = possible < r2.right() ?                                   possible : r2.right();                    if(r2.left() - w->width() > x)                        possible = possible < r2.left() - w->width() ?                                   possible : r2.left() - w->width();                }            }            x = possible;        } else if (overlap == -2) {            x = maxRect.left();            possible = maxRect.bottom();            if (possible - w->height() > y) possible -= w->height();            QWidget *l;            QList<QWidget *>::Iterator it(widgets.begin());            while (it != widgets.end()) {                l = *it;                ++it;                if (maxWindow == l)                    r2 = maxRestore;                else                    r2.setRect(l->x(), l->y(), l->width(), l->height());                if(r2.bottom() > y)                    possible = possible < r2.bottom() ?                               possible : r2.bottom();                if(r2.top() - w->height() > y)                    possible = possible < r2.top() - w->height() ?                               possible : r2.top() - w->height();            }            y = possible;        }    }    while(overlap != 0 && overlap != -1);    w->move(wpos);    updateWorkspace();}void QWorkspacePrivate::insertIcon(QWidget* w){    Q_Q(QWorkspace);    if (!w || icons.contains(w))        return;    icons.append(w);    if (w->parentWidget() != q) {        w->setParent(q, 0);        w->move(0,0);    }    QRect cr = updateWorkspace();    int x = 0;    int y = cr.height() - w->height();    QList<QWidget *>::Iterator it(icons.begin());    while (it != icons.end()) {        QWidget* i = *it;        ++it;        if (x > 0 && x + i->width() > cr.width()){            x = 0;            y -= i->height();        }        if (i != w &&            i->geometry().intersects(QRect(x, y, w->width(), w->height())))            x += i->width();    }    w->move(x, y);    if (q->isVisibleTo(q->parentWidget())) {        w->show();        w->lower();    }    updateWorkspace();}void QWorkspacePrivate::removeIcon(QWidget* w){    if (icons.removeAll(w))        w->hide();}/*! \reimp  */void QWorkspace::resizeEvent(QResizeEvent *){    Q_D(QWorkspace);    if (d->maxWindow) {        d->maxWindow->adjustToFullscreen();        if (d->maxWindow->windowWidget())            d->maxWindow->windowWidget()->overrideWindowState(Qt::WindowMaximized);    }    d->updateWorkspace();}/*! \reimp */void QWorkspace::showEvent(QShowEvent *e){    Q_D(QWorkspace);    if (d->maxWindow)        d->showMaximizeControls();    QWidget::showEvent(e);    if (d->becomeActive) {        d->activateWindow(d->becomeActive);        d->becomeActive = 0;    } else if (d->windows.count() > 0 && !d->active) {        d->activateWindow(d->windows.first()->windowWidget());    }//     // force a frame repaint - this is a workaround for what seems to be a bug//     // introduced when changing the QWidget::show() implementation. Might be//     // a windows bug as well though.//     for (int i = 0; i < d->windows.count(); ++i) {// 	QWorkspaceChild* c = d->windows.at(i);//         c->update(c->rect());//     }    d->updateWorkspace();}/*! \reimp */void QWorkspace::hideEvent(QHideEvent *){    Q_D(QWorkspace);    if (!isVisible())        d->hideMaximizeControls();}/*! \reimp */void QWorkspace::paintEvent(QPaintEvent *){    Q_D(QWorkspace);    if (d->background.style() != Qt::NoBrush) {        QPainter p(this);        p.fillRect(0, 0, width(), height(), d->background);    }}void QWorkspacePrivate::minimizeWindow(QWidget* w){    QWorkspaceChild* c = findChild(w);    if (!w || !(w->windowFlags() & Qt::WindowMinimizeButtonHint))        return;    if (c) {        bool wasMax = false;        if (c == maxWindow) {            wasMax = true;            maxWindow = 0;            hideMaximizeControls();            for (QList<QWorkspaceChild *>::Iterator it(windows.begin()); it != windows.end(); ++it) {                QWorkspaceChild* c = *it;                if (c->titlebar)                    c->titlebar->setMovable(true);                c->widgetResizeHandler->setActive(true);            }        }        c->hide();        if (wasMax)            c->setGeometry(maxRestore);        if (!focus.contains(c))            focus.append(c);        insertIcon(c->iconWidget());        if (!maxWindow)            activateWindow(w);        updateWorkspace();        w->overrideWindowState(Qt::WindowMinimized);        c->overrideWindowState(Qt::WindowMinimized);    }}void QWorkspacePrivate::normalizeWindow(QWidget* w){    Q_Q(QWorkspace);    QWorkspaceChild* c = findChild(w);    if (!w)        return;    if (c) {        w->overrideWindowState(Qt::WindowNoState);        hideMaximizeControls();        if (q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q) || !maxWindow) {            if (w->minimumSize() != w->maximumSize())                c->widgetResizeHandler->setActive(true);            if (c->titlebar)                c->titlebar->setMovable(true);        }        w->overrideWindowState(Qt::WindowNoState);        c->overrideWindowState(Qt::WindowNoState);        if (c == maxWindow) {            c->setGeometry(maxRestore);            maxWindow = 0;        } else {            if (c->iconw)                removeIcon(c->iconw->parentWidget());            c->show();        }        hideMaximizeControls();        for (QList<QWorkspaceChild *>::Iterator it(windows.begin()); it != windows.end(); ++it) {            QWorkspaceChild* c = *it;            if (c->titlebar)                c->titlebar->setMovable(true);            if (c->childWidget && c->childWidget->minimumSize() != c->childWidget->maximumSize())                c->widgetResizeHandler->setActive(true);        }        activateWindow(w, true);        updateWorkspace();    }}void QWorkspacePrivate::maximizeWindow(QWidget* w){    Q_Q(QWorkspace);    QWorkspaceChild* c = findChild(w);    if (!w || !(w->windowFlags() & Qt::WindowMaximizeButtonHint))        return;    if (!c || c == maxWindow)        return;    bool updatesEnabled = q->updatesEnabled();    q->setUpdatesEnabled(false);    if (c->iconw && icons.contains(c->iconw->parentWidget()))        normalizeWindow(w);    QRect r(c->geometry());    QWorkspaceChild *oldMaxWindow = maxWindow;    maxWindow = c;    c->adjustToFullscreen();    c->show();    c->internalRaise();    if (oldMaxWindow != c) {        if (oldMaxWindow) {            oldMaxWindow->setGeometry(maxRestore);            oldMaxWindow->overrideWindowState(Qt::WindowNoState);            if(oldMaxWindow->windowWidget())                oldMaxWindow->windowWidget()->overrideWindowState(Qt::WindowNoState);        }        maxRestore = r;    }    activateWindow(w);    showMaximizeControls();    if(q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) {        if (!active && becomeActive) {            active = (QWorkspaceChild*)becomeActive->parentWidget();            active->setActive(true);            becomeActive = 0;            emit q->windowActivated(active->windowWidget());        }        c->widgetResizeHandler->setActive(false);        if (c->titlebar)            c->titlebar->setMovable(false);    }    updateWorkspace();    w->overrideWindowState(Qt::WindowMaximized);    c->overrideWindowState(Qt::WindowMaximized);    q->setUpdatesEnabled(updatesEnabled);}void QWorkspacePrivate::showWindow(QWidget* w){    if (w->isMinimized() && (w->windowFlags() & Qt::WindowMinimizeButtonHint))        minimizeWindow(w);    else if ((maxWindow || w->isMaximized()) && w->windowFlags() & Qt::WindowMaximizeButtonHint)        maximizeWindow(w);    else if (w->windowFlags() & Qt::WindowMaximizeButtonHint)        normalizeWindow(w);    else        w->parentWidget()->show();    if (maxWindow)        maxWindow->internalRaise();    updateWorkspace();}QWorkspaceChild* QWorkspacePrivate::findChild(QWidget* w){    QList<QWorkspaceChild *>::Iterator it(windows.begin());    while (it != windows.end()) {        QWorkspaceChild* c = *it;        ++it;        if (c->windowWidget() == w)            return c;    }    return 0;}/*!    Returns a list of all visible or minimized child windows. If \a    order is CreationOrder (the default), the windows are listed in    the order in which they were inserted into the workspace. If \a    order is StackingOrder, the windows are listed in their stacking    order, with the topmost window as the last item in the list.*/QWidgetList QWorkspace::windowList(WindowOrder order) const{    Q_D(const QWorkspace);    QWidgetList windows;    if (order == StackingOrder) {        QObjectList cl = children();        for (int i = 0; i < cl.size(); ++i) {            QWorkspaceChild *c = qobject_cast<QWorkspaceChild*>(cl.at(i));            if (c && c->isWindowOrIconVisible())                windows.append(c->windowWidget());        }    } else {        QList<QWorkspaceChild *>::ConstIterator it(d->windows.begin());        while (it != d->windows.end()) {            QWorkspaceChild* c = *it;            ++it;            if (c && c->isWindowOrIconVisible())                windows.append(c->windowWidget());        }    }    return windows;}/*! \reimp */bool QWorkspace::event(QEvent *e){    Q_D(QWorkspace);    if (e->type() == QEvent::Shortcut) {        QShortcutEvent *se = static_cast<QShortcutEvent *>(e);        const char *theSlot = d->shortcutMap.value(se->shortcutId(), 0);        if (theSlot)            QMetaObject::invokeMethod(this, theSlot);    } else if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut){        return true;    }    return QWidget::event(e);}/*! \reimp */

⌨️ 快捷键说明

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