summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMorten Johan Sorvig <morten.sorvig@nokia.com>2012-05-16 11:57:56 +0200
committerMorten Johan Sørvig <morten.sorvig@nokia.com>2012-05-21 10:42:34 +0200
commitbc8aec8085fff0be66f1b8f83097ab69ad78264b (patch)
treed9870b10d68985f3d39d8cae256fb966150641db
parentd1bca8c60c737ecbc2e9d8b70fde43a40f7d4191 (diff)
downloadqtquickcontrols-bc8aec8085fff0be66f1b8f83097ab69ad78264b.tar.gz
Don't use QMainWindow on Qt 5.
Simplify and make QQuickView the top-level window. Menus still work on OS X, other platforms are unknown. Change-Id: Ic5bd505ed91675dd34aef7ee2926cd603fc3e9ad Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
-rw-r--r--src/qtoplevelwindow.cpp45
-rw-r--r--src/qtoplevelwindow.h15
-rw-r--r--src/qwindowwidget.cpp45
-rw-r--r--src/qwindowwidget.h54
-rw-r--r--src/src.pro4
5 files changed, 26 insertions, 137 deletions
diff --git a/src/qtoplevelwindow.cpp b/src/qtoplevelwindow.cpp
index 042cc28c..93d014f3 100644
--- a/src/qtoplevelwindow.cpp
+++ b/src/qtoplevelwindow.cpp
@@ -1,12 +1,15 @@
#include "qtoplevelwindow.h"
#include <QDesktopWidget>
+#if QT_VERSION >= 0x050000
+#include <QtWidgets/QMenuBar>
+#endif
QTopLevelWindow::QTopLevelWindow()
#if QT_VERSION < 0x050000
: QMainWindow(), _view(new QDeclarativeView), _positionIsDefined(false) {
#else
- : QMainWindow(), _windowWidget(new QWindowWidget), _view(new QQuickView), _positionIsDefined(false) {
+ : QQuickView(), _menuBar(new QMenuBar), _positionIsDefined(false) {
#endif
setVisible(false);
@@ -16,12 +19,17 @@ QTopLevelWindow::QTopLevelWindow()
#if QT_VERSION < 0x050000
_view->setBackgroundBrush(palette().window());
setCentralWidget(_view);
-#else
- _windowWidget->setEmbeddedWindow(_view);
- setCentralWidget(_windowWidget);
#endif
}
+#if QT_VERSION >= 0x050000
+QMenuBar *QTopLevelWindow::menuBar()
+{
+ return _menuBar;
+}
+#endif
+
+
QTopLevelWindow::~QTopLevelWindow()
{
foreach (QTopLevelWindow* child, findChildren<QTopLevelWindow*>())
@@ -76,32 +84,19 @@ void QTopLevelWindow::move(int x, int y)
void QTopLevelWindow::move(const QPoint &point)
{
_positionIsDefined = true;
+#if QT_VERSION < 0x050000
QMainWindow::move(point);
+#else
+ QQuickView::setPos(point);
+#endif
}
void QTopLevelWindow::setWindowFlags(Qt::WindowFlags type)
{
+#if QT_VERSION < 0x050000
QWidget::setWindowFlags(type | Qt::Window);
+#else
+ QQuickView::setWindowFlags(type | Qt::Window);
+#endif
}
-bool QTopLevelWindow::event(QEvent *event) {
- switch (event->type()) {
- case QEvent::WindowStateChange:
- emit windowStateChanged();
- break;
- case QEvent::Show:
- emit visibilityChanged();
- break;
- case QEvent::Hide:
- hideChildWindows();
- emit visibilityChanged();
- break;
- case QEvent::Resize: {
- const QResizeEvent *resize = static_cast<const QResizeEvent *>(event);
- emit sizeChanged(resize->size());
- break;
- }
- default: break;
- }
- return QMainWindow::event(event);
-}
diff --git a/src/qtoplevelwindow.h b/src/qtoplevelwindow.h
index 10f0845a..a3cbe6a0 100644
--- a/src/qtoplevelwindow.h
+++ b/src/qtoplevelwindow.h
@@ -34,16 +34,15 @@
#include <QDeclarativeView>
#else
#include <QtQuick/QQuickView>
-#include <QtGui/QWindow>
-#include "qwindowwidget.h"
#endif
#include <QWindowStateChangeEvent>
#include <QDebug>
// Qt 4, QtQuick1 : QTopLevelWindow is a QMainWindow with a QDeclarativeView centerWidget
-// Qt 5, QtQuick2 : QTopLevelWindow is a QMainWindow with a QWindowWidget centerWidget that embeds a QQuickView.
-class QTopLevelWindow : public QMainWindow {
+// Qt 5, QtQuick2 : QTopLevelWindow is a QQuickView.
+class QMenuBar;
+class QTopLevelWindow : public QQuickView {
Q_OBJECT
public:
QTopLevelWindow();
@@ -53,7 +52,8 @@ public:
QGraphicsScene *scene() { return _view->scene(); }
QDeclarativeView *view() { return _view; }
#else
- QQuickView * view() { return _view; }
+ QQuickView * view() { return this; }
+ QMenuBar *menuBar();
#endif
void registerChildWindow(QTopLevelWindow* child);
void hideChildWindows();
@@ -64,8 +64,6 @@ public:
void move(int x, int y);
void move(const QPoint &);
-protected:
- virtual bool event(QEvent *event);
Q_SIGNALS:
void visibilityChanged();
@@ -76,8 +74,7 @@ private:
#if QT_VERSION < 0x050000
QDeclarativeView *_view;
#else
- QWindowWidget *_windowWidget;
- QQuickView *_view;
+ QMenuBar *_menuBar;
#endif
bool _positionIsDefined;
diff --git a/src/qwindowwidget.cpp b/src/qwindowwidget.cpp
deleted file mode 100644
index a5054080..00000000
--- a/src/qwindowwidget.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "qwindowwidget.h"
-#include <QtCore/qdebug.h>
-#include <QtGui/qevent.h>
-
-QWindowWidget::QWindowWidget()
- :m_EmbeddedWindow(0)
-{
-
-}
-
-void QWindowWidget::setEmbeddedWindow(QWindow *window)
-{
- m_EmbeddedWindow = window;
-
- this->window()->winId(); // force parent (top-level) creation
- m_EmbeddedWindow->setParent(this->window()->windowHandle());
-}
-
-QWindow *QWindowWidget::embeddedWindow() const
-{
- return m_EmbeddedWindow;
-}
-
-bool QWindowWidget::event(QEvent *event) {
- switch (event->type()) {
- case QEvent::Show:
- m_EmbeddedWindow->show();
- break;
- case QEvent::Hide:
- m_EmbeddedWindow->hide();
- break;
- case QEvent::Resize: {
- QResizeEvent *resize = static_cast<QResizeEvent *>(event);
- // qDebug() << "\n" << this << "resize current geom" << m_EmbeddedWindow->geometry() ;
- // qDebug() << "newsize" << resize->size();
-
- // Propagate resize, force pos to (0,0).
- m_EmbeddedWindow->setGeometry(QRect(QPoint(), resize->size()));
- break;
- }
- default: break;
- }
- return QWidget::event(event);
-}
-
diff --git a/src/qwindowwidget.h b/src/qwindowwidget.h
deleted file mode 100644
index b5b27d9b..00000000
--- a/src/qwindowwidget.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the Qt Components project on Qt Labs.
-**
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions contained
-** in the Technology Preview License Agreement accompanying this package.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at qt-info@nokia.com.
-**
-****************************************************************************/
-
-#ifndef QWINDOWWIDGET_H
-#define QWINDOWWIDGET_H
-
-#include <QtCore/qglobal.h>
-#include <QtWidgets/QWidget>
-#include <QtGui/QWindow>
-
-//
-// QWindowWidget supports embedding a QWindow in a QWidget hierarchy,
-// making the QWindow geometry track the QWidget geometry.
-//
-// This class has one major limitation: the embedded QWindow has a
-// native (non-toplevel) window surface which is overlayed the QWidget
-// hierarchy. This means that "complex" configurations like placing
-// placing the QWindowWidget in a scroll area will most likely not work.
-//
-class QWindowWidget : public QWidget
-{
-public:
- QWindowWidget();
- void setEmbeddedWindow(QWindow *embeddedWindow);
- QWindow *embeddedWindow() const;
- bool event(QEvent *event);
-private:
- QWindow *m_EmbeddedWindow;
-};
-
-#endif // QWIDGETWINDOW_H
diff --git a/src/src.pro b/src/src.pro
index e2d6b226..abaedd5f 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -41,10 +41,6 @@ SOURCES += qtmenu.cpp \
qtooltiparea.cpp \
qtsplitterbase.cpp
-### Qt 5 only
-HEADERS += qwindowwidget.h
-SOURCES += qwindowwidget.cpp
-
TARGETPATH = QtDesktop/plugin
target.path = $$[QT_INSTALL_IMPORTS]/$$TARGETPATH