annotate view/Pane.cpp @ 1181:e0ac21f07ab0 bqresample

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