annotate view/Pane.cpp @ 646:ba76130ed7e5 tonioni

added context sensitive mouse pointers in note edit tool mode
author gyorgyf
date Sat, 15 Jun 2013 17:04:03 +0100
parents c8f45afb83d5
children 2ad082c5a090 12d570c27d85
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@264 7 This file copyright 2006-2007 Chris Cannam and QMUL.
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@376 23 #include "widgets/CommandHistory.h"
Chris@376 24 #include "widgets/TextAbbrev.h"
Chris@338 25 #include "base/Preferences.h"
Chris@127 26 #include "layer/WaveformLayer.h"
Chris@127 27
gyorgyf@646 28 // GF: added so we can propagate the mouse move event to the note layer for context handling.
gyorgyf@646 29 #include "layer/LayerFactory.h"
gyorgyf@646 30 #include "layer/FlexiNoteLayer.h"
gyorgyf@646 31
gyorgyf@646 32
Chris@326 33 //!!! ugh
Chris@326 34 #include "data/model/WaveFileModel.h"
Chris@326 35
Chris@127 36 #include <QPaintEvent>
Chris@127 37 #include <QPainter>
Chris@257 38 #include <QBitmap>
Chris@312 39 #include <QDragEnterEvent>
Chris@312 40 #include <QDropEvent>
Chris@257 41 #include <QCursor>
Chris@316 42 #include <QTextStream>
Chris@316 43
Chris@127 44 #include <iostream>
Chris@127 45 #include <cmath>
Chris@127 46
Chris@133 47 //!!! for HUD -- pull out into a separate class
Chris@133 48 #include <QFrame>
Chris@133 49 #include <QGridLayout>
Chris@133 50 #include <QPushButton>
Chris@133 51 #include "widgets/Thumbwheel.h"
Chris@172 52 #include "widgets/Panner.h"
Chris@188 53 #include "widgets/RangeInputDialog.h"
Chris@189 54 #include "widgets/NotifyingPushButton.h"
Chris@133 55
Chris@282 56 #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget
Chris@282 57
Chris@363 58 //#define DEBUG_PANE
Chris@363 59
Chris@127 60 using std::cerr;
Chris@127 61 using std::endl;
Chris@127 62
Chris@267 63 QCursor *Pane::m_measureCursor1 = 0;
Chris@267 64 QCursor *Pane::m_measureCursor2 = 0;
Chris@262 65
Chris@127 66 Pane::Pane(QWidget *w) :
Chris@127 67 View(w, true),
Chris@127 68 m_identifyFeatures(false),
Chris@127 69 m_clickedInRange(false),
Chris@127 70 m_shiftPressed(false),
Chris@127 71 m_ctrlPressed(false),
Chris@510 72 m_altPressed(false),
Chris@127 73 m_navigating(false),
Chris@127 74 m_resizing(false),
Chris@343 75 m_editing(false),
Chris@343 76 m_releasing(false),
Chris@133 77 m_centreLineVisible(true),
Chris@222 78 m_scaleWidth(0),
Chris@237 79 m_headsUpDisplay(0),
Chris@237 80 m_vpan(0),
Chris@237 81 m_hthumb(0),
Chris@237 82 m_vthumb(0),
Chris@290 83 m_reset(0),
Chris@290 84 m_mouseInWidget(false)
Chris@127 85 {
Chris@127 86 setObjectName("Pane");
Chris@127 87 setMouseTracking(true);
Chris@312 88 setAcceptDrops(true);
Chris@133 89
Chris@133 90 updateHeadsUpDisplay();
Chris@456 91
Chris@456 92
Chris@587 93 // SVDEBUG << "Pane::Pane(" << this << ") returning" << endl;
Chris@133 94 }
Chris@133 95
Chris@133 96 void
Chris@133 97 Pane::updateHeadsUpDisplay()
Chris@133 98 {
Chris@382 99 Profiler profiler("Pane::updateHeadsUpDisplay");
Chris@187 100
Chris@192 101 if (!isVisible()) return;
Chris@192 102
Chris@132 103 /*
Chris@132 104 int count = 0;
Chris@132 105 int currentLevel = 1;
Chris@132 106 int level = 1;
Chris@132 107 while (true) {
Chris@132 108 if (getZoomLevel() == level) currentLevel = count;
Chris@132 109 int newLevel = getZoomConstraintBlockSize(level + 1,
Chris@132 110 ZoomConstraint::RoundUp);
Chris@132 111 if (newLevel == level) break;
Chris@132 112 if (newLevel == 131072) break; //!!! just because
Chris@132 113 level = newLevel;
Chris@132 114 ++count;
Chris@132 115 }
Chris@132 116
Chris@132 117 std::cerr << "Have " << count+1 << " zoom levels" << std::endl;
Chris@132 118 */
Chris@133 119
Chris@188 120 Layer *layer = 0;
Chris@188 121 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
Chris@188 122
Chris@133 123 if (!m_headsUpDisplay) {
Chris@133 124
Chris@133 125 m_headsUpDisplay = new QFrame(this);
Chris@133 126
Chris@133 127 QGridLayout *layout = new QGridLayout;
Chris@133 128 layout->setMargin(0);
Chris@133 129 layout->setSpacing(0);
Chris@133 130 m_headsUpDisplay->setLayout(layout);
Chris@133 131
Chris@133 132 m_hthumb = new Thumbwheel(Qt::Horizontal);
Chris@187 133 m_hthumb->setObjectName(tr("Horizontal Zoom"));
Chris@260 134 m_hthumb->setCursor(Qt::ArrowCursor);
Chris@173 135 layout->addWidget(m_hthumb, 1, 0, 1, 2);
Chris@133 136 m_hthumb->setFixedWidth(70);
Chris@133 137 m_hthumb->setFixedHeight(16);
Chris@133 138 m_hthumb->setDefaultValue(0);
Chris@165 139 m_hthumb->setSpeed(0.6);
Chris@133 140 connect(m_hthumb, SIGNAL(valueChanged(int)), this,
Chris@133 141 SLOT(horizontalThumbwheelMoved(int)));
Chris@189 142 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@189 143 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@172 144
Chris@172 145 m_vpan = new Panner;
Chris@260 146 m_vpan->setCursor(Qt::ArrowCursor);
Chris@172 147 layout->addWidget(m_vpan, 0, 1);
Chris@173 148 m_vpan->setFixedWidth(12);
Chris@172 149 m_vpan->setFixedHeight(70);
Chris@174 150 m_vpan->setAlpha(80, 130);
Chris@174 151 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)),
Chris@174 152 this, SLOT(verticalPannerMoved(float, float, float, float)));
Chris@188 153 connect(m_vpan, SIGNAL(doubleClicked()),
Chris@188 154 this, SLOT(editVerticalPannerExtents()));
Chris@189 155 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@189 156 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@172 157
Chris@133 158 m_vthumb = new Thumbwheel(Qt::Vertical);
Chris@187 159 m_vthumb->setObjectName(tr("Vertical Zoom"));
Chris@260 160 m_vthumb->setCursor(Qt::ArrowCursor);
Chris@172 161 layout->addWidget(m_vthumb, 0, 2);
Chris@133 162 m_vthumb->setFixedWidth(16);
Chris@133 163 m_vthumb->setFixedHeight(70);
Chris@133 164 connect(m_vthumb, SIGNAL(valueChanged(int)), this,
Chris@133 165 SLOT(verticalThumbwheelMoved(int)));
Chris@189 166 connect(m_vthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@189 167 connect(m_vthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@133 168
Chris@188 169 if (layer) {
Chris@188 170 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper();
Chris@188 171 if (rm) m_vthumb->setRangeMapper(rm);
Chris@188 172 }
Chris@188 173
Chris@189 174 m_reset = new NotifyingPushButton;
gyorgyf@645 175 m_reset->setFlat(true);
Chris@260 176 m_reset->setCursor(Qt::ArrowCursor);
Chris@189 177 m_reset->setFixedHeight(16);
Chris@189 178 m_reset->setFixedWidth(16);
Chris@499 179 m_reset->setIcon(QPixmap(":/icons/zoom-reset.png"));
Chris@501 180 m_reset->setToolTip(tr("Reset zoom to default"));
Chris@189 181 layout->addWidget(m_reset, 1, 2);
Chris@492 182
Chris@492 183 layout->setColumnStretch(0, 20);
Chris@492 184
Chris@189 185 connect(m_reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault()));
Chris@189 186 connect(m_reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault()));
Chris@189 187 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault()));
Chris@189 188 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@189 189 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@133 190 }
Chris@133 191
Chris@133 192 int count = 0;
Chris@133 193 int current = 0;
Chris@133 194 int level = 1;
Chris@133 195
Chris@137 196 //!!! pull out into function (presumably in View)
Chris@137 197 bool haveConstraint = false;
Chris@137 198 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
Chris@137 199 ++i) {
Chris@137 200 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
Chris@137 201 haveConstraint = true;
Chris@137 202 break;
Chris@137 203 }
Chris@137 204 }
Chris@137 205
Chris@137 206 if (haveConstraint) {
Chris@137 207 while (true) {
Chris@137 208 if (getZoomLevel() == level) current = count;
Chris@137 209 int newLevel = getZoomConstraintBlockSize(level + 1,
Chris@137 210 ZoomConstraint::RoundUp);
Chris@137 211 if (newLevel == level) break;
Chris@137 212 level = newLevel;
Chris@137 213 if (++count == 50) break;
Chris@137 214 }
Chris@137 215 } else {
Chris@137 216 // if we have no particular constraints, we can really spread out
Chris@137 217 while (true) {
Chris@137 218 if (getZoomLevel() >= level) current = count;
Chris@137 219 int step = level / 10;
Chris@137 220 int pwr = 0;
Chris@137 221 while (step > 0) {
Chris@137 222 ++pwr;
Chris@137 223 step /= 2;
Chris@137 224 }
Chris@137 225 step = 1;
Chris@137 226 while (pwr > 0) {
Chris@137 227 step *= 2;
Chris@137 228 --pwr;
Chris@137 229 }
Chris@154 230 // std::cerr << level << std::endl;
Chris@137 231 level += step;
Chris@137 232 if (++count == 100 || level > 262144) break;
Chris@137 233 }
Chris@133 234 }
Chris@133 235
Chris@133 236 // std::cerr << "Have " << count << " zoom levels" << std::endl;
Chris@133 237
Chris@133 238 m_hthumb->setMinimumValue(0);
Chris@133 239 m_hthumb->setMaximumValue(count);
Chris@133 240 m_hthumb->setValue(count - current);
Chris@133 241
Chris@133 242 // std::cerr << "set value to " << count-current << std::endl;
Chris@133 243
Chris@133 244 // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl;
Chris@133 245
Chris@133 246 if (count != 50 && m_hthumb->getDefaultValue() == 0) {
Chris@133 247 m_hthumb->setDefaultValue(count - current);
Chris@133 248 // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl;
Chris@133 249 }
Chris@133 250
Chris@204 251 bool haveVThumb = false;
Chris@204 252
Chris@133 253 if (layer) {
Chris@133 254 int defaultStep = 0;
Chris@133 255 int max = layer->getVerticalZoomSteps(defaultStep);
Chris@133 256 if (max == 0) {
Chris@133 257 m_vthumb->hide();
Chris@133 258 } else {
Chris@204 259 haveVThumb = true;
Chris@133 260 m_vthumb->show();
Chris@187 261 m_vthumb->blockSignals(true);
Chris@133 262 m_vthumb->setMinimumValue(0);
Chris@133 263 m_vthumb->setMaximumValue(max);
Chris@133 264 m_vthumb->setDefaultValue(defaultStep);
Chris@133 265 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
Chris@187 266 m_vthumb->blockSignals(false);
Chris@135 267
Chris@205 268 // std::cerr << "Vertical thumbwheel: min 0, max " << max
Chris@205 269 // << ", default " << defaultStep << ", value "
Chris@205 270 // << m_vthumb->getValue() << std::endl;
Chris@135 271
Chris@133 272 }
Chris@133 273 }
Chris@133 274
Chris@174 275 updateVerticalPanner();
Chris@174 276
Chris@133 277 if (m_manager && m_manager->getZoomWheelsEnabled() &&
Chris@133 278 width() > 120 && height() > 100) {
Chris@165 279 if (!m_headsUpDisplay->isVisible()) {
Chris@165 280 m_headsUpDisplay->show();
Chris@165 281 }
Chris@204 282 if (haveVThumb) {
Chris@204 283 m_headsUpDisplay->setFixedHeight(m_vthumb->height() + m_hthumb->height());
Chris@133 284 m_headsUpDisplay->move(width() - 86, height() - 86);
Chris@133 285 } else {
Chris@204 286 m_headsUpDisplay->setFixedHeight(m_hthumb->height());
Chris@204 287 m_headsUpDisplay->move(width() - 86, height() - 16);
Chris@133 288 }
Chris@133 289 } else {
Chris@133 290 m_headsUpDisplay->hide();
Chris@133 291 }
Chris@127 292 }
Chris@127 293
Chris@174 294 void
Chris@174 295 Pane::updateVerticalPanner()
Chris@174 296 {
Chris@174 297 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
Chris@174 298
Chris@208 299 // In principle we should show or hide the panner on the basis of
Chris@208 300 // whether the top layer has adjustable display extents, and we do
Chris@208 301 // that below. However, we have no basis for layout of the panner
Chris@208 302 // if the vertical scroll wheel is not also present. So if we
Chris@208 303 // have no vertical scroll wheel, we should remove the panner as
Chris@208 304 // well. Ideally any layer that implements display extents should
Chris@208 305 // implement vertical zoom steps as well, but they don't all at
Chris@208 306 // the moment.
Chris@208 307
Chris@208 308 Layer *layer = 0;
Chris@208 309 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
Chris@208 310 int discard;
Chris@208 311 if (layer && layer->getVerticalZoomSteps(discard) == 0) {
Chris@208 312 m_vpan->hide();
Chris@208 313 return;
Chris@208 314 }
Chris@208 315
Chris@174 316 float vmin, vmax, dmin, dmax;
Chris@174 317 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) {
Chris@174 318 float y0 = (dmin - vmin) / (vmax - vmin);
Chris@174 319 float y1 = (dmax - vmin) / (vmax - vmin);
Chris@174 320 m_vpan->blockSignals(true);
Chris@174 321 m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0);
Chris@174 322 m_vpan->blockSignals(false);
Chris@174 323 m_vpan->show();
Chris@174 324 } else {
Chris@174 325 m_vpan->hide();
Chris@174 326 }
Chris@174 327 }
Chris@174 328
Chris@127 329 bool
Chris@127 330 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const
Chris@127 331 {
Chris@127 332 QPoint discard;
Chris@127 333 bool b0, b1;
Chris@127 334
Chris@262 335 if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) {
Chris@262 336 return false;
Chris@262 337 }
Chris@262 338
Chris@326 339 if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) {
Chris@326 340 return false;
Chris@326 341 }
Chris@326 342
Chris@127 343 if (layer == getSelectedLayer() &&
gyorgyf@645 344 !shouldIlluminateLocalSelection(discard, b0, b1)) {
gyorgyf@645 345
gyorgyf@645 346 pos = m_identifyPoint;
gyorgyf@645 347 return m_identifyFeatures;
Chris@127 348 }
Chris@127 349
Chris@127 350 return false;
Chris@127 351 }
Chris@127 352
Chris@127 353 bool
Chris@127 354 Pane::shouldIlluminateLocalSelection(QPoint &pos,
gyorgyf@645 355 bool &closeToLeft,
gyorgyf@645 356 bool &closeToRight) const
Chris@127 357 {
Chris@127 358 if (m_identifyFeatures &&
gyorgyf@645 359 m_manager &&
gyorgyf@645 360 m_manager->getToolMode() == ViewManager::EditMode &&
gyorgyf@645 361 !m_manager->getSelections().empty() &&
gyorgyf@645 362 !selectionIsBeingEdited()) {
gyorgyf@645 363
gyorgyf@645 364 Selection s(getSelectionAt(m_identifyPoint.x(),
gyorgyf@645 365 closeToLeft, closeToRight));
gyorgyf@645 366
gyorgyf@645 367 if (!s.isEmpty()) {
gyorgyf@645 368 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) {
gyorgyf@645 369
gyorgyf@645 370 pos = m_identifyPoint;
gyorgyf@645 371 return true;
gyorgyf@645 372 }
gyorgyf@645 373 }
Chris@127 374 }
Chris@127 375
Chris@127 376 return false;
Chris@127 377 }
Chris@127 378
Chris@127 379 bool
Chris@127 380 Pane::selectionIsBeingEdited() const
Chris@127 381 {
Chris@127 382 if (!m_editingSelection.isEmpty()) {
gyorgyf@645 383 if (m_mousePos != m_clickPos &&
gyorgyf@645 384 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
gyorgyf@645 385 return true;
gyorgyf@645 386 }
Chris@127 387 }
Chris@127 388 return false;
Chris@127 389 }
Chris@127 390
Chris@127 391 void
Chris@127 392 Pane::setCentreLineVisible(bool visible)
Chris@127 393 {
Chris@127 394 m_centreLineVisible = visible;
Chris@127 395 update();
Chris@127 396 }
Chris@127 397
Chris@127 398 void
Chris@127 399 Pane::paintEvent(QPaintEvent *e)
Chris@127 400 {
Chris@127 401 // Profiler profiler("Pane::paintEvent", true);
Chris@127 402
Chris@127 403 QPainter paint;
Chris@127 404
Chris@127 405 QRect r(rect());
Chris@261 406 if (e) r = e->rect();
Chris@127 407
Chris@127 408 View::paintEvent(e);
Chris@127 409
Chris@127 410 paint.begin(this);
Chris@339 411 setPaintFont(paint);
Chris@338 412
Chris@261 413 if (e) paint.setClipRect(r);
Chris@127 414
Chris@259 415 ViewManager::ToolMode toolMode = m_manager->getToolMode();
Chris@259 416
Chris@127 417 if (m_manager &&
Chris@290 418 // !m_manager->isPlaying() &&
Chris@290 419 m_mouseInWidget &&
Chris@259 420 toolMode == ViewManager::MeasureMode) {
Chris@127 421
Chris@127 422 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127 423 --vi;
Chris@127 424
Chris@127 425 std::vector<QRect> crosshairExtents;
Chris@127 426
Chris@127 427 if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint,
Chris@127 428 crosshairExtents)) {
Chris@127 429 (*vi)->paintCrosshairs(this, paint, m_identifyPoint);
Chris@127 430 break;
Chris@127 431 } else if ((*vi)->isLayerOpaque()) {
Chris@127 432 break;
Chris@127 433 }
Chris@127 434 }
Chris@127 435 }
Chris@127 436
Chris@268 437 Layer *topLayer = getTopLayer();
Chris@277 438 bool haveSomeTimeXAxis = false;
Chris@268 439
Chris@258 440 const Model *waveformModel = 0; // just for reporting purposes
Chris@326 441 const Model *workModel = 0;
Chris@326 442
Chris@127 443 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127 444 --vi;
Chris@277 445 if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) {
Chris@277 446 haveSomeTimeXAxis = true;
Chris@277 447 }
Chris@127 448 if (dynamic_cast<WaveformLayer *>(*vi)) {
Chris@127 449 waveformModel = (*vi)->getModel();
Chris@326 450 workModel = waveformModel;
Chris@326 451 } else {
Chris@326 452 Model *m = (*vi)->getModel();
Chris@326 453 if (dynamic_cast<WaveFileModel *>(m)) {
Chris@326 454 workModel = m;
Chris@326 455 } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) {
Chris@326 456 workModel = m->getSourceModel();
Chris@326 457 }
Chris@127 458 }
Chris@326 459
Chris@326 460 if (waveformModel && workModel && haveSomeTimeXAxis) break;
Chris@258 461 }
Chris@127 462
Chris@261 463 m_scaleWidth = 0;
Chris@261 464
Chris@261 465 if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
Chris@261 466 drawVerticalScale(r, topLayer, paint);
Chris@261 467 }
Chris@261 468
Chris@326 469 if (m_identifyFeatures &&
Chris@326 470 m_manager && m_manager->shouldIlluminateLocalFeatures() &&
Chris@326 471 topLayer) {
Chris@261 472 drawFeatureDescription(topLayer, paint);
Chris@261 473 }
Chris@261 474
Chris@261 475 int sampleRate = getModelsSampleRate();
Chris@261 476 paint.setBrush(Qt::NoBrush);
Chris@261 477
Chris@261 478 if (m_centreLineVisible &&
Chris@261 479 m_manager &&
Chris@261 480 m_manager->shouldShowCentreLine()) {
Chris@277 481 drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis);
Chris@261 482 }
Chris@261 483
Chris@261 484 paint.setPen(QColor(50, 50, 50));
Chris@261 485
Chris@261 486 if (waveformModel &&
Chris@261 487 m_manager &&
Chris@261 488 m_manager->shouldShowDuration()) {
Chris@261 489 drawDurationAndRate(r, waveformModel, sampleRate, paint);
Chris@261 490 }
Chris@261 491
Chris@326 492 bool haveWorkTitle = false;
Chris@326 493
Chris@326 494 if (workModel &&
Chris@326 495 m_manager &&
Chris@326 496 m_manager->shouldShowWorkTitle()) {
Chris@326 497 drawWorkTitle(r, paint, workModel);
Chris@326 498 haveWorkTitle = true;
Chris@326 499 }
Chris@326 500
Chris@326 501 if (workModel &&
Chris@320 502 m_manager &&
Chris@320 503 m_manager->getAlignMode()) {
Chris@326 504 drawAlignmentStatus(r, paint, workModel, haveWorkTitle);
Chris@320 505 }
Chris@320 506
Chris@261 507 if (m_manager &&
Chris@261 508 m_manager->shouldShowLayerNames()) {
Chris@261 509 drawLayerNames(r, paint);
Chris@261 510 }
Chris@261 511
Chris@262 512 if (m_shiftPressed && m_clickedInRange &&
Chris@283 513 (toolMode == ViewManager::NavigateMode || m_navigating)) {
Chris@261 514
Chris@261 515 //!!! be nice if this looked a bit more in keeping with the
Chris@261 516 //selection block
Chris@262 517
Chris@262 518 paint.setPen(Qt::blue);
Chris@262 519 //!!! shouldn't use clickPos -- needs to use a clicked frame
Chris@262 520 paint.drawRect(m_clickPos.x(), m_clickPos.y(),
Chris@262 521 m_mousePos.x() - m_clickPos.x(),
Chris@262 522 m_mousePos.y() - m_clickPos.y());
Chris@261 523
Chris@262 524 }
Chris@261 525
Chris@266 526 if (toolMode == ViewManager::MeasureMode && topLayer) {
Chris@272 527 bool showFocus = false;
Chris@272 528 if (!m_manager || !m_manager->isPlaying()) showFocus = true;
Chris@272 529 topLayer->paintMeasurementRects(this, paint, showFocus, m_identifyPoint);
Chris@261 530 }
Chris@261 531
Chris@261 532 if (selectionIsBeingEdited()) {
Chris@261 533 drawEditingSelection(paint);
Chris@261 534 }
Chris@261 535
Chris@261 536 paint.end();
Chris@261 537 }
Chris@261 538
Chris@276 539 size_t
Chris@276 540 Pane::getVerticalScaleWidth() const
Chris@276 541 {
Chris@276 542 if (m_scaleWidth > 0) return m_scaleWidth;
Chris@276 543 else return 0;
Chris@276 544 }
Chris@276 545
Chris@261 546 void
Chris@261 547 Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint)
Chris@261 548 {
Chris@258 549 Layer *scaleLayer = 0;
Chris@258 550
Chris@261 551 float min, max;
Chris@261 552 bool log;
Chris@261 553 QString unit;
Chris@258 554
Chris@261 555 // If the top layer has no scale and reports no display
Chris@261 556 // extents, but does report a unit, then the scale should be
Chris@261 557 // drawn from any underlying layer with a scale and that unit.
Chris@261 558 // If the top layer has no scale and no value extents at all,
Chris@261 559 // then the scale should be drawn from any underlying layer
Chris@261 560 // with a scale regardless of unit.
Chris@258 561
Chris@607 562 int sw = topLayer->getVerticalScaleWidth
Chris@607 563 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@258 564
Chris@261 565 if (sw > 0) {
Chris@261 566 scaleLayer = topLayer;
Chris@261 567 m_scaleWidth = sw;
Chris@258 568
Chris@261 569 } else {
Chris@258 570
Chris@261 571 bool hasDisplayExtents = topLayer->getDisplayExtents(min, max);
Chris@261 572 bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit);
Chris@261 573
Chris@261 574 if (!hasDisplayExtents) {
Chris@258 575
Chris@261 576 if (!hasValueExtents) {
Chris@258 577
Chris@261 578 for (LayerList::iterator vi = m_layers.end();
Chris@261 579 vi != m_layers.begin(); ) {
Chris@261 580
Chris@261 581 --vi;
Chris@261 582
Chris@261 583 if ((*vi) == topLayer) continue;
Chris@261 584
Chris@607 585 sw = (*vi)->getVerticalScaleWidth
Chris@607 586 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@261 587
Chris@261 588 if (sw > 0) {
Chris@261 589 scaleLayer = *vi;
Chris@261 590 m_scaleWidth = sw;
Chris@261 591 break;
Chris@261 592 }
Chris@261 593 }
Chris@261 594 } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents
Chris@258 595
Chris@261 596 QString requireUnit = unit;
Chris@261 597
Chris@261 598 for (LayerList::iterator vi = m_layers.end();
Chris@261 599 vi != m_layers.begin(); ) {
Chris@258 600
Chris@261 601 --vi;
Chris@258 602
Chris@261 603 if ((*vi) == topLayer) continue;
Chris@258 604
Chris@261 605 if ((*vi)->getDisplayExtents(min, max)) {
Chris@261 606
Chris@261 607 // search no further than this: if the
Chris@261 608 // scale from this layer isn't suitable,
Chris@261 609 // we'll have to draw no scale (else we'd
Chris@261 610 // risk ending up with the wrong scale)
Chris@261 611
Chris@261 612 if ((*vi)->getValueExtents(min, max, log, unit) &&
Chris@261 613 unit == requireUnit) {
Chris@261 614
Chris@607 615 sw = (*vi)->getVerticalScaleWidth
Chris@607 616 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@261 617 if (sw > 0) {
Chris@261 618 scaleLayer = *vi;
Chris@261 619 m_scaleWidth = sw;
Chris@261 620 }
Chris@258 621 }
Chris@261 622 break;
Chris@258 623 }
Chris@258 624 }
Chris@258 625 }
Chris@127 626 }
Chris@258 627 }
Chris@127 628
Chris@258 629 if (!scaleLayer) m_scaleWidth = 0;
Chris@258 630
Chris@258 631 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) {
Chris@127 632
gyorgyf@645 633 // Profiler profiler("Pane::paintEvent - painting vertical scale", true);
gyorgyf@645 634
gyorgyf@645 635 // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl;
Chris@258 636 paint.save();
Chris@258 637
Chris@287 638 paint.setPen(getForeground());
Chris@287 639 paint.setBrush(getBackground());
Chris@258 640 paint.drawRect(0, -1, m_scaleWidth, height()+1);
Chris@258 641
Chris@258 642 paint.setBrush(Qt::NoBrush);
Chris@258 643 scaleLayer->paintVerticalScale
Chris@607 644 (this, m_manager->shouldShowVerticalColourScale(),
Chris@607 645 paint, QRect(0, 0, m_scaleWidth, height()));
Chris@258 646
Chris@258 647 paint.restore();
Chris@258 648 }
Chris@261 649 }
Chris@261 650
Chris@261 651 void
Chris@261 652 Pane::drawFeatureDescription(Layer *topLayer, QPainter &paint)
Chris@261 653 {
Chris@261 654 QPoint pos = m_identifyPoint;
Chris@261 655 QString desc = topLayer->getFeatureDescription(this, pos);
gyorgyf@645 656
Chris@261 657 if (desc != "") {
Chris@261 658
Chris@261 659 paint.save();
Chris@261 660
Chris@261 661 int tabStop =
Chris@261 662 paint.fontMetrics().width(tr("Some lengthy prefix:"));
Chris@261 663
Chris@261 664 QRect boundingRect =
Chris@261 665 paint.fontMetrics().boundingRect
Chris@261 666 (rect(),
Chris@261 667 Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs,
Chris@261 668 desc, tabStop);
Chris@261 669
Chris@261 670 if (hasLightBackground()) {
Chris@261 671 paint.setPen(Qt::NoPen);
Chris@261 672 paint.setBrush(QColor(250, 250, 250, 200));
Chris@261 673 } else {
Chris@261 674 paint.setPen(Qt::NoPen);
Chris@261 675 paint.setBrush(QColor(50, 50, 50, 200));
Chris@261 676 }
Chris@261 677
Chris@261 678 int extra = paint.fontMetrics().descent();
Chris@261 679 paint.drawRect(width() - boundingRect.width() - 10 - extra,
Chris@261 680 10 - extra,
Chris@261 681 boundingRect.width() + 2 * extra,
Chris@261 682 boundingRect.height() + extra);
Chris@261 683
Chris@261 684 if (hasLightBackground()) {
Chris@261 685 paint.setPen(QColor(150, 20, 0));
Chris@261 686 } else {
Chris@261 687 paint.setPen(QColor(255, 150, 100));
Chris@261 688 }
Chris@261 689
Chris@261 690 QTextOption option;
Chris@261 691 option.setWrapMode(QTextOption::NoWrap);
Chris@261 692 option.setAlignment(Qt::AlignRight | Qt::AlignTop);
Chris@261 693 option.setTabStop(tabStop);
Chris@261 694 paint.drawText(QRectF(width() - boundingRect.width() - 10, 10,
Chris@261 695 boundingRect.width(),
Chris@261 696 boundingRect.height()),
Chris@261 697 desc,
Chris@261 698 option);
Chris@261 699
Chris@261 700 paint.restore();
Chris@261 701 }
Chris@261 702 }
Chris@258 703
Chris@261 704 void
Chris@277 705 Pane::drawCentreLine(int sampleRate, QPainter &paint, bool omitLine)
Chris@261 706 {
Chris@261 707 int fontHeight = paint.fontMetrics().height();
Chris@261 708 int fontAscent = paint.fontMetrics().ascent();
Chris@261 709
Chris@261 710 QColor c = QColor(0, 0, 0);
Chris@261 711 if (!hasLightBackground()) {
Chris@261 712 c = QColor(240, 240, 240);
Chris@261 713 }
Chris@277 714
Chris@261 715 paint.setPen(c);
Chris@274 716 int x = width() / 2;
Chris@277 717
Chris@277 718 if (!omitLine) {
Chris@277 719 paint.drawLine(x, 0, x, height() - 1);
Chris@277 720 paint.drawLine(x-1, 1, x+1, 1);
Chris@277 721 paint.drawLine(x-2, 0, x+2, 0);
Chris@277 722 paint.drawLine(x-1, height() - 2, x+1, height() - 2);
Chris@277 723 paint.drawLine(x-2, height() - 1, x+2, height() - 1);
Chris@277 724 }
Chris@261 725
Chris@261 726 paint.setPen(QColor(50, 50, 50));
Chris@261 727
Chris@261 728 int y = height() - fontHeight + fontAscent - 6;
Chris@261 729
Chris@261 730 LayerList::iterator vi = m_layers.end();
Chris@261 731
Chris@261 732 if (vi != m_layers.begin()) {
gyorgyf@645 733
Chris@261 734 switch ((*--vi)->getPreferredFrameCountPosition()) {
Chris@258 735
Chris@261 736 case Layer::PositionTop:
Chris@261 737 y = fontAscent + 6;
Chris@261 738 break;
Chris@258 739
Chris@261 740 case Layer::PositionMiddle:
Chris@261 741 y = (height() - fontHeight) / 2
Chris@261 742 + fontAscent;
Chris@261 743 break;
Chris@127 744
Chris@261 745 case Layer::PositionBottom:
Chris@261 746 // y already set correctly
Chris@261 747 break;
Chris@127 748 }
Chris@127 749 }
Chris@127 750
Chris@261 751 if (m_manager && m_manager->shouldShowFrameCount()) {
Chris@261 752
Chris@261 753 if (sampleRate) {
Chris@127 754
Chris@261 755 QString text(QString::fromStdString
Chris@261 756 (RealTime::frame2RealTime
Chris@549 757 (m_centreFrame, sampleRate)
Chris@549 758 .toText(true)));
Chris@127 759
Chris@261 760 int tw = paint.fontMetrics().width(text);
Chris@261 761 int x = width()/2 - 4 - tw;
Chris@127 762
Chris@127 763 drawVisibleText(paint, x, y, text, OutlinedText);
Chris@127 764 }
Chris@261 765
Chris@261 766 QString text = QString("%1").arg(m_centreFrame);
Chris@261 767
Chris@261 768 int x = width()/2 + 4;
Chris@261 769
Chris@261 770 drawVisibleText(paint, x, y, text, OutlinedText);
Chris@261 771 }
Chris@261 772 }
Chris@127 773
Chris@261 774 void
Chris@326 775 Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model,
Chris@326 776 bool down)
Chris@320 777 {
Chris@320 778 const Model *reference = model->getAlignmentReference();
Chris@320 779 /*
Chris@320 780 if (!reference) {
Chris@320 781 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << std::endl;
Chris@320 782 } else if (reference == model) {
Chris@320 783 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << std::endl;
Chris@320 784 } else {
Chris@320 785 std::cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << std::endl;
Chris@320 786 }
Chris@320 787 */
Chris@320 788 QString text;
Chris@320 789 int completion = 100;
Chris@320 790
Chris@320 791 if (reference == model) {
Chris@320 792 text = tr("Reference");
Chris@320 793 } else if (!reference) {
Chris@320 794 text = tr("Unaligned");
Chris@320 795 } else {
Chris@320 796 completion = model->getAlignmentCompletion();
Chris@320 797 if (completion == 0) {
Chris@320 798 text = tr("Unaligned");
Chris@320 799 } else if (completion < 100) {
Chris@320 800 text = tr("Aligning: %1%").arg(completion);
Chris@320 801 } else {
Chris@320 802 text = tr("Aligned");
Chris@320 803 }
Chris@320 804 }
Chris@320 805
Chris@320 806 paint.save();
Chris@320 807 QFont font(paint.font());
Chris@320 808 font.setBold(true);
Chris@320 809 paint.setFont(font);
Chris@326 810 if (completion < 100) paint.setBrush(Qt::red);
Chris@326 811
Chris@326 812 int y = 5;
Chris@326 813 if (down) y += paint.fontMetrics().height();
Chris@326 814 int w = paint.fontMetrics().width(text);
Chris@326 815 int h = paint.fontMetrics().height();
Chris@326 816 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
Chris@326 817 paint.restore();
Chris@326 818 return;
Chris@326 819 }
Chris@320 820
Chris@320 821 drawVisibleText(paint, m_scaleWidth + 5,
Chris@326 822 paint.fontMetrics().ascent() + y, text, OutlinedText);
Chris@320 823
Chris@320 824 paint.restore();
Chris@320 825 }
Chris@320 826
Chris@320 827 void
Chris@320 828 Pane::modelAlignmentCompletionChanged()
Chris@320 829 {
Chris@320 830 View::modelAlignmentCompletionChanged();
Chris@320 831 update(QRect(0, 0, 300, 100));
Chris@320 832 }
Chris@320 833
Chris@320 834 void
Chris@326 835 Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model)
Chris@326 836 {
Chris@326 837 QString title = model->getTitle();
Chris@326 838 QString maker = model->getMaker();
Chris@587 839 //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl;
Chris@326 840 if (title == "") return;
Chris@326 841
Chris@326 842 QString text = title;
Chris@326 843 if (maker != "") {
Chris@326 844 text = tr("%1 - %2").arg(title).arg(maker);
Chris@326 845 }
Chris@326 846
Chris@326 847 paint.save();
Chris@326 848 QFont font(paint.font());
Chris@326 849 font.setItalic(true);
Chris@326 850 paint.setFont(font);
Chris@326 851
Chris@326 852 int y = 5;
Chris@326 853 int w = paint.fontMetrics().width(text);
Chris@326 854 int h = paint.fontMetrics().height();
Chris@326 855 if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) {
Chris@326 856 paint.restore();
Chris@326 857 return;
Chris@326 858 }
Chris@326 859
Chris@326 860 drawVisibleText(paint, m_scaleWidth + 5,
Chris@326 861 paint.fontMetrics().ascent() + y, text, OutlinedText);
Chris@326 862
Chris@326 863 paint.restore();
Chris@326 864 }
Chris@326 865
Chris@326 866 void
Chris@261 867 Pane::drawLayerNames(QRect r, QPainter &paint)
Chris@261 868 {
Chris@261 869 int fontHeight = paint.fontMetrics().height();
Chris@261 870 int fontAscent = paint.fontMetrics().ascent();
Chris@127 871
Chris@300 872 int lly = height() - 6;
Chris@300 873 if (m_manager->getZoomWheelsEnabled()) {
Chris@300 874 lly -= 20;
Chris@300 875 }
Chris@300 876
Chris@300 877 if (r.y() + r.height() < lly - int(m_layers.size()) * fontHeight) {
Chris@261 878 return;
Chris@127 879 }
Chris@127 880
Chris@294 881 QStringList texts;
Chris@299 882 std::vector<QPixmap> pixmaps;
Chris@294 883 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) {
Chris@294 884 texts.push_back((*i)->getLayerPresentationName());
Chris@299 885 // std::cerr << "Pane " << this << ": Layer presentation name for " << *i << ": "
Chris@584 886 // << texts[texts.size()-1] << std::endl;
Chris@299 887 pixmaps.push_back((*i)->getLayerPresentationPixmap
Chris@299 888 (QSize(fontAscent, fontAscent)));
Chris@294 889 }
Chris@127 890
Chris@294 891 int maxTextWidth = width() / 3;
Chris@294 892 texts = TextAbbrev::abbreviate(texts, paint.fontMetrics(), maxTextWidth);
Chris@294 893
Chris@261 894 int llx = width() - maxTextWidth - 5;
Chris@261 895 if (m_manager->getZoomWheelsEnabled()) {
Chris@261 896 llx -= 36;
Chris@261 897 }
Chris@261 898
Chris@300 899 if (r.x() + r.width() >= llx - fontAscent - 3) {
gyorgyf@645 900
Chris@261 901 for (size_t i = 0; i < texts.size(); ++i) {
Chris@299 902
Chris@584 903 // std::cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << std::endl;
Chris@261 904
Chris@261 905 if (i + 1 == texts.size()) {
Chris@287 906 paint.setPen(getForeground());
Chris@261 907 }
Chris@261 908
Chris@261 909 drawVisibleText(paint, llx,
Chris@261 910 lly - fontHeight + fontAscent,
Chris@261 911 texts[i], OutlinedText);
Chris@299 912
Chris@299 913 if (!pixmaps[i].isNull()) {
Chris@299 914 paint.drawPixmap(llx - fontAscent - 3,
Chris@299 915 lly - fontHeight + (fontHeight-fontAscent)/2,
Chris@299 916 pixmaps[i]);
Chris@299 917 }
Chris@261 918
Chris@261 919 lly -= fontHeight;
Chris@261 920 }
Chris@261 921 }
Chris@261 922 }
Chris@127 923
Chris@261 924 void
Chris@261 925 Pane::drawEditingSelection(QPainter &paint)
Chris@261 926 {
Chris@261 927 int offset = m_mousePos.x() - m_clickPos.x();
Chris@577 928
Chris@577 929 long origStart = m_editingSelection.getStartFrame();
Chris@577 930
Chris@577 931 int p0 = getXForFrame(origStart) + offset;
Chris@261 932 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
Chris@577 933
Chris@261 934 if (m_editingSelectionEdge < 0) {
Chris@261 935 p1 = getXForFrame(m_editingSelection.getEndFrame());
Chris@261 936 } else if (m_editingSelectionEdge > 0) {
Chris@261 937 p0 = getXForFrame(m_editingSelection.getStartFrame());
Chris@127 938 }
Chris@127 939
Chris@577 940 long newStart = getFrameForX(p0);
Chris@577 941 long newEnd = getFrameForX(p1);
Chris@577 942
Chris@261 943 paint.save();
Chris@287 944 paint.setPen(QPen(getForeground(), 2));
Chris@577 945
Chris@577 946 int fontHeight = paint.fontMetrics().height();
Chris@577 947 int fontAscent = paint.fontMetrics().ascent();
Chris@577 948 int sampleRate = getModelsSampleRate();
Chris@577 949 QString startText, endText, offsetText;
Chris@577 950 startText = QString("%1").arg(newStart);
Chris@577 951 endText = QString("%1").arg(newEnd);
Chris@577 952 offsetText = QString("%1").arg(newStart - origStart);
Chris@577 953 if (newStart >= origStart) {
Chris@577 954 offsetText = tr("+%1").arg(offsetText);
Chris@577 955 }
Chris@577 956 if (sampleRate) {
Chris@577 957 startText = QString("%1 / %2")
Chris@577 958 .arg(QString::fromStdString
Chris@577 959 (RealTime::frame2RealTime(newStart, sampleRate).toText()))
Chris@577 960 .arg(startText);
Chris@577 961 endText = QString("%1 / %2")
Chris@577 962 .arg(QString::fromStdString
Chris@577 963 (RealTime::frame2RealTime(newEnd, sampleRate).toText()))
Chris@577 964 .arg(endText);
Chris@577 965 offsetText = QString("%1 / %2")
Chris@577 966 .arg(QString::fromStdString
Chris@577 967 (RealTime::frame2RealTime(newStart - origStart, sampleRate).toText()))
Chris@577 968 .arg(offsetText);
Chris@577 969 if (newStart >= origStart) {
Chris@577 970 offsetText = tr("+%1").arg(offsetText);
Chris@577 971 }
Chris@577 972 }
Chris@577 973 drawVisibleText(paint, p0 + 2, fontAscent + fontHeight + 4, startText, OutlinedText);
Chris@577 974 drawVisibleText(paint, p1 + 2, fontAscent + fontHeight + 4, endText, OutlinedText);
Chris@577 975 drawVisibleText(paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText);
Chris@577 976 drawVisibleText(paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText);
Chris@261 977
Chris@261 978 //!!! duplicating display policy with View::drawSelections
Chris@261 979
Chris@261 980 if (m_editingSelectionEdge < 0) {
Chris@261 981 paint.drawLine(p0, 1, p1, 1);
Chris@261 982 paint.drawLine(p0, 0, p0, height());
Chris@261 983 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@261 984 } else if (m_editingSelectionEdge > 0) {
Chris@261 985 paint.drawLine(p0, 1, p1, 1);
Chris@261 986 paint.drawLine(p1, 0, p1, height());
Chris@261 987 paint.drawLine(p0, height() - 1, p1, height() - 1);
Chris@261 988 } else {
Chris@261 989 paint.setBrush(Qt::NoBrush);
Chris@261 990 paint.drawRect(p0, 1, p1 - p0, height() - 2);
Chris@261 991 }
Chris@261 992 paint.restore();
Chris@261 993 }
Chris@127 994
Chris@261 995 void
Chris@261 996 Pane::drawDurationAndRate(QRect r, const Model *waveformModel,
Chris@261 997 int sampleRate, QPainter &paint)
Chris@261 998 {
Chris@261 999 int fontHeight = paint.fontMetrics().height();
Chris@261 1000 int fontAscent = paint.fontMetrics().ascent();
Chris@127 1001
Chris@261 1002 if (r.y() + r.height() < height() - fontHeight - 6) return;
Chris@127 1003
Chris@261 1004 size_t modelRate = waveformModel->getSampleRate();
Chris@301 1005 size_t nativeRate = waveformModel->getNativeRate();
Chris@261 1006 size_t playbackRate = m_manager->getPlaybackSampleRate();
Chris@261 1007 size_t outputRate = m_manager->getOutputSampleRate();
Chris@261 1008
Chris@261 1009 QString srNote = "";
Chris@127 1010
Chris@301 1011 // Show (R) for waveform models that have been resampled or will
Chris@301 1012 // be resampled on playback, and (X) for waveform models that will
Chris@301 1013 // be played at the wrong rate because their rate differs from the
Chris@261 1014 // current playback rate (which is not necessarily that of the
Chris@261 1015 // main model).
Chris@127 1016
Chris@261 1017 if (playbackRate != 0) {
Chris@261 1018 if (modelRate == playbackRate) {
Chris@301 1019 if (modelRate != outputRate || modelRate != nativeRate) {
Chris@301 1020 srNote = " " + tr("(R)");
Chris@301 1021 }
Chris@261 1022 } else {
Chris@261 1023 srNote = " " + tr("(X)");
Chris@261 1024 }
Chris@127 1025 }
Chris@127 1026
Chris@261 1027 QString desc = tr("%1 / %2Hz%3")
Chris@261 1028 .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(),
Chris@261 1029 sampleRate)
Chris@261 1030 .toText(false).c_str())
Chris@301 1031 .arg(nativeRate)
Chris@261 1032 .arg(srNote);
Chris@261 1033
Chris@384 1034 int x = m_scaleWidth + 5;
Chris@384 1035 int pbw = getProgressBarWidth();
Chris@384 1036 if (x < pbw + 5) x = pbw + 5;
Chris@384 1037
Chris@384 1038 if (r.x() < x + paint.fontMetrics().width(desc)) {
Chris@384 1039 drawVisibleText(paint, x,
Chris@261 1040 height() - fontHeight + fontAscent - 6,
Chris@261 1041 desc, OutlinedText);
Chris@261 1042 }
Chris@127 1043 }
Chris@127 1044
Chris@227 1045 bool
Chris@229 1046 Pane::render(QPainter &paint, int xorigin, size_t f0, size_t f1)
Chris@227 1047 {
Chris@229 1048 if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) {
Chris@227 1049 return false;
Chris@227 1050 }
Chris@227 1051
Chris@227 1052 if (m_scaleWidth > 0) {
Chris@227 1053
Chris@227 1054 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@227 1055 --vi;
Chris@227 1056
Chris@227 1057 paint.save();
Chris@227 1058
Chris@287 1059 paint.setPen(getForeground());
Chris@287 1060 paint.setBrush(getBackground());
Chris@229 1061 paint.drawRect(xorigin, -1, m_scaleWidth, height()+1);
Chris@227 1062
Chris@227 1063 paint.setBrush(Qt::NoBrush);
Chris@227 1064 (*vi)->paintVerticalScale
Chris@607 1065 (this, m_manager->shouldShowVerticalColourScale(),
Chris@607 1066 paint, QRect(xorigin, 0, m_scaleWidth, height()));
Chris@227 1067
Chris@227 1068 paint.restore();
Chris@227 1069 break;
Chris@227 1070 }
Chris@227 1071 }
Chris@227 1072
Chris@227 1073 return true;
Chris@227 1074 }
Chris@227 1075
Chris@227 1076 QImage *
Chris@229 1077 Pane::toNewImage(size_t f0, size_t f1)
Chris@227 1078 {
Chris@227 1079 size_t x0 = f0 / getZoomLevel();
Chris@227 1080 size_t x1 = f1 / getZoomLevel();
Chris@227 1081
Chris@227 1082 QImage *image = new QImage(x1 - x0 + m_scaleWidth,
Chris@227 1083 height(), QImage::Format_RGB32);
Chris@227 1084
Chris@227 1085 int formerScaleWidth = m_scaleWidth;
Chris@227 1086
Chris@227 1087 if (m_manager && m_manager->shouldShowVerticalScale()) {
Chris@227 1088 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@227 1089 --vi;
Chris@227 1090 QPainter paint(image);
Chris@607 1091 m_scaleWidth = (*vi)->getVerticalScaleWidth
Chris@607 1092 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@227 1093 break;
Chris@227 1094 }
Chris@227 1095 } else {
Chris@227 1096 m_scaleWidth = 0;
Chris@227 1097 }
Chris@227 1098
Chris@227 1099 if (m_scaleWidth != formerScaleWidth) {
Chris@227 1100 delete image;
Chris@227 1101 image = new QImage(x1 - x0 + m_scaleWidth,
Chris@227 1102 height(), QImage::Format_RGB32);
Chris@227 1103 }
Chris@227 1104
Chris@227 1105 QPainter *paint = new QPainter(image);
Chris@229 1106 if (!render(*paint, 0, f0, f1)) {
Chris@227 1107 delete paint;
Chris@227 1108 delete image;
Chris@227 1109 return 0;
Chris@227 1110 } else {
Chris@227 1111 delete paint;
Chris@227 1112 return image;
Chris@227 1113 }
Chris@227 1114 }
Chris@227 1115
Chris@229 1116 QSize
Chris@229 1117 Pane::getImageSize(size_t f0, size_t f1)
Chris@229 1118 {
Chris@229 1119 QSize s = View::getImageSize(f0, f1);
Chris@229 1120 QImage *image = new QImage(100, 100, QImage::Format_RGB32);
Chris@229 1121 QPainter paint(image);
Chris@229 1122
Chris@229 1123 int sw = 0;
Chris@229 1124 if (m_manager && m_manager->shouldShowVerticalScale()) {
Chris@229 1125 for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@229 1126 --vi;
Chris@229 1127 QPainter paint(image);
Chris@607 1128 sw = (*vi)->getVerticalScaleWidth
Chris@607 1129 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@229 1130 break;
Chris@229 1131 }
Chris@229 1132 }
Chris@229 1133
Chris@229 1134 return QSize(sw + s.width(), s.height());
Chris@229 1135 }
Chris@229 1136
Chris@222 1137 size_t
Chris@222 1138 Pane::getFirstVisibleFrame() const
Chris@222 1139 {
Chris@222 1140 long f0 = getFrameForX(m_scaleWidth);
Chris@222 1141 size_t f = View::getFirstVisibleFrame();
Chris@222 1142 if (f0 < 0 || f0 < long(f)) return f;
Chris@222 1143 return f0;
Chris@222 1144 }
Chris@222 1145
Chris@127 1146 Selection
Chris@127 1147 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const
Chris@127 1148 {
Chris@127 1149 closeToLeftEdge = closeToRightEdge = false;
Chris@127 1150
Chris@127 1151 if (!m_manager) return Selection();
Chris@127 1152
Chris@127 1153 long testFrame = getFrameForX(x - 5);
Chris@127 1154 if (testFrame < 0) {
gyorgyf@645 1155 testFrame = getFrameForX(x);
gyorgyf@645 1156 if (testFrame < 0) return Selection();
Chris@127 1157 }
Chris@127 1158
Chris@127 1159 Selection selection = m_manager->getContainingSelection(testFrame, true);
Chris@127 1160 if (selection.isEmpty()) return selection;
Chris@127 1161
Chris@127 1162 int lx = getXForFrame(selection.getStartFrame());
Chris@127 1163 int rx = getXForFrame(selection.getEndFrame());
Chris@127 1164
Chris@127 1165 int fuzz = 2;
Chris@127 1166 if (x < lx - fuzz || x > rx + fuzz) return Selection();
Chris@127 1167
Chris@127 1168 int width = rx - lx;
Chris@127 1169 fuzz = 3;
Chris@127 1170 if (width < 12) fuzz = width / 4;
Chris@127 1171 if (fuzz < 1) fuzz = 1;
Chris@127 1172
Chris@127 1173 if (x < lx + fuzz) closeToLeftEdge = true;
Chris@127 1174 if (x > rx - fuzz) closeToRightEdge = true;
Chris@127 1175
Chris@127 1176 return selection;
Chris@127 1177 }
Chris@127 1178
Chris@174 1179 bool
Chris@174 1180 Pane::canTopLayerMoveVertical()
Chris@174 1181 {
Chris@174 1182 float vmin, vmax, dmin, dmax;
Chris@174 1183 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false;
Chris@174 1184 if (dmin <= vmin && dmax >= vmax) return false;
Chris@174 1185 return true;
Chris@174 1186 }
Chris@174 1187
Chris@174 1188 bool
Chris@174 1189 Pane::getTopLayerDisplayExtents(float &vmin, float &vmax,
Chris@188 1190 float &dmin, float &dmax,
Chris@188 1191 QString *unit)
Chris@174 1192 {
Chris@268 1193 Layer *layer = getTopLayer();
Chris@174 1194 if (!layer) return false;
Chris@174 1195 bool vlog;
Chris@174 1196 QString vunit;
Chris@188 1197 bool rv = (layer->getValueExtents(vmin, vmax, vlog, vunit) &&
Chris@188 1198 layer->getDisplayExtents(dmin, dmax));
Chris@188 1199 if (unit) *unit = vunit;
Chris@188 1200 return rv;
Chris@174 1201 }
Chris@174 1202
Chris@174 1203 bool
Chris@174 1204 Pane::setTopLayerDisplayExtents(float dmin, float dmax)
Chris@174 1205 {
Chris@268 1206 Layer *layer = getTopLayer();
Chris@174 1207 if (!layer) return false;
Chris@174 1208 return layer->setDisplayExtents(dmin, dmax);
Chris@174 1209 }
Chris@174 1210
Chris@127 1211 void
Chris@282 1212 Pane::registerShortcuts(KeyReference &kr)
Chris@282 1213 {
Chris@282 1214 kr.setCategory(tr("Zoom"));
Chris@282 1215 kr.registerAlternativeShortcut(tr("Zoom In"), tr("Wheel Up"));
Chris@282 1216 kr.registerAlternativeShortcut(tr("Zoom Out"), tr("Wheel Down"));
Chris@282 1217
Chris@282 1218 kr.setCategory(tr("General Pane Mouse Actions"));
Chris@282 1219
Chris@282 1220 kr.registerShortcut(tr("Zoom"), tr("Wheel"),
Chris@282 1221 tr("Zoom in or out in time axis"));
Chris@408 1222 kr.registerShortcut(tr("Scroll"), tr("Ctrl+Wheel"),
Chris@282 1223 tr("Scroll rapidly left or right in time axis"));
Chris@282 1224 kr.registerShortcut(tr("Zoom Vertically"), tr("Shift+Wheel"),
Chris@282 1225 tr("Zoom in or out in the vertical axis"));
Chris@282 1226 kr.registerShortcut(tr("Scroll Vertically"), tr("Alt+Wheel"),
Chris@282 1227 tr("Scroll up or down in the vertical axis"));
Chris@282 1228 kr.registerShortcut(tr("Navigate"), tr("Middle"),
Chris@282 1229 tr("Click middle button and drag to navigate with any tool"));
Chris@282 1230 kr.registerShortcut(tr("Relocate"), tr("Double-Click Middle"),
Chris@282 1231 tr("Double-click middle button to relocate with any tool"));
Chris@282 1232 kr.registerShortcut(tr("Menu"), tr("Right"),
Chris@282 1233 tr("Show pane context menu"));
Chris@282 1234
Chris@282 1235 kr.setCategory(tr("Navigate Tool Mouse Actions"));
Chris@282 1236
Chris@282 1237 kr.registerShortcut(tr("Navigate"), tr("Left"),
Chris@282 1238 tr("Click left button and drag to move around"));
Chris@282 1239 kr.registerShortcut(tr("Zoom to Area"), tr("Shift+Left"),
Chris@282 1240 tr("Shift-click left button and drag to zoom to a rectangular area"));
Chris@282 1241 kr.registerShortcut(tr("Relocate"), tr("Double-Click Left"),
Chris@282 1242 tr("Double-click left button to jump to clicked location"));
Chris@282 1243 kr.registerShortcut(tr("Edit"), tr("Double-Click Left"),
Chris@282 1244 tr("Double-click left button on an item to edit it"));
Chris@282 1245
Chris@282 1246 kr.setCategory(tr("Select Tool Mouse Actions"));
Chris@282 1247 kr.registerShortcut(tr("Select"), tr("Left"),
Chris@282 1248 tr("Click left button and drag to select region; drag region edge to resize"));
Chris@282 1249 kr.registerShortcut(tr("Multi Select"), tr("Ctrl+Left"),
Chris@597 1250 #ifdef Q_OS_MAC
Chris@597 1251 tr("Cmd-click left button and drag to select an additional region"));
Chris@597 1252 #else
Chris@282 1253 tr("Ctrl-click left button and drag to select an additional region"));
Chris@597 1254 #endif
Chris@283 1255 kr.registerShortcut(tr("Fine Select"), tr("Shift+Left"),
Chris@283 1256 tr("Shift-click left button and drag to select without snapping to items or grid"));
Chris@282 1257
Chris@282 1258 kr.setCategory(tr("Edit Tool Mouse Actions"));
Chris@282 1259 kr.registerShortcut(tr("Move"), tr("Left"),
Chris@282 1260 tr("Click left button on an item or selected region and drag to move"));
Chris@282 1261 kr.registerShortcut(tr("Edit"), tr("Double-Click Left"),
Chris@282 1262 tr("Double-click left button on an item to edit it"));
Chris@282 1263
Chris@282 1264 kr.setCategory(tr("Draw Tool Mouse Actions"));
Chris@282 1265 kr.registerShortcut(tr("Draw"), tr("Left"),
Chris@282 1266 tr("Click left button and drag to create new item"));
Chris@282 1267
Chris@282 1268 kr.setCategory(tr("Measure Tool Mouse Actions"));
Chris@282 1269 kr.registerShortcut(tr("Measure Area"), tr("Left"),
Chris@282 1270 tr("Click left button and drag to measure a rectangular area"));
Chris@282 1271 kr.registerShortcut(tr("Measure Item"), tr("Double-Click Left"),
Chris@282 1272 tr("Click left button and drag to measure extents of an item or shape"));
Chris@283 1273 kr.registerShortcut(tr("Zoom to Area"), tr("Shift+Left"),
Chris@283 1274 tr("Shift-click left button and drag to zoom to a rectangular area"));
Chris@282 1275 }
Chris@282 1276
Chris@282 1277 void
Chris@127 1278 Pane::mousePressEvent(QMouseEvent *e)
Chris@127 1279 {
Chris@127 1280 if (e->buttons() & Qt::RightButton) {
Chris@189 1281 emit contextHelpChanged("");
Chris@127 1282 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
Chris@127 1283 return;
Chris@127 1284 }
Chris@127 1285
gyorgyf@635 1286 // std::cerr << "mousePressEvent" << std::endl;
Chris@341 1287
Chris@127 1288 m_clickPos = e->pos();
Chris@262 1289 m_mousePos = m_clickPos;
Chris@127 1290 m_clickedInRange = true;
Chris@127 1291 m_editingSelection = Selection();
Chris@127 1292 m_editingSelectionEdge = 0;
Chris@127 1293 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
Chris@127 1294 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
Chris@510 1295 m_altPressed = (e->modifiers() & Qt::AltModifier);
Chris@150 1296 m_dragMode = UnresolvedDrag;
Chris@127 1297
Chris@127 1298 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 1299 if (m_manager) mode = m_manager->getToolMode();
Chris@127 1300
Chris@127 1301 m_navigating = false;
Chris@343 1302 m_resizing = false;
Chris@343 1303 m_editing = false;
Chris@343 1304 m_releasing = false;
Chris@127 1305
Chris@283 1306 if (mode == ViewManager::NavigateMode ||
Chris@283 1307 (e->buttons() & Qt::MidButton) ||
Chris@283 1308 (mode == ViewManager::MeasureMode &&
Chris@283 1309 (e->buttons() & Qt::LeftButton) && m_shiftPressed)) {
Chris@127 1310
gyorgyf@645 1311 if (mode != ViewManager::NavigateMode) {
gyorgyf@645 1312 setCursor(Qt::PointingHandCursor);
gyorgyf@645 1313 }
gyorgyf@645 1314
gyorgyf@645 1315 m_navigating = true;
gyorgyf@645 1316 m_dragCentreFrame = m_centreFrame;
Chris@136 1317 m_dragStartMinValue = 0;
Chris@174 1318
Chris@174 1319 float vmin, vmax, dmin, dmax;
Chris@174 1320 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
Chris@174 1321 m_dragStartMinValue = dmin;
Chris@136 1322 }
Chris@136 1323
Chris@127 1324 } else if (mode == ViewManager::SelectMode) {
Chris@127 1325
Chris@217 1326 if (!hasTopLayerTimeXAxis()) return;
Chris@217 1327
gyorgyf@645 1328 bool closeToLeft = false, closeToRight = false;
gyorgyf@645 1329 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight);
gyorgyf@645 1330
gyorgyf@645 1331 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
gyorgyf@645 1332
gyorgyf@645 1333 m_manager->removeSelection(selection);
gyorgyf@645 1334
gyorgyf@645 1335 if (closeToLeft) {
gyorgyf@645 1336 m_selectionStartFrame = selection.getEndFrame();
gyorgyf@645 1337 } else {
gyorgyf@645 1338 m_selectionStartFrame = selection.getStartFrame();
gyorgyf@645 1339 }
gyorgyf@645 1340
gyorgyf@645 1341 m_manager->setInProgressSelection(selection, false);
gyorgyf@645 1342 m_resizing = true;
gyorgyf@645 1343
gyorgyf@645 1344 } else {
gyorgyf@645 1345
gyorgyf@645 1346 int mouseFrame = getFrameForX(e->x());
gyorgyf@645 1347 size_t resolution = 1;
gyorgyf@645 1348 int snapFrame = mouseFrame;
gyorgyf@645 1349
gyorgyf@645 1350 Layer *layer = getSelectedLayer();
gyorgyf@645 1351 if (layer && !m_shiftPressed) {
gyorgyf@645 1352 layer->snapToFeatureFrame(this, snapFrame,
gyorgyf@645 1353 resolution, Layer::SnapLeft);
gyorgyf@645 1354 }
gyorgyf@645 1355
gyorgyf@645 1356 if (snapFrame < 0) snapFrame = 0;
gyorgyf@645 1357 m_selectionStartFrame = snapFrame;
gyorgyf@645 1358 if (m_manager) {
gyorgyf@645 1359 m_manager->setInProgressSelection
Chris@333 1360 (Selection(alignToReference(snapFrame),
Chris@333 1361 alignToReference(snapFrame + resolution)),
Chris@333 1362 !m_ctrlPressed);
gyorgyf@645 1363 }
gyorgyf@645 1364
gyorgyf@645 1365 m_resizing = false;
gyorgyf@645 1366 }
gyorgyf@645 1367
gyorgyf@645 1368 update();
Chris@127 1369
Chris@127 1370 } else if (mode == ViewManager::DrawMode) {
Chris@127 1371
gyorgyf@645 1372 Layer *layer = getSelectedLayer();
gyorgyf@645 1373 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1374 layer->drawStart(this, e);
gyorgyf@645 1375 }
Chris@127 1376
Chris@335 1377 } else if (mode == ViewManager::EraseMode) {
Chris@335 1378
gyorgyf@645 1379 Layer *layer = getSelectedLayer();
gyorgyf@645 1380 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1381 layer->eraseStart(this, e);
gyorgyf@645 1382 }
gyorgyf@645 1383
gyorgyf@645 1384 // GF: handle mouse press for NoteEditMode
gyorgyf@645 1385 } else if (mode == ViewManager::NoteEditMode) {
gyorgyf@645 1386
gyorgyf@645 1387 std::cerr << "mouse pressed in note edit mode" << std::endl;
gyorgyf@635 1388 Layer *layer = getSelectedLayer();
gyorgyf@635 1389 if (layer && layer->isLayerEditable()) {
gyorgyf@635 1390 layer->splitStart(this, e);
gyorgyf@635 1391 }
gyorgyf@635 1392
gyorgyf@645 1393 } else if (mode == ViewManager::EditMode) {
gyorgyf@645 1394
Chris@343 1395 // Do nothing here -- we'll do it in mouseMoveEvent when the
Chris@343 1396 // drag threshold has been passed
Chris@262 1397
Chris@262 1398 } else if (mode == ViewManager::MeasureMode) {
Chris@262 1399
Chris@268 1400 Layer *layer = getTopLayer();
Chris@267 1401 if (layer) layer->measureStart(this, e);
Chris@262 1402 update();
Chris@127 1403 }
Chris@127 1404
Chris@127 1405 emit paneInteractedWith();
Chris@127 1406 }
Chris@127 1407
Chris@127 1408 void
Chris@127 1409 Pane::mouseReleaseEvent(QMouseEvent *e)
Chris@127 1410 {
Chris@127 1411 if (e->buttons() & Qt::RightButton) {
Chris@127 1412 return;
Chris@127 1413 }
Chris@127 1414
Chris@343 1415 // std::cerr << "mouseReleaseEvent" << std::endl;
Chris@341 1416
Chris@127 1417 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 1418 if (m_manager) mode = m_manager->getToolMode();
Chris@127 1419
Chris@343 1420 m_releasing = true;
Chris@343 1421
Chris@127 1422 if (m_clickedInRange) {
gyorgyf@645 1423 mouseMoveEvent(e);
Chris@127 1424 }
Chris@127 1425
Chris@127 1426 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@127 1427
gyorgyf@645 1428 m_navigating = false;
gyorgyf@645 1429
gyorgyf@645 1430 if (mode != ViewManager::NavigateMode) {
gyorgyf@645 1431 // restore cursor
gyorgyf@645 1432 toolModeChanged();
gyorgyf@645 1433 }
gyorgyf@645 1434
gyorgyf@645 1435 if (m_shiftPressed) {
gyorgyf@645 1436
gyorgyf@645 1437 int x0 = std::min(m_clickPos.x(), m_mousePos.x());
gyorgyf@645 1438 int x1 = std::max(m_clickPos.x(), m_mousePos.x());
gyorgyf@645 1439
gyorgyf@645 1440 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
gyorgyf@645 1441 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
Chris@127 1442
Chris@174 1443 zoomToRegion(x0, y0, x1, y1);
gyorgyf@645 1444 }
Chris@127 1445
Chris@127 1446 } else if (mode == ViewManager::SelectMode) {
Chris@127 1447
Chris@343 1448 if (!hasTopLayerTimeXAxis()) {
Chris@343 1449 m_releasing = false;
Chris@343 1450 return;
Chris@343 1451 }
Chris@217 1452
gyorgyf@645 1453 if (m_manager && m_manager->haveInProgressSelection()) {
gyorgyf@645 1454
gyorgyf@645 1455 bool exclusive;
gyorgyf@645 1456 Selection selection = m_manager->getInProgressSelection(exclusive);
gyorgyf@645 1457
gyorgyf@645 1458 if (selection.getEndFrame() < selection.getStartFrame() + 2) {
gyorgyf@645 1459 selection = Selection();
gyorgyf@645 1460 }
gyorgyf@645 1461
gyorgyf@645 1462 m_manager->clearInProgressSelection();
gyorgyf@645 1463
gyorgyf@645 1464 if (exclusive) {
gyorgyf@645 1465 m_manager->setSelection(selection);
gyorgyf@645 1466 } else {
gyorgyf@645 1467 m_manager->addSelection(selection);
gyorgyf@645 1468 }
gyorgyf@645 1469 }
gyorgyf@645 1470
gyorgyf@645 1471 update();
Chris@127 1472
Chris@127 1473 } else if (mode == ViewManager::DrawMode) {
Chris@127 1474
gyorgyf@645 1475 Layer *layer = getSelectedLayer();
gyorgyf@645 1476 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1477 layer->drawEnd(this, e);
gyorgyf@645 1478 update();
gyorgyf@645 1479 }
Chris@127 1480
Chris@335 1481 } else if (mode == ViewManager::EraseMode) {
Chris@335 1482
gyorgyf@645 1483 Layer *layer = getSelectedLayer();
gyorgyf@645 1484 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1485 layer->eraseEnd(this, e);
gyorgyf@645 1486 update();
gyorgyf@645 1487 }
gyorgyf@645 1488
gyorgyf@645 1489 } else if (mode == ViewManager::NoteEditMode) {
gyorgyf@645 1490
gyorgyf@645 1491 //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later)
gyorgyf@635 1492 Layer *layer = getSelectedLayer();
gyorgyf@635 1493 if (layer && layer->isLayerEditable()) {
gyorgyf@635 1494 layer->splitEnd(this, e);
gyorgyf@635 1495 update(); }
Chris@127 1496
Chris@343 1497 if (m_editing) {
Chris@343 1498 if (!editSelectionEnd(e)) {
Chris@343 1499 Layer *layer = getSelectedLayer();
Chris@343 1500 if (layer && layer->isLayerEditable()) {
Chris@343 1501 layer->editEnd(this, e);
Chris@343 1502 update();
Chris@343 1503 }
Chris@343 1504 }
gyorgyf@635 1505 }
Chris@262 1506
gyorgyf@645 1507 } else if (mode == ViewManager::EditMode) {
gyorgyf@645 1508
gyorgyf@645 1509 // GF: edited this previously, but restored to original state
gyorgyf@645 1510 if (m_editing) {
gyorgyf@645 1511 if (!editSelectionEnd(e)) {
gyorgyf@645 1512 Layer *layer = getSelectedLayer();
gyorgyf@645 1513 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1514 layer->editEnd(this, e);
gyorgyf@645 1515 update();
gyorgyf@645 1516 }
gyorgyf@645 1517 }
gyorgyf@645 1518 }
gyorgyf@645 1519
Chris@262 1520 } else if (mode == ViewManager::MeasureMode) {
Chris@262 1521
Chris@268 1522 Layer *layer = getTopLayer();
Chris@267 1523 if (layer) layer->measureEnd(this, e);
Chris@267 1524 if (m_measureCursor1) setCursor(*m_measureCursor1);
Chris@267 1525 update();
Chris@127 1526 }
Chris@127 1527
Chris@127 1528 m_clickedInRange = false;
Chris@343 1529 m_releasing = false;
Chris@127 1530
Chris@127 1531 emit paneInteractedWith();
Chris@127 1532 }
Chris@127 1533
Chris@127 1534 void
Chris@127 1535 Pane::mouseMoveEvent(QMouseEvent *e)
Chris@127 1536 {
Chris@127 1537 if (e->buttons() & Qt::RightButton) {
Chris@127 1538 return;
Chris@127 1539 }
Chris@127 1540
Chris@343 1541 // std::cerr << "mouseMoveEvent" << std::endl;
Chris@341 1542
Chris@189 1543 updateContextHelp(&e->pos());
Chris@189 1544
Chris@343 1545 if (m_navigating && m_clickedInRange && !m_releasing) {
Chris@343 1546
Chris@343 1547 // if no buttons pressed, and not called from
Chris@343 1548 // mouseReleaseEvent, we want to reset clicked-ness (to avoid
Chris@343 1549 // annoying continual drags when we moved the mouse outside
Chris@343 1550 // the window after pressing button first time).
Chris@343 1551
Chris@343 1552 if (!(e->buttons() & Qt::LeftButton) &&
Chris@343 1553 !(e->buttons() & Qt::MidButton)) {
Chris@343 1554 m_clickedInRange = false;
Chris@343 1555 return;
Chris@343 1556 }
Chris@343 1557 }
Chris@343 1558
Chris@127 1559 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 1560 if (m_manager) mode = m_manager->getToolMode();
Chris@127 1561
Chris@127 1562 QPoint prevPoint = m_identifyPoint;
Chris@127 1563 m_identifyPoint = e->pos();
Chris@127 1564
Chris@127 1565 if (!m_clickedInRange) {
gyorgyf@645 1566
gyorgyf@646 1567 // GF: handle mouse move for context sensitive cursor switching in NoteEditMode.
gyorgyf@646 1568 // GF: Propagate the event to FlexiNoteLayer. I somehow feel it's best handeled there rather than here, but perhaps not if this will be needed elsewhere too.
gyorgyf@646 1569 if (mode == ViewManager::NoteEditMode && LayerFactory::getInstance()->getLayerType(getTopLayer()) == LayerFactory::FlexiNotes) {
gyorgyf@646 1570
gyorgyf@646 1571 dynamic_cast<FlexiNoteLayer *>(getTopLayer())->mouseMoveEvent(this, e);
gyorgyf@646 1572
gyorgyf@646 1573 }
gyorgyf@646 1574
gyorgyf@646 1575 if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) {
gyorgyf@646 1576 bool closeToLeft = false, closeToRight = false;
gyorgyf@646 1577 getSelectionAt(e->x(), closeToLeft, closeToRight);
gyorgyf@646 1578 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
gyorgyf@646 1579 setCursor(Qt::SizeHorCursor);
gyorgyf@646 1580 } else {
gyorgyf@646 1581 setCursor(Qt::ArrowCursor);
gyorgyf@646 1582 }
gyorgyf@645 1583 }
Chris@127 1584
Chris@127 1585 if (!m_manager->isPlaying()) {
Chris@127 1586
Chris@272 1587 bool updating = false;
Chris@272 1588
Chris@326 1589 if (getSelectedLayer() &&
Chris@326 1590 m_manager->shouldIlluminateLocalFeatures()) {
Chris@127 1591
Chris@174 1592 bool previouslyIdentifying = m_identifyFeatures;
Chris@174 1593 m_identifyFeatures = true;
Chris@174 1594
Chris@174 1595 if (m_identifyFeatures != previouslyIdentifying ||
Chris@174 1596 m_identifyPoint != prevPoint) {
Chris@174 1597 update();
Chris@272 1598 updating = true;
Chris@272 1599 }
Chris@272 1600 }
Chris@272 1601
Chris@272 1602 if (!updating && mode == ViewManager::MeasureMode &&
Chris@272 1603 m_manager && !m_manager->isPlaying()) {
Chris@272 1604
Chris@272 1605 Layer *layer = getTopLayer();
Chris@272 1606 if (layer && layer->nearestMeasurementRectChanged
Chris@272 1607 (this, prevPoint, m_identifyPoint)) {
Chris@272 1608 update();
Chris@174 1609 }
Chris@174 1610 }
Chris@127 1611 }
Chris@127 1612
gyorgyf@645 1613 return;
Chris@127 1614 }
Chris@127 1615
Chris@127 1616 if (m_navigating || mode == ViewManager::NavigateMode) {
Chris@127 1617
gyorgyf@645 1618 if (m_shiftPressed) {
gyorgyf@645 1619
gyorgyf@645 1620 m_mousePos = e->pos();
gyorgyf@645 1621 update();
gyorgyf@645 1622
gyorgyf@645 1623 } else {
Chris@127 1624
Chris@174 1625 dragTopLayer(e);
Chris@150 1626 }
Chris@127 1627
Chris@127 1628 } else if (mode == ViewManager::SelectMode) {
Chris@127 1629
Chris@217 1630 if (!hasTopLayerTimeXAxis()) return;
Chris@217 1631
Chris@174 1632 dragExtendSelection(e);
Chris@127 1633
Chris@127 1634 } else if (mode == ViewManager::DrawMode) {
Chris@127 1635
gyorgyf@645 1636 Layer *layer = getSelectedLayer();
gyorgyf@645 1637 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1638 layer->drawDrag(this, e);
gyorgyf@645 1639 }
Chris@127 1640
Chris@335 1641 } else if (mode == ViewManager::EraseMode) {
Chris@335 1642
gyorgyf@645 1643 Layer *layer = getSelectedLayer();
gyorgyf@645 1644 if (layer && layer->isLayerEditable()) {
gyorgyf@645 1645 layer->eraseDrag(this, e);
gyorgyf@645 1646 }
Chris@335 1647
Chris@127 1648 } else if (mode == ViewManager::EditMode) {
Chris@127 1649
Chris@551 1650 bool resist = true;
Chris@551 1651
Chris@551 1652 if ((e->modifiers() & Qt::ShiftModifier)) {
Chris@551 1653 m_shiftPressed = true;
Chris@551 1654 // ... but don't set it false if shift has been
Chris@551 1655 // released -- we want the state when we started
Chris@551 1656 // dragging to be used most of the time
Chris@343 1657 }
Chris@343 1658
gyorgyf@645 1659 if (m_shiftPressed) resist = false;
Chris@551 1660
Chris@551 1661 m_dragMode = updateDragMode
Chris@551 1662 (m_dragMode,
Chris@551 1663 m_clickPos,
Chris@551 1664 e->pos(),
Chris@551 1665 true, // can move horiz
Chris@551 1666 true, // can move vert
Chris@551 1667 resist, // resist horiz
Chris@551 1668 resist); // resist vert
Chris@551 1669
Chris@343 1670 if (!m_editing) {
Chris@343 1671
Chris@551 1672 if (m_dragMode != UnresolvedDrag) {
Chris@343 1673
Chris@343 1674 m_editing = true;
Chris@343 1675
Chris@343 1676 QMouseEvent clickEvent(QEvent::MouseButtonPress,
Chris@343 1677 m_clickPos,
Chris@343 1678 Qt::NoButton,
Chris@343 1679 e->buttons(),
Chris@343 1680 e->modifiers());
Chris@343 1681
Chris@343 1682 if (!editSelectionStart(&clickEvent)) {
Chris@343 1683 Layer *layer = getSelectedLayer();
Chris@343 1684 if (layer && layer->isLayerEditable()) {
Chris@343 1685 layer->editStart(this, &clickEvent);
Chris@343 1686 }
Chris@343 1687 }
Chris@343 1688 }
Chris@551 1689
Chris@551 1690 } else {
Chris@551 1691
Chris@551 1692 if (!editSelectionDrag(e)) {
Chris@551 1693
Chris@551 1694 Layer *layer = getSelectedLayer();
Chris@551 1695
Chris@551 1696 if (layer && layer->isLayerEditable()) {
Chris@551 1697
Chris@551 1698 int x = e->x();
Chris@551 1699 int y = e->y();
Chris@551 1700 if (m_dragMode == VerticalDrag) x = m_clickPos.x();
Chris@551 1701 else if (m_dragMode == HorizontalDrag) y = m_clickPos.y();
Chris@551 1702
Chris@551 1703 QMouseEvent moveEvent(QEvent::MouseMove,
Chris@551 1704 QPoint(x, y),
Chris@551 1705 Qt::NoButton,
Chris@551 1706 e->buttons(),
Chris@551 1707 e->modifiers());
Chris@551 1708
Chris@551 1709 layer->editDrag(this, &moveEvent);
Chris@551 1710 }
Chris@551 1711 }
Chris@343 1712 }
Chris@259 1713
Chris@259 1714 } else if (mode == ViewManager::MeasureMode) {
Chris@259 1715
Chris@267 1716 if (m_measureCursor2) setCursor(*m_measureCursor2);
Chris@266 1717
Chris@268 1718 Layer *layer = getTopLayer();
Chris@290 1719 if (layer) {
Chris@290 1720 layer->measureDrag(this, e);
Chris@290 1721 if (layer->hasTimeXAxis()) edgeScrollMaybe(e->x());
Chris@290 1722 }
Chris@267 1723
Chris@267 1724 update();
Chris@127 1725 }
Chris@127 1726 }
Chris@127 1727
Chris@127 1728 void
Chris@174 1729 Pane::zoomToRegion(int x0, int y0, int x1, int y1)
Chris@174 1730 {
Chris@174 1731 int w = x1 - x0;
gyorgyf@645 1732
Chris@174 1733 long newStartFrame = getFrameForX(x0);
gyorgyf@645 1734
Chris@174 1735 long visibleFrames = getEndFrame() - getStartFrame();
Chris@174 1736 if (newStartFrame <= -visibleFrames) {
Chris@174 1737 newStartFrame = -visibleFrames + 1;
Chris@174 1738 }
gyorgyf@645 1739
Chris@174 1740 if (newStartFrame >= long(getModelsEndFrame())) {
Chris@174 1741 newStartFrame = getModelsEndFrame() - 1;
Chris@174 1742 }
gyorgyf@645 1743
Chris@174 1744 float ratio = float(w) / float(width());
gyorgyf@645 1745 // std::cerr << "ratio: " << ratio << std::endl;
Chris@174 1746 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
Chris@174 1747 if (newZoomLevel < 1) newZoomLevel = 1;
Chris@174 1748
gyorgyf@645 1749 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl;
Chris@174 1750 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
Chris@174 1751 setStartFrame(newStartFrame);
Chris@174 1752
Chris@174 1753 QString unit;
Chris@174 1754 float min, max;
Chris@174 1755 bool log;
Chris@174 1756 Layer *layer = 0;
Chris@174 1757 for (LayerList::const_iterator i = m_layers.begin();
Chris@174 1758 i != m_layers.end(); ++i) {
Chris@174 1759 if ((*i)->getValueExtents(min, max, log, unit) &&
Chris@174 1760 (*i)->getDisplayExtents(min, max)) {
Chris@174 1761 layer = *i;
Chris@174 1762 break;
Chris@174 1763 }
Chris@174 1764 }
Chris@174 1765
Chris@174 1766 if (layer) {
Chris@174 1767 if (log) {
Chris@174 1768 min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
Chris@174 1769 max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
Chris@174 1770 }
Chris@174 1771 float rmin = min + ((max - min) * (height() - y1)) / height();
Chris@174 1772 float rmax = min + ((max - min) * (height() - y0)) / height();
Chris@174 1773 std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl;
Chris@174 1774 if (log) {
Chris@522 1775 rmin = powf(10, rmin);
Chris@522 1776 rmax = powf(10, rmax);
Chris@174 1777 }
Chris@584 1778 std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << std::endl;
Chris@174 1779
Chris@174 1780 layer->setDisplayExtents(rmin, rmax);
Chris@174 1781 updateVerticalPanner();
Chris@174 1782 }
Chris@174 1783 }
Chris@174 1784
Chris@174 1785 void
Chris@174 1786 Pane::dragTopLayer(QMouseEvent *e)
Chris@174 1787 {
Chris@174 1788 // We need to avoid making it too easy to drag both
Chris@174 1789 // horizontally and vertically, in the case where the
Chris@174 1790 // mouse is moved "mostly" in horizontal or vertical axis
Chris@174 1791 // with only a small variation in the other axis. This is
Chris@174 1792 // particularly important during playback (when we want to
Chris@174 1793 // avoid small horizontal motions) or in slow refresh
Chris@174 1794 // layers like spectrogram (when we want to avoid small
Chris@174 1795 // vertical motions).
Chris@174 1796 //
Chris@174 1797 // To this end we have horizontal and vertical thresholds
Chris@174 1798 // and a series of states: unresolved, horizontally or
Chris@174 1799 // vertically constrained, free.
Chris@174 1800 //
Chris@174 1801 // When the mouse first moves, we're unresolved: we
Chris@174 1802 // restrict ourselves to whichever direction seems safest,
Chris@174 1803 // until the mouse has passed a small threshold distance
Chris@174 1804 // from the click point. Then we lock in to one of the
Chris@174 1805 // constrained modes, based on which axis that distance
Chris@174 1806 // was measured in first. Finally, if it turns out we've
Chris@174 1807 // also moved more than a certain larger distance in the
Chris@174 1808 // other direction as well, we may switch into free mode.
Chris@174 1809 //
Chris@174 1810 // If the top layer is incapable of being dragged
Chris@174 1811 // vertically, the logic is short circuited.
Chris@174 1812
Chris@343 1813 m_dragMode = updateDragMode
Chris@343 1814 (m_dragMode,
Chris@343 1815 m_clickPos,
Chris@343 1816 e->pos(),
Chris@343 1817 true, // can move horiz
Chris@343 1818 canTopLayerMoveVertical(), // can move vert
Chris@343 1819 canTopLayerMoveVertical() || (m_manager && m_manager->isPlaying()), // resist horiz
Chris@343 1820 !(m_manager && m_manager->isPlaying())); // resist vert
Chris@174 1821
Chris@343 1822 if (m_dragMode == HorizontalDrag ||
Chris@343 1823 m_dragMode == FreeDrag) {
Chris@174 1824
Chris@174 1825 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
Chris@174 1826
Chris@174 1827 size_t newCentreFrame = m_dragCentreFrame;
gyorgyf@645 1828
Chris@174 1829 if (frameOff < 0) {
Chris@174 1830 newCentreFrame -= frameOff;
Chris@174 1831 } else if (newCentreFrame >= size_t(frameOff)) {
Chris@174 1832 newCentreFrame -= frameOff;
Chris@174 1833 } else {
Chris@174 1834 newCentreFrame = 0;
Chris@174 1835 }
Chris@363 1836
gyorgyf@645 1837 #ifdef DEBUG_PANE
Chris@587 1838 SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame <<
Chris@585 1839 ", models end frame = " << getModelsEndFrame() << endl;
Chris@363 1840 #endif
Chris@339 1841
Chris@174 1842 if (newCentreFrame >= getModelsEndFrame()) {
Chris@174 1843 newCentreFrame = getModelsEndFrame();
Chris@174 1844 if (newCentreFrame > 0) --newCentreFrame;
Chris@174 1845 }
Chris@174 1846
Chris@174 1847 if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) {
Chris@510 1848 setCentreFrame(newCentreFrame, !m_altPressed);
Chris@174 1849 }
Chris@174 1850 }
Chris@174 1851
Chris@343 1852 if (m_dragMode == VerticalDrag ||
Chris@343 1853 m_dragMode == FreeDrag) {
Chris@174 1854
Chris@174 1855 float vmin = 0.f, vmax = 0.f;
Chris@174 1856 float dmin = 0.f, dmax = 0.f;
Chris@174 1857
Chris@174 1858 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
Chris@174 1859
Chris@248 1860 // std::cerr << "ydiff = " << ydiff << std::endl;
Chris@174 1861
Chris@343 1862 int ydiff = e->y() - m_clickPos.y();
Chris@174 1863 float perpix = (dmax - dmin) / height();
Chris@174 1864 float valdiff = ydiff * perpix;
Chris@248 1865 // std::cerr << "valdiff = " << valdiff << std::endl;
Chris@174 1866
Chris@343 1867 if (m_dragMode == UnresolvedDrag && ydiff != 0) {
Chris@343 1868 m_dragMode = VerticalDrag;
Chris@343 1869 }
Chris@343 1870
Chris@174 1871 float newmin = m_dragStartMinValue + valdiff;
Chris@174 1872 float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff;
Chris@174 1873 if (newmin < vmin) {
Chris@174 1874 newmax += vmin - newmin;
Chris@174 1875 newmin += vmin - newmin;
Chris@174 1876 }
Chris@174 1877 if (newmax > vmax) {
Chris@174 1878 newmin -= newmax - vmax;
Chris@174 1879 newmax -= newmax - vmax;
Chris@174 1880 }
Chris@248 1881 // std::cerr << "(" << dmin << ", " << dmax << ") -> ("
Chris@248 1882 // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl;
Chris@174 1883
Chris@174 1884 setTopLayerDisplayExtents(newmin, newmax);
Chris@174 1885 updateVerticalPanner();
Chris@174 1886 }
Chris@174 1887 }
Chris@174 1888 }
Chris@174 1889
Chris@343 1890 Pane::DragMode
Chris@343 1891 Pane::updateDragMode(DragMode dragMode,
Chris@343 1892 QPoint origin,
Chris@343 1893 QPoint point,
Chris@343 1894 bool canMoveHorizontal,
Chris@343 1895 bool canMoveVertical,
Chris@343 1896 bool resistHorizontal,
Chris@343 1897 bool resistVertical)
Chris@343 1898 {
Chris@343 1899 int xdiff = point.x() - origin.x();
Chris@343 1900 int ydiff = point.y() - origin.y();
Chris@343 1901
Chris@343 1902 int smallThreshold = 10, bigThreshold = 80;
Chris@343 1903
Chris@587 1904 // SVDEBUG << "Pane::updateDragMode: xdiff = " << xdiff << ", ydiff = "
Chris@585 1905 // << ydiff << ", canMoveVertical = " << canMoveVertical << ", drag mode = " << m_dragMode << endl;
Chris@343 1906
Chris@343 1907 if (dragMode == UnresolvedDrag) {
Chris@343 1908
Chris@343 1909 if (abs(ydiff) > smallThreshold &&
Chris@343 1910 abs(ydiff) > abs(xdiff) * 2 &&
Chris@343 1911 canMoveVertical) {
Chris@587 1912 // SVDEBUG << "Pane::updateDragMode: passed vertical threshold" << endl;
Chris@343 1913 dragMode = VerticalDrag;
Chris@343 1914 } else if (abs(xdiff) > smallThreshold &&
Chris@343 1915 abs(xdiff) > abs(ydiff) * 2 &&
Chris@343 1916 canMoveHorizontal) {
Chris@587 1917 // SVDEBUG << "Pane::updateDragMode: passed horizontal threshold" << endl;
Chris@343 1918 dragMode = HorizontalDrag;
Chris@343 1919 } else if (abs(xdiff) > smallThreshold &&
Chris@343 1920 abs(ydiff) > smallThreshold &&
Chris@343 1921 canMoveVertical &&
Chris@343 1922 canMoveHorizontal) {
Chris@587 1923 // SVDEBUG << "Pane::updateDragMode: passed both thresholds" << endl;
Chris@343 1924 dragMode = FreeDrag;
Chris@343 1925 }
Chris@343 1926 }
Chris@343 1927
Chris@343 1928 if (dragMode == VerticalDrag && canMoveHorizontal) {
Chris@343 1929 if (abs(xdiff) > bigThreshold) dragMode = FreeDrag;
Chris@343 1930 }
Chris@343 1931
Chris@343 1932 if (dragMode == HorizontalDrag && canMoveVertical) {
Chris@343 1933 if (abs(ydiff) > bigThreshold) dragMode = FreeDrag;
Chris@343 1934 }
Chris@343 1935
Chris@343 1936 if (dragMode == UnresolvedDrag) {
Chris@343 1937 if (!resistHorizontal && xdiff != 0) {
Chris@343 1938 dragMode = HorizontalDrag;
Chris@343 1939 }
Chris@343 1940 if (!resistVertical && ydiff != 0) {
Chris@343 1941 if (dragMode == HorizontalDrag) dragMode = FreeDrag;
Chris@343 1942 else dragMode = VerticalDrag;
Chris@343 1943 }
Chris@343 1944 }
Chris@343 1945
Chris@343 1946 return dragMode;
Chris@343 1947 }
Chris@343 1948
Chris@174 1949 void
Chris@174 1950 Pane::dragExtendSelection(QMouseEvent *e)
Chris@174 1951 {
Chris@174 1952 int mouseFrame = getFrameForX(e->x());
Chris@174 1953 size_t resolution = 1;
Chris@174 1954 int snapFrameLeft = mouseFrame;
Chris@174 1955 int snapFrameRight = mouseFrame;
gyorgyf@645 1956
Chris@174 1957 Layer *layer = getSelectedLayer();
Chris@174 1958 if (layer && !m_shiftPressed) {
Chris@174 1959 layer->snapToFeatureFrame(this, snapFrameLeft,
Chris@174 1960 resolution, Layer::SnapLeft);
Chris@174 1961 layer->snapToFeatureFrame(this, snapFrameRight,
Chris@174 1962 resolution, Layer::SnapRight);
Chris@174 1963 }
gyorgyf@645 1964
gyorgyf@645 1965 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl;
Chris@174 1966
Chris@174 1967 if (snapFrameLeft < 0) snapFrameLeft = 0;
Chris@174 1968 if (snapFrameRight < 0) snapFrameRight = 0;
gyorgyf@645 1969
Chris@174 1970 size_t min, max;
gyorgyf@645 1971
Chris@248 1972 if (m_selectionStartFrame > size_t(snapFrameLeft)) {
Chris@174 1973 min = snapFrameLeft;
Chris@174 1974 max = m_selectionStartFrame;
Chris@248 1975 } else if (size_t(snapFrameRight) > m_selectionStartFrame) {
Chris@174 1976 min = m_selectionStartFrame;
Chris@174 1977 max = snapFrameRight;
Chris@174 1978 } else {
Chris@174 1979 min = snapFrameLeft;
Chris@174 1980 max = snapFrameRight;
Chris@174 1981 }
Chris@174 1982
Chris@174 1983 if (m_manager) {
Chris@333 1984 m_manager->setInProgressSelection(Selection(alignToReference(min),
Chris@333 1985 alignToReference(max)),
Chris@174 1986 !m_resizing && !m_ctrlPressed);
Chris@174 1987 }
Chris@174 1988
Chris@259 1989 edgeScrollMaybe(e->x());
Chris@259 1990
Chris@259 1991 update();
Chris@259 1992 }
Chris@259 1993
Chris@259 1994 void
Chris@259 1995 Pane::edgeScrollMaybe(int x)
Chris@259 1996 {
Chris@259 1997 int mouseFrame = getFrameForX(x);
Chris@259 1998
Chris@174 1999 bool doScroll = false;
Chris@174 2000 if (!m_manager) doScroll = true;
Chris@174 2001 if (!m_manager->isPlaying()) doScroll = true;
Chris@174 2002 if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
Chris@174 2003
Chris@174 2004 if (doScroll) {
Chris@174 2005 int offset = mouseFrame - getStartFrame();
Chris@174 2006 int available = getEndFrame() - getStartFrame();
Chris@259 2007 int move = 0;
Chris@174 2008 if (offset >= available * 0.95) {
Chris@259 2009 move = int(offset - available * 0.95) + 1;
Chris@259 2010 } else if (offset <= available * 0.10) {
Chris@259 2011 move = int(available * 0.10 - offset) + 1;
Chris@259 2012 move = -move;
Chris@259 2013 }
Chris@259 2014 if (move != 0) {
Chris@174 2015 setCentreFrame(m_centreFrame + move);
Chris@259 2016 update();
Chris@174 2017 }
Chris@174 2018 }
Chris@174 2019 }
Chris@174 2020
Chris@174 2021 void
Chris@127 2022 Pane::mouseDoubleClickEvent(QMouseEvent *e)
Chris@127 2023 {
Chris@127 2024 if (e->buttons() & Qt::RightButton) {
Chris@127 2025 return;
Chris@127 2026 }
Chris@127 2027
Chris@343 2028 // std::cerr << "mouseDoubleClickEvent" << std::endl;
Chris@127 2029
Chris@127 2030 m_clickPos = e->pos();
Chris@127 2031 m_clickedInRange = true;
Chris@127 2032 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
Chris@127 2033 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
Chris@510 2034 m_altPressed = (e->modifiers() & Qt::AltModifier);
Chris@127 2035
Chris@127 2036 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@127 2037 if (m_manager) mode = m_manager->getToolMode();
Chris@127 2038
Chris@255 2039 bool relocate = (mode == ViewManager::NavigateMode ||
Chris@255 2040 (e->buttons() & Qt::MidButton));
Chris@255 2041
Chris@127 2042 if (mode == ViewManager::NavigateMode ||
Chris@127 2043 mode == ViewManager::EditMode) {
Chris@127 2044
gyorgyf@645 2045 Layer *layer = getSelectedLayer();
gyorgyf@645 2046 if (layer && layer->isLayerEditable()) {
gyorgyf@645 2047 if (layer->editOpen(this, e)) relocate = false;
gyorgyf@645 2048 }
Chris@280 2049
Chris@280 2050 } else if (mode == ViewManager::MeasureMode) {
Chris@280 2051
Chris@280 2052 Layer *layer = getTopLayer();
Chris@280 2053 if (layer) layer->measureDoubleClick(this, e);
Chris@280 2054 update();
Chris@127 2055 }
Chris@255 2056
Chris@255 2057 if (relocate) {
Chris@255 2058
Chris@255 2059 long f = getFrameForX(e->x());
Chris@255 2060
Chris@255 2061 setCentreFrame(f);
Chris@255 2062
Chris@255 2063 m_dragCentreFrame = f;
Chris@255 2064 m_dragStartMinValue = 0;
Chris@255 2065 m_dragMode = UnresolvedDrag;
Chris@255 2066
Chris@255 2067 float vmin, vmax, dmin, dmax;
Chris@255 2068 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
Chris@255 2069 m_dragStartMinValue = dmin;
Chris@255 2070 }
Chris@255 2071 }
Chris@551 2072
Chris@551 2073 m_clickedInRange = false; // in case mouseReleaseEvent is not properly called
Chris@127 2074 }
Chris@127 2075
Chris@127 2076 void
Chris@290 2077 Pane::enterEvent(QEvent *)
Chris@290 2078 {
Chris@290 2079 m_mouseInWidget = true;
Chris@290 2080 }
Chris@290 2081
Chris@290 2082 void
Chris@127 2083 Pane::leaveEvent(QEvent *)
Chris@127 2084 {
Chris@290 2085 m_mouseInWidget = false;
Chris@127 2086 bool previouslyIdentifying = m_identifyFeatures;
Chris@127 2087 m_identifyFeatures = false;
Chris@127 2088 if (previouslyIdentifying) update();
Chris@189 2089 emit contextHelpChanged("");
Chris@127 2090 }
Chris@127 2091
Chris@127 2092 void
Chris@133 2093 Pane::resizeEvent(QResizeEvent *)
Chris@133 2094 {
Chris@133 2095 updateHeadsUpDisplay();
Chris@133 2096 }
Chris@133 2097
Chris@133 2098 void
Chris@127 2099 Pane::wheelEvent(QWheelEvent *e)
Chris@127 2100 {
Chris@127 2101 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl;
Chris@127 2102
Chris@127 2103 int count = e->delta();
Chris@127 2104
Chris@127 2105 if (count > 0) {
gyorgyf@645 2106 if (count >= 120) count /= 120;
gyorgyf@645 2107 else count = 1;
Chris@127 2108 }
Chris@127 2109
Chris@127 2110 if (count < 0) {
gyorgyf@645 2111 if (count <= -120) count /= 120;
gyorgyf@645 2112 else count = -1;
Chris@127 2113 }
Chris@127 2114
Chris@127 2115 if (e->modifiers() & Qt::ControlModifier) {
Chris@127 2116
gyorgyf@645 2117 // Scroll left or right, rapidly
gyorgyf@645 2118
gyorgyf@645 2119 if (getStartFrame() < 0 &&
gyorgyf@645 2120 getEndFrame() >= getModelsEndFrame()) return;
gyorgyf@645 2121
gyorgyf@645 2122 long delta = ((width() / 2) * count * m_zoomLevel);
gyorgyf@645 2123
gyorgyf@645 2124 if (int(m_centreFrame) < delta) {
gyorgyf@645 2125 setCentreFrame(0);
gyorgyf@645 2126 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
gyorgyf@645 2127 setCentreFrame(getModelsEndFrame());
gyorgyf@645 2128 } else {
gyorgyf@645 2129 setCentreFrame(m_centreFrame - delta);
gyorgyf@645 2130 }
Chris@127 2131
Chris@256 2132 } else if (e->modifiers() & Qt::ShiftModifier) {
Chris@256 2133
Chris@256 2134 // Zoom vertically
Chris@256 2135
Chris@256 2136 if (m_vpan) {
Chris@256 2137 m_vpan->scroll(e->delta() > 0);
Chris@256 2138 }
Chris@256 2139
Chris@256 2140 } else if (e->modifiers() & Qt::AltModifier) {
Chris@256 2141
Chris@256 2142 // Zoom vertically
Chris@256 2143
Chris@256 2144 if (m_vthumb) {
Chris@256 2145 m_vthumb->scroll(e->delta() > 0);
Chris@256 2146 }
Chris@256 2147
Chris@127 2148 } else {
Chris@127 2149
gyorgyf@645 2150 // Zoom in or out
gyorgyf@645 2151
gyorgyf@645 2152 int newZoomLevel = m_zoomLevel;
Chris@127 2153
gyorgyf@645 2154 while (count > 0) {
gyorgyf@645 2155 if (newZoomLevel <= 2) {
gyorgyf@645 2156 newZoomLevel = 1;
gyorgyf@645 2157 break;
gyorgyf@645 2158 }
gyorgyf@645 2159 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1,
gyorgyf@645 2160 ZoomConstraint::RoundDown);
gyorgyf@645 2161 --count;
gyorgyf@645 2162 }
gyorgyf@645 2163
gyorgyf@645 2164 while (count < 0) {
gyorgyf@645 2165 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
gyorgyf@645 2166 ZoomConstraint::RoundUp);
gyorgyf@645 2167 ++count;
gyorgyf@645 2168 }
gyorgyf@645 2169
gyorgyf@645 2170 if (newZoomLevel != m_zoomLevel) {
gyorgyf@645 2171 setZoomLevel(newZoomLevel);
gyorgyf@645 2172 }
Chris@127 2173 }
Chris@127 2174
Chris@127 2175 emit paneInteractedWith();
Chris@127 2176 }
Chris@127 2177
Chris@132 2178 void
Chris@132 2179 Pane::horizontalThumbwheelMoved(int value)
Chris@132 2180 {
Chris@137 2181 //!!! dupe with updateHeadsUpDisplay
Chris@137 2182
Chris@132 2183 int count = 0;
Chris@132 2184 int level = 1;
Chris@137 2185
Chris@137 2186
Chris@137 2187 //!!! pull out into function (presumably in View)
Chris@137 2188 bool haveConstraint = false;
Chris@137 2189 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end();
Chris@137 2190 ++i) {
Chris@137 2191 if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) {
Chris@137 2192 haveConstraint = true;
Chris@137 2193 break;
Chris@137 2194 }
Chris@132 2195 }
Chris@132 2196
Chris@137 2197 if (haveConstraint) {
Chris@137 2198 while (true) {
Chris@137 2199 if (m_hthumb->getMaximumValue() - value == count) break;
Chris@137 2200 int newLevel = getZoomConstraintBlockSize(level + 1,
Chris@137 2201 ZoomConstraint::RoundUp);
Chris@137 2202 if (newLevel == level) break;
Chris@137 2203 level = newLevel;
Chris@137 2204 if (++count == 50) break;
Chris@137 2205 }
Chris@137 2206 } else {
Chris@137 2207 while (true) {
Chris@137 2208 if (m_hthumb->getMaximumValue() - value == count) break;
Chris@137 2209 int step = level / 10;
Chris@137 2210 int pwr = 0;
Chris@137 2211 while (step > 0) {
Chris@137 2212 ++pwr;
Chris@137 2213 step /= 2;
Chris@137 2214 }
Chris@137 2215 step = 1;
Chris@137 2216 while (pwr > 0) {
Chris@137 2217 step *= 2;
Chris@137 2218 --pwr;
Chris@137 2219 }
Chris@137 2220 // std::cerr << level << std::endl;
Chris@137 2221 level += step;
Chris@137 2222 if (++count == 100 || level > 262144) break;
Chris@137 2223 }
Chris@137 2224 }
Chris@137 2225
Chris@244 2226 // std::cerr << "new level is " << level << std::endl;
Chris@132 2227 setZoomLevel(level);
Chris@132 2228 }
Chris@132 2229
Chris@132 2230 void
Chris@132 2231 Pane::verticalThumbwheelMoved(int value)
Chris@132 2232 {
Chris@133 2233 Layer *layer = 0;
Chris@133 2234 if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
Chris@133 2235 if (layer) {
Chris@133 2236 int defaultStep = 0;
Chris@133 2237 int max = layer->getVerticalZoomSteps(defaultStep);
Chris@133 2238 if (max == 0) {
Chris@133 2239 updateHeadsUpDisplay();
Chris@133 2240 return;
Chris@133 2241 }
Chris@133 2242 if (value > max) {
Chris@133 2243 value = max;
Chris@133 2244 }
Chris@133 2245 layer->setVerticalZoomStep(value);
Chris@174 2246 updateVerticalPanner();
Chris@133 2247 }
Chris@132 2248 }
Chris@132 2249
Chris@174 2250 void
Chris@174 2251 Pane::verticalPannerMoved(float x0, float y0, float w, float h)
Chris@174 2252 {
Chris@174 2253 float vmin, vmax, dmin, dmax;
Chris@174 2254 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
Chris@174 2255 float y1 = y0 + h;
Chris@174 2256 float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
Chris@174 2257 float newmin = vmin + ((1.0 - y1) * (vmax - vmin));
Chris@438 2258 // std::cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w
Chris@438 2259 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << std::endl;
Chris@174 2260 setTopLayerDisplayExtents(newmin, newmax);
Chris@174 2261 }
Chris@174 2262
Chris@188 2263 void
Chris@188 2264 Pane::editVerticalPannerExtents()
Chris@188 2265 {
Chris@188 2266 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return;
Chris@188 2267
Chris@188 2268 float vmin, vmax, dmin, dmax;
Chris@188 2269 QString unit;
Chris@188 2270 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)
Chris@188 2271 || vmax == vmin) {
Chris@188 2272 return;
Chris@188 2273 }
Chris@188 2274
Chris@188 2275 RangeInputDialog dialog(tr("Enter new range"),
Chris@188 2276 tr("New vertical display range, from %1 to %2 %4:")
Chris@188 2277 .arg(vmin).arg(vmax).arg(unit),
Chris@188 2278 unit, vmin, vmax, this);
Chris@188 2279 dialog.setRange(dmin, dmax);
Chris@188 2280
Chris@188 2281 if (dialog.exec() == QDialog::Accepted) {
Chris@188 2282 dialog.getRange(dmin, dmax);
Chris@188 2283 setTopLayerDisplayExtents(dmin, dmax);
Chris@188 2284 updateVerticalPanner();
Chris@188 2285 }
Chris@188 2286 }
Chris@188 2287
Chris@312 2288 void
Chris@437 2289 Pane::layerParametersChanged()
Chris@437 2290 {
Chris@437 2291 View::layerParametersChanged();
Chris@437 2292 updateHeadsUpDisplay();
Chris@437 2293 }
Chris@437 2294
Chris@437 2295 void
Chris@312 2296 Pane::dragEnterEvent(QDragEnterEvent *e)
Chris@312 2297 {
Chris@312 2298 QStringList formats(e->mimeData()->formats());
Chris@312 2299 std::cerr << "dragEnterEvent: format: "
Chris@312 2300 << formats.join(",").toStdString()
Chris@312 2301 << ", possibleActions: " << e->possibleActions()
Chris@312 2302 << ", proposedAction: " << e->proposedAction() << std::endl;
Chris@312 2303
Chris@312 2304 if (e->provides("text/uri-list") || e->provides("text/plain")) {
Chris@312 2305
Chris@312 2306 if (e->proposedAction() & Qt::CopyAction) {
Chris@312 2307 e->acceptProposedAction();
Chris@312 2308 } else {
Chris@312 2309 e->setDropAction(Qt::CopyAction);
Chris@312 2310 e->accept();
Chris@312 2311 }
Chris@312 2312 }
Chris@312 2313 }
Chris@312 2314
Chris@312 2315 void
Chris@312 2316 Pane::dropEvent(QDropEvent *e)
Chris@312 2317 {
Chris@312 2318 std::cerr << "dropEvent: text: \"" << e->mimeData()->text().toStdString()
Chris@312 2319 << "\"" << std::endl;
Chris@312 2320
Chris@312 2321 if (e->provides("text/uri-list") || e->provides("text/plain")) {
Chris@312 2322
Chris@312 2323 if (e->proposedAction() & Qt::CopyAction) {
Chris@312 2324 e->acceptProposedAction();
Chris@312 2325 } else {
Chris@312 2326 e->setDropAction(Qt::CopyAction);
Chris@312 2327 e->accept();
Chris@312 2328 }
Chris@312 2329
Chris@312 2330 if (e->provides("text/uri-list")) {
Chris@312 2331
Chris@587 2332 SVDEBUG << "accepting... data is \"" << e->encodedData("text/uri-list").data() << "\"" << endl;
Chris@312 2333 emit dropAccepted(QString::fromLocal8Bit
Chris@312 2334 (e->encodedData("text/uri-list").data())
Chris@312 2335 .split(QRegExp("[\\r\\n]+"),
Chris@312 2336 QString::SkipEmptyParts));
Chris@312 2337 } else {
Chris@312 2338 emit dropAccepted(QString::fromLocal8Bit
Chris@312 2339 (e->encodedData("text/plain").data()));
Chris@312 2340 }
Chris@312 2341 }
Chris@312 2342 }
Chris@312 2343
Chris@127 2344 bool
Chris@127 2345 Pane::editSelectionStart(QMouseEvent *e)
Chris@127 2346 {
Chris@127 2347 if (!m_identifyFeatures ||
gyorgyf@645 2348 !m_manager ||
gyorgyf@645 2349 m_manager->getToolMode() != ViewManager::EditMode) {
gyorgyf@645 2350 return false;
Chris@127 2351 }
Chris@127 2352
Chris@127 2353 bool closeToLeft, closeToRight;
Chris@127 2354 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight));
Chris@127 2355 if (s.isEmpty()) return false;
Chris@127 2356 m_editingSelection = s;
Chris@127 2357 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0);
Chris@127 2358 m_mousePos = e->pos();
Chris@127 2359 return true;
Chris@127 2360 }
Chris@127 2361
Chris@127 2362 bool
Chris@127 2363 Pane::editSelectionDrag(QMouseEvent *e)
Chris@127 2364 {
Chris@127 2365 if (m_editingSelection.isEmpty()) return false;
Chris@127 2366 m_mousePos = e->pos();
Chris@127 2367 update();
Chris@127 2368 return true;
Chris@127 2369 }
Chris@127 2370
Chris@127 2371 bool
Chris@248 2372 Pane::editSelectionEnd(QMouseEvent *)
Chris@127 2373 {
Chris@127 2374 if (m_editingSelection.isEmpty()) return false;
Chris@127 2375
Chris@127 2376 int offset = m_mousePos.x() - m_clickPos.x();
Chris@127 2377 Layer *layer = getSelectedLayer();
Chris@127 2378
Chris@127 2379 if (offset == 0 || !layer) {
gyorgyf@645 2380 m_editingSelection = Selection();
gyorgyf@645 2381 return true;
Chris@127 2382 }
Chris@127 2383
Chris@127 2384 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset;
Chris@127 2385 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset;
Chris@127 2386
Chris@127 2387 long f0 = getFrameForX(p0);
Chris@127 2388 long f1 = getFrameForX(p1);
Chris@127 2389
Chris@127 2390 Selection newSelection(f0, f1);
Chris@127 2391
Chris@127 2392 if (m_editingSelectionEdge == 0) {
gyorgyf@645 2393
Chris@127 2394 CommandHistory::getInstance()->startCompoundOperation
Chris@127 2395 (tr("Drag Selection"), true);
Chris@127 2396
gyorgyf@645 2397 layer->moveSelection(m_editingSelection, f0);
gyorgyf@645 2398
Chris@127 2399 } else {
gyorgyf@645 2400
Chris@127 2401 CommandHistory::getInstance()->startCompoundOperation
Chris@127 2402 (tr("Resize Selection"), true);
Chris@127 2403
gyorgyf@645 2404 if (m_editingSelectionEdge < 0) {
gyorgyf@645 2405 f1 = m_editingSelection.getEndFrame();
gyorgyf@645 2406 } else {
gyorgyf@645 2407 f0 = m_editingSelection.getStartFrame();
gyorgyf@645 2408 }
gyorgyf@645 2409
gyorgyf@645 2410 newSelection = Selection(f0, f1);
gyorgyf@645 2411 layer->resizeSelection(m_editingSelection, newSelection);
Chris@127 2412 }
Chris@127 2413
Chris@127 2414 m_manager->removeSelection(m_editingSelection);
Chris@127 2415 m_manager->addSelection(newSelection);
Chris@127 2416
Chris@127 2417 CommandHistory::getInstance()->endCompoundOperation();
Chris@127 2418
Chris@127 2419 m_editingSelection = Selection();
Chris@127 2420 return true;
Chris@127 2421 }
Chris@127 2422
Chris@127 2423 void
Chris@127 2424 Pane::toolModeChanged()
Chris@127 2425 {
Chris@127 2426 ViewManager::ToolMode mode = m_manager->getToolMode();
Chris@587 2427 // SVDEBUG << "Pane::toolModeChanged(" << mode << ")" << endl;
Chris@127 2428
Chris@267 2429 if (mode == ViewManager::MeasureMode && !m_measureCursor1) {
Chris@267 2430 m_measureCursor1 = new QCursor(QBitmap(":/icons/measure1cursor.xbm"),
Chris@267 2431 QBitmap(":/icons/measure1mask.xbm"),
Chris@267 2432 15, 14);
Chris@267 2433 m_measureCursor2 = new QCursor(QBitmap(":/icons/measure2cursor.xbm"),
Chris@267 2434 QBitmap(":/icons/measure2mask.xbm"),
Chris@267 2435 16, 17);
Chris@257 2436 }
Chris@257 2437
Chris@127 2438 switch (mode) {
Chris@127 2439
Chris@127 2440 case ViewManager::NavigateMode:
gyorgyf@645 2441 setCursor(Qt::PointingHandCursor);
gyorgyf@645 2442 break;
gyorgyf@645 2443
Chris@127 2444 case ViewManager::SelectMode:
gyorgyf@645 2445 setCursor(Qt::ArrowCursor);
gyorgyf@645 2446 break;
gyorgyf@645 2447
Chris@127 2448 case ViewManager::EditMode:
gyorgyf@645 2449 setCursor(Qt::UpArrowCursor);
gyorgyf@645 2450 break;
gyorgyf@645 2451
Chris@127 2452 case ViewManager::DrawMode:
gyorgyf@645 2453 setCursor(Qt::CrossCursor);
gyorgyf@645 2454 break;
gyorgyf@645 2455
Chris@335 2456 case ViewManager::EraseMode:
gyorgyf@645 2457 setCursor(Qt::CrossCursor);
gyorgyf@645 2458 break;
Chris@257 2459
Chris@257 2460 case ViewManager::MeasureMode:
Chris@267 2461 if (m_measureCursor1) setCursor(*m_measureCursor1);
gyorgyf@645 2462 break;
gyorgyf@645 2463
gyorgyf@645 2464 // GF: NoteEditMode uses the same default cursor as EditMode, but it will change in a context sensitive manner.
gyorgyf@645 2465 case ViewManager::NoteEditMode:
gyorgyf@645 2466 setCursor(Qt::UpArrowCursor);
gyorgyf@645 2467 break;
gyorgyf@645 2468
gyorgyf@645 2469 /*
Chris@127 2470 case ViewManager::TextMode:
gyorgyf@645 2471 setCursor(Qt::IBeamCursor);
gyorgyf@645 2472 break;
Chris@127 2473 */
Chris@127 2474 }
Chris@127 2475 }
Chris@127 2476
Chris@133 2477 void
Chris@133 2478 Pane::zoomWheelsEnabledChanged()
Chris@133 2479 {
Chris@133 2480 updateHeadsUpDisplay();
Chris@133 2481 update();
Chris@133 2482 }
Chris@133 2483
Chris@133 2484 void
Chris@224 2485 Pane::viewZoomLevelChanged(View *v, unsigned long z, bool locked)
Chris@133 2486 {
Chris@212 2487 // std::cerr << "Pane[" << this << "]::zoomLevelChanged (global now "
Chris@212 2488 // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << std::endl;
Chris@192 2489
Chris@224 2490 View::viewZoomLevelChanged(v, z, locked);
Chris@224 2491
Chris@232 2492 if (m_hthumb && !m_hthumb->isVisible()) return;
Chris@224 2493
Chris@222 2494 if (v != this) {
Chris@222 2495 if (!locked || !m_followZoom) return;
Chris@222 2496 }
Chris@222 2497
Chris@133 2498 if (m_manager && m_manager->getZoomWheelsEnabled()) {
Chris@133 2499 updateHeadsUpDisplay();
Chris@133 2500 }
Chris@133 2501 }
Chris@133 2502
Chris@133 2503 void
Chris@133 2504 Pane::propertyContainerSelected(View *v, PropertyContainer *pc)
Chris@133 2505 {
Chris@133 2506 Layer *layer = 0;
Chris@133 2507
Chris@133 2508 if (getLayerCount() > 0) {
Chris@133 2509 layer = getLayer(getLayerCount() - 1);
Chris@133 2510 disconnect(layer, SIGNAL(verticalZoomChanged()),
Chris@133 2511 this, SLOT(verticalZoomChanged()));
Chris@133 2512 }
Chris@133 2513
Chris@133 2514 View::propertyContainerSelected(v, pc);
Chris@133 2515 updateHeadsUpDisplay();
Chris@133 2516
Chris@187 2517 if (m_vthumb) {
Chris@187 2518 RangeMapper *rm = 0;
Chris@187 2519 if (layer) rm = layer->getNewVerticalZoomRangeMapper();
Chris@187 2520 if (rm) m_vthumb->setRangeMapper(rm);
Chris@187 2521 }
Chris@187 2522
Chris@133 2523 if (getLayerCount() > 0) {
Chris@133 2524 layer = getLayer(getLayerCount() - 1);
Chris@133 2525 connect(layer, SIGNAL(verticalZoomChanged()),
Chris@133 2526 this, SLOT(verticalZoomChanged()));
Chris@133 2527 }
Chris@133 2528 }
Chris@133 2529
Chris@133 2530 void
Chris@133 2531 Pane::verticalZoomChanged()
Chris@133 2532 {
Chris@133 2533 Layer *layer = 0;
Chris@133 2534
Chris@133 2535 if (getLayerCount() > 0) {
Chris@133 2536
Chris@133 2537 layer = getLayer(getLayerCount() - 1);
Chris@133 2538
Chris@133 2539 if (m_vthumb && m_vthumb->isVisible()) {
Chris@133 2540 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
Chris@133 2541 }
Chris@133 2542 }
Chris@133 2543 }
Chris@133 2544
Chris@189 2545 void
Chris@189 2546 Pane::updateContextHelp(const QPoint *pos)
Chris@189 2547 {
Chris@189 2548 QString help = "";
Chris@189 2549
Chris@189 2550 if (m_clickedInRange) {
Chris@189 2551 emit contextHelpChanged("");
Chris@189 2552 return;
Chris@189 2553 }
Chris@189 2554
Chris@189 2555 ViewManager::ToolMode mode = ViewManager::NavigateMode;
Chris@189 2556 if (m_manager) mode = m_manager->getToolMode();
Chris@189 2557
Chris@189 2558 bool editable = false;
Chris@189 2559 Layer *layer = getSelectedLayer();
Chris@189 2560 if (layer && layer->isLayerEditable()) {
Chris@189 2561 editable = true;
Chris@189 2562 }
Chris@189 2563
Chris@189 2564 if (mode == ViewManager::NavigateMode) {
Chris@189 2565
Chris@189 2566 help = tr("Click and drag to navigate");
Chris@189 2567
Chris@189 2568 } else if (mode == ViewManager::SelectMode) {
Chris@189 2569
Chris@217 2570 if (!hasTopLayerTimeXAxis()) return;
Chris@217 2571
Chris@189 2572 bool haveSelection = (m_manager && !m_manager->getSelections().empty());
Chris@189 2573
Chris@189 2574 if (haveSelection) {
Chris@597 2575 #ifdef Q_OS_MAC
Chris@597 2576 if (editable) {
Chris@597 2577 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; hold Cmd for multi-select; middle-click and drag to navigate");
Chris@597 2578 } else {
Chris@597 2579 help = tr("Click and drag to select a range; hold Cmd for multi-select; middle-click and drag to navigate");
Chris@597 2580 }
Chris@597 2581 #else
Chris@189 2582 if (editable) {
Chris@189 2583 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; hold Ctrl for multi-select; middle-click and drag to navigate");
Chris@189 2584 } else {
Chris@189 2585 help = tr("Click and drag to select a range; hold Ctrl for multi-select; middle-click and drag to navigate");
Chris@189 2586 }
Chris@597 2587 #endif
Chris@189 2588
Chris@189 2589 if (pos) {
Chris@189 2590 bool closeToLeft = false, closeToRight = false;
Chris@189 2591 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
Chris@189 2592 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
Chris@189 2593
Chris@189 2594 help = tr("Click and drag to move the selection boundary");
Chris@189 2595 }
Chris@189 2596 }
Chris@189 2597 } else {
Chris@189 2598 if (editable) {
Chris@189 2599 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; middle-click to navigate");
Chris@189 2600 } else {
Chris@189 2601 help = tr("Click and drag to select a range; middle-click and drag to navigate");
Chris@189 2602 }
Chris@189 2603 }
Chris@189 2604
Chris@189 2605 } else if (mode == ViewManager::DrawMode) {
Chris@189 2606
Chris@189 2607 //!!! could call through to a layer function to find out exact meaning
gyorgyf@645 2608 if (editable) {
Chris@189 2609 help = tr("Click to add a new item in the active layer");
Chris@189 2610 }
Chris@335 2611
Chris@335 2612 } else if (mode == ViewManager::EraseMode) {
Chris@335 2613
Chris@335 2614 //!!! could call through to a layer function to find out exact meaning
gyorgyf@645 2615 if (editable) {
Chris@335 2616 help = tr("Click to erase an item from the active layer");
Chris@335 2617 }
Chris@189 2618
Chris@189 2619 } else if (mode == ViewManager::EditMode) {
Chris@189 2620
Chris@189 2621 //!!! could call through to layer
gyorgyf@645 2622 if (editable) {
Chris@551 2623 help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance");
Chris@189 2624 if (pos) {
Chris@189 2625 bool closeToLeft = false, closeToRight = false;
Chris@189 2626 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
Chris@189 2627 if (!selection.isEmpty()) {
Chris@189 2628 help = tr("Click and drag to move all items in the selected range");
Chris@189 2629 }
Chris@189 2630 }
Chris@189 2631 }
Chris@189 2632 }
Chris@189 2633
Chris@189 2634 emit contextHelpChanged(help);
Chris@189 2635 }
Chris@189 2636
Chris@189 2637 void
Chris@189 2638 Pane::mouseEnteredWidget()
Chris@189 2639 {
Chris@189 2640 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@189 2641 if (!w) return;
Chris@189 2642
Chris@189 2643 if (w == m_vpan) {
Chris@189 2644 emit contextHelpChanged(tr("Click and drag to adjust the visible range of the vertical scale"));
Chris@189 2645 } else if (w == m_vthumb) {
Chris@189 2646 emit contextHelpChanged(tr("Click and drag to adjust the vertical zoom level"));
Chris@189 2647 } else if (w == m_hthumb) {
Chris@189 2648 emit contextHelpChanged(tr("Click and drag to adjust the horizontal zoom level"));
Chris@189 2649 } else if (w == m_reset) {
Chris@189 2650 emit contextHelpChanged(tr("Reset horizontal and vertical zoom levels to their defaults"));
Chris@189 2651 }
Chris@189 2652 }
Chris@189 2653
Chris@189 2654 void
Chris@189 2655 Pane::mouseLeftWidget()
Chris@189 2656 {
Chris@189 2657 emit contextHelpChanged("");
Chris@189 2658 }
Chris@189 2659
Chris@316 2660 void
Chris@316 2661 Pane::toXml(QTextStream &stream,
Chris@316 2662 QString indent, QString extraAttributes) const
Chris@127 2663 {
Chris@316 2664 View::toXml
Chris@316 2665 (stream, indent,
gyorgyf@645 2666 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3")
gyorgyf@645 2667 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes));
Chris@127 2668 }
Chris@127 2669
Chris@127 2670