📄 qworkspace.cpp
字号:
QScrollBar *vbar, *hbar; QWidget *corner; int yoffset, xoffset; QBrush background; void init(); void insertIcon(QWidget* w); void removeIcon(QWidget* w); void place(QWidget*); QWorkspaceChild* findChild(QWidget* w); void showMaximizeControls(); void hideMaximizeControls(); void activateWindow(QWidget* w, bool change_focus = true); void hideChild(QWorkspaceChild *c); void showWindow(QWidget* w); void maximizeWindow(QWidget* w); void minimizeWindow(QWidget* w); void normalizeWindow(QWidget* w); QRect updateWorkspace();private: void _q_normalizeActiveWindow(); void _q_minimizeActiveWindow(); void _q_showOperationMenu(); void _q_popupOperationMenu(const QPoint&); void _q_operationMenuActivated(QAction *); void _q_scrollBarChanged(); void _q_updateActions(); bool inTitleChange;};static bool isChildOf(QWidget * child, QWidget * parent){ if (!parent || !child) return false; QWidget * w = child; while(w && w != parent) w = w->parentWidget(); return w != 0;}/*! Constructs a workspace with the given \a parent.*/QWorkspace::QWorkspace(QWidget *parent) : QWidget(*new QWorkspacePrivate, parent, 0){ Q_D(QWorkspace); d->init();}#ifdef QT3_SUPPORT/*! Use one of the constructors that doesn't take the \a name argument and then use setObjectName() instead.*/QWorkspace::QWorkspace(QWidget *parent, const char *name) : QWidget(*new QWorkspacePrivate, parent, 0){ Q_D(QWorkspace); setObjectName(QString::fromAscii(name)); d->init();}#endif // QT3_SUPPORT/*! \internal*/voidQWorkspacePrivate::init(){ Q_Q(QWorkspace); maxcontrols = 0; active = 0; maxWindow = 0; maxtools = 0; px = 0; py = 0; becomeActive = 0; popup = new QMenu(q); toolPopup = new QMenu(q); popup->setObjectName(QLatin1String("qt_internal_mdi_popup")); toolPopup->setObjectName(QLatin1String("qt_internal_mdi_tool_popup")); actions[QWorkspacePrivate::RestoreAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarNormalButton)), QWorkspace::tr("&Restore"), q); actions[QWorkspacePrivate::MoveAct] = new QAction(QWorkspace::tr("&Move"), q); actions[QWorkspacePrivate::ResizeAct] = new QAction(QWorkspace::tr("&Size"), q); actions[QWorkspacePrivate::MinimizeAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarMinButton)), QWorkspace::tr("Mi&nimize"), q); actions[QWorkspacePrivate::MaximizeAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarMaxButton)), QWorkspace::tr("Ma&ximize"), q); actions[QWorkspacePrivate::CloseAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarCloseButton)), QWorkspace::tr("&Close")#ifndef QT_NO_SHORTCUT +"\t"+(QString)QKeySequence(Qt::CTRL+Qt::Key_F4)#endif ,q); QObject::connect(actions[QWorkspacePrivate::CloseAct], SIGNAL(triggered()), q, SLOT(closeActiveWindow())); actions[QWorkspacePrivate::StaysOnTopAct] = new QAction(QWorkspace::tr("Stay on &Top"), q); actions[QWorkspacePrivate::StaysOnTopAct]->setChecked(true); actions[QWorkspacePrivate::ShadeAct] = new QAction(QIcon(q->style()->standardPixmap(QStyle::SP_TitleBarShadeButton)), QWorkspace::tr("Sh&ade"), q); QObject::connect(popup, SIGNAL(aboutToShow()), q, SLOT(_q_updateActions())); QObject::connect(popup, SIGNAL(triggered(QAction*)), q, SLOT(_q_operationMenuActivated(QAction*))); popup->addAction(actions[QWorkspacePrivate::RestoreAct]); popup->addAction(actions[QWorkspacePrivate::MoveAct]); popup->addAction(actions[QWorkspacePrivate::ResizeAct]); popup->addAction(actions[QWorkspacePrivate::MinimizeAct]); popup->addAction(actions[QWorkspacePrivate::MaximizeAct]); popup->addSeparator(); popup->addAction(actions[QWorkspacePrivate::CloseAct]); QObject::connect(toolPopup, SIGNAL(aboutToShow()), q, SLOT(_q_updateActions())); QObject::connect(toolPopup, SIGNAL(triggered(QAction*)), q, SLOT(_q_operationMenuActivated(QAction*))); toolPopup->addAction(actions[QWorkspacePrivate::MoveAct]); toolPopup->addAction(actions[QWorkspacePrivate::ResizeAct]); toolPopup->addAction(actions[QWorkspacePrivate::StaysOnTopAct]); toolPopup->addSeparator(); toolPopup->addAction(actions[QWorkspacePrivate::ShadeAct]); toolPopup->addAction(actions[QWorkspacePrivate::CloseAct]);#ifndef QT_NO_SHORTCUT // Set up shortcut bindings (id -> slot), most used first shortcutMap.insert(q->grabShortcut(Qt::CTRL + Qt::Key_Tab), "activateNextWindow"); shortcutMap.insert(q->grabShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab), "activatePreviousWindow"); shortcutMap.insert(q->grabShortcut(Qt::CTRL + Qt::Key_F4), "closeActiveWindow"); shortcutMap.insert(q->grabShortcut(Qt::ALT + Qt::Key_Minus), "_q_showOperationMenu"); shortcutMap.insert(q->grabShortcut(Qt::CTRL + Qt::Key_F6), "activateNextWindow"); shortcutMap.insert(q->grabShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_F6), "activatePreviousWindow"); shortcutMap.insert(q->grabShortcut(Qt::Key_Forward), "activateNextWindow"); shortcutMap.insert(q->grabShortcut(Qt::Key_Back), "activatePreviousWindow");#endif // QT_NO_SHORTCUT q->setBackgroundRole(QPalette::Dark); q->setAutoFillBackground(true); q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); hbar = vbar = 0; corner = 0; xoffset = yoffset = 0; q->window()->installEventFilter(q); inTitleChange = false; updateWorkspace();}/*! Destroys the workspace and frees any allocated resources.*/QWorkspace::~QWorkspace(){}/*! \reimp */QSize QWorkspace::sizeHint() const{ QSize s(QApplication::desktop()->size()); return QSize(s.width()*2/3, s.height()*2/3);}#ifdef QT3_SUPPORT/*! Sets the background color to \a c. Use setBackground() instead.*/void QWorkspace::setPaletteBackgroundColor(const QColor & c){ setBackground(c);}/*! Sets the background pixmap to \a pm. Use setBackground() instead.*/void QWorkspace::setPaletteBackgroundPixmap(const QPixmap & pm){ setBackground(pm);}#endif // QT3_SUPPORT/*! \property QWorkspace::background \brief the workspace's background*/QBrush QWorkspace::background() const{ Q_D(const QWorkspace); if (d->background.style() == Qt::NoBrush) return palette().dark(); return d->background;}void QWorkspace::setBackground(const QBrush &background){ Q_D(QWorkspace); d->background = background; setAttribute(Qt::WA_OpaquePaintEvent, background.style() == Qt::NoBrush); update();}/*! Adds widget \a w as new sub window to the workspace. If \a flags are non-zero, they will override the flags set on the widget. Returns the widget used for the window frame. To remove the widget \a w from the workspace, simply call setParent() with the new parent (or 0 to make it a stand-alone window).*/QWidget * QWorkspace::addWindow(QWidget *w, Qt::WFlags flags){ Q_D(QWorkspace); if (!w) return 0; w->setAutoFillBackground(true); bool customize = (flags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowContextHelpButtonHint)); uint type = (flags & Qt::WindowType_Mask); if (customize) ; else if (type == Qt::Dialog || type == Qt::Sheet) flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowContextHelpButtonHint; else if (type == Qt::Tool) flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint; else flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint;#if 0 bool wasMaximized = w->isMaximized(); bool wasMinimized = w->isMinimized();#endif bool hasSize = w->testAttribute(Qt::WA_Resized); int x = w->x(); int y = w->y(); bool hasPos = w->testAttribute(Qt::WA_Moved); QSize s = w->size().expandedTo(w->minimumSizeHint()); if (!hasSize && w->sizeHint().isValid()) w->adjustSize(); QWorkspaceChild* child = new QWorkspaceChild(w, this, flags); child->setObjectName(QLatin1String("qt_workspacechild")); child->installEventFilter(this); connect(child, SIGNAL(popupOperationMenu(QPoint)), this, SLOT(_q_popupOperationMenu(QPoint))); connect(child, SIGNAL(showOperationMenu()), this, SLOT(_q_showOperationMenu())); d->windows.append(child); if (child->isVisibleTo(this)) d->focus.append(child); child->internalRaise(); if (!hasPos) d->place(child); if (!hasSize) child->adjustSize(); if (hasPos) child->move(x, y); return child;#if 0 if (wasMaximized) w->showMaximized(); else if (wasMinimized) w->showMinimized(); else if (!hasBeenHidden) d->activateWindow(w); 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; if (d->vbar && d->vbar->isVisible() && !(e->modifiers() & Qt::AltModifier)) QApplication::sendEvent(d->vbar, e); else if (d->hbar && d->hbar->isVisible()) QApplication::sendEvent(d->hbar, 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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -