2
* This file is part of Maliit Plugins
4
* Copyright (C) 2012 One Laptop per Child Association
6
* Contact: maliit-discuss@lists.maliit.org
8
* Redistribution and use in source and binary forms, with or without modification,
9
* are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright notice, this list
12
* of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright notice, this list
14
* of conditions and the following disclaimer in the documentation and/or other materials
15
* provided with the distribution.
16
* Neither the name of Nokia Corporation nor the names of its contributors may be
17
* used to endorse or promote products derived from this software without specific
18
* prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
#include "logic/layout.h"
34
#include "view/renderer.h"
35
#include "view/glass.h"
38
#include <maliit/plugins/abstractwidgetssurface.h>
39
#include <maliit/plugins/abstractsurfacefactory.h>
45
using namespace MaliitKeyboard;
48
const QSize g_screen_size(200, 100);
49
bool g_create_overlay_surfaces(false);
56
: public virtual AbstractSurface
61
QGraphicsScene *m_scene;
62
QGraphicsView *m_view;
63
QGraphicsItem *m_root;
66
explicit SurfaceProbe()
71
virtual ~SurfaceProbe() {}
82
void setSize(const QSize &size)
87
QPoint relativePosition() const
92
void setRelativePosition(const QPoint &position)
97
QSharedPointer<AbstractSurface> parent() const
99
return QSharedPointer<AbstractSurface>();
102
QPoint translateEventPosition(const QPoint &event_position,
103
const QSharedPointer<AbstractSurface> &event_surface = QSharedPointer<AbstractSurface>()) const
105
Q_UNUSED(event_surface)
106
return event_position;
111
: public AbstractSurfaceFactory
114
explicit FactoryProbe() {}
115
virtual ~FactoryProbe() {}
118
QSize screenSize() const
120
return g_screen_size;
123
bool supported(AbstractSurface::Options options) const
129
QSharedPointer<AbstractSurface> create(AbstractSurface::Options options,
130
const QSharedPointer<AbstractSurface> &parent = QSharedPointer<AbstractSurface>())
134
if (not g_create_overlay_surfaces
135
&& (options & AbstractSurface::PositionOverlay)) {
136
return QSharedPointer<AbstractSurface>();
139
QSharedPointer<AbstractSurface> surface(new SurfaceProbe);
144
class GraphicsViewSurfaceProbe
145
: public SurfaceProbe, public AbstractGraphicsViewSurface
148
QGraphicsScene *m_scene;
149
QGraphicsView *m_view;
150
QGraphicsItem *m_root;
153
explicit GraphicsViewSurfaceProbe()
155
, m_scene(new QGraphicsScene)
156
, m_view(new QGraphicsView(m_scene))
157
, m_root(new QGraphicsRectItem(0))
159
m_scene->addItem(m_root);
162
virtual ~GraphicsViewSurfaceProbe() {}
164
QGraphicsScene * scene() const
169
QGraphicsView * view() const
174
QGraphicsItem * root() const
182
class GraphicsViewFactoryProbe
183
: public FactoryProbe
186
explicit GraphicsViewFactoryProbe() {}
187
virtual ~GraphicsViewFactoryProbe() {}
190
QSharedPointer<AbstractSurface> create(AbstractSurface::Options options,
191
const QSharedPointer<AbstractSurface> &parent = QSharedPointer<AbstractSurface>())
195
if (not g_create_overlay_surfaces
196
&& (options & AbstractSurface::PositionOverlay)) {
197
return QSharedPointer<AbstractSurface>();
200
QSharedPointer<AbstractSurface> surface(new GraphicsViewSurfaceProbe);
205
}} // namespace Plugins, Maliit
207
Q_DECLARE_METATYPE(Maliit::Plugins::AbstractSurfaceFactory *);
208
Q_DECLARE_METATYPE(Maliit::Plugins::FactoryProbe *);
216
Q_SLOT void initTestCase()
219
Q_SLOT void testSurfaceFactory_data()
221
using namespace Maliit::Plugins;
222
AbstractSurfaceFactory *invalid(0);
223
AbstractSurfaceFactory *probe(new FactoryProbe);
224
AbstractSurfaceFactory *specialized_probe(new GraphicsViewFactoryProbe);
226
QTest::addColumn<Maliit::Plugins::AbstractSurfaceFactory *>("factory");
227
QTest::addColumn<bool>("create_overlay_surfaces");
228
QTest::addColumn<bool>("expected_surface_valid");
230
QTest::newRow("invalid factory")
231
<< invalid << false << false;
232
QTest::newRow("invalid factory (w/ overlay surfaces)")
233
<< invalid << true << false;
235
QTest::newRow("use valid, but wrong factory probe")
236
<< probe << false << false;
237
QTest::newRow("use valid, but wrong factory probe (w/ overlay surfaces)")
238
<< probe << true << false;
240
QTest::newRow("use valid, specialized factory probe")
241
<< specialized_probe << false << true;
242
QTest::newRow("use valid, specialized factory probe (w/ overlay surfaces)")
243
<< specialized_probe << true << true;
246
Q_SLOT void testSurfaceFactory()
248
QFETCH(Maliit::Plugins::AbstractSurfaceFactory *, factory);
249
QFETCH(bool, create_overlay_surfaces);
250
QFETCH(bool, expected_surface_valid);
252
g_create_overlay_surfaces = create_overlay_surfaces;
255
renderer.setSurfaceFactory(factory);
258
glass.setSurface(renderer.surface());
259
glass.setExtendedSurface(renderer.extendedSurface());
261
Logic::Layout layout;
262
glass.addLayout(&layout);
264
QCOMPARE(not renderer.surface().isNull(), expected_surface_valid);
265
QCOMPARE(not renderer.extendedSurface().isNull(), expected_surface_valid && create_overlay_surfaces);
272
QTEST_MAIN(TestRendering)