📄 q3mainwindow.cpp
字号:
return true;}#ifndef QT_NO_TOOLBAR/*! Returns a list of all the toolbars which are in the \a dock dock area, regardless of their state. For example, the \c TornOff dock area may contain closed toolbars but these are returned along with the visible toolbars. \sa dockWindows()*/QList<Q3ToolBar *> Q3MainWindow::toolBars(Qt::Dock dock) const{ QList<Q3DockWindow *> lst = dockWindows(dock); QList<Q3ToolBar *> tbl; for (int i = 0; i < lst.size(); ++i) { Q3ToolBar *tb = qobject_cast<Q3ToolBar *>(lst.at(i)); if (tb) tbl.append(tb); } return tbl;}#endif/*! Returns a list of all the dock windows which are in the \a dock dock area, regardless of their state. For example, the Qt::DockTornOff dock area may contain closed dock windows but these are returned along with the visible dock windows.*/QList<Q3DockWindow *> Q3MainWindow::dockWindows(Qt::Dock dock) const{ Q_D(const Q3MainWindow); QList<Q3DockWindow *> lst; switch (dock) { case Qt::DockTop: return d->topDock->dockWindowList(); case Qt::DockBottom: return d->bottomDock->dockWindowList(); case Qt::DockLeft: return d->leftDock->dockWindowList(); case Qt::DockRight: return d->rightDock->dockWindowList(); case Qt::DockTornOff: { for (int i = 0; i < d->dockWindows.size(); ++i) { Q3DockWindow *w = d->dockWindows.at(i); if (!w->area() && w->place() == Q3DockWindow::OutsideDock) lst.append(w); } } return lst; case Qt::DockMinimized: { QObjectList childList = d->hideDock->children(); for (int i = 0; i < childList.size(); ++i) { Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(childList.at(i)); if (dw) lst.append(dw); } } return lst; default: break; } return lst;}/*! \overload Returns the list of dock windows which belong to this main window, regardless of which dock area they are in or what their state is, (e.g. irrespective of whether they are visible or not).*/QList<Q3DockWindow *> Q3MainWindow::dockWindows() const{ return d_func()->dockWindows;}void Q3MainWindow::setDockWindowsMovable(bool enable){ Q_D(Q3MainWindow); d->movable = enable; QObjectList l = queryList("Q3DockWindow"); for (int i = 0; i < l.size(); ++i) static_cast<Q3DockWindow*>(l.at(i))->setMovingEnabled(enable);}/*! \property Q3MainWindow::dockWindowsMovable \brief whether the dock windows are movable If true (the default), the user will be able to move movable dock windows from one Q3MainWindow dock area to another, including the \c TearOff area (i.e. where the dock window floats freely as a window in its own right), and the \c Minimized area (where only the dock window's handle is shown below the menu bar). Movable dock windows can also be moved within Q3MainWindow dock areas, i.e. to rearrange them within a dock area. If false the user will not be able to move any dock windows. By default dock windows are moved transparently (i.e. only an outline rectangle is shown during the drag), but this setting can be changed with setOpaqueMoving(). \sa setDockEnabled(), setOpaqueMoving()*/bool Q3MainWindow::dockWindowsMovable() const{ return d_func()->movable;}void Q3MainWindow::setOpaqueMoving(bool b){ Q_D(Q3MainWindow); d->opaque = b; QObjectList l = queryList("Q3DockWindow"); for (int i = 0; i < l.size(); ++i) static_cast<Q3DockWindow*>(l.at(i))->setOpaqueMoving(b);}/*! \property Q3MainWindow::opaqueMoving \brief whether dock windows are moved opaquely If true the dock windows of the main window are shown opaquely (i.e. it shows the toolbar as it looks when docked) whilst it is being moved. If false (the default) they are shown transparently, (i.e. as an outline rectangle). \warning Opaque moving of toolbars and dockwindows is known to have several problems. We recommend avoiding the use of this feature for the time being. We intend fixing the problems in a future release.*/bool Q3MainWindow::opaqueMoving() const{ return d_func()->opaque;}/*! This function will line up dock windows within the visible dock areas (\c Top, \c Left, \c Right and \c Bottom) as compactly as possible. If \a keepNewLines is true, all dock windows stay on their original lines. If \a keepNewLines is false then newlines may be removed to achieve the most compact layout possible. The method only works if dockWindowsMovable() returns true.*/void Q3MainWindow::lineUpDockWindows(bool keepNewLines){ Q_D(const Q3MainWindow); if (!dockWindowsMovable()) return; d->topDock->lineUp(keepNewLines); d->leftDock->lineUp(keepNewLines); d->rightDock->lineUp(keepNewLines); d->bottomDock->lineUp(keepNewLines);}/*! Returns true, if the dock window menu is enabled; otherwise returns false. The menu lists the (appropriate()) dock windows (which may be shown or hidden), and has a "Line Up Dock Windows" menu item. It will also have a "Customize" menu item if isCustomizable() returns true. \sa setDockEnabled(), lineUpDockWindows() appropriate() setAppropriate()*/bool Q3MainWindow::isDockMenuEnabled() const{ return d_func()->dockMenu;}/*! If \a b is true, then right clicking on a dock window or dock area will pop up the dock window menu. If \a b is false, right clicking a dock window or dock area will not pop up the menu. The menu lists the (appropriate()) dock windows (which may be shown or hidden), and has a "Line Up Dock Windows" item. It will also have a "Customize" menu item if isCustomizable() returns true. \sa lineUpDockWindows(), isDockMenuEnabled()*/void Q3MainWindow::setDockMenuEnabled(bool b){ d_func()->dockMenu = b;}/*! Creates the dock window menu which contains all toolbars (if \a dockWindows is \c OnlyToolBars), all dock windows (if \a dockWindows is \c NoToolBars) or all toolbars and dock windows (if \a dockWindows is \c AllDockWindows - the default). This function is called internally when necessary, e.g. when the user right clicks a dock area (providing isDockMenuEnabled() returns true). You can reimplement this function if you wish to customize the behavior. The menu items representing the toolbars and dock windows are checkable. The visible dock windows are checked and the hidden dock windows are unchecked. The user can click a menu item to change its state (show or hide the dock window). The list and the state are always kept up-to-date. Toolbars and dock windows which are not appropriate in the current context (see setAppropriate()) are not listed in the menu. The menu also has a menu item for lining up the dock windows. If isCustomizable() returns true, a Customize menu item is added to the menu, which if clicked will call customize(). The isCustomizable() function we provide returns false and customize() does nothing, so they must be reimplemented in a subclass to be useful.*/Q3PopupMenu *Q3MainWindow::createDockWindowMenu(DockWindows dockWindows) const{ Q_D(const Q3MainWindow); QObjectList l = queryList("Q3DockWindow"); if (l.isEmpty()) return 0; Q3PopupMenu *menu = new Q3PopupMenu((Q3MainWindow*)this); menu->setObjectName(QLatin1String("qt_customize_menu")); d->dockWindowModes.replace( menu, dockWindows ); menu->setCheckable(true); connect( menu, SIGNAL(aboutToShow()), this, SLOT(menuAboutToShow()) ); return menu;}/*! This slot is called from the aboutToShow() signal of the default dock menu of the mainwindow. The default implementation initializes the menu with all dock windows and toolbars in this slot.*/void Q3MainWindow::menuAboutToShow(){ Q_D(Q3MainWindow); Q3PopupMenu *menu = (Q3PopupMenu*)sender(); menu->clear(); DockWindows dockWindows; { QMap<Q3PopupMenu*, DockWindows>::Iterator it = d->dockWindowModes.find( menu ); if ( it == d->dockWindowModes.end() ) return; dockWindows = (*it); } QObjectList l = queryList("Q3DockWindow"); bool empty = true; if (!l.isEmpty()) { if (dockWindows == AllDockWindows || dockWindows == NoToolBars) { for (int i = 0; i < l.size(); ++i) { Q3DockWindow *dw = (Q3DockWindow*)l.at(i); if (!appropriate(dw) || qobject_cast<Q3ToolBar*>(dw) || !dockMainWindow(dw)) continue; QString label = dw->windowTitle(); if (!label.isEmpty()) { QAction *act = menu->addAction(label); act->setCheckable(true); act->setChecked(dw->isVisible()); QObject::connect(act, SIGNAL(triggered()), dw, SLOT(toggleVisible())); empty = false; } } } if (!empty) { menu->addSeparator(); empty = true; }#ifndef QT_NO_TOOLBAR if (dockWindows == AllDockWindows || dockWindows == OnlyToolBars) { for (int i = 0; i < l.size(); ++i) { Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(l.at(i)); if (!tb || !appropriate(tb) || !dockMainWindow(tb)) continue; QString label = tb->label(); if (!label.isEmpty()) { QAction *act = menu->addAction(label); act->setCheckable(true); act->setChecked(tb->isVisible()); QObject::connect(act, SIGNAL(triggered()), tb, SLOT(toggleVisible())); empty = false; } } }#endif } if (!empty) { menu->addSeparator(); empty = true; } if (dockWindowsMovable()) menu->addAction(tr("Line up"), this, SLOT(doLineUp())); if (isCustomizable()) menu->addAction(tr("Customize..."), this, SLOT(customize()));}/*! Shows the dock menu at the position \a globalPos. The menu lists the dock windows so that they can be shown (or hidden), lined up, and possibly customized. Returns true if the menu is shown; otherwise returns false. If you want a custom menu, reimplement this function. You can create the menu from scratch or call createDockWindowMenu() and modify the result. The default implementation uses the dock window menu which gets created by createDockWindowMenu(). You can reimplement createDockWindowMenu() if you want to use your own specialized popup menu.*/bool Q3MainWindow::showDockMenu(const QPoint &globalPos){ Q_D(Q3MainWindow); if (!d->dockMenu) return false; if(Q3PopupMenu *ret = createDockWindowMenu()) { ret->exec(globalPos); delete ret; return true; } return false;}void Q3MainWindow::slotPlaceChanged(){ QObject* obj = (QObject*)sender(); Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(obj); if (dw) emit dockWindowPositionChanged(dw);#ifndef QT_NO_TOOLBAR Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(obj); if (tb) emit toolBarPositionChanged(tb);#endif}/*! \internal For internal use of Q3DockWindow only. */Q3DockArea *Q3MainWindow::dockingArea(const QPoint &p){ Q_D(Q3MainWindow); int mh = d->mb ? d->mb->height() : 0; int sh = d->sb ? d->sb->height() : 0; if (p.x() >= -5 && p.x() <= 100 && p.y() > mh && p.y() - height() - sh) return d->leftDock; if (p.x() >= width() - 100 && p.x() <= width() + 5 && p.y() > mh && p.y() - height() - sh) return d->rightDock; if (p.y() >= -5 && p.y() < mh + 100 && p.x() >= 0 && p.x() <= width()) return d->topDock; if (p.y() >= height() - sh - 100 && p.y() <= height() + 5 && p.x() >= 0 && p.x() <= width()) return d->bottomDock; return 0;}/*! Returns true if \a dw is a dock window known to the main window; otherwise returns false.*/bool Q3MainWindow::hasDockWindow(Q3DockWindow *dw){ return d_func()->dockWindows.contains(dw);}/*! Returns the \c Left dock area \sa rightDock() topDock() bottomDock()*/Q3DockArea *Q3MainWindow::leftDock() const{ return d_func()->leftDock;}/*! Returns the \c Right dock area \sa leftDock() topDock() bottomDock()*/Q3DockArea *Q3MainWindow::rightDock() const{ return d_func()->rightDock;}/*! Returns the \c Top dock area \sa bottomDock() leftDock() rightDock()*/Q3DockArea *Q3MainWindow::topDock() const{ return d_func()->topDock;}/*! Returns a pointer the \c Bottom dock area \sa topDock()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -