1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include <QtVirtualKeyboard/private/inputselectionhandle_p.h>
5#include <QtVirtualKeyboard/private/desktopinputselectioncontrol_p.h>
6
7#include <QtCore/qcoreapplication.h>
8#include <QtGui/QPainter>
9
10QT_BEGIN_NAMESPACE
11namespace QtVirtualKeyboard {
12InputSelectionHandle::InputSelectionHandle(DesktopInputSelectionControl *control, QWindow *eventWindow)
13 : QRasterWindow()
14 , m_control(control)
15 , m_eventWindow(eventWindow)
16{
17 setFlags(Qt::ToolTip |
18 Qt::FramelessWindowHint |
19 Qt::WindowStaysOnTopHint |
20 Qt::WindowDoesNotAcceptFocus);
21
22 QSurfaceFormat format;
23 format.setAlphaBufferSize(8);
24 setFormat(format);
25}
26
27void InputSelectionHandle::applyImage(const QSize &windowSize)
28{
29 resize(newSize: windowSize);
30 update(); // update paint device in case resize() did not resize.
31}
32
33void InputSelectionHandle::paintEvent(QPaintEvent *pe)
34{
35 Q_UNUSED(pe);
36 QPainter painter(this);
37
38 Q_ASSERT(m_control);
39 QImage *img = m_control->handleImage();
40 const QSize szDelta = size() - img->size();
41 // center image onto window
42 painter.drawImage(p: QPoint(szDelta.width(), szDelta.height())/2, image: *img);
43}
44
45bool InputSelectionHandle::event(QEvent *e)
46{
47 switch (e->type())
48 {
49 case QEvent::MouseButtonPress:
50 case QEvent::MouseButtonRelease:
51 case QEvent::MouseMove:
52 return QCoreApplication::sendEvent(receiver: m_eventWindow, event: e);
53 default:
54 break;
55 }
56 return QRasterWindow::event(event: e);
57}
58
59} // namespace QtVirtualKeyboard
60QT_END_NAMESPACE
61

source code of qtvirtualkeyboard/src/virtualkeyboard/inputselectionhandle.cpp