-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatternViewBackgroundPainter.cpp
88 lines (75 loc) · 2.47 KB
/
PatternViewBackgroundPainter.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
#include "PatternViewBackgroundPainter.h"
#include "PatternView.h"
PatternViewBackgroundPainter::PatternViewBackgroundPainter(PatternView& a_view)
: m_view(a_view)
{
}
void PatternViewBackgroundPainter::drawBackground(QPainter* a_painter, const QRectF& a_rect)
{
a_painter->save();
QRectF rect = QtTools::limitBySceneRect(&m_view, a_rect);
// Horizontal lines/rows
const Key key_index_first = Properties::Piano::KeyCount - ceil (rect.bottom() / Properties::PianoRoll::KeyHeight );
const Key key_index_last = Properties::Piano::KeyCount - floor(rect.top() / Properties::PianoRoll::KeyHeight );
Q_ASSERT(key_index_first <= key_index_last);
for (Key key_index = key_index_first; key_index <= key_index_last; key_index++)
{
QRectF row_rect(
rect.x(),
Properties::PianoRoll::KeyHeight*(Properties::Piano::KeyCount - key_index - 1),
rect.width(),
Properties::PianoRoll::KeyHeight
);
Key key = key_index%Properties::Piano::KeysInOctave;
// Key areas
QColor key_color =
Properties::Piano::Sharps[key]
? PatternStyle::SharpKeyColor
: PatternStyle::KeyColor;
a_painter->setPen(Qt::NoPen);
a_painter->setBrush(key_color);
a_painter->drawRect(row_rect);
// Key lines
const QPoint right_fix{1,0}; // It draws 1 extra pixel for some reson
if (row_rect.top() > 0)
{
QRgb color;
if ((key+1)%Properties::Piano::KeysInOctave == 0)
color = PatternStyle::DarkLine;
else
color = PatternStyle::LightLine;
a_painter->setPen(color);
a_painter->drawLine(row_rect.topLeft(), row_rect.topRight()-right_fix);
}
}
// Vertical lines (time)
static_assert(Properties::Core::SecondWidth % PatternStyle::SecondDivider == 0);
const Pixel part_width = Properties::Core::SecondWidth/PatternStyle::SecondDivider;
const Second part_first = rect.left() / part_width;
const Second part_last = rect.right()/ part_width;
Q_ASSERT(part_first <= part_last);
for (Second part = part_first; part <= part_last; part++)
{
QRectF column_rect(
part_width*part,
rect.top(),
part_width,
rect.height()
);
if (column_rect.left() > 0)
{
if (part%PatternStyle::SecondDivider == 0)
a_painter->setPen(PatternStyle::DarkLine);
else
{
if (m_view.transform().m11() <= PatternStyle::IntermediateLineScaleMin)
// Don't draw intermediate lines on very small scales
continue;
else
a_painter->setPen(PatternStyle::LightLine);
}
a_painter->drawLine(column_rect.topLeft(), column_rect.bottomLeft());
}
}
a_painter->restore();
}