File indexing completed on 2024-05-26 03:53:28

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2014 Adam Dabrowski <adamdbrw@gmail.com>
0004 //
0005 
0006 #include <QApplication>
0007 #include <QQuickView>
0008 
0009 #include <marble/declarative/MarbleQuickItem.h>
0010 #include <marble/MarbleMap.h>
0011 #include <marble/declarative/MarbleDeclarativePlugin.h>
0012 
0013 using namespace Marble;
0014 
0015 class MarbleDemoItem : public MarbleQuickItem
0016 {
0017 Q_OBJECT
0018 
0019 public:
0020     MarbleDemoItem(QQuickItem *parent = nullptr) : MarbleQuickItem(parent)
0021     {
0022         // nothing to do
0023     }
0024 
0025     void componentComplete() override
0026     {
0027         QQuickItem *pinch = findChild<QQuickItem*>(QStringLiteral("pinchArea"));
0028         if (pinch)
0029         {
0030             pinch->installEventFilter(getEventFilter());
0031         }
0032     }
0033 
0034 public Q_SLOTS:
0035 
0036     void handlePinchStart(QPointF center)
0037     {
0038         makePinch(center, Qt::GestureStarted);
0039     }
0040 
0041     void handlePinchUpdate(QPointF center, qreal scale)
0042     {
0043         makePinch(center, Qt::GestureUpdated, scale);
0044     }
0045 
0046     void handlePinchEnd(QPointF center, bool canceled)
0047     {
0048         makePinch(center, canceled ? Qt::GestureCanceled : Qt::GestureFinished);
0049     }
0050 
0051 private:
0052     void makePinch(QPointF center, Qt::GestureState state, qreal scale = 1)
0053     {
0054         scale = sqrt(sqrt(scale));
0055         scale = qBound(static_cast<qreal>(0.5), scale, static_cast<qreal>(2.0));
0056         pinch(center, scale, state);
0057     }
0058 };
0059 
0060 class MapTestWrap : public QQuickView
0061 {
0062 public:
0063     void start()
0064     {
0065         MarbleDeclarativePlugin plugin;
0066         plugin.registerTypes("org.kde.marble");
0067         qmlRegisterType<MarbleDemoItem>("org.kde.marble", 0, 20, "MarbleDemoItem");
0068         setSource(QUrl(QStringLiteral("qrc:/main.qml")));
0069 
0070         if(status()!=QQuickView::Ready)
0071             qDebug("can't initialise view");
0072 
0073         QSurfaceFormat format;
0074         format.setAlphaBufferSize(8);
0075         setFormat(format);
0076         setClearBeforeRendering(true);
0077         setColor(QColor(Qt::transparent));
0078         setTitle(QStringLiteral("Marble in QML 2.0 demo"));
0079 
0080         show();
0081     }
0082 };
0083 
0084 int main(int argc, char *argv[])
0085 {
0086     QApplication app(argc, argv);
0087 
0088     MapTestWrap test;
0089     test.start();
0090 
0091     return app.exec();
0092 }
0093 
0094 #include "main.moc"