1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include "qplatformwindow_qpa.h"
45 #include "qsurfaceformat.h"
46 #include "qplatformglcontext_qpa.h"
47 #include "qguiglcontext_qpa.h"
50 #include "qwindow_p.h"
51 #include "qguiapplication_p.h"
53 #include <private/qevent_p.h>
55 #include <QtCore/QDebug>
59 QWindow::QWindow(QScreen *targetScreen)
60 : QObject(*new QWindowPrivate(), 0)
61 , QSurface(QSurface::Window)
64 d->screen = targetScreen;
66 d->screen = QGuiApplication::primaryScreen();
67 QGuiApplicationPrivate::window_list.prepend(this);
70 QWindow::QWindow(QWindow *parent)
71 : QObject(*new QWindowPrivate(), parent)
72 , QSurface(QSurface::Window)
75 d->parentWindow = parent;
77 d->screen = parent->screen();
79 d->screen = QGuiApplication::primaryScreen();
80 QGuiApplicationPrivate::window_list.prepend(this);
85 if (QGuiApplicationPrivate::active_window == this)
86 QGuiApplicationPrivate::active_window = 0;
87 QGuiApplicationPrivate::window_list.removeAll(this);
91 void QWindow::setSurfaceType(SurfaceType surfaceType)
94 d->surfaceType = surfaceType;
97 QWindow::SurfaceType QWindow::surfaceType() const
100 return d->surfaceType;
103 void QWindow::setVisible(bool visible)
107 if (d->visible == visible)
109 d->visible = visible;
111 if (!d->platformWindow)
113 d->platformWindow->setVisible(visible);
116 bool QWindow::visible() const
123 void QWindow::create()
126 if (!d->platformWindow) {
127 d->platformWindow = QGuiApplicationPrivate::platformIntegration()->createPlatformWindow(this);
128 QObjectList childObjects = children();
129 for (int i = 0; i < childObjects.size(); i ++) {
130 QObject *object = childObjects.at(i);
131 if(object->isWindowType()) {
132 QWindow *window = static_cast<QWindow *>(object);
133 if (window->d_func()->platformWindow)
134 window->d_func()->platformWindow->setParent(d->platformWindow);
140 WId QWindow::winId() const
143 if(!d->platformWindow)
144 const_cast<QWindow *>(this)->create();
145 return d->platformWindow->winId();
148 QWindow *QWindow::parent() const
151 return d->parentWindow;
155 Sets the parent Window. This will lead to the windowing system managing the clip of the window, so it will be clipped to the parent window.
156 Setting parent to be 0(NULL) means map it as a top level window. If the parent window has grabbed its window system resources, then the current window will also grab its window system resources.
159 void QWindow::setParent(QWindow *parent)
163 QObject::setParent(parent);
165 if (d->platformWindow) {
166 if (parent && parent->d_func()->platformWindow) {
167 d->platformWindow->setParent(parent->d_func()->platformWindow);
169 d->platformWindow->setParent(0);
173 d->parentWindow = parent;
177 Returns whether the window is top level, i.e. has no parent window.
179 bool QWindow::isTopLevel() const
182 return d->parentWindow == 0;
185 bool QWindow::isModal() const
188 return d->modality != Qt::NonModal;
191 Qt::WindowModality QWindow::windowModality() const
197 void QWindow::setWindowModality(Qt::WindowModality windowModality)
200 d->modality = windowModality;
203 void QWindow::setFormat(const QSurfaceFormat &format)
206 d->requestedFormat = format;
209 QSurfaceFormat QWindow::format() const
212 if (d->platformWindow)
213 return d->platformWindow->format();
214 return d->requestedFormat;
217 void QWindow::setWindowFlags(Qt::WindowFlags flags)
220 if (d->platformWindow)
221 d->windowFlags = d->platformWindow->setWindowFlags(flags);
223 d->windowFlags = flags;
226 Qt::WindowFlags QWindow::windowFlags() const
229 return d->windowFlags;
232 Qt::WindowType QWindow::windowType() const
235 return static_cast<Qt::WindowType>(int(d->windowFlags & Qt::WindowType_Mask));
238 void QWindow::setWindowTitle(const QString &title)
241 d->windowTitle = title;
242 if (d->platformWindow) {
243 d->platformWindow->setWindowTitle(title);
247 QString QWindow::windowTitle() const
250 return d->windowTitle;
253 void QWindow::raise()
256 if (d->platformWindow) {
257 d->platformWindow->raise();
261 void QWindow::lower()
264 if (d->platformWindow) {
265 d->platformWindow->lower();
269 void QWindow::setOpacity(qreal level)
272 if (d->platformWindow) {
273 d->platformWindow->setOpacity(level);
277 void QWindow::requestActivateWindow()
280 QGuiApplicationPrivate::active_window = this;
281 if (d->platformWindow) {
282 d->platformWindow->requestActivateWindow();
286 Qt::WindowState QWindow::windowState() const
289 return d->windowState;
292 void QWindow::setWindowState(Qt::WindowState state)
294 if (state == Qt::WindowActive) {
295 requestActivateWindow();
300 if (d->platformWindow)
301 d->windowState = d->platformWindow->setWindowState(state);
303 d->windowState = state;
307 Sets the transient parent, which is a hint to the window manager that this window is a dialog or pop-up on behalf of the given window.
309 void QWindow::setTransientParent(QWindow *parent)
312 d->transientParent = parent;
315 QWindow *QWindow::transientParent() const
318 return d->transientParent.data();
321 QSize QWindow::minimumSize() const
324 return d->minimumSize;
327 QSize QWindow::maximumSize() const
330 return d->maximumSize;
333 QSize QWindow::baseSize() const
339 QSize QWindow::sizeIncrement() const
342 return d->sizeIncrement;
345 void QWindow::setMinimumSize(const QSize &size)
348 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
349 if (d->minimumSize == adjustedSize)
351 d->minimumSize = adjustedSize;
352 if (d->platformWindow && isTopLevel())
353 d->platformWindow->propagateSizeHints();
356 void QWindow::setMaximumSize(const QSize &size)
359 QSize adjustedSize = QSize(qBound(0, size.width(), QWINDOWSIZE_MAX), qBound(0, size.height(), QWINDOWSIZE_MAX));
360 if (d->maximumSize == adjustedSize)
362 d->maximumSize = adjustedSize;
363 if (d->platformWindow && isTopLevel())
364 d->platformWindow->propagateSizeHints();
367 void QWindow::setBaseSize(const QSize &size)
370 if (d->baseSize == size)
373 if (d->platformWindow && isTopLevel())
374 d->platformWindow->propagateSizeHints();
377 void QWindow::setSizeIncrement(const QSize &size)
380 if (d->sizeIncrement == size)
382 d->sizeIncrement = size;
383 if (d->platformWindow && isTopLevel())
384 d->platformWindow->propagateSizeHints();
387 void QWindow::setGeometry(const QRect &rect)
391 if (d->platformWindow) {
392 d->platformWindow->setGeometry(rect);
396 QRect QWindow::geometry() const
402 QMargins QWindow::frameMargins() const
405 if (d->platformWindow)
406 return d->platformWindow->frameMargins();
410 void QWindow::setWindowIcon(const QImage &icon) const
413 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
416 void QWindow::destroy()
419 delete d->platformWindow;
420 d->platformWindow = 0;
423 QPlatformWindow *QWindow::handle() const
426 return d->platformWindow;
429 QPlatformSurface *QWindow::surfaceHandle() const
432 return d->platformWindow;
435 bool QWindow::setKeyboardGrabEnabled(bool grab)
438 if (d->platformWindow)
439 return d->platformWindow->setKeyboardGrabEnabled(grab);
443 bool QWindow::setMouseGrabEnabled(bool grab)
446 if (d->platformWindow)
447 return d->platformWindow->setMouseGrabEnabled(grab);
451 QScreen *QWindow::screen() const
457 void QWindow::setScreen(QScreen *newScreen)
460 bool wasCreated = d->platformWindow != 0;
463 d->screen = newScreen ? newScreen : QGuiApplication::primaryScreen();
468 void QWindow::showMinimized()
470 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
473 void QWindow::showMaximized()
475 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
478 void QWindow::showFullScreen()
480 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
483 void QWindow::showNormal()
485 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
488 bool QWindow::close()
490 //should we have close?
491 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
495 void QWindow::exposeEvent(QExposeEvent *)
499 void QWindow::resizeEvent(QResizeEvent *)
503 void QWindow::showEvent(QShowEvent *)
505 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
508 void QWindow::hideEvent(QHideEvent *)
510 qDebug() << "unimplemented:" << __FILE__ << __LINE__;
513 bool QWindow::event(QEvent *event)
515 switch (event->type()) {
516 case QEvent::MouseMove:
517 mouseMoveEvent(static_cast<QMouseEvent*>(event));
520 case QEvent::MouseButtonPress:
521 mousePressEvent(static_cast<QMouseEvent*>(event));
524 case QEvent::MouseButtonRelease:
525 mouseReleaseEvent(static_cast<QMouseEvent*>(event));
528 case QEvent::MouseButtonDblClick:
529 mouseDoubleClickEvent(static_cast<QMouseEvent*>(event));
533 resizeEvent(static_cast<QResizeEvent*>(event));
536 case QEvent::KeyPress:
537 keyPressEvent(static_cast<QKeyEvent *>(event));
540 case QEvent::KeyRelease:
541 keyReleaseEvent(static_cast<QKeyEvent *>(event));
544 #ifndef QT_NO_WHEELEVENT
546 wheelEvent(static_cast<QWheelEvent*>(event));
555 exposeEvent(static_cast<QExposeEvent *>(event));
559 return QObject::event(event);
564 void QWindow::keyPressEvent(QKeyEvent *)
568 void QWindow::keyReleaseEvent(QKeyEvent *)
572 void QWindow::inputMethodEvent(QInputMethodEvent *)
576 void QWindow::mousePressEvent(QMouseEvent *)
580 void QWindow::mouseReleaseEvent(QMouseEvent *)
584 void QWindow::mouseDoubleClickEvent(QMouseEvent *)
588 void QWindow::mouseMoveEvent(QMouseEvent *)
592 #ifndef QT_NO_WHEELEVENT
593 void QWindow::wheelEvent(QWheelEvent *)
596 #endif //QT_NO_WHEELEVENT
598 Q_GUI_EXPORT QWindowPrivate *qt_window_private(QWindow *window)
600 return window->d_func();