Mercurial > hg > dmlib
annotate edwaveform.cpp @ 376:40e33ad0d153
Work towards a working editor .. some day.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Oct 2012 02:27:55 +0300 |
parents | 1b8362a26692 |
children | e5220ff48bc8 |
rev | line source |
---|---|
357 | 1 #include <QtGui> |
2 #include "edwaveform.h" | |
3 | |
4 | |
5 WaveformView::WaveformView(QWidget *parent) : QWidget(parent) | |
6 { | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
7 data = NULL; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
8 len = time = offs = 0; |
357 | 9 scale = 1.0f; |
10 } | |
11 | |
12 | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
13 void WaveformView::setWaveform(qint16 *mdata, int mlen) |
357 | 14 { |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
15 data = mdata; |
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
16 len = mlen; |
357 | 17 update(); |
18 } | |
19 | |
20 | |
21 void WaveformView::setTime(const int mtime) | |
22 { | |
23 time = mtime; | |
24 update(); | |
25 } | |
26 | |
27 | |
28 void WaveformView::setOffset(const int moffs) | |
29 { | |
30 offs = moffs; | |
31 update(); | |
32 } | |
33 | |
34 | |
35 void WaveformView::setScale(const float mscale) | |
36 { | |
37 if (mscale > 0.05) | |
38 scale = mscale; | |
39 update(); | |
40 } | |
41 | |
42 | |
43 void WaveformView::paintEvent(QPaintEvent *) | |
44 { | |
45 QColor waveColor(0, 150, 0); | |
46 QColor markerColor(255,255,255); | |
47 | |
48 QPainter painter(this); | |
49 painter.setRenderHint(QPainter::Antialiasing); | |
50 | |
51 painter.save(); | |
52 painter.translate(0, height() / 2); | |
53 painter.scale(scale, height() / 32768.0f); | |
54 painter.setPen(waveColor); | |
55 | |
56 int prevY = 0, prevX = 0; | |
57 for (int xc = 0; xc < width(); xc++) | |
58 { | |
376
40e33ad0d153
Work towards a working editor .. some day.
Matti Hamalainen <ccr@tnsp.org>
parents:
357
diff
changeset
|
59 qint16 value = data[(int) ((offs + xc) * scale)]; |
357 | 60 painter.drawLine(prevX, prevY, xc, value); |
61 prevY = value; prevX = xc; | |
62 } | |
63 painter.restore(); | |
64 | |
65 | |
66 if (time >= offs * scale && time - offs <= width() * scale) | |
67 { | |
68 int xc = time - offs; | |
69 painter.scale(scale, 1); | |
70 painter.setPen(markerColor); | |
71 painter.drawLine(xc, 0, xc, height()); | |
72 } | |
73 } | |
74 | |
75 | |
76 void WaveformView::mousePressEvent(QMouseEvent *ev) | |
77 { | |
78 /* | |
79 if (ev->button() == Qt::LeftButton) | |
80 { | |
81 lastPoint = ev->pos(); | |
82 scribbling = true; | |
83 } | |
84 */ | |
85 } | |
86 | |
87 | |
88 void WaveformView::mouseMoveEvent(QMouseEvent *ev) | |
89 { | |
90 /* | |
91 if ((ev->buttons() & Qt::LeftButton) && scribbling) | |
92 drawLineTo(ev->pos()); | |
93 */ | |
94 } | |
95 | |
96 | |
97 void WaveformView::mouseReleaseEvent(QMouseEvent *ev) | |
98 { | |
99 /* | |
100 if (ev->button() == Qt::LeftButton && scribbling) | |
101 { | |
102 drawLineTo(ev->pos()); | |
103 scribbling = false; | |
104 } | |
105 */ | |
106 } |