Debian Codegraph @

tests/unit/custom_qpa/qcustomintegration.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** In addition, as a special exception, Digia gives you certain additional
27 ** rights. These rights are described in the Digia Qt LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** $QT_END_LICENSE$
31 **
32 ****************************************************************************/
33
34 #include "qcustomintegration.h"
35
36 #include <QtGui/qpa/qplatformfontdatabase.h>
37 #include <QtGui/qpa/qplatformnativeinterface.h>
38 #include <QtGui/qpa/qplatformwindow.h>
39 #include <QtGui/private/qguiapplication_p.h>
40 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
41 #include <QtGui/private/qgenericunixeventdispatcher_p.h>
42 #else
43 #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h>
44 #endif
45
46 #include "qcustombackingstore.h"
47
48 static const char devicePixelRatioEnvironmentVariable[] = "QT_DEVICE_PIXEL_RATIO";
49
50 class QCustomNativeInterface : public QPlatformNativeInterface
51 {
52 Q_OBJECT
53 public:
54 QVariant windowProperty(QPlatformWindow */*window*/, const QString &name) const override
55 {
56 if (name == QStringLiteral("scale"))
57 return m_scale;
58
59 return QVariant();
60 }
61
62 Q_INVOKABLE void changeScale(float scale)
63 {
64 m_scale = scale;
65 Q_EMIT windowPropertyChanged(nullptr, "scale");
66 }
67
68 private:
69 float m_scale = 1;
70 };
71
72 QCustomScreen::QCustomScreen()
73 : mDepth(32), mFormat(QImage::Format_ARGB32_Premultiplied), mDpr(1.0)
74 {
75 if (qEnvironmentVariableIsSet(devicePixelRatioEnvironmentVariable)) {
76 bool ok = false;
77 const float dpr = qgetenv(devicePixelRatioEnvironmentVariable).toFloat(&ok);
78 if (ok && dpr > 0) {
79 mDpr = dpr;
80 }
81 }
82 }
83
84 QCustomIntegration::QCustomIntegration()
85 : m_nativeInterface(new QCustomNativeInterface())
86 {
87 QCustomScreen *mPrimaryScreen = new QCustomScreen();
88
89 mPrimaryScreen->mGeometry = QRect(0, 0, 240, 320);
90 mPrimaryScreen->mDepth = 32;
91 mPrimaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied;
92
93 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
94 QWindowSystemInterface::handleScreenAdded(mPrimaryScreen);
95 #else
96 screenAdded(mPrimaryScreen);
97 #endif
98 }
99
100 QCustomIntegration::~QCustomIntegration()
101 {
102 delete m_nativeInterface;
103 }
104
105 bool QCustomIntegration::hasCapability(QPlatformIntegration::Capability cap) const
106 {
107 switch (cap) {
108 case ThreadedPixmaps: return true;
109 case MultipleWindows: return true;
110 default: return QPlatformIntegration::hasCapability(cap);
111 }
112 }
113
114 // Dummy font database that does not scan the fonts directory to be
115 // used for command line tools like qmlplugindump that do not create windows
116 // unless DebugBackingStore is activated.
117 class DummyFontDatabase : public QPlatformFontDatabase
118 {
119 public:
120 void populateFontDatabase() override {}
121 };
122
123 QPlatformFontDatabase *QCustomIntegration::fontDatabase() const
124 {
125 return new DummyFontDatabase;
126 }
127
128 QPlatformNativeInterface *QCustomIntegration::nativeInterface() const
129 {
130 return m_nativeInterface;
131 }
132
133 QPlatformWindow *QCustomIntegration::createPlatformWindow(QWindow *window) const
134 {
135 QPlatformWindow *w = new QPlatformWindow(window);
136 w->requestActivateWindow();
137 return w;
138 }
139
140 QPlatformBackingStore *QCustomIntegration::createPlatformBackingStore(QWindow *window) const
141 {
142 return new QCustomBackingStore(window);
143 }
144
145 QAbstractEventDispatcher *QCustomIntegration::createEventDispatcher() const
146 {
147 return createUnixEventDispatcher();
148 }
149
150 QCustomIntegration *QCustomIntegration::instance()
151 {
152 return static_cast<QCustomIntegration *>(QGuiApplicationPrivate::platformIntegration());
153 }
154
155 #include "qcustomintegration.moc"