annotate view/Pane.cpp @ 806:4c8ca536b54f warnfix_no_size_t

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