summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-08-12 15:20:08 +0200
committeraxis <qt-info@nokia.com>2009-08-12 17:05:52 +0200
commitecb4110040218fafaad8717c7c58de1086d3590d (patch)
tree3d803129114440896ef702c397342e5af77663b6
parent9bba7e42a2988967507d536c497c54efc791eb67 (diff)
downloadqt4-tools-ecb4110040218fafaad8717c7c58de1086d3590d.tar.gz
Revised SIP API.
After discussions with Matthias, several things were changed: - the autoSipOnMouseFocus property was removed and replaced with a new style hint, SH_RequestSoftwareInputPanel. This means the style can define when the input panel is launched. - The code which sends RequestSoftwareInputPanel events was moved into its own function, and the widgets call that function. AutoTest: Included and passed RevBy: mae
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp12
-rw-r--r--src/gui/kernel/qapplication.cpp35
-rw-r--r--src/gui/kernel/qapplication.h4
-rw-r--r--src/gui/kernel/qapplication_p.h1
-rw-r--r--src/gui/kernel/qwidget_p.h14
-rw-r--r--src/gui/styles/qcommonstyle.cpp3
-rw-r--r--src/gui/styles/qs60style.cpp3
-rw-r--r--src/gui/styles/qstyle.cpp17
-rw-r--r--src/gui/styles/qstyle.h6
-rw-r--r--src/gui/styles/qwindowscestyle.cpp3
-rw-r--r--src/gui/styles/qwindowsmobilestyle.cpp3
-rw-r--r--src/gui/widgets/qlineedit.cpp6
-rw-r--r--src/gui/widgets/qplaintextedit.cpp6
-rw-r--r--src/gui/widgets/qtextedit.cpp6
-rw-r--r--tests/auto/qinputcontext/tst_qinputcontext.cpp37
15 files changed, 91 insertions, 65 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index 7091b5df7d..4931d078d5 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -584,6 +584,7 @@
#include <private/qtextcontrol_p.h>
#include <private/qtextdocumentlayout_p.h>
#include <private/qtextengine_p.h>
+#include <private/qwidget_p.h>
#ifdef Q_WS_X11
#include <private/qt_x11_p.h>
@@ -9100,15 +9101,10 @@ void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
return;
}
- if (event->button() == Qt::LeftButton && qApp->autoSipEnabled()
- && (!dd->clickCausedFocus || qApp->autoSipOnMouseFocus())) {
- QEvent _event(QEvent::RequestSoftwareInputPanel);
- QWidget *receiver = event->widget();
- if(receiver) {
- QApplication::sendEvent(receiver, &_event);
- }
+ QWidget *widget = event->widget();
+ if (widget) {
+ qt_widget_private(widget)->handleSoftwareInputPanel(event->button(), dd->clickCausedFocus);
}
-
dd->clickCausedFocus = 0;
dd->sendControlEvent(event);
}
diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp
index 5d1ef8c695..734ba667c2 100644
--- a/src/gui/kernel/qapplication.cpp
+++ b/src/gui/kernel/qapplication.cpp
@@ -453,7 +453,6 @@ bool QApplicationPrivate::animate_tooltip = false;
bool QApplicationPrivate::fade_tooltip = false;
bool QApplicationPrivate::animate_toolbox = false;
bool QApplicationPrivate::widgetCount = false;
-bool QApplicationPrivate::auto_sip_on_mouse_focus = false;
#if defined(Q_WS_WIN) && !defined(Q_WS_WINCE)
bool QApplicationPrivate::inSizeMove = false;
#endif
@@ -1068,7 +1067,6 @@ QApplication::~QApplication()
QApplicationPrivate::animate_tooltip = false;
QApplicationPrivate::fade_tooltip = false;
QApplicationPrivate::widgetCount = false;
- QApplicationPrivate::auto_sip_on_mouse_focus = false;
#ifndef QT_NO_STATEMACHINE
// trigger unregistering of QStateMachine's GUI types
@@ -3460,39 +3458,6 @@ Qt::LayoutDirection QApplication::layoutDirection()
return layout_direction;
}
-/*!
- \property autoSipOnMouseFocus
- \since 4.6
- \brief toggles SIP (software input panel) launch policy
-
- This property holds whether widgets should request a software input
- panel when it is focused with the mouse. This is typically used to
- launch a virtual keyboard on devices which have very few or no keys.
-
- If the property is set to true, the widget asks for an input panel
- on the mouse click which causes the widget to be focused. If the
- property is set to false, the user must click a second time before
- the widget asks for an input panel.
-
- \note If the widget is focused by other means than a mouse click,
- the next click is will trigger an input panel request,
- regardless of the value of this property.
-
- The default is platform dependent.
-
- \sa QEvent::RequestSoftwareInputPanel, QInputContext
-*/
-
-void QApplication::setAutoSipOnMouseFocus(bool enable)
-{
- QApplicationPrivate::auto_sip_on_mouse_focus = enable;
-}
-
-bool QApplication::autoSipOnMouseFocus()
-{
- return QApplicationPrivate::auto_sip_on_mouse_focus;
-}
-
/*!
\obsolete
diff --git a/src/gui/kernel/qapplication.h b/src/gui/kernel/qapplication.h
index fcb3a7ce38..1f92b1aa6f 100644
--- a/src/gui/kernel/qapplication.h
+++ b/src/gui/kernel/qapplication.h
@@ -97,8 +97,6 @@ class Q_GUI_EXPORT QApplication : public QCoreApplication
Q_PROPERTY(int cursorFlashTime READ cursorFlashTime WRITE setCursorFlashTime)
Q_PROPERTY(int doubleClickInterval READ doubleClickInterval WRITE setDoubleClickInterval)
Q_PROPERTY(int keyboardInputInterval READ keyboardInputInterval WRITE setKeyboardInputInterval)
- Q_PROPERTY(bool autoSipOnMouseFocus READ autoSipOnMouseFocus
- WRITE setAutoSipOnMouseFocus)
#ifndef QT_NO_WHEELEVENT
Q_PROPERTY(int wheelScrollLines READ wheelScrollLines WRITE setWheelScrollLines)
#endif
@@ -299,8 +297,6 @@ public Q_SLOTS:
#endif
void setAutoSipEnabled(const bool enabled);
bool autoSipEnabled() const;
- void setAutoSipOnMouseFocus(bool);
- bool autoSipOnMouseFocus();
static void closeAllWindows();
static void aboutQt();
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index dc8ea6cb4d..c0f4f39798 100644
--- a/src/gui/kernel/qapplication_p.h
+++ b/src/gui/kernel/qapplication_p.h
@@ -432,7 +432,6 @@ public:
static bool fade_tooltip;
static bool animate_toolbox;
static bool widgetCount; // Coupled with -widgetcount switch
- static bool auto_sip_on_mouse_focus;
#ifdef Q_WS_MAC
static bool native_modal_dialog_active;
#endif
diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h
index f4cd61a8d0..86702ac52a 100644
--- a/src/gui/kernel/qwidget_p.h
+++ b/src/gui/kernel/qwidget_p.h
@@ -61,6 +61,7 @@
#include "QtGui/qregion.h"
#include "QtGui/qsizepolicy.h"
#include "QtGui/qstyle.h"
+#include "QtGui/qapplication.h"
#ifdef Q_WS_WIN
#include "QtCore/qt_windows.h"
@@ -461,6 +462,19 @@ public:
QSize adjustedSize() const;
+ inline void handleSoftwareInputPanel(Qt::MouseButton button, bool clickCausedFocus)
+ {
+ Q_Q(QWidget);
+ if (button == Qt::LeftButton && qApp->autoSipEnabled()) {
+ QStyle::RequestSoftwareInputPanel behavior = QStyle::RequestSoftwareInputPanel(
+ q->style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
+ if (!clickCausedFocus || behavior == QStyle::RSIP_OnMouseClick) {
+ QEvent event(QEvent::RequestSoftwareInputPanel);
+ QApplication::sendEvent(q, &event);
+ }
+ }
+ }
+
#ifndef Q_WS_QWS // Almost cross-platform :-)
void setWSGeometry(bool dontShow=false, const QRect &oldRect = QRect());
diff --git a/src/gui/styles/qcommonstyle.cpp b/src/gui/styles/qcommonstyle.cpp
index 3420ad1178..1d1144e444 100644
--- a/src/gui/styles/qcommonstyle.cpp
+++ b/src/gui/styles/qcommonstyle.cpp
@@ -5356,6 +5356,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
}
#endif
break;
+ case SH_RequestSoftwareInputPanel:
+ ret = RSIP_OnMouseClickAndAlreadyFocused;
+ break;
default:
ret = 0;
break;
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp
index 81284827f6..42be96293e 100644
--- a/src/gui/styles/qs60style.cpp
+++ b/src/gui/styles/qs60style.cpp
@@ -2312,6 +2312,9 @@ int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
case SH_UnderlineShortcut:
retValue = 0;
break;
+ case SH_RequestSoftwareInputPanel:
+ retValue = RSIP_OnMouseClickAndAlreadyFocused;
+ break;
default:
break;
}
diff --git a/src/gui/styles/qstyle.cpp b/src/gui/styles/qstyle.cpp
index 598fe6b76b..f93010711d 100644
--- a/src/gui/styles/qstyle.cpp
+++ b/src/gui/styles/qstyle.cpp
@@ -1586,6 +1586,20 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
*/
/*!
+ \enum QStyle::RequestSoftwareInputPanel
+
+ This enum describes under what circumstances a software input panel will be
+ requested by input capable widgets.
+
+ \value RSIP_OnMouseClickAndAlreadyFocused Requests an input panel if the user
+ clicks on the widget, but only if it is already focused.
+ \value RSIP_OnMouseClick Requests an input panel if the user clicks on the
+ widget.
+
+ \sa QEvent::RequestSoftwareInputPanel, QInputContext
+*/
+
+/*!
\enum QStyle::StyleHint
This enum describes the available style hints. A style hint is a general look
@@ -1868,6 +1882,9 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_ToolButtonStyle Determines the default system style for tool buttons that uses Qt::ToolButtonFollowStyle.
+ \value SH_RequestSoftwareInputPanel Determines when a software input panel should
+ be requested by input widgets. Returns an enum of type QStyle::RequestSoftwareInputPanel.
+
\omitvalue SH_UnderlineAccelerator
\sa styleHint()
diff --git a/src/gui/styles/qstyle.h b/src/gui/styles/qstyle.h
index f22bf55a63..4d179348ce 100644
--- a/src/gui/styles/qstyle.h
+++ b/src/gui/styles/qstyle.h
@@ -632,6 +632,11 @@ public:
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt,
const QSize &contentsSize, const QWidget *w = 0) const = 0;
+ enum RequestSoftwareInputPanel {
+ RSIP_OnMouseClickAndAlreadyFocused,
+ RSIP_OnMouseClick
+ };
+
enum StyleHint {
SH_EtchDisabledText,
SH_DitherDisabledText,
@@ -731,6 +736,7 @@ public:
SH_TabBar_CloseButtonPosition,
SH_DockWidget_ButtonsHaveFrame,
SH_ToolButtonStyle,
+ SH_RequestSoftwareInputPanel,
// Add new style hint values here
#ifdef QT3_SUPPORT
diff --git a/src/gui/styles/qwindowscestyle.cpp b/src/gui/styles/qwindowscestyle.cpp
index 997fc722f1..0572ba13c1 100644
--- a/src/gui/styles/qwindowscestyle.cpp
+++ b/src/gui/styles/qwindowscestyle.cpp
@@ -2291,6 +2291,9 @@ int QWindowsCEStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QW
break;
case SH_EtchDisabledText:
ret = false;
+ case SH_RequestSoftwareInputPanel:
+ ret = RSIP_OnMouseClick;
+ break;
default:
ret = QWindowsStyle::styleHint(hint, opt, widget, returnData);
break;
diff --git a/src/gui/styles/qwindowsmobilestyle.cpp b/src/gui/styles/qwindowsmobilestyle.cpp
index c70b4c83f2..18d733a8c4 100644
--- a/src/gui/styles/qwindowsmobilestyle.cpp
+++ b/src/gui/styles/qwindowsmobilestyle.cpp
@@ -3404,6 +3404,9 @@ int QWindowsMobileStyle::styleHint(StyleHint hint, const QStyleOption *opt, cons
case SH_MenuBar_AltKeyNavigation:
ret = false;
break;
+ case SH_RequestSoftwareInputPanel:
+ ret = RSIP_OnMouseClick;
+ break;
default:
ret = QWindowsStyle::styleHint(hint, opt, widget, returnData);
break;
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index cd9666df00..5dabd98716 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -1494,11 +1494,7 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e)
}
#endif
- if (e->button() == Qt::LeftButton && qApp->autoSipEnabled()
- && (!d->clickCausedFocus || qApp->autoSipOnMouseFocus())) {
- QEvent event(QEvent::RequestSoftwareInputPanel);
- QApplication::sendEvent(this, &event);
- }
+ d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
d->clickCausedFocus = 0;
}
diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp
index 7d9d2b5bb0..7f71d1e013 100644
--- a/src/gui/widgets/qplaintextedit.cpp
+++ b/src/gui/widgets/qplaintextedit.cpp
@@ -1932,11 +1932,7 @@ void QPlainTextEdit::mouseReleaseEvent(QMouseEvent *e)
d->ensureCursorVisible();
}
- if (e->button() == Qt::LeftButton && qApp->autoSipEnabled()
- && (!d->clickCausedFocus || qApp->autoSipOnMouseFocus())) {
- QEvent event(QEvent::RequestSoftwareInputPanel);
- QApplication::sendEvent(this, &event);
- }
+ d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
d->clickCausedFocus = 0;
}
diff --git a/src/gui/widgets/qtextedit.cpp b/src/gui/widgets/qtextedit.cpp
index 57f43c6f96..d6c74d8d43 100644
--- a/src/gui/widgets/qtextedit.cpp
+++ b/src/gui/widgets/qtextedit.cpp
@@ -1569,11 +1569,7 @@ void QTextEdit::mouseReleaseEvent(QMouseEvent *e)
d->autoScrollTimer.stop();
ensureCursorVisible();
}
- if (e->button() == Qt::LeftButton && qApp->autoSipEnabled()
- && (!d->clickCausedFocus || qApp->autoSipOnMouseFocus())) {
- QEvent event(QEvent::RequestSoftwareInputPanel);
- QApplication::sendEvent(this, &event);
- }
+ d->handleSoftwareInputPanel(e->button(), d->clickCausedFocus);
d->clickCausedFocus = 0;
}
diff --git a/tests/auto/qinputcontext/tst_qinputcontext.cpp b/tests/auto/qinputcontext/tst_qinputcontext.cpp
index 1ab950e885..05f79e582a 100644
--- a/tests/auto/qinputcontext/tst_qinputcontext.cpp
+++ b/tests/auto/qinputcontext/tst_qinputcontext.cpp
@@ -47,6 +47,7 @@
#include <qplaintextedit.h>
#include <qlayout.h>
#include <qradiobutton.h>
+#include <qwindowsstyle.h>
class tst_QInputContext : public QObject
{
@@ -122,8 +123,37 @@ void tst_QInputContext::filterMouseEvents()
le.setInputContext(0);
}
+class RequestSoftwareInputPanelStyle : public QWindowsStyle
+{
+public:
+ RequestSoftwareInputPanelStyle()
+ : m_rsipBehavior(RSIP_OnMouseClickAndAlreadyFocused)
+ {
+ }
+ ~RequestSoftwareInputPanelStyle()
+ {
+ }
+
+ int styleHint(StyleHint hint, const QStyleOption *opt = 0,
+ const QWidget *widget = 0, QStyleHintReturn* returnData = 0) const
+ {
+ if (hint == SH_RequestSoftwareInputPanel) {
+ return m_rsipBehavior;
+ } else {
+ return QWindowsStyle::styleHint(hint, opt, widget, returnData);
+ }
+ }
+
+ RequestSoftwareInputPanel m_rsipBehavior;
+};
+
void tst_QInputContext::requestSoftwareInputPanel()
{
+ QStyle *oldStyle = qApp->style();
+ oldStyle->setParent(this); // Prevent it being deleted.
+ RequestSoftwareInputPanelStyle *newStyle = new RequestSoftwareInputPanelStyle;
+ qApp->setStyle(newStyle);
+
QWidget w;
QLayout *layout = new QVBoxLayout;
QLineEdit *le1, *le2;
@@ -143,13 +173,13 @@ void tst_QInputContext::requestSoftwareInputPanel()
QApplication::setActiveWindow(&w);
// Testing single click panel activation.
- qApp->setAutoSipOnMouseFocus(true);
+ newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClick;
QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
QVERIFY(ic2->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) >= 0);
ic2->lastTypes.clear();
// Testing double click panel activation.
- qApp->setAutoSipOnMouseFocus(false);
+ newStyle->m_rsipBehavior = QStyle::RSIP_OnMouseClickAndAlreadyFocused;
QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0);
QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
@@ -159,6 +189,9 @@ void tst_QInputContext::requestSoftwareInputPanel()
// Testing right mouse button
QTest::mouseClick(le1, Qt::RightButton, Qt::NoModifier, QPoint(5, 5));
QVERIFY(ic1->lastTypes.indexOf(QEvent::RequestSoftwareInputPanel) < 0);
+
+ qApp->setStyle(oldStyle);
+ oldStyle->setParent(qApp);
}
void tst_QInputContext::closeSoftwareInputPanel()