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>
bb10
Lars Knoll 2011-08-31 10:47:09 +02:00 committed by Samuel Rødal
parent 3795e2c7be
commit 94355ca15a
13 changed files with 265 additions and 107 deletions

View File

@ -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 += \

View File

@ -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()

View File

@ -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);

View File

@ -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.

View File

@ -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.

View File

@ -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);
};

View File

@ -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();
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -68,6 +68,8 @@
#include "private/qstyle_p.h"
#include "qmessagebox.h"
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtGui/qstylehints.h>
#include "qinputcontext.h"
#include "private/qkeymapper_p.h"
@ -456,9 +458,6 @@ QWidget *QApplicationPrivate::focus_widget = 0; // has keyboard input foc
QWidget *QApplicationPrivate::hidden_focus_widget = 0; // will get keyboard input focus after show()
QWidget *QApplicationPrivate::active_window = 0; // toplevel with keyboard focus
bool QApplicationPrivate::obey_desktop_settings = true; // use winsys resources
int QApplicationPrivate::cursor_flash_time = 1000; // text caret flash time
int QApplicationPrivate::mouse_double_click_time = 400; // mouse dbl click limit
int QApplicationPrivate::keyboard_input_time = 400; // keyboard input interval
#ifndef QT_NO_WHEELEVENT
int QApplicationPrivate::wheel_scroll_lines; // number of lines to scroll
#endif
@ -466,16 +465,6 @@ bool qt_is_gui_used;
bool Q_WIDGETS_EXPORT qt_tab_all_widgets = true;
bool qt_in_tab_key_event = false;
int qt_antialiasing_threshold = -1;
static int drag_time = 500;
#ifndef QT_GUI_DRAG_DISTANCE
#define QT_GUI_DRAG_DISTANCE 4
#endif
#ifdef Q_OS_SYMBIAN
// The screens are a bit too small to for your thumb when using only 4 pixels drag distance.
static int drag_distance = 12; //XXX move to qplatformdefs.h
#else
static int drag_distance = QT_GUI_DRAG_DISTANCE;
#endif
QSize QApplicationPrivate::app_strut = QSize(0,0); // no default application strut
bool QApplicationPrivate::animate_ui = true;
bool QApplicationPrivate::animate_menu = false;
@ -1117,12 +1106,7 @@ QApplication::~QApplication()
#endif //QT_NO_SESSIONMANAGER
QApplicationPrivate::obey_desktop_settings = true;
QApplicationPrivate::cursor_flash_time = 1000;
QApplicationPrivate::mouse_double_click_time = 400;
QApplicationPrivate::keyboard_input_time = 400;
drag_time = 500;
drag_distance = 4;
QApplicationPrivate::app_strut = QSize(0, 0);
QApplicationPrivate::animate_ui = true;
QApplicationPrivate::animate_menu = false;
@ -3419,7 +3403,7 @@ void QApplication::saveState(QSessionManager &manager)
void QApplication::setStartDragTime(int ms)
{
drag_time = ms;
Q_UNUSED(ms)
}
/*!
@ -3441,7 +3425,7 @@ void QApplication::setStartDragTime(int ms)
int QApplication::startDragTime()
{
return drag_time;
return qApp->styleHints()->startDragTime();
}
/*
@ -3452,7 +3436,7 @@ int QApplication::startDragTime()
void QApplication::setStartDragDistance(int l)
{
drag_distance = l;
Q_UNUSED(l);
}
/*!
@ -3478,7 +3462,7 @@ void QApplication::setStartDragDistance(int l)
int QApplication::startDragDistance()
{
return drag_distance;
return qApp->styleHints()->startDragTime();
}
/*!
@ -5038,6 +5022,16 @@ bool QApplication::keypadNavigationEnabled()
We recommend that widgets do not cache this value as it may change at any
time if the user changes the global desktop settings.
*/
void QApplication::setCursorFlashTime(int msecs)
{
Q_UNUSED(msecs);
}
int QApplication::cursorFlashTime()
{
return qApp->styleHints()->cursorFlashTime();
}
/*!
\property QApplication::doubleClickInterval
@ -5045,9 +5039,19 @@ bool QApplication::keypadNavigationEnabled()
from two consecutive mouse clicks
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
operating system's value is used. However, on Windows and Symbian OS,
calling this function sets the double click interval for all applications.
operating system's value is used.
Setting the interval is not supported anymore in Qt 5.
*/
void QApplication::setDoubleClickInterval(int ms)
{
Q_UNUSED(ms);
}
int QApplication::doubleClickInterval()
{
return qApp->styleHints()->mouseDoubleClickInterval();
}
/*!
\property QApplication::keyboardInputInterval
@ -5058,6 +5062,15 @@ bool QApplication::keypadNavigationEnabled()
The default value on X11 is 400 milliseconds. On Windows and Mac OS, the
operating system's value is used.
*/
void QApplication::setKeyboardInputInterval(int ms)
{
Q_UNUSED(ms);
}
int QApplication::keyboardInputInterval()
{
return qApp->styleHints()->keyboardInputInterval();
}
/*!
\property QApplication::wheelScrollLines

View File

@ -422,9 +422,6 @@ public:
static QWidget *active_window;
static QIcon *app_icon;
static bool obey_desktop_settings;
static int cursor_flash_time;
static int mouse_double_click_time;
static int keyboard_input_time;
#ifndef QT_NO_WHEELEVENT
static int wheel_scroll_lines;
#endif

View File

@ -287,36 +287,6 @@ void QApplicationPrivate::initializeWidgetPaletteHash()
{
}
void QApplication::setCursorFlashTime(int msecs)
{
QApplicationPrivate::cursor_flash_time = msecs;
}
int QApplication::cursorFlashTime()
{
return QApplicationPrivate::cursor_flash_time;
}
void QApplication::setDoubleClickInterval(int ms)
{
QApplicationPrivate::mouse_double_click_time = ms;
}
int QApplication::doubleClickInterval()
{
return QApplicationPrivate::mouse_double_click_time;
}
void QApplication::setKeyboardInputInterval(int ms)
{
QApplicationPrivate::keyboard_input_time = ms;
}
int QApplication::keyboardInputInterval()
{
return QApplicationPrivate::keyboard_input_time;
}
#ifndef QT_NO_WHEELEVENT
void QApplication::setWheelScrollLines(int lines)
{