Mercurial > hg > svgui
comparison view/Pane.cpp @ 133:9e6b3e239b9d
* Add zoom thumbwheels to Pane. Implement horizontal thumbwheel, and
vertical depending on layer type (supported for waveform and spectrogram,
though wrong for log-scale spectrogram at the moment).
* Add bare bones of a spectrum layer.
* Add window icon
* Add shortcut for "insert time instant" on laptops without keypad enter (";")
* Delete FFT processing thread when it exits (at least, next time we're asked
for something interesting)
* Get audio file extensions from the file readers, and thus from libsndfile for
the wave file reader -- leads to rather a wide combo box in file dialog though
* Better refresh order for spectrogram (redraw centre section first)
author | Chris Cannam |
---|---|
date | Fri, 04 Aug 2006 17:01:37 +0000 |
parents | 5d3a483856ff |
children | e98130764635 |
comparison
equal
deleted
inserted
replaced
132:5d3a483856ff | 133:9e6b3e239b9d |
---|---|
20 #include "base/RealTime.h" | 20 #include "base/RealTime.h" |
21 #include "base/Profiler.h" | 21 #include "base/Profiler.h" |
22 #include "ViewManager.h" | 22 #include "ViewManager.h" |
23 #include "base/CommandHistory.h" | 23 #include "base/CommandHistory.h" |
24 #include "layer/WaveformLayer.h" | 24 #include "layer/WaveformLayer.h" |
25 #include "widgets/Thumbwheel.h" | |
26 | 25 |
27 #include <QPaintEvent> | 26 #include <QPaintEvent> |
28 #include <QPainter> | 27 #include <QPainter> |
29 #include <iostream> | 28 #include <iostream> |
30 #include <cmath> | 29 #include <cmath> |
30 | |
31 //!!! for HUD -- pull out into a separate class | |
32 #include <QFrame> | |
33 #include <QGridLayout> | |
34 #include <QPushButton> | |
35 #include "widgets/Thumbwheel.h" | |
31 | 36 |
32 using std::cerr; | 37 using std::cerr; |
33 using std::endl; | 38 using std::endl; |
34 | 39 |
35 Pane::Pane(QWidget *w) : | 40 Pane::Pane(QWidget *w) : |
38 m_clickedInRange(false), | 43 m_clickedInRange(false), |
39 m_shiftPressed(false), | 44 m_shiftPressed(false), |
40 m_ctrlPressed(false), | 45 m_ctrlPressed(false), |
41 m_navigating(false), | 46 m_navigating(false), |
42 m_resizing(false), | 47 m_resizing(false), |
43 m_centreLineVisible(true) | 48 m_centreLineVisible(true), |
49 m_headsUpDisplay(0) | |
44 { | 50 { |
45 setObjectName("Pane"); | 51 setObjectName("Pane"); |
46 setMouseTracking(true); | 52 setMouseTracking(true); |
53 | |
54 updateHeadsUpDisplay(); | |
55 } | |
56 | |
57 void | |
58 Pane::updateHeadsUpDisplay() | |
59 { | |
47 /* | 60 /* |
48 int count = 0; | 61 int count = 0; |
49 int currentLevel = 1; | 62 int currentLevel = 1; |
50 int level = 1; | 63 int level = 1; |
51 while (true) { | 64 while (true) { |
58 ++count; | 71 ++count; |
59 } | 72 } |
60 | 73 |
61 std::cerr << "Have " << count+1 << " zoom levels" << std::endl; | 74 std::cerr << "Have " << count+1 << " zoom levels" << std::endl; |
62 */ | 75 */ |
63 /* | 76 |
64 Thumbwheel *thumbwheel = new Thumbwheel(0, 40, 5, | 77 if (!m_headsUpDisplay) { |
65 Qt::Vertical, this); | 78 |
66 thumbwheel->move(10, 10); | 79 m_headsUpDisplay = new QFrame(this); |
67 connect(thumbwheel, SIGNAL(valueChanged(int)), this, | 80 |
68 SLOT(horizontalThumbwheelMoved(int))); | 81 QGridLayout *layout = new QGridLayout; |
69 */ | 82 layout->setMargin(0); |
83 layout->setSpacing(0); | |
84 m_headsUpDisplay->setLayout(layout); | |
85 | |
86 m_hthumb = new Thumbwheel(Qt::Horizontal); | |
87 layout->addWidget(m_hthumb, 1, 0); | |
88 m_hthumb->setFixedWidth(70); | |
89 m_hthumb->setFixedHeight(16); | |
90 m_hthumb->setDefaultValue(0); | |
91 connect(m_hthumb, SIGNAL(valueChanged(int)), this, | |
92 SLOT(horizontalThumbwheelMoved(int))); | |
93 | |
94 m_vthumb = new Thumbwheel(Qt::Vertical); | |
95 layout->addWidget(m_vthumb, 0, 1); | |
96 m_vthumb->setFixedWidth(16); | |
97 m_vthumb->setFixedHeight(70); | |
98 connect(m_vthumb, SIGNAL(valueChanged(int)), this, | |
99 SLOT(verticalThumbwheelMoved(int))); | |
100 | |
101 QPushButton *reset = new QPushButton; | |
102 reset->setFixedHeight(16); | |
103 reset->setFixedWidth(16); | |
104 layout->addWidget(reset, 1, 1); | |
105 connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); | |
106 connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); | |
107 } | |
108 | |
109 int count = 0; | |
110 int current = 0; | |
111 int level = 1; | |
112 | |
113 while (true) { | |
114 if (getZoomLevel() == level) current = count; | |
115 int newLevel = getZoomConstraintBlockSize(level + 1, | |
116 ZoomConstraint::RoundUp); | |
117 if (newLevel == level) break; | |
118 level = newLevel; | |
119 if (++count == 50) break; | |
120 } | |
121 | |
122 // std::cerr << "Have " << count << " zoom levels" << std::endl; | |
123 | |
124 m_hthumb->setMinimumValue(0); | |
125 m_hthumb->setMaximumValue(count); | |
126 m_hthumb->setValue(count - current); | |
127 | |
128 // std::cerr << "set value to " << count-current << std::endl; | |
129 | |
130 // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl; | |
131 | |
132 if (count != 50 && m_hthumb->getDefaultValue() == 0) { | |
133 m_hthumb->setDefaultValue(count - current); | |
134 // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl; | |
135 } | |
136 | |
137 Layer *layer = 0; | |
138 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); | |
139 if (layer) { | |
140 int defaultStep = 0; | |
141 int max = layer->getVerticalZoomSteps(defaultStep); | |
142 if (max == 0) { | |
143 m_vthumb->hide(); | |
144 } else { | |
145 m_vthumb->show(); | |
146 m_vthumb->setMinimumValue(0); | |
147 m_vthumb->setMaximumValue(max); | |
148 m_vthumb->setDefaultValue(defaultStep); | |
149 m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); | |
150 } | |
151 } | |
152 | |
153 if (m_manager && m_manager->getZoomWheelsEnabled() && | |
154 width() > 120 && height() > 100) { | |
155 if (m_vthumb->isVisible()) { | |
156 m_headsUpDisplay->move(width() - 86, height() - 86); | |
157 } else { | |
158 m_headsUpDisplay->move(width() - 86, height() - 51); | |
159 } | |
160 if (!m_headsUpDisplay->isVisible()) { | |
161 m_headsUpDisplay->show(); | |
162 connect(m_manager, SIGNAL(zoomLevelChanged()), | |
163 this, SLOT(zoomLevelChanged())); | |
164 } | |
165 } else { | |
166 m_headsUpDisplay->hide(); | |
167 if (m_manager) { | |
168 disconnect(m_manager, SIGNAL(zoomLevelChanged()), | |
169 this, SLOT(zoomLevelChanged())); | |
170 } | |
171 } | |
70 } | 172 } |
71 | 173 |
72 bool | 174 bool |
73 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const | 175 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const |
74 { | 176 { |
407 } | 509 } |
408 if (tw > maxTextWidth) maxTextWidth = tw; | 510 if (tw > maxTextWidth) maxTextWidth = tw; |
409 } | 511 } |
410 | 512 |
411 int lly = height() - 6; | 513 int lly = height() - 6; |
412 | 514 int llx = width() - maxTextWidth - 5; |
413 if (r.x() + r.width() >= width() - maxTextWidth - 5) { | 515 |
516 if (m_manager->getZoomWheelsEnabled()) { | |
517 lly -= 20; | |
518 llx -= 20; | |
519 } | |
520 | |
521 if (r.x() + r.width() >= llx) { | |
414 | 522 |
415 for (int i = 0; i < texts.size(); ++i) { | 523 for (int i = 0; i < texts.size(); ++i) { |
416 | 524 |
417 if (i == texts.size() - 1) { | 525 if (i == texts.size() - 1) { |
418 paint.setPen(Qt::black); | 526 paint.setPen(Qt::black); |
419 } | 527 } |
420 | 528 |
421 drawVisibleText(paint, width() - maxTextWidth - 5, | 529 drawVisibleText(paint, llx, |
422 lly - fontHeight + fontAscent, | 530 lly - fontHeight + fontAscent, |
423 texts[i], OutlinedText); | 531 texts[i], OutlinedText); |
424 | 532 |
425 lly -= fontHeight; | 533 lly -= fontHeight; |
426 } | 534 } |
928 m_identifyFeatures = false; | 1036 m_identifyFeatures = false; |
929 if (previouslyIdentifying) update(); | 1037 if (previouslyIdentifying) update(); |
930 } | 1038 } |
931 | 1039 |
932 void | 1040 void |
1041 Pane::resizeEvent(QResizeEvent *) | |
1042 { | |
1043 updateHeadsUpDisplay(); | |
1044 } | |
1045 | |
1046 void | |
933 Pane::wheelEvent(QWheelEvent *e) | 1047 Pane::wheelEvent(QWheelEvent *e) |
934 { | 1048 { |
935 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; | 1049 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; |
936 | 1050 |
937 int count = e->delta(); | 1051 int count = e->delta(); |
997 Pane::horizontalThumbwheelMoved(int value) | 1111 Pane::horizontalThumbwheelMoved(int value) |
998 { | 1112 { |
999 int count = 0; | 1113 int count = 0; |
1000 int level = 1; | 1114 int level = 1; |
1001 while (true) { | 1115 while (true) { |
1002 if (value == count) break; | 1116 if (m_hthumb->getMaximumValue() - value == count) break; |
1003 int newLevel = getZoomConstraintBlockSize(level + 1, | 1117 int newLevel = getZoomConstraintBlockSize(level + 1, |
1004 ZoomConstraint::RoundUp); | 1118 ZoomConstraint::RoundUp); |
1005 if (newLevel == level) break; | 1119 if (newLevel == level) break; |
1006 level = newLevel; | 1120 level = newLevel; |
1007 ++count; | 1121 ++count; |
1008 } | 1122 } |
1009 | 1123 |
1010 std::cerr << "new level is " << level << std::endl; | 1124 // std::cerr << "new level is " << level << std::endl; |
1011 setZoomLevel(level); | 1125 setZoomLevel(level); |
1012 } | 1126 } |
1013 | 1127 |
1014 void | 1128 void |
1015 Pane::verticalThumbwheelMoved(int value) | 1129 Pane::verticalThumbwheelMoved(int value) |
1016 { | 1130 { |
1131 Layer *layer = 0; | |
1132 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); | |
1133 if (layer) { | |
1134 int defaultStep = 0; | |
1135 int max = layer->getVerticalZoomSteps(defaultStep); | |
1136 if (max == 0) { | |
1137 updateHeadsUpDisplay(); | |
1138 return; | |
1139 } | |
1140 if (value > max) { | |
1141 value = max; | |
1142 } | |
1143 layer->setVerticalZoomStep(value); | |
1144 } | |
1017 } | 1145 } |
1018 | 1146 |
1019 bool | 1147 bool |
1020 Pane::editSelectionStart(QMouseEvent *e) | 1148 Pane::editSelectionStart(QMouseEvent *e) |
1021 { | 1149 { |
1124 break; | 1252 break; |
1125 */ | 1253 */ |
1126 } | 1254 } |
1127 } | 1255 } |
1128 | 1256 |
1257 void | |
1258 Pane::zoomWheelsEnabledChanged() | |
1259 { | |
1260 updateHeadsUpDisplay(); | |
1261 update(); | |
1262 } | |
1263 | |
1264 void | |
1265 Pane::zoomLevelChanged() | |
1266 { | |
1267 if (m_manager && m_manager->getZoomWheelsEnabled()) { | |
1268 updateHeadsUpDisplay(); | |
1269 } | |
1270 } | |
1271 | |
1272 void | |
1273 Pane::propertyContainerSelected(View *v, PropertyContainer *pc) | |
1274 { | |
1275 Layer *layer = 0; | |
1276 | |
1277 if (getLayerCount() > 0) { | |
1278 layer = getLayer(getLayerCount() - 1); | |
1279 disconnect(layer, SIGNAL(verticalZoomChanged()), | |
1280 this, SLOT(verticalZoomChanged())); | |
1281 } | |
1282 | |
1283 View::propertyContainerSelected(v, pc); | |
1284 updateHeadsUpDisplay(); | |
1285 | |
1286 if (getLayerCount() > 0) { | |
1287 layer = getLayer(getLayerCount() - 1); | |
1288 connect(layer, SIGNAL(verticalZoomChanged()), | |
1289 this, SLOT(verticalZoomChanged())); | |
1290 } | |
1291 } | |
1292 | |
1293 void | |
1294 Pane::verticalZoomChanged() | |
1295 { | |
1296 Layer *layer = 0; | |
1297 | |
1298 if (getLayerCount() > 0) { | |
1299 | |
1300 layer = getLayer(getLayerCount() - 1); | |
1301 | |
1302 if (m_vthumb && m_vthumb->isVisible()) { | |
1303 m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); | |
1304 } | |
1305 } | |
1306 } | |
1307 | |
1129 QString | 1308 QString |
1130 Pane::toXmlString(QString indent, QString extraAttributes) const | 1309 Pane::toXmlString(QString indent, QString extraAttributes) const |
1131 { | 1310 { |
1132 return View::toXmlString | 1311 return View::toXmlString |
1133 (indent, | 1312 (indent, |