📄 qworkspace.cpp
字号:
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; showMaximizeControls(); 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); if(!maxmenubar || 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){#ifndef QT_NO_SHORTCUT 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#endif if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut){ return true; } return QWidget::event(e);}/*! \reimp */bool QWorkspace::eventFilter(QObject *o, QEvent * e){ Q_D(QWorkspace); static QTime* t = 0; static QWorkspace* tc = 0; if (o == d->maxtools) { switch (e->type()) { case QEvent::MouseButtonPress: { QMenuBar* b = (QMenuBar*)o->parent(); if (!t) t = new QTime; if (tc != this || t->elapsed() > QApplication::doubleClickInterval()) { if (isRightToLeft()) { QPoint p = b->mapToGlobal(QPoint(b->x() + b->width(), b->y() + b->height())); p.rx() -= d->popup->sizeHint().width(); d->_q_popupOperationMenu(p); } else { d->_q_popupOperationMenu(b->mapToGlobal(QPoint(b->x(), b->y() + b->height()))); } t->start(); tc = this; } else { tc = 0; closeActiveWindow(); } return true; } default: break; } return QWidget::eventFilter(o, e); } switch (e->type()) { case QEvent::HideToParent: break; case QEvent::ShowToParent: if (QWorkspaceChild *c = qobject_cast<QWorkspaceChild*>(o)) if (!d->focus.contains(c)) d->focus.append(c); d->updateWorkspace(); break; case QEvent::WindowTitleChange: if (!d->inTitleChange) { if (o == window()) d->topTitle = window()->windowTitle(); if (d->maxWindow && d->maxWindow->windowWidget() && d->topTitle.size()) { d->inTitleChange = true; window()->setWindowTitle(tr("%1 - [%2]") .arg(d->topTitle).arg(d->maxWindow->windowWidget()->windowTitle())); d->inTitleChange = false; } } break; case QEvent::ModifiedChange: if (o == d->maxWindow) window()->setWindowModified(d->maxWindow->isWindowModified()); break; case QEvent::Close: if (o == window()) { QList<QWorkspaceChild *>::Iterator it(d->windows.begin()); while (it != d->windows.end()) { QWorkspaceChild* c = *it; ++it; if (c->shademode) c->showShaded(); } } else if (qobject_cast<QWorkspaceChild*>(o)) { d->popup->hide(); } d->updateWorkspace(); break; default: break; } return QWidget::eventFilter(o, e);}static QMenuBar *findMenuBar(QWidget *w){ // don't search recursively to avoid finding a menu bar of a // mainwindow that happens to be a workspace window (like // a mainwindow in designer) QList<QObject *> children = w->children(); for (int i = 0; i < children.count(); ++i) { QMenuBar *bar = qobject_cast<QMenuBar *>(children.at(i)); if (bar) return bar; } return 0;}void QWorkspacePrivate::showMaximizeControls(){ Q_Q(QWorkspace); Q_ASSERT(maxWindow); // merge windowtitle and modified state if (!topTitle.size()) topTitle = q->window()->windowTitle(); if (maxWindow->windowWidget()) { QString docTitle = maxWindow->windowWidget()->windowTitle(); if (topTitle.size() && docTitle.size()) { inTitleChange = true; q->window()->setWindowTitle(QWorkspace::tr("%1 - [%2]").arg(topTitle).arg(docTitle)); inTitleChange = false; } q->window()->setWindowModified(maxWindow->windowWidget()->isWindowModified()); } if (!q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) { QMenuBar* b = 0; // Do a breadth-first search first on every parent, QWidget* w = q->parentWidget(); while (w) { b = findMenuBar(w); if (b) break; w = w->parentWidget(); } // last attempt. if (!b) b = findMenuBar(q->window()); if (!b) return; if (!maxcontrols) { maxmenubar = b; maxcontrols = new QMDIControl(b); QObject::connect(maxcontrols, SIGNAL(_q_minimize()), q, SLOT(_q_minimizeActiveWindow())); QObject::connect(maxcontrols, SIGNAL(_q_restore()), q, SLOT(_q_normalizeActiveWindow())); QObject::connect(maxcontrols, SIGNAL(_q_close()), q, SLOT(closeActiveWindow())); } b->setCornerWidget(maxcontrols); if (b->isVisible()) maxcontrols->show(); if (!active && becomeActive) { active = (QWorkspaceChild*)becomeActive->parentWidget(); active->setActive(true); becomeActive = 0; emit q->windowActivated(active->windowWidget()); } if (active) { if (!maxtools) { maxtools = new QLabel(q->window()); maxtools->setObjectName(QLatin1String("qt_maxtools")); maxtools->installEventFilter(q); } if (active->windowWidget() && !active->windowWidget()->windowIcon().isNull()) { QIcon icon = active->windowWidget()->windowIcon(); int iconSize = maxcontrols->size().height(); maxtools->setPixmap(icon.pixmap(QSize(iconSize, iconSize))); } else { QPixmap pm = q->style()->standardPixmap(QStyle::SP_TitleBarMenuButton); if (pm.isNull()) { pm = QPixmap(14,14); pm.fill(Qt::black); } maxtools->setPixmap(pm); } b->setCornerWidget(maxtools, Qt::TopLeftCorner); if (b->isVisible()) maxtools->show(); } }}void QWorkspacePrivate::hideMaximizeControls(){ Q_Q(QWorkspace); if (maxmenubar && !q->style()->styleHint(QStyle::SH_Workspace_FillSpaceOnMaximize, 0, q)) { if (maxmenubar) { maxmenubar->setCornerWidget(0, Qt::TopLeftCorner); maxmenubar->setCornerWidget(0, Qt::TopRightCorner); } if (maxcontrols) { maxcontrols->deleteLater(); maxcontrols = 0; } if (maxtools) { maxtools->deleteLater(); maxtools = 0; } } //unmerge the title bar/modification state if (topTitle.size()) { inTitleChange = true; q->window()->setWindowTitle(topTitle); inTitleChange = false; } q->window()->setWindowModified(false);}/*! Closes the child window that is currently active. \sa closeAllWindows()*/void QWorkspace::closeActiveWindow(){ Q_D(QWorkspace); if (d->maxWindow && d->maxWindow->windowWidget()) d->maxWindow->windowWidget()->close(); else if (d->active && d->active->windowWidget()) d->active->windowWidget()->close(); d->updateWorkspace();}/*! Closes all child windows. If any child window fails to accept the close event, the remaining windows will remain open. \sa closeActiveWindow()*/void QWorkspace::closeAllWindows(){ Q_D(QWorkspace); bool did_close = true; QList<QWorkspaceChild *>::const_iterator it = d->windows.constBegin(); while (it != d->windows.constEnd() && did_close) { QWorkspaceChild *c = *it; ++it; if (c->windowWidget() && !c->windowWidget()->isHidden()) did_close = c->windowWidget()->close(); }}void QWorkspacePrivate::_q_normalizeActiveWindow(){ if (maxWindow) maxWindow->showNormal(); else if (active) active->showNormal();}void QWorkspacePrivate::_q_minimizeActiveWindow(){ if (maxWindow) maxWindow->showMinimized(); else if (active) active->showMinimized();}void QWorkspacePrivate::_q_showOperationMenu(){ Q_Q(QWorkspace); if (!active || !active->windowWidget()) return; Q_ASSERT((active->windowWidget()->windowFlags() & Qt::WindowSystemMenuHint)); QPoint p; QMenu *popup = (active->titlebar && active->titlebar->isTool()) ? toolPopup : this->popup; if (q->isRightToLeft()) { p = QPoint(active->windowWidget()->mapToGlobal(QPoint(active->windowWidget()->width(),0))); p.rx() -= popup->sizeHint().width(); } else { p = QPoint(active->windowWidget()->mapToGlobal(QPoint(0,0))); } if (!active->isVisible()) { p = active->iconWidget()->mapToGlobal(QPoint(0,0)); p.ry() -= popup->sizeHint().height(); } _q_popupOperationMenu(p);}void QWorkspacePrivate::_q_popupOperationMenu(const QPoint& p){ if (!active || !active->windowWidget()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -