comparison view/Pane.cpp @ 1326:97c68bffbda6 zoom

More ZoomLevel updates
author Chris Cannam
date Thu, 20 Sep 2018 10:45:24 +0100
parents c0d8356e274f
children 4949061fcb8c
comparison
equal deleted inserted replaced
1325:bc2cb82050a0 1326:97c68bffbda6
199 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); 199 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
200 } 200 }
201 201
202 int count = 0; 202 int count = 0;
203 int current = 0; 203 int current = 0;
204 int level = 1; 204 ZoomLevel level;
205 205
206 //!!! pull out into function (presumably in View) 206 //!!! pull out into function (presumably in View)
207 bool haveConstraint = false; 207 bool haveConstraint = false;
208 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); 208 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end();
209 ++i) { 209 ++i) {
213 } 213 }
214 } 214 }
215 215
216 if (haveConstraint) { 216 if (haveConstraint) {
217 while (true) { 217 while (true) {
218 //!!! this won't terminate if level is in the PixelsPerFrame zone
218 if (getZoomLevel() == level) current = count; 219 if (getZoomLevel() == level) current = count;
219 int newLevel = getZoomConstraintBlockSize(level + 1, 220 ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(),
220 ZoomConstraint::RoundUp); 221 ZoomConstraint::RoundUp);
221 if (newLevel == level) break; 222 if (newLevel == level) break;
222 level = newLevel; 223 level = newLevel;
223 if (++count == 50) break; 224 if (++count == 50) break;
224 } 225 }
225 } else { 226 } else {
226 // if we have no particular constraints, we can really spread out 227 // if we have no particular constraints, we can really spread out
228 //!!! this is nonsense in PixelsPerFrame zone
227 while (true) { 229 while (true) {
230 using namespace std::rel_ops;
228 if (getZoomLevel() >= level) current = count; 231 if (getZoomLevel() >= level) current = count;
229 int step = level / 10; 232 int step = level.level / 10;
230 int pwr = 0; 233 int pwr = 0;
231 while (step > 0) { 234 while (step > 0) {
232 ++pwr; 235 ++pwr;
233 step /= 2; 236 step /= 2;
234 } 237 }
236 while (pwr > 0) { 239 while (pwr > 0) {
237 step *= 2; 240 step *= 2;
238 --pwr; 241 --pwr;
239 } 242 }
240 // cerr << level << endl; 243 // cerr << level << endl;
241 level += step; 244 level.level += step;
242 if (++count == 100 || level > 262144) break; 245 if (++count == 100 || level.level > 262144) break;
243 } 246 }
244 } 247 }
245 248
246 // cerr << "Have " << count << " zoom levels" << endl; 249 //!!!
250 SVCERR << "Have " << count << " zoom levels" << endl;
247 251
248 m_hthumb->setMinimumValue(0); 252 m_hthumb->setMinimumValue(0);
249 m_hthumb->setMaximumValue(count); 253 m_hthumb->setMaximumValue(count);
250 m_hthumb->setValue(count - current); 254 m_hthumb->setValue(count - current);
251 255
1143 } 1147 }
1144 1148
1145 QImage * 1149 QImage *
1146 Pane::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1) 1150 Pane::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1)
1147 { 1151 {
1148 int x0 = int(f0 / getZoomLevel()); 1152 int x0 = int(round(getZoomLevel().framesToPixels(double(f0))));
1149 int x1 = int(f1 / getZoomLevel()); 1153 int x1 = int(round(getZoomLevel().framesToPixels(double(f1))));
1150 1154
1151 QImage *image = new QImage(x1 - x0 + m_scaleWidth, 1155 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
1152 height(), QImage::Format_RGB32); 1156 height(), QImage::Format_RGB32);
1153 1157
1154 int formerScaleWidth = m_scaleWidth; 1158 int formerScaleWidth = m_scaleWidth;
1879 int x0 = r.x(); 1883 int x0 = r.x();
1880 int y0 = r.y(); 1884 int y0 = r.y();
1881 int x1 = r.x() + r.width(); 1885 int x1 = r.x() + r.width();
1882 int y1 = r.y() + r.height(); 1886 int y1 = r.y() + r.height();
1883 1887
1884 int w = x1 - x0;
1885
1886 sv_frame_t newStartFrame = getFrameForX(x0); 1888 sv_frame_t newStartFrame = getFrameForX(x0);
1889 sv_frame_t newEndFrame = getFrameForX(x1);
1890 sv_frame_t dist = newEndFrame - newStartFrame;
1887 1891
1888 sv_frame_t visibleFrames = getEndFrame() - getStartFrame(); 1892 sv_frame_t visibleFrames = getEndFrame() - getStartFrame();
1889 if (newStartFrame <= -visibleFrames) { 1893 if (newStartFrame <= -visibleFrames) {
1890 newStartFrame = -visibleFrames + 1; 1894 newStartFrame = -visibleFrames + 1;
1891 } 1895 }
1892 1896
1893 if (newStartFrame >= getModelsEndFrame()) { 1897 if (newStartFrame >= getModelsEndFrame()) {
1894 newStartFrame = getModelsEndFrame() - 1; 1898 newStartFrame = getModelsEndFrame() - 1;
1895 } 1899 }
1896 1900
1897 double ratio = double(w) / double(width()); 1901 ZoomLevel newZoomLevel = ZoomLevel::fromRatio(width(), dist);
1898 // cerr << "ratio: " << ratio << endl; 1902 setZoomLevel(getZoomConstraintLevel(newZoomLevel));
1899 int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio);
1900 if (newZoomLevel < 1) newZoomLevel = 1;
1901
1902 // cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl;
1903 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
1904 setStartFrame(newStartFrame); 1903 setStartFrame(newStartFrame);
1905 1904
1906 QString unit; 1905 QString unit;
1907 double min, max; 1906 double min, max;
1908 bool log; 1907 bool log;
2377 if (m_vthumb) { 2376 if (m_vthumb) {
2378 m_vthumb->scroll(sign > 0); 2377 m_vthumb->scroll(sign > 0);
2379 } 2378 }
2380 2379
2381 } else { 2380 } else {
2381 using namespace std::rel_ops;
2382 2382
2383 // Zoom in or out 2383 // Zoom in or out
2384 2384
2385 int newZoomLevel = m_zoomLevel; 2385 ZoomLevel newZoomLevel = m_zoomLevel;
2386 2386
2387 if (sign > 0) { 2387 if (sign > 0) {
2388 if (newZoomLevel <= 2) { 2388 newZoomLevel = getZoomConstraintLevel(newZoomLevel.decremented(),
2389 newZoomLevel = 1; 2389 ZoomConstraint::RoundDown);
2390 } else { 2390 } else {
2391 newZoomLevel = getZoomConstraintBlockSize 2391 newZoomLevel = getZoomConstraintLevel(newZoomLevel.incremented(),
2392 (newZoomLevel - 1, ZoomConstraint::RoundDown); 2392 ZoomConstraint::RoundUp);
2393 }
2394 } else { // sign < 0
2395 newZoomLevel = getZoomConstraintBlockSize
2396 (newZoomLevel + 1, ZoomConstraint::RoundUp);
2397 } 2393 }
2398 2394
2399 if (newZoomLevel != m_zoomLevel) { 2395 if (newZoomLevel != m_zoomLevel) {
2400 setZoomLevel(newZoomLevel); 2396 setZoomLevel(newZoomLevel);
2401 } 2397 }
2420 // cerr << "wheelHorizontalFine: pixels = " << pixels << endl; 2416 // cerr << "wheelHorizontalFine: pixels = " << pixels << endl;
2421 2417
2422 // Scroll left or right by a fixed number of pixels 2418 // Scroll left or right by a fixed number of pixels
2423 2419
2424 if (getStartFrame() < 0 && 2420 if (getStartFrame() < 0 &&
2425 getEndFrame() >= getModelsEndFrame()) return; 2421 getEndFrame() >= getModelsEndFrame()) {
2426 2422 return;
2427 int delta = (pixels * m_zoomLevel); 2423 }
2424
2425 int delta = int(round(m_zoomLevel.pixelsToFrames(pixels)));
2428 2426
2429 if (m_centreFrame < delta) { 2427 if (m_centreFrame < delta) {
2430 setCentreFrame(0); 2428 setCentreFrame(0);
2431 } else if (m_centreFrame - delta >= getModelsEndFrame()) { 2429 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
2432 setCentreFrame(getModelsEndFrame()); 2430 setCentreFrame(getModelsEndFrame());
2441 Pane::horizontalThumbwheelMoved(int value) 2439 Pane::horizontalThumbwheelMoved(int value)
2442 { 2440 {
2443 //!!! dupe with updateHeadsUpDisplay 2441 //!!! dupe with updateHeadsUpDisplay
2444 2442
2445 int count = 0; 2443 int count = 0;
2446 int level = 1; 2444 ZoomLevel level;
2447
2448 2445
2449 //!!! pull out into function (presumably in View) 2446 //!!! pull out into function (presumably in View)
2450 bool haveConstraint = false; 2447 bool haveConstraint = false;
2451 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); 2448 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end();
2452 ++i) { 2449 ++i) {
2456 } 2453 }
2457 } 2454 }
2458 2455
2459 if (haveConstraint) { 2456 if (haveConstraint) {
2460 while (true) { 2457 while (true) {
2458 //!!! this won't terminate if level is in the PixelsPerFrame zone
2461 if (m_hthumb->getMaximumValue() - value == count) break; 2459 if (m_hthumb->getMaximumValue() - value == count) break;
2462 int newLevel = getZoomConstraintBlockSize(level + 1, 2460 ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(),
2463 ZoomConstraint::RoundUp); 2461 ZoomConstraint::RoundUp);
2464 if (newLevel == level) break; 2462 if (newLevel == level) break;
2465 level = newLevel; 2463 level = newLevel;
2466 if (++count == 50) break; 2464 if (++count == 50) break;
2467 } 2465 }
2468 } else { 2466 } else {
2467 //!!! this is nonsense in PixelsPerFrame zone
2469 while (true) { 2468 while (true) {
2470 if (m_hthumb->getMaximumValue() - value == count) break; 2469 if (m_hthumb->getMaximumValue() - value == count) break;
2471 int step = level / 10; 2470 int step = level.level / 10;
2472 int pwr = 0; 2471 int pwr = 0;
2473 while (step > 0) { 2472 while (step > 0) {
2474 ++pwr; 2473 ++pwr;
2475 step /= 2; 2474 step /= 2;
2476 } 2475 }
2478 while (pwr > 0) { 2477 while (pwr > 0) {
2479 step *= 2; 2478 step *= 2;
2480 --pwr; 2479 --pwr;
2481 } 2480 }
2482 // cerr << level << endl; 2481 // cerr << level << endl;
2483 level += step; 2482 level.level += step;
2484 if (++count == 100 || level > 262144) break; 2483 if (++count == 100 || level.level > 262144) break;
2485 } 2484 }
2486 } 2485 }
2487 2486
2488 // cerr << "new level is " << level << endl; 2487 // cerr << "new level is " << level << endl;
2489 setZoomLevel(level); 2488 setZoomLevel(level);
2745 updateHeadsUpDisplay(); 2744 updateHeadsUpDisplay();
2746 update(); 2745 update();
2747 } 2746 }
2748 2747
2749 void 2748 void
2750 Pane::viewZoomLevelChanged(View *v, int z, bool locked) 2749 Pane::viewZoomLevelChanged(View *v, ZoomLevel z, bool locked)
2751 { 2750 {
2752 // cerr << "Pane[" << this << "]::zoomLevelChanged (global now " 2751 // cerr << "Pane[" << this << "]::zoomLevelChanged (global now "
2753 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl; 2752 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl;
2754 2753
2755 View::viewZoomLevelChanged(v, z, locked); 2754 View::viewZoomLevelChanged(v, z, locked);