annotate view/Pane.cpp @ 880:dd95abfe736c alignment_view

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