annotate view/Pane.cpp @ 1618:f67e9e12e101

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