annotate widgets/Pane.cpp @ 18:7c767d41bcee

* Add basic drag editing of time instants. Plenty of tuning to do for both this and drawing.
author Chris Cannam
date Thu, 26 Jan 2006 18:01:38 +0000
parents 0183ebb725ca
children 46d8f5add6f0
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@18 345
Chris@18 346 } else if (mode == ViewManager::EditMode) {
Chris@18 347
Chris@18 348 Layer *layer = getSelectedLayer();
Chris@18 349 if (layer) {
Chris@18 350 layer->editStart(e);
Chris@18 351 }
Chris@13 352 }
Chris@0 353
Chris@0 354 emit paneInteractedWith();
Chris@0 355 }
Chris@0 356
Chris@0 357 void
Chris@0 358 Pane::mouseReleaseEvent(QMouseEvent *e)
Chris@0 359 {
Chris@13 360 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@13 361 if (m_manager) mode = m_manager->getToolMode();
Chris@13 362
Chris@0 363 if (m_clickedInRange) {
Chris@0 364 mouseMoveEvent(e);
Chris@0 365 }
Chris@0 366
Chris@17 367 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@17 368
Chris@17 369 m_navigating = false;
Chris@17 370
Chris@17 371 if (mode != ViewManager::NavigateMode) {
Chris@17 372 // restore cursor
Chris@17 373 toolModeChanged();
Chris@17 374 }
Chris@0 375
Chris@13 376 if (m_shiftPressed) {
Chris@0 377
Chris@13 378 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
Chris@13 379 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
Chris@13 380 int w = x1 - x0;
Chris@13 381
Chris@13 382 long newStartFrame = getStartFrame() + m_zoomLevel * x0;
Chris@13 383
Chris@13 384 if (newStartFrame <= -long(width() * m_zoomLevel)) {
Chris@13 385 newStartFrame = -long(width() * m_zoomLevel) + 1;
Chris@13 386 }
Chris@13 387
Chris@13 388 if (newStartFrame >= long(getModelsEndFrame())) {
Chris@13 389 newStartFrame = getModelsEndFrame() - 1;
Chris@13 390 }
Chris@13 391
Chris@13 392 float ratio = float(w) / float(width());
Chris@13 393 // std::cerr << "ratio: " << ratio << std::endl;
Chris@13 394 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
Chris@13 395 if (newZoomLevel < 1) newZoomLevel = 1;
Chris@13 396
Chris@13 397 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
Chris@13 398 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
Chris@13 399 setStartFrame(newStartFrame);
Chris@13 400
Chris@13 401 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
Chris@13 402 // update();
Chris@0 403 }
Chris@0 404
Chris@13 405 } else if (mode == ViewManager::SelectMode) {
Chris@13 406
Chris@13 407 if (m_manager && m_manager->haveInProgressSelection()) {
Chris@13 408
Chris@13 409 bool exclusive;
Chris@13 410 Selection selection = m_manager->getInProgressSelection(exclusive);
Chris@13 411
Chris@13 412 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
Chris@13 413 selection = Selection();
Chris@13 414 }
Chris@13 415
Chris@13 416 m_manager->clearInProgressSelection();
Chris@13 417
Chris@13 418 if (exclusive) {
Chris@13 419 m_manager->setSelection(selection);
Chris@13 420 } else {
Chris@13 421 m_manager->addSelection(selection);
Chris@13 422 }
Chris@0 423 }
Chris@13 424
Chris@13 425 update();
Chris@17 426
Chris@17 427 } else if (mode == ViewManager::DrawMode) {
Chris@17 428
Chris@17 429 Layer *layer = getSelectedLayer();
Chris@17 430 if (layer) {
Chris@17 431 layer->drawEnd(e);
Chris@17 432 update();
Chris@17 433 }
Chris@18 434
Chris@18 435 } else if (mode == ViewManager::EditMode) {
Chris@18 436
Chris@18 437 Layer *layer = getSelectedLayer();
Chris@18 438 if (layer) {
Chris@18 439 layer->editEnd(e);
Chris@18 440 update();
Chris@18 441 }
Chris@17 442 }
Chris@0 443
Chris@0 444 m_clickedInRange = false;
Chris@0 445
Chris@0 446 emit paneInteractedWith();
Chris@0 447 }
Chris@0 448
Chris@0 449 void
Chris@0 450 Pane::mouseMoveEvent(QMouseEvent *e)
Chris@0 451 {
Chris@13 452 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@13 453 if (m_manager) mode = m_manager->getToolMode();
Chris@13 454
Chris@0 455 if (!m_clickedInRange) {
Chris@0 456
Chris@17 457 if (mode == ViewManager::SelectMode) {
Chris@17 458 bool closeToLeft = false, closeToRight = false;
Chris@17 459 getSelectionAt(e->x(), closeToLeft, closeToRight);
Chris@17 460 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@17 461 setCursor(Qt::SizeHorCursor);
Chris@17 462 } else {
Chris@17 463 setCursor(Qt::ArrowCursor);
Chris@17 464 }
Chris@17 465 }
Chris@0 466
Chris@17 467 if (mode != ViewManager::DrawMode) {
Chris@0 468
Chris@17 469 bool previouslyIdentifying = m_identifyFeatures;
Chris@17 470 QPoint prevPoint = m_identifyPoint;
Chris@0 471
Chris@17 472 m_identifyFeatures = true;
Chris@17 473 m_identifyPoint = e->pos();
Chris@17 474
Chris@17 475 if (m_identifyFeatures != previouslyIdentifying ||
Chris@17 476 m_identifyPoint != prevPoint) {
Chris@17 477 update();
Chris@17 478 }
Chris@0 479 }
Chris@0 480
Chris@13 481 return;
Chris@13 482 }
Chris@0 483
Chris@17 484 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@0 485
Chris@13 486 if (m_shiftPressed) {
Chris@0 487
Chris@13 488 m_mousePos = e->pos();
Chris@13 489 update();
Chris@0 490
Chris@0 491 } else {
Chris@13 492
Chris@13 493 long xoff = int(e->x()) - int(m_clickPos.x());
Chris@13 494 long frameOff = xoff * m_zoomLevel;
Chris@13 495
Chris@13 496 size_t newCentreFrame = m_dragCentreFrame;
Chris@13 497
Chris@13 498 if (frameOff < 0) {
Chris@13 499 newCentreFrame -= frameOff;
Chris@13 500 } else if (newCentreFrame >= size_t(frameOff)) {
Chris@13 501 newCentreFrame -= frameOff;
Chris@13 502 } else {
Chris@13 503 newCentreFrame = 0;
Chris@13 504 }
Chris@13 505
Chris@13 506 if (newCentreFrame >= getModelsEndFrame()) {
Chris@13 507 newCentreFrame = getModelsEndFrame();
Chris@13 508 if (newCentreFrame > 0) --newCentreFrame;
Chris@13 509 }
Chris@13 510
Chris@13 511 if (std::max(m_centreFrame, newCentreFrame) -
Chris@13 512 std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) {
Chris@13 513 setCentreFrame(newCentreFrame);
Chris@13 514 }
Chris@0 515 }
Chris@0 516
Chris@13 517 } else if (mode == ViewManager::SelectMode) {
Chris@13 518
Chris@13 519 int mouseFrame = e->x() * m_zoomLevel + getStartFrame();
Chris@13 520 size_t resolution = 1;
Chris@13 521 int snapFrameLeft = mouseFrame;
Chris@13 522 int snapFrameRight = mouseFrame;
Chris@13 523
Chris@13 524 Layer *layer = getSelectedLayer();
Chris@13 525 if (layer) {
Chris@13 526 snapFrameLeft = layer->getNearestFeatureFrame(mouseFrame, resolution,
Chris@13 527 false);
Chris@13 528 snapFrameRight = layer->getNearestFeatureFrame(mouseFrame, resolution,
Chris@13 529 true);
Chris@13 530 }
Chris@13 531
Chris@13 532 if (snapFrameLeft < 0) snapFrameLeft = 0;
Chris@13 533 if (snapFrameRight < 0) snapFrameRight = 0;
Chris@13 534
Chris@13 535 size_t min, max;
Chris@13 536
Chris@13 537 if (m_selectionStartFrame > snapFrameLeft) {
Chris@13 538 min = snapFrameLeft;
Chris@13 539 max = m_selectionStartFrame;
Chris@13 540 } else if (snapFrameRight > m_selectionStartFrame) {
Chris@13 541 min = m_selectionStartFrame;
Chris@13 542 max = snapFrameRight;
Chris@13 543 } else {
Chris@13 544 min = snapFrameLeft;
Chris@13 545 max = snapFrameRight;
Chris@0 546 }
Chris@0 547
Chris@13 548 if (m_manager) {
Chris@13 549 m_manager->setInProgressSelection(Selection(min, max),
Chris@17 550 !m_resizing && !m_ctrlPressed);
Chris@0 551 }
Chris@15 552
Chris@15 553 bool doScroll = false;
Chris@15 554 if (!m_manager) doScroll = true;
Chris@15 555 if (!m_manager->isPlaying()) doScroll = true;
Chris@15 556 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
Chris@15 557
Chris@15 558 if (doScroll) {
Chris@13 559 int offset = mouseFrame - getStartFrame();
Chris@13 560 int available = getEndFrame() - getStartFrame();
Chris@15 561 if (offset >= available * 0.95) {
Chris@15 562 int move = int(offset - available * 0.95) + 1;
Chris@14 563 setCentreFrame(m_centreFrame + move);
Chris@15 564 } else if (offset <= available * 0.10) {
Chris@15 565 int move = int(available * 0.10 - offset) + 1;
Chris@14 566 if (m_centreFrame > move) {
Chris@14 567 setCentreFrame(m_centreFrame - move);
Chris@14 568 } else {
Chris@14 569 setCentreFrame(0);
Chris@14 570 }
Chris@13 571 }
Chris@13 572 }
Chris@13 573
Chris@13 574 update();
Chris@17 575
Chris@17 576 } else if (mode == ViewManager::DrawMode) {
Chris@17 577
Chris@17 578 Layer *layer = getSelectedLayer();
Chris@17 579 if (layer) {
Chris@17 580 layer->drawDrag(e);
Chris@17 581 }
Chris@18 582
Chris@18 583 } else if (mode == ViewManager::EditMode) {
Chris@18 584
Chris@18 585 Layer *layer = getSelectedLayer();
Chris@18 586 if (layer) {
Chris@18 587 layer->editDrag(e);
Chris@18 588 }
Chris@0 589 }
Chris@0 590 }
Chris@0 591
Chris@0 592 void
Chris@0 593 Pane::mouseDoubleClickEvent(QMouseEvent *e)
Chris@0 594 {
Chris@0 595 std::cerr << "mouseDoubleClickEvent" << std::endl;
Chris@0 596 }
Chris@0 597
Chris@0 598 void
Chris@0 599 Pane::leaveEvent(QEvent *)
Chris@0 600 {
Chris@0 601 bool previouslyIdentifying = m_identifyFeatures;
Chris@0 602 m_identifyFeatures = false;
Chris@0 603 if (previouslyIdentifying) update();
Chris@0 604 }
Chris@0 605
Chris@0 606 void
Chris@0 607 Pane::wheelEvent(QWheelEvent *e)
Chris@0 608 {
Chris@0 609 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
Chris@0 610
Chris@0 611 int count = e->delta();
Chris@0 612
Chris@0 613 if (count > 0) {
Chris@0 614 if (count >= 120) count /= 120;
Chris@0 615 else count = 1;
Chris@0 616 }
Chris@0 617
Chris@0 618 if (count < 0) {
Chris@0 619 if (count <= -120) count /= 120;
Chris@0 620 else count = -1;
Chris@0 621 }
Chris@17 622
Chris@17 623 if (e->modifiers() & Qt::ControlModifier) {
Chris@17 624
Chris@17 625 if (getStartFrame() < 0 &&
Chris@17 626 getEndFrame() >= getModelsEndFrame()) return;
Chris@17 627
Chris@17 628 long delta = ((width() / 2) * count * m_zoomLevel);
Chris@17 629
Chris@17 630 if (int(m_centreFrame) < delta) {
Chris@17 631 setCentreFrame(0);
Chris@17 632 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
Chris@17 633 setCentreFrame(getModelsEndFrame());
Chris@17 634 } else {
Chris@17 635 setCentreFrame(m_centreFrame - delta);
Chris@17 636 }
Chris@17 637
Chris@17 638 } else {
Chris@17 639
Chris@17 640 int newZoomLevel = m_zoomLevel;
Chris@0 641
Chris@17 642 while (count > 0) {
Chris@17 643 if (newZoomLevel <= 2) {
Chris@17 644 newZoomLevel = 1;
Chris@17 645 break;
Chris@17 646 }
Chris@17 647 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
Chris@17 648 ZoomConstraint::RoundDown);
Chris@17 649 --count;
Chris@0 650 }
Chris@17 651
Chris@17 652 while (count < 0) {
Chris@17 653 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
Chris@17 654 ZoomConstraint::RoundUp);
Chris@17 655 ++count;
Chris@17 656 }
Chris@17 657
Chris@17 658 if (newZoomLevel != m_zoomLevel) {
Chris@17 659 setZoomLevel(newZoomLevel);
Chris@17 660 }
Chris@0 661 }
Chris@0 662
Chris@0 663 emit paneInteractedWith();
Chris@0 664 }
Chris@8 665
Chris@13 666 void
Chris@13 667 Pane::toolModeChanged()
Chris@13 668 {
Chris@13 669 ViewManager::ToolMode mode = m_manager->getToolMode();
Chris@13 670 std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
Chris@13 671
Chris@13 672 switch (mode) {
Chris@13 673
Chris@13 674 case ViewManager::NavigateMode:
Chris@13 675 setCursor(Qt::PointingHandCursor);
Chris@13 676 break;
Chris@13 677
Chris@13 678 case ViewManager::SelectMode:
Chris@13 679 setCursor(Qt::ArrowCursor);
Chris@13 680 break;
Chris@13 681
Chris@13 682 case ViewManager::EditMode:
Chris@13 683 setCursor(Qt::SizeAllCursor);
Chris@13 684 break;
Chris@13 685
Chris@13 686 case ViewManager::DrawMode:
Chris@13 687 setCursor(Qt::CrossCursor);
Chris@13 688 break;
Chris@13 689
Chris@13 690 case ViewManager::TextMode:
Chris@13 691 setCursor(Qt::IBeamCursor);
Chris@13 692 break;
Chris@13 693 }
Chris@13 694 }
Chris@13 695
Chris@8 696 QString
Chris@8 697 Pane::toXmlString(QString indent, QString extraAttributes) const
Chris@8 698 {
Chris@8 699 return View::toXmlString
Chris@8 700 (indent,
Chris@8 701 QString("type=\"pane\" centreLineVisible=\"%1\" %2")
Chris@8 702 .arg(m_centreLineVisible).arg(extraAttributes));
Chris@8 703 }
Chris@8 704
Chris@0 705
Chris@0 706 #ifdef INCLUDE_MOCFILES
Chris@0 707 #include "Pane.moc.cpp"
Chris@0 708 #endif
Chris@0 709