summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-03-22 16:53:18 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-03-31 03:05:41 +0000
commitf5b5e1f76dc1d317ac235007eb81d0cc01fa66d1 (patch)
treea3f008232cc9d38c9d2795c38c561bd0a73c5115 /src/plugins
parent87715cc4917e0edcc1090658ea09be508f47f3b7 (diff)
Windows QPA: Scale the cursor rectangle of the input method.
Fixes the position of the input method window when High DPI scaling is active. Task-number: QTBUG-51923 Change-Id: I35ee4bcf320f8c2b7d5cc7fb8484348b18e1d833 Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/windows/qwindowsinputcontext.cpp17
-rw-r--r--src/plugins/platforms/windows/qwindowsinputcontext.h3
2 files changed, 14 insertions, 6 deletions
diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
index d3299db460..1faa00d095 100644
--- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp
+++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
@@ -48,6 +48,8 @@
#include <QtGui/QPalette>
#include <QtGui/QGuiApplication>
+#include <private/qhighdpiscaling_p.h>
+
#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -159,7 +161,8 @@ Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id); // from qlocale_win.cpp
HIMC QWindowsInputContext::m_defaultContext = 0;
QWindowsInputContext::CompositionContext::CompositionContext() :
- hwnd(0), haveCaret(false), position(0), isComposing(false)
+ hwnd(0), haveCaret(false), position(0), isComposing(false),
+ factor(1)
{
}
@@ -270,9 +273,12 @@ void QWindowsInputContext::cursorRectChanged()
if (!m_compositionContext.hwnd)
return;
const QInputMethod *inputMethod = QGuiApplication::inputMethod();
- const QRect cursorRectangle = inputMethod->cursorRectangle().toRect();
- if (!cursorRectangle.isValid())
+ const QRectF cursorRectangleF = inputMethod->cursorRectangle();
+ if (!cursorRectangleF.isValid())
return;
+ const QRect cursorRectangle =
+ QRectF(cursorRectangleF.topLeft() * m_compositionContext.factor,
+ cursorRectangleF.size() * m_compositionContext.factor).toRect();
qCDebug(lcQpaInputMethods) << __FUNCTION__<< cursorRectangle;
@@ -390,7 +396,7 @@ bool QWindowsInputContext::startComposition(HWND hwnd)
qCDebug(lcQpaInputMethods) << __FUNCTION__ << fo << window << "language=" << m_languageId;
if (!fo || QWindowsWindow::handleOf(window) != hwnd)
return false;
- initContext(hwnd, fo);
+ initContext(hwnd, QHighDpiScaling::factor(window), fo);
startContextComposition();
return true;
}
@@ -522,12 +528,13 @@ bool QWindowsInputContext::endComposition(HWND hwnd)
return true;
}
-void QWindowsInputContext::initContext(HWND hwnd, QObject *focusObject)
+void QWindowsInputContext::initContext(HWND hwnd, qreal factor, QObject *focusObject)
{
if (m_compositionContext.hwnd)
doneContext();
m_compositionContext.hwnd = hwnd;
m_compositionContext.focusObject = focusObject;
+ m_compositionContext.factor = factor;
// Create a hidden caret which is kept at the microfocus
// position in update(). This is important for some
// Chinese input methods.
diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.h b/src/plugins/platforms/windows/qwindowsinputcontext.h
index 636d481e70..071e2c7d82 100644
--- a/src/plugins/platforms/windows/qwindowsinputcontext.h
+++ b/src/plugins/platforms/windows/qwindowsinputcontext.h
@@ -59,6 +59,7 @@ class QWindowsInputContext : public QPlatformInputContext
int position;
bool isComposing;
QPointer<QObject> focusObject;
+ qreal factor;
};
public:
explicit QWindowsInputContext();
@@ -88,7 +89,7 @@ private slots:
void cursorRectChanged();
private:
- void initContext(HWND hwnd, QObject *focusObject);
+ void initContext(HWND hwnd, qreal factor, QObject *focusObject);
void doneContext();
void startContextComposition();
void endContextComposition();