From 3ae0164687186b68b530fe8d30f5a3434163c1ee Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 5 Mar 2012 10:52:34 +0200 Subject: Update QTouchEvent docs with regards to raw positions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2c955e42605c442793095d5ca27c34d7d87e08fb Reviewed-by: Samuel Rødal --- src/gui/kernel/qevent.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 60e754b289..52cb799b39 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3863,11 +3863,16 @@ QTouchEvent::TouchPoint::InfoFlags QTouchEvent::TouchPoint::flags() const } /*! - Returns the raw, unfiltered positions for the touch point. The positions are in screen coordinates. + Returns the raw, unfiltered positions for the touch point. The positions are in native screen coordinates. To get local coordinates you can use mapFromGlobal() of the QWindow returned by QTouchEvent::window(). \note Returns an empty list if the touch device's capabilities do not include QTouchDevice::RawPositions. + \note Native screen coordinates refer to the native orientation of the screen which, in case of + mobile devices, is typically portrait. This means that on systems capable of screen orientation + changes the positions in this list will not reflect the current orientation (unlike pos(), + screenPos(), etc.) and will always be reported in the native orientation. + \sa QTouchDevice::capabilities(), device(), window() */ QList QTouchEvent::TouchPoint::rawScreenPositions() const -- cgit v1.2.3 From 930a90d97835223587c2c8df1213c64295f3af97 Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Fri, 24 Feb 2012 09:17:00 +0100 Subject: Cocoa: Implement widget palettes. Add roles to QPLatformTheme::Palette, map QWidget subclasses to those. Port Qt4 widget palette creation code to use the QPLatformTheme::Palette roles. Palette entries are disabled in this commit, this will be fixed later. Change-Id: I07babe3d7c76d306efc4ea4813c7161fdf36227f Reviewed-by: Friedemann Kleint --- src/gui/kernel/qplatformtheme_qpa.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qplatformtheme_qpa.h b/src/gui/kernel/qplatformtheme_qpa.h index 3610a3c1c8..be18e4fe38 100644 --- a/src/gui/kernel/qplatformtheme_qpa.h +++ b/src/gui/kernel/qplatformtheme_qpa.h @@ -86,6 +86,19 @@ public: enum Palette { SystemPalette, ToolTipPalette, + ToolButtonPalette, + ButtonPalette, + HeaderPalette, + ComboBoxPalette, + ItemViewPalette, + MessageBoxLabelPelette, + TabBarPalette, + LabelPalette, + GroupBoxPalette, + MenuPalette, + MenuBarPalette, + TextEditPalette, + TextLineEditPalette, NPalettes }; -- cgit v1.2.3 From b371f3f943703840d0dfbe30505018bcca06e260 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 6 Mar 2012 16:09:09 +0200 Subject: Fix double click handling. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now double clicking in Qt 5 resulted in the following sequence of mouse events: pressed, released, double clicked, released. This is wrong, the press belonging to the second button down is missing. In Qt 4 that pressed event is present. The problem is not apparent in desktop environments because the double click is functioning properly even when the second pressed is missing. However when using a platform plug-in like wayland, where the clients receive only press, move and release events, double click was broken because the second click was effectively ignored (due to receiving nothing but a button release). Change-Id: Ief6af12c666b23e544da4a68cb835cd577265469 Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 42 +++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index be82005a54..095336a948 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -933,6 +933,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo QPointF globalPoint = e->globalPos; Qt::MouseButton button = Qt::NoButton; + bool doubleClick = false; if (QGuiApplicationPrivate::lastCursorPosition != globalPoint) { type = QEvent::MouseMove; @@ -940,8 +941,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo if (qAbs(globalPoint.x() - mousePressX) > mouse_double_click_distance|| qAbs(globalPoint.y() - mousePressY) > mouse_double_click_distance) mousePressButton = Qt::NoButton; - } - else { // Check to see if a new button has been pressed/released. + } else { // Check to see if a new button has been pressed/released. for (int check = Qt::LeftButton; check <= int(Qt::MaxMouseButton); check = check << 1) { @@ -956,25 +956,19 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo } buttons = e->buttons; if (button & e->buttons) { - if ((e->timestamp - mousePressTime) < static_cast(qApp->styleHints()->mouseDoubleClickInterval()) && - button == mousePressButton) { - type = QEvent::MouseButtonDblClick; - mousePressButton = Qt::NoButton; - } - else { - type = QEvent::MouseButtonPress; - mousePressTime = e->timestamp; - mousePressButton = button; - const QPoint point = QGuiApplicationPrivate::lastCursorPosition.toPoint(); - mousePressX = point.x(); - mousePressY = point.y(); - } - } - else + ulong doubleClickInterval = static_cast(qApp->styleHints()->mouseDoubleClickInterval()); + doubleClick = e->timestamp - mousePressTime < doubleClickInterval && button == mousePressButton; + type = QEvent::MouseButtonPress; + mousePressTime = e->timestamp; + mousePressButton = button; + const QPoint point = QGuiApplicationPrivate::lastCursorPosition.toPoint(); + mousePressX = point.x(); + mousePressY = point.y(); + } else { type = QEvent::MouseButtonRelease; + } } - if (window) { QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers); ev.setTimestamp(e->timestamp); @@ -1017,12 +1011,16 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo fake.synthetic = true; processTouchEvent(&fake); } + if (doubleClick) { + mousePressButton = Qt::NoButton; + QMouseEvent dblClickEvent(QEvent::MouseButtonDblClick, localPoint, localPoint, globalPoint, + button, buttons, e->modifiers); + dblClickEvent.setTimestamp(e->timestamp); + QGuiApplication::sendSpontaneousEvent(window, &dblClickEvent); + } } } - -//### there's a lot of duplicated logic here -- refactoring required! - void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::WheelEvent *e) { if (!e->window) @@ -1041,8 +1039,6 @@ void QGuiApplicationPrivate::processWheelEvent(QWindowSystemInterfacePrivate::Wh } } - - // Remember, Qt convention is: keyboard state is state *before* void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent *e) -- cgit v1.2.3 From 83cabda862dced9477d155c84df9440047c856cf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 7 Mar 2012 08:56:41 +0100 Subject: Add fonts to QPlatformTheme. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove QPlatformFontDatabase::defaultFonts() returning a hash containing widget name ->font and the Windows implementation. - Add enumeration and font accessor to QPlatformTheme. The value returned for the enumeration value overwrites the default font of the font database. - Implement for Windows, Mac and KDE. - Add more Windows palettes. Task-number: QTBUG-23686 Change-Id: I8a2abdfd216df23daa7c9630c54264cdf61295db Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qguiapplication.cpp | 5 +++++ src/gui/kernel/qplatformtheme_qpa.cpp | 6 ++++++ src/gui/kernel/qplatformtheme_qpa.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 095336a948..f5aea654fc 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -172,6 +172,11 @@ static inline void clearPalette() static void initFontUnlocked() { + if (!QGuiApplicationPrivate::app_font) { + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) + if (const QFont *font = theme->font(QPlatformTheme::SystemFont)) + QGuiApplicationPrivate::app_font = new QFont(*font); + } if (!QGuiApplicationPrivate::app_font) QGuiApplicationPrivate::app_font = new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont()); diff --git a/src/gui/kernel/qplatformtheme_qpa.cpp b/src/gui/kernel/qplatformtheme_qpa.cpp index 3fdece70ea..c6314825d7 100644 --- a/src/gui/kernel/qplatformtheme_qpa.cpp +++ b/src/gui/kernel/qplatformtheme_qpa.cpp @@ -137,6 +137,12 @@ const QPalette *QPlatformTheme::palette(Palette type) const return 0; } +const QFont *QPlatformTheme::font(Font type) const +{ + Q_UNUSED(type) + return 0; +} + QVariant QPlatformTheme::themeHint(ThemeHint hint) const { switch (hint) { diff --git a/src/gui/kernel/qplatformtheme_qpa.h b/src/gui/kernel/qplatformtheme_qpa.h index be18e4fe38..6ac6a0f573 100644 --- a/src/gui/kernel/qplatformtheme_qpa.h +++ b/src/gui/kernel/qplatformtheme_qpa.h @@ -55,6 +55,7 @@ class QPlatformMenuBar; class QPlatformDialogHelper; class QVariant; class QPalette; +class QFont; class Q_GUI_EXPORT QPlatformTheme { @@ -102,6 +103,31 @@ public: NPalettes }; + enum Font { + SystemFont, + MenuFont, + MenuBarFont, + MenuItemFont, + MessageBoxFont, + LabelFont, + TipLabelFont, + StatusBarFont, + TitleBarFont, + MdiSubWindowTitleFont, + DockWidgetTitleFont, + PushButtonFont, + ToolButtonFont, + ItemViewFont, + ListViewFont, + HeaderViewFont, + ListBoxFont, + ComboMenuItemFont, + ComboLineEditFont, + SmallFont, + MiniFont, + NFonts + }; + enum KeyboardSchemes { WindowsKeyboardScheme, @@ -122,6 +148,8 @@ public: virtual const QPalette *palette(Palette type = SystemPalette) const; + virtual const QFont *font(Font type = SystemFont) const; + virtual QVariant themeHint(ThemeHint hint) const; }; -- cgit v1.2.3 From b319d44798fe4c5aa8b859966d64f28b08be28dd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 5 Mar 2012 14:42:42 +0100 Subject: QCursor: Associate cursor with screen. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduce cursor() accessor to QPlatformScreen. - Remove screen member of QPlatformCursor (a cursor can be shared by multiple screens of a virtual desktop). - Add QCursor::pos()/ QCursor::setPos() taking a QScreen-parameter, use primaryScreen() for old overloads. QCursor::pos() can then query the platform cursor for the position and return the position even if the mouse position is outside the windows owned by the Qt application. - Fix tests Reviewed-by: Samuel Rødal Task-number: QTBUG-22457 Task-number: QTBUG-22565 Task-number: QTBUG-20753 Change-Id: Ia69f37343f95772e934eab1cd806bd54cbdbbe51 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qcursor.cpp | 46 +++++++++++++++++++++++++++++----- src/gui/kernel/qcursor.h | 4 +++ src/gui/kernel/qcursor_qpa.cpp | 40 +++++++++++++++++------------ src/gui/kernel/qguiapplication.cpp | 22 ++++++---------- src/gui/kernel/qplatformcursor_qpa.cpp | 15 ++++++++--- src/gui/kernel/qplatformcursor_qpa.h | 10 +++----- src/gui/kernel/qplatformscreen_qpa.cpp | 11 ++++++++ src/gui/kernel/qplatformscreen_qpa.h | 2 ++ 8 files changed, 103 insertions(+), 47 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index f16e5c85de..95b2b4a28e 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -185,10 +185,10 @@ QT_BEGIN_NAMESPACE */ /*! - \fn QPoint QCursor::pos() + \fn QPoint QCursor::pos(const QScreen *screen) - Returns the position of the cursor (hot spot) in global screen - coordinates. + Returns the position of the cursor (hot spot) of the \a screen + in global screen coordinates. You can call QWidget::mapFromGlobal() to translate it to widget coordinates. @@ -197,10 +197,23 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QCursor::setPos(int x, int y) + \fn QPoint QCursor::pos() + + Returns the position of the cursor (hot spot) of + the primary screen in global screen coordinates. + + You can call QWidget::mapFromGlobal() to translate it to widget + coordinates. + + \sa setPos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen() +*/ - Moves the cursor (hot spot) to the global screen position (\a x, - \a y). + +/*! + \fn void QCursor::setPos(QScreen *screen, int x, int y) + + Moves the cursor (hot spot) of the \a screen to the global + screen position (\a x, \a y). You can call QWidget::mapToGlobal() to translate widget coordinates to global screen coordinates. @@ -208,6 +221,18 @@ QT_BEGIN_NAMESPACE \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal() */ +/*! + \fn void QCursor::setPos(int x, int y) + + Moves the cursor (hot spot) of the primary screen + to the global screen position (\a x, \a y). + + You can call QWidget::mapToGlobal() to translate widget + coordinates to global screen coordinates. + + \sa pos(), QWidget::mapFromGlobal(), QWidget::mapToGlobal(), QGuiApplication::primaryScreen() +*/ + /*! \fn void QCursor::setPos (const QPoint &p) @@ -217,6 +242,15 @@ QT_BEGIN_NAMESPACE \a p. */ +/*! + \fn void QCursor::setPos (QScreen *screen,const QPoint &p) + + \overload + + Moves the cursor (hot spot) to the global screen position of the + \a screen at point \a p. +*/ + /***************************************************************************** QCursor stream functions *****************************************************************************/ diff --git a/src/gui/kernel/qcursor.h b/src/gui/kernel/qcursor.h index 00b709b308..4820bcee9b 100644 --- a/src/gui/kernel/qcursor.h +++ b/src/gui/kernel/qcursor.h @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE class QVariant; +class QScreen; /* ### The fake cursor has to go first with old qdoc. @@ -101,8 +102,11 @@ public: QPoint hotSpot() const; static QPoint pos(); + static QPoint pos(const QScreen *screen); static void setPos(int x, int y); + static void setPos(QScreen *screen, int x, int y); inline static void setPos(const QPoint &p) { setPos(p.x(), p.y()); } + inline static void setPos(QScreen *screen, const QPoint &p) { setPos(screen, p.x(), p.y()); } #ifdef qdoc HCURSOR_or_HANDLE handle() const; diff --git a/src/gui/kernel/qcursor_qpa.cpp b/src/gui/kernel/qcursor_qpa.cpp index 7ba2e1c580..1c719c839e 100644 --- a/src/gui/kernel/qcursor_qpa.cpp +++ b/src/gui/kernel/qcursor_qpa.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include +#include #include #include #include @@ -110,27 +111,34 @@ void QCursorData::update() QPoint QCursor::pos() { + return QCursor::pos(QGuiApplication::primaryScreen()); +} + +QPoint QCursor::pos(const QScreen *screen) +{ + if (screen) + if (const QPlatformCursor *cursor = screen->handle()->cursor()) + return cursor->pos(); return QGuiApplicationPrivate::lastCursorPosition.toPoint(); } -void QCursor::setPos(int x, int y) +void QCursor::setPos(QScreen *screen, int x, int y) { - QPoint target(x, y); - - // Need to check, since some X servers generate null mouse move - // events, causing looping in applications which call setPos() on - // every mouse move event. - // - if (pos() == target) - return; - - QList > cursors = QPlatformCursorPrivate::getInstances(); - int cursorCount = cursors.count(); - for (int i = 0; i < cursorCount; ++i) { - const QWeakPointer &cursor(cursors.at(i)); - if (cursor) - cursor.data()->setPos(target); + if (screen) { + if (QPlatformCursor *cursor = screen->handle()->cursor()) { + const QPoint pos = QPoint(x, y); + // Need to check, since some X servers generate null mouse move + // events, causing looping in applications which call setPos() on + // every mouse move event. + if (pos != cursor->pos()) + cursor->setPos(pos); + } } } +void QCursor::setPos(int x, int y) +{ + QCursor::setPos(QGuiApplication::primaryScreen(), x, y); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index f5aea654fc..42ce3745de 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -978,10 +978,9 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo QMouseEvent ev(type, localPoint, localPoint, globalPoint, button, buttons, e->modifiers); ev.setTimestamp(e->timestamp); #ifndef QT_NO_CURSOR - QList > cursors = QPlatformCursorPrivate::getInstances(); - for (int i = 0; i < cursors.count(); ++i) - if (cursors.at(i)) - cursors.at(i).data()->pointerEvent(ev); + if (const QScreen *screen = window->screen()) + if (QPlatformCursor *cursor = screen->handle()->cursor()) + cursor->pointerEvent(ev); #endif QGuiApplication::sendSpontaneousEvent(window, &ev); if (!e->synthetic && !ev.isAccepted() && qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) { @@ -1814,16 +1813,11 @@ void QGuiApplication::changeOverrideCursor(const QCursor &cursor) #ifndef QT_NO_CURSOR -static void applyCursor(QWindow *w, const QCursor &c) -{ - QCursor cc = c; - QList > cursors = QPlatformCursorPrivate::getInstances(); - int cursorCount = cursors.count(); - for (int i = 0; i < cursorCount; ++i) { - const QWeakPointer &cursor(cursors.at(i)); - if (cursor) - cursor.data()->changeCursor(&cc, w); - } +static inline void applyCursor(QWindow *w, QCursor c) +{ + if (const QScreen *screen = w->screen()) + if (QPlatformCursor *cursor = screen->handle()->cursor()) + cursor->changeCursor(&c, w); } static inline void applyCursor(const QList &l, const QCursor &c) diff --git a/src/gui/kernel/qplatformcursor_qpa.cpp b/src/gui/kernel/qplatformcursor_qpa.cpp index fd7bcdcf18..a4e998ddbc 100644 --- a/src/gui/kernel/qplatformcursor_qpa.cpp +++ b/src/gui/kernel/qplatformcursor_qpa.cpp @@ -43,13 +43,22 @@ #include #include #include +#include +#include #include #include QT_BEGIN_NAMESPACE -QList > QPlatformCursorPrivate::instances; +QList QPlatformCursorPrivate::getInstances() +{ + QList result; + foreach (const QScreen *screen, QGuiApplicationPrivate::screen_list) + if (QPlatformCursor *cursor = screen->handle()->cursor()) + result.push_back(cursor); + return result; +} /*! \class QPlatformCursor @@ -93,10 +102,8 @@ QList > QPlatformCursorPrivate::instances; Constructs a QPlatformCursor for the given \a screen. */ -QPlatformCursor::QPlatformCursor(QPlatformScreen *scr ) - : screen(scr) +QPlatformCursor::QPlatformCursor() { - QPlatformCursorPrivate::instances.append(this); } QPoint QPlatformCursor::pos() const diff --git a/src/gui/kernel/qplatformcursor_qpa.h b/src/gui/kernel/qplatformcursor_qpa.h index a8cbb282fa..e29cf87d03 100644 --- a/src/gui/kernel/qplatformcursor_qpa.h +++ b/src/gui/kernel/qplatformcursor_qpa.h @@ -74,13 +74,12 @@ class QPlatformCursor; class Q_GUI_EXPORT QPlatformCursorPrivate { public: - static QList > getInstances() { return instances; } - static QList > instances; + static QList getInstances(); }; class Q_GUI_EXPORT QPlatformCursor : public QObject { public: - QPlatformCursor(QPlatformScreen *); + QPlatformCursor(); // input methods virtual void pointerEvent(const QMouseEvent & event) { Q_UNUSED(event); } @@ -88,11 +87,8 @@ public: virtual QPoint pos() const; virtual void setPos(const QPoint &pos); -protected: - QPlatformScreen* screen; // Where to request an update - private: - Q_DECLARE_PRIVATE(QPlatformCursor); + Q_DECLARE_PRIVATE(QPlatformCursor) friend void qt_qpa_set_cursor(QWidget * w, bool force); friend class QApplicationPrivate; }; diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp index c832d853f4..022f198073 100644 --- a/src/gui/kernel/qplatformscreen_qpa.cpp +++ b/src/gui/kernel/qplatformscreen_qpa.cpp @@ -41,6 +41,7 @@ #include "qplatformscreen_qpa.h" #include +#include #include #include #include @@ -250,4 +251,14 @@ QPlatformScreenPageFlipper *QPlatformScreen::pageFlipper() const return 0; } +/*! + Reimplement this function in subclass to return the cursor of the screen. + + The default implementation returns 0. +*/ +QPlatformCursor *QPlatformScreen::cursor() const +{ + return 0; +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformscreen_qpa.h b/src/gui/kernel/qplatformscreen_qpa.h index 7d74698074..b6eb91f9b2 100644 --- a/src/gui/kernel/qplatformscreen_qpa.h +++ b/src/gui/kernel/qplatformscreen_qpa.h @@ -63,6 +63,7 @@ class QPlatformBackingStore; class QPlatformOpenGLContext; class QPlatformScreenPrivate; class QPlatformWindow; +class QPlatformCursor; class QPlatformScreenPageFlipper; class QScreen; class QSurfaceFormat; @@ -103,6 +104,7 @@ public: virtual QString name() const { return QString(); } virtual QPlatformScreenPageFlipper *pageFlipper() const; + virtual QPlatformCursor *cursor() const; protected: QScopedPointer d_ptr; -- cgit v1.2.3