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
|
void AsaGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect){
QColor BaseColor(250,250,250);
QColor LightGrey1(220,220,220);
QColor LightGrey2(220,220,220);
QColor MiddleGrey(200,200,200);
QColor DarkGrey(180,180,180);
int k=1; //// if zoomed to a certain scale, 'k' is used to produce new lines
if (ScaleFactor>2){
k=2;
LightGrey2.setRgb(200,200,200);
MiddleGrey.setRgb(160,160,160);
DarkGrey.setRgb(120,120,120);
}
const int gridSize = 10*ScaleFactor/k;
qreal left = int(rect.left()) - ( int(rect.left()) % (gridSize*10) );
qreal bottom = int(rect.bottom() ) - ( int(rect.bottom()) % (gridSize*10) ) + int(this->height())%(gridSize*10) + gridSize*10;
QVarLengthArray<QLineF, 100> linesVert;
QVarLengthArray<QLineF, 100> linesHor;
for (qreal x = left; x < rect.right(); x += gridSize)
linesVert.append(QLineF(x, rect.top(), x, rect.bottom()));
for (qreal y = bottom; y > rect.top(); y -= gridSize)
linesHor.append(QLineF(rect.left(), y, rect.right(), y));
painter->fillRect(rect, BaseColor );
for (int i=0; i<linesVert.size(); i++){
if(i%(1*k)==0){
if( i%(5*k)==0){
if( i%(10*k)==0)
painter->setPen(DarkGrey);
else
painter->setPen(MiddleGrey);
}
else painter->setPen(LightGrey2);
}
else
painter->setPen(LightGrey1);
painter->drawLine(linesVert[i]);
}
painter->setPen(BaseColor); //
painter->drawLine(linesVert[0]); // remove Line at x=0
for (int i=0; i<linesVert.size(); i++){
if(i%(1*k)==0){
if( i%(5*k)==0){
if( i%(10*k)==0)
painter->setPen(DarkGrey);
else
painter->setPen(MiddleGrey);
}
else painter->setPen(LightGrey2);
}
else
painter->setPen(LightGrey1);
painter->drawLine(linesHor[i]);
}
}
|