annotate view/Pane.cpp @ 261:11021509c4eb

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