annotate widgets/Pane.cpp @ 17:0183ebb725ca

* Add ability to create empty layers for editing * Add first basic editing capability (adding points to a time instant layer) * Add various keyboard and mouse shortcuts for navigation &c * Add ability to resize a selection by dragging its edges * Add maximum zoom level
author Chris Cannam
date Thu, 26 Jan 2006 16:15:40 +0000
parents 4d5d9aba406b
children 7c767d41bcee
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@5 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "widgets/Pane.h"
Chris@0 11 #include "base/Layer.h"
Chris@0 12 #include "base/Model.h"
Chris@0 13 #include "base/ZoomConstraint.h"
Chris@0 14 #include "base/RealTime.h"
Chris@0 15 #include "base/Profiler.h"
Chris@13 16 #include "base/ViewManager.h"
Chris@0 17
Chris@0 18 #include <QPaintEvent>
Chris@0 19 #include <QPainter>
Chris@0 20 #include <iostream>
Chris@0 21 #include <cmath>
Chris@0 22
Chris@0 23 using std::cerr;
Chris@0 24 using std::endl;
Chris@0 25
Chris@0 26 Pane::Pane(QWidget *w) :
Chris@0 27 View(w, true),
Chris@0 28 m_identifyFeatures(false),
Chris@0 29 m_clickedInRange(false),
Chris@0 30 m_shiftPressed(false),
Chris@13 31 m_ctrlPressed(false),
Chris@17 32 m_navigating(false),
Chris@17 33 m_resizing(false),
Chris@0 34 m_centreLineVisible(true)
Chris@0 35 {
Chris@0 36 setObjectName("Pane");
Chris@0 37 setMouseTracking(true);
Chris@0 38 }
Chris@0 39
Chris@0 40 bool
Chris@0 41 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos)
Chris@0 42 {
Chris@0 43 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@0 44 --vi;
Chris@0 45 if (layer != *vi) return false;
Chris@0 46 pos = m_identifyPoint;
Chris@0 47 return m_identifyFeatures;
Chris@0 48 }
Chris@0 49
Chris@0 50 return false;
Chris@0 51 }
Chris@0 52
Chris@0 53 void
Chris@0 54 Pane::setCentreLineVisible(bool visible)
Chris@0 55 {
Chris@0 56 m_centreLineVisible = visible;
Chris@0 57 update();
Chris@0 58 }
Chris@0 59
Chris@0 60 void
Chris@0 61 Pane::paintEvent(QPaintEvent *e)
Chris@0 62 {
Chris@0 63 QPainter paint;
Chris@0 64
Chris@0 65 QRect r(rect());
Chris@0 66
Chris@0 67 if (e) {
Chris@0 68 r = e->rect();
Chris@0 69 }
Chris@0 70 /*
Chris@0 71 paint.begin(this);
Chris@0 72 paint.setClipRect(r);
Chris@0 73
Chris@0 74 if (hasLightBackground()) {
Chris@0 75 paint.setPen(Qt::white);
Chris@0 76 paint.setBrush(Qt::white);
Chris@0 77 } else {
Chris@0 78 paint.setPen(Qt::black);
Chris@0 79 paint.setBrush(Qt::black);
Chris@0 80 }
Chris@0 81 paint.drawRect(r);
Chris@0 82
Chris@0 83 paint.end();
Chris@0 84 */
Chris@0 85 View::paintEvent(e);
Chris@0 86
Chris@0 87 paint.begin(this);
Chris@0 88
Chris@0 89 if (e) {
Chris@0 90 paint.setClipRect(r);
Chris@0 91 }
Chris@0 92
Chris@0 93 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@0 94 --vi;
Chris@0 95
Chris@0 96 int sw = (*vi)->getVerticalScaleWidth(paint);
Chris@0 97
Chris@0 98 if (sw > 0 && r.left() < sw) {
Chris@0 99
Chris@0 100 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
Chris@0 101
Chris@0 102 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
Chris@0 103 paint.save();
Chris@0 104
Chris@0 105 paint.setPen(Qt::black);
Chris@0 106 paint.setBrush(Qt::white);
Chris@0 107 paint.drawRect(0, 0, sw, height());
Chris@0 108
Chris@0 109 paint.setBrush(Qt::NoBrush);
Chris@0 110 (*vi)->paintVerticalScale(paint, QRect(0, 0, sw, height()));
Chris@0 111
Chris@0 112 paint.restore();
Chris@0 113 }
Chris@0 114
Chris@0 115 if (m_identifyFeatures) {
Chris@0 116 QRect descRect = (*vi)->getFeatureDescriptionRect(paint,
Chris@0 117 m_identifyPoint);
Chris@0 118 if (descRect.width() > 0 && descRect.height() > 0 &&
Chris@0 119 r.left() + r.width() >= width() - descRect.width() &&
Chris@0 120 r.top() < descRect.height()) {
Chris@0 121
Chris@0 122 // Profiler profiler("Pane::paintEvent - painting local feature description", true);
Chris@0 123
Chris@0 124 // std::cerr << "Pane::paintEvent: calling paint.save() in feature description block" << std::endl;
Chris@0 125 paint.save();
Chris@0 126
Chris@0 127 paint.setPen(Qt::black);
Chris@0 128 paint.setBrush(Qt::white);
Chris@0 129
Chris@0 130 QRect rect(width() - descRect.width() - 1, 0,
Chris@0 131 descRect.width(), descRect.height());
Chris@0 132
Chris@0 133 paint.drawRect(rect);
Chris@0 134
Chris@0 135 paint.setBrush(Qt::NoBrush);
Chris@0 136 (*vi)->paintLocalFeatureDescription(paint, rect, m_identifyPoint);
Chris@0 137
Chris@0 138 paint.restore();
Chris@0 139 }
Chris@0 140 }
Chris@0 141
Chris@0 142 break;
Chris@0 143 }
Chris@0 144
Chris@0 145 if (m_centreLineVisible) {
Chris@0 146
Chris@0 147 if (hasLightBackground()) {
Chris@0 148 paint.setPen(QColor(50, 50, 50));
Chris@0 149 } else {
Chris@0 150 paint.setPen(QColor(200, 200, 200));
Chris@0 151 }
Chris@0 152 paint.setBrush(Qt::NoBrush);
Chris@0 153 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
Chris@0 154
Chris@0 155 // QFont font(paint.font());
Chris@0 156 // font.setBold(true);
Chris@0 157 // paint.setFont(font);
Chris@0 158
Chris@0 159 int sampleRate = getModelsSampleRate();
Chris@0 160 int y = height() - paint.fontMetrics().height()
Chris@0 161 + paint.fontMetrics().ascent() - 6;
Chris@0 162
Chris@0 163 LayerList::iterator vi = m_layers.end();
Chris@0 164
Chris@0 165 if (vi != m_layers.begin()) {
Chris@0 166
Chris@0 167 switch ((*--vi)->getPreferredFrameCountPosition()) {
Chris@0 168
Chris@0 169 case Layer::PositionTop:
Chris@0 170 y = paint.fontMetrics().ascent() + 6;
Chris@0 171 break;
Chris@0 172
Chris@0 173 case Layer::PositionMiddle:
Chris@0 174 y = (height() - paint.fontMetrics().height()) / 2
Chris@0 175 + paint.fontMetrics().ascent();
Chris@0 176 break;
Chris@0 177
Chris@0 178 case Layer::PositionBottom:
Chris@0 179 // y already set correctly
Chris@0 180 break;
Chris@0 181 }
Chris@0 182 }
Chris@0 183
Chris@0 184 if (sampleRate) {
Chris@0 185
Chris@0 186 QString text(QString::fromStdString
Chris@0 187 (RealTime::frame2RealTime
Chris@0 188 (m_centreFrame, sampleRate).toText(true)));
Chris@0 189
Chris@0 190 int tw = paint.fontMetrics().width(text);
Chris@0 191 int x = width()/2 - 4 - tw;
Chris@0 192
Chris@0 193 if (hasLightBackground()) {
Chris@0 194 paint.setPen(palette().background().color());
Chris@0 195 for (int dx = -1; dx <= 1; ++dx) {
Chris@0 196 for (int dy = -1; dy <= 1; ++dy) {
Chris@0 197 if ((dx && dy) || !(dx || dy)) continue;
Chris@0 198 paint.drawText(x + dx, y + dy, text);
Chris@0 199 }
Chris@0 200 }
Chris@0 201 paint.setPen(QColor(50, 50, 50));
Chris@0 202 } else {
Chris@0 203 paint.setPen(QColor(200, 200, 200));
Chris@0 204 }
Chris@0 205
Chris@0 206 paint.drawText(x, y, text);
Chris@0 207 }
Chris@0 208
Chris@0 209 QString text = QString("%1").arg(m_centreFrame);
Chris@0 210
Chris@0 211 int tw = paint.fontMetrics().width(text);
Chris@0 212 int x = width()/2 + 4;
Chris@0 213
Chris@0 214 if (hasLightBackground()) {
Chris@0 215 paint.setPen(palette().background().color());
Chris@0 216 for (int dx = -1; dx <= 1; ++dx) {
Chris@0 217 for (int dy = -1; dy <= 1; ++dy) {
Chris@0 218 if ((dx && dy) || !(dx || dy)) continue;
Chris@0 219 paint.drawText(x + dx, y + dy, text);
Chris@0 220 }
Chris@0 221 }
Chris@0 222 paint.setPen(QColor(50, 50, 50));
Chris@0 223 } else {
Chris@0 224 paint.setPen(QColor(200, 200, 200));
Chris@0 225 }
Chris@0 226 paint.drawText(x, y, text);
Chris@0 227 }
Chris@0 228
Chris@0 229 if (m_clickedInRange && m_shiftPressed) {
Chris@13 230 //!!! be nice if this looked a bit more in keeping with the
Chris@13 231 //selection block
Chris@0 232 paint.setPen(Qt::blue);
Chris@0 233 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
Chris@0 234 m_mousePos.x() - m_clickPos.x(),
Chris@0 235 m_mousePos.y() - m_clickPos.y());
Chris@0 236 }
Chris@0 237
Chris@0 238 paint.end();
Chris@0 239 }
Chris@0 240
Chris@17 241 Selection
Chris@17 242 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge)
Chris@17 243 {
Chris@17 244 closeToLeftEdge = closeToRightEdge = false;
Chris@17 245
Chris@17 246 if (!m_manager) return Selection();
Chris@17 247
Chris@17 248 long testFrame = (x - 5) * m_zoomLevel + getStartFrame();
Chris@17 249 if (testFrame < 0) {
Chris@17 250 testFrame = x * m_zoomLevel + getStartFrame();
Chris@17 251 if (testFrame < 0) return Selection();
Chris@17 252 }
Chris@17 253
Chris@17 254 Selection selection = m_manager->getContainingSelection(testFrame, true);
Chris@17 255 if (selection.isEmpty()) return selection;
Chris@17 256
Chris@17 257 int lx = (int(selection.getStartFrame()) - getStartFrame()) / m_zoomLevel;
Chris@17 258 int rx = (int(selection.getEndFrame()) - getStartFrame()) / m_zoomLevel;
Chris@17 259
Chris@17 260 int fuzz = 2;
Chris@17 261 if (x < lx - fuzz || x > rx + fuzz) return Selection();
Chris@17 262
Chris@17 263 int width = rx - lx;
Chris@17 264 fuzz = 3;
Chris@17 265 if (width < 12) fuzz = width / 4;
Chris@17 266 if (fuzz < 1) fuzz = 1;
Chris@17 267
Chris@17 268 if (x < lx + fuzz) closeToLeftEdge = true;
Chris@17 269 if (x > rx - fuzz) closeToRightEdge = true;
Chris@17 270
Chris@17 271 return selection;
Chris@17 272 }
Chris@17 273
Chris@0 274 void
Chris@0 275 Pane::mousePressEvent(QMouseEvent *e)
Chris@0 276 {
Chris@0 277 m_clickPos = e->pos();
Chris@0 278 m_clickedInRange = true;
Chris@0 279 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
Chris@13 280 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
Chris@13 281
Chris@13 282 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@13 283 if (m_manager) mode = m_manager->getToolMode();
Chris@13 284
Chris@17 285 m_navigating = false;
Chris@13 286
Chris@17 287 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
Chris@17 288
Chris@17 289 if (mode != ViewManager::NavigateMode) {
Chris@17 290 setCursor(Qt::PointingHandCursor);
Chris@17 291 }
Chris@17 292
Chris@17 293 m_navigating = true;
Chris@13 294 m_dragCentreFrame = m_centreFrame;
Chris@13 295
Chris@13 296 } else if (mode == ViewManager::SelectMode) {
Chris@13 297
Chris@17 298 bool closeToLeft = false, closeToRight = false;
Chris@17 299 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
Chris@17 300
Chris@17 301 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@17 302
Chris@17 303 m_manager->removeSelection(selection);
Chris@17 304
Chris@17 305 if (closeToLeft) {
Chris@17 306 m_selectionStartFrame = selection.getEndFrame();
Chris@17 307 } else {
Chris@17 308 m_selectionStartFrame = selection.getStartFrame();
Chris@17 309 }
Chris@17 310
Chris@17 311 m_manager->setInProgressSelection(selection, false);
Chris@17 312 m_resizing = true;
Chris@13 313
Chris@17 314 } else {
Chris@17 315
Chris@17 316 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
Chris@17 317 size_t resolution = 1;
Chris@17 318 int snapFrame = mouseFrame;
Chris@17 319
Chris@17 320 Layer *layer = getSelectedLayer();
Chris@17 321 if (layer) {
Chris@17 322 snapFrame = layer->getNearestFeatureFrame(mouseFrame, resolution,
Chris@17 323 false);
Chris@17 324 }
Chris@17 325
Chris@17 326 if (snapFrame < 0) snapFrame = 0;
Chris@17 327 m_selectionStartFrame = snapFrame;
Chris@17 328 if (m_manager) {
Chris@17 329 m_manager->setInProgressSelection(Selection(snapFrame,
Chris@17 330 snapFrame + resolution),
Chris@17 331 !m_ctrlPressed);
Chris@17 332 }
Chris@17 333
Chris@17 334 m_resizing = false;
Chris@17 335 }
Chris@17 336
Chris@17 337 update();
Chris@17 338
Chris@17 339 } else if (mode == ViewManager::DrawMode) {
Chris@17 340
Chris@13 341 Layer *layer = getSelectedLayer();
Chris@13 342 if (layer) {
Chris@17 343 layer->drawStart(e);
Chris@13 344 }
Chris@13 345 }
Chris@0 346
Chris@0 347 emit paneInteractedWith();
Chris@0 348 }
Chris@0 349
Chris@0 350 void
Chris@0 351 Pane::mouseReleaseEvent(QMouseEvent *e)
Chris@0 352 {
Chris@13 353 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@13 354 if (m_manager) mode = m_manager->getToolMode();
Chris@13 355
Chris@0 356 if (m_clickedInRange) {
Chris@0 357 mouseMoveEvent(e);
Chris@0 358 }
Chris@0 359
Chris@17 360 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@17 361
Chris@17 362 m_navigating = false;
Chris@17 363
Chris@17 364 if (mode != ViewManager::NavigateMode) {
Chris@17 365 // restore cursor
Chris@17 366 toolModeChanged();
Chris@17 367 }
Chris@0 368
Chris@13 369 if (m_shiftPressed) {
Chris@0 370
Chris@13 371 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
Chris@13 372 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
Chris@13 373 int w = x1 - x0;
Chris@13 374
Chris@13 375 long newStartFrame = getStartFrame() + m_zoomLevel * x0;
Chris@13 376
Chris@13 377 if (newStartFrame <= -long(width() * m_zoomLevel)) {
Chris@13 378 newStartFrame = -long(width() * m_zoomLevel) + 1;
Chris@13 379 }
Chris@13 380
Chris@13 381 if (newStartFrame >= long(getModelsEndFrame())) {
Chris@13 382 newStartFrame = getModelsEndFrame() - 1;
Chris@13 383 }
Chris@13 384
Chris@13 385 float ratio = float(w) / float(width());
Chris@13 386 // std::cerr << "ratio: " << ratio << std::endl;
Chris@13 387 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
Chris@13 388 if (newZoomLevel < 1) newZoomLevel = 1;
Chris@13 389
Chris@13 390 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
Chris@13 391 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
Chris@13 392 setStartFrame(newStartFrame);
Chris@13 393
Chris@13 394 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
Chris@13 395 // update();
Chris@0 396 }
Chris@0 397
Chris@13 398 } else if (mode == ViewManager::SelectMode) {
Chris@13 399
Chris@13 400 if (m_manager && m_manager->haveInProgressSelection()) {
Chris@13 401
Chris@13 402 bool exclusive;
Chris@13 403 Selection selection = m_manager->getInProgressSelection(exclusive);
Chris@13 404
Chris@13 405 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
Chris@13 406 selection = Selection();
Chris@13 407 }
Chris@13 408
Chris@13 409 m_manager->clearInProgressSelection();
Chris@13 410
Chris@13 411 if (exclusive) {
Chris@13 412 m_manager->setSelection(selection);
Chris@13 413 } else {
Chris@13 414 m_manager->addSelection(selection);
Chris@13 415 }
Chris@0 416 }
Chris@13 417
Chris@13 418 update();
Chris@17 419
Chris@17 420 } else if (mode == ViewManager::DrawMode) {
Chris@17 421
Chris@17 422 Layer *layer = getSelectedLayer();
Chris@17 423 if (layer) {
Chris@17 424 layer->drawEnd(e);
Chris@17 425 update();
Chris@17 426 }
Chris@17 427 }
Chris@0 428
Chris@0 429 m_clickedInRange = false;
Chris@0 430
Chris@0 431 emit paneInteractedWith();
Chris@0 432 }
Chris@0 433
Chris@0 434 void
Chris@0 435 Pane::mouseMoveEvent(QMouseEvent *e)
Chris@0 436 {
Chris@13 437 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@13 438 if (m_manager) mode = m_manager->getToolMode();
Chris@13 439
Chris@0 440 if (!m_clickedInRange) {
Chris@0 441
Chris@17 442 if (mode == ViewManager::SelectMode) {
Chris@17 443 bool closeToLeft = false, closeToRight = false;
Chris@17 444 getSelectionAt(e->x(), closeToLeft, closeToRight);
Chris@17 445 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@17 446 setCursor(Qt::SizeHorCursor);
Chris@17 447 } else {
Chris@17 448 setCursor(Qt::ArrowCursor);
Chris@17 449 }
Chris@17 450 }
Chris@0 451
Chris@17 452 if (mode != ViewManager::DrawMode) {
Chris@0 453
Chris@17 454 bool previouslyIdentifying = m_identifyFeatures;
Chris@17 455 QPoint prevPoint = m_identifyPoint;
Chris@0 456
Chris@17 457 m_identifyFeatures = true;
Chris@17 458 m_identifyPoint = e->pos();
Chris@17 459
Chris@17 460 if (m_identifyFeatures != previouslyIdentifying ||
Chris@17 461 m_identifyPoint != prevPoint) {
Chris@17 462 update();
Chris@17 463 }
Chris@0 464 }
Chris@0 465
Chris@13 466 return;
Chris@13 467 }
Chris@0 468
Chris@17 469 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@0 470
Chris@13 471 if (m_shiftPressed) {
Chris@0 472
Chris@13 473 m_mousePos = e->pos();
Chris@13 474 update();
Chris@0 475
Chris@0 476 } else {
Chris@13 477
Chris@13 478 long xoff = int(e->x()) - int(m_clickPos.x());
Chris@13 479 long frameOff = xoff * m_zoomLevel;
Chris@13 480
Chris@13 481 size_t newCentreFrame = m_dragCentreFrame;
Chris@13 482
Chris@13 483 if (frameOff < 0) {
Chris@13 484 newCentreFrame -= frameOff;
Chris@13 485 } else if (newCentreFrame >= size_t(frameOff)) {
Chris@13 486 newCentreFrame -= frameOff;
Chris@13 487 } else {
Chris@13 488 newCentreFrame = 0;
Chris@13 489 }
Chris@13 490
Chris@13 491 if (newCentreFrame >= getModelsEndFrame()) {
Chris@13 492 newCentreFrame = getModelsEndFrame();
Chris@13 493 if (newCentreFrame > 0) --newCentreFrame;
Chris@13 494 }
Chris@13 495
Chris@13 496 if (std::max(m_centreFrame, newCentreFrame) -
Chris@13 497 std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) {
Chris@13 498 setCentreFrame(newCentreFrame);
Chris@13 499 }
Chris@0 500 }
Chris@0 501
Chris@13 502 } else if (mode == ViewManager::SelectMode) {
Chris@13 503
Chris@13 504 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
Chris@13 505 size_t resolution = 1;
Chris@13 506 int snapFrameLeft = mouseFrame;
Chris@13 507 int snapFrameRight = mouseFrame;
Chris@13 508
Chris@13 509 Layer *layer = getSelectedLayer();
Chris@13 510 if (layer) {
Chris@13 511 snapFrameLeft = layer->getNearestFeatureFrame(mouseFrame, resolution,
Chris@13 512 false);
Chris@13 513 snapFrameRight = layer->getNearestFeatureFrame(mouseFrame, resolution,
Chris@13 514 true);
Chris@13 515 }
Chris@13 516
Chris@13 517 if (snapFrameLeft < 0) snapFrameLeft = 0;
Chris@13 518 if (snapFrameRight < 0) snapFrameRight = 0;
Chris@13 519
Chris@13 520 size_t min, max;
Chris@13 521
Chris@13 522 if (m_selectionStartFrame > snapFrameLeft) {
Chris@13 523 min = snapFrameLeft;
Chris@13 524 max = m_selectionStartFrame;
Chris@13 525 } else if (snapFrameRight > m_selectionStartFrame) {
Chris@13 526 min = m_selectionStartFrame;
Chris@13 527 max = snapFrameRight;
Chris@13 528 } else {
Chris@13 529 min = snapFrameLeft;
Chris@13 530 max = snapFrameRight;
Chris@0 531 }
Chris@0 532
Chris@13 533 if (m_manager) {
Chris@13 534 m_manager->setInProgressSelection(Selection(min, max),
Chris@17 535 !m_resizing && !m_ctrlPressed);
Chris@0 536 }
Chris@15 537
Chris@15 538 bool doScroll = false;
Chris@15 539 if (!m_manager) doScroll = true;
Chris@15 540 if (!m_manager->isPlaying()) doScroll = true;
Chris@15 541 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
Chris@15 542
Chris@15 543 if (doScroll) {
Chris@13 544 int offset = mouseFrame - getStartFrame();
Chris@13 545 int available = getEndFrame() - getStartFrame();
Chris@15 546 if (offset >= available * 0.95) {
Chris@15 547 int move = int(offset - available * 0.95) + 1;
Chris@14 548 setCentreFrame(m_centreFrame + move);
Chris@15 549 } else if (offset <= available * 0.10) {
Chris@15 550 int move = int(available * 0.10 - offset) + 1;
Chris@14 551 if (m_centreFrame > move) {
Chris@14 552 setCentreFrame(m_centreFrame - move);
Chris@14 553 } else {
Chris@14 554 setCentreFrame(0);
Chris@14 555 }
Chris@13 556 }
Chris@13 557 }
Chris@13 558
Chris@13 559 update();
Chris@17 560
Chris@17 561 } else if (mode == ViewManager::DrawMode) {
Chris@17 562
Chris@17 563 Layer *layer = getSelectedLayer();
Chris@17 564 if (layer) {
Chris@17 565 layer->drawDrag(e);
Chris@17 566 }
Chris@0 567 }
Chris@0 568 }
Chris@0 569
Chris@0 570 void
Chris@0 571 Pane::mouseDoubleClickEvent(QMouseEvent *e)
Chris@0 572 {
Chris@0 573 std::cerr << "mouseDoubleClickEvent" << std::endl;
Chris@0 574 }
Chris@0 575
Chris@0 576 void
Chris@0 577 Pane::leaveEvent(QEvent *)
Chris@0 578 {
Chris@0 579 bool previouslyIdentifying = m_identifyFeatures;
Chris@0 580 m_identifyFeatures = false;
Chris@0 581 if (previouslyIdentifying) update();
Chris@0 582 }
Chris@0 583
Chris@0 584 void
Chris@0 585 Pane::wheelEvent(QWheelEvent *e)
Chris@0 586 {
Chris@0 587 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
Chris@0 588
Chris@0 589 int count = e->delta();
Chris@0 590
Chris@0 591 if (count > 0) {
Chris@0 592 if (count >= 120) count /= 120;
Chris@0 593 else count = 1;
Chris@0 594 }
Chris@0 595
Chris@0 596 if (count < 0) {
Chris@0 597 if (count <= -120) count /= 120;
Chris@0 598 else count = -1;
Chris@0 599 }
Chris@17 600
Chris@17 601 if (e->modifiers() & Qt::ControlModifier) {
Chris@17 602
Chris@17 603 if (getStartFrame() < 0 &&
Chris@17 604 getEndFrame() >= getModelsEndFrame()) return;
Chris@17 605
Chris@17 606 long delta = ((width() / 2) * count * m_zoomLevel);
Chris@17 607
Chris@17 608 if (int(m_centreFrame) < delta) {
Chris@17 609 setCentreFrame(0);
Chris@17 610 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
Chris@17 611 setCentreFrame(getModelsEndFrame());
Chris@17 612 } else {
Chris@17 613 setCentreFrame(m_centreFrame - delta);
Chris@17 614 }
Chris@17 615
Chris@17 616 } else {
Chris@17 617
Chris@17 618 int newZoomLevel = m_zoomLevel;
Chris@0 619
Chris@17 620 while (count > 0) {
Chris@17 621 if (newZoomLevel <= 2) {
Chris@17 622 newZoomLevel = 1;
Chris@17 623 break;
Chris@17 624 }
Chris@17 625 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
Chris@17 626 ZoomConstraint::RoundDown);
Chris@17 627 --count;
Chris@0 628 }
Chris@17 629
Chris@17 630 while (count < 0) {
Chris@17 631 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
Chris@17 632 ZoomConstraint::RoundUp);
Chris@17 633 ++count;
Chris@17 634 }
Chris@17 635
Chris@17 636 if (newZoomLevel != m_zoomLevel) {
Chris@17 637 setZoomLevel(newZoomLevel);
Chris@17 638 }
Chris@0 639 }
Chris@0 640
Chris@0 641 emit paneInteractedWith();
Chris@0 642 }
Chris@8 643
Chris@13 644 void
Chris@13 645 Pane::toolModeChanged()
Chris@13 646 {
Chris@13 647 ViewManager::ToolMode mode = m_manager->getToolMode();
Chris@13 648 std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
Chris@13 649
Chris@13 650 switch (mode) {
Chris@13 651
Chris@13 652 case ViewManager::NavigateMode:
Chris@13 653 setCursor(Qt::PointingHandCursor);
Chris@13 654 break;
Chris@13 655
Chris@13 656 case ViewManager::SelectMode:
Chris@13 657 setCursor(Qt::ArrowCursor);
Chris@13 658 break;
Chris@13 659
Chris@13 660 case ViewManager::EditMode:
Chris@13 661 setCursor(Qt::SizeAllCursor);
Chris@13 662 break;
Chris@13 663
Chris@13 664 case ViewManager::DrawMode:
Chris@13 665 setCursor(Qt::CrossCursor);
Chris@13 666 break;
Chris@13 667
Chris@13 668 case ViewManager::TextMode:
Chris@13 669 setCursor(Qt::IBeamCursor);
Chris@13 670 break;
Chris@13 671 }
Chris@13 672 }
Chris@13 673
Chris@8 674 QString
Chris@8 675 Pane::toXmlString(QString indent, QString extraAttributes) const
Chris@8 676 {
Chris@8 677 return View::toXmlString
Chris@8 678 (indent,
Chris@8 679 QString("type=\"pane\" centreLineVisible=\"%1\" %2")
Chris@8 680 .arg(m_centreLineVisible).arg(extraAttributes));
Chris@8 681 }
Chris@8 682
Chris@0 683
Chris@0 684 #ifdef INCLUDE_MOCFILES
Chris@0 685 #include "Pane.moc.cpp"
Chris@0 686 #endif
Chris@0 687