📄 qworkspace.cpp
字号:
d->updateWorkspace(); return child;#endif}/*! \reimp */void QWorkspace::childEvent(QChildEvent * e){ Q_D(QWorkspace); if (e->removed()) { if (d->windows.removeAll(static_cast<QWorkspaceChild*>(e->child()))) { d->focus.removeAll(static_cast<QWorkspaceChild*>(e->child())); if (d->maxWindow == e->child()) d->maxWindow = 0; d->updateWorkspace(); } }}/*! \reimp */#ifndef QT_NO_WHEELEVENTvoid QWorkspace::wheelEvent(QWheelEvent *e){ Q_D(QWorkspace); if (!scrollBarsEnabled()) return; // the scroll bars are children of the workspace, so if we receive // a wheel event we redirect to the scroll bars using a direct event // call, /not/ using sendEvent() because if the scroll bar ignores the // event QApplication::sendEvent() will propagate the event to the parent widget, // which is us, who /just/ sent it. if (d->vbar && d->vbar->isVisible() && !(e->modifiers() & Qt::AltModifier)) d->vbar->event(e); else if (d->hbar && d->hbar->isVisible()) d->hbar->event(e);}#endifvoid QWorkspacePrivate::activateWindow(QWidget* w, bool change_focus){ Q_Q(QWorkspace); if (!w) { active = 0; emit q->windowActivated(0); return; } if (!q->isVisible()) { becomeActive = w; return; } if (active && active->windowWidget() == w) { if (!isChildOf(q->focusWidget(), w)) // child window does not have focus active->setActive(true); return; } active = 0; // First deactivate all other workspace clients QList<QWorkspaceChild *>::Iterator it(windows.begin()); while (it != windows.end()) { QWorkspaceChild* c = *it; ++it; if (c->windowWidget() == w) active = c; else c->setActive(false); } if (!active) return; // Then activate the new one, so the focus is stored correctly active->setActive(true); if (!active) return; if (maxWindow && maxWindow != active && active->windowWidget() && (active->windowWidget()->windowFlags() & Qt::WindowMaximizeButtonHint)) active->showMaximized(); active->internalRaise(); if (change_focus) { int from = focus.indexOf(active); if (from >= 0) focus.move(from, focus.size() - 1); } updateWorkspace(); emit q->windowActivated(w);}/*! Returns a pointer to the widget corresponding to the active child window, or 0 if no window is active. \sa setActiveWindow()*/QWidget* QWorkspace::activeWindow() const{ Q_D(const QWorkspace); return d->active? d->active->windowWidget() : 0;}/*! Makes the child window that contains \a w the active child window. \sa activeWindow()*/void QWorkspace::setActiveWindow(QWidget *w){ Q_D(QWorkspace); d->activateWindow(w, true); if (w && w->isMinimized()) w->setWindowState(w->windowState() & ~Qt::WindowMinimized);}void QWorkspacePrivate::place(QWidget *w){ Q_Q(QWorkspace); QList<QWidget *> widgets; for (QList<QWorkspaceChild *>::Iterator it(windows.begin()); it != windows.end(); ++it) if (*it != w) widgets.append(*it); int overlap, minOverlap = 0; int possible; QRect r1(0, 0, 0, 0); QRect r2(0, 0, 0, 0); QRect maxRect = q->rect(); int x = maxRect.left(), y = maxRect.top(); 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 = QStyle::visualRect(q->layoutDirection(), maxRect, maxRestore); else r2 = QStyle::visualRect(q->layoutDirection(), maxRect, QRect(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 = QStyle::visualRect(q->layoutDirection(), maxRect, maxRestore); else r2 = QStyle::visualRect(q->layoutDirection(), maxRect, QRect(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 = QStyle::visualRect(q->layoutDirection(), maxRect, maxRestore); else r2 = QStyle::visualRect(q->layoutDirection(), maxRect, QRect(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); QRect resultRect = w->geometry(); resultRect.moveTo(wpos); w->setGeometry(QStyle::visualRect(q->layoutDirection(), maxRect, resultRect)); 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 (!maxmenubar || 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())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -