diff options
author | David Faure <faure@kde.org> | 2011-08-17 11:14:57 (GMT) |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@nokia.com> | 2011-08-17 11:14:57 (GMT) |
commit | 3b5354386225974ea6db78c12f32cb81e2d50104 (patch) | |
tree | 6ab2fffb846b52908ec3f6d889403e3e539db08e /src | |
parent | fb934f2a8d7398a3ff39a107093f9da6ceda59a7 (diff) | |
download | Qt-3b5354386225974ea6db78c12f32cb81e2d50104.zip Qt-3b5354386225974ea6db78c12f32cb81e2d50104.tar.gz Qt-3b5354386225974ea6db78c12f32cb81e2d50104.tar.bz2 |
Add a QApplication::queryKeyboardModifiers() method.
QApplication::keyboardModifiers returns the keyboard modifiers
from the last keypress event in this process, as documented. However
there are use cases for querying keyboard modifiers as they currently are,
see QTBUG-11243.
Merge-request: 585
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qapplication.cpp | 21 | ||||
-rw-r--r-- | src/gui/kernel/qapplication.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 5 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_qws.cpp | 5 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_s60.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_win.cpp | 5 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_x11.cpp | 15 | ||||
-rw-r--r-- | src/gui/kernel/qdnd_x11.cpp | 17 |
8 files changed, 60 insertions, 17 deletions
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index cd13894..15d37c3 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -3321,7 +3321,7 @@ bool QApplication::desktopSettingsAware() one of the above events. If no keys are being held Qt::NoModifier is returned. - \sa mouseButtons() + \sa mouseButtons(), queryKeyboardModifiers() */ Qt::KeyboardModifiers QApplication::keyboardModifiers() @@ -3330,6 +3330,25 @@ Qt::KeyboardModifiers QApplication::keyboardModifiers() } /*! + \fn Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() + + Queries and returns the state of the modifier keys on the keyboard. + Unlike keyboardModifiers, this method returns the actual keys held + on the input device at the time of calling the method. + + It does not rely on the keypress events having been received by this + process, which makes it possible to check the modifiers while moving + a window, for instance. Note that in most cases, you should use + keyboardModifiers(), which is faster and more accurate since it contains + the state of the modifiers as they were when the currently processed + event was received. + + \sa keyboardModifiers() + + \since 4.8 +*/ + +/*! Returns the current state of the buttons on the mouse. The current state is updated syncronously as the event queue is emptied of events that will spontaneously change the mouse state (QEvent::MouseButtonPress and diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h index 01a246a..1548849 100644 --- a/src/gui/kernel/qapplication.h +++ b/src/gui/kernel/qapplication.h @@ -198,6 +198,7 @@ public: static void alert(QWidget *widget, int duration = 0); static Qt::KeyboardModifiers keyboardModifiers(); + static Qt::KeyboardModifiers queryKeyboardModifiers(); static Qt::MouseButtons mouseButtons(); static void setDesktopSettingsAware(bool); diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index c5ff799..1f75f09 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1395,6 +1395,11 @@ void QApplication::restoreOverrideCursor() } #endif // QT_NO_CURSOR +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return qt_mac_get_modifiers(GetCurrentEventKeyModifiers()); +} + QWidget *QApplication::topLevelAt(const QPoint &p) { #ifndef QT_MAC_USE_COCOA diff --git a/src/gui/kernel/qapplication_qws.cpp b/src/gui/kernel/qapplication_qws.cpp index 3b6a075..193dfcd 100644 --- a/src/gui/kernel/qapplication_qws.cpp +++ b/src/gui/kernel/qapplication_qws.cpp @@ -2699,6 +2699,11 @@ void QApplication::alert(QWidget *, int) { } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return keyboardModifiers(); // TODO proper implementation +} + int QApplication::qwsProcessEvent(QWSEvent* event) { Q_D(QApplication); diff --git a/src/gui/kernel/qapplication_s60.cpp b/src/gui/kernel/qapplication_s60.cpp index 5ac9803..31246f4 100644 --- a/src/gui/kernel/qapplication_s60.cpp +++ b/src/gui/kernel/qapplication_s60.cpp @@ -115,6 +115,8 @@ QWidget *qt_button_down = 0; // widget got last button-down QSymbianControl *QSymbianControl::lastFocusedControl = 0; +static Qt::KeyboardModifiers app_keyboardModifiers = Qt::NoModifier; + QS60Data* qGlobalS60Data() { return qt_s60Data(); @@ -735,6 +737,7 @@ void QSymbianControl::HandlePointerEvent(const TPointerEvent& pEvent) Qt::MouseButton button; mapS60MouseEventTypeToQt(&type, &button, &pEvent); Qt::KeyboardModifiers modifiers = mapToQtModifiers(pEvent.iModifiers); + app_keyboardModifiers = modifiers; QPoint widgetPos = translatePointForFixedNativeOrientation(pEvent.iPosition); TPoint controlScreenPos = PositionRelativeToScreen(); @@ -2590,6 +2593,11 @@ void QApplication::setEffectEnabled(Qt::UIEffect /* effect */, bool /* enable */ // TODO: Implement QApplication::setEffectEnabled(Qt::UIEffect effect, bool enable) } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return app_keyboardModifiers; +} + TUint QApplicationPrivate::resolveS60ScanCode(TInt scanCode, TUint keysym) { if (!scanCode) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index c34e75f..756cb56 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1319,6 +1319,11 @@ Qt::KeyboardModifiers qt_win_getKeyboardModifiers() return modifiers; } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + return qt_win_getKeyboardModifiers(); +} + /***************************************************************************** Routines to find a Qt widget from a screen position *****************************************************************************/ diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp index 666fe85..ef8e2b8 100644 --- a/src/gui/kernel/qapplication_x11.cpp +++ b/src/gui/kernel/qapplication_x11.cpp @@ -3058,6 +3058,21 @@ void QApplicationPrivate::_q_alertTimeOut() } } +Qt::KeyboardModifiers QApplication::queryKeyboardModifiers() +{ + Window root; + Window child; + int root_x, root_y, win_x, win_y; + uint keybstate; + for (int i = 0; i < ScreenCount(X11->display); ++i) { + if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child, + &root_x, &root_y, &win_x, &win_y, &keybstate)) + return X11->translateModifiers(keybstate & 0x00ff); + } + return 0; + +} + /***************************************************************************** Special lookup functions for windows that have been reparented recently *****************************************************************************/ diff --git a/src/gui/kernel/qdnd_x11.cpp b/src/gui/kernel/qdnd_x11.cpp index 0c683b4..5847021 100644 --- a/src/gui/kernel/qdnd_x11.cpp +++ b/src/gui/kernel/qdnd_x11.cpp @@ -1112,21 +1112,6 @@ void qt_xdnd_send_leave() waiting_for_status = false; } -// TODO: remove and use QApplication::currentKeyboardModifiers() in Qt 4.8. -static Qt::KeyboardModifiers currentKeyboardModifiers() -{ - Window root; - Window child; - int root_x, root_y, win_x, win_y; - uint keybstate; - for (int i = 0; i < ScreenCount(X11->display); ++i) { - if (XQueryPointer(X11->display, QX11Info::appRootWindow(i), &root, &child, - &root_x, &root_y, &win_x, &win_y, &keybstate)) - return X11->translateModifiers(keybstate & 0x00ff); - } - return 0; -} - void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) { DEBUG("xdndHandleDrop"); @@ -1183,7 +1168,7 @@ void QX11Data::xdndHandleDrop(QWidget *, const XEvent * xe, bool passive) // Drop coming from another app? Update keyboard modifiers. if (!qt_xdnd_dragging) { - QApplicationPrivate::modifier_buttons = currentKeyboardModifiers(); + QApplicationPrivate::modifier_buttons = QApplication::queryKeyboardModifiers(); } QDropEvent de(qt_xdnd_current_position, possible_actions, dropData, |