annotate view/Pane.cpp @ 337:813170c57b13

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