summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qguiapplication.cpp40
-rw-r--r--src/gui/kernel/qguiapplication_p.h4
-rw-r--r--src/gui/kernel/qplatforminputcontext.cpp10
-rw-r--r--src/gui/kernel/qplatformintegration.cpp10
-rw-r--r--src/gui/kernel/qplatformintegration.h3
-rw-r--r--src/gui/kernel/qsimpledrag.cpp8
-rw-r--r--src/gui/kernel/qstylehints.cpp5
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp6
-rw-r--r--src/gui/kernel/qtouchdevice.cpp3
-rw-r--r--src/gui/kernel/qtouchdevice.h3
10 files changed, 58 insertions, 34 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 0d5a130dfd..b60ef4b8c1 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -105,6 +105,14 @@
QT_BEGIN_NAMESPACE
+// Helper macro for static functions to check on the existence of the application class.
+#define CHECK_QAPP_INSTANCE(...) \
+ if (Q_LIKELY(QCoreApplication::instance())) { \
+ } else { \
+ qWarning("Must construct a QGuiApplication first."); \
+ return __VA_ARGS__; \
+ }
+
Q_GUI_EXPORT bool qt_is_gui_used = true;
Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton;
@@ -163,6 +171,7 @@ QWindow *QGuiApplicationPrivate::focus_window = 0;
static QBasicMutex applicationFontMutex;
QFont *QGuiApplicationPrivate::app_font = 0;
+QStyleHints *QGuiApplicationPrivate::styleHints = Q_NULLPTR;
bool QGuiApplicationPrivate::obey_desktop_settings = true;
QInputDeviceManager *QGuiApplicationPrivate::m_inputDeviceManager = 0;
@@ -595,7 +604,6 @@ QGuiApplication::~QGuiApplication()
QGuiApplicationPrivate::QGuiApplicationPrivate(int &argc, char **argv, int flags)
: QCoreApplicationPrivate(argc, argv, flags),
- styleHints(0),
inputMethod(0),
lastTouchType(QEvent::TouchEnd),
ownGlobalShareContext(false)
@@ -648,6 +656,7 @@ QString QGuiApplication::applicationDisplayName()
*/
QWindow *QGuiApplication::modalWindow()
{
+ CHECK_QAPP_INSTANCE(Q_NULLPTR)
if (QGuiApplicationPrivate::self->modalWindowList.isEmpty())
return 0;
return QGuiApplicationPrivate::self->modalWindowList.first();
@@ -788,12 +797,6 @@ bool QGuiApplicationPrivate::isWindowBlocked(QWindow *window, QWindow **blocking
return false;
}
-bool QGuiApplicationPrivate::synthesizeMouseFromTouchEventsEnabled()
-{
- return QCoreApplication::testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)
- && QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool();
-}
-
/*!
Returns the QWindow that receives events tied to focus,
such as key events.
@@ -1355,7 +1358,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate()
cleanupThreadData();
- delete styleHints;
+ delete QGuiApplicationPrivate::styleHints;
+ QGuiApplicationPrivate::styleHints = Q_NULLPTR;
delete inputMethod;
qt_cleanupFontDatabase();
@@ -1435,6 +1439,7 @@ Qt::KeyboardModifiers QGuiApplication::keyboardModifiers()
*/
Qt::KeyboardModifiers QGuiApplication::queryKeyboardModifiers()
{
+ CHECK_QAPP_INSTANCE(Qt::KeyboardModifiers(0))
QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration();
return pi->queryKeyboardModifiers();
}
@@ -1723,7 +1728,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
}
mouse_buttons = buttons = e->buttons;
if (button & e->buttons) {
- ulong doubleClickInterval = static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval());
+ ulong doubleClickInterval = static_cast<ulong>(QGuiApplication::styleHints()->mouseDoubleClickInterval());
doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton;
type = frameStrut ? QEvent::NonClientAreaMouseButtonPress : QEvent::MouseButtonPress;
mousePressTime = e->timestamp;
@@ -2423,9 +2428,9 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
}
QGuiApplication::sendSpontaneousEvent(w, &touchEvent);
- if (!e->synthetic() && !touchEvent.isAccepted() && synthesizeMouseFromTouchEventsEnabled()) {
- // exclude touchpads as those generate their own mouse events
- if (touchEvent.device()->type() != QTouchDevice::TouchPad) {
+ if (!e->synthetic() && !touchEvent.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)) {
+ // exclude devices which generate their own mouse events
+ if (!(touchEvent.device()->capabilities() & QTouchDevice::MouseEmulation)) {
Qt::MouseButtons b = eventType == QEvent::TouchEnd ? Qt::NoButton : Qt::LeftButton;
if (b == Qt::NoButton)
self->synthesizedMousePoints.clear();
@@ -3172,6 +3177,7 @@ Qt::LayoutDirection QGuiApplication::layoutDirection()
#ifndef QT_NO_CURSOR
QCursor *QGuiApplication::overrideCursor()
{
+ CHECK_QAPP_INSTANCE(Q_NULLPTR)
return qGuiApp->d_func()->cursor_list.isEmpty() ? 0 : &qGuiApp->d_func()->cursor_list.first();
}
@@ -3185,6 +3191,7 @@ QCursor *QGuiApplication::overrideCursor()
*/
void QGuiApplication::changeOverrideCursor(const QCursor &cursor)
{
+ CHECK_QAPP_INSTANCE()
if (qGuiApp->d_func()->cursor_list.isEmpty())
return;
qGuiApp->d_func()->cursor_list.removeFirst();
@@ -3259,6 +3266,7 @@ static inline void applyWindowCursor(const QList<QWindow *> &l)
*/
void QGuiApplication::setOverrideCursor(const QCursor &cursor)
{
+ CHECK_QAPP_INSTANCE()
qGuiApp->d_func()->cursor_list.prepend(cursor);
applyCursor(QGuiApplicationPrivate::window_list, cursor);
}
@@ -3276,6 +3284,7 @@ void QGuiApplication::setOverrideCursor(const QCursor &cursor)
*/
void QGuiApplication::restoreOverrideCursor()
{
+ CHECK_QAPP_INSTANCE()
if (qGuiApp->d_func()->cursor_list.isEmpty())
return;
qGuiApp->d_func()->cursor_list.removeFirst();
@@ -3300,9 +3309,9 @@ void QGuiApplication::restoreOverrideCursor()
*/
QStyleHints *QGuiApplication::styleHints()
{
- if (!qGuiApp->d_func()->styleHints)
- qGuiApp->d_func()->styleHints = new QStyleHints();
- return qGuiApp->d_func()->styleHints;
+ if (!QGuiApplicationPrivate::styleHints)
+ QGuiApplicationPrivate::styleHints = new QStyleHints();
+ return QGuiApplicationPrivate::styleHints;
}
/*!
@@ -3343,6 +3352,7 @@ bool QGuiApplication::desktopSettingsAware()
*/
QInputMethod *QGuiApplication::inputMethod()
{
+ CHECK_QAPP_INSTANCE(Q_NULLPTR)
if (!qGuiApp->d_func()->inputMethod)
qGuiApp->d_func()->inputMethod = new QInputMethod();
return qGuiApp->d_func()->inputMethod;
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index d29ebf5f10..0c00e06499 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -190,8 +190,6 @@ public:
static void updateBlockedStatus(QWindow *window);
virtual bool isWindowBlocked(QWindow *window, QWindow **blockingWindow = 0) const;
- static bool synthesizeMouseFromTouchEventsEnabled();
-
static Qt::MouseButtons buttons;
static ulong mousePressTime;
static Qt::MouseButton mousePressButton;
@@ -220,7 +218,7 @@ public:
static QFont *app_font;
- QStyleHints *styleHints;
+ static QStyleHints *styleHints;
static bool obey_desktop_settings;
QInputMethod *inputMethod;
diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp
index e983ded20b..f9ff1d36d9 100644
--- a/src/gui/kernel/qplatforminputcontext.cpp
+++ b/src/gui/kernel/qplatforminputcontext.cpp
@@ -163,7 +163,7 @@ QRectF QPlatformInputContext::keyboardRect() const
*/
void QPlatformInputContext::emitKeyboardRectChanged()
{
- emit qApp->inputMethod()->keyboardRectangleChanged();
+ emit QGuiApplication::inputMethod()->keyboardRectangleChanged();
}
/*!
@@ -182,7 +182,7 @@ bool QPlatformInputContext::isAnimating() const
*/
void QPlatformInputContext::emitAnimatingChanged()
{
- emit qApp->inputMethod()->animatingChanged();
+ emit QGuiApplication::inputMethod()->animatingChanged();
}
/*!
@@ -214,7 +214,7 @@ bool QPlatformInputContext::isInputPanelVisible() const
*/
void QPlatformInputContext::emitInputPanelVisibleChanged()
{
- emit qApp->inputMethod()->visibleChanged();
+ emit QGuiApplication::inputMethod()->visibleChanged();
}
QLocale QPlatformInputContext::locale() const
@@ -224,7 +224,7 @@ QLocale QPlatformInputContext::locale() const
void QPlatformInputContext::emitLocaleChanged()
{
- emit qApp->inputMethod()->localeChanged();
+ emit QGuiApplication::inputMethod()->localeChanged();
}
Qt::LayoutDirection QPlatformInputContext::inputDirection() const
@@ -234,7 +234,7 @@ Qt::LayoutDirection QPlatformInputContext::inputDirection() const
void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDirection)
{
- emit qApp->inputMethod()->inputDirectionChanged(newDirection);
+ emit QGuiApplication::inputMethod()->inputDirectionChanged(newDirection);
}
/*!
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp
index d2db6af52b..6147a2a53a 100644
--- a/src/gui/kernel/qplatformintegration.cpp
+++ b/src/gui/kernel/qplatformintegration.cpp
@@ -386,8 +386,6 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
case UseRtlExtensions:
return QVariant(false);
- case SynthesizeMouseFromTouchEvents:
- return true;
case SetFocusOnTouchRelease:
return QVariant(false);
case MousePressAndHoldInterval:
@@ -443,11 +441,15 @@ QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
The screen should be deleted by calling QPlatformIntegration::destroyScreen().
*/
-void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
+void QPlatformIntegration::screenAdded(QPlatformScreen *ps, bool isPrimary)
{
QScreen *screen = new QScreen(ps);
ps->d_func()->screen = screen;
- QGuiApplicationPrivate::screen_list << screen;
+ if (isPrimary) {
+ QGuiApplicationPrivate::screen_list.prepend(screen);
+ } else {
+ QGuiApplicationPrivate::screen_list.append(screen);
+ }
emit qGuiApp->screenAdded(screen);
}
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index a0756a4992..24e19f68e6 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -141,7 +141,6 @@ public:
FontSmoothingGamma,
StartDragVelocity,
UseRtlExtensions,
- SynthesizeMouseFromTouchEvents,
PasswordMaskCharacter,
SetFocusOnTouchRelease,
ShowIsMaximized,
@@ -171,7 +170,7 @@ public:
#endif
protected:
- void screenAdded(QPlatformScreen *screen);
+ void screenAdded(QPlatformScreen *screen, bool isPrimary = false);
void destroyScreen(QPlatformScreen *screen);
};
diff --git a/src/gui/kernel/qsimpledrag.cpp b/src/gui/kernel/qsimpledrag.cpp
index b3dc6e915d..090e88c118 100644
--- a/src/gui/kernel/qsimpledrag.cpp
+++ b/src/gui/kernel/qsimpledrag.cpp
@@ -255,18 +255,18 @@ void QBasicDrag::updateCursor(Qt::DropAction action)
}
}
- QCursor *cursor = qApp->overrideCursor();
+ QCursor *cursor = QGuiApplication::overrideCursor();
QPixmap pixmap = m_drag->dragCursor(action);
if (!cursor) {
- qApp->changeOverrideCursor((pixmap.isNull()) ? QCursor(cursorShape) : QCursor(pixmap));
+ QGuiApplication::changeOverrideCursor((pixmap.isNull()) ? QCursor(cursorShape) : QCursor(pixmap));
} else {
if (!pixmap.isNull()) {
if ((cursor->pixmap().cacheKey() != pixmap.cacheKey())) {
- qApp->changeOverrideCursor(QCursor(pixmap));
+ QGuiApplication::changeOverrideCursor(QCursor(pixmap));
}
} else {
if (cursorShape != cursor->shape()) {
- qApp->changeOverrideCursor(QCursor(cursorShape));
+ QGuiApplication::changeOverrideCursor(QCursor(cursorShape));
}
}
}
diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp
index a0f98383ff..b7af2e759f 100644
--- a/src/gui/kernel/qstylehints.cpp
+++ b/src/gui/kernel/qstylehints.cpp
@@ -35,6 +35,7 @@
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformtheme.h>
#include <private/qguiapplication_p.h>
+#include <qdebug.h>
QT_BEGIN_NAMESPACE
@@ -46,6 +47,10 @@ static inline QVariant hint(QPlatformIntegration::StyleHint h)
static inline QVariant themeableHint(QPlatformTheme::ThemeHint th,
QPlatformIntegration::StyleHint ih)
{
+ if (!QCoreApplication::instance()) {
+ qWarning() << "Must construct a QGuiApplication before accessing a platform theme hint.";
+ return QVariant();
+ }
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const QVariant themeHint = theme->themeHint(th);
if (themeHint.isValid())
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 2fdfa3baf1..6ec13e92a1 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -747,6 +747,12 @@ Q_GLOBAL_STATIC(QSurfaceFormat, qt_default_surface_format)
and surfaces, even the ones created internally by Qt, will use the same
format.
+ \note When setting Qt::AA_ShareOpenGLContexts, it is strongly recommended to
+ place the call to this function before the construction of the
+ QGuiApplication or QApplication. Otherwise \a format will not be applied to
+ the global share context and therefore issues may arise with context sharing
+ afterwards.
+
\since 5.4
\sa defaultFormat()
*/
diff --git a/src/gui/kernel/qtouchdevice.cpp b/src/gui/kernel/qtouchdevice.cpp
index cbba171276..8737825de0 100644
--- a/src/gui/kernel/qtouchdevice.cpp
+++ b/src/gui/kernel/qtouchdevice.cpp
@@ -96,6 +96,9 @@ QT_BEGIN_NAMESPACE
\value NormalizedPosition Indicates that the normalized position is available, meaning that normalizedPos()
returns a valid value.
+
+ \value MouseEmulation Indicates that the device synthesizes mouse events.
+ This enum value has been introduced in Qt 5.5.
*/
/*!
diff --git a/src/gui/kernel/qtouchdevice.h b/src/gui/kernel/qtouchdevice.h
index 4a2d05a7b9..f2157ce2d6 100644
--- a/src/gui/kernel/qtouchdevice.h
+++ b/src/gui/kernel/qtouchdevice.h
@@ -55,7 +55,8 @@ public:
Pressure = 0x0004,
Velocity = 0x0008,
RawPositions = 0x0010,
- NormalizedPosition = 0x0020
+ NormalizedPosition = 0x0020,
+ MouseEmulation = 0x0040
};
Q_DECLARE_FLAGS(Capabilities, CapabilityFlag)