Mercurial > hg > svgui
comparison view/Pane.cpp @ 1354:40b9a495a0e0
Use zoom constraints more consistently, including the new RelativelyFine one
| author | Chris Cannam |
|---|---|
| date | Wed, 10 Oct 2018 14:33:10 +0100 |
| parents | 4949061fcb8c |
| children | b9bfcb8cd5a1 |
comparison
equal
deleted
inserted
replaced
| 1353:86429ff00f05 | 1354:40b9a495a0e0 |
|---|---|
| 108 { | 108 { |
| 109 Profiler profiler("Pane::updateHeadsUpDisplay"); | 109 Profiler profiler("Pane::updateHeadsUpDisplay"); |
| 110 | 110 |
| 111 if (!isVisible()) return; | 111 if (!isVisible()) return; |
| 112 | 112 |
| 113 /* | |
| 114 int count = 0; | |
| 115 int currentLevel = 1; | |
| 116 int level = 1; | |
| 117 while (true) { | |
| 118 if (getZoomLevel() == level) currentLevel = count; | |
| 119 int newLevel = getZoomConstraintBlockSize(level + 1, | |
| 120 ZoomConstraint::RoundUp); | |
| 121 if (newLevel == level) break; | |
| 122 if (newLevel == 131072) break; //!!! just because | |
| 123 level = newLevel; | |
| 124 ++count; | |
| 125 } | |
| 126 | |
| 127 cerr << "Have " << count+1 << " zoom levels" << endl; | |
| 128 */ | |
| 129 | |
| 130 Layer *layer = 0; | 113 Layer *layer = 0; |
| 131 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); | 114 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); |
| 132 | 115 |
| 133 if (!m_headsUpDisplay) { | 116 if (!m_headsUpDisplay) { |
| 134 | 117 |
| 197 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault())); | 180 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault())); |
| 198 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 181 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); |
| 199 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 182 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); |
| 200 } | 183 } |
| 201 | 184 |
| 202 int count = 0; | 185 int count = countZoomLevels(); |
| 203 int current = 0; | 186 int current = getZoomLevelIndex(getZoomLevel()); |
| 204 ZoomLevel level; | 187 |
| 205 | 188 m_hthumb->setMinimumValue(1); |
| 206 //!!! pull out into function (presumably in View) | |
| 207 bool haveConstraint = false; | |
| 208 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); | |
| 209 ++i) { | |
| 210 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { | |
| 211 haveConstraint = true; | |
| 212 break; | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 SVCERR << "haveConstraint = " << haveConstraint << endl; | |
| 217 | |
| 218 if (haveConstraint) { | |
| 219 while (true) { | |
| 220 //!!! this won't terminate if level is in the PixelsPerFrame zone | |
| 221 if (getZoomLevel() == level) current = count; | |
| 222 ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), | |
| 223 ZoomConstraint::RoundUp); | |
| 224 SVCERR << "newLevel = " << newLevel << endl; | |
| 225 if (newLevel == level) break; | |
| 226 level = newLevel; | |
| 227 if (++count == 50) break; | |
| 228 } | |
| 229 } else { | |
| 230 // if we have no particular constraints, we can really spread out | |
| 231 //!!! this is nonsense in PixelsPerFrame zone | |
| 232 while (true) { | |
| 233 using namespace std::rel_ops; | |
| 234 if (getZoomLevel() >= level) current = count; | |
| 235 int step = level.level / 10; | |
| 236 int pwr = 0; | |
| 237 while (step > 0) { | |
| 238 ++pwr; | |
| 239 step /= 2; | |
| 240 } | |
| 241 step = 1; | |
| 242 while (pwr > 0) { | |
| 243 step *= 2; | |
| 244 --pwr; | |
| 245 } | |
| 246 cerr << level.level << ", step " << step << endl; | |
| 247 level.level += step; | |
| 248 if (++count == 100 || level.level > 262144) break; | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 //!!! | |
| 253 SVCERR << "Have " << count << " zoom levels" << endl; | |
| 254 | |
| 255 m_hthumb->setMinimumValue(0); | |
| 256 m_hthumb->setMaximumValue(count); | 189 m_hthumb->setMaximumValue(count); |
| 257 m_hthumb->setValue(count - current); | 190 m_hthumb->setValue(count - current); |
| 258 | 191 |
| 259 // cerr << "set value to " << count-current << endl; | 192 cerr << "set value to " << count - 1 - current << endl; |
| 260 | 193 |
| 261 // cerr << "default value is " << m_hthumb->getDefaultValue() << endl; | 194 cerr << "default value is " << m_hthumb->getDefaultValue() << endl; |
| 262 | 195 |
| 263 if (count != 50 && m_hthumb->getDefaultValue() == 0) { | 196 if (m_hthumb->getDefaultValue() == 0) { |
| 264 m_hthumb->setDefaultValue(count - current); | 197 m_hthumb->setDefaultValue(count - current); |
| 265 // cerr << "set default value to " << m_hthumb->getDefaultValue() << endl; | 198 cerr << "set default value to " << m_hthumb->getDefaultValue() << endl; |
| 266 } | 199 } |
| 267 | 200 |
| 268 bool haveVThumb = false; | 201 bool haveVThumb = false; |
| 269 | 202 |
| 270 if (layer) { | 203 if (layer) { |
| 2439 } | 2372 } |
| 2440 | 2373 |
| 2441 void | 2374 void |
| 2442 Pane::horizontalThumbwheelMoved(int value) | 2375 Pane::horizontalThumbwheelMoved(int value) |
| 2443 { | 2376 { |
| 2444 //!!! dupe with updateHeadsUpDisplay | 2377 cerr << "horizontalThumbwheelMoved(" << value << ")" << endl; |
| 2445 | 2378 |
| 2446 int count = 0; | 2379 ZoomLevel level = getZoomLevelByIndex |
| 2447 ZoomLevel level; | 2380 (m_hthumb->getMaximumValue() - value); |
| 2448 | 2381 |
| 2449 //!!! pull out into function (presumably in View) | 2382 cerr << "new level is " << level << endl; |
| 2450 bool haveConstraint = false; | |
| 2451 for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); | |
| 2452 ++i) { | |
| 2453 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { | |
| 2454 haveConstraint = true; | |
| 2455 break; | |
| 2456 } | |
| 2457 } | |
| 2458 | |
| 2459 if (haveConstraint) { | |
| 2460 while (true) { | |
| 2461 //!!! this won't terminate if level is in the PixelsPerFrame zone | |
| 2462 if (m_hthumb->getMaximumValue() - value == count) break; | |
| 2463 ZoomLevel newLevel = getZoomConstraintLevel(level.incremented(), | |
| 2464 ZoomConstraint::RoundUp); | |
| 2465 if (newLevel == level) break; | |
| 2466 level = newLevel; | |
| 2467 if (++count == 50) break; | |
| 2468 } | |
| 2469 } else { | |
| 2470 //!!! this is nonsense in PixelsPerFrame zone | |
| 2471 while (true) { | |
| 2472 if (m_hthumb->getMaximumValue() - value == count) break; | |
| 2473 int step = level.level / 10; | |
| 2474 int pwr = 0; | |
| 2475 while (step > 0) { | |
| 2476 ++pwr; | |
| 2477 step /= 2; | |
| 2478 } | |
| 2479 step = 1; | |
| 2480 while (pwr > 0) { | |
| 2481 step *= 2; | |
| 2482 --pwr; | |
| 2483 } | |
| 2484 // cerr << level << endl; | |
| 2485 level.level += step; | |
| 2486 if (++count == 100 || level.level > 262144) break; | |
| 2487 } | |
| 2488 } | |
| 2489 | |
| 2490 // cerr << "new level is " << level << endl; | |
| 2491 setZoomLevel(level); | 2383 setZoomLevel(level); |
| 2492 } | 2384 } |
| 2493 | 2385 |
| 2494 void | 2386 void |
| 2495 Pane::verticalThumbwheelMoved(int value) | 2387 Pane::verticalThumbwheelMoved(int value) |
