diff --git a/abstractlayer.cpp b/abstractlayer.cpp index 9abd2a4..f4043b3 100644 --- a/abstractlayer.cpp +++ b/abstractlayer.cpp @@ -74,10 +74,12 @@ bool AbstractLayer::isVisible() const void AbstractLayer::setVisible(bool visible) { m_visible = visible; + emit visibilityChanged(m_visible); } void AbstractLayer::toggleVisibility() { m_visible = !m_visible; + emit visibilityChanged(m_visible); } diff --git a/abstractlayer.h b/abstractlayer.h index b62cb9f..a946384 100644 --- a/abstractlayer.h +++ b/abstractlayer.h @@ -40,12 +40,17 @@ public: void paintLayer(QPainter *painter); - MapWidget *map() const; bool isVisible() const; + +public slots: void setVisible(bool visible = true); void toggleVisibility(); +signals: + void visibilityChanged(bool visible); + protected: + MapWidget *map() const; virtual void paint(QPainter *painter) = 0; private: diff --git a/mainwidget.cpp b/mainwidget.cpp index 44394e1..1a891b0 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -48,11 +48,11 @@ MainWidget::MainWidget(QWidget *parent) AbstractLayer *l = new TimeLayer(m_map); l->setVisible(false); - m_map->addLayer(l, 4); + m_map->addLayer(l, 4, "Time"); l = new BatteryLayer(m_map); l->setVisible(false); - m_map->addLayer(l, 4); + m_map->addLayer(l, 4, "Battery"); l = new MarkerLayer(m_map); connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString))); @@ -60,10 +60,10 @@ MainWidget::MainWidget(QWidget *parent) connect(m_markerList, SIGNAL(removeMarker(int)), l, SLOT(removeMarker(int))); connect(m_markerList, SIGNAL(markerRenamed(int, QString)), l, SLOT(renameMarker(int, QString))); l->load(QDir::homePath()+"/Maps/marker.list"); - m_map->addLayer(l, 3); + m_map->addLayer(l, 3, "Marker"); l = new GpsLayer(m_map); - m_map->addLayer(l, 1); + m_map->addLayer(l, 1, "GPS-Position"); connect(m_map, SIGNAL(close()), this, SIGNAL(close())); connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList())); @@ -93,7 +93,7 @@ void MainWidget::loadGpx(const QString &fileName) if (fileName.endsWith(".gpx")) { AbstractLayer *l = new GpxLayer(m_map); l->load(fileName); - m_map->addLayer(l, 2); + m_map->addLayer(l, 2, "GPS-Track"); } } diff --git a/mapwidget.cpp b/mapwidget.cpp index f7a2108..2289753 100644 --- a/mapwidget.cpp +++ b/mapwidget.cpp @@ -73,7 +73,8 @@ MapWidget::MapWidget(QWidget *parent) m_manager(new QNetworkAccessManager(this)), m_networkMode(false), m_copyright(), - m_layer() + m_layer(), + m_layerMenu(new QMenu(this)) { for (int x = 0; x < 100; ++x) { for (int y = 0; y < 100; ++y) { @@ -135,8 +136,14 @@ MapWidget::~MapWidget() } } -void MapWidget::addLayer(AbstractLayer *layer, int z) +void MapWidget::addLayer(AbstractLayer *layer, int z, const QString &name) { + QAction *action = new QAction(name, m_layerMenu); + action->setCheckable(true); + action->setChecked(layer->isVisible()); + connect(action, SIGNAL(triggered(bool)), layer, SLOT(setVisible(bool))); + connect(layer, SIGNAL(visibilityChanged(bool)), action, SLOT(setChecked(bool))); + m_layerMenu->addAction(action); m_layer.insertMulti(z, layer); } @@ -315,6 +322,13 @@ void MapWidget::keyPressEvent(QKeyEvent *event) } break; } + case Qt::Key_L: + { + if (event->modifiers() == Qt::NoModifier) { + m_layerMenu->popup(mapToGlobal(QPoint(0, 0))); + } + break; + } case Qt::Key_Q: case Qt::Key_Escape: { @@ -420,7 +434,7 @@ void MapWidget::paintEvent(QPaintEvent *event) } usage << "u: Show/hide user interface"; usage << "m: Add a marker"; - usage << "Alt+m: Show/hide all marker"; + usage << "l: Show/hide individual layers"; usage << "tab: Show/hide marker list"; if (m_networkMode) { usage << "d: Download tiles for visible area"; diff --git a/mapwidget.h b/mapwidget.h index 971b410..8f3507a 100644 --- a/mapwidget.h +++ b/mapwidget.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -34,7 +35,7 @@ public: MapWidget(QWidget *parent = 0); ~MapWidget(); - void addLayer(AbstractLayer *layer, int z); + void addLayer(AbstractLayer *layer, int z, const QString &name); QRectF geoRect() const; QPointF geoPos() const; @@ -95,6 +96,7 @@ private: bool m_networkMode; QString m_copyright; QMap m_layer; + QMenu *m_layerMenu; };