annotate view/Pane.cpp @ 132:5d3a483856ff

* Add Thumbwheel widget for all our zooming needs * Use QSettings to save/restore window size and position -- precursor to switching our preferences to QSettings as well -- wish I'd noticed it sooner * Only suspend writes (not reads from the underlying cache objects) from the fft caches when repainting the spectrogram -- performance should now be significantly better
author Chris Cannam
date Thu, 03 Aug 2006 15:40:11 +0000
parents 33929e0c3c6b
children 9e6b3e239b9d
rev   line source
Chris@127 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@127 2
Chris@127 3 /*
Chris@127 4 Sonic Visualiser
Chris@127 5 An audio file viewer and annotation editor.
Chris@127 6 Centre for Digital Music, Queen Mary, University of London.
Chris@127 7 This file copyright 2006 Chris Cannam.
Chris@127 8
Chris@127 9 This program is free software; you can redistribute it and/or
Chris@127 10 modify it under the terms of the GNU General Public License as
Chris@127 11 published by the Free Software Foundation; either version 2 of the
Chris@127 12 License, or (at your option) any later version. See the file
Chris@127 13 COPYING included with this distribution for more information.
Chris@127 14 */
Chris@127 15
Chris@128 16 #include "Pane.h"
Chris@128 17 #include "layer/Layer.h"
Chris@128 18 #include "data/model/Model.h"
Chris@127 19 #include "base/ZoomConstraint.h"
Chris@127 20 #include "base/RealTime.h"
Chris@127 21 #include "base/Profiler.h"
Chris@128 22 #include "ViewManager.h"
Chris@127 23 #include "base/CommandHistory.h"
Chris@127 24 #include "layer/WaveformLayer.h"
Chris@132 25 #include "widgets/Thumbwheel.h"
Chris@127 26
Chris@127 27 #include <QPaintEvent>
Chris@127 28 #include <QPainter>
Chris@127 29 #include <iostream>
Chris@127 30 #include <cmath>
Chris@127 31
Chris@127 32 using std::cerr;
Chris@127 33 using std::endl;
Chris@127 34
Chris@127 35 Pane::Pane(QWidget *w) :
Chris@127 36 View(w, true),
Chris@127 37 m_identifyFeatures(false),
Chris@127 38 m_clickedInRange(false),
Chris@127 39 m_shiftPressed(false),
Chris@127 40 m_ctrlPressed(false),
Chris@127 41 m_navigating(false),
Chris@127 42 m_resizing(false),
Chris@127 43 m_centreLineVisible(true)
Chris@127 44 {
Chris@127 45 setObjectName("Pane");
Chris@127 46 setMouseTracking(true);
Chris@132 47 /*
Chris@132 48 int count = 0;
Chris@132 49 int currentLevel = 1;
Chris@132 50 int level = 1;
Chris@132 51 while (true) {
Chris@132 52 if (getZoomLevel() == level) currentLevel = count;
Chris@132 53 int newLevel = getZoomConstraintBlockSize(level + 1,
Chris@132 54 ZoomConstraint::RoundUp);
Chris@132 55 if (newLevel == level) break;
Chris@132 56 if (newLevel == 131072) break; //!!! just because
Chris@132 57 level = newLevel;
Chris@132 58 ++count;
Chris@132 59 }
Chris@132 60
Chris@132 61 std::cerr << "Have " << count+1 << " zoom levels" << std::endl;
Chris@132 62 */
Chris@132 63 /*
Chris@132 64 Thumbwheel *thumbwheel = new Thumbwheel(0, 40, 5,
Chris@132 65 Qt::Vertical, this);
Chris@132 66 thumbwheel->move(10, 10);
Chris@132 67 connect(thumbwheel, SIGNAL(valueChanged(int)), this,
Chris@132 68 SLOT(horizontalThumbwheelMoved(int)));
Chris@132 69 */
Chris@127 70 }
Chris@127 71
Chris@127 72 bool
Chris@127 73 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
Chris@127 74 {
Chris@127 75 QPoint discard;
Chris@127 76 bool b0, b1;
Chris@127 77
Chris@127 78 if (layer == getSelectedLayer() &&
Chris@127 79 !shouldIlluminateLocalSelection(discard, b0, b1)) {
Chris@127 80
Chris@127 81 pos = m_identifyPoint;
Chris@127 82 return m_identifyFeatures;
Chris@127 83 }
Chris@127 84
Chris@127 85 return false;
Chris@127 86 }
Chris@127 87
Chris@127 88 bool
Chris@127 89 Pane::shouldIlluminateLocalSelection(QPoint &pos,
Chris@127 90 bool &closeToLeft,
Chris@127 91 bool &closeToRight) const
Chris@127 92 {
Chris@127 93 if (m_identifyFeatures &&
Chris@127 94 m_manager &&
Chris@127 95 m_manager->getToolMode() == ViewManager::EditMode &&
Chris@127 96 !m_manager->getSelections().empty() &&
Chris@127 97 !selectionIsBeingEdited()) {
Chris@127 98
Chris@127 99 Selection s(getSelectionAt(m_identifyPoint.x(),
Chris@127 100 closeToLeft, closeToRight));
Chris@127 101
Chris@127 102 if (!s.isEmpty()) {
Chris@127 103 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
Chris@127 104
Chris@127 105 pos = m_identifyPoint;
Chris@127 106 return true;
Chris@127 107 }
Chris@127 108 }
Chris@127 109 }
Chris@127 110
Chris@127 111 return false;
Chris@127 112 }
Chris@127 113
Chris@127 114 bool
Chris@127 115 Pane::selectionIsBeingEdited() const
Chris@127 116 {
Chris@127 117 if (!m_editingSelection.isEmpty()) {
Chris@127 118 if (m_mousePos != m_clickPos &&
Chris@127 119 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
Chris@127 120 return true;
Chris@127 121 }
Chris@127 122 }
Chris@127 123 return false;
Chris@127 124 }
Chris@127 125
Chris@127 126 void
Chris@127 127 Pane::setCentreLineVisible(bool visible)
Chris@127 128 {
Chris@127 129 m_centreLineVisible = visible;
Chris@127 130 update();
Chris@127 131 }
Chris@127 132
Chris@127 133 void
Chris@127 134 Pane::paintEvent(QPaintEvent *e)
Chris@127 135 {
Chris@127 136 // Profiler profiler("Pane::paintEvent", true);
Chris@127 137
Chris@127 138 QPainter paint;
Chris@127 139
Chris@127 140 QRect r(rect());
Chris@127 141
Chris@127 142 if (e) {
Chris@127 143 r = e->rect();
Chris@127 144 }
Chris@127 145 /*
Chris@127 146 paint.begin(this);
Chris@127 147 paint.setClipRect(r);
Chris@127 148
Chris@127 149 if (hasLightBackground()) {
Chris@127 150 paint.setPen(Qt::white);
Chris@127 151 paint.setBrush(Qt::white);
Chris@127 152 } else {
Chris@127 153 paint.setPen(Qt::black);
Chris@127 154 paint.setBrush(Qt::black);
Chris@127 155 }
Chris@127 156 paint.drawRect(r);
Chris@127 157
Chris@127 158 paint.end();
Chris@127 159 */
Chris@127 160 View::paintEvent(e);
Chris@127 161
Chris@127 162 paint.begin(this);
Chris@127 163
Chris@127 164 if (e) {
Chris@127 165 paint.setClipRect(r);
Chris@127 166 }
Chris@127 167
Chris@127 168 const Model *waveformModel = 0; // just for reporting purposes
Chris@127 169 int verticalScaleWidth = 0;
Chris@127 170
Chris@127 171 int fontHeight = paint.fontMetrics().height();
Chris@127 172 int fontAscent = paint.fontMetrics().ascent();
Chris@127 173
Chris@127 174 if (m_manager &&
Chris@127 175 !m_manager->isPlaying() &&
Chris@127 176 m_manager->getToolMode() == ViewManager::SelectMode) {
Chris@127 177
Chris@127 178 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127 179 --vi;
Chris@127 180
Chris@127 181 std::vector<QRect> crosshairExtents;
Chris@127 182
Chris@127 183 if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint,
Chris@127 184 crosshairExtents)) {
Chris@127 185 (*vi)->paintCrosshairs(this, paint, m_identifyPoint);
Chris@127 186 break;
Chris@127 187 } else if ((*vi)->isLayerOpaque()) {
Chris@127 188 break;
Chris@127 189 }
Chris@127 190 }
Chris@127 191 }
Chris@127 192
Chris@127 193 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127 194 --vi;
Chris@127 195
Chris@127 196 if (dynamic_cast<WaveformLayer *>(*vi)) {
Chris@127 197 waveformModel = (*vi)->getModel();
Chris@127 198 }
Chris@127 199
Chris@127 200 if (!m_manager ||
Chris@127 201 m_manager->getOverlayMode() == ViewManager::NoOverlays) {
Chris@127 202 break;
Chris@127 203 }
Chris@127 204
Chris@127 205 verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
Chris@127 206
Chris@127 207 if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) {
Chris@127 208
Chris@127 209 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
Chris@127 210
Chris@127 211 // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl;
Chris@127 212 paint.save();
Chris@127 213
Chris@127 214 paint.setPen(Qt::black);
Chris@127 215 paint.setBrush(Qt::white);
Chris@127 216 paint.drawRect(0, -1, verticalScaleWidth, height()+1);
Chris@127 217
Chris@127 218 paint.setBrush(Qt::NoBrush);
Chris@127 219 (*vi)->paintVerticalScale
Chris@127 220 (this, paint, QRect(0, 0, verticalScaleWidth, height()));
Chris@127 221
Chris@127 222 paint.restore();
Chris@127 223 }
Chris@127 224
Chris@127 225 if (m_identifyFeatures) {
Chris@127 226
Chris@127 227 QPoint pos = m_identifyPoint;
Chris@127 228 QString desc = (*vi)->getFeatureDescription(this, pos);
Chris@127 229
Chris@127 230 if (desc != "") {
Chris@127 231
Chris@127 232 paint.save();
Chris@127 233
Chris@127 234 int tabStop =
Chris@127 235 paint.fontMetrics().width(tr("Some lengthy prefix:"));
Chris@127 236
Chris@127 237 QRect boundingRect =
Chris@127 238 paint.fontMetrics().boundingRect
Chris@127 239 (rect(),
Chris@127 240 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
Chris@127 241 desc, tabStop);
Chris@127 242
Chris@127 243 if (hasLightBackground()) {
Chris@127 244 paint.setPen(Qt::NoPen);
Chris@127 245 paint.setBrush(QColor(250, 250, 250, 200));
Chris@127 246 } else {
Chris@127 247 paint.setPen(Qt::NoPen);
Chris@127 248 paint.setBrush(QColor(50, 50, 50, 200));
Chris@127 249 }
Chris@127 250
Chris@127 251 int extra = paint.fontMetrics().descent();
Chris@127 252 paint.drawRect(width() - boundingRect.width() - 10 - extra,
Chris@127 253 10 - extra,
Chris@127 254 boundingRect.width() + 2 * extra,
Chris@127 255 boundingRect.height() + extra);
Chris@127 256
Chris@127 257 if (hasLightBackground()) {
Chris@127 258 paint.setPen(QColor(150, 20, 0));
Chris@127 259 } else {
Chris@127 260 paint.setPen(QColor(255, 150, 100));
Chris@127 261 }
Chris@127 262
Chris@127 263 QTextOption option;
Chris@127 264 option.setWrapMode(QTextOption::NoWrap);
Chris@127 265 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
Chris@127 266 option.setTabStop(tabStop);
Chris@127 267 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
Chris@127 268 boundingRect.width(),
Chris@127 269 boundingRect.height()),
Chris@127 270 desc,
Chris@127 271 option);
Chris@127 272
Chris@127 273 paint.restore();
Chris@127 274 }
Chris@127 275 }
Chris@127 276
Chris@127 277 break;
Chris@127 278 }
Chris@127 279
Chris@127 280 int sampleRate = getModelsSampleRate();
Chris@127 281 paint.setBrush(Qt::NoBrush);
Chris@127 282
Chris@127 283 if (m_centreLineVisible) {
Chris@127 284
Chris@127 285 if (hasLightBackground()) {
Chris@127 286 paint.setPen(QColor(50, 50, 50));
Chris@127 287 } else {
Chris@127 288 paint.setPen(QColor(200, 200, 200));
Chris@127 289 }
Chris@127 290 paint.drawLine(width() / 2, 0, width() / 2, height() - 1);
Chris@127 291
Chris@127 292 paint.setPen(QColor(50, 50, 50));
Chris@127 293
Chris@127 294 int y = height() - fontHeight
Chris@127 295 + fontAscent - 6;
Chris@127 296
Chris@127 297 LayerList::iterator vi = m_layers.end();
Chris@127 298
Chris@127 299 if (vi != m_layers.begin()) {
Chris@127 300
Chris@127 301 switch ((*--vi)->getPreferredFrameCountPosition()) {
Chris@127 302
Chris@127 303 case Layer::PositionTop:
Chris@127 304 y = fontAscent + 6;
Chris@127 305 break;
Chris@127 306
Chris@127 307 case Layer::PositionMiddle:
Chris@127 308 y = (height() - fontHeight) / 2
Chris@127 309 + fontAscent;
Chris@127 310 break;
Chris@127 311
Chris@127 312 case Layer::PositionBottom:
Chris@127 313 // y already set correctly
Chris@127 314 break;
Chris@127 315 }
Chris@127 316 }
Chris@127 317
Chris@127 318 if (m_manager &&
Chris@127 319 m_manager->getOverlayMode() != ViewManager::NoOverlays) {
Chris@127 320
Chris@127 321 if (sampleRate) {
Chris@127 322
Chris@127 323 QString text(QString::fromStdString
Chris@127 324 (RealTime::frame2RealTime
Chris@127 325 (m_centreFrame, sampleRate).toText(true)));
Chris@127 326
Chris@127 327 int tw = paint.fontMetrics().width(text);
Chris@127 328 int x = width()/2 - 4 - tw;
Chris@127 329
Chris@127 330 drawVisibleText(paint, x, y, text, OutlinedText);
Chris@127 331 }
Chris@127 332
Chris@127 333 QString text = QString("%1").arg(m_centreFrame);
Chris@127 334
Chris@127 335 int tw = paint.fontMetrics().width(text);
Chris@127 336 int x = width()/2 + 4;
Chris@127 337
Chris@127 338 drawVisibleText(paint, x, y, text, OutlinedText);
Chris@127 339 }
Chris@127 340
Chris@127 341 } else {
Chris@127 342
Chris@127 343 paint.setPen(QColor(50, 50, 50));
Chris@127 344 }
Chris@127 345
Chris@127 346 if (waveformModel &&
Chris@127 347 m_manager &&
Chris@127 348 m_manager->getOverlayMode() != ViewManager::NoOverlays &&
Chris@127 349 r.y() + r.height() >= height() - fontHeight - 6) {
Chris@127 350
Chris@127 351 size_t mainModelRate = m_manager->getMainModelSampleRate();
Chris@127 352 size_t playbackRate = m_manager->getPlaybackSampleRate();
Chris@127 353
Chris@127 354 QString srNote = "";
Chris@127 355
Chris@127 356 // Show (R) for waveform models that will be resampled on
Chris@127 357 // playback, and (X) for waveform models that will be played
Chris@127 358 // at the wrong rate because their rate differs from that of
Chris@127 359 // the main model.
Chris@127 360
Chris@127 361 if (sampleRate == mainModelRate) {
Chris@127 362 if (sampleRate != playbackRate) srNote = " " + tr("(R)");
Chris@127 363 } else {
Chris@127 364 std::cerr << "Sample rate = " << sampleRate << ", main model rate = " << mainModelRate << std::endl;
Chris@127 365 srNote = " " + tr("(X)");
Chris@127 366 }
Chris@127 367
Chris@127 368 QString desc = tr("%1 / %2Hz%3")
Chris@127 369 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
Chris@127 370 sampleRate)
Chris@127 371 .toText(false).c_str())
Chris@127 372 .arg(sampleRate)
Chris@127 373 .arg(srNote);
Chris@127 374
Chris@127 375 if (r.x() < verticalScaleWidth + 5 + paint.fontMetrics().width(desc)) {
Chris@127 376 drawVisibleText(paint, verticalScaleWidth + 5,
Chris@127 377 height() - fontHeight + fontAscent - 6,
Chris@127 378 desc, OutlinedText);
Chris@127 379 }
Chris@127 380 }
Chris@127 381
Chris@127 382 if (m_manager &&
Chris@127 383 m_manager->getOverlayMode() == ViewManager::AllOverlays &&
Chris@127 384 r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) {
Chris@127 385
Chris@127 386 std::vector<QString> texts;
Chris@127 387 int maxTextWidth = 0;
Chris@127 388
Chris@127 389 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
Chris@127 390
Chris@127 391 QString text = (*i)->getLayerPresentationName();
Chris@127 392 int tw = paint.fontMetrics().width(text);
Chris@127 393 bool reduced = false;
Chris@127 394 while (tw > width() / 3 && text.length() > 4) {
Chris@127 395 if (!reduced && text.length() > 8) {
Chris@127 396 text = text.left(text.length() - 4);
Chris@127 397 } else {
Chris@127 398 text = text.left(text.length() - 2);
Chris@127 399 }
Chris@127 400 reduced = true;
Chris@127 401 tw = paint.fontMetrics().width(text + "...");
Chris@127 402 }
Chris@127 403 if (reduced) {
Chris@127 404 texts.push_back(text + "...");
Chris@127 405 } else {
Chris@127 406 texts.push_back(text);
Chris@127 407 }
Chris@127 408 if (tw > maxTextWidth) maxTextWidth = tw;
Chris@127 409 }
Chris@127 410
Chris@127 411 int lly = height() - 6;
Chris@127 412
Chris@127 413 if (r.x() + r.width() >= width() - maxTextWidth - 5) {
Chris@127 414
Chris@127 415 for (int i = 0; i < texts.size(); ++i) {
Chris@127 416
Chris@127 417 if (i == texts.size() - 1) {
Chris@127 418 paint.setPen(Qt::black);
Chris@127 419 }
Chris@127 420
Chris@127 421 drawVisibleText(paint, width() - maxTextWidth - 5,
Chris@127 422 lly - fontHeight + fontAscent,
Chris@127 423 texts[i], OutlinedText);
Chris@127 424
Chris@127 425 lly -= fontHeight;
Chris@127 426 }
Chris@127 427 }
Chris@127 428 }
Chris@127 429
Chris@127 430 if (m_clickedInRange && m_shiftPressed) {
Chris@127 431 if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) {
Chris@127 432 //!!! be nice if this looked a bit more in keeping with the
Chris@127 433 //selection block
Chris@127 434 paint.setPen(Qt::blue);
Chris@127 435 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
Chris@127 436 m_mousePos.x() - m_clickPos.x(),
Chris@127 437 m_mousePos.y() - m_clickPos.y());
Chris@127 438 }
Chris@127 439 }
Chris@127 440
Chris@127 441 if (selectionIsBeingEdited()) {
Chris@127 442
Chris@127 443 int offset = m_mousePos.x() - m_clickPos.x();
Chris@127 444 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
Chris@127 445 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
Chris@127 446
Chris@127 447 if (m_editingSelectionEdge < 0) {
Chris@127 448 p1 = getXForFrame(m_editingSelection.getEndFrame());
Chris@127 449 } else if (m_editingSelectionEdge > 0) {
Chris@127 450 p0 = getXForFrame(m_editingSelection.getStartFrame());
Chris@127 451 }
Chris@127 452
Chris@127 453 paint.save();
Chris@127 454 if (hasLightBackground()) {
Chris@127 455 paint.setPen(QPen(Qt::black, 2));
Chris@127 456 } else {
Chris@127 457 paint.setPen(QPen(Qt::white, 2));
Chris@127 458 }
Chris@127 459
Chris@127 460 //!!! duplicating display policy with View::drawSelections
Chris@127 461
Chris@127 462 if (m_editingSelectionEdge < 0) {
Chris@127 463 paint.drawLine(p0, 1, p1, 1);
Chris@127 464 paint.drawLine(p0, 0, p0, height());
Chris@127 465 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@127 466 } else if (m_editingSelectionEdge > 0) {
Chris@127 467 paint.drawLine(p0, 1, p1, 1);
Chris@127 468 paint.drawLine(p1, 0, p1, height());
Chris@127 469 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@127 470 } else {
Chris@127 471 paint.setBrush(Qt::NoBrush);
Chris@127 472 paint.drawRect(p0, 1, p1 - p0, height() - 2);
Chris@127 473 }
Chris@127 474 paint.restore();
Chris@127 475 }
Chris@127 476
Chris@127 477 paint.end();
Chris@127 478 }
Chris@127 479
Chris@127 480 Selection
Chris@127 481 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
Chris@127 482 {
Chris@127 483 closeToLeftEdge = closeToRightEdge = false;
Chris@127 484
Chris@127 485 if (!m_manager) return Selection();
Chris@127 486
Chris@127 487 long testFrame = getFrameForX(x - 5);
Chris@127 488 if (testFrame < 0) {
Chris@127 489 testFrame = getFrameForX(x);
Chris@127 490 if (testFrame < 0) return Selection();
Chris@127 491 }
Chris@127 492
Chris@127 493 Selection selection = m_manager->getContainingSelection(testFrame, true);
Chris@127 494 if (selection.isEmpty()) return selection;
Chris@127 495
Chris@127 496 int lx = getXForFrame(selection.getStartFrame());
Chris@127 497 int rx = getXForFrame(selection.getEndFrame());
Chris@127 498
Chris@127 499 int fuzz = 2;
Chris@127 500 if (x < lx - fuzz || x > rx + fuzz) return Selection();
Chris@127 501
Chris@127 502 int width = rx - lx;
Chris@127 503 fuzz = 3;
Chris@127 504 if (width < 12) fuzz = width / 4;
Chris@127 505 if (fuzz < 1) fuzz = 1;
Chris@127 506
Chris@127 507 if (x < lx + fuzz) closeToLeftEdge = true;
Chris@127 508 if (x > rx - fuzz) closeToRightEdge = true;
Chris@127 509
Chris@127 510 return selection;
Chris@127 511 }
Chris@127 512
Chris@127 513 void
Chris@127 514 Pane::mousePressEvent(QMouseEvent *e)
Chris@127 515 {
Chris@127 516 if (e->buttons() & Qt::RightButton) {
Chris@127 517 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
Chris@127 518 return;
Chris@127 519 }
Chris@127 520
Chris@127 521 m_clickPos = e->pos();
Chris@127 522 m_clickedInRange = true;
Chris@127 523 m_editingSelection = Selection();
Chris@127 524 m_editingSelectionEdge = 0;
Chris@127 525 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
Chris@127 526 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
Chris@127 527
Chris@127 528 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 529 if (m_manager) mode = m_manager->getToolMode();
Chris@127 530
Chris@127 531 m_navigating = false;
Chris@127 532
Chris@127 533 if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) {
Chris@127 534
Chris@127 535 if (mode != ViewManager::NavigateMode) {
Chris@127 536 setCursor(Qt::PointingHandCursor);
Chris@127 537 }
Chris@127 538
Chris@127 539 m_navigating = true;
Chris@127 540 m_dragCentreFrame = m_centreFrame;
Chris@127 541
Chris@127 542 } else if (mode == ViewManager::SelectMode) {
Chris@127 543
Chris@127 544 bool closeToLeft = false, closeToRight = false;
Chris@127 545 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
Chris@127 546
Chris@127 547 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@127 548
Chris@127 549 m_manager->removeSelection(selection);
Chris@127 550
Chris@127 551 if (closeToLeft) {
Chris@127 552 m_selectionStartFrame = selection.getEndFrame();
Chris@127 553 } else {
Chris@127 554 m_selectionStartFrame = selection.getStartFrame();
Chris@127 555 }
Chris@127 556
Chris@127 557 m_manager->setInProgressSelection(selection, false);
Chris@127 558 m_resizing = true;
Chris@127 559
Chris@127 560 } else {
Chris@127 561
Chris@127 562 int mouseFrame = getFrameForX(e->x());
Chris@127 563 size_t resolution = 1;
Chris@127 564 int snapFrame = mouseFrame;
Chris@127 565
Chris@127 566 Layer *layer = getSelectedLayer();
Chris@127 567 if (layer && !m_shiftPressed) {
Chris@127 568 layer->snapToFeatureFrame(this, snapFrame,
Chris@127 569 resolution, Layer::SnapLeft);
Chris@127 570 }
Chris@127 571
Chris@127 572 if (snapFrame < 0) snapFrame = 0;
Chris@127 573 m_selectionStartFrame = snapFrame;
Chris@127 574 if (m_manager) {
Chris@127 575 m_manager->setInProgressSelection(Selection(snapFrame,
Chris@127 576 snapFrame + resolution),
Chris@127 577 !m_ctrlPressed);
Chris@127 578 }
Chris@127 579
Chris@127 580 m_resizing = false;
Chris@127 581 }
Chris@127 582
Chris@127 583 update();
Chris@127 584
Chris@127 585 } else if (mode == ViewManager::DrawMode) {
Chris@127 586
Chris@127 587 Layer *layer = getSelectedLayer();
Chris@127 588 if (layer && layer->isLayerEditable()) {
Chris@127 589 layer->drawStart(this, e);
Chris@127 590 }
Chris@127 591
Chris@127 592 } else if (mode == ViewManager::EditMode) {
Chris@127 593
Chris@127 594 if (!editSelectionStart(e)) {
Chris@127 595 Layer *layer = getSelectedLayer();
Chris@127 596 if (layer && layer->isLayerEditable()) {
Chris@127 597 layer->editStart(this, e);
Chris@127 598 }
Chris@127 599 }
Chris@127 600 }
Chris@127 601
Chris@127 602 emit paneInteractedWith();
Chris@127 603 }
Chris@127 604
Chris@127 605 void
Chris@127 606 Pane::mouseReleaseEvent(QMouseEvent *e)
Chris@127 607 {
Chris@127 608 if (e->buttons() & Qt::RightButton) {
Chris@127 609 return;
Chris@127 610 }
Chris@127 611
Chris@127 612 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 613 if (m_manager) mode = m_manager->getToolMode();
Chris@127 614
Chris@127 615 if (m_clickedInRange) {
Chris@127 616 mouseMoveEvent(e);
Chris@127 617 }
Chris@127 618
Chris@127 619 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@127 620
Chris@127 621 m_navigating = false;
Chris@127 622
Chris@127 623 if (mode != ViewManager::NavigateMode) {
Chris@127 624 // restore cursor
Chris@127 625 toolModeChanged();
Chris@127 626 }
Chris@127 627
Chris@127 628 if (m_shiftPressed) {
Chris@127 629
Chris@127 630 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
Chris@127 631 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
Chris@127 632 int w = x1 - x0;
Chris@127 633
Chris@127 634 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
Chris@127 635 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
Chris@127 636 // int h = y1 - y0;
Chris@127 637
Chris@127 638 long newStartFrame = getFrameForX(x0);
Chris@127 639
Chris@127 640 long visibleFrames = getEndFrame() - getStartFrame();
Chris@127 641 if (newStartFrame <= -visibleFrames) {
Chris@127 642 newStartFrame = -visibleFrames + 1;
Chris@127 643 }
Chris@127 644
Chris@127 645 if (newStartFrame >= long(getModelsEndFrame())) {
Chris@127 646 newStartFrame = getModelsEndFrame() - 1;
Chris@127 647 }
Chris@127 648
Chris@127 649 float ratio = float(w) / float(width());
Chris@127 650 // std::cerr << "ratio: " << ratio << std::endl;
Chris@127 651 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
Chris@127 652 if (newZoomLevel < 1) newZoomLevel = 1;
Chris@127 653
Chris@127 654 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
Chris@127 655 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
Chris@127 656 setStartFrame(newStartFrame);
Chris@127 657
Chris@127 658 //!!! lots of faff, shouldn't be here
Chris@127 659
Chris@127 660 QString unit;
Chris@127 661 float min, max;
Chris@127 662 bool log;
Chris@127 663 Layer *layer = 0;
Chris@127 664 for (LayerList::const_iterator i = m_layers.begin();
Chris@127 665 i != m_layers.end(); ++i) {
Chris@127 666 if ((*i)->getValueExtents(min, max, log, unit) &&
Chris@127 667 (*i)->getDisplayExtents(min, max)) {
Chris@127 668 layer = *i;
Chris@127 669 break;
Chris@127 670 }
Chris@127 671 }
Chris@127 672
Chris@127 673 if (layer) {
Chris@127 674 if (log) {
Chris@127 675 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
Chris@127 676 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
Chris@127 677 }
Chris@127 678 float rmin = min + ((max - min) * (height() - y1)) / height();
Chris@127 679 float rmax = min + ((max - min) * (height() - y0)) / height();
Chris@127 680 std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl;
Chris@127 681 if (log) {
Chris@127 682 rmin = powf(10, rmin);
Chris@127 683 rmax = powf(10, rmax);
Chris@127 684 }
Chris@127 685 std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit.toStdString() << std::endl;
Chris@127 686
Chris@127 687 layer->setDisplayExtents(rmin, rmax);
Chris@127 688 }
Chris@127 689
Chris@127 690 //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl;
Chris@127 691 // update();
Chris@127 692 }
Chris@127 693
Chris@127 694 } else if (mode == ViewManager::SelectMode) {
Chris@127 695
Chris@127 696 if (m_manager && m_manager->haveInProgressSelection()) {
Chris@127 697
Chris@127 698 bool exclusive;
Chris@127 699 Selection selection = m_manager->getInProgressSelection(exclusive);
Chris@127 700
Chris@127 701 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
Chris@127 702 selection = Selection();
Chris@127 703 }
Chris@127 704
Chris@127 705 m_manager->clearInProgressSelection();
Chris@127 706
Chris@127 707 if (exclusive) {
Chris@127 708 m_manager->setSelection(selection);
Chris@127 709 } else {
Chris@127 710 m_manager->addSelection(selection);
Chris@127 711 }
Chris@127 712 }
Chris@127 713
Chris@127 714 update();
Chris@127 715
Chris@127 716 } else if (mode == ViewManager::DrawMode) {
Chris@127 717
Chris@127 718 Layer *layer = getSelectedLayer();
Chris@127 719 if (layer && layer->isLayerEditable()) {
Chris@127 720 layer->drawEnd(this, e);
Chris@127 721 update();
Chris@127 722 }
Chris@127 723
Chris@127 724 } else if (mode == ViewManager::EditMode) {
Chris@127 725
Chris@127 726 if (!editSelectionEnd(e)) {
Chris@127 727 Layer *layer = getSelectedLayer();
Chris@127 728 if (layer && layer->isLayerEditable()) {
Chris@127 729 layer->editEnd(this, e);
Chris@127 730 update();
Chris@127 731 }
Chris@127 732 }
Chris@127 733 }
Chris@127 734
Chris@127 735 m_clickedInRange = false;
Chris@127 736
Chris@127 737 emit paneInteractedWith();
Chris@127 738 }
Chris@127 739
Chris@127 740 void
Chris@127 741 Pane::mouseMoveEvent(QMouseEvent *e)
Chris@127 742 {
Chris@127 743 if (e->buttons() & Qt::RightButton) {
Chris@127 744 return;
Chris@127 745 }
Chris@127 746
Chris@127 747 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 748 if (m_manager) mode = m_manager->getToolMode();
Chris@127 749
Chris@127 750 QPoint prevPoint = m_identifyPoint;
Chris@127 751 m_identifyPoint = e->pos();
Chris@127 752
Chris@127 753 if (!m_clickedInRange) {
Chris@127 754
Chris@127 755 if (mode == ViewManager::SelectMode) {
Chris@127 756 bool closeToLeft = false, closeToRight = false;
Chris@127 757 getSelectionAt(e->x(), closeToLeft, closeToRight);
Chris@127 758 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@127 759 setCursor(Qt::SizeHorCursor);
Chris@127 760 } else {
Chris@127 761 setCursor(Qt::ArrowCursor);
Chris@127 762 }
Chris@127 763 }
Chris@127 764
Chris@127 765 //!!! if (mode != ViewManager::DrawMode) {
Chris@127 766
Chris@127 767 if (!m_manager->isPlaying()) {
Chris@127 768
Chris@127 769 if (getSelectedLayer()) {
Chris@127 770
Chris@127 771 bool previouslyIdentifying = m_identifyFeatures;
Chris@127 772 m_identifyFeatures = true;
Chris@127 773
Chris@127 774 if (m_identifyFeatures != previouslyIdentifying ||
Chris@127 775 m_identifyPoint != prevPoint) {
Chris@127 776 update();
Chris@127 777 }
Chris@127 778 }
Chris@127 779
Chris@127 780 }
Chris@127 781
Chris@127 782 // }
Chris@127 783
Chris@127 784 return;
Chris@127 785 }
Chris@127 786
Chris@127 787 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@127 788
Chris@127 789 if (m_shiftPressed) {
Chris@127 790
Chris@127 791 m_mousePos = e->pos();
Chris@127 792 update();
Chris@127 793
Chris@127 794 } else {
Chris@127 795
Chris@127 796 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
Chris@127 797
Chris@127 798 size_t newCentreFrame = m_dragCentreFrame;
Chris@127 799
Chris@127 800 if (frameOff < 0) {
Chris@127 801 newCentreFrame -= frameOff;
Chris@127 802 } else if (newCentreFrame >= size_t(frameOff)) {
Chris@127 803 newCentreFrame -= frameOff;
Chris@127 804 } else {
Chris@127 805 newCentreFrame = 0;
Chris@127 806 }
Chris@127 807
Chris@127 808 if (newCentreFrame >= getModelsEndFrame()) {
Chris@127 809 newCentreFrame = getModelsEndFrame();
Chris@127 810 if (newCentreFrame > 0) --newCentreFrame;
Chris@127 811 }
Chris@127 812
Chris@127 813 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
Chris@127 814 setCentreFrame(newCentreFrame);
Chris@127 815 }
Chris@127 816 }
Chris@127 817
Chris@127 818 } else if (mode == ViewManager::SelectMode) {
Chris@127 819
Chris@127 820 int mouseFrame = getFrameForX(e->x());
Chris@127 821 size_t resolution = 1;
Chris@127 822 int snapFrameLeft = mouseFrame;
Chris@127 823 int snapFrameRight = mouseFrame;
Chris@127 824
Chris@127 825 Layer *layer = getSelectedLayer();
Chris@127 826 if (layer && !m_shiftPressed) {
Chris@127 827 layer->snapToFeatureFrame(this, snapFrameLeft,
Chris@127 828 resolution, Layer::SnapLeft);
Chris@127 829 layer->snapToFeatureFrame(this, snapFrameRight,
Chris@127 830 resolution, Layer::SnapRight);
Chris@127 831 }
Chris@127 832
Chris@127 833 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
Chris@127 834
Chris@127 835 if (snapFrameLeft < 0) snapFrameLeft = 0;
Chris@127 836 if (snapFrameRight < 0) snapFrameRight = 0;
Chris@127 837
Chris@127 838 size_t min, max;
Chris@127 839
Chris@127 840 if (m_selectionStartFrame > snapFrameLeft) {
Chris@127 841 min = snapFrameLeft;
Chris@127 842 max = m_selectionStartFrame;
Chris@127 843 } else if (snapFrameRight > m_selectionStartFrame) {
Chris@127 844 min = m_selectionStartFrame;
Chris@127 845 max = snapFrameRight;
Chris@127 846 } else {
Chris@127 847 min = snapFrameLeft;
Chris@127 848 max = snapFrameRight;
Chris@127 849 }
Chris@127 850
Chris@127 851 if (m_manager) {
Chris@127 852 m_manager->setInProgressSelection(Selection(min, max),
Chris@127 853 !m_resizing && !m_ctrlPressed);
Chris@127 854 }
Chris@127 855
Chris@127 856 bool doScroll = false;
Chris@127 857 if (!m_manager) doScroll = true;
Chris@127 858 if (!m_manager->isPlaying()) doScroll = true;
Chris@127 859 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
Chris@127 860
Chris@127 861 if (doScroll) {
Chris@127 862 int offset = mouseFrame - getStartFrame();
Chris@127 863 int available = getEndFrame() - getStartFrame();
Chris@127 864 if (offset >= available * 0.95) {
Chris@127 865 int move = int(offset - available * 0.95) + 1;
Chris@127 866 setCentreFrame(m_centreFrame + move);
Chris@127 867 } else if (offset <= available * 0.10) {
Chris@127 868 int move = int(available * 0.10 - offset) + 1;
Chris@127 869 if (m_centreFrame > move) {
Chris@127 870 setCentreFrame(m_centreFrame - move);
Chris@127 871 } else {
Chris@127 872 setCentreFrame(0);
Chris@127 873 }
Chris@127 874 }
Chris@127 875 }
Chris@127 876
Chris@127 877 update();
Chris@127 878
Chris@127 879 } else if (mode == ViewManager::DrawMode) {
Chris@127 880
Chris@127 881 Layer *layer = getSelectedLayer();
Chris@127 882 if (layer && layer->isLayerEditable()) {
Chris@127 883 layer->drawDrag(this, e);
Chris@127 884 }
Chris@127 885
Chris@127 886 } else if (mode == ViewManager::EditMode) {
Chris@127 887
Chris@127 888 if (!editSelectionDrag(e)) {
Chris@127 889 Layer *layer = getSelectedLayer();
Chris@127 890 if (layer && layer->isLayerEditable()) {
Chris@127 891 layer->editDrag(this, e);
Chris@127 892 }
Chris@127 893 }
Chris@127 894 }
Chris@127 895 }
Chris@127 896
Chris@127 897 void
Chris@127 898 Pane::mouseDoubleClickEvent(QMouseEvent *e)
Chris@127 899 {
Chris@127 900 if (e->buttons() & Qt::RightButton) {
Chris@127 901 return;
Chris@127 902 }
Chris@127 903
Chris@127 904 // std::cerr << "mouseDoubleClickEvent" << std::endl;
Chris@127 905
Chris@127 906 m_clickPos = e->pos();
Chris@127 907 m_clickedInRange = true;
Chris@127 908 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
Chris@127 909 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
Chris@127 910
Chris@127 911 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 912 if (m_manager) mode = m_manager->getToolMode();
Chris@127 913
Chris@127 914 if (mode == ViewManager::NavigateMode ||
Chris@127 915 mode == ViewManager::EditMode) {
Chris@127 916
Chris@127 917 Layer *layer = getSelectedLayer();
Chris@127 918 if (layer && layer->isLayerEditable()) {
Chris@127 919 layer->editOpen(this, e);
Chris@127 920 }
Chris@127 921 }
Chris@127 922 }
Chris@127 923
Chris@127 924 void
Chris@127 925 Pane::leaveEvent(QEvent *)
Chris@127 926 {
Chris@127 927 bool previouslyIdentifying = m_identifyFeatures;
Chris@127 928 m_identifyFeatures = false;
Chris@127 929 if (previouslyIdentifying) update();
Chris@127 930 }
Chris@127 931
Chris@127 932 void
Chris@127 933 Pane::wheelEvent(QWheelEvent *e)
Chris@127 934 {
Chris@127 935 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
Chris@127 936
Chris@127 937 int count = e->delta();
Chris@127 938
Chris@127 939 if (count > 0) {
Chris@127 940 if (count >= 120) count /= 120;
Chris@127 941 else count = 1;
Chris@127 942 }
Chris@127 943
Chris@127 944 if (count < 0) {
Chris@127 945 if (count <= -120) count /= 120;
Chris@127 946 else count = -1;
Chris@127 947 }
Chris@127 948
Chris@127 949 if (e->modifiers() & Qt::ControlModifier) {
Chris@127 950
Chris@127 951 // Scroll left or right, rapidly
Chris@127 952
Chris@127 953 if (getStartFrame() < 0 &&
Chris@127 954 getEndFrame() >= getModelsEndFrame()) return;
Chris@127 955
Chris@127 956 long delta = ((width() / 2) * count * m_zoomLevel);
Chris@127 957
Chris@127 958 if (int(m_centreFrame) < delta) {
Chris@127 959 setCentreFrame(0);
Chris@127 960 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
Chris@127 961 setCentreFrame(getModelsEndFrame());
Chris@127 962 } else {
Chris@127 963 setCentreFrame(m_centreFrame - delta);
Chris@127 964 }
Chris@127 965
Chris@127 966 } else {
Chris@127 967
Chris@127 968 // Zoom in or out
Chris@127 969
Chris@127 970 int newZoomLevel = m_zoomLevel;
Chris@127 971
Chris@127 972 while (count > 0) {
Chris@127 973 if (newZoomLevel <= 2) {
Chris@127 974 newZoomLevel = 1;
Chris@127 975 break;
Chris@127 976 }
Chris@127 977 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
Chris@127 978 ZoomConstraint::RoundDown);
Chris@127 979 --count;
Chris@127 980 }
Chris@127 981
Chris@127 982 while (count < 0) {
Chris@127 983 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
Chris@127 984 ZoomConstraint::RoundUp);
Chris@127 985 ++count;
Chris@127 986 }
Chris@127 987
Chris@127 988 if (newZoomLevel != m_zoomLevel) {
Chris@127 989 setZoomLevel(newZoomLevel);
Chris@127 990 }
Chris@127 991 }
Chris@127 992
Chris@127 993 emit paneInteractedWith();
Chris@127 994 }
Chris@127 995
Chris@132 996 void
Chris@132 997 Pane::horizontalThumbwheelMoved(int value)
Chris@132 998 {
Chris@132 999 int count = 0;
Chris@132 1000 int level = 1;
Chris@132 1001 while (true) {
Chris@132 1002 if (value == count) break;
Chris@132 1003 int newLevel = getZoomConstraintBlockSize(level + 1,
Chris@132 1004 ZoomConstraint::RoundUp);
Chris@132 1005 if (newLevel == level) break;
Chris@132 1006 level = newLevel;
Chris@132 1007 ++count;
Chris@132 1008 }
Chris@132 1009
Chris@132 1010 std::cerr << "new level is " << level << std::endl;
Chris@132 1011 setZoomLevel(level);
Chris@132 1012 }
Chris@132 1013
Chris@132 1014 void
Chris@132 1015 Pane::verticalThumbwheelMoved(int value)
Chris@132 1016 {
Chris@132 1017 }
Chris@132 1018
Chris@127 1019 bool
Chris@127 1020 Pane::editSelectionStart(QMouseEvent *e)
Chris@127 1021 {
Chris@127 1022 if (!m_identifyFeatures ||
Chris@127 1023 !m_manager ||
Chris@127 1024 m_manager->getToolMode() != ViewManager::EditMode) {
Chris@127 1025 return false;
Chris@127 1026 }
Chris@127 1027
Chris@127 1028 bool closeToLeft, closeToRight;
Chris@127 1029 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
Chris@127 1030 if (s.isEmpty()) return false;
Chris@127 1031 m_editingSelection = s;
Chris@127 1032 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
Chris@127 1033 m_mousePos = e->pos();
Chris@127 1034 return true;
Chris@127 1035 }
Chris@127 1036
Chris@127 1037 bool
Chris@127 1038 Pane::editSelectionDrag(QMouseEvent *e)
Chris@127 1039 {
Chris@127 1040 if (m_editingSelection.isEmpty()) return false;
Chris@127 1041 m_mousePos = e->pos();
Chris@127 1042 update();
Chris@127 1043 return true;
Chris@127 1044 }
Chris@127 1045
Chris@127 1046 bool
Chris@127 1047 Pane::editSelectionEnd(QMouseEvent *e)
Chris@127 1048 {
Chris@127 1049 if (m_editingSelection.isEmpty()) return false;
Chris@127 1050
Chris@127 1051 int offset = m_mousePos.x() - m_clickPos.x();
Chris@127 1052 Layer *layer = getSelectedLayer();
Chris@127 1053
Chris@127 1054 if (offset == 0 || !layer) {
Chris@127 1055 m_editingSelection = Selection();
Chris@127 1056 return true;
Chris@127 1057 }
Chris@127 1058
Chris@127 1059 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
Chris@127 1060 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
Chris@127 1061
Chris@127 1062 long f0 = getFrameForX(p0);
Chris@127 1063 long f1 = getFrameForX(p1);
Chris@127 1064
Chris@127 1065 Selection newSelection(f0, f1);
Chris@127 1066
Chris@127 1067 if (m_editingSelectionEdge == 0) {
Chris@127 1068
Chris@127 1069 CommandHistory::getInstance()->startCompoundOperation
Chris@127 1070 (tr("Drag Selection"), true);
Chris@127 1071
Chris@127 1072 layer->moveSelection(m_editingSelection, f0);
Chris@127 1073
Chris@127 1074 } else {
Chris@127 1075
Chris@127 1076 CommandHistory::getInstance()->startCompoundOperation
Chris@127 1077 (tr("Resize Selection"), true);
Chris@127 1078
Chris@127 1079 if (m_editingSelectionEdge < 0) {
Chris@127 1080 f1 = m_editingSelection.getEndFrame();
Chris@127 1081 } else {
Chris@127 1082 f0 = m_editingSelection.getStartFrame();
Chris@127 1083 }
Chris@127 1084
Chris@127 1085 newSelection = Selection(f0, f1);
Chris@127 1086 layer->resizeSelection(m_editingSelection, newSelection);
Chris@127 1087 }
Chris@127 1088
Chris@127 1089 m_manager->removeSelection(m_editingSelection);
Chris@127 1090 m_manager->addSelection(newSelection);
Chris@127 1091
Chris@127 1092 CommandHistory::getInstance()->endCompoundOperation();
Chris@127 1093
Chris@127 1094 m_editingSelection = Selection();
Chris@127 1095 return true;
Chris@127 1096 }
Chris@127 1097
Chris@127 1098 void
Chris@127 1099 Pane::toolModeChanged()
Chris@127 1100 {
Chris@127 1101 ViewManager::ToolMode mode = m_manager->getToolMode();
Chris@127 1102 // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl;
Chris@127 1103
Chris@127 1104 switch (mode) {
Chris@127 1105
Chris@127 1106 case ViewManager::NavigateMode:
Chris@127 1107 setCursor(Qt::PointingHandCursor);
Chris@127 1108 break;
Chris@127 1109
Chris@127 1110 case ViewManager::SelectMode:
Chris@127 1111 setCursor(Qt::ArrowCursor);
Chris@127 1112 break;
Chris@127 1113
Chris@127 1114 case ViewManager::EditMode:
Chris@127 1115 setCursor(Qt::UpArrowCursor);
Chris@127 1116 break;
Chris@127 1117
Chris@127 1118 case ViewManager::DrawMode:
Chris@127 1119 setCursor(Qt::CrossCursor);
Chris@127 1120 break;
Chris@127 1121 /*
Chris@127 1122 case ViewManager::TextMode:
Chris@127 1123 setCursor(Qt::IBeamCursor);
Chris@127 1124 break;
Chris@127 1125 */
Chris@127 1126 }
Chris@127 1127 }
Chris@127 1128
Chris@127 1129 QString
Chris@127 1130 Pane::toXmlString(QString indent, QString extraAttributes) const
Chris@127 1131 {
Chris@127 1132 return View::toXmlString
Chris@127 1133 (indent,
Chris@127 1134 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
Chris@127 1135 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
Chris@127 1136 }
Chris@127 1137
Chris@127 1138
Chris@127 1139 #ifdef INCLUDE_MOCFILES
Chris@127 1140 #include "Pane.moc.cpp"
Chris@127 1141 #endif
Chris@127 1142