annotate view/Pane.cpp @ 1475:84c4ddb38415 by-id

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