summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorJesper Thomschutz <jesper.thomschutz@nokia.com>2010-09-15 07:45:55 (GMT)
committerA-Team <ateam@pad.test.qt.nokia.com>2010-09-15 07:46:55 (GMT)
commitf78119906b0ffc7fd3dd36d6d827d456478a7fd5 (patch)
treee161fe397dedd702f86d186ef32eabcf7cae00d8 /src/gui/widgets
parent66420856664c7a412b3c9efe4be6ff7a6061e5f2 (diff)
parent05ab8ad1577fc038aa2b3bd96cedda54e6a64979 (diff)
downloadQt-f78119906b0ffc7fd3dd36d6d827d456478a7fd5.zip
Qt-f78119906b0ffc7fd3dd36d6d827d456478a7fd5.tar.gz
Qt-f78119906b0ffc7fd3dd36d6d827d456478a7fd5.tar.bz2
git Merge branch '4.7-upstream' into 4.7-doc
Conflicts: src/gui/kernel/qgesturemanager.cpp
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qdockarealayout.cpp10
-rw-r--r--src/gui/widgets/qdockwidget.cpp37
-rw-r--r--src/gui/widgets/qmainwindow.cpp71
-rw-r--r--src/gui/widgets/qmainwindowlayout.cpp11
-rw-r--r--src/gui/widgets/qmainwindowlayout_p.h2
-rw-r--r--src/gui/widgets/qtoolbar.cpp20
-rw-r--r--src/gui/widgets/qtoolbararealayout.cpp5
-rw-r--r--src/gui/widgets/qtoolbarlayout.cpp7
8 files changed, 117 insertions, 46 deletions
diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp
index 171000b..b540e76 100644
--- a/src/gui/widgets/qdockarealayout.cpp
+++ b/src/gui/widgets/qdockarealayout.cpp
@@ -60,6 +60,9 @@
QT_BEGIN_NAMESPACE
+// qmainwindow.cpp
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
+
enum { StateFlagVisible = 1, StateFlagFloating = 2 };
/******************************************************************************
@@ -1480,7 +1483,7 @@ QList<int> QDockAreaLayoutInfo::indexOf(QWidget *widget) const
QMainWindowLayout *QDockAreaLayoutInfo::mainWindowLayout() const
{
- QMainWindowLayout *result = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
+ QMainWindowLayout *result = qt_mainwindow_layout(mainWindow);
Q_ASSERT(result != 0);
return result;
}
@@ -3070,8 +3073,7 @@ void QDockAreaLayout::splitDockWidget(QDockWidget *after,
void QDockAreaLayout::apply(bool animate)
{
- QWidgetAnimator &widgetAnimator
- = qobject_cast<QMainWindowLayout*>(mainWindow->layout())->widgetAnimator;
+ QWidgetAnimator &widgetAnimator = qt_mainwindow_layout(mainWindow)->widgetAnimator;
for (int i = 0; i < QInternal::DockCount; ++i)
docks[i].apply(animate);
@@ -3176,7 +3178,7 @@ void QDockAreaLayout::updateSeparatorWidgets() const
if (j < separatorWidgets.size()) {
sepWidget = separatorWidgets.at(j);
} else {
- sepWidget = qobject_cast<QMainWindowLayout*>(mainWindow->layout())->getSeparatorWidget();
+ sepWidget = qt_mainwindow_layout(mainWindow)->getSeparatorWidget();
separatorWidgets.append(sepWidget);
}
j++;
diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp
index 11f0a94..df9b171 100644
--- a/src/gui/widgets/qdockwidget.cpp
+++ b/src/gui/widgets/qdockwidget.cpp
@@ -68,6 +68,9 @@ QT_BEGIN_NAMESPACE
extern QString qt_setWindowTitle_helperHelper(const QString&, const QWidget*); // qwidget.cpp
+// qmainwindow.cpp
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
+
static inline bool hasFeature(const QDockWidgetPrivate *priv, QDockWidget::DockWidgetFeature feature)
{ return (priv->features & feature) == feature; }
@@ -690,7 +693,7 @@ void QDockWidgetPrivate::initDrag(const QPoint &pos, bool nca)
QMainWindow *win = qobject_cast<QMainWindow*>(parent);
Q_ASSERT(win != 0);
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
Q_ASSERT(layout != 0);
if (layout->pluggingWidget != 0) // the main window is animating a docking operation
return;
@@ -711,8 +714,7 @@ void QDockWidgetPrivate::startDrag()
if (state == 0 || state->dragging)
return;
- QMainWindowLayout *layout
- = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
Q_ASSERT(layout != 0);
state->widgetItem = layout->unplug(q);
@@ -739,8 +741,7 @@ void QDockWidgetPrivate::endDrag(bool abort)
q->releaseMouse();
if (state->dragging) {
- QMainWindowLayout *mwLayout =
- qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *mwLayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
Q_ASSERT(mwLayout != 0);
if (abort || !mwLayout->plug(state->widgetItem)) {
@@ -780,8 +781,7 @@ bool QDockWidgetPrivate::isAnimating() const
if (mainWin == 0)
return false;
- QMainWindowLayout *mainWinLayout
- = qobject_cast<QMainWindowLayout*>(mainWin->layout());
+ QMainWindowLayout *mainWinLayout = qt_mainwindow_layout(mainWin);
if (mainWinLayout == 0)
return false;
@@ -847,9 +847,8 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event)
return ret;
QDockWidgetLayout *dwlayout
- = qobject_cast<QDockWidgetLayout*>(layout);
- QMainWindowLayout *mwlayout
- = qobject_cast<QMainWindowLayout*>(q->parentWidget()->layout());
+ = qobject_cast<QDockWidgetLayout *>(layout);
+ QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
if (!dwlayout->nativeWindowDeco()) {
if (!state->dragging
&& mwlayout->pluggingWidget == 0
@@ -943,8 +942,7 @@ void QDockWidgetPrivate::nonClientAreaMouseEvent(QMouseEvent *event)
}
#ifdef Q_OS_MAC
else { // workaround for lack of mouse-grab on Mac
- QMainWindowLayout *layout
- = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
Q_ASSERT(layout != 0);
q->move(event->globalPos() - state->pressPos);
@@ -980,8 +978,7 @@ void QDockWidgetPrivate::moveEvent(QMoveEvent *event)
if (state->ctrlDrag)
return;
- QMainWindowLayout *layout
- = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
Q_ASSERT(layout != 0);
QPoint globalMousePos = event->pos() + state->pressPos;
@@ -1009,7 +1006,7 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect
Q_Q(QDockWidget);
if (!floating && parent) {
- QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
if (mwlayout && mwlayout->dockWidgetArea(q) == Qt::NoDockWidgetArea)
return; // this dockwidget can't be redocked
}
@@ -1055,7 +1052,7 @@ void QDockWidgetPrivate::setWindowState(bool floating, bool unplug, const QRect
if (floating != wasFloating) {
emit q->topLevelChanged(floating);
if (!floating && parent) {
- QMainWindowLayout *mwlayout = qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *mwlayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
if (mwlayout)
emit q->dockLocationChanged(mwlayout->dockWidgetArea(q));
}
@@ -1326,10 +1323,10 @@ void QDockWidget::changeEvent(QEvent *event)
#ifndef QT_NO_TABBAR
{
QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget());
- if (QMainWindowLayout *winLayout =
- (win ? qobject_cast<QMainWindowLayout*>(win->layout()) : 0))
+ if (QMainWindowLayout *winLayout = qt_mainwindow_layout(win)) {
if (QDockAreaLayoutInfo *info = winLayout->layoutState.dockAreaLayout.info(this))
info->updateTabBar();
+ }
}
#endif // QT_NO_TABBAR
break;
@@ -1382,9 +1379,7 @@ bool QDockWidget::event(QEvent *event)
Q_D(QDockWidget);
QMainWindow *win = qobject_cast<QMainWindow*>(parentWidget());
- QMainWindowLayout *layout = 0;
- if (win != 0)
- layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
switch (event->type()) {
#ifndef QT_NO_ACTION
diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp
index 44483ea..1183be6 100644
--- a/src/gui/widgets/qmainwindow.cpp
+++ b/src/gui/widgets/qmainwindow.cpp
@@ -39,6 +39,8 @@
**
****************************************************************************/
+//#define QT_EXPERIMENTAL_CLIENT_DECORATIONS
+
#include "qmainwindow.h"
#include "qmainwindowlayout_p.h"
@@ -99,12 +101,70 @@ public:
uint hasOldCursor : 1;
uint cursorAdjusted : 1;
#endif
+
+ static inline QMainWindowLayout *mainWindowLayout(const QMainWindow *mainWindow)
+ {
+ return mainWindow ? mainWindow->d_func()->layout : static_cast<QMainWindowLayout *>(0);
+ }
};
+QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow)
+{
+ return QMainWindowPrivate::mainWindowLayout(mainWindow);
+}
+
+#ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS
+Q_GUI_EXPORT void qt_setMainWindowTitleWidget(QMainWindow *mainWindow, Qt::DockWidgetArea area, QWidget *widget)
+{
+ QGridLayout *topLayout = qobject_cast<QGridLayout *>(mainWindow->layout());
+ Q_ASSERT(topLayout);
+
+ int row = 0;
+ int column = 0;
+
+ switch (area) {
+ case Qt::LeftDockWidgetArea:
+ row = 1;
+ column = 0;
+ break;
+ case Qt::TopDockWidgetArea:
+ row = 0;
+ column = 1;
+ break;
+ case Qt::BottomDockWidgetArea:
+ row = 2;
+ column = 1;
+ break;
+ case Qt::RightDockWidgetArea:
+ row = 1;
+ column = 2;
+ break;
+ default:
+ Q_ASSERT_X(false, "qt_setMainWindowTitleWidget", "Unknown area");
+ return;
+ }
+
+ if (QLayoutItem *oldItem = topLayout->itemAtPosition(row, column))
+ delete oldItem->widget();
+ topLayout->addWidget(widget, row, column);
+}
+#endif
+
void QMainWindowPrivate::init()
{
Q_Q(QMainWindow);
- layout = new QMainWindowLayout(q);
+
+#ifdef QT_EXPERIMENTAL_CLIENT_DECORATIONS
+ QGridLayout *topLayout = new QGridLayout(q);
+ topLayout->setContentsMargins(0, 0, 0, 0);
+
+ layout = new QMainWindowLayout(q, topLayout);
+
+ topLayout->addItem(layout, 1, 1);
+#else
+ layout = new QMainWindowLayout(q, 0);
+#endif
+
const int metric = q->style()->pixelMetric(QStyle::PM_ToolBarIconSize, 0, q);
iconSize = QSize(metric, metric);
q->setAttribute(Qt::WA_Hover);
@@ -461,10 +521,11 @@ QMenuBar *QMainWindow::menuBar() const
*/
void QMainWindow::setMenuBar(QMenuBar *menuBar)
{
- Q_D(QMainWindow);
- if (d->layout->menuBar() && d->layout->menuBar() != menuBar) {
+ QLayout *topLayout = layout();
+
+ if (topLayout->menuBar() && topLayout->menuBar() != menuBar) {
// Reparent corner widgets before we delete the old menu bar.
- QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(d->layout->menuBar());
+ QMenuBar *oldMenuBar = qobject_cast<QMenuBar *>(topLayout->menuBar());
if (menuBar) {
// TopLeftCorner widget.
QWidget *cornerWidget = oldMenuBar->cornerWidget(Qt::TopLeftCorner);
@@ -478,7 +539,7 @@ void QMainWindow::setMenuBar(QMenuBar *menuBar)
oldMenuBar->hide();
oldMenuBar->deleteLater();
}
- d->layout->setMenuBar(menuBar);
+ topLayout->setMenuBar(menuBar);
}
/*!
diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp
index 62ee398..4dd5208 100644
--- a/src/gui/widgets/qmainwindowlayout.cpp
+++ b/src/gui/widgets/qmainwindowlayout.cpp
@@ -160,7 +160,7 @@ static void dumpLayout(QTextStream &qout, const QDockAreaLayout &layout, QString
void qt_dumpLayout(QTextStream &qout, QMainWindow *window)
{
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(window->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(window);
dumpLayout(qout, layout->layoutState.dockAreaLayout, QString());
}
@@ -235,7 +235,7 @@ void QMainWindowLayoutState::apply(bool animated)
dockAreaLayout.apply(animated);
#else
if (centralWidgetItem != 0) {
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow);
Q_ASSERT(layout != 0);
layout->widgetAnimator.animate(centralWidgetItem->widget(), centralWidgetRect, animated);
}
@@ -1674,8 +1674,8 @@ void QMainWindowLayout::restore(bool keepSavedState)
updateGapIndicator();
}
-QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow)
- : QLayout(mainwindow)
+QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLayout)
+ : QLayout(parentLayout ? static_cast<QWidget *>(0) : mainwindow)
, layoutState(mainwindow)
, savedState(mainwindow)
, dockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowTabbedDocks)
@@ -1698,6 +1698,9 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow)
, blockVisiblityCheck(false)
#endif
{
+ if (parentLayout)
+ setParent(parentLayout);
+
#ifndef QT_NO_DOCKWIDGET
#ifndef QT_NO_TABBAR
sep = mainwindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainwindow);
diff --git a/src/gui/widgets/qmainwindowlayout_p.h b/src/gui/widgets/qmainwindowlayout_p.h
index 955693d..e1b981c 100644
--- a/src/gui/widgets/qmainwindowlayout_p.h
+++ b/src/gui/widgets/qmainwindowlayout_p.h
@@ -159,7 +159,7 @@ class Q_AUTOTEST_EXPORT QMainWindowLayout : public QLayout
public:
QMainWindowLayoutState layoutState, savedState;
- explicit QMainWindowLayout(QMainWindow *mainwindow);
+ QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLayout);
~QMainWindowLayout();
QMainWindow::DockOptions dockOptions;
diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp
index 7ed27ea..316bb44 100644
--- a/src/gui/widgets/qtoolbar.cpp
+++ b/src/gui/widgets/qtoolbar.cpp
@@ -82,6 +82,9 @@ static void qt_mac_updateToolBarButtonHint(QWidget *parentWidget)
}
#endif
+// qmainwindow.cpp
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
+
/******************************************************************************
** QToolBarPrivate
*/
@@ -197,7 +200,7 @@ void QToolBarPrivate::initDrag(const QPoint &pos)
QMainWindow *win = qobject_cast<QMainWindow*>(parent);
Q_ASSERT(win != 0);
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
Q_ASSERT(layout != 0);
if (layout->pluggingWidget != 0) // the main window is animating a docking operation
return;
@@ -223,7 +226,7 @@ void QToolBarPrivate::startDrag(bool moving)
QMainWindow *win = qobject_cast<QMainWindow*>(parent);
Q_ASSERT(win != 0);
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
Q_ASSERT(layout != 0);
if (!moving) {
@@ -247,8 +250,7 @@ void QToolBarPrivate::endDrag()
q->releaseMouse();
if (state->dragging) {
- QMainWindowLayout *layout =
- qobject_cast<QMainWindowLayout *>(q->parentWidget()->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
Q_ASSERT(layout != 0);
if (!layout->plug(state->widgetItem)) {
@@ -340,7 +342,7 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event)
if (win == 0)
return true;
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
Q_ASSERT(layout != 0);
if (layout->pluggingWidget == 0
@@ -588,7 +590,7 @@ QToolBar::~QToolBar()
QMainWindow *mainwindow = qobject_cast<QMainWindow *>(parentWidget());
if (mainwindow) {
#ifdef Q_WS_MAC
- QMainWindowLayout *mainwin_layout = qobject_cast<QMainWindowLayout *>(mainwindow->layout());
+ QMainWindowLayout *mainwin_layout = qt_mainwindow_layout(mainwindow);
if (mainwin_layout && mainwin_layout->layoutState.toolBarAreaLayout.isEmpty()
&& mainwindow->testAttribute(Qt::WA_WState_Created))
macWindowToolbarShow(mainwindow, false);
@@ -1135,7 +1137,7 @@ bool QToolBar::event(QEvent *event)
if (toolbarInUnifiedToolBar(this)) {
// I can static_cast because I did the qobject_cast in the if above, therefore
// we must have a QMainWindowLayout here.
- QMainWindowLayout *mwLayout = static_cast<QMainWindowLayout *>(parentWidget()->layout());
+ QMainWindowLayout *mwLayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(parentWidget()));
mwLayout->fixSizeInUnifiedToolbar(this);
mwLayout->syncUnifiedToolbarVisibility();
}
@@ -1289,6 +1291,8 @@ QWidget *QToolBar::widgetForAction(QAction *action) const
return d->layout->itemAt(index)->widget();
}
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
+
/*!
\internal
*/
@@ -1315,7 +1319,7 @@ void QToolBar::initStyleOption(QStyleOptionToolBar *option) const
if (!mainWindow)
return;
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout *>(mainWindow->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow);
Q_ASSERT_X(layout != 0, "QToolBar::initStyleOption()",
"QMainWindow->layout() != QMainWindowLayout");
diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp
index 8327af5..b312751 100644
--- a/src/gui/widgets/qtoolbararealayout.cpp
+++ b/src/gui/widgets/qtoolbararealayout.cpp
@@ -59,6 +59,9 @@
QT_BEGIN_NAMESPACE
+// qmainwindow.cpp
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *mainWindow);
+
QSize QToolBarAreaLayoutItem::minimumSize() const
{
if (skip())
@@ -872,7 +875,7 @@ void QToolBarAreaLayout::insertItem(QToolBar *before, QLayoutItem *item)
void QToolBarAreaLayout::apply(bool animate)
{
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(mainWindow->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(mainWindow);
Q_ASSERT(layout != 0);
Qt::LayoutDirection dir = mainWindow->layoutDirection();
diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp
index f87510f..59b027e 100644
--- a/src/gui/widgets/qtoolbarlayout.cpp
+++ b/src/gui/widgets/qtoolbarlayout.cpp
@@ -57,6 +57,9 @@
QT_BEGIN_NAMESPACE
+// qmainwindow.cpp
+extern QMainWindowLayout *qt_mainwindow_layout(const QMainWindow *window);
+
/******************************************************************************
** QToolBarItem
*/
@@ -404,7 +407,7 @@ void QToolBarLayout::setGeometry(const QRect &rect)
if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) {
Qt::ToolBarArea area = win->toolBarArea(tb);
if (win->unifiedTitleAndToolBarOnMac() && area == Qt::TopToolBarArea) {
- static_cast<QMainWindowLayout *>(win->layout())->fixSizeInUnifiedToolbar(tb);
+ qt_mainwindow_layout(win)->fixSizeInUnifiedToolbar(tb);
}
}
# endif
@@ -659,7 +662,7 @@ void QToolBarLayout::setExpanded(bool exp)
#else
animating = !tb->isWindow() && win->isAnimated();
#endif
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(win);
if (expanded) {
tb->raise();
} else {