comparison view/Pane.cpp @ 944:78c152e4db95

Merge from branch tonioni
author Chris Cannam
date Mon, 20 Apr 2015 09:12:17 +0100
parents 3fb91da7d98d
children 36cddc3de023 e297b7d752f2
comparison
equal deleted inserted replaced
896:78e041e45ff0 944:78c152e4db95
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 int fontHeight = paint.fontMetrics().height(); 720 int fontHeight = paint.fontMetrics().height();
720 int fontAscent = paint.fontMetrics().ascent(); 721 int fontAscent = paint.fontMetrics().ascent();
721 722
722 QColor c = QColor(0, 0, 0); 723 QColor c = QColor(0, 0, 0);
967 void 968 void
968 Pane::drawEditingSelection(QPainter &paint) 969 Pane::drawEditingSelection(QPainter &paint)
969 { 970 {
970 int offset = m_mousePos.x() - m_clickPos.x(); 971 int offset = m_mousePos.x() - m_clickPos.x();
971 972
972 int origStart = m_editingSelection.getStartFrame(); 973 sv_frame_t origStart = m_editingSelection.getStartFrame();
973 974
974 int p0 = getXForFrame(origStart) + offset; 975 int p0 = getXForFrame(origStart) + offset;
975 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; 976 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
976 977
977 if (m_editingSelectionEdge < 0) { 978 if (m_editingSelectionEdge < 0) {
978 p1 = getXForFrame(m_editingSelection.getEndFrame()); 979 p1 = getXForFrame(m_editingSelection.getEndFrame());
979 } else if (m_editingSelectionEdge > 0) { 980 } else if (m_editingSelectionEdge > 0) {
980 p0 = getXForFrame(m_editingSelection.getStartFrame()); 981 p0 = getXForFrame(m_editingSelection.getStartFrame());
981 } 982 }
982 983
983 int newStart = getFrameForX(p0); 984 sv_frame_t newStart = getFrameForX(p0);
984 int newEnd = getFrameForX(p1); 985 sv_frame_t newEnd = getFrameForX(p1);
985 986
986 paint.save(); 987 paint.save();
987 paint.setPen(QPen(getForeground(), 2)); 988 paint.setPen(QPen(getForeground(), 2));
988 989
989 int fontHeight = paint.fontMetrics().height(); 990 int fontHeight = paint.fontMetrics().height();
990 int fontAscent = paint.fontMetrics().ascent(); 991 int fontAscent = paint.fontMetrics().ascent();
991 int sampleRate = getModelsSampleRate(); 992 sv_samplerate_t sampleRate = getModelsSampleRate();
992 QString startText, endText, offsetText; 993 QString startText, endText, offsetText;
993 startText = QString("%1").arg(newStart); 994 startText = QString("%1").arg(newStart);
994 endText = QString("%1").arg(newEnd); 995 endText = QString("%1").arg(newEnd);
995 offsetText = QString("%1").arg(newStart - origStart); 996 offsetText = QString("%1").arg(newStart - origStart);
996 if (newStart >= origStart) { 997 if (newStart >= origStart) {
1035 paint.restore(); 1036 paint.restore();
1036 } 1037 }
1037 1038
1038 void 1039 void
1039 Pane::drawDurationAndRate(QRect r, const Model *waveformModel, 1040 Pane::drawDurationAndRate(QRect r, const Model *waveformModel,
1040 int sampleRate, QPainter &paint) 1041 sv_samplerate_t sampleRate, QPainter &paint)
1041 { 1042 {
1042 int fontHeight = paint.fontMetrics().height(); 1043 int fontHeight = paint.fontMetrics().height();
1043 int fontAscent = paint.fontMetrics().ascent(); 1044 int fontAscent = paint.fontMetrics().ascent();
1044 1045
1045 if (r.y() + r.height() < height() - fontHeight - 6) return; 1046 if (r.y() + r.height() < height() - fontHeight - 6) return;
1046 1047
1047 int modelRate = waveformModel->getSampleRate(); 1048 sv_samplerate_t modelRate = waveformModel->getSampleRate();
1048 int nativeRate = waveformModel->getNativeRate(); 1049 sv_samplerate_t nativeRate = waveformModel->getNativeRate();
1049 int playbackRate = m_manager->getPlaybackSampleRate(); 1050 sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate();
1050 int outputRate = m_manager->getOutputSampleRate(); 1051 sv_samplerate_t outputRate = m_manager->getOutputSampleRate();
1051 1052
1052 QString srNote = ""; 1053 QString srNote = "";
1053 1054
1054 // Show (R) for waveform models that have been resampled or will 1055 // Show (R) for waveform models that have been resampled or will
1055 // be resampled on playback, and (X) for waveform models that will 1056 // be resampled on playback, and (X) for waveform models that will
1084 desc, OutlinedText); 1085 desc, OutlinedText);
1085 } 1086 }
1086 } 1087 }
1087 1088
1088 bool 1089 bool
1089 Pane::render(QPainter &paint, int xorigin, int f0, int f1) 1090 Pane::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1)
1090 { 1091 {
1091 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) { 1092 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) {
1092 return false; 1093 return false;
1093 } 1094 }
1094 1095
1115 1116
1116 return true; 1117 return true;
1117 } 1118 }
1118 1119
1119 QImage * 1120 QImage *
1120 Pane::toNewImage(int f0, int f1) 1121 Pane::toNewImage(sv_frame_t f0, sv_frame_t f1)
1121 { 1122 {
1122 int x0 = f0 / getZoomLevel(); 1123 int x0 = int(f0 / getZoomLevel());
1123 int x1 = f1 / getZoomLevel(); 1124 int x1 = int(f1 / getZoomLevel());
1124 1125
1125 QImage *image = new QImage(x1 - x0 + m_scaleWidth, 1126 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
1126 height(), QImage::Format_RGB32); 1127 height(), QImage::Format_RGB32);
1127 1128
1128 int formerScaleWidth = m_scaleWidth; 1129 int formerScaleWidth = m_scaleWidth;
1154 return image; 1155 return image;
1155 } 1156 }
1156 } 1157 }
1157 1158
1158 QSize 1159 QSize
1159 Pane::getImageSize(int f0, int f1) 1160 Pane::getImageSize(sv_frame_t f0, sv_frame_t f1)
1160 { 1161 {
1161 QSize s = View::getImageSize(f0, f1); 1162 QSize s = View::getImageSize(f0, f1);
1162 QImage *image = new QImage(100, 100, QImage::Format_RGB32); 1163 QImage *image = new QImage(100, 100, QImage::Format_RGB32);
1163 QPainter paint(image); 1164 QPainter paint(image);
1164 1165
1172 } 1173 }
1173 1174
1174 return QSize(sw + s.width(), s.height()); 1175 return QSize(sw + s.width(), s.height());
1175 } 1176 }
1176 1177
1177 int 1178 sv_frame_t
1178 Pane::getFirstVisibleFrame() const 1179 Pane::getFirstVisibleFrame() const
1179 { 1180 {
1180 int f0 = getFrameForX(m_scaleWidth); 1181 sv_frame_t f0 = getFrameForX(m_scaleWidth);
1181 int f = View::getFirstVisibleFrame(); 1182 sv_frame_t f = View::getFirstVisibleFrame();
1182 if (f0 < 0 || f0 < long(f)) return f; 1183 if (f0 < 0 || f0 < f) return f;
1183 return f0; 1184 return f0;
1184 } 1185 }
1185 1186
1186 Selection 1187 Selection
1187 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const 1188 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
1188 { 1189 {
1189 closeToLeftEdge = closeToRightEdge = false; 1190 closeToLeftEdge = closeToRightEdge = false;
1190 1191
1191 if (!m_manager) return Selection(); 1192 if (!m_manager) return Selection();
1192 1193
1193 int testFrame = getFrameForX(x - 5); 1194 sv_frame_t testFrame = getFrameForX(x - 5);
1194 if (testFrame < 0) { 1195 if (testFrame < 0) {
1195 testFrame = getFrameForX(x); 1196 testFrame = getFrameForX(x);
1196 if (testFrame < 0) return Selection(); 1197 if (testFrame < 0) return Selection();
1197 } 1198 }
1198 1199
1199 Selection selection = m_manager->getContainingSelection(testFrame, true); 1200 Selection selection = m_manager->getContainingSelection(testFrame, true);
1200 if (selection.isEmpty()) return selection; 1201 if (selection.isEmpty()) return selection;
1201 1202
1217 } 1218 }
1218 1219
1219 bool 1220 bool
1220 Pane::canTopLayerMoveVertical() 1221 Pane::canTopLayerMoveVertical()
1221 { 1222 {
1222 float vmin, vmax, dmin, dmax; 1223 double vmin, vmax, dmin, dmax;
1223 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false; 1224 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false;
1224 if (dmin <= vmin && dmax >= vmax) return false; 1225 if (dmin <= vmin && dmax >= vmax) return false;
1225 return true; 1226 return true;
1226 } 1227 }
1227 1228
1228 bool 1229 bool
1229 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax, 1230 Pane::getTopLayerDisplayExtents(double &vmin, double &vmax,
1230 float &dmin, float &dmax, 1231 double &dmin, double &dmax,
1231 QString *unit) 1232 QString *unit)
1232 { 1233 {
1233 Layer *layer = getTopLayer(); 1234 Layer *layer = getTopLayer();
1234 if (!layer) return false; 1235 if (!layer) return false;
1235 bool vlog; 1236 bool vlog;
1239 if (unit) *unit = vunit; 1240 if (unit) *unit = vunit;
1240 return rv; 1241 return rv;
1241 } 1242 }
1242 1243
1243 bool 1244 bool
1244 Pane::setTopLayerDisplayExtents(float dmin, float dmax) 1245 Pane::setTopLayerDisplayExtents(double dmin, double dmax)
1245 { 1246 {
1246 Layer *layer = getTopLayer(); 1247 Layer *layer = getTopLayer();
1247 if (!layer) return false; 1248 if (!layer) return false;
1248 return layer->setDisplayExtents(dmin, dmax); 1249 return layer->setDisplayExtents(dmin, dmax);
1249 } 1250 }
1325 1326
1326 m_navigating = true; 1327 m_navigating = true;
1327 m_dragCentreFrame = m_centreFrame; 1328 m_dragCentreFrame = m_centreFrame;
1328 m_dragStartMinValue = 0; 1329 m_dragStartMinValue = 0;
1329 1330
1330 float vmin, vmax, dmin, dmax; 1331 double vmin, vmax, dmin, dmax;
1331 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { 1332 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
1332 m_dragStartMinValue = dmin; 1333 m_dragStartMinValue = dmin;
1333 } 1334 }
1334 1335
1335 if (m_followPlay == PlaybackScrollPage) { 1336 if (m_followPlay == PlaybackScrollPage) {
1360 m_manager->setInProgressSelection(selection, false); 1361 m_manager->setInProgressSelection(selection, false);
1361 m_resizing = true; 1362 m_resizing = true;
1362 1363
1363 } else { 1364 } else {
1364 1365
1365 int mouseFrame = getFrameForX(e->x()); 1366 sv_frame_t mouseFrame = getFrameForX(e->x());
1366 int resolution = 1; 1367 int resolution = 1;
1367 int snapFrame = mouseFrame; 1368 sv_frame_t snapFrame = mouseFrame;
1368 1369
1369 Layer *layer = getInteractionLayer(); 1370 Layer *layer = getInteractionLayer();
1370 if (layer && !m_shiftPressed) { 1371 if (layer && !m_shiftPressed &&
1372 !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs
1371 layer->snapToFeatureFrame(this, snapFrame, 1373 layer->snapToFeatureFrame(this, snapFrame,
1372 resolution, Layer::SnapLeft); 1374 resolution, Layer::SnapLeft);
1373 } 1375 }
1374 1376
1375 if (snapFrame < 0) snapFrame = 0; 1377 if (snapFrame < 0) snapFrame = 0;
1431 1433
1432 emit paneInteractedWith(); 1434 emit paneInteractedWith();
1433 } 1435 }
1434 1436
1435 void 1437 void
1436 Pane::schedulePlaybackFrameMove(int frame) 1438 Pane::schedulePlaybackFrameMove(sv_frame_t frame)
1437 { 1439 {
1438 m_playbackFrameMoveTo = frame; 1440 m_playbackFrameMoveTo = frame;
1439 m_playbackFrameMoveScheduled = true; 1441 m_playbackFrameMoveScheduled = true;
1440 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this, 1442 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this,
1441 SLOT(playbackScheduleTimerElapsed())); 1443 SLOT(playbackScheduleTimerElapsed()));
1466 1468
1467 if (m_clickedInRange) { 1469 if (m_clickedInRange) {
1468 mouseMoveEvent(e); 1470 mouseMoveEvent(e);
1469 } 1471 }
1470 1472
1471 int mouseFrame = e ? getFrameForX(e->x()) : 0; 1473 sv_frame_t mouseFrame = e ? getFrameForX(e->x()) : 0;
1472 if (mouseFrame < 0) mouseFrame = 0; 1474 if (mouseFrame < 0) mouseFrame = 0;
1473 1475
1474 if (m_navigating || mode == ViewManager::NavigateMode) { 1476 if (m_navigating || mode == ViewManager::NavigateMode) {
1475 1477
1476 m_navigating = false; 1478 m_navigating = false;
1738 1740
1739 } else { 1741 } else {
1740 1742
1741 if (!editSelectionDrag(e)) { 1743 if (!editSelectionDrag(e)) {
1742 1744
1743 Layer *layer = getInteractionLayer(); 1745 Layer *layer = getTopFlexiNoteLayer();
1744 1746
1745 if (layer && layer->isLayerEditable()) { 1747 if (layer) {
1746 1748
1747 int x = e->x(); 1749 int x = e->x();
1748 int y = e->y(); 1750 int y = e->y();
1749 if (m_dragMode == VerticalDrag) x = m_clickPos.x(); 1751 if (m_dragMode == VerticalDrag) x = m_clickPos.x();
1750 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y(); 1752 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y();
1852 int x1 = r.x() + r.width(); 1854 int x1 = r.x() + r.width();
1853 int y1 = r.y() + r.height(); 1855 int y1 = r.y() + r.height();
1854 1856
1855 int w = x1 - x0; 1857 int w = x1 - x0;
1856 1858
1857 int newStartFrame = getFrameForX(x0); 1859 sv_frame_t newStartFrame = getFrameForX(x0);
1858 1860
1859 int visibleFrames = getEndFrame() - getStartFrame(); 1861 sv_frame_t visibleFrames = getEndFrame() - getStartFrame();
1860 if (newStartFrame <= -visibleFrames) { 1862 if (newStartFrame <= -visibleFrames) {
1861 newStartFrame = -visibleFrames + 1; 1863 newStartFrame = -visibleFrames + 1;
1862 } 1864 }
1863 1865
1864 if (newStartFrame >= long(getModelsEndFrame())) { 1866 if (newStartFrame >= getModelsEndFrame()) {
1865 newStartFrame = getModelsEndFrame() - 1; 1867 newStartFrame = getModelsEndFrame() - 1;
1866 } 1868 }
1867 1869
1868 float ratio = float(w) / float(width()); 1870 double ratio = double(w) / double(width());
1869 // cerr << "ratio: " << ratio << endl; 1871 // cerr << "ratio: " << ratio << endl;
1870 int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio); 1872 int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio);
1871 if (newZoomLevel < 1) newZoomLevel = 1; 1873 if (newZoomLevel < 1) newZoomLevel = 1;
1872 1874
1873 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl; 1875 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl;
1874 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); 1876 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
1875 setStartFrame(newStartFrame); 1877 setStartFrame(newStartFrame);
1876 1878
1877 QString unit; 1879 QString unit;
1878 float min, max; 1880 double min, max;
1879 bool log; 1881 bool log;
1880 Layer *layer = 0; 1882 Layer *layer = 0;
1881 for (LayerList::const_iterator i = m_layerStack.begin(); 1883 for (LayerList::const_iterator i = m_layerStack.begin();
1882 i != m_layerStack.end(); ++i) { 1884 i != m_layerStack.end(); ++i) {
1883 if ((*i)->getValueExtents(min, max, log, unit) && 1885 if ((*i)->getValueExtents(min, max, log, unit) &&
1887 } 1889 }
1888 } 1890 }
1889 1891
1890 if (layer) { 1892 if (layer) {
1891 if (log) { 1893 if (log) {
1892 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min); 1894 min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min);
1893 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max); 1895 max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max);
1894 } 1896 }
1895 float rmin = min + ((max - min) * (height() - y1)) / height(); 1897 double rmin = min + ((max - min) * (height() - y1)) / height();
1896 float rmax = min + ((max - min) * (height() - y0)) / height(); 1898 double rmax = min + ((max - min) * (height() - y0)) / height();
1897 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl; 1899 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl;
1898 if (log) { 1900 if (log) {
1899 rmin = powf(10, rmin); 1901 rmin = pow(10, rmin);
1900 rmax = powf(10, rmax); 1902 rmax = pow(10, rmax);
1901 } 1903 }
1902 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl; 1904 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl;
1903 1905
1904 layer->setDisplayExtents(rmin, rmax); 1906 layer->setDisplayExtents(rmin, rmax);
1905 updateVerticalPanner(); 1907 updateVerticalPanner();
1944 !(m_manager && m_manager->isPlaying())); // resist vert 1946 !(m_manager && m_manager->isPlaying())); // resist vert
1945 1947
1946 if (m_dragMode == HorizontalDrag || 1948 if (m_dragMode == HorizontalDrag ||
1947 m_dragMode == FreeDrag) { 1949 m_dragMode == FreeDrag) {
1948 1950
1949 int frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); 1951 sv_frame_t frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
1950 int newCentreFrame = m_dragCentreFrame; 1952 sv_frame_t newCentreFrame = m_dragCentreFrame;
1951 1953
1952 if (frameOff < 0) { 1954 if (frameOff < 0) {
1953 newCentreFrame -= frameOff; 1955 newCentreFrame -= frameOff;
1954 } else if (newCentreFrame >= frameOff) { 1956 } else if (newCentreFrame >= frameOff) {
1955 newCentreFrame -= frameOff; 1957 newCentreFrame -= frameOff;
1973 } 1975 }
1974 1976
1975 if (m_dragMode == VerticalDrag || 1977 if (m_dragMode == VerticalDrag ||
1976 m_dragMode == FreeDrag) { 1978 m_dragMode == FreeDrag) {
1977 1979
1978 float vmin = 0.f, vmax = 0.f; 1980 double vmin = 0.f, vmax = 0.f;
1979 float dmin = 0.f, dmax = 0.f; 1981 double dmin = 0.f, dmax = 0.f;
1980 1982
1981 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { 1983 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
1982 1984
1983 // cerr << "ydiff = " << ydiff << endl; 1985 // cerr << "ydiff = " << ydiff << endl;
1984 1986
1985 int ydiff = e->y() - m_clickPos.y(); 1987 int ydiff = e->y() - m_clickPos.y();
1986 float perpix = (dmax - dmin) / height(); 1988 double perpix = (dmax - dmin) / height();
1987 float valdiff = ydiff * perpix; 1989 double valdiff = ydiff * perpix;
1988 // cerr << "valdiff = " << valdiff << endl; 1990 // cerr << "valdiff = " << valdiff << endl;
1989 1991
1990 if (m_dragMode == UnresolvedDrag && ydiff != 0) { 1992 if (m_dragMode == UnresolvedDrag && ydiff != 0) {
1991 m_dragMode = VerticalDrag; 1993 m_dragMode = VerticalDrag;
1992 } 1994 }
1993 1995
1994 float newmin = m_dragStartMinValue + valdiff; 1996 double newmin = m_dragStartMinValue + valdiff;
1995 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; 1997 double newmax = m_dragStartMinValue + (dmax - dmin) + valdiff;
1996 if (newmin < vmin) { 1998 if (newmin < vmin) {
1997 newmax += vmin - newmin; 1999 newmax += vmin - newmin;
1998 newmin += vmin - newmin; 2000 newmin += vmin - newmin;
1999 } 2001 }
2000 if (newmax > vmax) { 2002 if (newmax > vmax) {
2075 } 2077 }
2076 2078
2077 void 2079 void
2078 Pane::dragExtendSelection(QMouseEvent *e) 2080 Pane::dragExtendSelection(QMouseEvent *e)
2079 { 2081 {
2080 int mouseFrame = getFrameForX(e->x()); 2082 sv_frame_t mouseFrame = getFrameForX(e->x());
2081 int resolution = 1; 2083 int resolution = 1;
2082 int snapFrameLeft = mouseFrame; 2084 sv_frame_t snapFrameLeft = mouseFrame;
2083 int snapFrameRight = mouseFrame; 2085 sv_frame_t snapFrameRight = mouseFrame;
2084 2086
2085 Layer *layer = getInteractionLayer(); 2087 Layer *layer = getInteractionLayer();
2086 if (layer && !m_shiftPressed) { 2088 if (layer && !m_shiftPressed &&
2089 !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs
2087 layer->snapToFeatureFrame(this, snapFrameLeft, 2090 layer->snapToFeatureFrame(this, snapFrameLeft,
2088 resolution, Layer::SnapLeft); 2091 resolution, Layer::SnapLeft);
2089 layer->snapToFeatureFrame(this, snapFrameRight, 2092 layer->snapToFeatureFrame(this, snapFrameRight,
2090 resolution, Layer::SnapRight); 2093 resolution, Layer::SnapRight);
2091 } 2094 }
2093 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl; 2096 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl;
2094 2097
2095 if (snapFrameLeft < 0) snapFrameLeft = 0; 2098 if (snapFrameLeft < 0) snapFrameLeft = 0;
2096 if (snapFrameRight < 0) snapFrameRight = 0; 2099 if (snapFrameRight < 0) snapFrameRight = 0;
2097 2100
2098 int min, max; 2101 sv_frame_t min, max;
2099 2102
2100 if (m_selectionStartFrame > snapFrameLeft) { 2103 if (m_selectionStartFrame > snapFrameLeft) {
2101 min = snapFrameLeft; 2104 min = snapFrameLeft;
2102 max = m_selectionStartFrame; 2105 max = m_selectionStartFrame;
2103 } else if (snapFrameRight > m_selectionStartFrame) { 2106 } else if (snapFrameRight > m_selectionStartFrame) {
2124 } 2127 }
2125 2128
2126 void 2129 void
2127 Pane::edgeScrollMaybe(int x) 2130 Pane::edgeScrollMaybe(int x)
2128 { 2131 {
2129 int mouseFrame = getFrameForX(x); 2132 sv_frame_t mouseFrame = getFrameForX(x);
2130 2133
2131 bool doScroll = false; 2134 bool doScroll = false;
2132 if (!m_manager) doScroll = true; 2135 if (!m_manager) doScroll = true;
2133 else if (!m_manager->isPlaying()) doScroll = true; 2136 else if (!m_manager->isPlaying()) doScroll = true;
2134 2137
2135 if (m_followPlay != PlaybackScrollContinuous) doScroll = true; 2138 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
2136 2139
2137 if (doScroll) { 2140 if (doScroll) {
2138 int offset = mouseFrame - getStartFrame(); 2141 sv_frame_t offset = mouseFrame - getStartFrame();
2139 int available = getEndFrame() - getStartFrame(); 2142 sv_frame_t available = getEndFrame() - getStartFrame();
2140 int move = 0; 2143 sv_frame_t move = 0;
2141 if (offset >= available * 0.95) { 2144 if (offset >= double(available) * 0.95) {
2142 move = int(offset - available * 0.95) + 1; 2145 move = sv_frame_t(double(offset - available) * 0.95) + 1;
2143 } else if (offset <= available * 0.10) { 2146 } else if (offset <= double(available) * 0.10) {
2144 move = int(available * 0.10 - offset) + 1; 2147 move = sv_frame_t(double(available) * 0.10 - double(offset)) + 1;
2145 move = -move; 2148 move = -move;
2146 } 2149 }
2147 if (move != 0) { 2150 if (move != 0) {
2148 setCentreFrame(m_centreFrame + move); 2151 setCentreFrame(m_centreFrame + move);
2149 update(); 2152 update();
2150 } 2153 }
2197 update(); 2200 update();
2198 } 2201 }
2199 2202
2200 if (relocate) { 2203 if (relocate) {
2201 2204
2202 int f = getFrameForX(e->x()); 2205 sv_frame_t f = getFrameForX(e->x());
2203 2206
2204 setCentreFrame(f); 2207 setCentreFrame(f);
2205 2208
2206 m_dragCentreFrame = f; 2209 m_dragCentreFrame = f;
2207 m_dragStartMinValue = 0; 2210 m_dragStartMinValue = 0;
2208 m_dragMode = UnresolvedDrag; 2211 m_dragMode = UnresolvedDrag;
2209 2212
2210 float vmin, vmax, dmin, dmax; 2213 double vmin, vmax, dmin, dmax;
2211 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { 2214 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
2212 m_dragStartMinValue = dmin; 2215 m_dragStartMinValue = dmin;
2213 } 2216 }
2214 } 2217 }
2215 2218
2291 // Coarse wheel information (or vertical zoom, which is 2294 // Coarse wheel information (or vertical zoom, which is
2292 // necessarily coarse itself) 2295 // necessarily coarse itself)
2293 2296
2294 // Sometimes on Linux we're seeing absurdly extreme angles on 2297 // Sometimes on Linux we're seeing absurdly extreme angles on
2295 // the first wheel event -- discard those entirely 2298 // the first wheel event -- discard those entirely
2296 if (abs(m_pendingWheelAngle) > 1000) { 2299 if (abs(m_pendingWheelAngle) >= 600) {
2297 m_pendingWheelAngle = 0; 2300 m_pendingWheelAngle = 0;
2298 return; 2301 return;
2299 } 2302 }
2300 2303
2301 while (abs(m_pendingWheelAngle) >= 120) { 2304 while (abs(m_pendingWheelAngle) >= 120) {
2466 } 2469 }
2467 2470
2468 void 2471 void
2469 Pane::verticalPannerMoved(float , float y0, float , float h) 2472 Pane::verticalPannerMoved(float , float y0, float , float h)
2470 { 2473 {
2471 float vmin, vmax, dmin, dmax; 2474 double vmin, vmax, dmin, dmax;
2472 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; 2475 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
2473 float y1 = y0 + h; 2476 double y1 = y0 + h;
2474 float newmax = vmin + ((1.0 - y0) * (vmax - vmin)); 2477 double newmax = vmin + ((1.0 - y0) * (vmax - vmin));
2475 float newmin = vmin + ((1.0 - y1) * (vmax - vmin)); 2478 double newmin = vmin + ((1.0 - y1) * (vmax - vmin));
2476 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w 2479 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
2477 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; 2480 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl;
2478 setTopLayerDisplayExtents(newmin, newmax); 2481 setTopLayerDisplayExtents(newmin, newmax);
2479 } 2482 }
2480 2483
2481 void 2484 void
2482 Pane::editVerticalPannerExtents() 2485 Pane::editVerticalPannerExtents()
2483 { 2486 {
2484 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; 2487 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
2485 2488
2486 float vmin, vmax, dmin, dmax; 2489 double vmin, vmax, dmin, dmax;
2487 QString unit; 2490 QString unit;
2488 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) 2491 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)
2489 || vmax == vmin) { 2492 || vmax == vmin) {
2490 return; 2493 return;
2491 } 2494 }
2492 2495
2493 RangeInputDialog dialog(tr("Enter new range"), 2496 RangeInputDialog dialog(tr("Enter new range"),
2494 tr("New vertical display range, from %1 to %2 %4:") 2497 tr("New vertical display range, from %1 to %2 %4:")
2495 .arg(vmin).arg(vmax).arg(unit), 2498 .arg(vmin).arg(vmax).arg(unit),
2496 unit, vmin, vmax, this); 2499 unit, float(vmin), float(vmax), this);
2497 dialog.setRange(dmin, dmax); 2500 dialog.setRange(float(dmin), float(dmax));
2498 2501
2499 if (dialog.exec() == QDialog::Accepted) { 2502 if (dialog.exec() == QDialog::Accepted) {
2500 dialog.getRange(dmin, dmax); 2503 float newmin, newmax;
2501 setTopLayerDisplayExtents(dmin, dmax); 2504 dialog.getRange(newmin, newmax);
2505 setTopLayerDisplayExtents(newmin, newmax);
2502 updateVerticalPanner(); 2506 updateVerticalPanner();
2503 } 2507 }
2504 } 2508 }
2505 2509
2506 void 2510 void
2602 } 2606 }
2603 2607
2604 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; 2608 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
2605 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; 2609 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
2606 2610
2607 int f0 = getFrameForX(p0); 2611 sv_frame_t f0 = getFrameForX(p0);
2608 int f1 = getFrameForX(p1); 2612 sv_frame_t f1 = getFrameForX(p1);
2609 2613
2610 Selection newSelection(f0, f1); 2614 Selection newSelection(f0, f1);
2611 2615
2612 if (m_editingSelectionEdge == 0) { 2616 if (m_editingSelectionEdge == 0) {
2613 2617