Chris@127: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@127: Chris@127: /* Chris@127: Sonic Visualiser Chris@127: An audio file viewer and annotation editor. Chris@127: Centre for Digital Music, Queen Mary, University of London. Chris@264: This file copyright 2006-2007 Chris Cannam and QMUL. Chris@127: Chris@127: This program is free software; you can redistribute it and/or Chris@127: modify it under the terms of the GNU General Public License as Chris@127: published by the Free Software Foundation; either version 2 of the Chris@127: License, or (at your option) any later version. See the file Chris@127: COPYING included with this distribution for more information. Chris@127: */ Chris@127: Chris@128: #include "Pane.h" Chris@128: #include "layer/Layer.h" Chris@128: #include "data/model/Model.h" Chris@127: #include "base/ZoomConstraint.h" Chris@127: #include "base/RealTime.h" Chris@127: #include "base/Profiler.h" Chris@128: #include "ViewManager.h" Chris@376: #include "widgets/CommandHistory.h" Chris@376: #include "widgets/TextAbbrev.h" Chris@1193: #include "widgets/IconLoader.h" Chris@338: #include "base/Preferences.h" Chris@127: #include "layer/WaveformLayer.h" Chris@928: #include "layer/TimeRulerLayer.h" Chris@1078: #include "layer/PaintAssistant.h" Chris@127: gyorgyf@646: // GF: added so we can propagate the mouse move event to the note layer for context handling. gyorgyf@646: #include "layer/LayerFactory.h" gyorgyf@646: #include "layer/FlexiNoteLayer.h" gyorgyf@646: gyorgyf@646: Chris@326: //!!! ugh Chris@326: #include "data/model/WaveFileModel.h" Chris@326: Chris@127: #include Chris@127: #include Chris@257: #include Chris@312: #include Chris@312: #include Chris@257: #include Chris@316: #include Chris@616: #include Chris@802: #include Chris@316: Chris@127: #include Chris@127: #include Chris@127: Chris@133: //!!! for HUD -- pull out into a separate class Chris@133: #include Chris@133: #include Chris@133: #include Chris@133: #include "widgets/Thumbwheel.h" Chris@172: #include "widgets/Panner.h" Chris@188: #include "widgets/RangeInputDialog.h" Chris@189: #include "widgets/NotifyingPushButton.h" Chris@133: Chris@282: #include "widgets/KeyReference.h" //!!! should probably split KeyReference into a data class in base and another that shows the widget Chris@282: Chris@363: //#define DEBUG_PANE Chris@363: Chris@1408: QCursor *Pane::m_measureCursor1 = nullptr; Chris@1408: QCursor *Pane::m_measureCursor2 = nullptr; Chris@262: Chris@127: Pane::Pane(QWidget *w) : Chris@127: View(w, true), Chris@127: m_identifyFeatures(false), Chris@127: m_clickedInRange(false), Chris@127: m_shiftPressed(false), Chris@127: m_ctrlPressed(false), Chris@510: m_altPressed(false), Chris@127: m_navigating(false), Chris@127: m_resizing(false), Chris@343: m_editing(false), Chris@343: m_releasing(false), Chris@133: m_centreLineVisible(true), Chris@222: m_scaleWidth(0), Chris@826: m_pendingWheelAngle(0), Chris@1408: m_headsUpDisplay(nullptr), Chris@1408: m_vpan(nullptr), Chris@1408: m_hthumb(nullptr), Chris@1408: m_vthumb(nullptr), Chris@1408: m_reset(nullptr), Chris@802: m_mouseInWidget(false), Chris@802: m_playbackFrameMoveScheduled(false), Chris@802: m_playbackFrameMoveTo(0) Chris@127: { Chris@127: setObjectName("Pane"); Chris@127: setMouseTracking(true); Chris@312: setAcceptDrops(true); Chris@133: Chris@133: updateHeadsUpDisplay(); Chris@456: Chris@730: connect(this, SIGNAL(regionOutlined(QRect)), Chris@730: this, SLOT(zoomToRegion(QRect))); Chris@730: Chris@728: cerr << "Pane::Pane(" << this << ") returning" << endl; Chris@133: } Chris@133: Chris@133: void Chris@133: Pane::updateHeadsUpDisplay() Chris@133: { Chris@382: Profiler profiler("Pane::updateHeadsUpDisplay"); Chris@187: Chris@192: if (!isVisible()) return; Chris@192: Chris@1408: Layer *layer = nullptr; Chris@1362: if (getLayerCount() > 0) { Chris@1362: layer = getLayer(getLayerCount() - 1); Chris@1362: } Chris@188: Chris@133: if (!m_headsUpDisplay) { Chris@133: Chris@133: m_headsUpDisplay = new QFrame(this); Chris@133: Chris@133: QGridLayout *layout = new QGridLayout; Chris@133: layout->setMargin(0); Chris@133: layout->setSpacing(0); Chris@133: m_headsUpDisplay->setLayout(layout); Chris@133: Chris@133: m_hthumb = new Thumbwheel(Qt::Horizontal); Chris@187: m_hthumb->setObjectName(tr("Horizontal Zoom")); Chris@260: m_hthumb->setCursor(Qt::ArrowCursor); Chris@173: layout->addWidget(m_hthumb, 1, 0, 1, 2); Chris@1193: m_hthumb->setFixedWidth(m_manager->scalePixelSize(70)); Chris@1193: m_hthumb->setFixedHeight(m_manager->scalePixelSize(16)); Chris@133: m_hthumb->setDefaultValue(0); Chris@908: m_hthumb->setSpeed(0.6f); Chris@133: connect(m_hthumb, SIGNAL(valueChanged(int)), this, Chris@133: SLOT(horizontalThumbwheelMoved(int))); Chris@189: connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); Chris@189: connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); Chris@172: Chris@172: m_vpan = new Panner; Chris@260: m_vpan->setCursor(Qt::ArrowCursor); Chris@172: layout->addWidget(m_vpan, 0, 1); Chris@1193: m_vpan->setFixedWidth(m_manager->scalePixelSize(12)); Chris@1193: m_vpan->setFixedHeight(m_manager->scalePixelSize(70)); Chris@174: m_vpan->setAlpha(80, 130); Chris@174: connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)), Chris@174: this, SLOT(verticalPannerMoved(float, float, float, float))); Chris@188: connect(m_vpan, SIGNAL(doubleClicked()), Chris@188: this, SLOT(editVerticalPannerExtents())); Chris@189: connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); Chris@189: connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); Chris@172: Chris@133: m_vthumb = new Thumbwheel(Qt::Vertical); Chris@187: m_vthumb->setObjectName(tr("Vertical Zoom")); Chris@260: m_vthumb->setCursor(Qt::ArrowCursor); Chris@172: layout->addWidget(m_vthumb, 0, 2); Chris@1193: m_vthumb->setFixedWidth(m_manager->scalePixelSize(16)); Chris@1193: m_vthumb->setFixedHeight(m_manager->scalePixelSize(70)); Chris@133: connect(m_vthumb, SIGNAL(valueChanged(int)), this, Chris@133: SLOT(verticalThumbwheelMoved(int))); Chris@189: connect(m_vthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); Chris@189: connect(m_vthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); Chris@133: Chris@188: if (layer) { Chris@188: RangeMapper *rm = layer->getNewVerticalZoomRangeMapper(); Chris@188: if (rm) m_vthumb->setRangeMapper(rm); Chris@188: } Chris@188: Chris@189: m_reset = new NotifyingPushButton; Chris@713: m_reset->setFlat(true); Chris@260: m_reset->setCursor(Qt::ArrowCursor); Chris@1193: m_reset->setFixedHeight(m_manager->scalePixelSize(16)); Chris@1193: m_reset->setFixedWidth(m_manager->scalePixelSize(16)); Chris@1193: m_reset->setIcon(IconLoader().load("zoom-reset")); Chris@501: m_reset->setToolTip(tr("Reset zoom to default")); Chris@189: layout->addWidget(m_reset, 1, 2); Chris@492: Chris@492: layout->setColumnStretch(0, 20); Chris@492: Chris@189: connect(m_reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); Chris@189: connect(m_reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); Chris@189: connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault())); Chris@189: connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); Chris@189: connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); Chris@133: } Chris@133: Chris@1354: int count = countZoomLevels(); Chris@1354: int current = getZoomLevelIndex(getZoomLevel()); Chris@1354: Chris@1354: m_hthumb->setMinimumValue(1); Chris@133: m_hthumb->setMaximumValue(count); Chris@133: m_hthumb->setValue(count - current); Chris@133: Chris@1354: if (m_hthumb->getDefaultValue() == 0) { Chris@133: m_hthumb->setDefaultValue(count - current); Chris@133: } Chris@133: Chris@204: bool haveVThumb = false; Chris@204: Chris@133: if (layer) { Chris@133: int defaultStep = 0; Chris@133: int max = layer->getVerticalZoomSteps(defaultStep); Chris@133: if (max == 0) { Chris@133: m_vthumb->hide(); Chris@133: } else { Chris@204: haveVThumb = true; Chris@133: m_vthumb->show(); Chris@187: m_vthumb->blockSignals(true); Chris@133: m_vthumb->setMinimumValue(0); Chris@133: m_vthumb->setMaximumValue(max); Chris@133: m_vthumb->setDefaultValue(defaultStep); Chris@133: m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); Chris@187: m_vthumb->blockSignals(false); Chris@135: Chris@682: // cerr << "Vertical thumbwheel: min 0, max " << max Chris@205: // << ", default " << defaultStep << ", value " Chris@682: // << m_vthumb->getValue() << endl; Chris@135: Chris@133: } Chris@133: } Chris@133: Chris@174: updateVerticalPanner(); Chris@174: Chris@133: if (m_manager && m_manager->getZoomWheelsEnabled() && Chris@1193: width() > m_manager->scalePixelSize(120) && Chris@1193: height() > m_manager->scalePixelSize(100)) { Chris@165: if (!m_headsUpDisplay->isVisible()) { Chris@165: m_headsUpDisplay->show(); Chris@165: } Chris@1193: int shift = m_manager->scalePixelSize(86); Chris@204: if (haveVThumb) { Chris@204: m_headsUpDisplay->setFixedHeight(m_vthumb->height() + m_hthumb->height()); Chris@1193: m_headsUpDisplay->move(width() - shift, height() - shift); Chris@133: } else { Chris@204: m_headsUpDisplay->setFixedHeight(m_hthumb->height()); Chris@1193: m_headsUpDisplay->move(width() - shift, Chris@1193: height() - m_manager->scalePixelSize(16)); Chris@133: } Chris@133: } else { Chris@133: m_headsUpDisplay->hide(); Chris@133: } Chris@127: } Chris@127: Chris@174: void Chris@174: Pane::updateVerticalPanner() Chris@174: { Chris@174: if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; Chris@174: Chris@208: // In principle we should show or hide the panner on the basis of Chris@208: // whether the top layer has adjustable display extents, and we do Chris@208: // that below. However, we have no basis for layout of the panner Chris@208: // if the vertical scroll wheel is not also present. So if we Chris@208: // have no vertical scroll wheel, we should remove the panner as Chris@208: // well. Ideally any layer that implements display extents should Chris@208: // implement vertical zoom steps as well, but they don't all at Chris@208: // the moment. Chris@208: Chris@1408: Layer *layer = nullptr; Chris@208: if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); Chris@208: int discard; Chris@208: if (layer && layer->getVerticalZoomSteps(discard) == 0) { Chris@208: m_vpan->hide(); Chris@208: return; Chris@208: } Chris@208: Chris@908: double vmin, vmax, dmin, dmax; Chris@174: if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) { Chris@908: double y0 = (dmin - vmin) / (vmax - vmin); Chris@908: double y1 = (dmax - vmin) / (vmax - vmin); Chris@174: m_vpan->blockSignals(true); Chris@908: m_vpan->setRectExtents(0, float(1.0 - y1), 1, float(y1 - y0)); Chris@174: m_vpan->blockSignals(false); Chris@174: m_vpan->show(); Chris@174: } else { Chris@174: m_vpan->hide(); Chris@174: } Chris@174: } Chris@174: Chris@127: bool Chris@127: Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) const Chris@127: { Chris@127: QPoint discard; Chris@127: bool b0, b1; Chris@127: Chris@711: if (m_manager && m_manager->getToolModeFor(this) == ViewManager::MeasureMode) { Chris@262: return false; Chris@262: } matthiasm@651: Chris@326: if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) { Chris@326: return false; Chris@326: } Chris@326: Chris@840: if (layer == getInteractionLayer() && Chris@753: !shouldIlluminateLocalSelection(discard, b0, b1)) { Chris@753: Chris@753: pos = m_identifyPoint; Chris@753: return m_identifyFeatures; Chris@127: } Chris@127: Chris@127: return false; Chris@127: } Chris@127: Chris@127: bool Chris@127: Pane::shouldIlluminateLocalSelection(QPoint &pos, Chris@1391: bool &closeToLeft, Chris@1391: bool &closeToRight) const Chris@127: { Chris@127: if (m_identifyFeatures && Chris@731: m_manager && Chris@731: m_manager->getToolModeFor(this) == ViewManager::EditMode && Chris@731: !m_manager->getSelections().empty() && Chris@731: !selectionIsBeingEdited()) { gyorgyf@645: Chris@753: Selection s(getSelectionAt(m_identifyPoint.x(), Chris@753: closeToLeft, closeToRight)); Chris@753: Chris@753: if (!s.isEmpty()) { Chris@840: if (getInteractionLayer() && getInteractionLayer()->isLayerEditable()) { Chris@753: Chris@753: pos = m_identifyPoint; Chris@753: return true; Chris@753: } gyorgyf@645: } gyorgyf@645: } Chris@127: Chris@127: return false; Chris@127: } Chris@127: Chris@127: bool Chris@127: Pane::selectionIsBeingEdited() const Chris@127: { Chris@127: if (!m_editingSelection.isEmpty()) { Chris@966: if (m_mousePos != m_clickPos && Chris@966: getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { Chris@966: return true; Chris@966: } Chris@127: } Chris@127: return false; Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::setCentreLineVisible(bool visible) Chris@127: { Chris@127: m_centreLineVisible = visible; Chris@127: update(); Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::paintEvent(QPaintEvent *e) Chris@127: { Chris@127: // Profiler profiler("Pane::paintEvent", true); Chris@127: Chris@127: QPainter paint; Chris@127: Chris@127: QRect r(rect()); Chris@261: if (e) r = e->rect(); Chris@127: Chris@127: View::paintEvent(e); Chris@127: Chris@127: paint.begin(this); Chris@339: setPaintFont(paint); Chris@338: Chris@261: if (e) paint.setClipRect(r); Chris@127: Chris@854: ViewManager::ToolMode toolMode = ViewManager::NavigateMode; Chris@854: if (m_manager) toolMode = m_manager->getToolModeFor(this); Chris@259: Chris@1239: // Locate some relevant layers and models Chris@1239: Chris@268: Layer *topLayer = getTopLayer(); Chris@277: bool haveSomeTimeXAxis = false; Chris@268: Chris@1475: std::shared_ptr waveformModel; // just for reporting purposes Chris@1475: std::shared_ptr workModel; Chris@326: Chris@835: for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { Chris@127: --vi; Chris@277: if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) { Chris@277: haveSomeTimeXAxis = true; Chris@277: } Chris@1475: auto model = ModelById::get((*vi)->getModel()); Chris@1475: Chris@1475: if (model) { Chris@1475: if (dynamic_cast(*vi)) { Chris@1475: waveformModel = model; Chris@1475: workModel = waveformModel; Chris@1475: } else { Chris@1475: if (std::dynamic_pointer_cast(model)) { Chris@1475: workModel = model; Chris@1475: } else if (auto wm = ModelById::getAs Chris@1475: (model->getSourceModel())) { Chris@1475: workModel = wm; Chris@1475: } Chris@326: } Chris@127: } Chris@326: Chris@326: if (waveformModel && workModel && haveSomeTimeXAxis) break; Chris@258: } Chris@127: Chris@1239: // Block off left and right extents so we can see where the main model ends Chris@1239: Chris@861: if (workModel && hasTopLayerTimeXAxis()) { Chris@1475: drawModelTimeExtents(r, paint, *workModel); Chris@759: } Chris@759: Chris@1239: // Crosshairs for mouse movement in measure mode Chris@1239: Chris@1239: if (m_manager && Chris@1239: m_mouseInWidget && Chris@1239: toolMode == ViewManager::MeasureMode) { Chris@1239: Chris@1239: for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) { Chris@1239: --vi; Chris@1239: Chris@1239: std::vector crosshairExtents; Chris@1239: Chris@1239: if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint, Chris@1239: crosshairExtents)) { Chris@1239: (*vi)->paintCrosshairs(this, paint, m_identifyPoint); Chris@1239: break; Chris@1239: } else if ((*vi)->isLayerOpaque()) { Chris@1239: break; Chris@1239: } Chris@1239: } Chris@1239: } Chris@1239: Chris@1239: // Scale width will be set implicitly during drawVerticalScale call Chris@1239: m_scaleWidth = 0; Chris@1239: Chris@261: if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) { Chris@261: drawVerticalScale(r, topLayer, paint); Chris@261: } Chris@261: Chris@1239: // Feature description: the box in top-right showing values from Chris@1239: // the nearest feature to the mouse Chris@1239: Chris@326: if (m_identifyFeatures && Chris@326: m_manager && m_manager->shouldIlluminateLocalFeatures() && Chris@326: topLayer) { Chris@261: drawFeatureDescription(topLayer, paint); Chris@261: } Chris@261: Chris@908: sv_samplerate_t sampleRate = getModelsSampleRate(); Chris@261: paint.setBrush(Qt::NoBrush); Chris@261: Chris@261: if (m_centreLineVisible && Chris@261: m_manager && Chris@261: m_manager->shouldShowCentreLine()) { Chris@277: drawCentreLine(sampleRate, paint, !haveSomeTimeXAxis); Chris@261: } Chris@261: Chris@261: paint.setPen(QColor(50, 50, 50)); Chris@261: Chris@261: if (waveformModel && Chris@854: sampleRate && Chris@261: m_manager && Chris@261: m_manager->shouldShowDuration()) { Chris@1475: drawDurationAndRate(r, *waveformModel, sampleRate, paint); Chris@261: } Chris@261: Chris@326: bool haveWorkTitle = false; Chris@326: Chris@326: if (workModel && Chris@326: m_manager && Chris@326: m_manager->shouldShowWorkTitle()) { Chris@1475: drawWorkTitle(r, paint, *workModel); Chris@326: haveWorkTitle = true; Chris@326: } Chris@326: Chris@326: if (workModel && Chris@320: m_manager && Chris@320: m_manager->getAlignMode()) { Chris@1475: drawAlignmentStatus(r, paint, *workModel, haveWorkTitle); Chris@320: } Chris@320: Chris@261: if (m_manager && Chris@261: m_manager->shouldShowLayerNames()) { Chris@261: drawLayerNames(r, paint); Chris@261: } Chris@261: Chris@1239: // The blue box that is shown when you ctrl-click in navigate mode Chris@1239: // to define a zoom region Chris@1239: Chris@262: if (m_shiftPressed && m_clickedInRange && Chris@283: (toolMode == ViewManager::NavigateMode || m_navigating)) { Chris@261: Chris@261: //!!! be nice if this looked a bit more in keeping with the Chris@261: //selection block Chris@262: Chris@262: paint.setPen(Qt::blue); Chris@262: //!!! shouldn't use clickPos -- needs to use a clicked frame Chris@262: paint.drawRect(m_clickPos.x(), m_clickPos.y(), Chris@262: m_mousePos.x() - m_clickPos.x(), Chris@262: m_mousePos.y() - m_clickPos.y()); Chris@261: Chris@262: } Chris@261: Chris@266: if (toolMode == ViewManager::MeasureMode && topLayer) { Chris@272: bool showFocus = false; Chris@272: if (!m_manager || !m_manager->isPlaying()) showFocus = true; Chris@272: topLayer->paintMeasurementRects(this, paint, showFocus, m_identifyPoint); Chris@261: } Chris@261: Chris@261: if (selectionIsBeingEdited()) { Chris@261: drawEditingSelection(paint); Chris@261: } Chris@261: Chris@261: paint.end(); Chris@261: } Chris@261: Chris@806: int Chris@276: Pane::getVerticalScaleWidth() const Chris@276: { Chris@276: if (m_scaleWidth > 0) return m_scaleWidth; Chris@276: else return 0; Chris@276: } Chris@276: Chris@261: void Chris@261: Pane::drawVerticalScale(QRect r, Layer *topLayer, QPainter &paint) Chris@261: { Chris@1408: Layer *scaleLayer = nullptr; Chris@258: Chris@1226: // cerr << "Pane::drawVerticalScale[" << this << "]" << endl; Chris@1226: Chris@908: double min, max; Chris@261: bool log; Chris@261: QString unit; Chris@258: Chris@1467: // If the top layer has no scale and reports no display extents, Chris@1467: // but does report a unit, then the scale should be drawn from any Chris@1467: // (visible) underlying layer with a scale and that unit. If the Chris@1467: // top layer has no scale and no value extents at all, then the Chris@1467: // scale should be drawn from any (visible) underlying layer with Chris@1467: // a scale regardless of unit. Chris@258: Chris@607: int sw = topLayer->getVerticalScaleWidth Chris@607: (this, m_manager->shouldShowVerticalColourScale(), paint); Chris@1226: Chris@261: if (sw > 0) { Chris@261: scaleLayer = topLayer; Chris@261: m_scaleWidth = sw; Chris@258: Chris@261: } else { Chris@258: Chris@261: bool hasDisplayExtents = topLayer->getDisplayExtents(min, max); Chris@261: bool hasValueExtents = topLayer->getValueExtents(min, max, log, unit); Chris@261: Chris@261: if (!hasDisplayExtents) { Chris@258: Chris@261: if (!hasValueExtents) { Chris@258: Chris@835: for (LayerList::iterator vi = m_layerStack.end(); Chris@835: vi != m_layerStack.begin(); ) { Chris@261: Chris@261: --vi; Chris@261: Chris@261: if ((*vi) == topLayer) continue; Chris@1467: if ((*vi)->isLayerDormant(this)) continue; Chris@261: Chris@607: sw = (*vi)->getVerticalScaleWidth Chris@607: (this, m_manager->shouldShowVerticalColourScale(), paint); Chris@261: Chris@261: if (sw > 0) { Chris@261: scaleLayer = *vi; Chris@261: m_scaleWidth = sw; Chris@261: break; Chris@261: } Chris@261: } Chris@261: } else if (unit != "") { // && hasValueExtents && !hasDisplayExtents Chris@258: Chris@261: QString requireUnit = unit; Chris@261: Chris@835: for (LayerList::iterator vi = m_layerStack.end(); Chris@835: vi != m_layerStack.begin(); ) { Chris@258: Chris@261: --vi; Chris@258: Chris@261: if ((*vi) == topLayer) continue; Chris@1467: if ((*vi)->isLayerDormant(this)) continue; Chris@258: Chris@261: if ((*vi)->getDisplayExtents(min, max)) { Chris@261: Chris@261: // search no further than this: if the Chris@261: // scale from this layer isn't suitable, Chris@261: // we'll have to draw no scale (else we'd Chris@261: // risk ending up with the wrong scale) Chris@261: Chris@261: if ((*vi)->getValueExtents(min, max, log, unit) && Chris@261: unit == requireUnit) { Chris@261: Chris@607: sw = (*vi)->getVerticalScaleWidth Chris@607: (this, m_manager->shouldShowVerticalColourScale(), paint); Chris@261: if (sw > 0) { Chris@261: scaleLayer = *vi; Chris@261: m_scaleWidth = sw; Chris@261: } Chris@258: } Chris@261: break; Chris@258: } Chris@258: } Chris@258: } Chris@127: } Chris@258: } Chris@127: Chris@258: if (!scaleLayer) m_scaleWidth = 0; Chris@1226: Chris@1226: // cerr << "m_scaleWidth = " << m_scaleWidth << ", r.left = " << r.left() << endl; Chris@1226: Chris@258: if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { Chris@127: gyorgyf@645: // Profiler profiler("Pane::paintEvent - painting vertical scale", true); gyorgyf@645: gyorgyf@645: // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; Chris@258: paint.save(); Chris@258: Chris@1316: paint.setPen(Qt::NoPen); Chris@1316: paint.setBrush(getBackground()); Chris@1316: paint.drawRect(0, 0, m_scaleWidth, height()); Chris@1316: Chris@287: paint.setPen(getForeground()); Chris@1316: paint.drawLine(m_scaleWidth, 0, m_scaleWidth, height()); Chris@1316: Chris@258: paint.setBrush(Qt::NoBrush); Chris@258: scaleLayer->paintVerticalScale Chris@607: (this, m_manager->shouldShowVerticalColourScale(), Chris@607: paint, QRect(0, 0, m_scaleWidth, height())); Chris@258: Chris@258: paint.restore(); Chris@258: } Chris@261: } Chris@261: Chris@261: void Chris@261: Pane::drawFeatureDescription(Layer *topLayer, QPainter &paint) Chris@261: { Chris@261: QPoint pos = m_identifyPoint; Chris@261: QString desc = topLayer->getFeatureDescription(this, pos); gyorgyf@645: Chris@261: if (desc != "") { Chris@261: Chris@261: paint.save(); Chris@261: Chris@1475: // Qt 5.13 deprecates QFontMetrics::width(), but its suggested Chris@1475: // replacement (horizontalAdvance) was only added in Qt 5.11 Chris@1475: // which is too new for us Chris@1475: #pragma GCC diagnostic ignored "-Wdeprecated-declarations" Chris@1475: Chris@261: int tabStop = Chris@261: paint.fontMetrics().width(tr("Some lengthy prefix:")); Chris@261: Chris@261: QRect boundingRect = Chris@261: paint.fontMetrics().boundingRect Chris@261: (rect(), Chris@261: Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs, Chris@261: desc, tabStop); Chris@261: Chris@261: if (hasLightBackground()) { Chris@261: paint.setPen(Qt::NoPen); Chris@261: paint.setBrush(QColor(250, 250, 250, 200)); Chris@261: } else { Chris@261: paint.setPen(Qt::NoPen); Chris@261: paint.setBrush(QColor(50, 50, 50, 200)); Chris@261: } Chris@261: Chris@261: int extra = paint.fontMetrics().descent(); Chris@261: paint.drawRect(width() - boundingRect.width() - 10 - extra, Chris@261: 10 - extra, Chris@261: boundingRect.width() + 2 * extra, Chris@261: boundingRect.height() + extra); Chris@261: Chris@261: if (hasLightBackground()) { Chris@261: paint.setPen(QColor(150, 20, 0)); Chris@261: } else { Chris@261: paint.setPen(QColor(255, 150, 100)); Chris@261: } Chris@261: Chris@261: QTextOption option; Chris@261: option.setWrapMode(QTextOption::NoWrap); Chris@261: option.setAlignment(Qt::AlignRight | Qt::AlignTop); Chris@261: option.setTabStop(tabStop); Chris@261: paint.drawText(QRectF(width() - boundingRect.width() - 10, 10, Chris@261: boundingRect.width(), Chris@261: boundingRect.height()), Chris@261: desc, Chris@261: option); Chris@261: Chris@261: paint.restore(); Chris@261: } Chris@261: } Chris@258: Chris@261: void Chris@908: Pane::drawCentreLine(sv_samplerate_t sampleRate, QPainter &paint, bool omitLine) Chris@261: { Chris@880: if (omitLine && m_manager->getMainModelSampleRate() == 0) { Chris@880: return; Chris@880: } Chris@880: Chris@261: int fontHeight = paint.fontMetrics().height(); Chris@261: int fontAscent = paint.fontMetrics().ascent(); Chris@261: Chris@261: QColor c = QColor(0, 0, 0); Chris@261: if (!hasLightBackground()) { Chris@261: c = QColor(240, 240, 240); Chris@261: } Chris@277: Chris@1401: paint.setPen(scalePen(c)); Chris@274: int x = width() / 2; Chris@277: Chris@277: if (!omitLine) { Chris@277: paint.drawLine(x, 0, x, height() - 1); Chris@277: paint.drawLine(x-1, 1, x+1, 1); Chris@277: paint.drawLine(x-2, 0, x+2, 0); Chris@277: paint.drawLine(x-1, height() - 2, x+1, height() - 2); Chris@277: paint.drawLine(x-2, height() - 1, x+2, height() - 1); Chris@277: } Chris@261: Chris@261: paint.setPen(QColor(50, 50, 50)); Chris@261: Chris@261: int y = height() - fontHeight + fontAscent - 6; Chris@261: Chris@835: LayerList::iterator vi = m_layerStack.end(); Chris@261: Chris@835: if (vi != m_layerStack.begin()) { gyorgyf@645: Chris@261: switch ((*--vi)->getPreferredFrameCountPosition()) { Chris@258: Chris@261: case Layer::PositionTop: Chris@261: y = fontAscent + 6; Chris@261: break; Chris@258: Chris@261: case Layer::PositionMiddle: Chris@261: y = (height() - fontHeight) / 2 Chris@261: + fontAscent; Chris@261: break; Chris@127: Chris@261: case Layer::PositionBottom: Chris@261: // y already set correctly Chris@261: break; Chris@127: } Chris@127: } Chris@127: Chris@261: if (m_manager && m_manager->shouldShowFrameCount()) { Chris@261: Chris@261: if (sampleRate) { Chris@127: Chris@261: QString text(QString::fromStdString Chris@261: (RealTime::frame2RealTime Chris@549: (m_centreFrame, sampleRate) Chris@549: .toText(true))); Chris@127: Chris@261: int tw = paint.fontMetrics().width(text); Chris@261: int x = width()/2 - 4 - tw; Chris@127: Chris@1078: PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); Chris@127: } Chris@261: Chris@261: QString text = QString("%1").arg(m_centreFrame); Chris@261: Chris@261: int x = width()/2 + 4; Chris@261: Chris@1078: PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); Chris@261: } Chris@261: } Chris@127: Chris@261: void Chris@1475: Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model &model) Chris@759: { Chris@759: paint.save(); Chris@1375: Chris@759: QBrush brush; Chris@759: Chris@759: if (hasLightBackground()) { Chris@1269: brush = QBrush(QColor("#aaf8f8f8")); Chris@759: paint.setPen(Qt::black); Chris@759: } else { Chris@1269: brush = QBrush(QColor("#aa101010")); Chris@759: paint.setPen(Qt::white); Chris@759: } Chris@759: Chris@1475: sv_frame_t f0 = model.getStartFrame(); Chris@1375: Chris@1375: if (f0 > getStartFrame() && f0 < getEndFrame()) { Chris@1375: int x0 = getXForFrame(f0); Chris@1375: if (x0 > r.x()) { Chris@1375: paint.fillRect(0, 0, x0, height(), brush); Chris@1375: paint.drawLine(x0, 0, x0, height()); Chris@1375: } Chris@759: } Chris@759: Chris@1475: sv_frame_t f1 = model.getEndFrame(); Chris@1375: Chris@1375: if (f1 > getStartFrame() && f1 < getEndFrame()) { Chris@1375: int x1 = getXForFrame(f1); Chris@1375: if (x1 < r.x() + r.width()) { Chris@1375: paint.fillRect(x1, 0, width() - x1, height(), brush); Chris@1375: paint.drawLine(x1, 0, x1, height()); Chris@1375: } Chris@759: } Chris@759: Chris@759: paint.restore(); Chris@759: } Chris@759: Chris@759: void Chris@1475: Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model &model, Chris@326: bool down) Chris@320: { Chris@1475: ModelId reference = model.getAlignmentReference(); Chris@320: /* Chris@320: if (!reference) { Chris@682: cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl; Chris@1475: } else if (reference == model.getId()) { Chris@682: cerr << "Pane[" << this << "]::drawAlignmentStatus: This is the reference model" << endl; Chris@320: } else { Chris@682: cerr << "Pane[" << this << "]::drawAlignmentStatus: This is not the reference" << endl; Chris@320: } Chris@320: */ Chris@320: QString text; Chris@320: int completion = 100; Chris@320: Chris@1475: if (reference == model.getId()) { Chris@320: text = tr("Reference"); Chris@1475: } else if (reference.isNone()) { Chris@320: text = tr("Unaligned"); Chris@320: } else { Chris@1475: completion = model.getAlignmentCompletion(); Chris@320: if (completion == 0) { Chris@320: text = tr("Unaligned"); Chris@320: } else if (completion < 100) { Chris@320: text = tr("Aligning: %1%").arg(completion); Chris@320: } else { Chris@320: text = tr("Aligned"); Chris@320: } Chris@320: } Chris@320: Chris@320: paint.save(); Chris@320: QFont font(paint.font()); Chris@320: font.setBold(true); Chris@320: paint.setFont(font); Chris@326: if (completion < 100) paint.setBrush(Qt::red); Chris@326: Chris@326: int y = 5; Chris@326: if (down) y += paint.fontMetrics().height(); Chris@326: int w = paint.fontMetrics().width(text); Chris@326: int h = paint.fontMetrics().height(); Chris@326: if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) { Chris@326: paint.restore(); Chris@326: return; Chris@326: } Chris@320: Chris@1078: PaintAssistant::drawVisibleText(this, paint, m_scaleWidth + 5, Chris@1078: paint.fontMetrics().ascent() + y, text, PaintAssistant::OutlinedText); Chris@320: Chris@320: paint.restore(); Chris@320: } Chris@320: Chris@320: void Chris@320: Pane::modelAlignmentCompletionChanged() Chris@320: { Chris@320: View::modelAlignmentCompletionChanged(); Chris@320: update(QRect(0, 0, 300, 100)); Chris@320: } Chris@320: Chris@320: void Chris@1475: Pane::drawWorkTitle(QRect r, QPainter &paint, const Model &model) Chris@326: { Chris@1475: QString title = model.getTitle(); Chris@1475: QString maker = model.getMaker(); Chris@587: //SVDEBUG << "Pane::drawWorkTitle: title=\"" << title//<< "\", maker=\"" << maker << "\"" << endl; Chris@326: if (title == "") return; Chris@326: Chris@326: QString text = title; Chris@326: if (maker != "") { Chris@326: text = tr("%1 - %2").arg(title).arg(maker); Chris@326: } Chris@326: Chris@326: paint.save(); Chris@326: QFont font(paint.font()); Chris@326: font.setItalic(true); Chris@326: paint.setFont(font); Chris@326: Chris@326: int y = 5; Chris@326: int w = paint.fontMetrics().width(text); Chris@326: int h = paint.fontMetrics().height(); Chris@326: if (r.top() > h + y || r.left() > w + m_scaleWidth + 5) { Chris@326: paint.restore(); Chris@326: return; Chris@326: } Chris@326: Chris@1078: PaintAssistant::drawVisibleText(this, paint, m_scaleWidth + 5, Chris@1078: paint.fontMetrics().ascent() + y, text, PaintAssistant::OutlinedText); Chris@326: Chris@326: paint.restore(); Chris@326: } Chris@326: Chris@326: void Chris@261: Pane::drawLayerNames(QRect r, QPainter &paint) Chris@261: { Chris@261: int fontHeight = paint.fontMetrics().height(); Chris@261: int fontAscent = paint.fontMetrics().ascent(); Chris@127: Chris@300: int lly = height() - 6; Chris@1397: Chris@1397: int zoomWheelSkip = 0, horizontalScaleSkip = 0; Chris@1397: Chris@300: if (m_manager->getZoomWheelsEnabled()) { Chris@1397: zoomWheelSkip = m_manager->scalePixelSize(20); Chris@300: } Chris@300: Chris@1390: for (LayerList::iterator i = m_layerStack.end(); i != m_layerStack.begin();) { Chris@1390: --i; Chris@1397: horizontalScaleSkip = (*i)->getHorizontalScaleHeight(this, paint); Chris@1397: if (horizontalScaleSkip > 0) { Chris@1390: break; Chris@1390: } Chris@1390: if ((*i)->isLayerOpaque()) { Chris@1390: break; Chris@1390: } Chris@1390: } Chris@1397: Chris@1397: lly -= std::max(zoomWheelSkip, horizontalScaleSkip); Chris@1390: Chris@835: if (r.y() + r.height() < lly - int(m_layerStack.size()) * fontHeight) { Chris@261: return; Chris@127: } Chris@127: Chris@294: QStringList texts; Chris@299: std::vector pixmaps; Chris@835: for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { Chris@294: texts.push_back((*i)->getLayerPresentationName()); Chris@682: // cerr << "Pane " << this << ": Layer presentation name for " << *i << ": " Chris@682: // << texts[texts.size()-1] << endl; Chris@299: pixmaps.push_back((*i)->getLayerPresentationPixmap Chris@299: (QSize(fontAscent, fontAscent))); Chris@294: } Chris@127: Chris@294: int maxTextWidth = width() / 3; Chris@294: texts = TextAbbrev::abbreviate(texts, paint.fontMetrics(), maxTextWidth); Chris@294: Chris@261: int llx = width() - maxTextWidth - 5; Chris@261: if (m_manager->getZoomWheelsEnabled()) { Chris@1193: llx -= m_manager->scalePixelSize(36); Chris@261: } Chris@261: Chris@300: if (r.x() + r.width() >= llx - fontAscent - 3) { gyorgyf@645: Chris@802: for (int i = 0; i < texts.size(); ++i) { Chris@299: Chris@682: // cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << endl; Chris@261: Chris@261: if (i + 1 == texts.size()) { Chris@287: paint.setPen(getForeground()); Chris@261: } Chris@261: Chris@1078: PaintAssistant::drawVisibleText(this, paint, llx, Chris@261: lly - fontHeight + fontAscent, Chris@1078: texts[i], PaintAssistant::OutlinedText); Chris@299: Chris@299: if (!pixmaps[i].isNull()) { Chris@299: paint.drawPixmap(llx - fontAscent - 3, Chris@299: lly - fontHeight + (fontHeight-fontAscent)/2, Chris@299: pixmaps[i]); Chris@299: } Chris@261: Chris@261: lly -= fontHeight; Chris@261: } Chris@261: } Chris@261: } Chris@127: Chris@261: void Chris@261: Pane::drawEditingSelection(QPainter &paint) Chris@261: { Chris@261: int offset = m_mousePos.x() - m_clickPos.x(); Chris@577: Chris@908: sv_frame_t origStart = m_editingSelection.getStartFrame(); Chris@577: Chris@577: int p0 = getXForFrame(origStart) + offset; Chris@261: int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; Chris@577: Chris@261: if (m_editingSelectionEdge < 0) { Chris@261: p1 = getXForFrame(m_editingSelection.getEndFrame()); Chris@261: } else if (m_editingSelectionEdge > 0) { Chris@261: p0 = getXForFrame(m_editingSelection.getStartFrame()); Chris@127: } Chris@127: Chris@908: sv_frame_t newStart = getFrameForX(p0); Chris@908: sv_frame_t newEnd = getFrameForX(p1); Chris@577: Chris@261: paint.save(); Chris@287: paint.setPen(QPen(getForeground(), 2)); Chris@577: Chris@577: int fontHeight = paint.fontMetrics().height(); Chris@577: int fontAscent = paint.fontMetrics().ascent(); Chris@908: sv_samplerate_t sampleRate = getModelsSampleRate(); Chris@577: QString startText, endText, offsetText; Chris@577: startText = QString("%1").arg(newStart); Chris@577: endText = QString("%1").arg(newEnd); Chris@577: offsetText = QString("%1").arg(newStart - origStart); Chris@577: if (newStart >= origStart) { Chris@577: offsetText = tr("+%1").arg(offsetText); Chris@577: } Chris@577: if (sampleRate) { Chris@577: startText = QString("%1 / %2") Chris@577: .arg(QString::fromStdString Chris@577: (RealTime::frame2RealTime(newStart, sampleRate).toText())) Chris@577: .arg(startText); Chris@577: endText = QString("%1 / %2") Chris@577: .arg(QString::fromStdString Chris@577: (RealTime::frame2RealTime(newEnd, sampleRate).toText())) Chris@577: .arg(endText); Chris@577: offsetText = QString("%1 / %2") Chris@577: .arg(QString::fromStdString Chris@577: (RealTime::frame2RealTime(newStart - origStart, sampleRate).toText())) Chris@577: .arg(offsetText); Chris@577: if (newStart >= origStart) { Chris@577: offsetText = tr("+%1").arg(offsetText); Chris@577: } Chris@577: } Chris@1078: PaintAssistant::drawVisibleText(this, paint, p0 + 2, fontAscent + fontHeight + 4, startText, PaintAssistant::OutlinedText); Chris@1078: PaintAssistant::drawVisibleText(this, paint, p1 + 2, fontAscent + fontHeight + 4, endText, PaintAssistant::OutlinedText); Chris@1078: PaintAssistant::drawVisibleText(this, paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, PaintAssistant::OutlinedText); Chris@1078: PaintAssistant::drawVisibleText(this, paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, PaintAssistant::OutlinedText); Chris@261: Chris@261: //!!! duplicating display policy with View::drawSelections Chris@261: Chris@261: if (m_editingSelectionEdge < 0) { Chris@261: paint.drawLine(p0, 1, p1, 1); Chris@261: paint.drawLine(p0, 0, p0, height()); Chris@261: paint.drawLine(p0, height() - 1, p1, height() - 1); Chris@261: } else if (m_editingSelectionEdge > 0) { Chris@261: paint.drawLine(p0, 1, p1, 1); Chris@261: paint.drawLine(p1, 0, p1, height()); Chris@261: paint.drawLine(p0, height() - 1, p1, height() - 1); Chris@261: } else { Chris@261: paint.setBrush(Qt::NoBrush); Chris@261: paint.drawRect(p0, 1, p1 - p0, height() - 2); Chris@261: } Chris@261: paint.restore(); Chris@261: } Chris@127: Chris@261: void Chris@1475: Pane::drawDurationAndRate(QRect r, const Model &waveformModel, Chris@908: sv_samplerate_t sampleRate, QPainter &paint) Chris@261: { Chris@261: int fontHeight = paint.fontMetrics().height(); Chris@261: int fontAscent = paint.fontMetrics().ascent(); Chris@127: Chris@261: if (r.y() + r.height() < height() - fontHeight - 6) return; Chris@127: Chris@1475: sv_samplerate_t modelRate = waveformModel.getSampleRate(); Chris@1475: sv_samplerate_t nativeRate = waveformModel.getNativeRate(); Chris@908: sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); Chris@261: Chris@261: QString srNote = ""; Chris@127: Chris@1181: // Show (R) for waveform models that have been resampled during Chris@1181: // load, and (X) for waveform models that will be played at the Chris@1181: // wrong rate because their rate differs from the current playback Chris@1181: // rate (which is not necessarily that of the main model). Chris@1181: Chris@1181: if (modelRate != nativeRate) { Chris@1181: if (playbackRate != 0 && modelRate != playbackRate) { Chris@261: srNote = " " + tr("(X)"); Chris@1181: } else { Chris@1181: srNote = " " + tr("(R)"); Chris@261: } Chris@127: } Chris@127: Chris@261: QString desc = tr("%1 / %2Hz%3") Chris@1475: .arg(RealTime::frame2RealTime(waveformModel.getEndFrame(), Chris@261: sampleRate) Chris@261: .toText(false).c_str()) Chris@301: .arg(nativeRate) Chris@261: .arg(srNote); Chris@261: Chris@384: int x = m_scaleWidth + 5; Chris@384: int pbw = getProgressBarWidth(); Chris@384: if (x < pbw + 5) x = pbw + 5; Chris@384: Chris@384: if (r.x() < x + paint.fontMetrics().width(desc)) { Chris@1078: PaintAssistant::drawVisibleText(this, paint, x, Chris@261: height() - fontHeight + fontAscent - 6, Chris@1078: desc, PaintAssistant::OutlinedText); Chris@261: } Chris@127: } Chris@127: Chris@227: bool Chris@908: Pane::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1) Chris@227: { Chris@229: if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) { Chris@227: return false; Chris@227: } Chris@227: Chris@227: if (m_scaleWidth > 0) { Chris@227: Chris@854: Layer *layer = getTopLayer(); Chris@854: Chris@854: if (layer) { Chris@227: Chris@227: paint.save(); Chris@227: Chris@287: paint.setPen(getForeground()); Chris@287: paint.setBrush(getBackground()); Chris@229: paint.drawRect(xorigin, -1, m_scaleWidth, height()+1); Chris@227: Chris@227: paint.setBrush(Qt::NoBrush); Chris@854: layer->paintVerticalScale Chris@607: (this, m_manager->shouldShowVerticalColourScale(), Chris@607: paint, QRect(xorigin, 0, m_scaleWidth, height())); Chris@227: Chris@227: paint.restore(); Chris@227: } Chris@227: } Chris@227: Chris@227: return true; Chris@227: } Chris@227: Chris@227: QImage * Chris@1202: Pane::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1) Chris@227: { Chris@1326: int x0 = int(round(getZoomLevel().framesToPixels(double(f0)))); Chris@1326: int x1 = int(round(getZoomLevel().framesToPixels(double(f1)))); Chris@227: Chris@227: QImage *image = new QImage(x1 - x0 + m_scaleWidth, Chris@227: height(), QImage::Format_RGB32); Chris@227: Chris@227: int formerScaleWidth = m_scaleWidth; Chris@227: Chris@227: if (m_manager && m_manager->shouldShowVerticalScale()) { Chris@854: Layer *layer = getTopLayer(); Chris@854: if (layer) { Chris@227: QPainter paint(image); Chris@854: m_scaleWidth = layer->getVerticalScaleWidth Chris@607: (this, m_manager->shouldShowVerticalColourScale(), paint); Chris@227: } Chris@227: } else { Chris@227: m_scaleWidth = 0; Chris@227: } Chris@227: Chris@227: if (m_scaleWidth != formerScaleWidth) { Chris@227: delete image; Chris@227: image = new QImage(x1 - x0 + m_scaleWidth, Chris@227: height(), QImage::Format_RGB32); Chris@227: } Chris@227: Chris@227: QPainter *paint = new QPainter(image); Chris@229: if (!render(*paint, 0, f0, f1)) { Chris@227: delete paint; Chris@227: delete image; Chris@1408: return nullptr; Chris@227: } else { Chris@227: delete paint; Chris@227: return image; Chris@227: } Chris@227: } Chris@227: Chris@229: QSize Chris@1202: Pane::getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1) Chris@229: { Chris@1202: QSize s = View::getRenderedPartImageSize(f0, f1); Chris@229: QImage *image = new QImage(100, 100, QImage::Format_RGB32); Chris@229: QPainter paint(image); Chris@229: Chris@229: int sw = 0; Chris@229: if (m_manager && m_manager->shouldShowVerticalScale()) { Chris@854: Layer *layer = getTopLayer(); Chris@854: if (layer) { Chris@854: sw = layer->getVerticalScaleWidth Chris@607: (this, m_manager->shouldShowVerticalColourScale(), paint); Chris@229: } Chris@229: } Chris@229: Chris@229: return QSize(sw + s.width(), s.height()); Chris@229: } Chris@229: Chris@908: sv_frame_t Chris@222: Pane::getFirstVisibleFrame() const Chris@222: { Chris@908: sv_frame_t f0 = getFrameForX(m_scaleWidth); Chris@908: sv_frame_t f = View::getFirstVisibleFrame(); Chris@908: if (f0 < 0 || f0 < f) return f; Chris@222: return f0; Chris@222: } Chris@222: Chris@127: Selection Chris@127: Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) const Chris@127: { Chris@127: closeToLeftEdge = closeToRightEdge = false; Chris@127: Chris@127: if (!m_manager) return Selection(); Chris@127: Chris@1402: sv_frame_t testFrame = getFrameForX(x - scalePixelSize(5)); Chris@127: if (testFrame < 0) { Chris@908: testFrame = getFrameForX(x); Chris@908: if (testFrame < 0) return Selection(); Chris@127: } Chris@127: Chris@127: Selection selection = m_manager->getContainingSelection(testFrame, true); Chris@127: if (selection.isEmpty()) return selection; Chris@127: Chris@127: int lx = getXForFrame(selection.getStartFrame()); Chris@127: int rx = getXForFrame(selection.getEndFrame()); Chris@127: Chris@1402: int fuzz = scalePixelSize(2); Chris@127: if (x < lx - fuzz || x > rx + fuzz) return Selection(); Chris@127: Chris@127: int width = rx - lx; Chris@1402: fuzz = scalePixelSize(3); Chris@127: if (width < 12) fuzz = width / 4; Chris@1402: if (fuzz < scalePixelSize(1)) { Chris@1402: fuzz = scalePixelSize(1); Chris@1270: } Chris@127: Chris@127: if (x < lx + fuzz) closeToLeftEdge = true; Chris@127: if (x > rx - fuzz) closeToRightEdge = true; Chris@127: Chris@127: return selection; Chris@127: } Chris@127: Chris@174: bool Chris@174: Pane::canTopLayerMoveVertical() Chris@174: { Chris@908: double vmin, vmax, dmin, dmax; Chris@174: if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false; Chris@174: if (dmin <= vmin && dmax >= vmax) return false; Chris@174: return true; Chris@174: } Chris@174: Chris@174: bool Chris@908: Pane::getTopLayerDisplayExtents(double &vmin, double &vmax, Chris@908: double &dmin, double &dmax, Chris@188: QString *unit) Chris@174: { Chris@268: Layer *layer = getTopLayer(); Chris@174: if (!layer) return false; Chris@174: bool vlog; Chris@174: QString vunit; Chris@188: bool rv = (layer->getValueExtents(vmin, vmax, vlog, vunit) && Chris@188: layer->getDisplayExtents(dmin, dmax)); Chris@188: if (unit) *unit = vunit; Chris@188: return rv; Chris@174: } Chris@174: Chris@174: bool Chris@908: Pane::setTopLayerDisplayExtents(double dmin, double dmax) Chris@174: { Chris@268: Layer *layer = getTopLayer(); Chris@174: if (!layer) return false; Chris@174: return layer->setDisplayExtents(dmin, dmax); Chris@174: } Chris@174: Chris@127: void Chris@282: Pane::registerShortcuts(KeyReference &kr) Chris@282: { Chris@282: kr.setCategory(tr("Zoom")); Chris@282: kr.registerAlternativeShortcut(tr("Zoom In"), tr("Wheel Up")); Chris@282: kr.registerAlternativeShortcut(tr("Zoom Out"), tr("Wheel Down")); Chris@282: Chris@282: kr.setCategory(tr("General Pane Mouse Actions")); Chris@282: Chris@282: kr.registerShortcut(tr("Zoom"), tr("Wheel"), Chris@282: tr("Zoom in or out in time axis")); Chris@408: kr.registerShortcut(tr("Scroll"), tr("Ctrl+Wheel"), Chris@282: tr("Scroll rapidly left or right in time axis")); Chris@282: kr.registerShortcut(tr("Zoom Vertically"), tr("Shift+Wheel"), Chris@282: tr("Zoom in or out in the vertical axis")); Chris@282: kr.registerShortcut(tr("Scroll Vertically"), tr("Alt+Wheel"), Chris@282: tr("Scroll up or down in the vertical axis")); Chris@282: kr.registerShortcut(tr("Navigate"), tr("Middle"), Chris@282: tr("Click middle button and drag to navigate with any tool")); Chris@282: kr.registerShortcut(tr("Relocate"), tr("Double-Click Middle"), Chris@282: tr("Double-click middle button to relocate with any tool")); Chris@282: kr.registerShortcut(tr("Menu"), tr("Right"), Chris@282: tr("Show pane context menu")); Chris@282: } Chris@282: Chris@753: Layer * Chris@753: Pane::getTopFlexiNoteLayer() Chris@753: { Chris@835: for (int i = int(m_layerStack.size()) - 1; i >= 0; --i) { Chris@835: if (LayerFactory::getInstance()->getLayerType(m_layerStack[i]) == Chris@753: LayerFactory::FlexiNotes) { Chris@835: return m_layerStack[i]; Chris@753: } Chris@753: } Chris@1408: return nullptr; Chris@753: } Chris@753: Chris@282: void Chris@127: Pane::mousePressEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@189: emit contextHelpChanged(""); Chris@127: emit rightButtonMenuRequested(mapToGlobal(e->pos())); Chris@127: return; Chris@127: } Chris@127: Chris@682: // cerr << "mousePressEvent" << endl; Chris@341: Chris@127: m_clickPos = e->pos(); Chris@262: m_mousePos = m_clickPos; Chris@127: m_clickedInRange = true; Chris@127: m_editingSelection = Selection(); Chris@127: m_editingSelectionEdge = 0; Chris@127: m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); Chris@127: m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); Chris@510: m_altPressed = (e->modifiers() & Qt::AltModifier); Chris@150: m_dragMode = UnresolvedDrag; Chris@127: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@711: if (m_manager) mode = m_manager->getToolModeFor(this); Chris@127: Chris@127: m_navigating = false; Chris@343: m_resizing = false; Chris@343: m_editing = false; Chris@343: m_releasing = false; Chris@127: Chris@283: if (mode == ViewManager::NavigateMode || Chris@283: (e->buttons() & Qt::MidButton) || Chris@283: (mode == ViewManager::MeasureMode && Chris@283: (e->buttons() & Qt::LeftButton) && m_shiftPressed)) { Chris@127: Chris@713: if (mode != ViewManager::NavigateMode) { Chris@713: setCursor(Qt::PointingHandCursor); Chris@713: } Chris@713: Chris@713: m_navigating = true; Chris@713: m_dragCentreFrame = m_centreFrame; Chris@136: m_dragStartMinValue = 0; Chris@174: Chris@908: double vmin, vmax, dmin, dmax; Chris@174: if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { Chris@174: m_dragStartMinValue = dmin; Chris@136: } Chris@136: Chris@829: if (m_followPlay == PlaybackScrollPage) { Chris@829: // Schedule a play-head move to the mouse frame Chris@829: // location. This will happen only if nothing else of Chris@829: // interest happens (double-click, drag) before the Chris@829: // timeout. Chris@829: schedulePlaybackFrameMove(getFrameForX(e->x())); Chris@829: } Chris@802: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@217: if (!hasTopLayerTimeXAxis()) return; Chris@217: Chris@713: bool closeToLeft = false, closeToRight = false; Chris@713: Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); Chris@713: Chris@713: if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { Chris@713: Chris@713: m_manager->removeSelection(selection); Chris@713: Chris@713: if (closeToLeft) { Chris@713: m_selectionStartFrame = selection.getEndFrame(); Chris@713: } else { Chris@713: m_selectionStartFrame = selection.getStartFrame(); Chris@713: } Chris@713: Chris@713: m_manager->setInProgressSelection(selection, false); Chris@713: m_resizing = true; Chris@713: gyorgyf@645: } else { Chris@713: Chris@908: sv_frame_t mouseFrame = getFrameForX(e->x()); Chris@806: int resolution = 1; Chris@908: sv_frame_t snapFrame = mouseFrame; gyorgyf@645: Chris@840: Layer *layer = getInteractionLayer(); Chris@928: if (layer && !m_shiftPressed && Chris@928: !qobject_cast(layer)) { // don't snap to secs Chris@713: layer->snapToFeatureFrame(this, snapFrame, Chris@713: resolution, Layer::SnapLeft); Chris@713: } gyorgyf@645: Chris@713: if (snapFrame < 0) snapFrame = 0; Chris@713: m_selectionStartFrame = snapFrame; Chris@713: if (m_manager) { Chris@713: m_manager->setInProgressSelection Chris@333: (Selection(alignToReference(snapFrame), Chris@333: alignToReference(snapFrame + resolution)), Chris@333: !m_ctrlPressed); Chris@713: } Chris@713: Chris@713: m_resizing = false; Chris@802: Chris@829: if (m_followPlay == PlaybackScrollPage) { Chris@829: // Schedule a play-head move to the mouse frame Chris@829: // location. This will happen only if nothing else of Chris@829: // interest happens (double-click, drag) before the Chris@829: // timeout. Chris@829: schedulePlaybackFrameMove(mouseFrame); Chris@829: } gyorgyf@645: } gyorgyf@645: Chris@713: update(); Chris@127: Chris@127: } else if (mode == ViewManager::DrawMode) { Chris@127: Chris@840: Layer *layer = getInteractionLayer(); Chris@713: if (layer && layer->isLayerEditable()) { Chris@713: layer->drawStart(this, e); Chris@713: } Chris@127: Chris@335: } else if (mode == ViewManager::EraseMode) { Chris@335: Chris@840: Layer *layer = getInteractionLayer(); Chris@713: if (layer && layer->isLayerEditable()) { Chris@713: layer->eraseStart(this, e); Chris@713: } Chris@713: Chris@713: // GF: handle mouse press for NoteEditMode gyorgyf@645: } else if (mode == ViewManager::NoteEditMode) { gyorgyf@645: gyorgyf@645: std::cerr << "mouse pressed in note edit mode" << std::endl; Chris@753: Layer *layer = getTopFlexiNoteLayer(); Chris@753: if (layer) { gyorgyf@635: layer->splitStart(this, e); gyorgyf@635: } Chris@335: Chris@127: } else if (mode == ViewManager::EditMode) { Chris@127: Chris@343: // Do nothing here -- we'll do it in mouseMoveEvent when the Chris@343: // drag threshold has been passed Chris@262: Chris@262: } else if (mode == ViewManager::MeasureMode) { Chris@262: Chris@268: Layer *layer = getTopLayer(); Chris@267: if (layer) layer->measureStart(this, e); Chris@262: update(); Chris@127: } Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@127: void Chris@908: Pane::schedulePlaybackFrameMove(sv_frame_t frame) Chris@802: { Chris@802: m_playbackFrameMoveTo = frame; Chris@802: m_playbackFrameMoveScheduled = true; Chris@802: QTimer::singleShot(QApplication::doubleClickInterval() + 10, this, Chris@802: SLOT(playbackScheduleTimerElapsed())); Chris@802: } Chris@802: Chris@802: void Chris@802: Pane::playbackScheduleTimerElapsed() Chris@802: { Chris@802: if (m_playbackFrameMoveScheduled) { Chris@802: m_manager->setPlaybackFrame(m_playbackFrameMoveTo); Chris@802: m_playbackFrameMoveScheduled = false; Chris@802: } Chris@802: } Chris@802: Chris@802: void Chris@127: Pane::mouseReleaseEvent(QMouseEvent *e) Chris@127: { Chris@854: if (e && (e->buttons() & Qt::RightButton)) { Chris@127: return; Chris@127: } Chris@127: Chris@682: // cerr << "mouseReleaseEvent" << endl; Chris@341: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@711: if (m_manager) mode = m_manager->getToolModeFor(this); Chris@127: Chris@343: m_releasing = true; Chris@343: Chris@127: if (m_clickedInRange) { Chris@713: mouseMoveEvent(e); Chris@127: } Chris@127: Chris@908: sv_frame_t mouseFrame = e ? getFrameForX(e->x()) : 0; Chris@802: if (mouseFrame < 0) mouseFrame = 0; Chris@790: Chris@127: if (m_navigating || mode == ViewManager::NavigateMode) { Chris@127: Chris@713: m_navigating = false; Chris@713: Chris@713: if (mode != ViewManager::NavigateMode) { Chris@713: // restore cursor Chris@713: toolModeChanged(); Chris@713: } Chris@713: Chris@713: if (m_shiftPressed) { Chris@713: Chris@713: int x0 = std::min(m_clickPos.x(), m_mousePos.x()); Chris@713: int x1 = std::max(m_clickPos.x(), m_mousePos.x()); Chris@713: Chris@713: int y0 = std::min(m_clickPos.y(), m_mousePos.y()); Chris@713: int y1 = std::max(m_clickPos.y(), m_mousePos.y()); Chris@127: Chris@730: emit regionOutlined(QRect(x0, y0, x1 - x0, y1 - y0)); Chris@713: } Chris@127: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@343: if (!hasTopLayerTimeXAxis()) { Chris@343: m_releasing = false; Chris@343: return; Chris@343: } Chris@217: Chris@713: if (m_manager && m_manager->haveInProgressSelection()) { Chris@713: justin@726: //cerr << "JTEST: release with selection" << endl; Chris@713: bool exclusive; Chris@713: Selection selection = m_manager->getInProgressSelection(exclusive); gyorgyf@645: Chris@713: if (selection.getEndFrame() < selection.getStartFrame() + 2) { Chris@713: selection = Selection(); Chris@713: } Chris@713: Chris@713: m_manager->clearInProgressSelection(); Chris@713: Chris@713: if (exclusive) { Chris@713: m_manager->setSelection(selection); Chris@713: } else { Chris@713: m_manager->addSelection(selection); Chris@713: } justin@726: } Chris@713: Chris@713: update(); Chris@713: Chris@713: } else if (mode == ViewManager::DrawMode) { Chris@713: Chris@840: Layer *layer = getInteractionLayer(); Chris@713: if (layer && layer->isLayerEditable()) { Chris@713: layer->drawEnd(this, e); Chris@713: update(); gyorgyf@645: } Chris@127: Chris@335: } else if (mode == ViewManager::EraseMode) { Chris@335: Chris@840: Layer *layer = getInteractionLayer(); gyorgyf@645: if (layer && layer->isLayerEditable()) { gyorgyf@645: layer->eraseEnd(this, e); gyorgyf@645: update(); gyorgyf@645: } gyorgyf@645: gyorgyf@645: } else if (mode == ViewManager::NoteEditMode) { gyorgyf@645: gyorgyf@645: //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later) Chris@753: Layer *layer = getTopFlexiNoteLayer(); Chris@753: Chris@753: if (layer) { gyorgyf@635: layer->splitEnd(this, e); Chris@753: update(); Chris@753: Chris@753: if (m_editing) { Chris@753: if (!editSelectionEnd(e)) { Chris@753: layer->editEnd(this, e); Chris@753: update(); Chris@753: } Chris@753: } Chris@753: } Chris@753: Chris@753: } else if (mode == ViewManager::EditMode) { Chris@753: Chris@343: if (m_editing) { Chris@343: if (!editSelectionEnd(e)) { Chris@840: Layer *layer = getInteractionLayer(); Chris@343: if (layer && layer->isLayerEditable()) { Chris@343: layer->editEnd(this, e); Chris@343: update(); Chris@343: } Chris@343: } gyorgyf@635: } Chris@607: Chris@262: } else if (mode == ViewManager::MeasureMode) { Chris@262: Chris@268: Layer *layer = getTopLayer(); Chris@267: if (layer) layer->measureEnd(this, e); Chris@267: if (m_measureCursor1) setCursor(*m_measureCursor1); Chris@267: update(); Chris@127: } Chris@127: Chris@127: m_clickedInRange = false; Chris@343: m_releasing = false; Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::mouseMoveEvent(QMouseEvent *e) Chris@127: { Chris@854: if (!e || (e->buttons() & Qt::RightButton)) { Chris@127: return; Chris@127: } Chris@127: Chris@682: // cerr << "mouseMoveEvent" << endl; Chris@341: Chris@616: QPoint pos = e->pos(); Chris@616: updateContextHelp(&pos); Chris@189: Chris@343: if (m_navigating && m_clickedInRange && !m_releasing) { Chris@343: Chris@343: // if no buttons pressed, and not called from Chris@343: // mouseReleaseEvent, we want to reset clicked-ness (to avoid Chris@343: // annoying continual drags when we moved the mouse outside Chris@343: // the window after pressing button first time). Chris@343: Chris@343: if (!(e->buttons() & Qt::LeftButton) && Chris@343: !(e->buttons() & Qt::MidButton)) { Chris@343: m_clickedInRange = false; Chris@343: return; Chris@343: } Chris@343: } Chris@343: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@711: if (m_manager) mode = m_manager->getToolModeFor(this); Chris@127: Chris@127: QPoint prevPoint = m_identifyPoint; Chris@127: m_identifyPoint = e->pos(); Chris@127: Chris@127: if (!m_clickedInRange) { gyorgyf@645: gyorgyf@646: // GF: handle mouse move for context sensitive cursor switching in NoteEditMode. gyorgyf@646: // 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: if (mode == ViewManager::NoteEditMode) { Chris@753: FlexiNoteLayer *layer = qobject_cast(getTopFlexiNoteLayer()); Chris@753: if (layer) { Chris@753: layer->mouseMoveEvent(this, e); //!!! ew matthiasm@785: update(); matthiasm@785: // return; Chris@753: } gyorgyf@646: } gyorgyf@646: gyorgyf@646: if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { gyorgyf@646: bool closeToLeft = false, closeToRight = false; gyorgyf@646: getSelectionAt(e->x(), closeToLeft, closeToRight); gyorgyf@646: if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { gyorgyf@646: setCursor(Qt::SizeHorCursor); gyorgyf@646: } else { gyorgyf@646: setCursor(Qt::ArrowCursor); gyorgyf@646: } gyorgyf@645: } Chris@127: Chris@854: if (m_manager && !m_manager->isPlaying()) { Chris@127: Chris@272: bool updating = false; Chris@272: Chris@840: if (getInteractionLayer() && Chris@326: m_manager->shouldIlluminateLocalFeatures()) { Chris@127: Chris@174: bool previouslyIdentifying = m_identifyFeatures; Chris@174: m_identifyFeatures = true; Chris@174: Chris@174: if (m_identifyFeatures != previouslyIdentifying || Chris@174: m_identifyPoint != prevPoint) { Chris@174: update(); Chris@272: updating = true; Chris@272: } Chris@272: } Chris@272: Chris@854: if (!updating && mode == ViewManager::MeasureMode) { Chris@272: Chris@272: Layer *layer = getTopLayer(); Chris@272: if (layer && layer->nearestMeasurementRectChanged Chris@272: (this, prevPoint, m_identifyPoint)) { Chris@272: update(); Chris@174: } Chris@174: } Chris@127: } Chris@127: Chris@713: return; Chris@127: } Chris@127: Chris@127: if (m_navigating || mode == ViewManager::NavigateMode) { Chris@127: Chris@713: if (m_shiftPressed) { Chris@713: Chris@713: m_mousePos = e->pos(); Chris@713: update(); Chris@713: Chris@713: } else { Chris@127: Chris@174: dragTopLayer(e); Chris@150: } Chris@127: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@713: if (!hasTopLayerTimeXAxis()) return; Chris@713: Chris@713: dragExtendSelection(e); Chris@127: Chris@127: } else if (mode == ViewManager::DrawMode) { Chris@127: Chris@840: Layer *layer = getInteractionLayer(); gyorgyf@649: if (layer && layer->isLayerEditable()) { gyorgyf@649: layer->drawDrag(this, e); gyorgyf@649: } Chris@127: Chris@335: } else if (mode == ViewManager::EraseMode) { Chris@335: Chris@840: Layer *layer = getInteractionLayer(); gyorgyf@649: if (layer && layer->isLayerEditable()) { gyorgyf@649: layer->eraseDrag(this, e); gyorgyf@649: } gyorgyf@649: Chris@713: // GF: handling NoteEditMode dragging and boundary actions for mouseMoveEvent gyorgyf@649: } else if (mode == ViewManager::NoteEditMode) { gyorgyf@649: gyorgyf@649: bool resist = true; gyorgyf@649: gyorgyf@649: if ((e->modifiers() & Qt::ShiftModifier)) { gyorgyf@649: m_shiftPressed = true; gyorgyf@649: } gyorgyf@649: gyorgyf@649: if (m_shiftPressed) resist = false; gyorgyf@649: gyorgyf@649: m_dragMode = updateDragMode gyorgyf@649: (m_dragMode, gyorgyf@649: m_clickPos, gyorgyf@649: e->pos(), gyorgyf@649: true, // can move horiz gyorgyf@649: true, // can move vert gyorgyf@649: resist, // resist horiz gyorgyf@649: resist); // resist vert gyorgyf@649: gyorgyf@649: if (!m_editing) { gyorgyf@649: gyorgyf@649: if (m_dragMode != UnresolvedDrag) { gyorgyf@649: gyorgyf@649: m_editing = true; gyorgyf@649: gyorgyf@649: QMouseEvent clickEvent(QEvent::MouseButtonPress, gyorgyf@649: m_clickPos, gyorgyf@649: Qt::NoButton, gyorgyf@649: e->buttons(), gyorgyf@649: e->modifiers()); gyorgyf@649: gyorgyf@649: if (!editSelectionStart(&clickEvent)) { Chris@753: Layer *layer = getTopFlexiNoteLayer(); Chris@753: if (layer) { gyorgyf@649: std::cerr << "calling edit start" << std::endl; gyorgyf@649: layer->editStart(this, &clickEvent); gyorgyf@649: } gyorgyf@649: } gyorgyf@649: } gyorgyf@649: gyorgyf@649: } else { gyorgyf@649: gyorgyf@649: if (!editSelectionDrag(e)) { gyorgyf@649: Chris@875: Layer *layer = getTopFlexiNoteLayer(); Chris@875: Chris@875: if (layer) { gyorgyf@649: gyorgyf@649: int x = e->x(); gyorgyf@649: int y = e->y(); gyorgyf@649: if (m_dragMode == VerticalDrag) x = m_clickPos.x(); gyorgyf@649: else if (m_dragMode == HorizontalDrag) y = m_clickPos.y(); gyorgyf@649: gyorgyf@649: QMouseEvent moveEvent(QEvent::MouseMove, gyorgyf@649: QPoint(x, y), gyorgyf@649: Qt::NoButton, gyorgyf@649: e->buttons(), gyorgyf@649: e->modifiers()); gyorgyf@649: std::cerr << "calling editDrag" << std::endl; gyorgyf@649: layer->editDrag(this, &moveEvent); gyorgyf@649: } gyorgyf@649: } gyorgyf@649: } Chris@335: Chris@127: } else if (mode == ViewManager::EditMode) { Chris@127: Chris@551: bool resist = true; Chris@551: Chris@551: if ((e->modifiers() & Qt::ShiftModifier)) { Chris@551: m_shiftPressed = true; Chris@551: // ... but don't set it false if shift has been Chris@551: // released -- we want the state when we started Chris@551: // dragging to be used most of the time Chris@343: } Chris@343: Chris@551: if (m_shiftPressed) resist = false; Chris@551: Chris@551: m_dragMode = updateDragMode Chris@551: (m_dragMode, Chris@551: m_clickPos, Chris@551: e->pos(), Chris@551: true, // can move horiz Chris@551: true, // can move vert Chris@551: resist, // resist horiz Chris@551: resist); // resist vert Chris@551: Chris@343: if (!m_editing) { Chris@343: Chris@551: if (m_dragMode != UnresolvedDrag) { Chris@343: Chris@343: m_editing = true; Chris@343: Chris@343: QMouseEvent clickEvent(QEvent::MouseButtonPress, Chris@343: m_clickPos, Chris@343: Qt::NoButton, Chris@343: e->buttons(), Chris@343: e->modifiers()); Chris@343: Chris@343: if (!editSelectionStart(&clickEvent)) { Chris@840: Layer *layer = getInteractionLayer(); Chris@343: if (layer && layer->isLayerEditable()) { Chris@343: layer->editStart(this, &clickEvent); Chris@343: } Chris@343: } Chris@343: } Chris@551: Chris@551: } else { Chris@551: Chris@551: if (!editSelectionDrag(e)) { Chris@551: Chris@840: Layer *layer = getInteractionLayer(); Chris@551: Chris@551: if (layer && layer->isLayerEditable()) { Chris@551: Chris@551: int x = e->x(); Chris@551: int y = e->y(); Chris@551: if (m_dragMode == VerticalDrag) x = m_clickPos.x(); Chris@551: else if (m_dragMode == HorizontalDrag) y = m_clickPos.y(); Chris@551: Chris@551: QMouseEvent moveEvent(QEvent::MouseMove, Chris@551: QPoint(x, y), Chris@551: Qt::NoButton, Chris@551: e->buttons(), Chris@551: e->modifiers()); Chris@551: Chris@551: layer->editDrag(this, &moveEvent); Chris@551: } Chris@551: } Chris@343: } Chris@259: Chris@259: } else if (mode == ViewManager::MeasureMode) { Chris@259: Chris@267: if (m_measureCursor2) setCursor(*m_measureCursor2); Chris@266: Chris@268: Layer *layer = getTopLayer(); Chris@290: if (layer) { Chris@290: layer->measureDrag(this, e); Chris@290: if (layer->hasTimeXAxis()) edgeScrollMaybe(e->x()); Chris@290: } Chris@267: Chris@267: update(); Chris@127: } Chris@802: Chris@802: if (m_dragMode != UnresolvedDrag) { Chris@802: m_playbackFrameMoveScheduled = false; Chris@802: } Chris@127: } Chris@127: Chris@127: void Chris@730: Pane::zoomToRegion(QRect r) Chris@174: { Chris@730: int x0 = r.x(); Chris@730: int y0 = r.y(); Chris@730: int x1 = r.x() + r.width(); Chris@730: int y1 = r.y() + r.height(); Chris@730: Chris@1389: SVDEBUG << "Pane::zoomToRegion: region defined by pixel rect (" Chris@1389: << r.x() << "," << r.y() << "), " << r.width() << "x" << r.height() Chris@1389: << endl; Chris@1389: Chris@1389: Layer *interactionLayer = getInteractionLayer(); Chris@1389: if (interactionLayer && !(interactionLayer->hasTimeXAxis())) { Chris@1389: SVDEBUG << "Interaction layer does not have time X axis - delegating to it to decide what to do" << endl; Chris@1397: interactionLayer->zoomToRegion(this, r); Chris@1389: return; Chris@1389: } Chris@1389: Chris@908: sv_frame_t newStartFrame = getFrameForX(x0); Chris@1326: sv_frame_t newEndFrame = getFrameForX(x1); Chris@1326: sv_frame_t dist = newEndFrame - newStartFrame; gyorgyf@645: Chris@908: sv_frame_t visibleFrames = getEndFrame() - getStartFrame(); Chris@174: if (newStartFrame <= -visibleFrames) { Chris@174: newStartFrame = -visibleFrames + 1; Chris@174: } gyorgyf@645: Chris@908: if (newStartFrame >= getModelsEndFrame()) { Chris@174: newStartFrame = getModelsEndFrame() - 1; Chris@174: } Chris@1326: Chris@1326: ZoomLevel newZoomLevel = ZoomLevel::fromRatio(width(), dist); Chris@1326: setZoomLevel(getZoomConstraintLevel(newZoomLevel)); Chris@174: setStartFrame(newStartFrame); Chris@174: Chris@174: QString unit; Chris@908: double min, max; Chris@174: bool log; Chris@1408: Layer *layer = nullptr; Chris@835: for (LayerList::const_iterator i = m_layerStack.begin(); Chris@835: i != m_layerStack.end(); ++i) { Chris@174: if ((*i)->getValueExtents(min, max, log, unit) && Chris@174: (*i)->getDisplayExtents(min, max)) { Chris@174: layer = *i; Chris@174: break; Chris@174: } Chris@174: } Chris@174: Chris@174: if (layer) { Chris@174: if (log) { Chris@908: min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min); Chris@908: max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max); Chris@174: } Chris@908: double rmin = min + ((max - min) * (height() - y1)) / height(); Chris@908: double rmax = min + ((max - min) * (height() - y0)) / height(); Chris@682: cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl; Chris@174: if (log) { Chris@908: rmin = pow(10, rmin); Chris@908: rmax = pow(10, rmax); Chris@174: } Chris@682: cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl; Chris@174: Chris@174: layer->setDisplayExtents(rmin, rmax); Chris@174: updateVerticalPanner(); Chris@174: } Chris@174: } Chris@174: Chris@174: void Chris@174: Pane::dragTopLayer(QMouseEvent *e) Chris@174: { Chris@174: // We need to avoid making it too easy to drag both Chris@174: // horizontally and vertically, in the case where the Chris@174: // mouse is moved "mostly" in horizontal or vertical axis Chris@174: // with only a small variation in the other axis. This is Chris@174: // particularly important during playback (when we want to Chris@174: // avoid small horizontal motions) or in slow refresh Chris@174: // layers like spectrogram (when we want to avoid small Chris@174: // vertical motions). Chris@174: // Chris@174: // To this end we have horizontal and vertical thresholds Chris@174: // and a series of states: unresolved, horizontally or Chris@174: // vertically constrained, free. Chris@174: // Chris@174: // When the mouse first moves, we're unresolved: we Chris@174: // restrict ourselves to whichever direction seems safest, Chris@174: // until the mouse has passed a small threshold distance Chris@174: // from the click point. Then we lock in to one of the Chris@174: // constrained modes, based on which axis that distance Chris@174: // was measured in first. Finally, if it turns out we've Chris@174: // also moved more than a certain larger distance in the Chris@174: // other direction as well, we may switch into free mode. Chris@174: // Chris@174: // If the top layer is incapable of being dragged Chris@174: // vertically, the logic is short circuited. Chris@174: Chris@343: m_dragMode = updateDragMode Chris@343: (m_dragMode, Chris@343: m_clickPos, Chris@343: e->pos(), Chris@343: true, // can move horiz Chris@343: canTopLayerMoveVertical(), // can move vert Chris@343: canTopLayerMoveVertical() || (m_manager && m_manager->isPlaying()), // resist horiz Chris@897: true); // resist vert Chris@174: Chris@343: if (m_dragMode == HorizontalDrag || Chris@343: m_dragMode == FreeDrag) { Chris@174: Chris@908: sv_frame_t frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); Chris@908: sv_frame_t newCentreFrame = m_dragCentreFrame; gyorgyf@645: Chris@174: if (frameOff < 0) { Chris@174: newCentreFrame -= frameOff; Chris@806: } else if (newCentreFrame >= frameOff) { Chris@174: newCentreFrame -= frameOff; Chris@174: } else { Chris@174: newCentreFrame = 0; Chris@174: } Chris@363: gyorgyf@645: #ifdef DEBUG_PANE Chris@587: SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame << Chris@585: ", models end frame = " << getModelsEndFrame() << endl; Chris@363: #endif Chris@339: Chris@174: if (newCentreFrame >= getModelsEndFrame()) { Chris@174: newCentreFrame = getModelsEndFrame(); Chris@174: if (newCentreFrame > 0) --newCentreFrame; Chris@174: } Chris@174: Chris@174: if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) { Chris@510: setCentreFrame(newCentreFrame, !m_altPressed); Chris@174: } Chris@174: } Chris@174: Chris@343: if (m_dragMode == VerticalDrag || Chris@343: m_dragMode == FreeDrag) { Chris@174: Chris@908: double vmin = 0.f, vmax = 0.f; Chris@908: double dmin = 0.f, dmax = 0.f; Chris@174: Chris@174: if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { Chris@174: Chris@682: // cerr << "ydiff = " << ydiff << endl; Chris@174: Chris@343: int ydiff = e->y() - m_clickPos.y(); Chris@908: double perpix = (dmax - dmin) / height(); Chris@908: double valdiff = ydiff * perpix; Chris@682: // cerr << "valdiff = " << valdiff << endl; Chris@174: Chris@343: if (m_dragMode == UnresolvedDrag && ydiff != 0) { Chris@343: m_dragMode = VerticalDrag; Chris@343: } Chris@343: Chris@908: double newmin = m_dragStartMinValue + valdiff; Chris@908: double newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; Chris@174: if (newmin < vmin) { Chris@174: newmax += vmin - newmin; Chris@174: newmin += vmin - newmin; Chris@174: } Chris@174: if (newmax > vmax) { Chris@174: newmin -= newmax - vmax; Chris@174: newmax -= newmax - vmax; Chris@174: } Chris@682: // cerr << "(" << dmin << ", " << dmax << ") -> (" Chris@682: // << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << endl; Chris@174: Chris@174: setTopLayerDisplayExtents(newmin, newmax); Chris@174: updateVerticalPanner(); Chris@174: } Chris@174: } Chris@174: } Chris@174: Chris@343: Pane::DragMode Chris@343: Pane::updateDragMode(DragMode dragMode, Chris@343: QPoint origin, Chris@343: QPoint point, Chris@343: bool canMoveHorizontal, Chris@343: bool canMoveVertical, Chris@343: bool resistHorizontal, Chris@343: bool resistVertical) Chris@343: { Chris@343: int xdiff = point.x() - origin.x(); Chris@343: int ydiff = point.y() - origin.y(); Chris@343: Chris@343: int smallThreshold = 10, bigThreshold = 80; Chris@343: Chris@896: if (m_manager) { Chris@896: smallThreshold = m_manager->scalePixelSize(smallThreshold); Chris@896: bigThreshold = m_manager->scalePixelSize(bigThreshold); Chris@896: } Chris@896: Chris@587: // SVDEBUG << "Pane::updateDragMode: xdiff = " << xdiff << ", ydiff = " Chris@585: // << ydiff << ", canMoveVertical = " << canMoveVertical << ", drag mode = " << m_dragMode << endl; Chris@343: Chris@343: if (dragMode == UnresolvedDrag) { Chris@343: Chris@343: if (abs(ydiff) > smallThreshold && Chris@343: abs(ydiff) > abs(xdiff) * 2 && Chris@343: canMoveVertical) { Chris@587: // SVDEBUG << "Pane::updateDragMode: passed vertical threshold" << endl; Chris@343: dragMode = VerticalDrag; Chris@343: } else if (abs(xdiff) > smallThreshold && Chris@343: abs(xdiff) > abs(ydiff) * 2 && Chris@343: canMoveHorizontal) { Chris@587: // SVDEBUG << "Pane::updateDragMode: passed horizontal threshold" << endl; Chris@343: dragMode = HorizontalDrag; Chris@343: } else if (abs(xdiff) > smallThreshold && Chris@343: abs(ydiff) > smallThreshold && Chris@343: canMoveVertical && Chris@343: canMoveHorizontal) { Chris@587: // SVDEBUG << "Pane::updateDragMode: passed both thresholds" << endl; Chris@343: dragMode = FreeDrag; Chris@343: } Chris@343: } Chris@343: Chris@343: if (dragMode == VerticalDrag && canMoveHorizontal) { Chris@343: if (abs(xdiff) > bigThreshold) dragMode = FreeDrag; Chris@343: } Chris@343: Chris@343: if (dragMode == HorizontalDrag && canMoveVertical) { Chris@343: if (abs(ydiff) > bigThreshold) dragMode = FreeDrag; Chris@343: } Chris@343: Chris@343: if (dragMode == UnresolvedDrag) { Chris@343: if (!resistHorizontal && xdiff != 0) { Chris@343: dragMode = HorizontalDrag; Chris@343: } Chris@343: if (!resistVertical && ydiff != 0) { Chris@343: if (dragMode == HorizontalDrag) dragMode = FreeDrag; Chris@343: else dragMode = VerticalDrag; Chris@343: } Chris@343: } Chris@343: Chris@343: return dragMode; Chris@343: } Chris@343: Chris@174: void Chris@174: Pane::dragExtendSelection(QMouseEvent *e) Chris@174: { Chris@908: sv_frame_t mouseFrame = getFrameForX(e->x()); Chris@806: int resolution = 1; Chris@908: sv_frame_t snapFrameLeft = mouseFrame; Chris@908: sv_frame_t snapFrameRight = mouseFrame; gyorgyf@645: Chris@840: Layer *layer = getInteractionLayer(); Chris@928: if (layer && !m_shiftPressed && Chris@928: !qobject_cast(layer)) { // don't snap to secs Chris@174: layer->snapToFeatureFrame(this, snapFrameLeft, Chris@174: resolution, Layer::SnapLeft); Chris@174: layer->snapToFeatureFrame(this, snapFrameRight, Chris@174: resolution, Layer::SnapRight); Chris@174: } Chris@1266: Chris@1266: // cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << endl; Chris@174: Chris@174: if (snapFrameLeft < 0) snapFrameLeft = 0; Chris@174: if (snapFrameRight < 0) snapFrameRight = 0; gyorgyf@645: Chris@908: sv_frame_t min, max; gyorgyf@645: Chris@806: if (m_selectionStartFrame > snapFrameLeft) { Chris@174: min = snapFrameLeft; Chris@174: max = m_selectionStartFrame; Chris@806: } else if (snapFrameRight > m_selectionStartFrame) { Chris@174: min = m_selectionStartFrame; Chris@174: max = snapFrameRight; Chris@174: } else { Chris@174: min = snapFrameLeft; Chris@174: max = snapFrameRight; Chris@174: } Chris@174: Chris@966: sv_frame_t end = getModelsEndFrame(); Chris@966: if (min > end) min = end; Chris@966: if (max > end) max = end; Chris@966: Chris@174: if (m_manager) { Chris@966: Chris@966: Selection sel(alignToReference(min), alignToReference(max)); Chris@966: Chris@966: bool exc; Chris@966: bool same = (m_manager->haveInProgressSelection() && Chris@966: m_manager->getInProgressSelection(exc) == sel); Chris@966: Chris@966: m_manager->setInProgressSelection(sel, !m_resizing && !m_ctrlPressed); Chris@966: Chris@966: if (!same) { Chris@966: edgeScrollMaybe(e->x()); Chris@966: } Chris@174: } Chris@174: Chris@259: update(); Chris@802: Chris@802: if (min != max) { Chris@802: m_playbackFrameMoveScheduled = false; Chris@802: } Chris@259: } Chris@259: Chris@259: void Chris@259: Pane::edgeScrollMaybe(int x) Chris@259: { Chris@908: sv_frame_t mouseFrame = getFrameForX(x); Chris@259: Chris@174: bool doScroll = false; Chris@174: if (!m_manager) doScroll = true; Chris@854: else if (!m_manager->isPlaying()) doScroll = true; Chris@854: Chris@174: if (m_followPlay != PlaybackScrollContinuous) doScroll = true; Chris@174: Chris@174: if (doScroll) { Chris@908: sv_frame_t offset = mouseFrame - getStartFrame(); Chris@908: sv_frame_t available = getEndFrame() - getStartFrame(); Chris@908: sv_frame_t move = 0; Chris@967: sv_frame_t rightEdge = available - (available / 20); Chris@967: sv_frame_t leftEdge = (available / 10); Chris@967: if (offset >= rightEdge) { Chris@967: move = offset - rightEdge + 1; Chris@967: } else if (offset <= leftEdge) { Chris@967: move = offset - leftEdge - 1; Chris@259: } Chris@259: if (move != 0) { Chris@174: setCentreFrame(m_centreFrame + move); Chris@259: update(); Chris@174: } Chris@174: } Chris@174: } Chris@174: Chris@174: void Chris@127: Pane::mouseDoubleClickEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@127: return; Chris@127: } Chris@127: Chris@802: cerr << "mouseDoubleClickEvent" << endl; Chris@127: Chris@127: m_clickPos = e->pos(); Chris@127: m_clickedInRange = true; Chris@127: m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); Chris@127: m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); Chris@510: m_altPressed = (e->modifiers() & Qt::AltModifier); Chris@127: Chris@802: // cancel any pending move that came from a single click Chris@802: m_playbackFrameMoveScheduled = false; Chris@802: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@711: if (m_manager) mode = m_manager->getToolModeFor(this); Chris@127: Chris@255: bool relocate = (mode == ViewManager::NavigateMode || Chris@255: (e->buttons() & Qt::MidButton)); Chris@255: Chris@716: if (mode == ViewManager::SelectMode) { Chris@716: m_clickedInRange = false; Chris@854: if (m_manager) m_manager->clearInProgressSelection(); Chris@716: emit doubleClickSelectInvoked(getFrameForX(e->x())); Chris@716: return; Chris@716: } Chris@716: Chris@1468: if (mode == ViewManager::EditMode || Chris@1468: (mode == ViewManager::NavigateMode && Chris@1468: m_manager->getOpportunisticEditingEnabled())) { Chris@127: Chris@840: Layer *layer = getInteractionLayer(); matthiasm@660: if (layer && layer->isLayerEditable()) { matthiasm@660: if (layer->editOpen(this, e)) relocate = false; matthiasm@660: } Chris@280: Chris@280: } else if (mode == ViewManager::MeasureMode) { Chris@280: Chris@280: Layer *layer = getTopLayer(); Chris@280: if (layer) layer->measureDoubleClick(this, e); Chris@280: update(); Chris@127: } Chris@255: Chris@255: if (relocate) { Chris@255: Chris@908: sv_frame_t f = getFrameForX(e->x()); Chris@255: Chris@255: setCentreFrame(f); Chris@255: Chris@255: m_dragCentreFrame = f; Chris@255: m_dragStartMinValue = 0; Chris@255: m_dragMode = UnresolvedDrag; Chris@255: Chris@908: double vmin, vmax, dmin, dmax; Chris@255: if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { Chris@255: m_dragStartMinValue = dmin; Chris@255: } Chris@255: } matthiasm@660: matthiasm@660: if (mode == ViewManager::NoteEditMode) { matthiasm@660: std::cerr << "double click in note edit mode" << std::endl; Chris@840: Layer *layer = getInteractionLayer(); matthiasm@660: if (layer && layer->isLayerEditable()) { matthiasm@660: layer->addNote(this, e); matthiasm@660: } matthiasm@660: } Chris@551: Chris@551: m_clickedInRange = false; // in case mouseReleaseEvent is not properly called Chris@127: } Chris@127: Chris@127: void Chris@290: Pane::enterEvent(QEvent *) Chris@290: { Chris@290: m_mouseInWidget = true; Chris@290: } Chris@290: Chris@290: void Chris@127: Pane::leaveEvent(QEvent *) Chris@127: { Chris@290: m_mouseInWidget = false; Chris@127: bool previouslyIdentifying = m_identifyFeatures; Chris@127: m_identifyFeatures = false; Chris@127: if (previouslyIdentifying) update(); Chris@189: emit contextHelpChanged(""); Chris@127: } Chris@127: Chris@127: void Chris@133: Pane::resizeEvent(QResizeEvent *) Chris@133: { Chris@133: updateHeadsUpDisplay(); Chris@133: } Chris@133: Chris@133: void Chris@127: Pane::wheelEvent(QWheelEvent *e) Chris@127: { cannam@1207: // cerr << "wheelEvent, delta " << e->delta() << ", angleDelta " << e->angleDelta().x() << "," << e->angleDelta().y() << ", pixelDelta " << e->pixelDelta().x() << "," << e->pixelDelta().y() << ", modifiers " << e->modifiers() << endl; Chris@826: Chris@1172: e->accept(); // we never want wheel events on the pane to be propagated Chris@1172: Chris@826: int dx = e->angleDelta().x(); Chris@826: int dy = e->angleDelta().y(); Chris@826: Chris@826: if (dx == 0 && dy == 0) { Chris@826: return; Chris@127: } Chris@127: Chris@826: int d = dy; Chris@826: bool horizontal = false; Chris@826: Chris@826: if (abs(dx) > abs(dy)) { Chris@826: d = dx; Chris@826: horizontal = true; Chris@826: } else if (e->modifiers() & Qt::ControlModifier) { Chris@826: // treat a vertical wheel as horizontal Chris@826: horizontal = true; Chris@826: } Chris@826: Chris@826: if (e->phase() == Qt::ScrollBegin || cannam@1184: std::abs(d) >= 120 || Chris@826: (d > 0 && m_pendingWheelAngle < 0) || Chris@826: (d < 0 && m_pendingWheelAngle > 0)) { Chris@826: m_pendingWheelAngle = d; Chris@826: } else { Chris@826: m_pendingWheelAngle += d; Chris@826: } Chris@826: Chris@826: if (horizontal && e->pixelDelta().x() != 0) { Chris@826: Chris@826: // Have fine pixel information: use it Chris@826: Chris@826: wheelHorizontalFine(e->pixelDelta().x(), e->modifiers()); Chris@826: Chris@826: m_pendingWheelAngle = 0; Chris@826: Chris@826: } else { Chris@826: Chris@826: // Coarse wheel information (or vertical zoom, which is Chris@826: // necessarily coarse itself) Chris@826: Chris@1449: // Sometimes on Linux we're seeing very extreme angles on the Chris@1449: // first wheel event. They could be spurious, or they could be Chris@1449: // a result of the user frantically wheeling away while the Chris@1449: // pane was unresponsive for some reason. We don't want to Chris@1449: // discard them, as that makes the application feel even less Chris@1449: // responsive, but if we take them literally we risk changing Chris@1449: // the view so radically that the user won't recognise what Chris@1449: // has happened. Clamp them instead. Chris@1449: if (m_pendingWheelAngle > 600) { Chris@1449: m_pendingWheelAngle = 600; Chris@1449: } Chris@1449: if (m_pendingWheelAngle < -600) { Chris@1449: m_pendingWheelAngle = -600; Chris@870: } Chris@895: Chris@826: while (abs(m_pendingWheelAngle) >= 120) { Chris@826: Chris@826: int sign = (m_pendingWheelAngle < 0 ? -1 : 1); Chris@826: Chris@826: if (horizontal) { Chris@826: wheelHorizontal(sign, e->modifiers()); Chris@826: } else { Chris@826: wheelVertical(sign, e->modifiers()); Chris@826: } Chris@826: Chris@826: m_pendingWheelAngle -= sign * 120; Chris@826: } Chris@826: } Chris@826: } Chris@826: Chris@826: void Chris@826: Pane::wheelVertical(int sign, Qt::KeyboardModifiers mods) Chris@826: { Chris@1208: // cerr << "wheelVertical: sign = " << sign << endl; Chris@826: Chris@826: if (mods & Qt::ShiftModifier) { Chris@826: Chris@826: // Pan vertically Chris@826: Chris@826: if (m_vpan) { Chris@826: m_vpan->scroll(sign > 0); Chris@826: } Chris@826: Chris@826: } else if (mods & Qt::AltModifier) { Chris@826: Chris@826: // Zoom vertically Chris@826: Chris@826: if (m_vthumb) { Chris@826: m_vthumb->scroll(sign > 0); Chris@826: } Chris@826: Chris@826: } else { Chris@1326: using namespace std::rel_ops; Chris@826: Chris@826: // Zoom in or out Chris@826: Chris@1326: ZoomLevel newZoomLevel = m_zoomLevel; Chris@826: Chris@826: if (sign > 0) { Chris@1326: newZoomLevel = getZoomConstraintLevel(newZoomLevel.decremented(), Chris@1326: ZoomConstraint::RoundDown); Chris@1326: } else { Chris@1326: newZoomLevel = getZoomConstraintLevel(newZoomLevel.incremented(), Chris@1326: ZoomConstraint::RoundUp); Chris@826: } Chris@826: Chris@826: if (newZoomLevel != m_zoomLevel) { Chris@826: setZoomLevel(newZoomLevel); Chris@826: } Chris@826: } Chris@826: Chris@826: emit paneInteractedWith(); Chris@826: } Chris@826: Chris@826: void Chris@826: Pane::wheelHorizontal(int sign, Qt::KeyboardModifiers mods) Chris@826: { gyorgyf@645: // Scroll left or right, rapidly gyorgyf@645: Chris@1404: wheelHorizontalFine(120 * sign, mods); Chris@826: } Chris@826: Chris@826: void Chris@826: Pane::wheelHorizontalFine(int pixels, Qt::KeyboardModifiers) Chris@826: { Chris@826: // Scroll left or right by a fixed number of pixels Chris@826: gyorgyf@645: if (getStartFrame() < 0 && Chris@1326: getEndFrame() >= getModelsEndFrame()) { Chris@1326: return; Chris@1326: } Chris@1326: Chris@1326: int delta = int(round(m_zoomLevel.pixelsToFrames(pixels))); Chris@806: Chris@806: if (m_centreFrame < delta) { gyorgyf@645: setCentreFrame(0); Chris@806: } else if (m_centreFrame - delta >= getModelsEndFrame()) { gyorgyf@645: setCentreFrame(getModelsEndFrame()); gyorgyf@645: } else { gyorgyf@645: setCentreFrame(m_centreFrame - delta); gyorgyf@645: } Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@132: void Chris@132: Pane::horizontalThumbwheelMoved(int value) Chris@132: { Chris@1357: ZoomLevel level = getZoomLevelByIndex(m_hthumb->getMaximumValue() - value); Chris@132: setZoomLevel(level); Chris@132: } Chris@132: Chris@132: void Chris@132: Pane::verticalThumbwheelMoved(int value) Chris@132: { Chris@1408: Layer *layer = nullptr; Chris@133: if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); Chris@133: if (layer) { Chris@133: int defaultStep = 0; Chris@133: int max = layer->getVerticalZoomSteps(defaultStep); Chris@133: if (max == 0) { Chris@133: updateHeadsUpDisplay(); Chris@133: return; Chris@133: } Chris@133: if (value > max) { Chris@133: value = max; Chris@133: } Chris@133: layer->setVerticalZoomStep(value); Chris@174: updateVerticalPanner(); Chris@133: } Chris@132: } Chris@132: Chris@174: void Chris@806: Pane::verticalPannerMoved(float , float y0, float , float h) Chris@174: { Chris@908: double vmin, vmax, dmin, dmax; Chris@174: if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; Chris@908: double y1 = y0 + h; Chris@908: double newmax = vmin + ((1.0 - y0) * (vmax - vmin)); Chris@908: double newmin = vmin + ((1.0 - y1) * (vmax - vmin)); Chris@682: // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w Chris@682: // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; Chris@174: setTopLayerDisplayExtents(newmin, newmax); Chris@174: } Chris@174: Chris@188: void Chris@188: Pane::editVerticalPannerExtents() Chris@188: { Chris@188: if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; Chris@188: Chris@908: double vmin, vmax, dmin, dmax; Chris@188: QString unit; Chris@188: if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) Chris@188: || vmax == vmin) { Chris@188: return; Chris@188: } Chris@188: Chris@188: RangeInputDialog dialog(tr("Enter new range"), Chris@188: tr("New vertical display range, from %1 to %2 %4:") Chris@188: .arg(vmin).arg(vmax).arg(unit), Chris@908: unit, float(vmin), float(vmax), this); Chris@908: dialog.setRange(float(dmin), float(dmax)); Chris@188: Chris@188: if (dialog.exec() == QDialog::Accepted) { Chris@908: float newmin, newmax; Chris@908: dialog.getRange(newmin, newmax); Chris@908: setTopLayerDisplayExtents(newmin, newmax); Chris@188: updateVerticalPanner(); Chris@188: } Chris@188: } Chris@188: Chris@312: void Chris@437: Pane::layerParametersChanged() Chris@437: { Chris@437: View::layerParametersChanged(); Chris@437: updateHeadsUpDisplay(); Chris@437: } Chris@437: Chris@437: void Chris@312: Pane::dragEnterEvent(QDragEnterEvent *e) Chris@312: { Chris@312: QStringList formats(e->mimeData()->formats()); Chris@682: cerr << "dragEnterEvent: format: " Chris@683: << formats.join(",") Chris@312: << ", possibleActions: " << e->possibleActions() Chris@682: << ", proposedAction: " << e->proposedAction() << endl; Chris@312: Chris@616: if (e->mimeData()->hasFormat("text/uri-list") || Chris@616: e->mimeData()->hasFormat("text/plain")) { Chris@312: Chris@312: if (e->proposedAction() & Qt::CopyAction) { Chris@312: e->acceptProposedAction(); Chris@312: } else { Chris@312: e->setDropAction(Qt::CopyAction); Chris@312: e->accept(); Chris@312: } Chris@312: } Chris@312: } Chris@312: Chris@312: void Chris@312: Pane::dropEvent(QDropEvent *e) Chris@312: { Chris@683: cerr << "dropEvent: text: \"" << e->mimeData()->text() Chris@682: << "\"" << endl; Chris@312: Chris@616: if (e->mimeData()->hasFormat("text/uri-list") || Chris@616: e->mimeData()->hasFormat("text/plain")) { Chris@312: Chris@312: if (e->proposedAction() & Qt::CopyAction) { Chris@312: e->acceptProposedAction(); Chris@312: } else { Chris@312: e->setDropAction(Qt::CopyAction); Chris@312: e->accept(); Chris@312: } Chris@312: Chris@616: if (e->mimeData()->hasFormat("text/uri-list")) { Chris@616: Chris@616: SVDEBUG << "accepting... data is \"" << e->mimeData()->data("text/uri-list").data() << "\"" << endl; Chris@312: emit dropAccepted(QString::fromLocal8Bit Chris@616: (e->mimeData()->data("text/uri-list").data()) Chris@312: .split(QRegExp("[\\r\\n]+"), Chris@312: QString::SkipEmptyParts)); Chris@312: } else { Chris@312: emit dropAccepted(QString::fromLocal8Bit Chris@616: (e->mimeData()->data("text/plain").data())); Chris@312: } Chris@312: } Chris@312: } Chris@312: Chris@127: bool Chris@127: Pane::editSelectionStart(QMouseEvent *e) Chris@127: { Chris@127: if (!m_identifyFeatures || Chris@711: !m_manager || Chris@711: m_manager->getToolModeFor(this) != ViewManager::EditMode) { Chris@711: return false; Chris@127: } Chris@127: Chris@127: bool closeToLeft, closeToRight; Chris@127: Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight)); Chris@127: if (s.isEmpty()) return false; Chris@127: m_editingSelection = s; Chris@127: m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0); Chris@127: m_mousePos = e->pos(); Chris@127: return true; Chris@127: } Chris@127: Chris@127: bool Chris@127: Pane::editSelectionDrag(QMouseEvent *e) Chris@127: { Chris@127: if (m_editingSelection.isEmpty()) return false; Chris@127: m_mousePos = e->pos(); Chris@127: update(); Chris@127: return true; Chris@127: } Chris@127: Chris@127: bool Chris@248: Pane::editSelectionEnd(QMouseEvent *) Chris@127: { Chris@127: if (m_editingSelection.isEmpty()) return false; Chris@127: Chris@127: int offset = m_mousePos.x() - m_clickPos.x(); Chris@840: Layer *layer = getInteractionLayer(); Chris@127: Chris@127: if (offset == 0 || !layer) { Chris@716: m_editingSelection = Selection(); Chris@716: return true; Chris@127: } Chris@127: Chris@127: int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; Chris@127: int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; Chris@127: Chris@908: sv_frame_t f0 = getFrameForX(p0); Chris@908: sv_frame_t f1 = getFrameForX(p1); Chris@127: Chris@127: Selection newSelection(f0, f1); Chris@127: Chris@127: if (m_editingSelectionEdge == 0) { gyorgyf@645: Chris@127: CommandHistory::getInstance()->startCompoundOperation Chris@127: (tr("Drag Selection"), true); Chris@127: Chris@716: layer->moveSelection(m_editingSelection, f0); gyorgyf@645: Chris@127: } else { gyorgyf@645: Chris@127: CommandHistory::getInstance()->startCompoundOperation Chris@127: (tr("Resize Selection"), true); Chris@127: Chris@716: if (m_editingSelectionEdge < 0) { Chris@716: f1 = m_editingSelection.getEndFrame(); Chris@716: } else { Chris@716: f0 = m_editingSelection.getStartFrame(); Chris@716: } Chris@716: Chris@716: newSelection = Selection(f0, f1); Chris@716: layer->resizeSelection(m_editingSelection, newSelection); Chris@127: } Chris@127: Chris@127: m_manager->removeSelection(m_editingSelection); Chris@127: m_manager->addSelection(newSelection); Chris@127: Chris@127: CommandHistory::getInstance()->endCompoundOperation(); Chris@127: Chris@127: m_editingSelection = Selection(); Chris@127: return true; Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::toolModeChanged() Chris@127: { Chris@711: ViewManager::ToolMode mode = m_manager->getToolModeFor(this); Chris@587: // SVDEBUG << "Pane::toolModeChanged(" << mode << ")" << endl; Chris@127: Chris@267: if (mode == ViewManager::MeasureMode && !m_measureCursor1) { Chris@267: m_measureCursor1 = new QCursor(QBitmap(":/icons/measure1cursor.xbm"), Chris@267: QBitmap(":/icons/measure1mask.xbm"), Chris@267: 15, 14); Chris@267: m_measureCursor2 = new QCursor(QBitmap(":/icons/measure2cursor.xbm"), Chris@267: QBitmap(":/icons/measure2mask.xbm"), Chris@267: 16, 17); Chris@257: } Chris@257: Chris@127: switch (mode) { Chris@127: Chris@127: case ViewManager::NavigateMode: Chris@713: setCursor(Qt::PointingHandCursor); Chris@713: break; gyorgyf@645: Chris@127: case ViewManager::SelectMode: Chris@713: setCursor(Qt::ArrowCursor); Chris@713: break; gyorgyf@645: Chris@127: case ViewManager::EditMode: Chris@713: setCursor(Qt::UpArrowCursor); Chris@713: break; gyorgyf@645: Chris@127: case ViewManager::DrawMode: Chris@713: setCursor(Qt::CrossCursor); Chris@713: break; gyorgyf@645: Chris@335: case ViewManager::EraseMode: Chris@713: setCursor(Qt::CrossCursor); Chris@713: break; Chris@257: Chris@257: case ViewManager::MeasureMode: Chris@267: if (m_measureCursor1) setCursor(*m_measureCursor1); Chris@713: break; Chris@713: Chris@713: // GF: NoteEditMode uses the same default cursor as EditMode, but it will change in a context sensitive manner. gyorgyf@645: case ViewManager::NoteEditMode: Chris@713: setCursor(Qt::UpArrowCursor); Chris@713: break; gyorgyf@645: gyorgyf@645: /* Chris@127: case ViewManager::TextMode: gyorgyf@645: setCursor(Qt::IBeamCursor); gyorgyf@645: break; Chris@127: */ Chris@127: } Chris@127: } Chris@127: Chris@133: void Chris@133: Pane::zoomWheelsEnabledChanged() Chris@133: { Chris@133: updateHeadsUpDisplay(); Chris@133: update(); Chris@133: } Chris@133: Chris@133: void Chris@1326: Pane::viewZoomLevelChanged(View *v, ZoomLevel z, bool locked) Chris@133: { Chris@682: // cerr << "Pane[" << this << "]::zoomLevelChanged (global now " Chris@682: // << (m_manager ? m_manager->getGlobalZoom() : 0) << ")" << endl; Chris@192: Chris@224: View::viewZoomLevelChanged(v, z, locked); Chris@224: Chris@232: if (m_hthumb && !m_hthumb->isVisible()) return; Chris@224: Chris@222: if (v != this) { Chris@222: if (!locked || !m_followZoom) return; Chris@222: } Chris@222: Chris@133: if (m_manager && m_manager->getZoomWheelsEnabled()) { Chris@133: updateHeadsUpDisplay(); Chris@133: } Chris@133: } Chris@133: Chris@133: void Chris@133: Pane::propertyContainerSelected(View *v, PropertyContainer *pc) Chris@133: { Chris@1408: Layer *layer = nullptr; Chris@133: Chris@133: if (getLayerCount() > 0) { Chris@133: layer = getLayer(getLayerCount() - 1); Chris@133: disconnect(layer, SIGNAL(verticalZoomChanged()), Chris@133: this, SLOT(verticalZoomChanged())); Chris@133: } Chris@133: Chris@133: View::propertyContainerSelected(v, pc); Chris@133: updateHeadsUpDisplay(); Chris@133: Chris@187: if (m_vthumb) { Chris@1408: RangeMapper *rm = nullptr; Chris@187: if (layer) rm = layer->getNewVerticalZoomRangeMapper(); Chris@187: if (rm) m_vthumb->setRangeMapper(rm); Chris@187: } Chris@187: Chris@133: if (getLayerCount() > 0) { Chris@133: layer = getLayer(getLayerCount() - 1); Chris@133: connect(layer, SIGNAL(verticalZoomChanged()), Chris@133: this, SLOT(verticalZoomChanged())); Chris@133: } Chris@133: } Chris@133: Chris@133: void Chris@133: Pane::verticalZoomChanged() Chris@133: { Chris@1408: Layer *layer = nullptr; Chris@133: Chris@133: if (getLayerCount() > 0) { Chris@133: Chris@133: layer = getLayer(getLayerCount() - 1); Chris@133: Chris@133: if (m_vthumb && m_vthumb->isVisible()) { Chris@133: m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); Chris@133: } Chris@133: } Chris@133: } Chris@133: Chris@189: void Chris@189: Pane::updateContextHelp(const QPoint *pos) Chris@189: { Chris@189: QString help = ""; Chris@189: Chris@189: if (m_clickedInRange) { Chris@189: emit contextHelpChanged(""); Chris@189: return; Chris@189: } Chris@189: Chris@189: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@711: if (m_manager) mode = m_manager->getToolModeFor(this); Chris@189: Chris@189: bool editable = false; Chris@840: Layer *layer = getInteractionLayer(); Chris@189: if (layer && layer->isLayerEditable()) { Chris@189: editable = true; Chris@189: } Chris@189: Chris@189: if (mode == ViewManager::NavigateMode) { Chris@189: Chris@1388: help = tr("Click and drag to navigate; use mouse-wheel or trackpad-scroll to zoom; hold Shift and drag to zoom to an area"); Chris@189: Chris@189: } else if (mode == ViewManager::SelectMode) { Chris@189: Chris@217: if (!hasTopLayerTimeXAxis()) return; Chris@217: Chris@189: bool haveSelection = (m_manager && !m_manager->getSelections().empty()); Chris@189: Chris@189: if (haveSelection) { Chris@597: #ifdef Q_OS_MAC Chris@597: if (editable) { Chris@597: 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: } else { Chris@597: help = tr("Click and drag to select a range; hold Cmd for multi-select; middle-click and drag to navigate"); Chris@597: } Chris@597: #else Chris@189: if (editable) { Chris@189: 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: } else { Chris@189: help = tr("Click and drag to select a range; hold Ctrl for multi-select; middle-click and drag to navigate"); Chris@189: } Chris@597: #endif Chris@189: Chris@189: if (pos) { Chris@189: bool closeToLeft = false, closeToRight = false; Chris@189: Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight); Chris@189: if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { Chris@189: Chris@189: help = tr("Click and drag to move the selection boundary"); Chris@189: } Chris@189: } Chris@189: } else { Chris@189: if (editable) { Chris@189: help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; middle-click to navigate"); Chris@189: } else { Chris@189: help = tr("Click and drag to select a range; middle-click and drag to navigate"); Chris@189: } Chris@189: } Chris@189: Chris@189: } else if (mode == ViewManager::DrawMode) { Chris@189: Chris@189: //!!! could call through to a layer function to find out exact meaning Chris@713: if (editable) { Chris@189: help = tr("Click to add a new item in the active layer"); Chris@189: } Chris@335: Chris@335: } else if (mode == ViewManager::EraseMode) { Chris@335: Chris@335: //!!! could call through to a layer function to find out exact meaning Chris@713: if (editable) { Chris@335: help = tr("Click to erase an item from the active layer"); Chris@335: } Chris@189: Chris@189: } else if (mode == ViewManager::EditMode) { Chris@189: Chris@189: //!!! could call through to layer Chris@713: if (editable) { Chris@551: help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance"); Chris@189: if (pos) { Chris@189: bool closeToLeft = false, closeToRight = false; Chris@189: Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight); Chris@189: if (!selection.isEmpty()) { Chris@189: help = tr("Click and drag to move all items in the selected range"); Chris@189: } Chris@189: } Chris@189: } Chris@189: } Chris@189: Chris@189: emit contextHelpChanged(help); Chris@189: } Chris@189: Chris@189: void Chris@189: Pane::mouseEnteredWidget() Chris@189: { Chris@189: QWidget *w = dynamic_cast(sender()); Chris@189: if (!w) return; Chris@189: Chris@189: if (w == m_vpan) { Chris@189: emit contextHelpChanged(tr("Click and drag to adjust the visible range of the vertical scale")); Chris@189: } else if (w == m_vthumb) { Chris@189: emit contextHelpChanged(tr("Click and drag to adjust the vertical zoom level")); Chris@189: } else if (w == m_hthumb) { Chris@189: emit contextHelpChanged(tr("Click and drag to adjust the horizontal zoom level")); Chris@189: } else if (w == m_reset) { Chris@189: emit contextHelpChanged(tr("Reset horizontal and vertical zoom levels to their defaults")); Chris@189: } Chris@189: } Chris@189: Chris@189: void Chris@189: Pane::mouseLeftWidget() Chris@189: { Chris@189: emit contextHelpChanged(""); Chris@189: } Chris@189: Chris@316: void Chris@316: Pane::toXml(QTextStream &stream, Chris@316: QString indent, QString extraAttributes) const Chris@127: { Chris@316: View::toXml Chris@316: (stream, indent, gyorgyf@645: QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") gyorgyf@645: .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); Chris@127: } Chris@127: Chris@127: