comparison view/Pane.cpp @ 684:917039d333bb tonioni

Merge from default branch
author Chris Cannam
date Tue, 26 Nov 2013 14:38:48 +0000
parents 1a0fdad4af4d 692a8b9804fe
children 084fd76deb89
comparison
equal deleted inserted replaced
680:ced5f158eda7 684:917039d333bb
56 56
57 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget 57 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget
58 58
59 //#define DEBUG_PANE 59 //#define DEBUG_PANE
60 60
61 using std::cerr; 61
62 using std::endl; 62
63 63
64 QCursor *Pane::m_measureCursor1 = 0; 64 QCursor *Pane::m_measureCursor1 = 0;
65 QCursor *Pane::m_measureCursor2 = 0; 65 QCursor *Pane::m_measureCursor2 = 0;
66 66
67 Pane::Pane(QWidget *w) : 67 Pane::Pane(QWidget *w) :
113 if (newLevel == 131072) break; //!!! just because 113 if (newLevel == 131072) break; //!!! just because
114 level = newLevel; 114 level = newLevel;
115 ++count; 115 ++count;
116 } 116 }
117 117
118 std::cerr << "Have " << count+1 << " zoom levels" << std::endl; 118 cerr << "Have " << count+1 << " zoom levels" << endl;
119 */ 119 */
120 120
121 Layer *layer = 0; 121 Layer *layer = 0;
122 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); 122 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
123 123
226 step = 1; 226 step = 1;
227 while (pwr > 0) { 227 while (pwr > 0) {
228 step *= 2; 228 step *= 2;
229 --pwr; 229 --pwr;
230 } 230 }
231 // std::cerr << level << std::endl; 231 // cerr << level << endl;
232 level += step; 232 level += step;
233 if (++count == 100 || level > 262144) break; 233 if (++count == 100 || level > 262144) break;
234 } 234 }
235 } 235 }
236 236
237 // std::cerr << "Have " << count << " zoom levels" << std::endl; 237 // cerr << "Have " << count << " zoom levels" << endl;
238 238
239 m_hthumb->setMinimumValue(0); 239 m_hthumb->setMinimumValue(0);
240 m_hthumb->setMaximumValue(count); 240 m_hthumb->setMaximumValue(count);
241 m_hthumb->setValue(count - current); 241 m_hthumb->setValue(count - current);
242 242
243 // std::cerr << "set value to " << count-current << std::endl; 243 // cerr << "set value to " << count-current << endl;
244 244
245 // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl; 245 // cerr << "default value is " << m_hthumb->getDefaultValue() << endl;
246 246
247 if (count != 50 && m_hthumb->getDefaultValue() == 0) { 247 if (count != 50 && m_hthumb->getDefaultValue() == 0) {
248 m_hthumb->setDefaultValue(count - current); 248 m_hthumb->setDefaultValue(count - current);
249 // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl; 249 // cerr << "set default value to " << m_hthumb->getDefaultValue() << endl;
250 } 250 }
251 251
252 bool haveVThumb = false; 252 bool haveVThumb = false;
253 253
254 if (layer) { 254 if (layer) {
264 m_vthumb->setMaximumValue(max); 264 m_vthumb->setMaximumValue(max);
265 m_vthumb->setDefaultValue(defaultStep); 265 m_vthumb->setDefaultValue(defaultStep);
266 m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); 266 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
267 m_vthumb->blockSignals(false); 267 m_vthumb->blockSignals(false);
268 268
269 // std::cerr << "Vertical thumbwheel: min 0, max " << max 269 // cerr << "Vertical thumbwheel: min 0, max " << max
270 // << ", default " << defaultStep << ", value " 270 // << ", default " << defaultStep << ", value "
271 // << m_vthumb->getValue() << std::endl; 271 // << m_vthumb->getValue() << endl;
272 272
273 } 273 }
274 } 274 }
275 275
276 updateVerticalPanner(); 276 updateVerticalPanner();
777 bool down) 777 bool down)
778 { 778 {
779 const Model *reference = model->getAlignmentReference(); 779 const Model *reference = model->getAlignmentReference();
780 /* 780 /*
781 if (!reference) { 781 if (!reference) {
782 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << std::endl; 782 cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl;
783 } else if (reference == model) { 783 } else if (reference == model) {
784 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << std::endl; 784 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl;
785 } else { 785 } else {
786 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << std::endl; 786 cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl;
787 } 787 }
788 */ 788 */
789 QString text; 789 QString text;
790 int completion = 100; 790 int completion = 100;
791 791
881 881
882 QStringList texts; 882 QStringList texts;
883 std::vector<QPixmap> pixmaps; 883 std::vector<QPixmap> pixmaps;
884 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { 884 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
885 texts.push_back((*i)->getLayerPresentationName()); 885 texts.push_back((*i)->getLayerPresentationName());
886 // std::cerr << "Pane " << this << ": Layer presentation name for " << *i << ": " 886 // cerr << "Pane " << this << ": Layer presentation name for " << *i << ": "
887 // << texts[texts.size()-1] << std::endl; 887 // << texts[texts.size()-1] << endl;
888 pixmaps.push_back((*i)->getLayerPresentationPixmap 888 pixmaps.push_back((*i)->getLayerPresentationPixmap
889 (QSize(fontAscent, fontAscent))); 889 (QSize(fontAscent, fontAscent)));
890 } 890 }
891 891
892 int maxTextWidth = width() / 3; 892 int maxTextWidth = width() / 3;
899 899
900 if (r.x() + r.width() >= llx - fontAscent - 3) { 900 if (r.x() + r.width() >= llx - fontAscent - 3) {
901 901
902 for (size_t i = 0; i < texts.size(); ++i) { 902 for (size_t i = 0; i < texts.size(); ++i) {
903 903
904 // std::cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << std::endl; 904 // cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << endl;
905 905
906 if (i + 1 == texts.size()) { 906 if (i + 1 == texts.size()) {
907 paint.setPen(getForeground()); 907 paint.setPen(getForeground());
908 } 908 }
909 909
1281 emit contextHelpChanged(""); 1281 emit contextHelpChanged("");
1282 emit rightButtonMenuRequested(mapToGlobal(e->pos())); 1282 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
1283 return; 1283 return;
1284 } 1284 }
1285 1285
1286 // std::cerr << "mousePressEvent" << std::endl; 1286 // cerr << "mousePressEvent" << endl;
1287 1287
1288 m_clickPos = e->pos(); 1288 m_clickPos = e->pos();
1289 m_mousePos = m_clickPos; 1289 m_mousePos = m_clickPos;
1290 m_clickedInRange = true; 1290 m_clickedInRange = true;
1291 m_editingSelection = Selection(); 1291 m_editingSelection = Selection();
1410 { 1410 {
1411 if (e->buttons() & Qt::RightButton) { 1411 if (e->buttons() & Qt::RightButton) {
1412 return; 1412 return;
1413 } 1413 }
1414 1414
1415 // std::cerr << "mouseReleaseEvent" << std::endl; 1415 // cerr << "mouseReleaseEvent" << endl;
1416 1416
1417 ViewManager::ToolMode mode = ViewManager::NavigateMode; 1417 ViewManager::ToolMode mode = ViewManager::NavigateMode;
1418 if (m_manager) mode = m_manager->getToolMode(); 1418 if (m_manager) mode = m_manager->getToolMode();
1419 1419
1420 m_releasing = true; 1420 m_releasing = true;
1536 { 1536 {
1537 if (e->buttons() & Qt::RightButton) { 1537 if (e->buttons() & Qt::RightButton) {
1538 return; 1538 return;
1539 } 1539 }
1540 1540
1541 // std::cerr << "mouseMoveEvent" << std::endl; 1541 // cerr << "mouseMoveEvent" << endl;
1542 1542
1543 QPoint pos = e->pos(); 1543 QPoint pos = e->pos();
1544 updateContextHelp(&pos); 1544 updateContextHelp(&pos);
1545 1545
1546 if (m_navigating && m_clickedInRange && !m_releasing) { 1546 if (m_navigating && m_clickedInRange && !m_releasing) {
1806 if (newStartFrame >= long(getModelsEndFrame())) { 1806 if (newStartFrame >= long(getModelsEndFrame())) {
1807 newStartFrame = getModelsEndFrame() - 1; 1807 newStartFrame = getModelsEndFrame() - 1;
1808 } 1808 }
1809 1809
1810 float ratio = float(w) / float(width()); 1810 float ratio = float(w) / float(width());
1811 // std::cerr << "ratio: " << ratio << std::endl; 1811 // cerr << "ratio: " << ratio << endl;
1812 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio); 1812 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
1813 if (newZoomLevel < 1) newZoomLevel = 1; 1813 if (newZoomLevel < 1) newZoomLevel = 1;
1814 1814
1815 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; 1815 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl;
1816 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); 1816 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
1817 setStartFrame(newStartFrame); 1817 setStartFrame(newStartFrame);
1818 1818
1819 QString unit; 1819 QString unit;
1820 float min, max; 1820 float min, max;
1834 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min); 1834 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
1835 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max); 1835 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
1836 } 1836 }
1837 float rmin = min + ((max - min) * (height() - y1)) / height(); 1837 float rmin = min + ((max - min) * (height() - y1)) / height();
1838 float rmax = min + ((max - min) * (height() - y0)) / height(); 1838 float rmax = min + ((max - min) * (height() - y0)) / height();
1839 std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl; 1839 cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl;
1840 if (log) { 1840 if (log) {
1841 rmin = powf(10, rmin); 1841 rmin = powf(10, rmin);
1842 rmax = powf(10, rmax); 1842 rmax = powf(10, rmax);
1843 } 1843 }
1844 std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << std::endl; 1844 cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl;
1845 1845
1846 layer->setDisplayExtents(rmin, rmax); 1846 layer->setDisplayExtents(rmin, rmax);
1847 updateVerticalPanner(); 1847 updateVerticalPanner();
1848 } 1848 }
1849 } 1849 }
1921 float vmin = 0.f, vmax = 0.f; 1921 float vmin = 0.f, vmax = 0.f;
1922 float dmin = 0.f, dmax = 0.f; 1922 float dmin = 0.f, dmax = 0.f;
1923 1923
1924 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { 1924 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
1925 1925
1926 // std::cerr << "ydiff = " << ydiff << std::endl; 1926 // cerr << "ydiff = " << ydiff << endl;
1927 1927
1928 int ydiff = e->y() - m_clickPos.y(); 1928 int ydiff = e->y() - m_clickPos.y();
1929 float perpix = (dmax - dmin) / height(); 1929 float perpix = (dmax - dmin) / height();
1930 float valdiff = ydiff * perpix; 1930 float valdiff = ydiff * perpix;
1931 // std::cerr << "valdiff = " << valdiff << std::endl; 1931 // cerr << "valdiff = " << valdiff << endl;
1932 1932
1933 if (m_dragMode == UnresolvedDrag && ydiff != 0) { 1933 if (m_dragMode == UnresolvedDrag && ydiff != 0) {
1934 m_dragMode = VerticalDrag; 1934 m_dragMode = VerticalDrag;
1935 } 1935 }
1936 1936
1942 } 1942 }
1943 if (newmax > vmax) { 1943 if (newmax > vmax) {
1944 newmin -= newmax - vmax; 1944 newmin -= newmax - vmax;
1945 newmax -= newmax - vmax; 1945 newmax -= newmax - vmax;
1946 } 1946 }
1947 // std::cerr << "(" << dmin << ", " << dmax << ") -> (" 1947 // cerr << "(" << dmin << ", " << dmax << ") -> ("
1948 // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl; 1948 // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << endl;
1949 1949
1950 setTopLayerDisplayExtents(newmin, newmax); 1950 setTopLayerDisplayExtents(newmin, newmax);
1951 updateVerticalPanner(); 1951 updateVerticalPanner();
1952 } 1952 }
1953 } 1953 }
2025 layer->snapToFeatureFrame(this, snapFrameLeft, 2025 layer->snapToFeatureFrame(this, snapFrameLeft,
2026 resolution, Layer::SnapLeft); 2026 resolution, Layer::SnapLeft);
2027 layer->snapToFeatureFrame(this, snapFrameRight, 2027 layer->snapToFeatureFrame(this, snapFrameRight,
2028 resolution, Layer::SnapRight); 2028 resolution, Layer::SnapRight);
2029 } 2029 }
2030 2030
2031 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; 2031 // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl;
2032 2032
2033 if (snapFrameLeft < 0) snapFrameLeft = 0; 2033 if (snapFrameLeft < 0) snapFrameLeft = 0;
2034 if (snapFrameRight < 0) snapFrameRight = 0; 2034 if (snapFrameRight < 0) snapFrameRight = 0;
2035 2035
2036 size_t min, max; 2036 size_t min, max;
2089 { 2089 {
2090 if (e->buttons() & Qt::RightButton) { 2090 if (e->buttons() & Qt::RightButton) {
2091 return; 2091 return;
2092 } 2092 }
2093 2093
2094 // std::cerr << "mouseDoubleClickEvent" << std::endl; 2094 // cerr << "mouseDoubleClickEvent" << endl;
2095 2095
2096 m_clickPos = e->pos(); 2096 m_clickPos = e->pos();
2097 m_clickedInRange = true; 2097 m_clickedInRange = true;
2098 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); 2098 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
2099 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); 2099 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
2170 } 2170 }
2171 2171
2172 void 2172 void
2173 Pane::wheelEvent(QWheelEvent *e) 2173 Pane::wheelEvent(QWheelEvent *e)
2174 { 2174 {
2175 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; 2175 //cerr << "wheelEvent, delta " << e->delta() << endl;
2176 2176
2177 int count = e->delta(); 2177 int count = e->delta();
2178 2178
2179 if (count > 0) { 2179 if (count > 0) {
2180 if (count >= 120) count /= 120; 2180 if (count >= 120) count /= 120;
2289 step = 1; 2289 step = 1;
2290 while (pwr > 0) { 2290 while (pwr > 0) {
2291 step *= 2; 2291 step *= 2;
2292 --pwr; 2292 --pwr;
2293 } 2293 }
2294 // std::cerr << level << std::endl; 2294 // cerr << level << endl;
2295 level += step; 2295 level += step;
2296 if (++count == 100 || level > 262144) break; 2296 if (++count == 100 || level > 262144) break;
2297 } 2297 }
2298 } 2298 }
2299 2299
2300 // std::cerr << "new level is " << level << std::endl; 2300 // cerr << "new level is " << level << endl;
2301 setZoomLevel(level); 2301 setZoomLevel(level);
2302 } 2302 }
2303 2303
2304 void 2304 void
2305 Pane::verticalThumbwheelMoved(int value) 2305 Pane::verticalThumbwheelMoved(int value)
2327 float vmin, vmax, dmin, dmax; 2327 float vmin, vmax, dmin, dmax;
2328 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; 2328 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
2329 float y1 = y0 + h; 2329 float y1 = y0 + h;
2330 float newmax = vmin + ((1.0 - y0) * (vmax - vmin)); 2330 float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
2331 float newmin = vmin + ((1.0 - y1) * (vmax - vmin)); 2331 float newmin = vmin + ((1.0 - y1) * (vmax - vmin));
2332 // std::cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w 2332 // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
2333 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << std::endl; 2333 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl;
2334 setTopLayerDisplayExtents(newmin, newmax); 2334 setTopLayerDisplayExtents(newmin, newmax);
2335 } 2335 }
2336 2336
2337 void 2337 void
2338 Pane::editVerticalPannerExtents() 2338 Pane::editVerticalPannerExtents()
2368 2368
2369 void 2369 void
2370 Pane::dragEnterEvent(QDragEnterEvent *e) 2370 Pane::dragEnterEvent(QDragEnterEvent *e)
2371 { 2371 {
2372 QStringList formats(e->mimeData()->formats()); 2372 QStringList formats(e->mimeData()->formats());
2373 std::cerr << "dragEnterEvent: format: " 2373 cerr << "dragEnterEvent: format: "
2374 << formats.join(",").toStdString() 2374 << formats.join(",")
2375 << ", possibleActions: " << e->possibleActions() 2375 << ", possibleActions: " << e->possibleActions()
2376 << ", proposedAction: " << e->proposedAction() << std::endl; 2376 << ", proposedAction: " << e->proposedAction() << endl;
2377 2377
2378 if (e->mimeData()->hasFormat("text/uri-list") || 2378 if (e->mimeData()->hasFormat("text/uri-list") ||
2379 e->mimeData()->hasFormat("text/plain")) { 2379 e->mimeData()->hasFormat("text/plain")) {
2380 2380
2381 if (e->proposedAction() & Qt::CopyAction) { 2381 if (e->proposedAction() & Qt::CopyAction) {
2388 } 2388 }
2389 2389
2390 void 2390 void
2391 Pane::dropEvent(QDropEvent *e) 2391 Pane::dropEvent(QDropEvent *e)
2392 { 2392 {
2393 std::cerr << "dropEvent: text: \"" << e->mimeData()->text().toStdString() 2393 cerr << "dropEvent: text: \"" << e->mimeData()->text()
2394 << "\"" << std::endl; 2394 << "\"" << endl;
2395 2395
2396 if (e->mimeData()->hasFormat("text/uri-list") || 2396 if (e->mimeData()->hasFormat("text/uri-list") ||
2397 e->mimeData()->hasFormat("text/plain")) { 2397 e->mimeData()->hasFormat("text/plain")) {
2398 2398
2399 if (e->proposedAction() & Qt::CopyAction) { 2399 if (e->proposedAction() & Qt::CopyAction) {
2558 } 2558 }
2559 2559
2560 void 2560 void
2561 Pane::viewZoomLevelChanged(View *v, unsigned long z, bool locked) 2561 Pane::viewZoomLevelChanged(View *v, unsigned long z, bool locked)
2562 { 2562 {
2563 // std::cerr << "Pane[" << this << "]::zoomLevelChanged (global now " 2563 // cerr << "Pane[" << this << "]::zoomLevelChanged (global now "
2564 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << std::endl; 2564 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl;
2565 2565
2566 View::viewZoomLevelChanged(v, z, locked); 2566 View::viewZoomLevelChanged(v, z, locked);
2567 2567
2568 if (m_hthumb && !m_hthumb->isVisible()) return; 2568 if (m_hthumb && !m_hthumb->isVisible()) return;
2569 2569