-
Notifications
You must be signed in to change notification settings - Fork 0
/
makegrid.cpp
130 lines (116 loc) · 3.02 KB
/
makegrid.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "makegrid.h"
MakeGrid::MakeGrid( int w, int h ,int del) : QGraphicsItem(),
width1(w), height1(h), del(10)
{
}
void MakeGrid::paint (QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// re-draw the grid lines from 0,0 to _width, _height
// do horizontal first
//QColor c (200,200,255,125);
QColor c (0,0,250,125);
QFont font = painter->font();
QFontMetrics fm(font);
int doubleDel = del * 2;
// qDebug() << "ff=" << fm.height();
int thickness = 1;
painter->setPen( QPen(c, thickness));
int k = 0;
int dist = width1;
//for (int y= doubleDel; y < height1; y+=del)
for (int y= 0; y < height1; y+=del)
{
if ( k % 10 == 0)
{
thickness = 2;
dist = width1+5;
painter->drawText( dist+2,y+2,QString::number(k));
//k = 0;
}
else
{
thickness = 1;
dist = width1;
}
painter->setPen( QPen(c, thickness));
// painter->drawLine(doubleDel,y, dist, y);
painter->drawLine(0,y, dist, y);
/* char num[3];
num [0] = ' ';
num [1] = k + '0';
num[2] = '\0';
//painter->drawText( width1+7,y+2, num);
painter->drawText( width1+7,y+2,QString::number(k));*/
k ++;
}
k = 0;
dist = height1;
// for (int x= doubleDel; x < width1; x+=del)
for (int x=0; x < width1; x+=del)
{
if ( k % 10 == 0 )
{
// k = 0;
thickness = 2;
dist = height1+5;
painter->drawText( x-1,dist+2+fm.height(),QString::number(k));
}
else
{
thickness = 1;
dist = height1;
}
painter->setPen( QPen(c, thickness));
painter->drawLine(x,0, x, dist);
k ++;
}
////////////
/* k = 0;
for (qreal y = top; y < bottom-10; y += gridSize)
{
QPointF pointt = QPointF(right,y+5);
char num[3];
num [0] = ' ';
num [1] = k + '0';
num[2] = '\0';
painter->drawText( pointt, num);
k = k + 1;
if ( k == 10 ) k = 0;
}
k = 0;
for (qreal x = left; x < right; x += gridSize)
{
QPoint pointt = QPoint( x-1, bottom );
char num[3];
num [0] = ' ';
num [1] = k + '0';
num[2] = '\0';
painter->drawText( pointt, num);
k = k + 1;
if ( k == 10 ) k = 0;
} */
}
QRectF MakeGrid::boundingRect() const
{
return QRectF ( static_cast<qreal>(0),
static_cast<qreal>(0), static_cast<qreal>(width1),
static_cast<qreal>( height1));
}
void MakeGrid::sizeChanged(int w, int h)
{
width1 = w;
height1 = h;
}
void MakeGrid::mouseMoveEvent(QGraphicsSceneDragDropEvent *)
{
}
void MakeGrid::mousePressEvent(QGraphicsSceneDragDropEvent *)
{
}
void MakeGrid::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
}
void MakeGrid::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
{
}