summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2011-08-31 10:47:09 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-08-31 11:47:21 +0200
commit94355ca15a4d451f4a4b858240e2c1a96e26537b (patch)
tree6b9209c03a86575a45c92e62a990c60528c02195 /src/gui/kernel
parent3795e2c7bec9eb50a04d139e45ecc809c4aa37f6 (diff)
Add a QStyleHints class to QtGui
This class encapsulates platform specific style hints like doubleClickInterval or cursorFlashTime. Change-Id: I0d88c47a59d564d8d346642184e5b14e1864cf40 Reviewed-on: http://codereview.qt.nokia.com/3927 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/kernel.pri6
-rw-r--r--src/gui/kernel/qguiapplication.cpp49
-rw-r--r--src/gui/kernel/qguiapplication.h11
-rw-r--r--src/gui/kernel/qguiapplication_p.h5
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.cpp19
-rw-r--r--src/gui/kernel/qplatformintegration_qpa.h10
-rw-r--r--src/gui/kernel/qstylehints.cpp80
-rw-r--r--src/gui/kernel/qstylehints.h73
8 files changed, 217 insertions, 36 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