annotate view/Pane.cpp @ 1230:366ffdf719cd

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