annotate view/Pane.cpp @ 1352:4949061fcb8c zoom

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