This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/2D/tools/ToolMapGrid.h
2018-10-25 12:23:40 +02:00

98 lines
2.0 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef TOOLMAPGRID_H
#define TOOLMAPGRID_H
#include "Tool.h"
class ToolMapGrid : public Tool {
private:
bool show = true;
public:
const std::string getName() const override {
return "MapGrid";
}
virtual bool keyPressEvent(MapView2D* m, QKeyEvent* e) override {
(void) m;
if (e->key() == Qt::Key_NumberSign) { show = !show; return true; }
return false;
}
void paintBefore(MapView2D* m, Painter& p) override {
(void) m;
if (!show) {return;}
static const QColor cB(245,245,245);
static const QColor cN(225,225,225);
static const QColor c0(128,128,128);
int w = p.width();
int h = p.height();
// grid-size
const float step = p.getScaler().getLODstep();
const float sStep = step/5;
// map-region visible on the screen
const Rect r = p.getScaler().getMapVisible(w, h, step);
// x-lines
for (float x = r.x0; x < r.x1; x += step) {
// major-lines (without center)
if (std::abs(x) > 0.001) {
p.setPenBrush(cN, Qt::NoBrush);
p.drawLine(x, r.y0, x, r.y1);
}
// minor-lines
p.setPenBrush(cB, Qt::NoBrush);
for (float x1 = x+sStep; x1 < x+step; x1 += sStep) {
p.drawLine(x1, r.y0, x1, r.y1);
}
}
// y-lines
for (float y = r.y0; y < r.y1; y += step) {
// major-lines (without center)
if (std::abs(y) > 0.001) {
p.setPenBrush(cN, Qt::NoBrush);
p.drawLine(r.x0, y, r.x1, y);
}
// minor-lines
p.setPenBrush(cB, Qt::NoBrush);
for (float y1 = y+sStep; y1 < y+step; y1 += sStep) {
p.drawLine(r.x0, y1, r.x1, y1);
}
}
// thick center lines
p.setPenBrush(c0, Qt::NoBrush);
p.drawLine(0, r.y0, 0, r.y1);
p.drawLine(r.x0, 0, r.x1, 0);
}
};
#endif // TOOLMAPGRID_H