annotate view/Pane.cpp @ 224:9465b5375235

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