📄 q3dockwindow.cpp
字号:
/*! Returns the orientation of the dock window. \sa orientationChanged()*/Qt::Orientation Q3DockWindow::orientation() const{ if (dockArea) return dockArea->orientation(); if (qobject_cast<const Q3ToolBar*>(this)) return Qt::Horizontal; return (((Q3DockWindow*)this)->boxLayout()->direction() == QBoxLayout::LeftToRight || ((Q3DockWindow*)this)->boxLayout()->direction() == QBoxLayout::RightToLeft ? Qt::Horizontal : Qt::Vertical);}int Q3DockWindow::offset() const{ return offs;}/*! \property Q3DockWindow::offset \brief the dock window's preferred offset from the dock area's left edge (top edge for vertical dock areas) The default is 0.*/void Q3DockWindow::setOffset(int o){ offs = o;}/*! Returns the dock window's preferred size (fixed extent). \sa setFixedExtentWidth() setFixedExtentHeight()*/QSize Q3DockWindow::fixedExtent() const{ return fExtent;}/*! Sets the dock window's preferred width for its fixed extent (size) to \a w. \sa setFixedExtentHeight()*/void Q3DockWindow::setFixedExtentWidth(int w){ fExtent.setWidth(w);}/*! Sets the dock window's preferred height for its fixed extent (size) to \a h. \sa setFixedExtentWidth()*/void Q3DockWindow::setFixedExtentHeight(int h){ fExtent.setHeight(h);}/*! \property Q3DockWindow::newLine \brief whether the dock window prefers to start a new line in the dock area. The default is false, i.e. the dock window doesn't require a new line in the dock area.*/void Q3DockWindow::setNewLine(bool b){ nl = b;}bool Q3DockWindow::newLine() const{ return nl;}/*! Returns the layout which is used for adding widgets to the dock window. The layout's orientation is set automatically to match the orientation of the dock window. You can add widgets to the layout using the box layout's QBoxLayout::addWidget() function. If the dock window only needs to contain a single widget use setWidget() instead. \sa setWidget() setOrientation()*/QBoxLayout *Q3DockWindow::boxLayout(){ return childBox;}/*! \reimp */QSize Q3DockWindow::sizeHint() const{ QSize sh(Q3Frame::sizeHint()); if (place() == InDock) sh = sh.expandedTo(fixedExtent()); sh = sh.expandedTo(QSize(16, 16)); if (area()) { if (area()->orientation() == Qt::Horizontal && !vHandleRight->isVisible()) sh.setWidth(sh.width() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); else if (area()->orientation() == Qt::Vertical && !hHandleBottom->isVisible()) sh.setHeight(sh.height() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); } return sh;}/*! \internal */QSize Q3DockWindow::minimumSize() const{ QSize ms(Q3Frame::minimumSize()); if (place() == InDock) ms = ms.expandedTo(fixedExtent()); ms = ms.expandedTo(QSize(16, 16)); if (area()) { if (area()->orientation() == Qt::Horizontal && !vHandleRight->isVisible()) ms.setWidth(ms.width() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); else if (area()->orientation() == Qt::Vertical && !hHandleBottom->isVisible()) ms.setHeight(ms.height() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); } return ms;}/*! \reimp */QSize Q3DockWindow::minimumSizeHint() const{ QSize msh(Q3Frame::minimumSize()); if (place() == InDock) msh = msh.expandedTo(fixedExtent()); msh = msh.expandedTo(QSize(16, 16)); if (area()) { if (area()->orientation() == Qt::Horizontal && !vHandleRight->isVisible()) msh.setWidth(msh.width() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); else if (area()->orientation() == Qt::Vertical && !hHandleBottom->isVisible()) msh.setHeight(msh.height() + 2 * style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this) / 3); } return msh;}/*! \fn void Q3DockWindow::undock() Undocks the Q3DockWindow from its current dock area if it is docked; otherwise does nothing. \sa dock() Q3DockArea::moveDockWindow(), Q3DockArea::removeDockWindow(), Q3MainWindow::moveDockWindow(), Q3MainWindow::removeDockWindow()*//*! \fn void Q3DockWindow::undock(QWidget *widget) Undocks the specified \a widget from its current dock area if it is docked; otherwise does nothing. \sa dock() Q3DockArea::moveDockWindow(), Q3DockArea::removeDockWindow(), Q3MainWindow::moveDockWindow(), Q3MainWindow::removeDockWindow()*/void Q3DockWindow::undock(QWidget *w){ Q3MainWindow *mw = 0; if (area()) mw = qobject_cast<Q3MainWindow*>(area()->parentWidget()); if (mw && !mw->isDockEnabled(this, Qt::DockTornOff)) return; if ((place() == OutsideDock && !w)) return; QPoint p(50, 50); if (window()) p = window()->pos() + QPoint(20, 20); if (dockArea) { delete (Q3DockArea::DockWindowData*)dockWindowData; dockWindowData = dockArea->dockWindowData(this); dockArea->removeDockWindow(this, true, orientation() != Qt::Horizontal && qobject_cast<Q3ToolBar*>(this)); } dockArea = 0; if (lastPos != QPoint(-1, -1) && lastPos.x() > 0 && lastPos.y() > 0) move(lastPos); else move(p); if (lastSize != QSize(-1, -1)) resize(lastSize); curPlace = OutsideDock; updateGui(); emit orientationChanged(orientation()); QApplication::sendPostedEvents(this, QEvent::LayoutHint); if (qobject_cast<Q3ToolBar*>(this)) adjustSize(); if (!w) { if (!parentWidget() || parentWidget()->isVisible()) { if (lastSize == QSize(-1, -1)) setAttribute(Qt::WA_Resized, false);// Ensures size is recalculated (opaque). show(); } } else { setParent(w, 0); move(-width() - 5, -height() - 5); resize(1, 1); show(); } if (parentWidget() && isWindow()) parentWidget()->setActiveWindow(); emit placeChanged(place());}void Q3DockWindow::removeFromDock(bool fixNewLines){ if (dockArea) dockArea->removeDockWindow(this, false, false, fixNewLines);}/*! Docks the dock window into the last dock area in which it was docked. If the dock window has no last dock area (e.g. it was created as a floating window and has never been docked), or if the last dock area it was docked in does not exist (e.g. the dock area has been deleted), nothing happens. The dock window will dock with the dock area regardless of the return value of Q3DockArea::isDockWindowAccepted(). \sa undock() Q3DockArea::moveDockWindow(), Q3DockArea::removeDockWindow(), Q3MainWindow::moveDockWindow(), Q3MainWindow::removeDockWindow(), Q3DockArea::isDockWindowAccepted()*/void Q3DockWindow::dock(){ if (!(Q3DockArea::DockWindowData*)dockWindowData || !((Q3DockArea::DockWindowData*)dockWindowData)->area) return; curPlace = InDock; lastPos = pos(); lastSize = size(); ((Q3DockArea::DockWindowData*)dockWindowData)-> area->dockWindow(this, (Q3DockArea::DockWindowData*)dockWindowData); emit orientationChanged(orientation()); emit placeChanged(place());}/*! \reimp */void Q3DockWindow::hideEvent(QHideEvent *e){ Q3Frame::hideEvent(e);}/*! \reimp */void Q3DockWindow::showEvent(QShowEvent *e){ if (curPlace == OutsideDock && (parent() && parent()->objectName() == QLatin1String("qt_hide_dock"))) { QRect sr = qApp->desktop()->availableGeometry(this); if (!sr.contains(pos())) { int nx = qMin(qMax(x(), sr.x()), sr.right()-width()); int ny = qMin(qMax(y(), sr.y()), sr.bottom()-height()); move(nx, ny); } } Q3Frame::showEvent(e);}/*! \property Q3DockWindow::opaqueMoving \brief whether the dock window will be shown normally whilst it is being moved. If this property is false, (the default), the dock window will be represented by an outline rectangle whilst it is being moved. \warning Currently opaque moving has some problems and we do not recommend using it at this time. We expect to fix these problems in a future release.*/void Q3DockWindow::setOpaqueMoving(bool b){ opaque = b; horHandle->setOpaqueMoving(b); verHandle->setOpaqueMoving(b); titleBar->setOpaqueMoving(b);}bool Q3DockWindow::opaqueMoving() const{ return opaque;}void Q3DockWindow::updateSplitterVisibility(bool visible){ if (area() && isResizeEnabled()) { if (orientation() == Qt::Horizontal) { if (visible) vHandleRight->show(); else vHandleRight->hide(); vHandleLeft->hide(); } else { if (visible) hHandleBottom->show(); else hHandleBottom->hide(); hHandleTop->hide(); } }}/*! \reimp */bool Q3DockWindow::eventFilter(QObject * o, QEvent *e){ if (!o->isWidgetType()) return false; if (e->type() == QEvent::KeyPress && (horHandle->mousePressed || verHandle->mousePressed || titleBar->mousePressed)) { QKeyEvent *ke = (QKeyEvent*)e; if (ke->key() == Qt::Key_Escape) { horHandle->mousePressed = verHandle->mousePressed = titleBar->mousePressed = false; endRectDraw(!opaque); qApp->removeEventFilter(this); return true; } } else if (((QWidget*)o)->window() != this && place() == OutsideDock && isWindow()) { if ((e->type() == QEvent::WindowDeactivate || e->type() == QEvent::WindowActivate)) event(e); } return false;}/*! \reimp */bool Q3DockWindow::event(QEvent *e){ switch (e->type()) { case QEvent::WindowDeactivate: if (place() == OutsideDock && isWindow() && parentWidget() && parentWidget()->isActiveWindow()) return true; break; case QEvent::HideToParent: emit visibilityChanged(false); break; case QEvent::ShowToParent: emit visibilityChanged(true); break; case QEvent::WindowTitleChange: { QString s = Q3Frame::windowTitle(); titleBar->setWindowTitle(s);#ifndef QT_NO_TOOLTIP horHandle->setToolTip(s); verHandle->setToolTip(s);#endif break; } default: break; } return Q3Frame::event(e);}/*! Returns the dock window's title.*/QString Q3DockWindow::windowTitle() const{ return titleBar->windowTitle();}/*! \reimp */void Q3DockWindow::contextMenuEvent(QContextMenuEvent *e){ QObject *o = this; while (o) { if (qobject_cast<Q3MainWindow*>(o)) break; o = o->parent(); } if (!o || ! ((Q3MainWindow*)o)->showDockMenu(e->globalPos())) e->ignore();}#include "q3dockwindow.moc"#endif //QT_NO_MAINWINDOW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -