Changeset View
Changeset View
Standalone View
Standalone View
examples/cpp/custom-layers/main.cpp
Show All 23 Lines | |||||
24 | 24 | | |||
25 | class MyPaintLayer : public QObject, public LayerInterface | 25 | class MyPaintLayer : public QObject, public LayerInterface | ||
26 | { | 26 | { | ||
27 | public: | 27 | public: | ||
28 | // Constructor | 28 | // Constructor | ||
29 | MyPaintLayer(MarbleWidget* widget); | 29 | MyPaintLayer(MarbleWidget* widget); | ||
30 | 30 | | |||
31 | // Implemented from LayerInterface | 31 | // Implemented from LayerInterface | ||
32 | virtual QStringList renderPosition() const; | 32 | RenderPositions renderPositions() const override; | ||
33 | 33 | | |||
34 | // Implemented from LayerInterface | 34 | // Implemented from LayerInterface | ||
35 | virtual bool render( GeoPainter *painter, ViewportParams *viewport, | 35 | bool render(GeoPainter *painter, ViewportParams *viewport, | ||
36 | const QString& renderPos = "NONE", GeoSceneLayer * layer = 0 ); | 36 | RenderPosition renderPos, GeoSceneLayer *layer) override; | ||
37 | 37 | | |||
38 | // Overriding QObject | 38 | // Overriding QObject | ||
39 | virtual bool eventFilter(QObject *obj, QEvent *event); | 39 | virtual bool eventFilter(QObject *obj, QEvent *event); | ||
40 | 40 | | |||
41 | static GeoDataCoordinates approximate(const GeoDataCoordinates &base, qreal angle, qreal dist); | 41 | static GeoDataCoordinates approximate(const GeoDataCoordinates &base, qreal angle, qreal dist); | ||
42 | 42 | | |||
43 | private: | 43 | private: | ||
44 | MarbleWidget* m_widget; | 44 | MarbleWidget* m_widget; | ||
45 | 45 | | |||
46 | QHash<RenderPosition, QString> m_renderPositions; | ||||
46 | int m_index; | 47 | int m_index; | ||
47 | }; | 48 | }; | ||
48 | 49 | | |||
49 | MyPaintLayer::MyPaintLayer(MarbleWidget* widget) : m_widget(widget), m_index(0) | 50 | MyPaintLayer::MyPaintLayer(MarbleWidget* widget) : m_widget(widget), m_index(0) | ||
50 | { | 51 | { | ||
51 | // nothing to do | | |||
52 | } | | |||
53 | | ||||
54 | QStringList MyPaintLayer::renderPosition() const | | |||
55 | { | | |||
56 | // We will paint in exactly one of the following layers. | 52 | // We will paint in exactly one of the following layers. | ||
57 | // The current one can be changed by pressing the '+' key | 53 | // The current one can be changed by pressing the '+' key | ||
58 | QStringList layers = QStringList() << "SURFACE" << "HOVERS_ABOVE_SURFACE"; | 54 | m_renderPositions.insert(SurfaceRenderPosition, "SURFACE"); | ||
59 | layers << "ORBIT" << "USER_TOOLS" << "STARS"; | 55 | m_renderPositions.insert(HoversAboveSurfaceRenderPosition, "HOVERS_ABOVE_SURFACE"); | ||
56 | m_renderPositions.insert(OrbitRenderPosition, "ORBIT"); | ||||
57 | m_renderPositions.insert(UserToolsRenderPosition, "USER_TOOLS"); | ||||
58 | m_renderPositions.insert(StarsRenderPosition, "STARS"); | ||||
60 | 59 | | |||
61 | int index = m_index % layers.size(); | 60 | } | ||
62 | return QStringList() << layers.at(index); | 61 | | ||
62 | RenderPositions MyPaintLayer::renderPositions() const | ||||
63 | { | ||||
64 | int index = m_index % m_renderPositions.size(); | ||||
65 | return m_renderPositions.keys().at(index); | ||||
63 | } | 66 | } | ||
64 | 67 | | |||
65 | bool MyPaintLayer::eventFilter(QObject *obj, QEvent *event) | 68 | bool MyPaintLayer::eventFilter(QObject *obj, QEvent *event) | ||
66 | { | 69 | { | ||
67 | Q_UNUSED(obj) | 70 | Q_UNUSED(obj) | ||
68 | 71 | | |||
69 | // Adjust the current layer when '+' is pressed | 72 | // Adjust the current layer when '+' is pressed | ||
70 | if (event->type() == QEvent::KeyPress) | 73 | if (event->type() == QEvent::KeyPress) | ||
Show All 12 Lines | |||||
83 | { | 86 | { | ||
84 | // This is just a rough estimation that ignores projections. | 87 | // This is just a rough estimation that ignores projections. | ||
85 | // It only works for short distances. Don't use in real code. | 88 | // It only works for short distances. Don't use in real code. | ||
86 | GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree; | 89 | GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree; | ||
87 | return GeoDataCoordinates ( base.longitude(deg) + 1.5 * dist * sin(angle), | 90 | return GeoDataCoordinates ( base.longitude(deg) + 1.5 * dist * sin(angle), | ||
88 | base.latitude(deg) + dist * cos(angle), 0.0, deg); | 91 | base.latitude(deg) + dist * cos(angle), 0.0, deg); | ||
89 | } | 92 | } | ||
90 | 93 | | |||
91 | bool MyPaintLayer::render( GeoPainter *painter, ViewportParams *viewport, | 94 | bool MyPaintLayer::render(GeoPainter *painter, ViewportParams *viewport, | ||
92 | const QString& renderPos, GeoSceneLayer * layer ) | 95 | RenderPosition renderPos, GeoSceneLayer * layer) | ||
93 | { | 96 | { | ||
94 | Q_UNUSED(viewport) | 97 | Q_UNUSED(viewport) | ||
95 | Q_UNUSED(renderPos) | 98 | Q_UNUSED(renderPos) | ||
96 | Q_UNUSED(layer) | 99 | Q_UNUSED(layer) | ||
97 | 100 | | |||
98 | // Have window title reflect the current paint layer | 101 | // Have window title reflect the current paint layer | ||
99 | m_widget->setWindowTitle(renderPosition().first()); | 102 | m_widget->setWindowTitle(m_renderPositions.value(renderPos)); | ||
100 | GeoDataCoordinates home(8.4, 48.0, 0.0, GeoDataCoordinates::Degree); | 103 | GeoDataCoordinates home(8.4, 48.0, 0.0, GeoDataCoordinates::Degree); | ||
101 | QTime now = QTime::currentTime(); | 104 | QTime now = QTime::currentTime(); | ||
102 | 105 | | |||
103 | painter->setRenderHint(QPainter::Antialiasing, true); | 106 | painter->setRenderHint(QPainter::Antialiasing, true); | ||
104 | 107 | | |||
105 | // Large circle built by 60 small circles | 108 | // Large circle built by 60 small circles | ||
106 | painter->setPen( QPen(QBrush(QColor::fromRgb(255,255,255,200)), 3.0, Qt::SolidLine, Qt::RoundCap ) ); | 109 | painter->setPen( QPen(QBrush(QColor::fromRgb(255,255,255,200)), 3.0, Qt::SolidLine, Qt::RoundCap ) ); | ||
107 | for (int i=0; i<60; ++i) | 110 | for (int i=0; i<60; ++i) | ||
Show All 40 Lines |