annotate view/Pane.cpp @ 1354:40b9a495a0e0

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