annotate view/Pane.cpp @ 814:db31266cf606

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