comparison view/AlignmentView.cpp @ 867:99373ca20caf alignment_view

First sketch at alignment view (between panes in stack)
author Chris Cannam
date Fri, 17 Oct 2014 14:58:51 +0100
parents
children 99299949f965
comparison
equal deleted inserted replaced
866:d854c72dcaa1 867:99373ca20caf
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006-2014 Chris Cannam and QMUL.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #include "AlignmentView.h"
17
18 #include <QPainter>
19
20 using std::vector;
21
22 AlignmentView::AlignmentView(QWidget *w) :
23 View(w, false),
24 m_above(0),
25 m_below(0)
26 {
27 setObjectName(tr("AlignmentView"));
28 }
29
30 void
31 AlignmentView::globalCentreFrameChanged(int f)
32 {
33 View::globalCentreFrameChanged(f);
34 update();
35 }
36
37 void
38 AlignmentView::viewCentreFrameChanged(View *v, int f)
39 {
40 View::viewCentreFrameChanged(v, f);
41 if (v == m_above) {
42 m_centreFrame = f;
43 update();
44 } else if (v == m_below) {
45 update();
46 }
47 }
48
49 void
50 AlignmentView::viewManagerPlaybackFrameChanged(int)
51 {
52 update();
53 }
54
55 void
56 AlignmentView::viewAboveZoomLevelChanged(int level, bool)
57 {
58 m_zoomLevel = level;
59 update();
60 }
61
62 void
63 AlignmentView::viewBelowZoomLevelChanged(int, bool)
64 {
65 update();
66 }
67
68 void
69 AlignmentView::setViewAbove(View *v)
70 {
71 if (m_above) {
72 disconnect(m_above, 0, this, 0);
73 }
74
75 m_above = v;
76
77 if (m_above) {
78 connect(m_above,
79 SIGNAL(zoomLevelChanged(int, bool)),
80 this,
81 SLOT(viewAboveZoomLevelChanged(int, bool)));
82 }
83 }
84
85 void
86 AlignmentView::setViewBelow(View *v)
87 {
88 if (m_below) {
89 disconnect(m_below, 0, this, 0);
90 }
91
92 m_below = v;
93
94 if (m_below) {
95 connect(m_below,
96 SIGNAL(zoomLevelChanged(int, bool)),
97 this,
98 SLOT(viewBelowZoomLevelChanged(int, bool)));
99 }
100 }
101
102 void
103 AlignmentView::paintEvent(QPaintEvent *)
104 {
105 if (m_above == 0 || m_below == 0 || !m_manager) return;
106
107 int rate = m_manager->getMainModelSampleRate();
108 if (rate == 0) return;
109
110 bool darkPalette = false;
111 if (m_manager) darkPalette = m_manager->getGlobalDarkBackground();
112
113 QColor fg = Qt::black, bg = Qt::white;
114 if (darkPalette) std::swap(fg, bg);
115
116 QPainter paint(this);
117 paint.setPen(QPen(fg, 2));
118 paint.setBrush(Qt::NoBrush);
119 paint.setRenderHint(QPainter::Antialiasing, true);
120
121 paint.fillRect(rect(), bg);
122
123 vector<int> keyFrames;
124 for (int f = m_above->getModelsStartFrame();
125 f <= m_above->getModelsEndFrame();
126 f += rate * 5) {
127 keyFrames.push_back(f);
128 }
129
130 foreach (int f, keyFrames) {
131 int af = m_above->alignFromReference(f);
132 int ax = m_above->getXForFrame(af);
133 int bf = m_below->alignFromReference(f);
134 int bx = m_below->getXForFrame(bf);
135 paint.drawLine(ax, 0, bx, height());
136 }
137
138 paint.end();
139 }
140