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/tools/ToolMapGrid.h
2016-06-06 22:08:53 +02:00

83 lines
1.5 KiB
C++

#ifndef TOOLMAPGRID_H
#define TOOLMAPGRID_H
#include "Tool.h"
class ToolMapGrid : public Tool {
private:
bool show = true;
public:
virtual void keyPressEvent(MapView2D* m, QKeyEvent* e) {
(void) m;
if (e->key() == Qt::Key_NumberSign) { show = !show; }
}
void paintBefore(MapView2D* m, Painter& p) override {
(void) m;
if (!show) {return;}
static const QColor cB(250,250,250);
static const QColor cN(235,235,235);
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