QMapControl  0.9.7.4
mapcontrol.h
1 /*
2 *
3 * This file is part of QMapControl,
4 * an open-source cross-platform map widget
5 *
6 * Copyright (C) 2007 - 2008 Kai Winter
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with QMapControl. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * Contact e-mail: kaiwinter@gmx.de
22 * Program URL : http://qmapcontrol.sourceforge.net/
23 *
24 */
25 
26 #ifndef MAPCONTROL_H
27 #define MAPCONTROL_H
28 
29 #include "qmapcontrol_global.h"
30 #include "layermanager.h"
31 #include "layer.h"
32 #include "mapadapter.h"
33 #include "geometry.h"
34 #include "imagemanager.h"
35 
36 #include <QWidget>
37 
39 namespace qmapcontrol
40 {
41  class LayerManager;
42  class MapAdapter;
43  class Layer;
44 
46 
54  class QMAPCONTROL_EXPORT MapControl : public QWidget
55  {
56  Q_OBJECT
57 
58  public:
60  enum MouseMode
61  {
64  None
65  };
66 
68 
72  MapControl (QWidget * parent = 0, Qt::WindowFlags windowFlags = 0);
73 
75 
89  MapControl ( QSize size, MouseMode mousemode = Panning, bool showScale = false, bool showCrosshairs = true, QWidget * parent = 0, Qt::WindowFlags windowFlags = 0);
90 
91  ~MapControl();
92 
94 
98  void addLayer ( Layer* layer );
99 
101 
105  void removeLayer ( Layer* layer );
106 
108 
112  Layer* layer ( const QString& layername ) const;
113 
115 
118  QList<QString> layers() const;
119 
121 
124  int numberOfLayers() const;
125 
127 
130  QPointF currentCoordinate() const;
131 
133 
136  int currentZoom() const;
137 
139  void updateView() const;
140 
142 
145  void enableMouseWheelEvents( bool enabled = true );
146 
148 
151  bool mouseWheelEventsEnabled();
152 
154 
157  void setView ( const QPointF& coordinate ) const;
158 
160 
163  void setView ( const QList<QPointF> coordinates ) const;
164 
166 
171  void setViewAndZoomIn ( const QList<QPointF> coordinates ) const;
172 
174 
178  void setView ( const Point* point ) const;
179 
181 
185  void followGeometry ( const Geometry* geometry ) const;
186 
187  //TODO:
188  // void followGeometry(const QList<Geometry*>) const;
189 
191 
196  void stopFollowing ( const Geometry* geometry ) const;
197 
199 
202  void moveTo ( QPointF coordinate );
203 
205 
213  void setMouseMode ( MouseMode mousemode );
214 
216 
220  MapControl::MouseMode mouseMode();
221 
222  //int rotation;
223 
225 
233  void enablePersistentCache ( int tileExpiry = -1, const QDir& path= QDir::homePath() + "/QMapControl.cache" );
234 
236 
244  void setProxy(QString host, int port, const QString username = QString(), const QString password = QString());
245 
247 
251  void showScale ( bool visible );
252 
253  void showCrosshairs ( bool visible );
254 
256 
260  void setUseBoundingBox( bool usebounds );
261 
263 
267  bool isBoundingBoxEnabled();
268 
270 
274  void setBoundingBox( QRectF &rect );
275 
277 
281  QRectF getBoundingBox();
282 
284 
288  QRectF getViewport();
289 
291 
296  bool isGeometryVisible( Geometry * geometry);
297 
299 
303  int loadingQueueSize();
304 
305  private:
306  LayerManager* layermanager;
307  QPoint screen_middle; // middle of the widget (half size)
308 
309  QPoint pre_click_px; // used for scrolling (MouseMode Panning)
310  QPoint current_mouse_pos; // used for scrolling and dragging (MouseMode Panning/Dragging)
311 
312  QSize size; // size of the widget
313 
314  bool mouse_wheel_events;
315  bool mousepressed;
316  MouseMode mymousemode;
317  bool scaleVisible;
318  bool crosshairsVisible;
319 
320  bool m_loadingFlag;
321 
322  QMutex moveMutex; // used for method moveTo()
323  QPointF target; // used for method moveTo()
324  int steps; // used for method moveTo()
325 
326  QPointF clickToWorldCoordinate ( QPoint click );
327 
328  Q_DISABLE_COPY( MapControl )
329 
330  protected:
331  void paintEvent ( QPaintEvent* evnt );
332  void mousePressEvent ( QMouseEvent* evnt );
333  void mouseReleaseEvent ( QMouseEvent* evnt );
334  void mouseMoveEvent ( QMouseEvent* evnt );
335  void wheelEvent( QWheelEvent* evnt );
336 
337  signals:
338  // void mouseEvent(const QMouseEvent* evnt);
339 
341 
348  void mouseEventCoordinate ( const QMouseEvent* evnt, const QPointF coordinate );
349 
351 
356  void boxDragged ( const QRectF );
357 
359 
363  void geometryClicked ( Geometry* geometry, QPoint coord_px );
364 
366 
370  void viewChanged ( const QPointF &coordinate, int zoom ) const;
371 
372  public slots:
374  void zoomIn();
375 
377  void zoomOut();
378 
380 
383  void setZoom ( int zoomlevel );
384 
386  void scrollLeft ( int pixel=10 );
387 
389  void scrollRight ( int pixel=10 );
390 
392  void scrollUp ( int pixel=10 );
393 
395  void scrollDown ( int pixel=10 );
396 
398  void scroll ( const QPoint scroll );
399 
401 
404  void updateRequest ( QRect rect );
405 
407 
410  void updateRequestNew();
411 
413 
416  void resize(const QSize newSize);
417 
418  private slots:
419  void tick();
420  void loadingFinished();
421  void positionChanged ( Geometry* geom );
422 
423  };
424 }
425 #endif
Main class for objects that should be painted in maps.
Definition: geometry.h:48
MouseMode
Declares what actions mouse movements have on the map.
Definition: mapcontrol.h:60
Definition: mapcontrol.h:63
The control element of the widget and also the widget itself.
Definition: mapcontrol.h:54
A geometric point to draw objects into maps.
Definition: point.h:66
Layer class.
Definition: layer.h:60
Definition: mapcontrol.h:62
QMapControl namespace.
Definition: arrowpoint.cpp:28