summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp158
-rw-r--r--src/gui/kernel/qguiapplication.h8
-rw-r--r--src/gui/kernel/qguiapplication_p.h12
-rw-r--r--src/gui/kernel/qkeysequence.cpp22
-rw-r--r--src/gui/kernel/qopenglcontext.h2
-rw-r--r--src/gui/kernel/qplatformcursor_qpa.h8
-rw-r--r--src/gui/kernel/qplatformwindow_qpa.cpp4
-rw-r--r--src/gui/kernel/qsurface.cpp4
-rw-r--r--src/gui/kernel/qwindow.cpp15
-rw-r--r--src/gui/kernel/qwindow.h7
-rw-r--r--src/gui/kernel/qwindow_p.h9
11 files changed, 210 insertions, 39 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index cb6f26b2c5..9ffc35a608 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -114,7 +114,6 @@ enum ApplicationResourceFlags
static unsigned applicationResourceFlags = 0;
QString *QGuiApplicationPrivate::platform_name = 0;
-bool QGuiApplicationPrivate::app_do_modal = false;
QPalette *QGuiApplicationPrivate::app_pal = 0; // default application palette
@@ -381,6 +380,132 @@ QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags
}
/*!
+ Returns the most recently shown modal window. If no modal windows are
+ visible, this function returns zero.
+
+ A modal window is a window which has its
+ \l{QWindow::windowModality}{windowModality} property set to Qt::WindowModal
+ or Qt::ApplicationModal. A modal window must be closed before the user can
+ continue with other parts of the program.
+
+ Modal window are organized in a stack. This function returns the modal
+ window at the top of the stack.
+
+ \sa Qt::WindowModality, QWindow::setWindowModality()
+*/
+QWindow *QGuiApplication::modalWindow()
+{
+ if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
+ return 0;
+ return QGuiApplicationPrivate::self->modalWindowList.first();
+}
+
+void QGuiApplicationPrivate::showModalWindow(QWindow *window)
+{
+ self->modalWindowList.prepend(window);
+
+ QEvent e(QEvent::WindowBlocked);
+ QWindowList windows = QGuiApplication::topLevelWindows();
+ for (int i = 0; i < windows.count(); ++i) {
+ QWindow *window = windows.at(i);
+ if (!window->d_func()->blockedByModalWindow && window->windowType() != Qt::Tool && self->isWindowBlocked(window)) {
+ window->d_func()->blockedByModalWindow = true;
+ QGuiApplication::sendEvent(window, &e);
+ }
+ }
+}
+
+void QGuiApplicationPrivate::hideModalWindow(QWindow *window)
+{
+ self->modalWindowList.removeAll(window);
+
+ QEvent e(QEvent::WindowUnblocked);
+ QWindowList windows = QGuiApplication::topLevelWindows();
+ for (int i = 0; i < windows.count(); ++i) {
+ QWindow *window = windows.at(i);
+ if (window->d_func()->blockedByModalWindow && window->windowType() != Qt::Tool && !self->isWindowBlocked(window)) {
+ window->d_func()->blockedByModalWindow = false;
+ QGuiApplication::sendEvent(window, &e);
+ }
+ }
+}
+
+/*
+ Returns true if \a window is blocked by a modal window. If \a
+ blockingWindow is non-zero, *blockingWindow will be set to the blocking
+ window (or to zero if \a window is not blocked).
+*/
+bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blockingWindow) const
+{
+ QWindow *unused = 0;
+ if (!blockingWindow)
+ blockingWindow = &unused;
+
+ if (modalWindowList.isEmpty()) {
+ *blockingWindow = 0;
+ return false;
+ }
+
+ for (int i = 0; i < modalWindowList.count(); ++i) {
+ QWindow *modalWindow = modalWindowList.at(i);
+
+ {
+ // check if the modal window is our window or a (transient) parent of our window
+ QWindow *w = window;
+ while (w) {
+ if (w == modalWindow) {
+ *blockingWindow = 0;
+ return false;
+ }
+ QWindow *p = w->parent();
+ if (!p)
+ p = w->transientParent();
+ w = p;
+ }
+ }
+
+ Qt::WindowModality windowModality = modalWindow->windowModality();
+ switch (windowModality) {
+ case Qt::ApplicationModal:
+ {
+ if (modalWindow != window) {
+ *blockingWindow = modalWindow;
+ return true;
+ }
+ break;
+ }
+ case Qt::WindowModal:
+ {
+ QWindow *w = window;
+ do {
+ QWindow *m = modalWindow;
+ do {
+ if (m == w) {
+ *blockingWindow = m;
+ return true;
+ }
+ QWindow *p = m->parent();
+ if (!p)
+ p = m->transientParent();
+ m = p;
+ } while (m);
+ QWindow *p = w->parent();
+ if (!p)
+ p = w->transientParent();
+ w = p;
+ } while (w);
+ break;
+ }
+ default:
+ Q_ASSERT_X(false, "QGuiApplication", "internal error, a modal widget cannot be modeless");
+ break;
+ }
+ }
+ *blockingWindow = 0;
+ return false;
+}
+
+/*!
Returns the QWindow that receives events tied to focus,
such as key events.
*/
@@ -1049,6 +1174,11 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
}
if (window) {
+ if (window->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow mouse events through
+ return;
+ }
+
QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers);
ev.setTimestamp(e->timestamp);
#ifndef QT_NO_CURSOR
@@ -1111,6 +1241,11 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh
QWindow *window = e->window.data();
if (window) {
+ if (window->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow wheel events through
+ return;
+ }
+
QWheelEvent ev(e->localPos, e->globalPos, e->pixelDelta, e->angleDelta, e->qt4Delta, e->qt4Orientation, buttons, e->modifiers);
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &ev);
@@ -1128,6 +1263,10 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
window = QGuiApplication::activeWindow();
if (!window)
return;
+ if (window->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow key events through
+ return;
+ }
QKeyEvent ev(e->keyType, e->key, e->modifiers,
e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
@@ -1140,6 +1279,10 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En
{
if (!e->enter)
return;
+ if (e->enter.data()->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow enter events through
+ return;
+ }
QEvent event(QEvent::Enter);
QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
@@ -1149,6 +1292,10 @@ void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::Le
{
if (!e->leave)
return;
+ if (e->leave.data()->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow leave events through
+ return;
+ }
QEvent event(QEvent::Leave);
QCoreApplication::sendSpontaneousEvent(e->leave.data(), &event);
@@ -1263,6 +1410,10 @@ void QGuiApplicationPrivate::processCloseEvent(QWindowSystemInterfacePrivate::Cl
{
if (e->window.isNull())
return;
+ if (e->window.data()->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow close events through
+ return;
+ }
QCloseEvent event;
QGuiApplication::sendSpontaneousEvent(e->window.data(), &event);
@@ -1451,6 +1602,11 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
break;
}
+ if (w->d_func()->blockedByModalWindow) {
+ // a modal window is blocking this window, don't allow touch events through
+ continue;
+ }
+
QTouchEvent touchEvent(eventType,
e->device,
e->modifiers,
diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h
index 858083b10b..75a0f6cd4b 100644
--- a/src/gui/kernel/qguiapplication.h
+++ b/src/gui/kernel/qguiapplication.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QGUIAPPLICATION_QPA_H
-#define QGUIAPPLICATION_QPA_H
+#ifndef QGUIAPPLICATION_H
+#define QGUIAPPLICATION_H
#include <QtCore/qcoreapplication.h>
#include <QtGui/qwindowdefs.h>
@@ -88,6 +88,8 @@ public:
static QString platformName();
+ static QWindow *modalWindow();
+
#ifdef QT_DEPRECATED
static QT_DEPRECATED QWindow *activeWindow() { return focusWindow(); }
#endif
@@ -168,4 +170,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QGUIAPPLICATION_QPA_H
+#endif // QGUIAPPLICATION_H
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index 352917f2db..435994cdd3 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QGUIAPPLICATION_QPA_P_H
-#define QGUIAPPLICATION_QPA_P_H
+#ifndef QGUIAPPLICATION_P_H
+#define QGUIAPPLICATION_P_H
#include <QtGui/qguiapplication.h>
@@ -147,7 +147,11 @@ public:
static QGuiApplicationPrivate *instance() { return self; }
static QString *platform_name;
- static bool app_do_modal;
+
+ QWindowList modalWindowList;
+ static void showModalWindow(QWindow *window);
+ static void hideModalWindow(QWindow *window);
+ virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
static Qt::MouseButtons buttons;
static ulong mousePressTime;
@@ -226,4 +230,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QGUIAPPLICATION_QPA_P_H
+#endif // QGUIAPPLICATION_P_H
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index b0200335d7..c616681b64 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -55,14 +55,14 @@
#endif
#include "qvariant.h"
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
#include <QtCore/private/qcore_mac_p.h>
#include <Carbon/Carbon.h>
#endif
QT_BEGIN_NAMESPACE
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
static bool qt_sequence_no_mnemonics = true;
struct MacSpecialKey {
int key;
@@ -966,7 +966,7 @@ QKeySequence::QKeySequence(const QKeySequence& keysequence)
d->ref.ref();
}
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
static inline int maybeSwapShortcut(int shortcut)
{
if (qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta)) {
@@ -998,7 +998,7 @@ QList<QKeySequence> QKeySequence::keyBindings(StandardKey key)
QKeyBinding keyBinding = QKeySequencePrivate::keyBindings[i];
if (keyBinding.standardKey == key && (keyBinding.platform & platform)) {
uint shortcut =
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
maybeSwapShortcut(QKeySequencePrivate::keyBindings[i].shortcut);
#else
QKeySequencePrivate::keyBindings[i].shortcut;
@@ -1200,7 +1200,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
if (nativeText) {
gmodifs = globalModifs();
if (gmodifs->isEmpty()) {
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
const bool dontSwap = qApp->testAttribute(Qt::AA_MacDontSwapCtrlAndMeta);
if (dontSwap)
*gmodifs << QModifKeyName(Qt::META, QChar(kCommandUnicode));
@@ -1240,7 +1240,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
modifs += *gmodifs; // Test non-translated ones last
QString sl = accel;
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
for (int i = 0; i < modifs.size(); ++i) {
const QModifKeyName &mkf = modifs.at(i);
if (sl.contains(mkf.name)) {
@@ -1292,7 +1292,7 @@ int QKeySequencePrivate::decodeString(const QString &str, QKeySequence::Sequence
int fnum = 0;
if (accel.length() == 1) {
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
int qtKey = qtkeyForMacSymbol(accel[0]);
if (qtKey != -1) {
ret |= qtKey;
@@ -1371,7 +1371,7 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
if (key == -1 || key == Qt::Key_unknown)
return s;
-#if defined(Q_OS_MAC)
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
if (nativeText) {
// On Mac OS X the order (by default) is Meta, Alt, Shift, Control.
// If the AA_MacDontSwapCtrlAndMeta is enabled, then the order
@@ -1427,7 +1427,7 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
: QString::fromLatin1("F%1").arg(key - Qt::Key_F1 + 1);
} else if (key) {
int i=0;
-#if defined(Q_OS_MAC)
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
if (nativeText) {
QChar ch = qt_macSymbolForQtKey(key);
if (!ch.isNull())
@@ -1437,7 +1437,7 @@ QString QKeySequencePrivate::encodeString(int key, QKeySequence::SequenceFormat
} else
#endif
{
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
NonSymbol:
#endif
while (keyname[i].name) {
@@ -1463,7 +1463,7 @@ NonSymbol:
}
}
-#ifdef Q_OS_MAC
+#if defined(Q_OS_MAC) && !defined(QT_NO_CORESERVICES)
if (nativeText)
s += p;
else
diff --git a/src/gui/kernel/qopenglcontext.h b/src/gui/kernel/qopenglcontext.h
index efb65ae3e7..b9a47a54b8 100644
--- a/src/gui/kernel/qopenglcontext.h
+++ b/src/gui/kernel/qopenglcontext.h
@@ -51,9 +51,11 @@
#include <QtGui/QSurfaceFormat>
#ifdef __GLEW_H__
+#if defined(Q_CC_GNU)
#warning qopenglfunctions.h is not compatible with GLEW, GLEW defines will be undefined
#warning To use GLEW with Qt, do not include <qopengl.h> or <QOpenGLFunctions> after glew.h
#endif
+#endif
#include <QtGui/qopengl.h>
diff --git a/src/gui/kernel/qplatformcursor_qpa.h b/src/gui/kernel/qplatformcursor_qpa.h
index e29cf87d03..c1a572b27d 100644
--- a/src/gui/kernel/qplatformcursor_qpa.h
+++ b/src/gui/kernel/qplatformcursor_qpa.h
@@ -38,8 +38,8 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QGRAPHICSSYSTEMCURSOR_H
-#define QGRAPHICSSYSTEMCURSOR_H
+#ifndef QPLATFORMCURSOR_QPA_H
+#define QPLATFORMCURSOR_QPA_H
#include <QtCore/QList>
#include <QtGui/QImage>
@@ -60,7 +60,7 @@ public:
QPlatformCursorImage(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY)
{ set(data, mask, width, height, hotX, hotY); }
QImage * image() { return &cursorImage; }
- QPoint hotspot() { return hot; }
+ QPoint hotspot() const { return hot; }
void set(const uchar *data, const uchar *mask, int width, int height, int hotX, int hotY);
void set(const QImage &image, int hx, int hy);
void set(Qt::CursorShape);
@@ -97,4 +97,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QGRAPHICSSYSTEMCURSOR_H
+#endif // QPLATFORMCURSOR_QPA_H
diff --git a/src/gui/kernel/qplatformwindow_qpa.cpp b/src/gui/kernel/qplatformwindow_qpa.cpp
index 227059e24e..a9dfbba788 100644
--- a/src/gui/kernel/qplatformwindow_qpa.cpp
+++ b/src/gui/kernel/qplatformwindow_qpa.cpp
@@ -329,7 +329,7 @@ bool QPlatformWindow::setMouseGrabEnabled(bool grab)
However, it is not concerned with how Qt renders into the window it represents.
Visible QWindows will always have a QPlatformWindow. However, it is not necessary for
- all windows to have a QWindowSurface. This is the case for QOpenGLWidget. And could be the case for
+ all windows to have a QBackingStore. This is the case for QOpenGLWidget. And could be the case for
windows where some 3.party renders into it.
The platform specific window handle can be retrieved by the winId function.
@@ -340,7 +340,7 @@ bool QPlatformWindow::setMouseGrabEnabled(bool grab)
The only way to retrieve a QPlatformOpenGLContext in QPA is by calling the glContext() function
on QPlatformWindow.
- \sa QWindowSurface, QWindow
+ \sa QBackingStore, QWindow
*/
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qsurface.cpp b/src/gui/kernel/qsurface.cpp
index 534135cc2f..8b71fc3536 100644
--- a/src/gui/kernel/qsurface.cpp
+++ b/src/gui/kernel/qsurface.cpp
@@ -88,7 +88,9 @@ QSurface::QSurface(SurfaceClass type)
{
}
-
+QSurface::~QSurface()
+{
+}
QSurface::SurfaceClass QSurface::surfaceClass() const
{
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index d65998ce49..b042283071 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -193,10 +193,6 @@ QWindow::~QWindow()
destroy();
}
-QSurface::~QSurface()
-{
-}
-
/*!
Set the \a surfaceType of the window.
@@ -253,6 +249,13 @@ void QWindow::setVisible(bool visible)
QGuiApplication::sendEvent(this, &showEvent);
}
+ if (isModal()) {
+ if (visible)
+ QGuiApplicationPrivate::showModalWindow(this);
+ else
+ QGuiApplicationPrivate::hideModalWindow(this);
+ }
+
d->platformWindow->setVisible(visible);
if (!visible) {
@@ -1396,7 +1399,7 @@ void QWindow::resizeEvent(QResizeEvent *ev)
/*!
Override this to handle show events.
- The show event is called when the window has requested becoming visible.
+ The function is called when the window has requested becoming visible.
If the window is successfully shown by the windowing system, this will
be followed by a resize and an expose event.
@@ -1409,7 +1412,7 @@ void QWindow::showEvent(QShowEvent *ev)
/*!
Override this to handle hide evens.
- The hide event is called when the window has requested being hidden in the
+ The function is called when the window has requested being hidden in the
windowing system.
*/
void QWindow::hideEvent(QHideEvent *ev)
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index 2be50d63bc..118e3ec25f 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QWINDOW_QPA_H
-#define QWINDOW_QPA_H
+#ifndef QWINDOW_H
+#define QWINDOW_H
#include <QtCore/QObject>
#include <QtCore/QEvent>
@@ -249,7 +249,6 @@ public Q_SLOTS:
}
Q_SIGNALS:
- void backBufferReady();
void screenChanged(QScreen *screen);
void windowModalityChanged(Qt::WindowModality windowModality);
@@ -306,4 +305,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QWINDOW_QPA_H
+#endif // QWINDOW_H
diff --git a/src/gui/kernel/qwindow_p.h b/src/gui/kernel/qwindow_p.h
index 03b3b92a25..375bd1e729 100644
--- a/src/gui/kernel/qwindow_p.h
+++ b/src/gui/kernel/qwindow_p.h
@@ -39,8 +39,8 @@
**
****************************************************************************/
-#ifndef QWINDOW_QPA_P_H
-#define QWINDOW_QPA_P_H
+#ifndef QWINDOW_P_H
+#define QWINDOW_P_H
#include <QtGui/qwindow.h>
#include <QtGui/qplatformwindow_qpa.h>
@@ -81,6 +81,7 @@ public:
, windowOrientation(Qt::PrimaryOrientation)
, maximumSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX)
, modality(Qt::NonModal)
+ , blockedByModalWindow(false)
, transientParent(0)
, screen(0)
{
@@ -123,6 +124,8 @@ public:
QSize sizeIncrement;
Qt::WindowModality modality;
+ bool blockedByModalWindow;
+
QPointer<QWindow> transientParent;
QScreen *screen;
};
@@ -132,4 +135,4 @@ QT_END_NAMESPACE
QT_END_HEADER
-#endif // QWINDOW_QPA_P_H
+#endif // QWINDOW_P_H