1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the Qt 3 compatibility classes of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "q3mainwindow.h"
30
#ifndef QT_NO_MAINWINDOW
32
#include "qapplication.h"
35
#include "qdatetime.h"
36
#include "q3dockarea.h"
42
#include "q3popupmenu.h"
43
#include "q3scrollview.h"
44
#include "qstatusbar.h"
45
#include "qstringlist.h"
47
#include "qstyleoption.h"
49
#include "q3toolbar.h"
51
#include "qwhatsthis.h"
53
# include <private/qt_mac_p.h>
58
#include <private/q3mainwindow_p.h>
60
/* Q3MainWindowLayout, respects widthForHeight layouts (like the left
64
class Q3MainWindowLayout : public QLayout
69
Q3MainWindowLayout(Q3MainWindow *mw, QLayout* parent = 0);
70
~Q3MainWindowLayout() {}
72
void addItem(QLayoutItem *);
73
void setLeftDock(Q3DockArea *l);
74
void setRightDock(Q3DockArea *r);
75
void setCentralWidget(QWidget *w);
76
bool hasHeightForWidth() const { return false; }
77
QSize sizeHint() const;
78
QSize minimumSize() const;
79
QLayoutItem *itemAt(int) const { return 0; } //###
80
QLayoutItem *takeAt(int) { return 0; } //###
81
int count() const { return 0; } //###
84
void setGeometry(const QRect &r) {
85
QLayout::setGeometry(r);
90
int layoutItems(const QRect&, bool testonly = false);
91
int extraPixels() const;
93
Q3DockArea *left, *right;
95
Q3MainWindow *mainWindow;
99
QSize Q3MainWindowLayout::sizeHint() const
105
w += left->sizeHint().width();
106
h = qMax(h, left->sizeHint().height());
109
w += right->sizeHint().width();
110
h = qMax(h, right->sizeHint().height());
113
w += central->sizeHint().width();
114
int diff = extraPixels();
115
h = qMax(h, central->sizeHint().height() + diff);
120
QSize Q3MainWindowLayout::minimumSize() const
126
QSize ms = left->minimumSizeHint().expandedTo(left->minimumSize());
128
h = qMax(h, ms.height());
131
QSize ms = right->minimumSizeHint().expandedTo(right->minimumSize());
133
h = qMax(h, ms.height());
136
QSize min = central->minimumSize().isNull() ?
137
central->minimumSizeHint() : central->minimumSize();
139
int diff = extraPixels();
140
h = qMax(h, min.height() + diff);
145
Q3MainWindowLayout::Q3MainWindowLayout(Q3MainWindow *mw, QLayout* parent)
146
: QLayout(parent), left(0), right(0), central(0)
151
void Q3MainWindowLayout::setLeftDock(Q3DockArea *l)
156
void Q3MainWindowLayout::setRightDock(Q3DockArea *r)
161
void Q3MainWindowLayout::setCentralWidget(QWidget *w)
166
int Q3MainWindowLayout::layoutItems(const QRect &r, bool testonly)
168
if (!left && !central && !right)
173
wl = ((Q3DockAreaLayout*)left->QWidget::layout())->widthForHeight(r.height());
175
wr = ((Q3DockAreaLayout*)right->QWidget::layout())->widthForHeight(r.height());
176
int w = r.width() - wr - wl;
180
int diff = extraPixels();
184
left->setGeometry(QRect(g.x(), g.y() + diff, wl, r.height() - diff));
186
right->setGeometry(QRect(g.x() + g.width() - wr, g.y() + diff, wr, r.height() - diff));
188
central->setGeometry(g.x() + wl, g.y() + diff, w, r.height() - diff);
193
w += central->minimumSize().width();
197
int Q3MainWindowLayout::extraPixels() const
199
if (mainWindow->d_func()->topDock->isEmpty() &&
200
!(mainWindow->d_func()->leftDock->isEmpty() &&
201
mainWindow->d_func()->rightDock->isEmpty())) {
208
void Q3MainWindowLayout::addItem(QLayoutItem * /* item */)
213
QHideToolTip and QHideDock - minimized dock
217
class QHideToolTip : public QToolTip
220
QHideToolTip(QWidget *parent) : QToolTip(parent) {}
222
void maybeTip(const QPoint &pos);
227
class QHideDock : public QWidget
232
QHideDock(Q3MainWindow *parent) : QWidget(parent, "qt_hide_dock") {
234
setFixedHeight(style()->pixelMetric(QStyle::PM_DockWidgetHandleExtent, 0, this) + 3);
237
setMouseTracking(true);
240
tip = new QHideToolTip(this);
251
void paintEvent(QPaintEvent *e) {
252
QObjectList childs = children();
253
if (childs.isEmpty())
256
p.setClipRegion(e->rect());
257
p.fillRect(e->rect(), palette().brush(QPalette::Background));
259
for (int i = 0; i < childs.size(); ++i) {
260
QObject *o = childs.at(i);
261
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(o);
262
if (!dw || !dw->isVisible())
264
QStyleOptionQ3DockWindow opt;
265
opt.rect.setRect(x, 0, 30, 10);
266
opt.palette = palette();
267
opt.docked = dw->area();
268
opt.closeEnabled = dw->isCloseEnabled();
269
opt.state = QStyle::State_None;
270
if (i == pressedHandle)
271
opt.state |= QStyle::State_On;
273
style()->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &p, this);
278
void mousePressEvent(QMouseEvent *e) {
280
QObjectList childs = children();
281
if (childs.isEmpty())
286
if (e->button() == Qt::RightButton && win->isDockMenuEnabled()) {
287
// ### TODO: HideDock menu
293
void mouseMoveEvent(QMouseEvent *e) {
294
QObjectList childs = children();
295
if (childs.isEmpty())
300
if (e->y() >= 0 && e->y() <= height()) {
301
for (int i = 0; i < childs.size(); ++i) {
302
QObject *o = childs.at(i);
303
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(o);
304
if (!dw || !dw->isVisible())
306
if (e->x() >= x && e->x() <= x + 30) {
307
int old = pressedHandle;
309
if (pressedHandle != old)
316
int old = pressedHandle;
322
void mouseReleaseEvent(QMouseEvent *e) {
324
if (pressedHandle == -1)
326
QObjectList childs = children();
327
if (childs.isEmpty())
329
if (e->button() == Qt::LeftButton) {
330
if (e->y() >= 0 && e->y() <= height()) {
331
QObject *o = childs.at(pressedHandle);
332
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(o);
343
bool eventFilter(QObject *o, QEvent *e) {
344
if (o == this || !o->isWidgetType())
345
return QWidget::eventFilter(o, e);
346
if (e->type() == QEvent::HideToParent ||
347
e->type() == QEvent::ShowToParent)
349
return QWidget::eventFilter(o, e);
354
QObjectList childs = children();
355
if (childs.isEmpty())
357
for (int i = 0; i < childs.size(); ++i) {
358
QObject *o = childs.at(i);
359
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(o);
362
if (dw->isHidden()) {
366
if (!dw->isVisible())
376
win->triggerLayout(false);
380
void childEvent(QChildEvent *e) {
381
QWidget::childEvent(e);
382
if (e->type() == QEvent::ChildInserted)
383
e->child()->installEventFilter(this);
385
e->child()->removeEventFilter(this);
395
friend class QHideToolTip;
400
void QHideToolTip::maybeTip(const QPoint &pos)
404
QHideDock *dock = (QHideDock*)parentWidget();
406
QObjectList dchilds = dock->children();
407
if (dchilds.isEmpty())
410
for (int i = 0; i < dchilds.size(); ++i) {
411
QObject *o = dchilds.at(i);
412
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(o);
413
if (!dw || !dw->isVisible())
415
if (pos.x() >= x && pos.x() <= x + 30) {
416
Q3DockWindow *dw = (Q3DockWindow*)o;
417
if (!dw->windowTitle().isEmpty())
418
tip(QRect(x, 0, 30, dock->height()), dw->windowTitle());
428
\brief The Q3MainWindow class provides a main application window,
429
with a menu bar, dock windows (e.g. for toolbars), and a status
434
Main windows are most often used to provide menus, toolbars and a
435
status bar around a large central widget, such as a text edit,
436
drawing canvas or QWorkspace (for MDI applications). Q3MainWindow
437
is usually subclassed since this makes it easier to encapsulate
438
the central widget, menus and toolbars as well as the window's
439
state. Subclassing makes it possible to create the slots that are
440
called when the user clicks menu items or toolbar buttons.
442
We'll briefly review adding menu items and
443
toolbar buttons then describe the facilities of Q3MainWindow
447
Q3MainWindow *mw = new Q3MainWindow;
448
QTextEdit *edit = new QTextEdit(mw, "editor");
450
mw->setWindowTitle("Main Window");
451
mw->setCentralWidget(edit);
455
Q3MainWindows may be created in their own right as shown above.
456
The central widget is set with setCentralWidget(). Popup menus can
457
be added to the default menu bar, widgets can be added to the
458
status bar, toolbars and dock windows can be added to any of the
461
The main window will take care of the dock areas, and the geometry
462
of the central widget, but all other aspects of the central widget
463
are left to you. Q3MainWindow automatically detects the creation of
464
a menu bar or status bar if you specify the Q3MainWindow as parent,
465
or you can use the provided menuBar() and statusBar() functions.
466
The functions menuBar() and statusBar() create a suitable widget
467
if one doesn't exist, and update the window's layout to make
470
New dock windows and toolbars can be added to a Q3MainWindow using
471
addDockWindow(). Qt::Dock windows can be moved using moveDockWindow()
472
and removed with removeDockWindow(). Q3MainWindow allows default
473
dock window (toolbar) docking in all its dock areas (\c Top, \c
474
Left, \c Right, \c Bottom). You can use setDockEnabled() to
475
enable and disable docking areas for dock windows. When adding or
476
moving dock windows you can specify their 'edge' (dock area). The
477
currently available edges are: \c Top, \c Left, \c Right, \c
478
Bottom, \c Minimized (effectively a 'hidden' dock area) and \c
479
TornOff (floating). See \l Qt::Dock for an explanation of these
480
areas. Note that the *ToolBar functions are included for backward
481
compatibility; all new code should use the *DockWindow functions.
482
QToolbar is a subclass of Q3DockWindow so all functions that work
483
with dock windows work on toolbars in the same way.
486
If the user clicks the close button, then the dock window is
487
hidden. A dock window can be hidden or unhidden by the user by
488
right clicking a dock area and clicking the name of the relevant
489
dock window on the pop up dock window menu. This menu lists the
490
names of every dock window; visible dock windows have a tick
491
beside their names. The dock window menu is created automatically
492
as required by createDockWindowMenu(). Since it may not always be
493
appropriate for a dock window to appear on this menu the
494
setAppropriate() function is used to inform the main window
495
whether or not the dock window menu should include a particular
496
dock window. Double clicking a dock window handle (usually on the
497
left-hand side of the dock window) undocks (floats) the dock
498
window. Double clicking a floating dock window's title bar will
499
dock the floating dock window. (See also
500
\l{Q3MainWindow::DockWindows}.)
502
Some functions change the appearance of a Q3MainWindow globally:
504
\i Q3DockWindow::setHorizontalStretchable() and
505
Q3DockWindow::setVerticalStretchable() are used to make specific dock
506
windows or toolbars stretchable.
507
\i setUsesBigPixmaps() is used to set whether tool buttons should
508
draw small or large pixmaps (see QIcon for more information).
509
\i setUsesTextLabel() is used to set whether tool buttons
510
should display a textual label in addition to pixmaps
511
(see QToolButton for more information).
514
The user can drag dock windows into any enabled docking area. Qt::Dock
515
windows can also be dragged \e within a docking area, for example
516
to rearrange the order of some toolbars. Qt::Dock windows can also be
517
dragged outside any docking area (undocked or 'floated'). Being
518
able to drag dock windows can be enabled (the default) and
519
disabled using setDockWindowsMovable().
521
The \c Minimized edge is a hidden dock area. If this dock area is
522
enabled the user can hide (minimize) a dock window or show (restore)
523
a minimized dock window by clicking the dock window handle. If the
524
user hovers the mouse cursor over one of the handles, the caption of
525
the dock window is displayed in a tool tip (see
526
Q3DockWindow::windowTitle() or Q3ToolBar::label()), so if you enable the
527
\c Minimized dock area, it is best to specify a meaningful caption
528
or label for each dock window. To minimize a dock window
529
programmatically use moveDockWindow() with an edge of \c Minimized.
531
Qt::Dock windows are moved transparently by default, i.e. during the
532
drag an outline rectangle is drawn on the screen representing the
533
position of the dock window as it moves. If you want the dock
534
window to be shown normally whilst it is moved use
537
The location of a dock window, i.e. its dock area and position
538
within the dock area, can be determined by calling getLocation().
539
Movable dock windows can be lined up to minimize wasted space with
540
lineUpDockWindows(). Pointers to the dock areas are available from
541
topDock(), leftDock(), rightDock() and bottomDock(). A customize
542
menu item is added to the pop up dock window menu if
543
isCustomizable() returns true; it returns false by default.
544
Reimplement isCustomizable() and customize() if you want to offer
545
this extra menu item, for example, to allow the user to change
546
settings relating to the main window and its toolbars and dock
549
The main window's menu bar is fixed (at the top) by default. If
550
you want a movable menu bar, create a QMenuBar as a stretchable
551
widget inside its own movable dock window and restrict this dock
552
window to only live within the \c Top or \c Bottom dock:
555
Q3ToolBar *tb = new Q3ToolBar(this);
556
addDockWindow(tb, tr("Menubar"), Top, false);
557
QMenuBar *mb = new QMenuBar(tb);
558
mb->setFrameStyle(QFrame::NoFrame);
559
tb->setStretchableWidget(mb);
560
setDockEnabled(tb, Left, false);
561
setDockEnabled(tb, Right, false);
564
An application with multiple dock windows can choose to save the
565
current dock window layout in order to restore it later, e.g. in
566
the next session. You can do this by using the streaming operators
569
To save the layout and positions of all the dock windows do this:
572
QFile file(filename);
573
if (file.open(IO_WriteOnly)) {
574
QTextStream stream(&file);
575
stream << *mainWindow;
580
To restore the dock window positions and sizes (normally when the
581
application is next started), do the following:
584
QFile file(filename);
585
if (file.open(IO_ReadOnly)) {
586
QTextStream stream(&file);
587
stream >> *mainWindow;
592
The QSettings class can be used in conjunction with the streaming
593
operators to store the application's settings.
595
Q3MainWindow's management of dock windows and toolbars is done
596
transparently behind-the-scenes by Q3DockArea.
598
For multi-document interfaces (MDI), use a QWorkspace as the
601
Adding dock windows, e.g. toolbars, to Q3MainWindow's dock areas is
602
straightforward. If the supplied dock areas are not sufficient for
603
your application we suggest that you create a QWidget subclass and
604
add your own dock areas (see \l Q3DockArea) to the subclass since
605
Q3MainWindow provides functionality specific to the standard dock
608
\sa Q3ToolBar Q3DockWindow QStatusBar QAction QMenuBar Q3PopupMenu QDialog
612
\enum Q3MainWindow::DockWindows
614
Right-clicking a dock area will pop-up the dock window menu
615
(createDockWindowMenu() is called automatically). When called in
616
code you can specify what items should appear on the menu with
619
\value OnlyToolBars The menu will list all the toolbars, but not
620
any other dock windows.
622
\value NoToolBars The menu will list dock windows but not
625
\value AllDockWindows The menu will list all toolbars and other
626
dock windows. (This is the default.)
630
\fn void Q3MainWindow::addToolBar(Q3DockWindow *dockWindow,
631
Qt::Dock position, bool newLine);
633
Adds a new toolbar to the \a dockWindow. The toolbar is placed in
634
the given \a position. If \a newLine is true the toolbar is put on
639
\fn void Q3MainWindow::addToolBar(Q3DockWindow *dockWindow, const
640
QString &label, Qt::Dock position, bool newLine)
643
The toolbar has the caption \a label and is placed in the given \a
648
\fn void Q3MainWindow::moveToolBar(Q3DockWindow *dockWindow, Qt::Dock position);
650
Moves the given \a dockWindow into the given \a position.
654
\fn void Q3MainWindow::moveToolBar(Q3DockWindow *dockWindow,
655
Qt::Dock position, bool nl, int index, int extraOffset)
658
The \a dockWindow is made the \a{index}-th item in the toolbar,
659
moved over by \a extraOffset. If \a nl is true, the dock window is
664
\fn void Q3MainWindow::removeToolBar(Q3DockWindow *dockWindow);
666
Removes the toolbar from the given \a dockWindow.
670
\fn void Q3MainWindow::lineUpToolBars(bool keepNewLines);
672
Lines up the toolbars. Line breaks are preserved if \a
673
keepNewLines is true.
677
\fn void Q3MainWindow::toolBarPositionChanged(Q3ToolBar *toolbar);
679
This signal is emitted when a \a toolbar is moved.
683
\fn bool Q3MainWindow::toolBarsMovable() const
687
\fn void Q3MainWindow::setToolBarsMovable(bool b)
688
If \a b is true the tool bars can be moved.
692
Constructs an empty main window. The \a parent, \a name and widget
693
flags \a f, are passed on to the QWidget constructor.
695
By default, the widget flags are set to \c Qt::WType_TopLevel rather
696
than 0 as they are with QWidget. If you don't want your
697
Q3MainWindow to be a top level widget then you will need to set \a
701
Q3MainWindow::Q3MainWindow(QWidget * parent, const char * name, Qt::WFlags f)
702
: QWidget(*new Q3MainWindowPrivate, parent, f)
706
setAttribute(Qt::WA_PaintOnScreen); // disable double buffering
712
installEventFilter(this);
713
d->topDock = new Q3DockArea(Qt::Horizontal, Q3DockArea::Normal, this, "qt_top_dock");
714
d->topDock->installEventFilter(this);
715
d->bottomDock = new Q3DockArea(Qt::Horizontal, Q3DockArea::Reverse, this, "qt_bottom_dock");
716
d->bottomDock->installEventFilter(this);
717
d->leftDock = new Q3DockArea(Qt::Vertical, Q3DockArea::Normal, this, "qt_left_dock");
718
d->leftDock->installEventFilter(this);
719
d->rightDock = new Q3DockArea(Qt::Vertical, Q3DockArea::Reverse, this, "qt_right_dock");
720
d->rightDock->installEventFilter(this);
721
d->hideDock = new QHideDock(this);
726
Destroys the object and frees any allocated resources.
729
Q3MainWindow::~Q3MainWindow()
734
#ifndef QT_NO_MENUBAR
736
Sets this main window to use the menu bar \a newMenuBar.
738
The existing menu bar (if any) is deleted along with its contents.
743
void Q3MainWindow::setMenuBar(QMenuBar * newMenuBar)
751
d->mb->installEventFilter(this);
757
Returns the menu bar for this window.
759
If there isn't one, then menuBar() creates an empty menu bar.
764
QMenuBar * Q3MainWindow::menuBar() const
766
Q_D(const Q3MainWindow);
770
QObjectList l = queryList("QMenuBar", 0, false, false);
773
b = static_cast<QMenuBar *>(l.at(0));
775
b = new QMenuBar((Q3MainWindow *)this);
776
b->setObjectName("automatic menu bar");
780
d->mb->installEventFilter(const_cast<Q3MainWindow *>(this));
781
((Q3MainWindow *)this)->triggerLayout();
784
#endif // QT_NO_MENUBAR
787
Sets this main window to use the status bar \a newStatusBar.
789
The existing status bar (if any) is deleted along with its
792
Note that \a newStatusBar \e must be a child of this main window,
793
and that it is not automatically displayed. If you call this
794
function after show(), you will probably also need to call
795
newStatusBar->show().
797
\sa setMenuBar() statusBar()
800
void Q3MainWindow::setStatusBar(QStatusBar * newStatusBar)
803
if (!newStatusBar || newStatusBar == d->sb)
807
d->sb = newStatusBar;
809
// ### this code can cause unnecessary creation of a tool tip group
810
connect(toolTipGroup(), SIGNAL(showTip(QString)),
811
d->sb, SLOT(showMessage(QString)));
812
connect(toolTipGroup(), SIGNAL(removeTip()),
813
d->sb, SLOT(clearMessage()));
815
d->sb->installEventFilter(this);
821
Returns this main window's status bar. If there isn't one,
822
statusBar() creates an empty status bar, and if necessary a tool
828
QStatusBar * Q3MainWindow::statusBar() const
830
Q_D(const Q3MainWindow);
834
QObjectList l = queryList("QStatusBar", 0, false, false);
837
s = (QStatusBar *)l.at(0);
839
s = new QStatusBar((Q3MainWindow *)this, "automatic status bar");
842
((Q3MainWindow *)this)->setStatusBar(s);
843
((Q3MainWindow *)this)->triggerLayout(true);
850
Sets this main window to use the tool tip group \a
853
The existing tool tip group (if any) is deleted along with its
854
contents. All the tool tips connected to it lose the ability to
855
display the group texts.
860
void Q3MainWindow::setToolTipGroup(QToolTipGroup * newToolTipGroup)
863
if (!newToolTipGroup || newToolTipGroup == d->ttg)
867
d->ttg = newToolTipGroup;
869
connect(toolTipGroup(), SIGNAL(showTip(QString)),
870
statusBar(), SLOT(showMessage(QString)));
871
connect(toolTipGroup(), SIGNAL(removeTip()),
872
statusBar(), SLOT(clearMessage()));
877
Returns this main window's tool tip group. If there isn't one,
878
toolTipGroup() creates an empty tool tip group.
880
\sa menuBar() statusBar()
882
QToolTipGroup * Q3MainWindow::toolTipGroup() const
884
Q_D(const Q3MainWindow);
888
QToolTipGroup * t = new QToolTipGroup((Q3MainWindow*)this,
889
"automatic tool tip group");
890
((Q3MainWindowPrivate*)d)->ttg = t;
897
If \a enable is true then users can dock windows in the \a dock
898
area. If \a enable is false users cannot dock windows in the \a
901
Users can dock (drag) dock windows into any enabled dock area.
904
void Q3MainWindow::setDockEnabled(Qt::Dock dock, bool enable)
906
d_func()->docks.insert(dock, enable);
911
Returns true if the \a dock dock area is enabled, i.e. it can
912
accept user dragged dock windows; otherwise returns false.
917
bool Q3MainWindow::isDockEnabled(Qt::Dock dock) const
919
return d_func()->docks[dock];
925
Returns true if dock area \a area is enabled, i.e. it can accept
926
user dragged dock windows; otherwise returns false.
931
bool Q3MainWindow::isDockEnabled(Q3DockArea *area) const
933
Q_D(const Q3MainWindow);
934
if (area == d->leftDock)
935
return d->docks[Qt::DockLeft];
936
if (area == d->rightDock)
937
return d->docks[Qt::DockRight];
938
if (area == d->topDock)
939
return d->docks[Qt::DockTop];
940
if (area == d->bottomDock)
941
return d->docks[Qt::DockBottom];
948
If \a enable is true then users can dock the \a dw dock window in
949
the \a dock area. If \a enable is false users cannot dock the \a
950
dw dock window in the \a dock area.
952
In general users can dock (drag) dock windows into any enabled
953
dock area. Using this function particular dock areas can be
954
enabled (or disabled) as docking points for particular dock
959
void Q3MainWindow::setDockEnabled(Q3DockWindow *dw, Qt::Dock dock, bool enable)
962
if (d->dockWindows.contains(dw)) {
963
d->dockWindows.append(dw);
964
connect(dw, SIGNAL(placeChanged(Q3DockWindow::Place)),
965
this, SLOT(slotPlaceChanged()));
968
s.sprintf("%p_%d", (void*)dw, (int)dock);
970
d->disabledDocks.removeAll(s);
971
else if (!d->disabledDocks.contains(s))
972
d->disabledDocks << s;
975
topDock()->setAcceptDockWindow(dw, enable);
978
leftDock()->setAcceptDockWindow(dw, enable);
981
rightDock()->setAcceptDockWindow(dw, enable);
984
bottomDock()->setAcceptDockWindow(dw, enable);
994
Returns true if dock area \a area is enabled for the dock window
995
\a dw; otherwise returns false.
1000
bool Q3MainWindow::isDockEnabled(Q3DockWindow *dw, Q3DockArea *area) const
1002
Q_D(const Q3MainWindow);
1003
if (!isDockEnabled(area))
1006
if (area == d->leftDock)
1007
dock = Qt::DockLeft;
1008
else if (area == d->rightDock)
1009
dock = Qt::DockRight;
1010
else if (area == d->topDock)
1012
else if (area == d->bottomDock)
1013
dock = Qt::DockBottom;
1016
return isDockEnabled(dw, dock);
1022
Returns true if dock area \a dock is enabled for the dock window
1023
\a tb; otherwise returns false.
1025
\sa setDockEnabled()
1028
bool Q3MainWindow::isDockEnabled(Q3DockWindow *tb, Qt::Dock dock) const
1030
if (!isDockEnabled(dock))
1033
s.sprintf("%p_%d", (void*)tb, (int)dock);
1034
return !d_func()->disabledDocks.contains(s);
1040
Adds \a dockWindow to the \a edge dock area.
1042
If \a newLine is false (the default) then the \a dockWindow is
1043
added at the end of the \a edge. For vertical edges the end is at
1044
the bottom, for horizontal edges (including \c Minimized) the end
1045
is at the right. If \a newLine is true a new line of dock windows
1046
is started with \a dockWindow as the first (left-most and
1047
top-most) dock window.
1049
If \a dockWindow is managed by another main window, it is first
1050
removed from that window.
1053
void Q3MainWindow::addDockWindow(Q3DockWindow *dockWindow,
1054
Qt::Dock edge, bool newLine)
1058
extern WindowPtr qt_mac_window_for(const QWidget*); //qwidget_mac.cpp
1059
if(isWindow() && edge == Qt::DockTop)
1060
ChangeWindowAttributes(qt_mac_window_for(this), kWindowToolbarButtonAttribute, 0);
1062
moveDockWindow(dockWindow, edge);
1063
dockWindow->setNewLine(newLine);
1064
if (!d->dockWindows.contains(dockWindow)) {
1065
d->dockWindows.append(dockWindow);
1066
connect(dockWindow, SIGNAL(placeChanged(Q3DockWindow::Place)),
1067
this, SLOT(slotPlaceChanged()));
1068
dockWindow->installEventFilter(this);
1070
dockWindow->setOpaqueMoving(d->opaque);
1077
Adds \a dockWindow to the dock area with label \a label.
1079
If \a newLine is false (the default) the \a dockWindow is added at
1080
the end of the \a edge. For vertical edges the end is at the
1081
bottom, for horizontal edges (including \c Minimized) the end is
1082
at the right. If \a newLine is true a new line of dock windows is
1083
started with \a dockWindow as the first (left-most and top-most)
1086
If \a dockWindow is managed by another main window, it is first
1087
removed from that window.
1090
void Q3MainWindow::addDockWindow(Q3DockWindow * dockWindow, const QString &label,
1091
Qt::Dock edge, bool newLine)
1093
addDockWindow(dockWindow, edge, newLine);
1094
#ifndef QT_NO_TOOLBAR
1095
Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(dockWindow);
1097
tb->setLabel(label);
1102
Moves \a dockWindow to the end of the \a edge.
1104
For vertical edges the end is at the bottom, for horizontal edges
1105
(including \c Minimized) the end is at the right.
1107
If \a dockWindow is managed by another main window, it is first
1108
removed from that window.
1111
void Q3MainWindow::moveDockWindow(Q3DockWindow * dockWindow, Qt::Dock edge)
1114
Qt::Orientation oo = dockWindow->orientation();
1117
if (dockWindow->area() != d->topDock)
1118
dockWindow->removeFromDock(false);
1119
d->topDock->moveDockWindow(dockWindow);
1120
emit dockWindowPositionChanged(dockWindow);
1122
case Qt::DockBottom:
1123
if (dockWindow->area() != d->bottomDock)
1124
dockWindow->removeFromDock(false);
1125
d->bottomDock->moveDockWindow(dockWindow);
1126
emit dockWindowPositionChanged(dockWindow);
1129
if (dockWindow->area() != d->rightDock)
1130
dockWindow->removeFromDock(false);
1131
d->rightDock->moveDockWindow(dockWindow);
1132
emit dockWindowPositionChanged(dockWindow);
1135
if (dockWindow->area() != d->leftDock)
1136
dockWindow->removeFromDock(false);
1137
d->leftDock->moveDockWindow(dockWindow);
1138
emit dockWindowPositionChanged(dockWindow);
1140
case Qt::DockTornOff:
1141
dockWindow->undock();
1143
case Qt::DockMinimized:
1144
dockWindow->undock(d->hideDock);
1146
case Qt::DockUnmanaged:
1150
if (oo != dockWindow->orientation())
1151
dockWindow->setOrientation(dockWindow->orientation());
1157
Moves \a dockWindow to position \a index within the \a edge dock
1160
Any dock windows with positions \a index or higher have their
1161
position number incremented and any of these on the same line are
1162
moved right (down for vertical dock areas) to make room.
1164
If \a nl is true, a new dock window line is created below the line
1165
in which the moved dock window appears and the moved dock window,
1166
with any others with higher positions on the same line, is moved
1169
The \a extraOffset is the space to put between the left side of
1170
the dock area (top side for vertical dock areas) and the dock
1171
window. (This is mostly used for restoring dock windows to the
1172
positions the user has dragged them to.)
1174
If \a dockWindow is managed by another main window, it is first
1175
removed from that window.
1178
void Q3MainWindow::moveDockWindow(Q3DockWindow * dockWindow, Qt::Dock edge, bool nl, int index, int extraOffset)
1181
Qt::Orientation oo = dockWindow->orientation();
1183
dockWindow->setNewLine(nl);
1184
dockWindow->setOffset(extraOffset);
1187
if (dockWindow->area() != d->topDock)
1188
dockWindow->removeFromDock(false);
1189
d->topDock->moveDockWindow(dockWindow, index);
1191
case Qt::DockBottom:
1192
if (dockWindow->area() != d->bottomDock)
1193
dockWindow->removeFromDock(false);
1194
d->bottomDock->moveDockWindow(dockWindow, index);
1197
if (dockWindow->area() != d->rightDock)
1198
dockWindow->removeFromDock(false);
1199
d->rightDock->moveDockWindow(dockWindow, index);
1202
if (dockWindow->area() != d->leftDock)
1203
dockWindow->removeFromDock(false);
1204
d->leftDock->moveDockWindow(dockWindow, index);
1206
case Qt::DockTornOff:
1207
dockWindow->undock();
1209
case Qt::DockMinimized:
1210
dockWindow->undock(d->hideDock);
1212
case Qt::DockUnmanaged:
1216
if (oo != dockWindow->orientation())
1217
dockWindow->setOrientation(dockWindow->orientation());
1221
Removes \a dockWindow from the main window's docking area,
1222
provided \a dockWindow is non-null and managed by this main
1226
void Q3MainWindow::removeDockWindow(Q3DockWindow * dockWindow)
1231
extern WindowPtr qt_mac_window_for(const QWidget*); //qwidget_mac.cpp
1232
if(isWindow() && dockWindow->area() == topDock() && !dockWindows(Qt::DockTop).count())
1233
ChangeWindowAttributes(qt_mac_window_for(this), 0, kWindowToolbarButtonAttribute);
1237
d->dockWindows.removeAll(dockWindow);
1238
disconnect(dockWindow, SIGNAL(placeChanged(Q3DockWindow::Place)),
1239
this, SLOT(slotPlaceChanged()));
1240
dockWindow->removeEventFilter(this);
1244
Sets up the geometry management of the window. It is called
1245
automatically when needed, so you shouldn't need to call it.
1248
void Q3MainWindow::setUpLayout()
1251
#ifndef QT_NO_MENUBAR
1253
// slightly evil hack here. reconsider this
1254
QObjectList l = queryList("QMenuBar", 0, false, false);
1261
QObjectList l = queryList("QStatusBar", 0, false, false);
1263
d->sb = statusBar();
1267
d->tll = new QBoxLayout(this, QBoxLayout::Down);
1268
d->tll->setResizeMode(minimumSize().isNull() ? QLayout::Minimum : QLayout::FreeResize);
1270
d->tll->setMenuBar(0);
1272
while ((item = d->tll->takeAt(0)))
1276
#ifndef QT_NO_MENUBAR
1277
if (d->mb && d->mb->isVisibleTo(this)) {
1278
d->tll->setMenuBar(d->mb);
1279
if (style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this))
1280
d->tll->addSpacing(d->movable ? 1 : 2);
1284
d->tll->addWidget(d->hideDock);
1285
if(d->topDock->parentWidget() == this)
1286
d->tll->addWidget(d->topDock);
1288
Q3MainWindowLayout *mwl = new Q3MainWindowLayout(this, d->tll);
1289
d->tll->setStretchFactor(mwl, 1);
1291
if(d->leftDock->parentWidget() == this)
1292
mwl->setLeftDock(d->leftDock);
1293
if (centralWidget())
1294
mwl->setCentralWidget(centralWidget());
1295
if(d->rightDock->parentWidget() == this)
1296
mwl->setRightDock(d->rightDock);
1299
if(d->bottomDock->parentWidget() == this)
1300
d->tll->addWidget(d->bottomDock);
1302
if (d->sb && d->sb->parentWidget() == this) {
1303
d->tll->addWidget(d->sb, 0);
1304
// make the sb stay on top of tool bars if there isn't enough space
1310
void Q3MainWindow::setVisible(bool visible)
1317
// show all floating dock windows not explicitly hidden
1319
for (int i = 0; i < d->dockWindows.size(); ++i) {
1320
Q3DockWindow *dw = d->dockWindows.at(i);
1321
if (dw->isWindow() && !dw->isVisible() && !dw->testAttribute(Qt::WA_WState_Hidden)) {
1322
reinterpret_cast<Q3MainWindow *>(dw)->setAttribute(Qt::WA_WState_Hidden);
1327
} else if (isVisible()) {
1328
for (int i = 0; i < d->dockWindows.size(); ++i) {
1329
Q3DockWindow *dw = d->dockWindows.at(i);
1330
if (dw->isWindow() && dw->isVisible()) {
1331
dw->hide(); // implicit hide, so clear forcehide
1332
reinterpret_cast<Q3MainWindow *>(dw)->setAttribute(Qt::WA_WState_Hidden, false);
1336
QWidget::setVisible(visible);
1341
QSize Q3MainWindow::sizeHint() const
1343
Q3MainWindow* that = (Q3MainWindow*) this;
1344
// Workaround: because d->tll get's deleted in
1345
// totalSizeHint->polish->sendPostedEvents->childEvent->triggerLayout
1346
// [eg. canvas example on Qt/Embedded]
1347
QApplication::sendPostedEvents(that, QEvent::ChildInserted);
1348
if (!that->d_func()->tll)
1349
that->setUpLayout();
1350
return that->d_func()->tll->totalSizeHint();
1354
QSize Q3MainWindow::minimumSizeHint() const
1356
Q_D(const Q3MainWindow);
1358
Q3MainWindow* that = (Q3MainWindow*) this;
1359
that->setUpLayout();
1361
return d->tll->totalMinimumSize();
1365
Sets the central widget for this main window to \a w.
1367
The central widget is surrounded by the left, top, right and
1368
bottom dock areas. The menu bar is above the top dock area.
1373
void Q3MainWindow::setCentralWidget(QWidget * w)
1377
d->mc->removeEventFilter(this);
1380
d->mc->installEventFilter(this);
1386
Returns a pointer to the main window's central widget.
1388
The central widget is surrounded by the left, top, right and
1389
bottom dock areas. The menu bar is above the top dock area.
1391
\sa setCentralWidget()
1394
QWidget * Q3MainWindow::centralWidget() const
1396
return d_func()->mc;
1402
void Q3MainWindow::paintEvent(QPaintEvent *)
1406
style()->styleHint(QStyle::SH_MainWindow_SpaceBelowMenuBar, 0, this)) {
1408
int y = d->mb->height() + 1;
1409
QStyleOption opt(0, QStyleOption::SO_Default);
1410
opt.rect.setRect(0, y, width(), 1);
1411
opt.palette = palette();
1412
opt.state = QStyle::State_Sunken;
1413
style()->drawPrimitive(QStyle::PE_Q3Separator, &opt, &p, this);
1418
bool Q3MainWindow::dockMainWindow(QObject *dock) const
1421
if (dock->parent() &&
1422
dock->parent() == const_cast<Q3MainWindow*>(this))
1424
if (qobject_cast<Q3MainWindow*>(dock->parent()))
1426
dock = dock->parent();
1435
bool Q3MainWindow::eventFilter(QObject* o, QEvent *e)
1438
if (e->type() == QEvent::Show && o == this) {
1442
} else if (e->type() == QEvent::ContextMenu && d->dockMenu &&
1443
(qobject_cast<Q3DockArea*>(o) && dockMainWindow(o) || o == d->hideDock || o == d->mb)) {
1444
if (showDockMenu(((QMouseEvent*)e)->globalPos())) {
1445
((QContextMenuEvent*)e)->accept();
1450
return QWidget::eventFilter(o, e);
1455
Monitors events, received in \a e, to ensure the layout is updated.
1457
void Q3MainWindow::childEvent(QChildEvent* e)
1460
if (e->type() == QEvent::ChildRemoved) {
1461
if (e->child() == 0 ||
1462
!e->child()->isWidgetType() ||
1463
((QWidget*)e->child())->isWindow()) {
1465
} else if (e->child() == d->sb) {
1468
} else if (e->child() == d->mb) {
1471
} else if (e->child() == d->mc) {
1473
d->mwl->setCentralWidget(0);
1475
} else if (qobject_cast<Q3DockWindow*>(e->child())) {
1476
removeDockWindow((Q3DockWindow *)(e->child()));
1477
d->appropriate.remove((Q3DockWindow*)e->child());
1480
} else if (e->type() == QEvent::ChildInserted && !d->sb) {
1481
d->sb = qobject_cast<QStatusBar*>(e->child());
1484
if (!d->tll->findWidget(d->sb))
1485
d->tll->addWidget(d->sb);
1497
bool Q3MainWindow::event(QEvent * e)
1500
if (e->type() == QEvent::StatusTip) {
1502
d->sb->showMessage(static_cast<QStatusTipEvent*>(e)->tip());
1506
if (e->type() == QEvent::ToolBarChange) {
1507
// Keep compatibility with the Qt 3 main window, use the real main window
1508
// or reimplement if you want proper handling.
1510
Q3DockArea *area = topDock();
1511
if (area->width() >= area->height()) {
1512
deltaH = area->sizeHint().height();
1513
if (!area->isVisible()) {
1522
QApplication::sendPostedEvents(this, QEvent::LayoutRequest);
1523
resize(width(), height() + deltaH);
1527
if (e->type() == QEvent::ChildRemoved && ((QChildEvent*)e)->child() == d->mc) {
1528
d->mc->removeEventFilter(this);
1530
d->mwl->setCentralWidget(0);
1533
return QWidget::event(e);
1538
\property Q3MainWindow::usesBigPixmaps
1539
\brief whether big pixmaps are enabled
1541
If false (the default), the tool buttons will use small pixmaps;
1542
otherwise big pixmaps will be used.
1544
Tool buttons and other widgets that wish to respond to this
1545
setting are responsible for reading the correct state on startup,
1546
and for connecting to the main window's widget's
1547
pixmapSizeChanged() signal.
1550
bool Q3MainWindow::usesBigPixmaps() const
1552
return d_func()->ubp;
1555
void Q3MainWindow::setUsesBigPixmaps(bool enable)
1558
if (enable == (bool)d->ubp)
1562
emit pixmapSizeChanged(enable);
1564
QObjectList l = queryList("QLayout");
1565
for (int i = 0; i < l.size(); ++i)
1566
static_cast<QLayout *>(l.at(i))->activate();
1570
\property Q3MainWindow::usesTextLabel
1571
\brief whether text labels for toolbar buttons are enabled
1573
If disabled (the default), the tool buttons will not use text
1574
labels. If enabled, text labels will be used.
1576
Tool buttons and other widgets that wish to respond to this
1577
setting are responsible for reading the correct state on startup,
1578
and for connecting to the main window's widget's
1579
usesTextLabelChanged() signal.
1581
\sa QToolButton::setUsesTextLabel()
1584
bool Q3MainWindow::usesTextLabel() const
1586
return d_func()->utl;
1590
void Q3MainWindow::setUsesTextLabel(bool enable)
1593
if (enable == (bool)d->utl)
1597
emit usesTextLabelChanged(enable);
1599
QObjectList l = queryList("QLayout");
1600
for (int i = 0; i < l.size(); ++i)
1601
static_cast<QLayout *>(l.at(i))->activate();
1606
\fn void Q3MainWindow::pixmapSizeChanged(bool b)
1608
This signal is emitted whenever the setUsesBigPixmaps() is called
1609
with a value different to the current setting. The new value is
1610
passed in \a b. All widgets that should respond to such changes,
1611
e.g. toolbar buttons, must connect to this signal.
1615
\fn void Q3MainWindow::usesTextLabelChanged(bool b)
1617
This signal is emitted whenever the setUsesTextLabel() is called
1618
with a value different to the current setting. The new value is
1619
passed in \a b. All widgets that should respond to such changes,
1620
e.g. toolbar buttons, must connect to this signal.
1624
\fn void Q3MainWindow::dockWindowPositionChanged(Q3DockWindow *dockWindow)
1626
This signal is emitted when the \a dockWindow has changed its
1627
position. A change in position occurs when a dock window is moved
1628
within its dock area or moved to another dock area (including the
1629
\c Minimized and \c TearOff dock areas).
1634
void Q3MainWindow::setRightJustification(bool enable)
1637
if (enable == (bool)d->justify)
1639
d->justify = enable;
1640
triggerLayout(true);
1645
\property Q3MainWindow::rightJustification
1646
\brief whether the main window right-justifies its dock windows
1648
If disabled (the default), stretchable dock windows are expanded,
1649
and non-stretchable dock windows are given the minimum space they
1650
need. Since most dock windows are not stretchable, this usually
1651
results in an unjustified right edge (or unjustified bottom edge
1652
for a vertical dock area). If enabled, the main window will
1653
right-justify its dock windows.
1655
\sa Q3DockWindow::setVerticalStretchable(), Q3DockWindow::setHorizontalStretchable()
1658
bool Q3MainWindow::rightJustification() const
1660
return d_func()->justify;
1666
void Q3MainWindow::triggerLayout(bool deleteLayout)
1669
if (deleteLayout || !d->tll)
1671
QApplication::postEvent(this, new QEvent(QEvent::LayoutHint));
1675
Enters 'What's This?' mode and returns immediately.
1677
This is the same as QWhatsThis::enterWhatsThisMode(), but
1678
implemented as a main window object's slot. This way it can easily
1679
be used for popup menus, for example:
1682
Q3PopupMenu * help = new Q3PopupMenu(this);
1683
help->insertItem("What's &This", this , SLOT(enterWhatsThis()), Qt::SHIFT+Qt::Key_F1);
1686
\sa Q3WhatsThis::enterWhatsThisMode()
1688
void Q3MainWindow::whatsThis()
1690
#ifndef QT_NO_WHATSTHIS
1691
QWhatsThis::enterWhatsThisMode();
1696
Finds the location of the dock window \a dw.
1698
If the \a dw dock window is found in the main window the function
1699
returns true and populates the \a dock variable with the dw's dock
1700
area and the \a index with the dw's position within the dock area.
1701
It also sets \a nl to true if the \a dw begins a new line
1702
(otherwise false), and \a extraOffset with the dock window's offset.
1704
If the \a dw dock window is not found then the function returns
1705
false and the state of \a dock, \a index, \a nl and \a extraOffset
1708
If you want to save and restore dock window positions then use
1709
operator>>() and operator<<().
1712
bool Q3MainWindow::getLocation(Q3DockWindow *dw, Qt::Dock &dock, int &index, bool &nl, int &extraOffset) const
1714
Q_D(const Q3MainWindow);
1715
dock = Qt::DockTornOff;
1716
if (d->topDock->hasDockWindow(dw, &index))
1718
else if (d->bottomDock->hasDockWindow(dw, &index))
1719
dock = Qt::DockBottom;
1720
else if (d->leftDock->hasDockWindow(dw, &index))
1721
dock = Qt::DockLeft;
1722
else if (d->rightDock->hasDockWindow(dw, &index))
1723
dock = Qt::DockRight;
1724
else if (dw->parentWidget() == d->hideDock) {
1726
dock = Qt::DockMinimized;
1731
extraOffset = dw->offset();
1735
#ifndef QT_NO_TOOLBAR
1737
Returns a list of all the toolbars which are in the \a dock dock
1738
area, regardless of their state.
1740
For example, the \c TornOff dock area may contain closed toolbars
1741
but these are returned along with the visible toolbars.
1746
QList<Q3ToolBar *> Q3MainWindow::toolBars(Qt::Dock dock) const
1748
QList<Q3DockWindow *> lst = dockWindows(dock);
1749
QList<Q3ToolBar *> tbl;
1750
for (int i = 0; i < lst.size(); ++i) {
1751
Q3ToolBar *tb = qobject_cast<Q3ToolBar *>(lst.at(i));
1760
Returns a list of all the dock windows which are in the \a dock
1761
dock area, regardless of their state.
1763
For example, the \c Qt::DockTornOff dock area may contain closed dock
1764
windows but these are returned along with the visible dock
1768
QList<Q3DockWindow *> Q3MainWindow::dockWindows(Qt::Dock dock) const
1770
Q_D(const Q3MainWindow);
1771
QList<Q3DockWindow *> lst;
1774
return d->topDock->dockWindowList();
1775
case Qt::DockBottom:
1776
return d->bottomDock->dockWindowList();
1778
return d->leftDock->dockWindowList();
1780
return d->rightDock->dockWindowList();
1781
case Qt::DockTornOff: {
1782
for (int i = 0; i < d->dockWindows.size(); ++i) {
1783
Q3DockWindow *w = d->dockWindows.at(i);
1784
if (!w->area() && w->place() == Q3DockWindow::OutsideDock)
1789
case Qt::DockMinimized: {
1790
QObjectList childs = d->hideDock->children();
1791
for (int i = 0; i < childs.size(); ++i) {
1792
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(childs.at(i));
1807
Returns the list of dock windows which belong to this main window,
1808
regardless of which dock area they are in or what their state is,
1809
(e.g. irrespective of whether they are visible or not).
1812
QList<Q3DockWindow *> Q3MainWindow::dockWindows() const
1814
return d_func()->dockWindows;
1817
void Q3MainWindow::setDockWindowsMovable(bool enable)
1820
d->movable = enable;
1821
QObjectList l = queryList("Q3DockWindow");
1822
for (int i = 0; i < l.size(); ++i)
1823
static_cast<Q3DockWindow*>(l.at(i))->setMovingEnabled(enable);
1827
\property Q3MainWindow::dockWindowsMovable
1828
\brief whether the dock windows are movable
1830
If true (the default), the user will be able to move movable dock
1831
windows from one Q3MainWindow dock area to another, including the
1832
\c TearOff area (i.e. where the dock window floats freely as a
1833
window in its own right), and the \c Minimized area (where only
1834
the dock window's handle is shown below the menu bar). Movable
1835
dock windows can also be moved within Q3MainWindow dock areas, i.e.
1836
to rearrange them within a dock area.
1838
If false the user will not be able to move any dock windows.
1840
By default dock windows are moved transparently (i.e. only an
1841
outline rectangle is shown during the drag), but this setting can
1842
be changed with setOpaqueMoving().
1844
\sa setDockEnabled(), setOpaqueMoving()
1847
bool Q3MainWindow::dockWindowsMovable() const
1849
return d_func()->movable;
1852
void Q3MainWindow::setOpaqueMoving(bool b)
1856
QObjectList l = queryList("Q3DockWindow");
1857
for (int i = 0; i < l.size(); ++i)
1858
static_cast<Q3DockWindow*>(l.at(i))->setOpaqueMoving(b);
1862
\property Q3MainWindow::opaqueMoving
1863
\brief whether dock windows are moved opaquely
1865
If true the dock windows of the main window are shown opaquely
1866
(i.e. it shows the toolbar as it looks when docked) whilst it is
1867
being moved. If false (the default) they are shown transparently,
1868
(i.e. as an outline rectangle).
1870
\warning Opaque moving of toolbars and dockwindows is known to
1871
have several problems. We recommend avoiding the use of this
1872
feature for the time being. We intend fixing the problems in a
1876
bool Q3MainWindow::opaqueMoving() const
1878
return d_func()->opaque;
1882
This function will line up dock windows within the visible dock
1883
areas (\c Top, \c Left, \c Right and \c Bottom) as compactly as
1886
If \a keepNewLines is true, all dock windows stay on their
1887
original lines. If \a keepNewLines is false then newlines may be
1888
removed to achieve the most compact layout possible.
1890
The method only works if dockWindowsMovable() returns true.
1893
void Q3MainWindow::lineUpDockWindows(bool keepNewLines)
1895
Q_D(const Q3MainWindow);
1896
if (!dockWindowsMovable())
1898
d->topDock->lineUp(keepNewLines);
1899
d->leftDock->lineUp(keepNewLines);
1900
d->rightDock->lineUp(keepNewLines);
1901
d->bottomDock->lineUp(keepNewLines);
1905
Returns true, if the dock window menu is enabled; otherwise
1908
The menu lists the (appropriate()) dock windows (which may be
1909
shown or hidden), and has a "Line Up Dock Windows" menu item. It
1910
will also have a "Customize" menu item if isCustomizable() returns
1913
\sa setDockEnabled(), lineUpDockWindows() appropriate()
1917
bool Q3MainWindow::isDockMenuEnabled() const
1919
return d_func()->dockMenu;
1923
If \a b is true, then right clicking on a dock window or dock area
1924
will pop up the dock window menu. If \a b is false, right clicking
1925
a dock window or dock area will not pop up the menu.
1927
The menu lists the (appropriate()) dock windows (which may be
1928
shown or hidden), and has a "Line Up Dock Windows" item. It will
1929
also have a "Customize" menu item if isCustomizable() returns
1932
\sa lineUpDockWindows(), isDockMenuEnabled()
1935
void Q3MainWindow::setDockMenuEnabled(bool b)
1937
d_func()->dockMenu = b;
1941
Creates the dock window menu which contains all toolbars (if \a
1942
dockWindows is \c OnlyToolBars), all dock windows (if \a
1943
dockWindows is \c NoToolBars) or all toolbars and dock windows (if
1944
\a dockWindows is \c AllDockWindows - the default).
1946
This function is called internally when necessary, e.g. when the
1947
user right clicks a dock area (providing isDockMenuEnabled()
1948
returns true). You can reimplement this function if you wish to
1949
customize the behavior.
1951
The menu items representing the toolbars and dock windows are
1952
checkable. The visible dock windows are checked and the hidden
1953
dock windows are unchecked. The user can click a menu item to
1954
change its state (show or hide the dock window).
1956
The list and the state are always kept up-to-date.
1958
Toolbars and dock windows which are not appropriate in the current
1959
context (see setAppropriate()) are not listed in the menu.
1961
The menu also has a menu item for lining up the dock windows.
1963
If isCustomizable() returns true, a Customize menu item is added
1964
to the menu, which if clicked will call customize(). The
1965
isCustomizable() function we provide returns false and customize()
1966
does nothing, so they must be reimplemented in a subclass to be
1970
Q3PopupMenu *Q3MainWindow::createDockWindowMenu(DockWindows dockWindows) const
1972
QObjectList l = queryList("Q3DockWindow");
1976
Q3PopupMenu *menu = new Q3PopupMenu((Q3MainWindow*)this);
1977
menu->setObjectName("qt_customize_menu");
1978
menu->setCheckable(true);
1982
if (dockWindows == AllDockWindows || dockWindows == NoToolBars) {
1983
for (int i = 0; i < l.size(); ++i) {
1984
Q3DockWindow *dw = (Q3DockWindow*)l.at(i);
1985
if (!appropriate(dw) || qobject_cast<Q3ToolBar*>(dw) || !dockMainWindow(dw))
1987
QString label = dw->windowTitle();
1988
if (!label.isEmpty()) {
1989
QAction *act = menu->addAction(label);
1990
act->setChecked(dw->isVisible());
1991
QObject::connect(act, SIGNAL(triggered()), dw, SLOT(toggleVisible()));
1997
menu->addSeparator();
2000
#ifndef QT_NO_TOOLBAR
2001
if (dockWindows == AllDockWindows || dockWindows == OnlyToolBars) {
2002
for (int i = 0; i < l.size(); ++i) {
2003
Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(l.at(i));
2004
if (!tb || !appropriate(tb) || !dockMainWindow(tb))
2006
QString label = tb->label();
2007
if (!label.isEmpty()) {
2008
QAction *act = menu->addAction(label);
2009
act->setCheckable(true);
2010
act->setChecked(tb->isVisible());
2011
QObject::connect(act, SIGNAL(triggered()), tb, SLOT(toggleVisible()));
2019
menu->addSeparator();
2023
if (dockWindowsMovable())
2024
menu->addAction(tr("Line up"), this, SLOT(doLineUp()));
2025
if (isCustomizable())
2026
menu->addAction(tr("Customize..."), this, SLOT(customize()));
2031
Shows the dock menu at the position \a globalPos. The menu lists
2032
the dock windows so that they can be shown (or hidden), lined up,
2033
and possibly customized. Returns true if the menu is shown;
2034
otherwise returns false.
2036
If you want a custom menu, reimplement this function. You can
2037
create the menu from scratch or call createDockWindowMenu() and
2040
The default implementation uses the dock window menu which gets
2041
created by createDockWindowMenu(). You can reimplement
2042
createDockWindowMenu() if you want to use your own specialized
2046
bool Q3MainWindow::showDockMenu(const QPoint &globalPos)
2052
if(Q3PopupMenu *ret = createDockWindowMenu()) {
2053
ret->exec(globalPos);
2060
void Q3MainWindow::slotPlaceChanged()
2062
QObject* obj = (QObject*)sender();
2063
Q3DockWindow *dw = qobject_cast<Q3DockWindow*>(obj);
2065
emit dockWindowPositionChanged(dw);
2066
#ifndef QT_NO_TOOLBAR
2067
Q3ToolBar *tb = qobject_cast<Q3ToolBar*>(obj);
2069
emit toolBarPositionChanged(tb);
2075
For internal use of Q3DockWindow only.
2078
Q3DockArea *Q3MainWindow::dockingArea(const QPoint &p)
2081
int mh = d->mb ? d->mb->height() : 0;
2082
int sh = d->sb ? d->sb->height() : 0;
2083
if (p.x() >= -5 && p.x() <= 100 && p.y() > mh && p.y() - height() - sh)
2085
if (p.x() >= width() - 100 && p.x() <= width() + 5 && p.y() > mh && p.y() - height() - sh)
2086
return d->rightDock;
2087
if (p.y() >= -5 && p.y() < mh + 100 && p.x() >= 0 && p.x() <= width())
2089
if (p.y() >= height() - sh - 100 && p.y() <= height() + 5 && p.x() >= 0 && p.x() <= width())
2090
return d->bottomDock;
2095
Returns true if \a dw is a dock window known to the main window;
2096
otherwise returns false.
2099
bool Q3MainWindow::hasDockWindow(Q3DockWindow *dw)
2101
return d_func()->dockWindows.contains(dw);
2105
Returns the \c Left dock area
2107
\sa rightDock() topDock() bottomDock()
2110
Q3DockArea *Q3MainWindow::leftDock() const
2112
return d_func()->leftDock;
2116
Returns the \c Right dock area
2118
\sa leftDock() topDock() bottomDock()
2121
Q3DockArea *Q3MainWindow::rightDock() const
2123
return d_func()->rightDock;
2127
Returns the \c Top dock area
2129
\sa bottomDock() leftDock() rightDock()
2132
Q3DockArea *Q3MainWindow::topDock() const
2134
return d_func()->topDock;
2138
Returns a pointer the \c Bottom dock area
2140
\sa topDock() leftDock() rightDock()
2143
Q3DockArea *Q3MainWindow::bottomDock() const
2145
return d_func()->bottomDock;
2149
This function is called when the user clicks the Customize menu
2150
item on the dock window menu.
2152
The customize menu item will only appear if isCustomizable()
2153
returns true (it returns false by default).
2155
The function is intended, for example, to provide the user with a
2156
means of telling the application that they wish to customize the
2157
main window, dock windows or dock areas.
2159
The default implementation does nothing and the Customize menu
2160
item is not shown on the right-click menu by default. If you want
2161
the item to appear then reimplement isCustomizable() to return
2162
true, and reimplement this function to do whatever you want.
2164
\sa isCustomizable()
2167
void Q3MainWindow::customize()
2172
Returns true if the dock area dock window menu includes the
2173
Customize menu item (which calls customize() when clicked).
2174
Returns false by default, i.e. the popup menu will not contain a
2175
Customize menu item. You will need to reimplement this function
2176
and set it to return true if you wish the user to be able to see
2177
the dock window menu.
2182
bool Q3MainWindow::isCustomizable() const
2188
Returns true if it is appropriate to include a menu item for the
2189
\a dw dock window in the dock window menu; otherwise returns
2192
The user is able to change the state (show or hide) a dock window
2193
that has a menu item by clicking the item.
2195
Call setAppropriate() to indicate whether or not a particular dock
2196
window should appear on the popup menu.
2198
\sa setAppropriate()
2201
bool Q3MainWindow::appropriate(Q3DockWindow *dw) const
2203
Q_D(const Q3MainWindow);
2204
QMap<Q3DockWindow*, bool>::ConstIterator it = d->appropriate.find(dw);
2205
if (it == d->appropriate.end())
2211
Use this function to control whether or not the \a dw dock
2212
window's caption should appear as a menu item on the dock window
2213
menu that lists the dock windows.
2215
If \a a is true then the \a dw will appear as a menu item on the
2216
dock window menu. The user is able to change the state (show or
2217
hide) a dock window that has a menu item by clicking the item;
2218
depending on the state of your application, this may or may not be
2219
appropriate. If \a a is false the \a dw will not appear on the
2222
\sa showDockMenu() isCustomizable() customize()
2225
void Q3MainWindow::setAppropriate(Q3DockWindow *dw, bool a)
2227
d_func()->appropriate.insert(dw, a);
2230
#ifndef QT_NO_TEXTSTREAM
2231
static void saveDockArea(QTextStream &ts, Q3DockArea *a)
2233
QList<Q3DockWindow *> l = a->dockWindowList();
2234
for (int i = 0; i < l.size(); ++i) {
2235
Q3DockWindow *dw = l.at(i);
2236
ts << QString(dw->windowTitle());
2244
\relates Q3MainWindow
2246
Writes the layout (sizes and positions) of the dock windows in the
2247
dock areas of the Q3MainWindow \a mainWindow, including \c
2248
Minimized and \c TornOff dock windows, to the text stream \a ts.
2250
This can be used, for example, in conjunction with QSettings to
2251
save the user's layout when the \a mainWindow receives a
2254
\sa QWidget::closeEvent()
2257
QTextStream &operator<<(QTextStream &ts, const Q3MainWindow &mainWindow)
2259
QList<Q3DockWindow *> l = mainWindow.dockWindows(Qt::DockMinimized);
2260
for (int i = 0; i < l.size(); ++i) {
2261
Q3DockWindow *dw = l.at(i);
2262
ts << dw->windowTitle();
2267
l = mainWindow.dockWindows(Qt::DockTornOff);
2268
for (int i = 0; i < l.size(); ++i) {
2269
Q3DockWindow *dw = l.at(i);
2270
ts << dw->windowTitle();
2274
for (int i = 0; i < l.size(); ++i) {
2275
Q3DockWindow *dw = l.at(i);
2276
ts << "[" << dw->windowTitle() << ","
2277
<< (int)dw->geometry().x() << ","
2278
<< (int)dw->geometry().y() << ","
2279
<< (int)dw->geometry().width() << ","
2280
<< (int)dw->geometry().height() << ","
2281
<< (int)dw->isVisible() << "]";
2285
saveDockArea(ts, mainWindow.topDock());
2286
saveDockArea(ts, mainWindow.bottomDock());
2287
saveDockArea(ts, mainWindow.rightDock());
2288
saveDockArea(ts, mainWindow.leftDock());
2292
static void loadDockArea(const QStringList &names, Q3DockArea *a, Qt::Dock dl, QList<Q3DockWindow *> &l, Q3MainWindow *mw, QTextStream &ts)
2294
for (QStringList::ConstIterator it = names.begin(); it != names.end(); ++it) {
2295
for (int i = 0; i < l.size(); ++i) {
2296
Q3DockWindow *dw = l.at(i);
2297
if (dw->windowTitle() == *it) {
2298
mw->addDockWindow(dw, dl);
2305
} else if (dl == Qt::DockTornOff) {
2306
QString s = ts.readLine();
2307
enum State { Pre, Name, X, Y, Width, Height, Visible, Post };
2309
QString name, x, y, w, h, visible;
2311
for (int i = 0; i < (int)s.length(); ++i) {
2313
if (state == Pre && c == '[') {
2318
(state == Name || state == X || state == Y || state == Width || state == Height)) {
2322
if (state == Visible && c == ']') {
2323
for (int i = 0; i < l.size(); ++i) {
2324
Q3DockWindow *dw = l.at(i);
2325
if (QString(dw->windowTitle()) == name) {
2326
if (!qobject_cast<Q3ToolBar*>(dw))
2327
dw->setGeometry(x.toInt(), y.toInt(), w.toInt(), h.toInt());
2329
dw->setGeometry(x.toInt(), y.toInt(), dw->width(), dw->height());
2330
if (!(bool)visible.toInt())
2338
name = x = y = w = h = visible = "";
2345
else if (state == X)
2347
else if (state == Y)
2349
else if (state == Width)
2351
else if (state == Height)
2353
else if (state == Visible)
2360
\relates Q3MainWindow
2362
Reads the layout (sizes and positions) of the dock windows in the
2363
dock areas of the Q3MainWindow \a mainWindow from the text stream,
2364
\a ts, including \c Minimized and \c TornOff dock windows.
2365
Restores the dock windows and dock areas to these sizes and
2366
positions. The layout information must be in the format produced
2369
This can be used, for example, in conjunction with QSettings to
2370
restore the user's layout.
2373
QTextStream &operator>>(QTextStream &ts, Q3MainWindow &mainWindow)
2375
QList<Q3DockWindow *> l = mainWindow.dockWindows();
2377
QString s = ts.readLine();
2378
QStringList names = s.split(',');
2379
loadDockArea(names, 0, Qt::DockMinimized, l, &mainWindow, ts);
2382
names = s.split(',');
2383
loadDockArea(names, 0, Qt::DockTornOff, l, &mainWindow, ts);
2386
Q3DockArea *areas[] = { mainWindow.topDock(), mainWindow.bottomDock(), mainWindow.rightDock(), mainWindow.leftDock() };
2387
for (int dl = (int)Qt::DockTop; dl != (int)Qt::DockMinimized; ++dl, ++i) {
2389
names = s.split(',');
2390
loadDockArea(names, areas[i], (Qt::Dock)dl, l, &mainWindow, ts);
2396
#include "q3mainwindow.moc"