-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrgridwidget.cpp
More file actions
executable file
·56 lines (48 loc) · 1.5 KB
/
rgridwidget.cpp
File metadata and controls
executable file
·56 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "rgridwidget.h"
#include <QPainter>
#include "rcompositemapobject.h"
#include "rmapobjectfocusholder.h"
//--------------------------------------------------------------------------------------
RGridWidget::RGridWidget(QWidget *parent, int size) :
QFrame(parent),
gridSize(size)
{
setFrameShape(Panel);
setFrameShadow(Raised);
}
//--------------------------------------------------------------------------------------
RGridWidget::~RGridWidget()
{
RCompositeMapObject::deleteInstance();
RMapObjectFocusHolder::instance().setFocusMapObject(0);
}
//--------------------------------------------------------------------------------------
void RGridWidget::paintEvent(QPaintEvent *event)
{
if (!polygon.empty()) {
QPainter painter(this);
QPen pen(Qt::SolidLine);
pen.setColor(QColor(Qt::black));
painter.setPen(pen);
painter.drawPoints(polygon);
}
QFrame::paintEvent(event);
}
//--------------------------------------------------------------------------------------
void RGridWidget::resizeEvent(QResizeEvent *event)
{
updatePolygonData();
QFrame::resizeEvent(event);
}
//--------------------------------------------------------------------------------------
void RGridWidget::updatePolygonData()
{
if (gridSize > 1) {
polygon.clear();
int left = rect().left() - (rect().left() % gridSize);
int top = rect().top() - (rect().top() % gridSize);
for (int x = left; x < rect().right(); x += gridSize)
for (int y = top; y < rect().bottom(); y += gridSize)
polygon.append(QPoint(x, y));
}
}