summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-09-13 18:28:31 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-09-13 18:28:31 (GMT)
commitd012e5e808526e84507134656ca97c3884dae47b (patch)
tree9da70fead4e2b4110dee84fc1e55249ac7a81755 /src/gui
parent0b3183427395be7dae29ba91254b00b0845b72af (diff)
parent019032c93b7397c7239ec99ec44b4923df31533b (diff)
downloadQt-d012e5e808526e84507134656ca97c3884dae47b.zip
Qt-d012e5e808526e84507134656ca97c3884dae47b.tar.gz
Qt-d012e5e808526e84507134656ca97c3884dae47b.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (25 commits) run depend_command even if the binary has no absolute path fix scaleFactor/totalScaleFactor in QPinchGestureRecognizer Added velocity property to the QPanGesture. Changed the speed property on QSwipeGesture to velocity fix typos in comment unbreak test Don't add generic subdirs project twice. Remove debug, quiet warnings. Fix memory leaks and valgrind errors. QStroker: Fix erroneous SvgMiterJoin behavior for parallel lines Revert "Properly implement qobject_cast for const pointers." Bearer management: Fix compilation with namespace. fetch next token after class definition opening delay next token fetching when opening namespace don't let operator overloads confuse us don't try to show source when no locations are given Implement a private API for setting title widgets Fix the bug for QSettings on Windows, to store qint32/quint32, qint64/quint64 in Windows registry. fix CRLF Added private API to install an x11EventFilter ...
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qapplication_x11.cpp28
-rw-r--r--src/gui/kernel/qgesture.cpp2
-rw-r--r--src/gui/kernel/qgesture.h3
-rw-r--r--src/gui/kernel/qgesture_p.h18
-rw-r--r--src/gui/kernel/qgesturemanager.cpp2
-rw-r--r--src/gui/kernel/qstandardgestures.cpp16
-rw-r--r--src/gui/kernel/qwidget_mac.mm9
-rw-r--r--src/gui/painting/qstroker.cpp2
-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
16 files changed, 179 insertions, 64 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index 7495f6d..e7b7ed8 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -400,11 +400,39 @@ QTabletDeviceDataList *qt_tablet_devices()
extern bool qt_tabletChokeMouse;
#endif
+typedef bool(*QX11FilterFunction)(XEvent *event);
+
+Q_GLOBAL_STATIC(QList<QX11FilterFunction>, x11Filters)
+
+Q_GUI_EXPORT void qt_installX11EventFilter(QX11FilterFunction func)
+{
+ Q_ASSERT(func);
+
+ if (QList<QX11FilterFunction> *list = x11Filters())
+ list->append(func);
+}
+
+Q_GUI_EXPORT void qt_removeX11EventFilter(QX11FilterFunction func)
+{
+ Q_ASSERT(func);
+
+ if (QList<QX11FilterFunction> *list = x11Filters())
+ list->removeOne(func);
+}
+
+
static bool qt_x11EventFilter(XEvent* ev)
{
long unused;
if (qApp->filterEvent(ev, &unused))
return true;
+ if (const QList<QX11FilterFunction> *list = x11Filters()) {
+ for (QList<QX11FilterFunction>::const_iterator it = list->constBegin(); it != list->constEnd(); ++it) {
+ if ((*it)(ev))
+ return true;
+ }
+ }
+
return qApp->x11EventFilter(ev);
}
diff --git a/src/gui/kernel/qgesture.cpp b/src/gui/kernel/qgesture.cpp
index 13274c4..5725a22 100644
--- a/src/gui/kernel/qgesture.cpp
+++ b/src/gui/kernel/qgesture.cpp
@@ -775,4 +775,6 @@ int QTapAndHoldGesturePrivate::Timeout = 700; // in ms
QT_END_NAMESPACE
+#include <moc_qgesture.cpp>
+
#endif // QT_NO_GESTURES
diff --git a/src/gui/kernel/qgesture.h b/src/gui/kernel/qgesture.h
index dcb0264..2e279b0 100644
--- a/src/gui/kernel/qgesture.h
+++ b/src/gui/kernel/qgesture.h
@@ -112,6 +112,8 @@ class Q_GUI_EXPORT QPanGesture : public QGesture
Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
Q_PROPERTY(QPointF delta READ delta STORED false)
Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration)
+ Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal horizontalVelocity READ horizontalVelocity WRITE setHorizontalVelocity)
+ Q_PRIVATE_PROPERTY(QPanGesture::d_func(), qreal verticalVelocity READ verticalVelocity WRITE setVerticalVelocity)
public:
QPanGesture(QObject *parent = 0);
@@ -210,6 +212,7 @@ class Q_GUI_EXPORT QSwipeGesture : public QGesture
Q_PROPERTY(SwipeDirection horizontalDirection READ horizontalDirection STORED false)
Q_PROPERTY(SwipeDirection verticalDirection READ verticalDirection STORED false)
Q_PROPERTY(qreal swipeAngle READ swipeAngle WRITE setSwipeAngle)
+ Q_PRIVATE_PROPERTY(QSwipeGesture::d_func(), qreal velocity READ velocity WRITE setVelocity)
public:
enum SwipeDirection { NoDirection, Left, Right, Up, Down };
diff --git a/src/gui/kernel/qgesture_p.h b/src/gui/kernel/qgesture_p.h
index 29b923e..e8f8fe3 100644
--- a/src/gui/kernel/qgesture_p.h
+++ b/src/gui/kernel/qgesture_p.h
@@ -88,14 +88,21 @@ class QPanGesturePrivate : public QGesturePrivate
public:
QPanGesturePrivate()
- : acceleration(0)
+ : acceleration(0), xVelocity(0), yVelocity(0)
{
}
+ qreal horizontalVelocity() const { return xVelocity; }
+ void setHorizontalVelocity(qreal value) { xVelocity = value; }
+ qreal verticalVelocity() const { return yVelocity; }
+ void setVerticalVelocity(qreal value) { yVelocity = value; }
+
QPointF lastOffset;
QPointF offset;
QPoint startPosition;
qreal acceleration;
+ qreal xVelocity;
+ qreal yVelocity;
};
class QPinchGesturePrivate : public QGesturePrivate
@@ -105,7 +112,7 @@ class QPinchGesturePrivate : public QGesturePrivate
public:
QPinchGesturePrivate()
: totalChangeFlags(0), changeFlags(0),
- totalScaleFactor(0), lastScaleFactor(0), scaleFactor(0),
+ totalScaleFactor(1), lastScaleFactor(1), scaleFactor(1),
totalRotationAngle(0), lastRotationAngle(0), rotationAngle(0),
isNewSequence(true)
{
@@ -139,17 +146,20 @@ public:
: horizontalDirection(QSwipeGesture::NoDirection),
verticalDirection(QSwipeGesture::NoDirection),
swipeAngle(0),
- started(false), speed(0)
+ started(false), velocityValue(0),
{
}
+ qreal velocity() const { return velocityValue; }
+ void setVelocity(qreal value) { velocityValue = value; }
+
QSwipeGesture::SwipeDirection horizontalDirection;
QSwipeGesture::SwipeDirection verticalDirection;
qreal swipeAngle;
QPoint lastPositions[3];
bool started;
- qreal speed;
+ qreal velocityValue;
QElapsedTimer time;
};
diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp
index 5c80340..6dd8127 100644
--- a/src/gui/kernel/qgesturemanager.cpp
+++ b/src/gui/kernel/qgesturemanager.cpp
@@ -184,7 +184,7 @@ void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType typ
// get or create a QGesture object that will represent the state for a given object, used by the recognizer
QGesture *QGestureManager::getState(QObject *object, QGestureRecognizer *recognizer, Qt::GestureType type)
{
- // if the widget is being deleted we should be carefull and not to
+ // if the widget is being deleted we should be careful not to
// create a new state, as it will create QWeakPointer which doesnt work
// from the destructor.
if (object->isWidgetType()) {
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 127e150..893ba2b 100644
--- a/src/gui/kernel/qstandardgestures.cpp
+++ b/src/gui/kernel/qstandardgestures.cpp
@@ -199,6 +199,7 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->startPosition[1] = p2.screenPos();
}
QLineF line(p1.screenPos(), p2.screenPos());
+ QLineF lastLine(p1.lastScreenPos(), p2.lastScreenPos());
QLineF tmp(line);
tmp.setLength(line.length() / 2.);
QPointF centerPoint = tmp.p2();
@@ -207,16 +208,15 @@ QGestureRecognizer::Result QPinchGestureRecognizer::recognize(QGesture *state,
d->centerPoint = centerPoint;
d->changeFlags |= QPinchGesture::CenterPointChanged;
- const qreal scaleFactor =
- QLineF(p1.screenPos(), p2.screenPos()).length()
- / QLineF(d->startPosition[0], d->startPosition[1]).length();
+ const qreal scaleFactor = line.length() / lastLine.length();
+
if (d->isNewSequence) {
d->lastScaleFactor = scaleFactor;
} else {
d->lastScaleFactor = d->scaleFactor;
}
d->scaleFactor = scaleFactor;
- d->totalScaleFactor += d->scaleFactor - d->lastScaleFactor;
+ d->totalScaleFactor = d->totalScaleFactor * scaleFactor;
d->changeFlags |= QPinchGesture::ScaleFactorChanged;
qreal angle = QLineF(p1.screenPos(), p2.screenPos()).angle();
@@ -266,7 +266,7 @@ void QPinchGestureRecognizer::reset(QGesture *state)
d->totalChangeFlags = d->changeFlags = 0;
d->startCenterPoint = d->lastCenterPoint = d->centerPoint = QPointF();
- d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 0;
+ d->totalScaleFactor = d->lastScaleFactor = d->scaleFactor = 1;
d->totalRotationAngle = d->lastRotationAngle = d->rotationAngle = 0;
d->isNewSequence = true;
@@ -304,7 +304,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
switch (event->type()) {
case QEvent::TouchBegin: {
- d->speed = 1;
+ d->velocityValue = 1;
d->time.start();
d->started = true;
result = QGestureRecognizer::MayBeGesture;
@@ -345,7 +345,7 @@ QGestureRecognizer::Result QSwipeGestureRecognizer::recognize(QGesture *state,
int elapsedTime = d->time.restart();
if (!elapsedTime)
elapsedTime = 1;
- d->speed = 0.9 * d->speed + distance / elapsedTime;
+ d->velocityValue = 0.9 * d->velocityValue + distance / elapsedTime;
d->swipeAngle = QLineF(p1.startScreenPos(), p1.screenPos()).angle();
static const int MoveThreshold = 50;
@@ -407,7 +407,7 @@ void QSwipeGestureRecognizer::reset(QGesture *state)
d->lastPositions[0] = d->lastPositions[1] = d->lastPositions[2] = QPoint();
d->started = false;
- d->speed = 0;
+ d->velocityValue = 0;
d->time.invalidate();
QGestureRecognizer::reset(state);
diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm
index 1979c84..159c45d 100644
--- a/src/gui/kernel/qwidget_mac.mm
+++ b/src/gui/kernel/qwidget_mac.mm
@@ -2375,7 +2375,8 @@ void QWidgetPrivate::recreateMacWindow()
HIViewRemoveFromSuperview(myView);
determineWindowClass();
createWindow_sys();
- if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
+
+ if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
mwl->updateHIToolBarStatus();
}
@@ -2912,7 +2913,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
// We do this down below for wasCreated, so avoid doing this twice
// (only for performance, it gets called a lot anyway).
if (!wasCreated) {
- if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
+ if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
mwl->updateHIToolBarStatus();
}
}
@@ -2937,7 +2938,7 @@ void QWidgetPrivate::setParent_sys(QWidget *parent, Qt::WindowFlags f)
// If we were a unified window, We just transfered our toolbars out of the unified toolbar.
// So redo the status one more time. It apparently is not an issue with Cocoa.
if (q->isWindow()) {
- if (QMainWindowLayout *mwl = qobject_cast<QMainWindowLayout *>(q->layout())) {
+ if (QMainWindowLayout *mwl = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q))) {
mwl->updateHIToolBarStatus();
}
}
@@ -5138,7 +5139,7 @@ void QWidgetPrivate::macUpdateMetalAttribute()
return;
recreateMacWindow();
#else
- QMainWindowLayout *layout = qobject_cast<QMainWindowLayout *>(q->layout());
+ QMainWindowLayout *layout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q));
if (q->testAttribute(Qt::WA_MacBrushedMetal)) {
if (layout)
layout->updateHIToolBarStatus();
diff --git a/src/gui/painting/qstroker.cpp b/src/gui/painting/qstroker.cpp
index eabbd8a..9cff339 100644
--- a/src/gui/painting/qstroker.cpp
+++ b/src/gui/painting/qstroker.cpp
@@ -609,7 +609,7 @@ void QStroker::joinPoints(qfixed focal_x, qfixed focal_y, const QLineF &nextLine
}
QLineF miterLine(QPointF(qt_fixed_to_real(focal_x),
qt_fixed_to_real(focal_y)), isect);
- if (miterLine.length() > qt_fixed_to_real(m_strokeWidth * m_miterLimit) / 2) {
+ if (type == QLineF::NoIntersection || miterLine.length() > qt_fixed_to_real(m_strokeWidth * m_miterLimit) / 2) {
emitLineTo(qt_real_to_fixed(nextLine.x1()),
qt_real_to_fixed(nextLine.y1()));
} else {
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 {