comparison edwaveform.cpp @ 357:1b8362a26692

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