diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/kernel.pri | 6 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 49 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.h | 11 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication_p.h | 5 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration_qpa.cpp | 19 | ||||
-rw-r--r-- | src/gui/kernel/qplatformintegration_qpa.h | 10 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints.cpp | 80 | ||||
-rw-r--r-- | src/gui/kernel/qstylehints.h | 73 | ||||
-rw-r--r-- | src/gui/text/qlinecontrol.cpp | 10 | ||||
-rw-r--r-- | src/gui/text/qtextcontrol.cpp | 15 |
10 files changed, 228 insertions, 50 deletions
diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index b24d51c17d..36caa9ce83 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -20,7 +20,8 @@ HEADERS += \ kernel/qpalette.h \ kernel/qsessionmanager.h \ kernel/qwindowdefs.h \ - kernel/qscreen.h + kernel/qscreen.h \ + kernel/qstylehints.h SOURCES += \ kernel/qclipboard.cpp \ @@ -34,7 +35,8 @@ SOURCES += \ kernel/qmime.cpp \ kernel/qpalette.cpp \ kernel/qguivariant.cpp \ - kernel/qscreen.cpp + kernel/qscreen.cpp \ + kernel/qstylehints.cpp qpa { HEADERS += \ diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index e1d40806bc..029a89c472 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -58,6 +58,7 @@ #include <QtGui/QPlatformIntegration> #include <QtGui/QGenericPluginFactory> +#include <QtGui/qstylehints.h> #include <QWindowSystemInterface> #include "private/qwindowsysteminterface_qpa_p.h" @@ -82,8 +83,6 @@ Q_GUI_EXPORT bool qt_is_gui_used = true; Qt::MouseButtons QGuiApplicationPrivate::mouse_buttons = Qt::NoButton; Qt::KeyboardModifiers QGuiApplicationPrivate::modifier_buttons = Qt::NoModifier; -int QGuiApplicationPrivate::keyboard_input_time = 400; -int QGuiApplicationPrivate::mouse_double_click_time = 400; QPointF QGuiApplicationPrivate::lastCursorPosition(0.0, 0.0); QPlatformIntegration *QGuiApplicationPrivate::platform_integration = 0; @@ -401,6 +400,8 @@ QGuiApplicationPrivate::~QGuiApplicationPrivate() cleanupThreadData(); + delete styleHints; + delete platform_integration; platform_integration = 0; } @@ -434,26 +435,6 @@ Qt::MouseButtons QGuiApplication::mouseButtons() return QGuiApplicationPrivate::mouse_buttons; } -void QGuiApplication::setDoubleClickInterval(int ms) -{ - QGuiApplicationPrivate::mouse_double_click_time = ms; -} - -int QGuiApplication::doubleClickInterval() -{ - return QGuiApplicationPrivate::mouse_double_click_time; -} - -void QGuiApplication::setKeyboardInputInterval(int ms) -{ - QGuiApplicationPrivate::keyboard_input_time = ms; -} - -int QGuiApplication::keyboardInputInterval() -{ - return QGuiApplicationPrivate::keyboard_input_time; -} - QPlatformNativeInterface *QGuiApplication::platformNativeInterface() { QPlatformIntegration *pi = QGuiApplicationPrivate::platformIntegration(); @@ -588,7 +569,8 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo } buttons = e->buttons; if (button & e->buttons) { - if ((e->timestamp - mousePressTime) < static_cast<ulong>(QGuiApplication::doubleClickInterval()) && button == mousePressButton) { + if ((e->timestamp - mousePressTime) < static_cast<ulong>(qApp->styleHints()->mouseDoubleClickInterval()) && + button == mousePressButton) { type = QEvent::MouseButtonDblClick; mousePressButton = Qt::NoButton; } @@ -1171,6 +1153,27 @@ void QGuiApplication::restoreOverrideCursor() } #endif// QT_NO_CURSOR +/*! + \since 5.0 + + returns the style hints. + + The style hints encapsulate a set of platform dependent properties + such as double click intervals, full width selection and others. + + The hints can be used to integrate tighter with the underlying platform. + + \sa QStyleHints + */ +QStyleHints *QGuiApplication::styleHints() const +{ + Q_D(const QGuiApplication); + if (!d->styleHints) + const_cast<QGuiApplicationPrivate *>(d)->styleHints = new QStyleHints(); + return d->styleHints; +} + + // Returns the current platform used by keyBindings uint QGuiApplicationPrivate::currentKeyPlatform() diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 871e314540..c402b9b9dc 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -58,6 +58,7 @@ class QGuiApplicationPrivate; class QPlatformNativeInterface; class QPalette; class QScreen; +class QStyleHints; #if defined(qApp) #undef qApp @@ -73,8 +74,6 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication { Q_OBJECT Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection) - Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval) - Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval) Q_PROPERTY(bool quitOnLastWindowClosed READ quitOnLastWindowClosed WRITE setQuitOnLastWindowClosed) @@ -108,12 +107,6 @@ public: static Qt::KeyboardModifiers keyboardModifiers(); static Qt::MouseButtons mouseButtons(); - static void setDoubleClickInterval(int); - static int doubleClickInterval(); - - static void setKeyboardInputInterval(int); - static int keyboardInputInterval(); - static void setLayoutDirection(Qt::LayoutDirection direction); static Qt::LayoutDirection layoutDirection(); @@ -123,6 +116,8 @@ public: static QLocale keyboardInputLocale(); static Qt::LayoutDirection keyboardInputDirection(); + QStyleHints *styleHints() const; + static QPlatformNativeInterface *platformNativeInterface(); static void setQuitOnLastWindowClosed(bool quit); diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h index 43cb21460e..bdf79d4394 100644 --- a/src/gui/kernel/qguiapplication_p.h +++ b/src/gui/kernel/qguiapplication_p.h @@ -75,9 +75,6 @@ public: virtual void notifyLayoutDirectionChange(); virtual void notifyActiveWindowChange(QWindow *previous); - static int keyboard_input_time; - static int mouse_double_click_time; - static Qt::KeyboardModifiers modifier_buttons; static Qt::MouseButtons mouse_buttons; @@ -175,6 +172,8 @@ public: static QFont *app_font; + QStyleHints *styleHints; + static bool quitOnLastWindowClosed; QString qmljs_debug_arguments; // a string containing arguments for js/qml debugging. diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp index 39341fa88f..2beb0bb240 100644 --- a/src/gui/kernel/qplatformintegration_qpa.cpp +++ b/src/gui/kernel/qplatformintegration_qpa.cpp @@ -209,6 +209,25 @@ QPlatformInputContext *QPlatformIntegration::inputContext() const return 0; } +QVariant QPlatformIntegration::styleHint(StyleHint hint) const +{ + switch (hint) { + case CursorFlashTime: + return 1000; + case KeyboardInputInterval: + return 400; + case MouseDoubleClickInterval: + return 400; + case StartDragDistance: + return 10; + case StartDragTime: + return 500; + } + + return 0; +} + + /*! Should be called by the implementation whenever a new screen is added. diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index d26fcfabb4..367f6596e2 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -98,6 +98,16 @@ public: // Access native handles. The window handle is already available from Wid; virtual QPlatformNativeInterface *nativeInterface() const; + enum StyleHint { + CursorFlashTime, + KeyboardInputInterval, + MouseDoubleClickInterval, + StartDragDistance, + StartDragTime + }; + + virtual QVariant styleHint(StyleHint hint) const; + protected: void screenAdded(QPlatformScreen *screen); }; diff --git a/src/gui/kernel/qstylehints.cpp b/src/gui/kernel/qstylehints.cpp new file mode 100644 index 0000000000..8c87c390a3 --- /dev/null +++ b/src/gui/kernel/qstylehints.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qstylehints.h> +#include <qplatformintegration_qpa.h> +#include <private/qguiapplication_p.h> + +static inline QVariant hint(QPlatformIntegration::StyleHint h) +{ + return QGuiApplicationPrivate::platformIntegration()->styleHint(h); +} + +QStyleHints::QStyleHints() + : QObject() +{ +} + + +int QStyleHints::mouseDoubleClickInterval() const +{ + return hint(QPlatformIntegration::MouseDoubleClickInterval).toInt(); +} + +int QStyleHints::startDragDistance() const +{ + return hint(QPlatformIntegration::StartDragDistance).toInt(); +} + +int QStyleHints::startDragTime() const +{ + return hint(QPlatformIntegration::StartDragTime).toInt(); +} + +int QStyleHints::keyboardInputInterval() const +{ + return hint(QPlatformIntegration::KeyboardInputInterval).toInt(); +} + +int QStyleHints::cursorFlashTime() const +{ + return hint(QPlatformIntegration::CursorFlashTime).toInt(); +} diff --git a/src/gui/kernel/qstylehints.h b/src/gui/kernel/qstylehints.h new file mode 100644 index 0000000000..3cb549daad --- /dev/null +++ b/src/gui/kernel/qstylehints.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSTYLEHINTS_H +#define QSTYLEHINTS_H + +#include <QtCore/qobject.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class QPlatformIntegration; + +class Q_GUI_EXPORT QStyleHints : public QObject +{ + Q_OBJECT +public: + int mouseDoubleClickInterval() const; + int startDragDistance() const; + int startDragTime() const; + int keyboardInputInterval() const; + int cursorFlashTime() const; +private: + friend class QGuiApplication; + QStyleHints(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/gui/text/qlinecontrol.cpp b/src/gui/text/qlinecontrol.cpp index 36c064ee40..6f9d9402ee 100644 --- a/src/gui/text/qlinecontrol.cpp +++ b/src/gui/text/qlinecontrol.cpp @@ -56,12 +56,11 @@ #include "qlist.h" #endif #include "qguiapplication.h" +#include "qstylehints.h" QT_BEGIN_NAMESPACE -// ### these should come from the application -const int startDragDistance = 10; -const int cursorFlashTime = 2000; +// ### these should come from QStyleHints const int textCursorWidth = 1; const bool fullWidthSelection = true; @@ -1394,8 +1393,7 @@ void QLineControl::processMouseEvent(QMouseEvent* ev) switch (ev->type()) { case QEvent::MouseButtonPress:{ if (m_tripleClickTimer - && (ev->pos() - m_tripleClick).manhattanLength() - < startDragDistance) { + && (ev->pos() - m_tripleClick).manhattanLength() < qApp->styleHints()->startDragDistance()) { selectAll(); return; } @@ -1412,7 +1410,7 @@ void QLineControl::processMouseEvent(QMouseEvent* ev) selectWordAtPos(xToPos(ev->pos().x())); if (m_tripleClickTimer) killTimer(m_tripleClickTimer); - m_tripleClickTimer = startTimer(QGuiApplication::doubleClickInterval()); + m_tripleClickTimer = startTimer(qApp->styleHints()->mouseDoubleClickInterval()); m_tripleClick = ev->pos(); } break; diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index 9ca6a24ce7..f7ea2fa34a 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -70,10 +70,9 @@ #include <qtexttable.h> #include <qvariant.h> #include <qurl.h> +#include <qstylehints.h> -// ### these should come from the application -const int startDragDistance = 10; -const int cursorFlashTime = 2000; +// ### these should come from QStyleHints const int textCursorWidth = 1; const bool fullWidthSelection = true; @@ -635,8 +634,8 @@ void QTextControlPrivate::setBlinkingCursorEnabled(bool enable) { Q_Q(QTextControl); - if (enable && cursorFlashTime > 0) - cursorBlinkTimer.start(cursorFlashTime / 2, q); + if (enable && qApp->styleHints()->cursorFlashTime() > 0) + cursorBlinkTimer.start(qApp->styleHints()->cursorFlashTime() / 2, q); else cursorBlinkTimer.stop(); @@ -1452,7 +1451,7 @@ void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, con #endif if (trippleClickTimer.isActive() - && ((pos - trippleClickPoint).toPoint().manhattanLength() < startDragDistance)) { + && ((pos - trippleClickPoint).toPoint().manhattanLength() < qApp->styleHints()->startDragDistance())) { cursor.movePosition(QTextCursor::StartOfBlock); cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); @@ -1550,7 +1549,7 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons const int oldCursorPos = cursor.position(); if (mightStartDrag) { - if ((mousePos.toPoint() - dragStartPos).manhattanLength() > startDragDistance) + if ((mousePos.toPoint() - dragStartPos).manhattanLength() > qApp->styleHints()->startDragDistance()) startDrag(); return; } @@ -1697,7 +1696,7 @@ void QTextControlPrivate::mouseDoubleClickEvent(QEvent *e, Qt::MouseButton butto selectedWordOnDoubleClick = cursor; trippleClickPoint = pos; - trippleClickTimer.start(QGuiApplication::doubleClickInterval(), q); + trippleClickTimer.start(qApp->styleHints()->mouseDoubleClickInterval(), q); if (doEmit) { selectionChanged(); #ifndef QT_NO_CLIPBOARD |