1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 //
3 // SPDX-FileCopyrightText: 2005-2007 Torsten Rahn <tackat@kde.org>
4 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
5 //
6 
7 //
8 // Testapplication with controls
9 //
10 
11 
12 #ifndef MARBLE_CONTROLVIEW_H
13 #define MARBLE_CONTROLVIEW_H
14 
15 
16 #include <QWidget>
17 #include <QPointer>
18 
19 #include "MarbleWidget.h"
20 
21 class QPrintDialog;
22 class QTextDocument;
23 class QMainWindow;
24 class QDockWidget;
25 class QPrinter;
26 class QActionGroup;
27 class QPixmap;
28 
29 namespace Marble
30 {
31 
32 class TourWidget;
33 class CurrentLocationWidget;
34 class MapThemeManager;
35 class ConflictDialog;
36 class MarbleModel;
37 class MergeItem;
38 class CloudSyncManager;
39 
40 class ControlView : public QWidget
41 {
42     Q_OBJECT
43 
44  public:
45     explicit ControlView( QWidget * = nullptr );
46     ~ControlView() override;
47 
48     /**
49       * Returns the version of the Marble applications (which differs from
50       * the Marble library version).
51       */
52     static QString applicationVersion();
53 
marbleWidget()54     MarbleWidget      *marbleWidget()        { return m_marbleWidget; }
marbleModel()55     MarbleModel       *marbleModel()         { return m_marbleWidget->model(); }
56     MapThemeManager   *mapThemeManager();
57 
58     void zoomIn();
59     void zoomOut();
60     void moveLeft();
61     void moveRight();
62     void moveUp();
63     void moveDown();
64 
65     void addGeoDataFile( const QString &filename );
66 
mapScreenShot()67     QPixmap mapScreenShot() { return m_marbleWidget->mapScreenShot(); }
68 
69     /**
70       * Returns a default map theme: earth/srtm/srtm.dgml if installed,
71       * any other theme id if earth/srtm/srtm.dgml is not installed,
72       * or an empty string if no themes are installed at all
73       */
74     QString defaultMapThemeId() const;
75 
76     /**
77       * Returns the editor used to launch a map editor application
78       */
79     QString externalMapEditor() const;
80 
81     /**
82       * Change the editor to launch via @see launchExternalMapEditor. Recognized values
83       * are 'potlatch', 'josm', 'merkaartor'
84       */
85     void setExternalMapEditor( const QString &editor );
86 
87     QList<QAction*> setupDockWidgets( QMainWindow* mainWindow );
88 
89     CurrentLocationWidget* currentLocationWidget();
90 
91     void setWorkOffline( bool workOffline );
92 
93     CloudSyncManager* cloudSyncManager();
94 
95     /**
96      * Opens the passed Geo URI
97      * @return true if uri could be parsed and opened
98      * @see Marble::GeoUriParser for details
99      */
100     bool openGeoUri( const QString& geoUriString );
101 
102     static QActionGroup* createViewSizeActionGroup( QObject* parent );
103 
104  public Q_SLOTS:
105     void printMapScreenShot( const QPointer<QPrintDialog>& dialog );
106     void printPreview();
107     void paintPrintPreview( QPrinter * printer );
108 
109     /**
110       * Start the configured external map editor (or update it if it is already running)
111       */
112     void launchExternalMapEditor();
113 
114     /**
115      *  Toggles all of the docking panels on or off
116      */
117     void togglePanelVisibility();
118 
119     void handleTourLinkClicked( const QString &path );
120 
121     void openTour( const QString &filename );
122 
123 Q_SIGNALS:
124     void showMapWizard();
125     void mapThemeDeleted();
126 
127 protected:
128     void closeEvent( QCloseEvent *event ) override;
129     /**
130      * @brief Reimplementation of the dragEnterEvent() function in QWidget.
131      */
132     void dragEnterEvent(QDragEnterEvent *event) override;
133 
134     /**
135      * @brief Reimplementation of the dropEvent() function in QWidget.
136      */
137     void dropEvent(QDropEvent *event) override;
138 
139 private Q_SLOTS:
140     void showSearch();
141     // Bookmark sync slots
142     void showConflictDialog( MergeItem *item );
143     void updateAnnotationDockVisibility();
144     void updateAnnotationDock();
145 
146  private:
147     /**
148       * Try to reach an external application server at localhost:8111. If none is running,
149       * start the given application
150       * @param application Executable to start when no server is running
151       * @param argument Argument to set the download region for the external application.
152       * Use placeholders %1-%4 for the borders
153       */
154     void synchronizeWithExternalMapEditor( const QString &application, const QString &argument );
155 
156     static void printPixmap( QPrinter * printer, const QPixmap& pixmap );
157     void printMap( QTextDocument &document, QString &text, QPrinter *printer );
158     void printLegend( QTextDocument &document, QString &text );
159     void printRouteSummary( QTextDocument &document, QString &text );
160     void printDrivingInstructions( QTextDocument &document, QString &text );
161     static void printDrivingInstructionsAdvice( QTextDocument &document, QString &text );
162     static void addViewSizeAction( QActionGroup* actionGroup, const QString &nameTemplate, int width, int height );
163 
164     MapThemeManager   *const m_mapThemeManager;
165     MarbleWidget      *m_marbleWidget;
166     QString            m_externalEditor;
167     QDockWidget       *m_searchDock;
168     CurrentLocationWidget* m_locationWidget;
169     ConflictDialog *m_conflictDialog;
170     CloudSyncManager *m_cloudSyncManager;
171     QAction         *m_togglePanelVisibilityAction;
172     QList<QAction*>  m_panelActions;
173     QList<bool>      m_panelVisibility;
174     bool             m_isPanelVisible;
175     TourWidget      *m_tourWidget;
176     QDockWidget     *m_annotationDock;
177     RenderPlugin    *m_annotationPlugin;
178 };
179 
180 }
181 
182 #endif
183