Mercurial > hg > svgui
comparison view/Pane.cpp @ 946:36cddc3de023 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:19:52 +0100 |
parents | 499b637f2a26 3fb91da7d98d |
children | f2c63ec85901 |
comparison
equal
deleted
inserted
replaced
897:499b637f2a26 | 946:36cddc3de023 |
---|---|
22 #include "ViewManager.h" | 22 #include "ViewManager.h" |
23 #include "widgets/CommandHistory.h" | 23 #include "widgets/CommandHistory.h" |
24 #include "widgets/TextAbbrev.h" | 24 #include "widgets/TextAbbrev.h" |
25 #include "base/Preferences.h" | 25 #include "base/Preferences.h" |
26 #include "layer/WaveformLayer.h" | 26 #include "layer/WaveformLayer.h" |
27 #include "layer/TimeRulerLayer.h" | |
27 | 28 |
28 // GF: added so we can propagate the mouse move event to the note layer for context handling. | 29 // GF: added so we can propagate the mouse move event to the note layer for context handling. |
29 #include "layer/LayerFactory.h" | 30 #include "layer/LayerFactory.h" |
30 #include "layer/FlexiNoteLayer.h" | 31 #include "layer/FlexiNoteLayer.h" |
31 | 32 |
141 m_hthumb->setCursor(Qt::ArrowCursor); | 142 m_hthumb->setCursor(Qt::ArrowCursor); |
142 layout->addWidget(m_hthumb, 1, 0, 1, 2); | 143 layout->addWidget(m_hthumb, 1, 0, 1, 2); |
143 m_hthumb->setFixedWidth(70); | 144 m_hthumb->setFixedWidth(70); |
144 m_hthumb->setFixedHeight(16); | 145 m_hthumb->setFixedHeight(16); |
145 m_hthumb->setDefaultValue(0); | 146 m_hthumb->setDefaultValue(0); |
146 m_hthumb->setSpeed(0.6); | 147 m_hthumb->setSpeed(0.6f); |
147 connect(m_hthumb, SIGNAL(valueChanged(int)), this, | 148 connect(m_hthumb, SIGNAL(valueChanged(int)), this, |
148 SLOT(horizontalThumbwheelMoved(int))); | 149 SLOT(horizontalThumbwheelMoved(int))); |
149 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 150 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); |
150 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 151 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); |
151 | 152 |
318 if (layer && layer->getVerticalZoomSteps(discard) == 0) { | 319 if (layer && layer->getVerticalZoomSteps(discard) == 0) { |
319 m_vpan->hide(); | 320 m_vpan->hide(); |
320 return; | 321 return; |
321 } | 322 } |
322 | 323 |
323 float vmin, vmax, dmin, dmax; | 324 double vmin, vmax, dmin, dmax; |
324 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) { | 325 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) { |
325 float y0 = (dmin - vmin) / (vmax - vmin); | 326 double y0 = (dmin - vmin) / (vmax - vmin); |
326 float y1 = (dmax - vmin) / (vmax - vmin); | 327 double y1 = (dmax - vmin) / (vmax - vmin); |
327 m_vpan->blockSignals(true); | 328 m_vpan->blockSignals(true); |
328 m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0); | 329 m_vpan->setRectExtents(0, float(1.0 - y1), 1, float(y1 - y0)); |
329 m_vpan->blockSignals(false); | 330 m_vpan->blockSignals(false); |
330 m_vpan->show(); | 331 m_vpan->show(); |
331 } else { | 332 } else { |
332 m_vpan->hide(); | 333 m_vpan->hide(); |
333 } | 334 } |
481 m_manager && m_manager->shouldIlluminateLocalFeatures() && | 482 m_manager && m_manager->shouldIlluminateLocalFeatures() && |
482 topLayer) { | 483 topLayer) { |
483 drawFeatureDescription(topLayer, paint); | 484 drawFeatureDescription(topLayer, paint); |
484 } | 485 } |
485 | 486 |
486 int sampleRate = getModelsSampleRate(); | 487 sv_samplerate_t sampleRate = getModelsSampleRate(); |
487 paint.setBrush(Qt::NoBrush); | 488 paint.setBrush(Qt::NoBrush); |
488 | 489 |
489 if (m_centreLineVisible && | 490 if (m_centreLineVisible && |
490 m_manager && | 491 m_manager && |
491 m_manager->shouldShowCentreLine()) { | 492 m_manager->shouldShowCentreLine()) { |
558 void | 559 void |
559 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint) | 560 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint) |
560 { | 561 { |
561 Layer *scaleLayer = 0; | 562 Layer *scaleLayer = 0; |
562 | 563 |
563 float min, max; | 564 double min, max; |
564 bool log; | 565 bool log; |
565 QString unit; | 566 QString unit; |
566 | 567 |
567 // If the top layer has no scale and reports no display | 568 // If the top layer has no scale and reports no display |
568 // extents, but does report a unit, then the scale should be | 569 // extents, but does report a unit, then the scale should be |
712 paint.restore(); | 713 paint.restore(); |
713 } | 714 } |
714 } | 715 } |
715 | 716 |
716 void | 717 void |
717 Pane::drawCentreLine(int sampleRate, QPainter &paint, bool omitLine) | 718 Pane::drawCentreLine(sv_samplerate_t sampleRate, QPainter &paint, bool omitLine) |
718 { | 719 { |
719 if (omitLine && m_manager->getMainModelSampleRate() == 0) { | 720 if (omitLine && m_manager->getMainModelSampleRate() == 0) { |
720 return; | 721 return; |
721 } | 722 } |
722 | 723 |
971 void | 972 void |
972 Pane::drawEditingSelection(QPainter &paint) | 973 Pane::drawEditingSelection(QPainter &paint) |
973 { | 974 { |
974 int offset = m_mousePos.x() - m_clickPos.x(); | 975 int offset = m_mousePos.x() - m_clickPos.x(); |
975 | 976 |
976 int origStart = m_editingSelection.getStartFrame(); | 977 sv_frame_t origStart = m_editingSelection.getStartFrame(); |
977 | 978 |
978 int p0 = getXForFrame(origStart) + offset; | 979 int p0 = getXForFrame(origStart) + offset; |
979 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; | 980 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; |
980 | 981 |
981 if (m_editingSelectionEdge < 0) { | 982 if (m_editingSelectionEdge < 0) { |
982 p1 = getXForFrame(m_editingSelection.getEndFrame()); | 983 p1 = getXForFrame(m_editingSelection.getEndFrame()); |
983 } else if (m_editingSelectionEdge > 0) { | 984 } else if (m_editingSelectionEdge > 0) { |
984 p0 = getXForFrame(m_editingSelection.getStartFrame()); | 985 p0 = getXForFrame(m_editingSelection.getStartFrame()); |
985 } | 986 } |
986 | 987 |
987 int newStart = getFrameForX(p0); | 988 sv_frame_t newStart = getFrameForX(p0); |
988 int newEnd = getFrameForX(p1); | 989 sv_frame_t newEnd = getFrameForX(p1); |
989 | 990 |
990 paint.save(); | 991 paint.save(); |
991 paint.setPen(QPen(getForeground(), 2)); | 992 paint.setPen(QPen(getForeground(), 2)); |
992 | 993 |
993 int fontHeight = paint.fontMetrics().height(); | 994 int fontHeight = paint.fontMetrics().height(); |
994 int fontAscent = paint.fontMetrics().ascent(); | 995 int fontAscent = paint.fontMetrics().ascent(); |
995 int sampleRate = getModelsSampleRate(); | 996 sv_samplerate_t sampleRate = getModelsSampleRate(); |
996 QString startText, endText, offsetText; | 997 QString startText, endText, offsetText; |
997 startText = QString("%1").arg(newStart); | 998 startText = QString("%1").arg(newStart); |
998 endText = QString("%1").arg(newEnd); | 999 endText = QString("%1").arg(newEnd); |
999 offsetText = QString("%1").arg(newStart - origStart); | 1000 offsetText = QString("%1").arg(newStart - origStart); |
1000 if (newStart >= origStart) { | 1001 if (newStart >= origStart) { |
1039 paint.restore(); | 1040 paint.restore(); |
1040 } | 1041 } |
1041 | 1042 |
1042 void | 1043 void |
1043 Pane::drawDurationAndRate(QRect r, const Model *waveformModel, | 1044 Pane::drawDurationAndRate(QRect r, const Model *waveformModel, |
1044 int sampleRate, QPainter &paint) | 1045 sv_samplerate_t sampleRate, QPainter &paint) |
1045 { | 1046 { |
1046 int fontHeight = paint.fontMetrics().height(); | 1047 int fontHeight = paint.fontMetrics().height(); |
1047 int fontAscent = paint.fontMetrics().ascent(); | 1048 int fontAscent = paint.fontMetrics().ascent(); |
1048 | 1049 |
1049 if (r.y() + r.height() < height() - fontHeight - 6) return; | 1050 if (r.y() + r.height() < height() - fontHeight - 6) return; |
1050 | 1051 |
1051 int modelRate = waveformModel->getSampleRate(); | 1052 sv_samplerate_t modelRate = waveformModel->getSampleRate(); |
1052 int nativeRate = waveformModel->getNativeRate(); | 1053 sv_samplerate_t nativeRate = waveformModel->getNativeRate(); |
1053 int playbackRate = m_manager->getPlaybackSampleRate(); | 1054 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); |
1054 int outputRate = m_manager->getOutputSampleRate(); | 1055 sv_samplerate_t outputRate = m_manager->getOutputSampleRate(); |
1055 | 1056 |
1056 QString srNote = ""; | 1057 QString srNote = ""; |
1057 | 1058 |
1058 // Show (R) for waveform models that have been resampled or will | 1059 // Show (R) for waveform models that have been resampled or will |
1059 // be resampled on playback, and (X) for waveform models that will | 1060 // be resampled on playback, and (X) for waveform models that will |
1088 desc, OutlinedText); | 1089 desc, OutlinedText); |
1089 } | 1090 } |
1090 } | 1091 } |
1091 | 1092 |
1092 bool | 1093 bool |
1093 Pane::render(QPainter &paint, int xorigin, int f0, int f1) | 1094 Pane::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1) |
1094 { | 1095 { |
1095 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) { | 1096 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) { |
1096 return false; | 1097 return false; |
1097 } | 1098 } |
1098 | 1099 |
1119 | 1120 |
1120 return true; | 1121 return true; |
1121 } | 1122 } |
1122 | 1123 |
1123 QImage * | 1124 QImage * |
1124 Pane::toNewImage(int f0, int f1) | 1125 Pane::toNewImage(sv_frame_t f0, sv_frame_t f1) |
1125 { | 1126 { |
1126 int x0 = f0 / getZoomLevel(); | 1127 int x0 = int(f0 / getZoomLevel()); |
1127 int x1 = f1 / getZoomLevel(); | 1128 int x1 = int(f1 / getZoomLevel()); |
1128 | 1129 |
1129 QImage *image = new QImage(x1 - x0 + m_scaleWidth, | 1130 QImage *image = new QImage(x1 - x0 + m_scaleWidth, |
1130 height(), QImage::Format_RGB32); | 1131 height(), QImage::Format_RGB32); |
1131 | 1132 |
1132 int formerScaleWidth = m_scaleWidth; | 1133 int formerScaleWidth = m_scaleWidth; |
1158 return image; | 1159 return image; |
1159 } | 1160 } |
1160 } | 1161 } |
1161 | 1162 |
1162 QSize | 1163 QSize |
1163 Pane::getImageSize(int f0, int f1) | 1164 Pane::getImageSize(sv_frame_t f0, sv_frame_t f1) |
1164 { | 1165 { |
1165 QSize s = View::getImageSize(f0, f1); | 1166 QSize s = View::getImageSize(f0, f1); |
1166 QImage *image = new QImage(100, 100, QImage::Format_RGB32); | 1167 QImage *image = new QImage(100, 100, QImage::Format_RGB32); |
1167 QPainter paint(image); | 1168 QPainter paint(image); |
1168 | 1169 |
1176 } | 1177 } |
1177 | 1178 |
1178 return QSize(sw + s.width(), s.height()); | 1179 return QSize(sw + s.width(), s.height()); |
1179 } | 1180 } |
1180 | 1181 |
1181 int | 1182 sv_frame_t |
1182 Pane::getFirstVisibleFrame() const | 1183 Pane::getFirstVisibleFrame() const |
1183 { | 1184 { |
1184 int f0 = getFrameForX(m_scaleWidth); | 1185 sv_frame_t f0 = getFrameForX(m_scaleWidth); |
1185 int f = View::getFirstVisibleFrame(); | 1186 sv_frame_t f = View::getFirstVisibleFrame(); |
1186 if (f0 < 0 || f0 < long(f)) return f; | 1187 if (f0 < 0 || f0 < f) return f; |
1187 return f0; | 1188 return f0; |
1188 } | 1189 } |
1189 | 1190 |
1190 Selection | 1191 Selection |
1191 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const | 1192 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const |
1192 { | 1193 { |
1193 closeToLeftEdge = closeToRightEdge = false; | 1194 closeToLeftEdge = closeToRightEdge = false; |
1194 | 1195 |
1195 if (!m_manager) return Selection(); | 1196 if (!m_manager) return Selection(); |
1196 | 1197 |
1197 int testFrame = getFrameForX(x - 5); | 1198 sv_frame_t testFrame = getFrameForX(x - 5); |
1198 if (testFrame < 0) { | 1199 if (testFrame < 0) { |
1199 testFrame = getFrameForX(x); | 1200 testFrame = getFrameForX(x); |
1200 if (testFrame < 0) return Selection(); | 1201 if (testFrame < 0) return Selection(); |
1201 } | 1202 } |
1202 | 1203 |
1203 Selection selection = m_manager->getContainingSelection(testFrame, true); | 1204 Selection selection = m_manager->getContainingSelection(testFrame, true); |
1204 if (selection.isEmpty()) return selection; | 1205 if (selection.isEmpty()) return selection; |
1205 | 1206 |
1221 } | 1222 } |
1222 | 1223 |
1223 bool | 1224 bool |
1224 Pane::canTopLayerMoveVertical() | 1225 Pane::canTopLayerMoveVertical() |
1225 { | 1226 { |
1226 float vmin, vmax, dmin, dmax; | 1227 double vmin, vmax, dmin, dmax; |
1227 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false; | 1228 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false; |
1228 if (dmin <= vmin && dmax >= vmax) return false; | 1229 if (dmin <= vmin && dmax >= vmax) return false; |
1229 return true; | 1230 return true; |
1230 } | 1231 } |
1231 | 1232 |
1232 bool | 1233 bool |
1233 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax, | 1234 Pane::getTopLayerDisplayExtents(double &vmin, double &vmax, |
1234 float &dmin, float &dmax, | 1235 double &dmin, double &dmax, |
1235 QString *unit) | 1236 QString *unit) |
1236 { | 1237 { |
1237 Layer *layer = getTopLayer(); | 1238 Layer *layer = getTopLayer(); |
1238 if (!layer) return false; | 1239 if (!layer) return false; |
1239 bool vlog; | 1240 bool vlog; |
1243 if (unit) *unit = vunit; | 1244 if (unit) *unit = vunit; |
1244 return rv; | 1245 return rv; |
1245 } | 1246 } |
1246 | 1247 |
1247 bool | 1248 bool |
1248 Pane::setTopLayerDisplayExtents(float dmin, float dmax) | 1249 Pane::setTopLayerDisplayExtents(double dmin, double dmax) |
1249 { | 1250 { |
1250 Layer *layer = getTopLayer(); | 1251 Layer *layer = getTopLayer(); |
1251 if (!layer) return false; | 1252 if (!layer) return false; |
1252 return layer->setDisplayExtents(dmin, dmax); | 1253 return layer->setDisplayExtents(dmin, dmax); |
1253 } | 1254 } |
1329 | 1330 |
1330 m_navigating = true; | 1331 m_navigating = true; |
1331 m_dragCentreFrame = m_centreFrame; | 1332 m_dragCentreFrame = m_centreFrame; |
1332 m_dragStartMinValue = 0; | 1333 m_dragStartMinValue = 0; |
1333 | 1334 |
1334 float vmin, vmax, dmin, dmax; | 1335 double vmin, vmax, dmin, dmax; |
1335 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { | 1336 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { |
1336 m_dragStartMinValue = dmin; | 1337 m_dragStartMinValue = dmin; |
1337 } | 1338 } |
1338 | 1339 |
1339 if (m_followPlay == PlaybackScrollPage) { | 1340 if (m_followPlay == PlaybackScrollPage) { |
1364 m_manager->setInProgressSelection(selection, false); | 1365 m_manager->setInProgressSelection(selection, false); |
1365 m_resizing = true; | 1366 m_resizing = true; |
1366 | 1367 |
1367 } else { | 1368 } else { |
1368 | 1369 |
1369 int mouseFrame = getFrameForX(e->x()); | 1370 sv_frame_t mouseFrame = getFrameForX(e->x()); |
1370 int resolution = 1; | 1371 int resolution = 1; |
1371 int snapFrame = mouseFrame; | 1372 sv_frame_t snapFrame = mouseFrame; |
1372 | 1373 |
1373 Layer *layer = getInteractionLayer(); | 1374 Layer *layer = getInteractionLayer(); |
1374 if (layer && !m_shiftPressed) { | 1375 if (layer && !m_shiftPressed && |
1376 !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs | |
1375 layer->snapToFeatureFrame(this, snapFrame, | 1377 layer->snapToFeatureFrame(this, snapFrame, |
1376 resolution, Layer::SnapLeft); | 1378 resolution, Layer::SnapLeft); |
1377 } | 1379 } |
1378 | 1380 |
1379 if (snapFrame < 0) snapFrame = 0; | 1381 if (snapFrame < 0) snapFrame = 0; |
1435 | 1437 |
1436 emit paneInteractedWith(); | 1438 emit paneInteractedWith(); |
1437 } | 1439 } |
1438 | 1440 |
1439 void | 1441 void |
1440 Pane::schedulePlaybackFrameMove(int frame) | 1442 Pane::schedulePlaybackFrameMove(sv_frame_t frame) |
1441 { | 1443 { |
1442 m_playbackFrameMoveTo = frame; | 1444 m_playbackFrameMoveTo = frame; |
1443 m_playbackFrameMoveScheduled = true; | 1445 m_playbackFrameMoveScheduled = true; |
1444 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this, | 1446 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this, |
1445 SLOT(playbackScheduleTimerElapsed())); | 1447 SLOT(playbackScheduleTimerElapsed())); |
1470 | 1472 |
1471 if (m_clickedInRange) { | 1473 if (m_clickedInRange) { |
1472 mouseMoveEvent(e); | 1474 mouseMoveEvent(e); |
1473 } | 1475 } |
1474 | 1476 |
1475 int mouseFrame = e ? getFrameForX(e->x()) : 0; | 1477 sv_frame_t mouseFrame = e ? getFrameForX(e->x()) : 0; |
1476 if (mouseFrame < 0) mouseFrame = 0; | 1478 if (mouseFrame < 0) mouseFrame = 0; |
1477 | 1479 |
1478 if (m_navigating || mode == ViewManager::NavigateMode) { | 1480 if (m_navigating || mode == ViewManager::NavigateMode) { |
1479 | 1481 |
1480 m_navigating = false; | 1482 m_navigating = false; |
1742 | 1744 |
1743 } else { | 1745 } else { |
1744 | 1746 |
1745 if (!editSelectionDrag(e)) { | 1747 if (!editSelectionDrag(e)) { |
1746 | 1748 |
1747 Layer *layer = getInteractionLayer(); | 1749 Layer *layer = getTopFlexiNoteLayer(); |
1748 | 1750 |
1749 if (layer && layer->isLayerEditable()) { | 1751 if (layer) { |
1750 | 1752 |
1751 int x = e->x(); | 1753 int x = e->x(); |
1752 int y = e->y(); | 1754 int y = e->y(); |
1753 if (m_dragMode == VerticalDrag) x = m_clickPos.x(); | 1755 if (m_dragMode == VerticalDrag) x = m_clickPos.x(); |
1754 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y(); | 1756 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y(); |
1856 int x1 = r.x() + r.width(); | 1858 int x1 = r.x() + r.width(); |
1857 int y1 = r.y() + r.height(); | 1859 int y1 = r.y() + r.height(); |
1858 | 1860 |
1859 int w = x1 - x0; | 1861 int w = x1 - x0; |
1860 | 1862 |
1861 int newStartFrame = getFrameForX(x0); | 1863 sv_frame_t newStartFrame = getFrameForX(x0); |
1862 | 1864 |
1863 int visibleFrames = getEndFrame() - getStartFrame(); | 1865 sv_frame_t visibleFrames = getEndFrame() - getStartFrame(); |
1864 if (newStartFrame <= -visibleFrames) { | 1866 if (newStartFrame <= -visibleFrames) { |
1865 newStartFrame = -visibleFrames + 1; | 1867 newStartFrame = -visibleFrames + 1; |
1866 } | 1868 } |
1867 | 1869 |
1868 if (newStartFrame >= long(getModelsEndFrame())) { | 1870 if (newStartFrame >= getModelsEndFrame()) { |
1869 newStartFrame = getModelsEndFrame() - 1; | 1871 newStartFrame = getModelsEndFrame() - 1; |
1870 } | 1872 } |
1871 | 1873 |
1872 float ratio = float(w) / float(width()); | 1874 double ratio = double(w) / double(width()); |
1873 // cerr << "ratio: " << ratio << endl; | 1875 // cerr << "ratio: " << ratio << endl; |
1874 int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio); | 1876 int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio); |
1875 if (newZoomLevel < 1) newZoomLevel = 1; | 1877 if (newZoomLevel < 1) newZoomLevel = 1; |
1876 | 1878 |
1877 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl; | 1879 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl; |
1878 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); | 1880 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); |
1879 setStartFrame(newStartFrame); | 1881 setStartFrame(newStartFrame); |
1880 | 1882 |
1881 QString unit; | 1883 QString unit; |
1882 float min, max; | 1884 double min, max; |
1883 bool log; | 1885 bool log; |
1884 Layer *layer = 0; | 1886 Layer *layer = 0; |
1885 for (LayerList::const_iterator i = m_layerStack.begin(); | 1887 for (LayerList::const_iterator i = m_layerStack.begin(); |
1886 i != m_layerStack.end(); ++i) { | 1888 i != m_layerStack.end(); ++i) { |
1887 if ((*i)->getValueExtents(min, max, log, unit) && | 1889 if ((*i)->getValueExtents(min, max, log, unit) && |
1891 } | 1893 } |
1892 } | 1894 } |
1893 | 1895 |
1894 if (layer) { | 1896 if (layer) { |
1895 if (log) { | 1897 if (log) { |
1896 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min); | 1898 min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min); |
1897 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max); | 1899 max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max); |
1898 } | 1900 } |
1899 float rmin = min + ((max - min) * (height() - y1)) / height(); | 1901 double rmin = min + ((max - min) * (height() - y1)) / height(); |
1900 float rmax = min + ((max - min) * (height() - y0)) / height(); | 1902 double rmax = min + ((max - min) * (height() - y0)) / height(); |
1901 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl; | 1903 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl; |
1902 if (log) { | 1904 if (log) { |
1903 rmin = powf(10, rmin); | 1905 rmin = pow(10, rmin); |
1904 rmax = powf(10, rmax); | 1906 rmax = pow(10, rmax); |
1905 } | 1907 } |
1906 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl; | 1908 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl; |
1907 | 1909 |
1908 layer->setDisplayExtents(rmin, rmax); | 1910 layer->setDisplayExtents(rmin, rmax); |
1909 updateVerticalPanner(); | 1911 updateVerticalPanner(); |
1948 true); // resist vert | 1950 true); // resist vert |
1949 | 1951 |
1950 if (m_dragMode == HorizontalDrag || | 1952 if (m_dragMode == HorizontalDrag || |
1951 m_dragMode == FreeDrag) { | 1953 m_dragMode == FreeDrag) { |
1952 | 1954 |
1953 int frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); | 1955 sv_frame_t frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); |
1954 int newCentreFrame = m_dragCentreFrame; | 1956 sv_frame_t newCentreFrame = m_dragCentreFrame; |
1955 | 1957 |
1956 if (frameOff < 0) { | 1958 if (frameOff < 0) { |
1957 newCentreFrame -= frameOff; | 1959 newCentreFrame -= frameOff; |
1958 } else if (newCentreFrame >= frameOff) { | 1960 } else if (newCentreFrame >= frameOff) { |
1959 newCentreFrame -= frameOff; | 1961 newCentreFrame -= frameOff; |
1977 } | 1979 } |
1978 | 1980 |
1979 if (m_dragMode == VerticalDrag || | 1981 if (m_dragMode == VerticalDrag || |
1980 m_dragMode == FreeDrag) { | 1982 m_dragMode == FreeDrag) { |
1981 | 1983 |
1982 float vmin = 0.f, vmax = 0.f; | 1984 double vmin = 0.f, vmax = 0.f; |
1983 float dmin = 0.f, dmax = 0.f; | 1985 double dmin = 0.f, dmax = 0.f; |
1984 | 1986 |
1985 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { | 1987 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { |
1986 | 1988 |
1987 // cerr << "ydiff = " << ydiff << endl; | 1989 // cerr << "ydiff = " << ydiff << endl; |
1988 | 1990 |
1989 int ydiff = e->y() - m_clickPos.y(); | 1991 int ydiff = e->y() - m_clickPos.y(); |
1990 float perpix = (dmax - dmin) / height(); | 1992 double perpix = (dmax - dmin) / height(); |
1991 float valdiff = ydiff * perpix; | 1993 double valdiff = ydiff * perpix; |
1992 // cerr << "valdiff = " << valdiff << endl; | 1994 // cerr << "valdiff = " << valdiff << endl; |
1993 | 1995 |
1994 if (m_dragMode == UnresolvedDrag && ydiff != 0) { | 1996 if (m_dragMode == UnresolvedDrag && ydiff != 0) { |
1995 m_dragMode = VerticalDrag; | 1997 m_dragMode = VerticalDrag; |
1996 } | 1998 } |
1997 | 1999 |
1998 float newmin = m_dragStartMinValue + valdiff; | 2000 double newmin = m_dragStartMinValue + valdiff; |
1999 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; | 2001 double newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; |
2000 if (newmin < vmin) { | 2002 if (newmin < vmin) { |
2001 newmax += vmin - newmin; | 2003 newmax += vmin - newmin; |
2002 newmin += vmin - newmin; | 2004 newmin += vmin - newmin; |
2003 } | 2005 } |
2004 if (newmax > vmax) { | 2006 if (newmax > vmax) { |
2079 } | 2081 } |
2080 | 2082 |
2081 void | 2083 void |
2082 Pane::dragExtendSelection(QMouseEvent *e) | 2084 Pane::dragExtendSelection(QMouseEvent *e) |
2083 { | 2085 { |
2084 int mouseFrame = getFrameForX(e->x()); | 2086 sv_frame_t mouseFrame = getFrameForX(e->x()); |
2085 int resolution = 1; | 2087 int resolution = 1; |
2086 int snapFrameLeft = mouseFrame; | 2088 sv_frame_t snapFrameLeft = mouseFrame; |
2087 int snapFrameRight = mouseFrame; | 2089 sv_frame_t snapFrameRight = mouseFrame; |
2088 | 2090 |
2089 Layer *layer = getInteractionLayer(); | 2091 Layer *layer = getInteractionLayer(); |
2090 if (layer && !m_shiftPressed) { | 2092 if (layer && !m_shiftPressed && |
2093 !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs | |
2091 layer->snapToFeatureFrame(this, snapFrameLeft, | 2094 layer->snapToFeatureFrame(this, snapFrameLeft, |
2092 resolution, Layer::SnapLeft); | 2095 resolution, Layer::SnapLeft); |
2093 layer->snapToFeatureFrame(this, snapFrameRight, | 2096 layer->snapToFeatureFrame(this, snapFrameRight, |
2094 resolution, Layer::SnapRight); | 2097 resolution, Layer::SnapRight); |
2095 } | 2098 } |
2097 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl; | 2100 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl; |
2098 | 2101 |
2099 if (snapFrameLeft < 0) snapFrameLeft = 0; | 2102 if (snapFrameLeft < 0) snapFrameLeft = 0; |
2100 if (snapFrameRight < 0) snapFrameRight = 0; | 2103 if (snapFrameRight < 0) snapFrameRight = 0; |
2101 | 2104 |
2102 int min, max; | 2105 sv_frame_t min, max; |
2103 | 2106 |
2104 if (m_selectionStartFrame > snapFrameLeft) { | 2107 if (m_selectionStartFrame > snapFrameLeft) { |
2105 min = snapFrameLeft; | 2108 min = snapFrameLeft; |
2106 max = m_selectionStartFrame; | 2109 max = m_selectionStartFrame; |
2107 } else if (snapFrameRight > m_selectionStartFrame) { | 2110 } else if (snapFrameRight > m_selectionStartFrame) { |
2128 } | 2131 } |
2129 | 2132 |
2130 void | 2133 void |
2131 Pane::edgeScrollMaybe(int x) | 2134 Pane::edgeScrollMaybe(int x) |
2132 { | 2135 { |
2133 int mouseFrame = getFrameForX(x); | 2136 sv_frame_t mouseFrame = getFrameForX(x); |
2134 | 2137 |
2135 bool doScroll = false; | 2138 bool doScroll = false; |
2136 if (!m_manager) doScroll = true; | 2139 if (!m_manager) doScroll = true; |
2137 else if (!m_manager->isPlaying()) doScroll = true; | 2140 else if (!m_manager->isPlaying()) doScroll = true; |
2138 | 2141 |
2139 if (m_followPlay != PlaybackScrollContinuous) doScroll = true; | 2142 if (m_followPlay != PlaybackScrollContinuous) doScroll = true; |
2140 | 2143 |
2141 if (doScroll) { | 2144 if (doScroll) { |
2142 int offset = mouseFrame - getStartFrame(); | 2145 sv_frame_t offset = mouseFrame - getStartFrame(); |
2143 int available = getEndFrame() - getStartFrame(); | 2146 sv_frame_t available = getEndFrame() - getStartFrame(); |
2144 int move = 0; | 2147 sv_frame_t move = 0; |
2145 if (offset >= available * 0.95) { | 2148 if (offset >= double(available) * 0.95) { |
2146 move = int(offset - available * 0.95) + 1; | 2149 move = sv_frame_t(double(offset - available) * 0.95) + 1; |
2147 } else if (offset <= available * 0.10) { | 2150 } else if (offset <= double(available) * 0.10) { |
2148 move = int(available * 0.10 - offset) + 1; | 2151 move = sv_frame_t(double(available) * 0.10 - double(offset)) + 1; |
2149 move = -move; | 2152 move = -move; |
2150 } | 2153 } |
2151 if (move != 0) { | 2154 if (move != 0) { |
2152 setCentreFrame(m_centreFrame + move); | 2155 setCentreFrame(m_centreFrame + move); |
2153 update(); | 2156 update(); |
2154 } | 2157 } |
2201 update(); | 2204 update(); |
2202 } | 2205 } |
2203 | 2206 |
2204 if (relocate) { | 2207 if (relocate) { |
2205 | 2208 |
2206 int f = getFrameForX(e->x()); | 2209 sv_frame_t f = getFrameForX(e->x()); |
2207 | 2210 |
2208 setCentreFrame(f); | 2211 setCentreFrame(f); |
2209 | 2212 |
2210 m_dragCentreFrame = f; | 2213 m_dragCentreFrame = f; |
2211 m_dragStartMinValue = 0; | 2214 m_dragStartMinValue = 0; |
2212 m_dragMode = UnresolvedDrag; | 2215 m_dragMode = UnresolvedDrag; |
2213 | 2216 |
2214 float vmin, vmax, dmin, dmax; | 2217 double vmin, vmax, dmin, dmax; |
2215 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { | 2218 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { |
2216 m_dragStartMinValue = dmin; | 2219 m_dragStartMinValue = dmin; |
2217 } | 2220 } |
2218 } | 2221 } |
2219 | 2222 |
2470 } | 2473 } |
2471 | 2474 |
2472 void | 2475 void |
2473 Pane::verticalPannerMoved(float , float y0, float , float h) | 2476 Pane::verticalPannerMoved(float , float y0, float , float h) |
2474 { | 2477 { |
2475 float vmin, vmax, dmin, dmax; | 2478 double vmin, vmax, dmin, dmax; |
2476 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; | 2479 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; |
2477 float y1 = y0 + h; | 2480 double y1 = y0 + h; |
2478 float newmax = vmin + ((1.0 - y0) * (vmax - vmin)); | 2481 double newmax = vmin + ((1.0 - y0) * (vmax - vmin)); |
2479 float newmin = vmin + ((1.0 - y1) * (vmax - vmin)); | 2482 double newmin = vmin + ((1.0 - y1) * (vmax - vmin)); |
2480 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w | 2483 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w |
2481 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; | 2484 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; |
2482 setTopLayerDisplayExtents(newmin, newmax); | 2485 setTopLayerDisplayExtents(newmin, newmax); |
2483 } | 2486 } |
2484 | 2487 |
2485 void | 2488 void |
2486 Pane::editVerticalPannerExtents() | 2489 Pane::editVerticalPannerExtents() |
2487 { | 2490 { |
2488 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; | 2491 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; |
2489 | 2492 |
2490 float vmin, vmax, dmin, dmax; | 2493 double vmin, vmax, dmin, dmax; |
2491 QString unit; | 2494 QString unit; |
2492 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) | 2495 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) |
2493 || vmax == vmin) { | 2496 || vmax == vmin) { |
2494 return; | 2497 return; |
2495 } | 2498 } |
2496 | 2499 |
2497 RangeInputDialog dialog(tr("Enter new range"), | 2500 RangeInputDialog dialog(tr("Enter new range"), |
2498 tr("New vertical display range, from %1 to %2 %4:") | 2501 tr("New vertical display range, from %1 to %2 %4:") |
2499 .arg(vmin).arg(vmax).arg(unit), | 2502 .arg(vmin).arg(vmax).arg(unit), |
2500 unit, vmin, vmax, this); | 2503 unit, float(vmin), float(vmax), this); |
2501 dialog.setRange(dmin, dmax); | 2504 dialog.setRange(float(dmin), float(dmax)); |
2502 | 2505 |
2503 if (dialog.exec() == QDialog::Accepted) { | 2506 if (dialog.exec() == QDialog::Accepted) { |
2504 dialog.getRange(dmin, dmax); | 2507 float newmin, newmax; |
2505 setTopLayerDisplayExtents(dmin, dmax); | 2508 dialog.getRange(newmin, newmax); |
2509 setTopLayerDisplayExtents(newmin, newmax); | |
2506 updateVerticalPanner(); | 2510 updateVerticalPanner(); |
2507 } | 2511 } |
2508 } | 2512 } |
2509 | 2513 |
2510 void | 2514 void |
2606 } | 2610 } |
2607 | 2611 |
2608 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; | 2612 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; |
2609 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; | 2613 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; |
2610 | 2614 |
2611 int f0 = getFrameForX(p0); | 2615 sv_frame_t f0 = getFrameForX(p0); |
2612 int f1 = getFrameForX(p1); | 2616 sv_frame_t f1 = getFrameForX(p1); |
2613 | 2617 |
2614 Selection newSelection(f0, f1); | 2618 Selection newSelection(f0, f1); |
2615 | 2619 |
2616 if (m_editingSelectionEdge == 0) { | 2620 if (m_editingSelectionEdge == 0) { |
2617 | 2621 |