annotate view/Pane.cpp @ 1362:d79e21855aef

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