comparison view/Pane.cpp @ 827:ea098f7565eb

Merge from branch tonioni
author Chris Cannam
date Fri, 18 Jul 2014 15:38:21 +0100
parents 43256b925e15
children 5acfb11e8aef
comparison
equal deleted inserted replaced
823:2d4af227fd32 827:ea098f7565eb
76 m_resizing(false), 76 m_resizing(false),
77 m_editing(false), 77 m_editing(false),
78 m_releasing(false), 78 m_releasing(false),
79 m_centreLineVisible(true), 79 m_centreLineVisible(true),
80 m_scaleWidth(0), 80 m_scaleWidth(0),
81 m_pendingWheelAngle(0),
81 m_headsUpDisplay(0), 82 m_headsUpDisplay(0),
82 m_vpan(0), 83 m_vpan(0),
83 m_hthumb(0), 84 m_hthumb(0),
84 m_vthumb(0), 85 m_vthumb(0),
85 m_reset(0), 86 m_reset(0),
2237 } 2238 }
2238 2239
2239 void 2240 void
2240 Pane::wheelEvent(QWheelEvent *e) 2241 Pane::wheelEvent(QWheelEvent *e)
2241 { 2242 {
2242 //cerr << "wheelEvent, delta " << e->delta() << endl; 2243 cerr << "wheelEvent, delta " << e->delta() << ", angleDelta " << e->angleDelta().x() << "," << e->angleDelta().y() << ", pixelDelta " << e->pixelDelta().x() << "," << e->pixelDelta().y() << ", modifiers " << e->modifiers() << endl;
2243 2244
2244 int count = e->delta(); 2245 int dx = e->angleDelta().x();
2245 2246 int dy = e->angleDelta().y();
2246 if (count > 0) { 2247
2247 if (count >= 120) count /= 120; 2248 if (dx == 0 && dy == 0) {
2248 else count = 1; 2249 return;
2249 } 2250 }
2250 2251
2251 if (count < 0) { 2252 int d = dy;
2252 if (count <= -120) count /= 120; 2253 bool horizontal = false;
2253 else count = -1; 2254
2254 } 2255 if (abs(dx) > abs(dy)) {
2255 2256 d = dx;
2256 if (e->modifiers() & Qt::ControlModifier) { 2257 horizontal = true;
2258 } else if (e->modifiers() & Qt::ControlModifier) {
2259 // treat a vertical wheel as horizontal
2260 horizontal = true;
2261 }
2262
2263 if (e->phase() == Qt::ScrollBegin ||
2264 fabs(d) >= 120 ||
2265 (d > 0 && m_pendingWheelAngle < 0) ||
2266 (d < 0 && m_pendingWheelAngle > 0)) {
2267 m_pendingWheelAngle = d;
2268 } else {
2269 m_pendingWheelAngle += d;
2270 }
2271
2272 if (horizontal && e->pixelDelta().x() != 0) {
2273
2274 // Have fine pixel information: use it
2275
2276 wheelHorizontalFine(e->pixelDelta().x(), e->modifiers());
2277
2278 m_pendingWheelAngle = 0;
2279
2280 } else {
2281
2282 // Coarse wheel information (or vertical zoom, which is
2283 // necessarily coarse itself)
2284
2285 while (abs(m_pendingWheelAngle) >= 120) {
2286
2287 int sign = (m_pendingWheelAngle < 0 ? -1 : 1);
2288
2289 if (horizontal) {
2290 wheelHorizontal(sign, e->modifiers());
2291 } else {
2292 wheelVertical(sign, e->modifiers());
2293 }
2294
2295 m_pendingWheelAngle -= sign * 120;
2296 }
2297 }
2298 }
2299
2300 void
2301 Pane::wheelVertical(int sign, Qt::KeyboardModifiers mods)
2302 {
2303 cerr << "wheelVertical: sign = " << sign << endl;
2304
2305 if (mods & Qt::ShiftModifier) {
2306
2307 // Pan vertically
2308
2309 if (m_vpan) {
2310 m_vpan->scroll(sign > 0);
2311 }
2312
2313 } else if (mods & Qt::AltModifier) {
2314
2315 // Zoom vertically
2316
2317 if (m_vthumb) {
2318 m_vthumb->scroll(sign > 0);
2319 }
2320
2321 } else {
2322
2323 // Zoom in or out
2324
2325 int newZoomLevel = m_zoomLevel;
2326
2327 if (sign > 0) {
2328 if (newZoomLevel <= 2) {
2329 newZoomLevel = 1;
2330 } else {
2331 newZoomLevel = getZoomConstraintBlockSize
2332 (newZoomLevel - 1, ZoomConstraint::RoundDown);
2333 }
2334 } else { // sign < 0
2335 newZoomLevel = getZoomConstraintBlockSize
2336 (newZoomLevel + 1, ZoomConstraint::RoundUp);
2337 }
2338
2339 if (newZoomLevel != m_zoomLevel) {
2340 setZoomLevel(newZoomLevel);
2341 }
2342 }
2343
2344 emit paneInteractedWith();
2345 }
2346
2347 void
2348 Pane::wheelHorizontal(int sign, Qt::KeyboardModifiers mods)
2349 {
2350 cerr << "wheelHorizontal: sign = " << sign << endl;
2257 2351
2258 // Scroll left or right, rapidly 2352 // Scroll left or right, rapidly
2353
2354 wheelHorizontalFine((width() / 4) * sign, mods);
2355 }
2356
2357 void
2358 Pane::wheelHorizontalFine(int pixels, Qt::KeyboardModifiers)
2359 {
2360 cerr << "wheelHorizontalFine: pixels = " << pixels << endl;
2361
2362 // Scroll left or right by a fixed number of pixels
2259 2363
2260 if (getStartFrame() < 0 && 2364 if (getStartFrame() < 0 &&
2261 getEndFrame() >= getModelsEndFrame()) return; 2365 getEndFrame() >= getModelsEndFrame()) return;
2262 2366
2263 int delta = ((width() / 2) * count * m_zoomLevel); 2367 int delta = (pixels * m_zoomLevel);
2264 2368
2265 if (m_centreFrame < delta) { 2369 if (m_centreFrame < delta) {
2266 setCentreFrame(0); 2370 setCentreFrame(0);
2267 } else if (m_centreFrame - delta >= getModelsEndFrame()) { 2371 } else if (m_centreFrame - delta >= getModelsEndFrame()) {
2268 setCentreFrame(getModelsEndFrame()); 2372 setCentreFrame(getModelsEndFrame());
2269 } else { 2373 } else {
2270 setCentreFrame(m_centreFrame - delta); 2374 setCentreFrame(m_centreFrame - delta);
2271 }
2272
2273 } else if (e->modifiers() & Qt::ShiftModifier) {
2274
2275 // Zoom vertically
2276
2277 if (m_vpan) {
2278 m_vpan->scroll(e->delta() > 0);
2279 }
2280
2281 } else if (e->modifiers() & Qt::AltModifier) {
2282
2283 // Zoom vertically
2284
2285 if (m_vthumb) {
2286 m_vthumb->scroll(e->delta() > 0);
2287 }
2288
2289 } else {
2290
2291 // Zoom in or out
2292
2293 int newZoomLevel = m_zoomLevel;
2294
2295 while (count > 0) {
2296 if (newZoomLevel <= 2) {
2297 newZoomLevel = 1;
2298 break;
2299 }
2300 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
2301 ZoomConstraint::RoundDown);
2302 --count;
2303 }
2304
2305 while (count < 0) {
2306 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
2307 ZoomConstraint::RoundUp);
2308 ++count;
2309 }
2310
2311 if (newZoomLevel != m_zoomLevel) {
2312 setZoomLevel(newZoomLevel);
2313 }
2314 } 2375 }
2315 2376
2316 emit paneInteractedWith(); 2377 emit paneInteractedWith();
2317 } 2378 }
2318 2379