version 2.13.0
add Map library (MapView with OSM maps and items) and mapviewer util
This commit is contained in:
104
libs/map/mapview.h
Normal file
104
libs/map/mapview.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef mapview_h
|
||||
#define mapview_h
|
||||
|
||||
#include "mapitembase.h"
|
||||
#include "qad_map_export.h"
|
||||
|
||||
#include <QImage>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class OSMDownloader;
|
||||
class OSMTileCache;
|
||||
|
||||
class QAD_MAP_EXPORT MapView: public QWidget {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPointF center READ center WRITE setCenter)
|
||||
Q_PROPERTY(double zoom READ getZoom WRITE setZoom)
|
||||
|
||||
friend class OSMDownloader;
|
||||
friend class OSMTileCache;
|
||||
friend class MapItemBase;
|
||||
|
||||
public:
|
||||
explicit MapView(QWidget * parent = 0);
|
||||
~MapView();
|
||||
|
||||
void addItem(MapItemBase * item);
|
||||
void removeItem(MapItemBase * item);
|
||||
|
||||
QPointF center() const;
|
||||
void setCenter(QPointF c);
|
||||
|
||||
double getZoom() const { return zoom_; }
|
||||
void setZoom(double z);
|
||||
|
||||
private:
|
||||
QSize sizeHint() const override { return QSize(200, 200); }
|
||||
void mousePressEvent(QMouseEvent * e) override;
|
||||
void mouseReleaseEvent(QMouseEvent * e) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent * e) override;
|
||||
void mouseMoveEvent(QMouseEvent * e) override;
|
||||
void wheelEvent(QWheelEvent * e) override;
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
void resizeEvent(QResizeEvent *) override;
|
||||
void drawBackground();
|
||||
void drawItems(QPainter & p);
|
||||
void checkZoom();
|
||||
void zoomLevelChanged(int new_level);
|
||||
void updateZoomLevel();
|
||||
void updateViewRect();
|
||||
void updateMouse(QPoint mouse);
|
||||
double scalePx2M(QPointF norm);
|
||||
|
||||
QPointF mapToNorm(QPoint screen) const;
|
||||
QPoint mapFromNorm(QPointF norm) const;
|
||||
|
||||
OSMDownloader * downloader = nullptr;
|
||||
OSMTileCache * cache = nullptr;
|
||||
MapItemBase * hover = nullptr;
|
||||
QPointF center_ = QPointF(0.5, 0.5);
|
||||
QPoint press_point;
|
||||
QPixmap background;
|
||||
QRectF view_rect;
|
||||
QVector<MapItemBase *> items_;
|
||||
QBrush brush_tr;
|
||||
bool is_pan = false;
|
||||
double zoom_ = 1., scale_ = 1., px2m = 1.;
|
||||
int zoom_level = 0, tiles_side = 1, max_level = 19;
|
||||
|
||||
public slots:
|
||||
void zoom(double factor);
|
||||
void zoom(double factor, QPoint anchor);
|
||||
void zoomTo(double level);
|
||||
void centerTo(QPointF coord);
|
||||
|
||||
private slots:
|
||||
|
||||
signals:
|
||||
void itemClicked(MapItemBase * item);
|
||||
void itemEntered(MapItemBase * item);
|
||||
void itemLeaved(MapItemBase * item);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user