2
// C++ Implementation: RegionMapWidget
7
// Author: Chris Browet <cbro@semperpax.com>, (C) 2008
9
// Copyright: See COPYING file that comes with this distribution
12
#include "RegionMapWidget.h"
13
#include "Utils/SlippyMapWidget.h"
15
#include "ImportExport/ImportExportOsmBin.h"
18
#include <QMouseEvent>
20
RegionMapWidget::RegionMapWidget(QWidget* aParent)
21
: SlippyMapWidget(aParent), showGrid(false)
25
RegionMapWidget::~RegionMapWidget(void)
29
void RegionMapWidget::setShowGrid(bool val)
34
bool RegionMapWidget::getShowGrid()
39
void RegionMapWidget::paintEvent(QPaintEvent* anEvent)
41
SlippyMapWidget::paintEvent(anEvent);
43
if (!showGrid) return;
47
CoordBox v = CoordBox(Coord(R.y(), R.x()), Coord(R.y()+R.height(), R.x()+R.width()));
48
P.setPen(QPen(Qt::blue,2));
49
P.setBrush(Qt::NoBrush);
51
double sx = (double)width() / v.lonDiff();
52
if (REGION_WIDTH * sx < 6) return;
54
double sy = (double)height() / v.latDiff();
56
qint32 l = v.bottomLeft().lon() / REGION_WIDTH;
57
qint32 t = v.bottomLeft().lat() / REGION_WIDTH;
58
//for (int x = l*REGION_WIDTH; x<v.width(); x+=REGION_WIDTH) {
59
// for (int y = t*REGION_WIDTH; y<v.height(); y+=REGION_WIDTH) {
60
// P.drawRect(x * sx, y * sy, REGION_WIDTH * sx, REGION_WIDTH * sy);
63
for (qint64 x = l; x<= v.topRight().lon() / REGION_WIDTH; ++x) {
64
P.drawLine(int((x * REGION_WIDTH - v.bottomLeft().lon()) * sx), 0, int((x * REGION_WIDTH - v.bottomLeft().lon()) * sx), height());
66
for (qint64 y = t; y<= v.topRight().lat() / REGION_WIDTH; ++y) {
67
P.drawLine(0, int(height() - ((y * REGION_WIDTH - v.bottomLeft().lat()) * sy)), width(), int(height() - ((y * REGION_WIDTH - v.bottomLeft().lat()) * sy)));
69
for (qint64 x = l; x<= v.topRight().lon() / REGION_WIDTH; ++x)
70
for (qint64 y = t; y<= v.topRight().lat() / REGION_WIDTH; ++y) {
71
quint32 rg = (y + NUM_REGIONS/2)*NUM_REGIONS + (x + NUM_REGIONS/2);
72
QRect rgRect = QRect(int((x * REGION_WIDTH - v.bottomLeft().lon()) * sx),
73
int(height() - ((y * REGION_WIDTH - v.bottomLeft().lat()) * sy)),
74
int(REGION_WIDTH * sx), int(-REGION_WIDTH * sy));
75
//P.setClipRect(rgRect.adjusted(-1, -1, 1, 1));
76
if (ExistingRegions[rg])
77
P.drawText(int((x * REGION_WIDTH - v.bottomLeft().lon()) * sx),
78
int(height() - ((y * REGION_WIDTH - v.bottomLeft().lat()) * sy)),
79
QString("%1 - %2").arg(QString::number(rg)).arg(DateRegions[rg].toString("yyyy-MM-dd")));
81
P.drawText(int((x * REGION_WIDTH - v.bottomLeft().lon()) * sx),
82
int(height() - ((y * REGION_WIDTH - v.bottomLeft().lat()) * sy)),
83
QString("%1").arg(QString::number(rg)));
85
if (ExistingRegions[rg] && !DeleteRegions[rg]) {
86
//qDebug() << (y + NUM_REGIONS/2)*NUM_REGIONS + (x + NUM_REGIONS/2);
89
P.setBrush(QBrush(Qt::green, Qt::FDiagPattern));
95
if (SelectedRegions[rg] && !DeleteRegions[rg]) {
96
//qDebug() << (y + NUM_REGIONS/2)*NUM_REGIONS + (x + NUM_REGIONS/2);
99
P.setBrush(QBrush(Qt::blue, Qt::BDiagPattern));
110
void RegionMapWidget::mouseReleaseEvent(QMouseEvent* ev)
114
CoordBox v = CoordBox(Coord(R.y(), R.x()), Coord(R.y()+R.height(), R.x()+R.width()));
115
QPointF P = ev->pos();
117
Coord Pt(int(((height()-P.y()) / height() * v.latDiff()) + v.bottomLeft().lat()), int((P.x() / width() * v.lonDiff()) + v.bottomLeft().lon()));
118
int x = int(((qint64)Pt.lon()) / REGION_WIDTH);
119
x = (x < 0) ? x-1 :x;
120
int y = int(((qint64)Pt.lat()) / REGION_WIDTH);
121
y = (y < 0) ? y-1 :y;
122
int rg = (y + NUM_REGIONS/2)*NUM_REGIONS + (x + NUM_REGIONS/2);
124
if (SelectedRegions[rg] && ExistingRegions[rg]) {
125
SelectedRegions[rg] = false;
126
DeleteRegions[rg] = true;
128
if (!SelectedRegions[rg] && DeleteRegions[rg])
129
DeleteRegions[rg] = false;
131
SelectedRegions[rg] = !SelectedRegions[rg];
136
SlippyMapWidget::mouseReleaseEvent(ev);