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@127: This file copyright 2006 Chris Cannam. 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@127: #include "base/CommandHistory.h" Chris@127: #include "layer/WaveformLayer.h" Chris@127: Chris@127: #include Chris@127: #include 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@133: Chris@127: using std::cerr; Chris@127: using std::endl; Chris@127: 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@127: m_navigating(false), Chris@127: m_resizing(false), Chris@133: m_centreLineVisible(true), Chris@133: m_headsUpDisplay(0) Chris@127: { Chris@127: setObjectName("Pane"); Chris@127: setMouseTracking(true); Chris@133: Chris@133: updateHeadsUpDisplay(); Chris@133: } Chris@133: Chris@133: void Chris@133: Pane::updateHeadsUpDisplay() Chris@133: { Chris@132: /* Chris@132: int count = 0; Chris@132: int currentLevel = 1; Chris@132: int level = 1; Chris@132: while (true) { Chris@132: if (getZoomLevel() == level) currentLevel = count; Chris@132: int newLevel = getZoomConstraintBlockSize(level + 1, Chris@132: ZoomConstraint::RoundUp); Chris@132: if (newLevel == level) break; Chris@132: if (newLevel == 131072) break; //!!! just because Chris@132: level = newLevel; Chris@132: ++count; Chris@132: } Chris@132: Chris@132: std::cerr << "Have " << count+1 << " zoom levels" << std::endl; Chris@132: */ Chris@133: 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@133: layout->addWidget(m_hthumb, 1, 0); Chris@133: m_hthumb->setFixedWidth(70); Chris@133: m_hthumb->setFixedHeight(16); Chris@133: m_hthumb->setDefaultValue(0); Chris@133: connect(m_hthumb, SIGNAL(valueChanged(int)), this, Chris@133: SLOT(horizontalThumbwheelMoved(int))); Chris@133: Chris@133: m_vthumb = new Thumbwheel(Qt::Vertical); Chris@133: layout->addWidget(m_vthumb, 0, 1); Chris@133: m_vthumb->setFixedWidth(16); Chris@133: m_vthumb->setFixedHeight(70); Chris@133: connect(m_vthumb, SIGNAL(valueChanged(int)), this, Chris@133: SLOT(verticalThumbwheelMoved(int))); Chris@133: Chris@133: QPushButton *reset = new QPushButton; Chris@133: reset->setFixedHeight(16); Chris@133: reset->setFixedWidth(16); Chris@133: layout->addWidget(reset, 1, 1); Chris@133: connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); Chris@133: connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); Chris@133: } Chris@133: Chris@133: int count = 0; Chris@133: int current = 0; Chris@133: int level = 1; Chris@133: Chris@137: //!!! pull out into function (presumably in View) Chris@137: bool haveConstraint = false; Chris@137: for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); Chris@137: ++i) { Chris@137: if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { Chris@137: haveConstraint = true; Chris@137: break; Chris@137: } Chris@137: } Chris@137: Chris@137: if (haveConstraint) { Chris@137: while (true) { Chris@137: if (getZoomLevel() == level) current = count; Chris@137: int newLevel = getZoomConstraintBlockSize(level + 1, Chris@137: ZoomConstraint::RoundUp); Chris@137: if (newLevel == level) break; Chris@137: level = newLevel; Chris@137: if (++count == 50) break; Chris@137: } Chris@137: } else { Chris@137: // if we have no particular constraints, we can really spread out Chris@137: while (true) { Chris@137: if (getZoomLevel() >= level) current = count; Chris@137: int step = level / 10; Chris@137: int pwr = 0; Chris@137: while (step > 0) { Chris@137: ++pwr; Chris@137: step /= 2; Chris@137: } Chris@137: step = 1; Chris@137: while (pwr > 0) { Chris@137: step *= 2; Chris@137: --pwr; Chris@137: } Chris@154: // std::cerr << level << std::endl; Chris@137: level += step; Chris@137: if (++count == 100 || level > 262144) break; Chris@137: } Chris@133: } Chris@133: Chris@133: // std::cerr << "Have " << count << " zoom levels" << std::endl; Chris@133: Chris@133: m_hthumb->setMinimumValue(0); Chris@133: m_hthumb->setMaximumValue(count); Chris@133: m_hthumb->setValue(count - current); Chris@133: Chris@133: // std::cerr << "set value to " << count-current << std::endl; Chris@133: Chris@133: // std::cerr << "default value is " << m_hthumb->getDefaultValue() << std::endl; Chris@133: Chris@133: if (count != 50 && m_hthumb->getDefaultValue() == 0) { Chris@133: m_hthumb->setDefaultValue(count - current); Chris@133: // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl; Chris@133: } Chris@133: Chris@133: Layer *layer = 0; 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: m_vthumb->hide(); Chris@133: } else { Chris@133: m_vthumb->show(); 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@135: Chris@135: std::cerr << "Vertical thumbwheel: min 0, max " << max Chris@135: << ", default " << defaultStep << ", value " Chris@135: << m_vthumb->getValue() << std::endl; Chris@135: Chris@133: } Chris@133: } Chris@133: Chris@133: if (m_manager && m_manager->getZoomWheelsEnabled() && Chris@133: width() > 120 && height() > 100) { Chris@133: if (m_vthumb->isVisible()) { Chris@133: m_headsUpDisplay->move(width() - 86, height() - 86); Chris@133: } else { Chris@133: m_headsUpDisplay->move(width() - 86, height() - 51); Chris@133: } Chris@133: if (!m_headsUpDisplay->isVisible()) { Chris@133: m_headsUpDisplay->show(); Chris@133: connect(m_manager, SIGNAL(zoomLevelChanged()), Chris@133: this, SLOT(zoomLevelChanged())); Chris@133: } Chris@133: } else { Chris@133: m_headsUpDisplay->hide(); Chris@133: if (m_manager) { Chris@133: disconnect(m_manager, SIGNAL(zoomLevelChanged()), Chris@133: this, SLOT(zoomLevelChanged())); Chris@133: } Chris@133: } Chris@127: } Chris@127: 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@127: if (layer == getSelectedLayer() && Chris@127: !shouldIlluminateLocalSelection(discard, b0, b1)) { Chris@127: Chris@127: pos = m_identifyPoint; Chris@127: 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@127: bool &closeToLeft, Chris@127: bool &closeToRight) const Chris@127: { Chris@127: if (m_identifyFeatures && Chris@127: m_manager && Chris@127: m_manager->getToolMode() == ViewManager::EditMode && Chris@127: !m_manager->getSelections().empty() && Chris@127: !selectionIsBeingEdited()) { Chris@127: Chris@127: Selection s(getSelectionAt(m_identifyPoint.x(), Chris@127: closeToLeft, closeToRight)); Chris@127: Chris@127: if (!s.isEmpty()) { Chris@127: if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { Chris@127: Chris@127: pos = m_identifyPoint; Chris@127: return true; Chris@127: } Chris@127: } Chris@127: } 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@127: if (m_mousePos != m_clickPos && Chris@127: getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { Chris@127: return true; Chris@127: } 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@127: Chris@127: if (e) { Chris@127: r = e->rect(); Chris@127: } Chris@127: /* Chris@127: paint.begin(this); Chris@127: paint.setClipRect(r); Chris@127: Chris@127: if (hasLightBackground()) { Chris@127: paint.setPen(Qt::white); Chris@127: paint.setBrush(Qt::white); Chris@127: } else { Chris@127: paint.setPen(Qt::black); Chris@127: paint.setBrush(Qt::black); Chris@127: } Chris@127: paint.drawRect(r); Chris@127: Chris@127: paint.end(); Chris@127: */ Chris@127: View::paintEvent(e); Chris@127: Chris@127: paint.begin(this); Chris@127: Chris@127: if (e) { Chris@127: paint.setClipRect(r); Chris@127: } Chris@127: Chris@127: const Model *waveformModel = 0; // just for reporting purposes Chris@127: int verticalScaleWidth = 0; Chris@127: Chris@127: int fontHeight = paint.fontMetrics().height(); Chris@127: int fontAscent = paint.fontMetrics().ascent(); Chris@127: Chris@127: if (m_manager && Chris@127: !m_manager->isPlaying() && Chris@127: m_manager->getToolMode() == ViewManager::SelectMode) { Chris@127: Chris@127: for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { Chris@127: --vi; Chris@127: Chris@127: std::vector crosshairExtents; Chris@127: Chris@127: if ((*vi)->getCrosshairExtents(this, paint, m_identifyPoint, Chris@127: crosshairExtents)) { Chris@127: (*vi)->paintCrosshairs(this, paint, m_identifyPoint); Chris@127: break; Chris@127: } else if ((*vi)->isLayerOpaque()) { Chris@127: break; Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) { Chris@127: --vi; Chris@127: Chris@127: if (dynamic_cast(*vi)) { Chris@127: waveformModel = (*vi)->getModel(); Chris@127: } Chris@127: Chris@127: if (!m_manager || Chris@127: m_manager->getOverlayMode() == ViewManager::NoOverlays) { Chris@127: break; Chris@127: } Chris@127: Chris@127: verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint); Chris@127: Chris@127: if (verticalScaleWidth > 0 && r.left() < verticalScaleWidth) { Chris@127: Chris@127: // Profiler profiler("Pane::paintEvent - painting vertical scale", true); Chris@127: Chris@127: // std::cerr << "Pane::paintEvent: calling paint.save() in vertical scale block" << std::endl; Chris@127: paint.save(); Chris@127: Chris@127: paint.setPen(Qt::black); Chris@127: paint.setBrush(Qt::white); Chris@127: paint.drawRect(0, -1, verticalScaleWidth, height()+1); Chris@127: Chris@127: paint.setBrush(Qt::NoBrush); Chris@127: (*vi)->paintVerticalScale Chris@127: (this, paint, QRect(0, 0, verticalScaleWidth, height())); Chris@127: Chris@127: paint.restore(); Chris@127: } Chris@127: Chris@127: if (m_identifyFeatures) { Chris@127: Chris@127: QPoint pos = m_identifyPoint; Chris@127: QString desc = (*vi)->getFeatureDescription(this, pos); Chris@127: Chris@127: if (desc != "") { Chris@127: Chris@127: paint.save(); Chris@127: Chris@127: int tabStop = Chris@127: paint.fontMetrics().width(tr("Some lengthy prefix:")); Chris@127: Chris@127: QRect boundingRect = Chris@127: paint.fontMetrics().boundingRect Chris@127: (rect(), Chris@127: Qt::AlignRight | Qt::AlignTop | Qt::TextExpandTabs, Chris@127: desc, tabStop); Chris@127: Chris@127: if (hasLightBackground()) { Chris@127: paint.setPen(Qt::NoPen); Chris@127: paint.setBrush(QColor(250, 250, 250, 200)); Chris@127: } else { Chris@127: paint.setPen(Qt::NoPen); Chris@127: paint.setBrush(QColor(50, 50, 50, 200)); Chris@127: } Chris@127: Chris@127: int extra = paint.fontMetrics().descent(); Chris@127: paint.drawRect(width() - boundingRect.width() - 10 - extra, Chris@127: 10 - extra, Chris@127: boundingRect.width() + 2 * extra, Chris@127: boundingRect.height() + extra); Chris@127: Chris@127: if (hasLightBackground()) { Chris@127: paint.setPen(QColor(150, 20, 0)); Chris@127: } else { Chris@127: paint.setPen(QColor(255, 150, 100)); Chris@127: } Chris@127: Chris@127: QTextOption option; Chris@127: option.setWrapMode(QTextOption::NoWrap); Chris@127: option.setAlignment(Qt::AlignRight | Qt::AlignTop); Chris@127: option.setTabStop(tabStop); Chris@127: paint.drawText(QRectF(width() - boundingRect.width() - 10, 10, Chris@127: boundingRect.width(), Chris@127: boundingRect.height()), Chris@127: desc, Chris@127: option); Chris@127: Chris@127: paint.restore(); Chris@127: } Chris@127: } Chris@127: Chris@127: break; Chris@127: } Chris@127: Chris@127: int sampleRate = getModelsSampleRate(); Chris@127: paint.setBrush(Qt::NoBrush); Chris@127: Chris@127: if (m_centreLineVisible) { Chris@127: Chris@127: if (hasLightBackground()) { Chris@127: paint.setPen(QColor(50, 50, 50)); Chris@127: } else { Chris@127: paint.setPen(QColor(200, 200, 200)); Chris@127: } Chris@127: paint.drawLine(width() / 2, 0, width() / 2, height() - 1); Chris@127: Chris@127: paint.setPen(QColor(50, 50, 50)); Chris@127: Chris@127: int y = height() - fontHeight Chris@127: + fontAscent - 6; Chris@127: Chris@127: LayerList::iterator vi = m_layers.end(); Chris@127: Chris@127: if (vi != m_layers.begin()) { Chris@127: Chris@127: switch ((*--vi)->getPreferredFrameCountPosition()) { Chris@127: Chris@127: case Layer::PositionTop: Chris@127: y = fontAscent + 6; Chris@127: break; Chris@127: Chris@127: case Layer::PositionMiddle: Chris@127: y = (height() - fontHeight) / 2 Chris@127: + fontAscent; Chris@127: break; Chris@127: Chris@127: case Layer::PositionBottom: Chris@127: // y already set correctly Chris@127: break; Chris@127: } Chris@127: } Chris@127: Chris@127: if (m_manager && Chris@127: m_manager->getOverlayMode() != ViewManager::NoOverlays) { Chris@127: Chris@127: if (sampleRate) { Chris@127: Chris@127: QString text(QString::fromStdString Chris@127: (RealTime::frame2RealTime Chris@127: (m_centreFrame, sampleRate).toText(true))); Chris@127: Chris@127: int tw = paint.fontMetrics().width(text); Chris@127: int x = width()/2 - 4 - tw; Chris@127: Chris@127: drawVisibleText(paint, x, y, text, OutlinedText); Chris@127: } Chris@127: Chris@127: QString text = QString("%1").arg(m_centreFrame); Chris@127: Chris@127: int tw = paint.fontMetrics().width(text); Chris@127: int x = width()/2 + 4; Chris@127: Chris@127: drawVisibleText(paint, x, y, text, OutlinedText); Chris@127: } Chris@127: Chris@127: } else { Chris@127: Chris@127: paint.setPen(QColor(50, 50, 50)); Chris@127: } Chris@127: Chris@127: if (waveformModel && Chris@127: m_manager && Chris@127: m_manager->getOverlayMode() != ViewManager::NoOverlays && Chris@127: r.y() + r.height() >= height() - fontHeight - 6) { Chris@127: Chris@150: size_t modelRate = waveformModel->getSampleRate(); Chris@127: size_t mainModelRate = m_manager->getMainModelSampleRate(); Chris@127: size_t playbackRate = m_manager->getPlaybackSampleRate(); Chris@127: Chris@127: QString srNote = ""; Chris@127: Chris@127: // Show (R) for waveform models that will be resampled on Chris@127: // playback, and (X) for waveform models that will be played Chris@127: // at the wrong rate because their rate differs from that of Chris@127: // the main model. Chris@127: Chris@150: if (modelRate == mainModelRate) { Chris@150: if (modelRate != playbackRate) srNote = " " + tr("(R)"); Chris@127: } else { Chris@150: // std::cerr << "Sample rate = " << modelRate << ", main model rate = " << mainModelRate << std::endl; Chris@127: srNote = " " + tr("(X)"); Chris@127: } Chris@127: Chris@127: QString desc = tr("%1 / %2Hz%3") Chris@127: .arg(RealTime::frame2RealTime(waveformModel->getEndFrame(), Chris@127: sampleRate) Chris@127: .toText(false).c_str()) Chris@150: .arg(modelRate) Chris@127: .arg(srNote); Chris@127: Chris@127: if (r.x() < verticalScaleWidth + 5 + paint.fontMetrics().width(desc)) { Chris@127: drawVisibleText(paint, verticalScaleWidth + 5, Chris@127: height() - fontHeight + fontAscent - 6, Chris@127: desc, OutlinedText); Chris@127: } Chris@127: } Chris@127: Chris@127: if (m_manager && Chris@127: m_manager->getOverlayMode() == ViewManager::AllOverlays && Chris@127: r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) { Chris@127: Chris@127: std::vector texts; Chris@127: int maxTextWidth = 0; Chris@127: Chris@127: for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { Chris@127: Chris@127: QString text = (*i)->getLayerPresentationName(); Chris@127: int tw = paint.fontMetrics().width(text); Chris@127: bool reduced = false; Chris@127: while (tw > width() / 3 && text.length() > 4) { Chris@127: if (!reduced && text.length() > 8) { Chris@127: text = text.left(text.length() - 4); Chris@127: } else { Chris@127: text = text.left(text.length() - 2); Chris@127: } Chris@127: reduced = true; Chris@127: tw = paint.fontMetrics().width(text + "..."); Chris@127: } Chris@127: if (reduced) { Chris@127: texts.push_back(text + "..."); Chris@127: } else { Chris@127: texts.push_back(text); Chris@127: } Chris@127: if (tw > maxTextWidth) maxTextWidth = tw; Chris@127: } Chris@127: Chris@127: int lly = height() - 6; Chris@133: int llx = width() - maxTextWidth - 5; Chris@127: Chris@133: if (m_manager->getZoomWheelsEnabled()) { Chris@133: lly -= 20; Chris@133: llx -= 20; Chris@133: } Chris@133: Chris@133: if (r.x() + r.width() >= llx) { Chris@127: Chris@127: for (int i = 0; i < texts.size(); ++i) { Chris@127: Chris@127: if (i == texts.size() - 1) { Chris@127: paint.setPen(Qt::black); Chris@127: } Chris@127: Chris@133: drawVisibleText(paint, llx, Chris@127: lly - fontHeight + fontAscent, Chris@127: texts[i], OutlinedText); Chris@127: Chris@127: lly -= fontHeight; Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: if (m_clickedInRange && m_shiftPressed) { Chris@127: if (m_manager && (m_manager->getToolMode() == ViewManager::NavigateMode)) { Chris@127: //!!! be nice if this looked a bit more in keeping with the Chris@127: //selection block Chris@127: paint.setPen(Qt::blue); Chris@127: paint.drawRect(m_clickPos.x(), m_clickPos.y(), Chris@127: m_mousePos.x() - m_clickPos.x(), Chris@127: m_mousePos.y() - m_clickPos.y()); Chris@127: } Chris@127: } Chris@127: Chris@127: if (selectionIsBeingEdited()) { Chris@127: Chris@127: int offset = m_mousePos.x() - m_clickPos.x(); Chris@127: int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; Chris@127: int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; Chris@127: Chris@127: if (m_editingSelectionEdge < 0) { Chris@127: p1 = getXForFrame(m_editingSelection.getEndFrame()); Chris@127: } else if (m_editingSelectionEdge > 0) { Chris@127: p0 = getXForFrame(m_editingSelection.getStartFrame()); Chris@127: } Chris@127: Chris@127: paint.save(); Chris@127: if (hasLightBackground()) { Chris@127: paint.setPen(QPen(Qt::black, 2)); Chris@127: } else { Chris@127: paint.setPen(QPen(Qt::white, 2)); Chris@127: } Chris@127: Chris@127: //!!! duplicating display policy with View::drawSelections Chris@127: Chris@127: if (m_editingSelectionEdge < 0) { Chris@127: paint.drawLine(p0, 1, p1, 1); Chris@127: paint.drawLine(p0, 0, p0, height()); Chris@127: paint.drawLine(p0, height() - 1, p1, height() - 1); Chris@127: } else if (m_editingSelectionEdge > 0) { Chris@127: paint.drawLine(p0, 1, p1, 1); Chris@127: paint.drawLine(p1, 0, p1, height()); Chris@127: paint.drawLine(p0, height() - 1, p1, height() - 1); Chris@127: } else { Chris@127: paint.setBrush(Qt::NoBrush); Chris@127: paint.drawRect(p0, 1, p1 - p0, height() - 2); Chris@127: } Chris@127: paint.restore(); Chris@127: } Chris@127: Chris@127: paint.end(); Chris@127: } Chris@127: 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@127: long testFrame = getFrameForX(x - 5); Chris@127: if (testFrame < 0) { Chris@127: testFrame = getFrameForX(x); Chris@127: 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@127: int fuzz = 2; Chris@127: if (x < lx - fuzz || x > rx + fuzz) return Selection(); Chris@127: Chris@127: int width = rx - lx; Chris@127: fuzz = 3; Chris@127: if (width < 12) fuzz = width / 4; Chris@127: if (fuzz < 1) fuzz = 1; 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@127: void Chris@127: Pane::mousePressEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@127: emit rightButtonMenuRequested(mapToGlobal(e->pos())); Chris@127: return; Chris@127: } Chris@127: Chris@127: m_clickPos = e->pos(); 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@150: m_dragMode = UnresolvedDrag; Chris@127: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@127: if (m_manager) mode = m_manager->getToolMode(); Chris@127: Chris@127: m_navigating = false; Chris@127: Chris@127: if (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)) { Chris@127: Chris@127: if (mode != ViewManager::NavigateMode) { Chris@127: setCursor(Qt::PointingHandCursor); Chris@127: } Chris@127: Chris@127: m_navigating = true; Chris@127: m_dragCentreFrame = m_centreFrame; Chris@127: Chris@136: //!!! pull out into function to go with mouse move code Chris@136: Chris@136: m_dragStartMinValue = 0; Chris@136: Chris@136: Layer *layer = 0; Chris@136: if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); Chris@136: Chris@136: if (layer) { Chris@136: float min = 0.f, max = 0.f; Chris@136: if (layer->getDisplayExtents(min, max)) { Chris@136: m_dragStartMinValue = min; Chris@136: } Chris@136: } Chris@136: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@127: bool closeToLeft = false, closeToRight = false; Chris@127: Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); Chris@127: Chris@127: if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { Chris@127: Chris@127: m_manager->removeSelection(selection); Chris@127: Chris@127: if (closeToLeft) { Chris@127: m_selectionStartFrame = selection.getEndFrame(); Chris@127: } else { Chris@127: m_selectionStartFrame = selection.getStartFrame(); Chris@127: } Chris@127: Chris@127: m_manager->setInProgressSelection(selection, false); Chris@127: m_resizing = true; Chris@127: Chris@127: } else { Chris@127: Chris@127: int mouseFrame = getFrameForX(e->x()); Chris@127: size_t resolution = 1; Chris@127: int snapFrame = mouseFrame; Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && !m_shiftPressed) { Chris@127: layer->snapToFeatureFrame(this, snapFrame, Chris@127: resolution, Layer::SnapLeft); Chris@127: } Chris@127: Chris@127: if (snapFrame < 0) snapFrame = 0; Chris@127: m_selectionStartFrame = snapFrame; Chris@127: if (m_manager) { Chris@127: m_manager->setInProgressSelection(Selection(snapFrame, Chris@127: snapFrame + resolution), Chris@127: !m_ctrlPressed); Chris@127: } Chris@127: Chris@127: m_resizing = false; Chris@127: } Chris@127: Chris@127: update(); Chris@127: Chris@127: } else if (mode == ViewManager::DrawMode) { Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->drawStart(this, e); Chris@127: } Chris@127: Chris@127: } else if (mode == ViewManager::EditMode) { Chris@127: Chris@127: if (!editSelectionStart(e)) { Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->editStart(this, e); Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::mouseReleaseEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@127: return; Chris@127: } Chris@127: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@127: if (m_manager) mode = m_manager->getToolMode(); Chris@127: Chris@127: if (m_clickedInRange) { Chris@127: mouseMoveEvent(e); Chris@127: } Chris@127: Chris@127: if (m_navigating || mode == ViewManager::NavigateMode) { Chris@127: Chris@127: m_navigating = false; Chris@127: Chris@127: if (mode != ViewManager::NavigateMode) { Chris@127: // restore cursor Chris@127: toolModeChanged(); Chris@127: } Chris@127: Chris@127: if (m_shiftPressed) { Chris@127: Chris@127: int x0 = std::min(m_clickPos.x(), m_mousePos.x()); Chris@127: int x1 = std::max(m_clickPos.x(), m_mousePos.x()); Chris@127: int w = x1 - x0; Chris@127: Chris@127: int y0 = std::min(m_clickPos.y(), m_mousePos.y()); Chris@127: int y1 = std::max(m_clickPos.y(), m_mousePos.y()); Chris@127: // int h = y1 - y0; Chris@127: Chris@127: long newStartFrame = getFrameForX(x0); Chris@127: Chris@127: long visibleFrames = getEndFrame() - getStartFrame(); Chris@127: if (newStartFrame <= -visibleFrames) { Chris@127: newStartFrame = -visibleFrames + 1; Chris@127: } Chris@127: Chris@127: if (newStartFrame >= long(getModelsEndFrame())) { Chris@127: newStartFrame = getModelsEndFrame() - 1; Chris@127: } Chris@127: Chris@127: float ratio = float(w) / float(width()); Chris@127: // std::cerr << "ratio: " << ratio << std::endl; Chris@127: size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio); Chris@127: if (newZoomLevel < 1) newZoomLevel = 1; Chris@127: Chris@127: // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; Chris@127: setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); Chris@127: setStartFrame(newStartFrame); Chris@127: Chris@127: //!!! lots of faff, shouldn't be here Chris@127: Chris@127: QString unit; Chris@127: float min, max; Chris@127: bool log; Chris@127: Layer *layer = 0; Chris@127: for (LayerList::const_iterator i = m_layers.begin(); Chris@127: i != m_layers.end(); ++i) { Chris@127: if ((*i)->getValueExtents(min, max, log, unit) && Chris@127: (*i)->getDisplayExtents(min, max)) { Chris@127: layer = *i; Chris@127: break; Chris@127: } Chris@127: } Chris@127: Chris@127: if (layer) { Chris@127: if (log) { Chris@127: min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min); Chris@127: max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max); Chris@127: } Chris@127: float rmin = min + ((max - min) * (height() - y1)) / height(); Chris@127: float rmax = min + ((max - min) * (height() - y0)) / height(); Chris@127: std::cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << std::endl; Chris@127: if (log) { Chris@127: rmin = powf(10, rmin); Chris@127: rmax = powf(10, rmax); Chris@127: } Chris@127: std::cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit.toStdString() << std::endl; Chris@127: Chris@127: layer->setDisplayExtents(rmin, rmax); Chris@127: } Chris@127: Chris@127: //cerr << "mouseReleaseEvent: start frame now " << m_startFrame << endl; Chris@127: // update(); Chris@127: } Chris@127: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@127: if (m_manager && m_manager->haveInProgressSelection()) { Chris@127: Chris@127: bool exclusive; Chris@127: Selection selection = m_manager->getInProgressSelection(exclusive); Chris@127: Chris@127: if (selection.getEndFrame() < selection.getStartFrame() + 2) { Chris@127: selection = Selection(); Chris@127: } Chris@127: Chris@127: m_manager->clearInProgressSelection(); Chris@127: Chris@127: if (exclusive) { Chris@127: m_manager->setSelection(selection); Chris@127: } else { Chris@127: m_manager->addSelection(selection); Chris@127: } Chris@127: } Chris@127: Chris@127: update(); Chris@127: Chris@127: } else if (mode == ViewManager::DrawMode) { Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->drawEnd(this, e); Chris@127: update(); Chris@127: } Chris@127: Chris@127: } else if (mode == ViewManager::EditMode) { Chris@127: Chris@127: if (!editSelectionEnd(e)) { Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->editEnd(this, e); Chris@127: update(); Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: m_clickedInRange = false; Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::mouseMoveEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@127: return; Chris@127: } Chris@127: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@127: if (m_manager) mode = m_manager->getToolMode(); Chris@127: Chris@127: QPoint prevPoint = m_identifyPoint; Chris@127: m_identifyPoint = e->pos(); Chris@127: Chris@127: if (!m_clickedInRange) { Chris@127: Chris@127: if (mode == ViewManager::SelectMode) { Chris@127: bool closeToLeft = false, closeToRight = false; Chris@127: getSelectionAt(e->x(), closeToLeft, closeToRight); Chris@127: if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { Chris@127: setCursor(Qt::SizeHorCursor); Chris@127: } else { Chris@127: setCursor(Qt::ArrowCursor); Chris@127: } Chris@127: } Chris@127: Chris@127: //!!! if (mode != ViewManager::DrawMode) { Chris@127: Chris@127: if (!m_manager->isPlaying()) { Chris@127: Chris@127: if (getSelectedLayer()) { Chris@127: Chris@127: bool previouslyIdentifying = m_identifyFeatures; Chris@127: m_identifyFeatures = true; Chris@127: Chris@127: if (m_identifyFeatures != previouslyIdentifying || Chris@127: m_identifyPoint != prevPoint) { Chris@127: update(); Chris@127: } Chris@127: } Chris@127: Chris@127: } Chris@127: Chris@127: // } Chris@127: Chris@127: return; Chris@127: } Chris@127: Chris@127: if (m_navigating || mode == ViewManager::NavigateMode) { Chris@127: Chris@127: if (m_shiftPressed) { Chris@127: Chris@127: m_mousePos = e->pos(); Chris@127: update(); Chris@127: Chris@127: } else { Chris@127: Chris@145: //!!! want to do some cleverness to avoid dragging left/right Chris@145: // at the same time as up/down when the user moves the mouse Chris@145: // diagonally. Chris@145: // e.g. have horizontal and vertical thresholds and a series Chris@145: // of states: unknown, constrained, free Chris@145: // Chris@145: // -> when the mouse first moves we're in unknown state: Chris@145: // what then? the thing we really want to avoid is moving Chris@145: // a tiny amount in the wrong direction, because usually Chris@145: // the problem is that to move at all is expensive -- so what Chris@145: // do we do? Chris@145: // Chris@145: // -> when it's moved more than say 10px in h or v Chris@145: // direction we lock into h or v constrained mode. If it Chris@145: // moves more than say 20px in the other direction Chris@145: // subsequently, then we switch into free mode. Chris@145: Chris@150: int xdiff = e->x() - m_clickPos.x(); Chris@150: int ydiff = e->y() - m_clickPos.y(); Chris@150: int smallThreshold = 10, bigThreshold = 50; Chris@136: Chris@150: bool canMoveVertical = true; Chris@150: bool canMoveHorizontal = true; Chris@136: Chris@150: //!!! need to test whether the layer is actually draggable Chris@150: // vertically before we do any of this Chris@136: Chris@150: if (m_dragMode == UnresolvedDrag) { Chris@136: Chris@150: if (abs(ydiff) > smallThreshold && Chris@150: abs(ydiff) > abs(xdiff) * 2) { Chris@150: m_dragMode = VerticalDrag; Chris@150: } else if (abs(xdiff) > smallThreshold && Chris@150: abs(xdiff) > abs(ydiff) * 2) { Chris@150: m_dragMode = HorizontalDrag; Chris@150: } else if (abs(xdiff) > smallThreshold && Chris@150: abs(ydiff) > smallThreshold) { Chris@150: m_dragMode = FreeDrag; Chris@150: } else { Chris@150: // When playing, we don't want to disturb the play Chris@150: // position too easily; when not playing, we don't Chris@150: // want to move up/down too easily Chris@150: if (m_manager && m_manager->isPlaying()) { Chris@150: canMoveHorizontal = false; Chris@150: } else { Chris@150: canMoveVertical = false; Chris@136: } Chris@136: } Chris@136: } Chris@150: Chris@150: if (m_dragMode == VerticalDrag) { Chris@150: if (abs(xdiff) > bigThreshold) m_dragMode = FreeDrag; Chris@150: else canMoveHorizontal = false; Chris@150: } Chris@150: Chris@150: if (m_dragMode == HorizontalDrag) { Chris@150: if (abs(ydiff) > bigThreshold) m_dragMode = FreeDrag; Chris@150: else canMoveVertical = false; Chris@150: } Chris@150: Chris@150: if (canMoveHorizontal) { Chris@150: Chris@150: long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); Chris@150: Chris@150: size_t newCentreFrame = m_dragCentreFrame; Chris@150: Chris@150: if (frameOff < 0) { Chris@150: newCentreFrame -= frameOff; Chris@150: } else if (newCentreFrame >= size_t(frameOff)) { Chris@150: newCentreFrame -= frameOff; Chris@150: } else { Chris@150: newCentreFrame = 0; Chris@150: } Chris@150: Chris@150: if (newCentreFrame >= getModelsEndFrame()) { Chris@150: newCentreFrame = getModelsEndFrame(); Chris@150: if (newCentreFrame > 0) --newCentreFrame; Chris@150: } Chris@150: Chris@150: if (getXForFrame(m_centreFrame) != getXForFrame(newCentreFrame)) { Chris@150: setCentreFrame(newCentreFrame); Chris@150: } Chris@150: } Chris@150: Chris@150: //!!! For drag up/down, we need to: call getValueExtents Chris@150: //and getDisplayExtents and see whether both return true Chris@150: //(we can only drag up/down if they do); and check whether Chris@150: //the ranges returned differ (likewise). Then, we know Chris@150: //the height of the layer, so... Chris@150: Chris@150: //!!! this should have its own function Chris@150: Chris@150: if (canMoveVertical) { Chris@150: Chris@150: Layer *layer = 0; Chris@150: if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); Chris@150: Chris@150: if (layer) { Chris@150: Chris@150: float vmin = 0.f, vmax = 0.f; Chris@150: bool vlog = false; Chris@150: QString vunit; Chris@150: Chris@150: float dmin = 0.f, dmax = 0.f; Chris@150: Chris@150: if (layer->getValueExtents(vmin, vmax, vlog, vunit) && Chris@150: layer->getDisplayExtents(dmin, dmax) && Chris@150: (dmin > vmin || dmax < vmax)) { Chris@150: Chris@150: std::cerr << "ydiff = " << ydiff << std::endl; Chris@150: Chris@150: float perpix = (dmax - dmin) / height(); Chris@150: float valdiff = ydiff * perpix; Chris@150: std::cerr << "valdiff = " << valdiff << std::endl; Chris@150: Chris@150: float newmin = m_dragStartMinValue + valdiff; Chris@150: float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; Chris@150: if (newmin < vmin) { Chris@150: newmax += vmin - newmin; Chris@150: newmin += vmin - newmin; Chris@150: } Chris@150: if (newmax > vmax) { Chris@150: newmin -= newmax - vmax; Chris@150: newmax -= newmax - vmax; Chris@150: } Chris@150: std::cerr << "(" << dmin << ", " << dmax << ") -> (" Chris@150: << newmin << ", " << newmax << ") (drag start " << m_dragStartMinValue << ")" << std::endl; Chris@150: layer->setDisplayExtents(newmin, newmax); Chris@150: } Chris@150: } Chris@150: } Chris@150: } Chris@127: Chris@127: } else if (mode == ViewManager::SelectMode) { Chris@127: Chris@127: int mouseFrame = getFrameForX(e->x()); Chris@127: size_t resolution = 1; Chris@127: int snapFrameLeft = mouseFrame; Chris@127: int snapFrameRight = mouseFrame; Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && !m_shiftPressed) { Chris@127: layer->snapToFeatureFrame(this, snapFrameLeft, Chris@127: resolution, Layer::SnapLeft); Chris@127: layer->snapToFeatureFrame(this, snapFrameRight, Chris@127: resolution, Layer::SnapRight); Chris@127: } Chris@127: Chris@127: // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; Chris@127: Chris@127: if (snapFrameLeft < 0) snapFrameLeft = 0; Chris@127: if (snapFrameRight < 0) snapFrameRight = 0; Chris@127: Chris@127: size_t min, max; Chris@127: Chris@127: if (m_selectionStartFrame > snapFrameLeft) { Chris@127: min = snapFrameLeft; Chris@127: max = m_selectionStartFrame; Chris@127: } else if (snapFrameRight > m_selectionStartFrame) { Chris@127: min = m_selectionStartFrame; Chris@127: max = snapFrameRight; Chris@127: } else { Chris@127: min = snapFrameLeft; Chris@127: max = snapFrameRight; Chris@127: } Chris@127: Chris@127: if (m_manager) { Chris@127: m_manager->setInProgressSelection(Selection(min, max), Chris@127: !m_resizing && !m_ctrlPressed); Chris@127: } Chris@127: Chris@127: bool doScroll = false; Chris@127: if (!m_manager) doScroll = true; Chris@127: if (!m_manager->isPlaying()) doScroll = true; Chris@127: if (m_followPlay != PlaybackScrollContinuous) doScroll = true; Chris@127: Chris@127: if (doScroll) { Chris@127: int offset = mouseFrame - getStartFrame(); Chris@127: int available = getEndFrame() - getStartFrame(); Chris@127: if (offset >= available * 0.95) { Chris@127: int move = int(offset - available * 0.95) + 1; Chris@127: setCentreFrame(m_centreFrame + move); Chris@127: } else if (offset <= available * 0.10) { Chris@127: int move = int(available * 0.10 - offset) + 1; Chris@127: if (m_centreFrame > move) { Chris@127: setCentreFrame(m_centreFrame - move); Chris@127: } else { Chris@127: setCentreFrame(0); Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: update(); Chris@127: Chris@127: } else if (mode == ViewManager::DrawMode) { Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->drawDrag(this, e); Chris@127: } Chris@127: Chris@127: } else if (mode == ViewManager::EditMode) { Chris@127: Chris@127: if (!editSelectionDrag(e)) { Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->editDrag(this, e); Chris@127: } Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::mouseDoubleClickEvent(QMouseEvent *e) Chris@127: { Chris@127: if (e->buttons() & Qt::RightButton) { Chris@127: return; Chris@127: } Chris@127: Chris@127: // std::cerr << "mouseDoubleClickEvent" << std::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@127: Chris@127: ViewManager::ToolMode mode = ViewManager::NavigateMode; Chris@127: if (m_manager) mode = m_manager->getToolMode(); Chris@127: Chris@127: if (mode == ViewManager::NavigateMode || Chris@127: mode == ViewManager::EditMode) { Chris@127: Chris@127: Layer *layer = getSelectedLayer(); Chris@127: if (layer && layer->isLayerEditable()) { Chris@127: layer->editOpen(this, e); Chris@127: } Chris@127: } Chris@127: } Chris@127: Chris@127: void Chris@127: Pane::leaveEvent(QEvent *) Chris@127: { Chris@127: bool previouslyIdentifying = m_identifyFeatures; Chris@127: m_identifyFeatures = false; Chris@127: if (previouslyIdentifying) update(); 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: { Chris@127: //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; Chris@127: Chris@127: int count = e->delta(); Chris@127: Chris@127: if (count > 0) { Chris@127: if (count >= 120) count /= 120; Chris@127: else count = 1; Chris@127: } Chris@127: Chris@127: if (count < 0) { Chris@127: if (count <= -120) count /= 120; Chris@127: else count = -1; Chris@127: } Chris@127: Chris@127: if (e->modifiers() & Qt::ControlModifier) { Chris@127: Chris@127: // Scroll left or right, rapidly Chris@127: Chris@127: if (getStartFrame() < 0 && Chris@127: getEndFrame() >= getModelsEndFrame()) return; Chris@127: Chris@127: long delta = ((width() / 2) * count * m_zoomLevel); Chris@127: Chris@127: if (int(m_centreFrame) < delta) { Chris@127: setCentreFrame(0); Chris@127: } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { Chris@127: setCentreFrame(getModelsEndFrame()); Chris@127: } else { Chris@127: setCentreFrame(m_centreFrame - delta); Chris@127: } Chris@127: Chris@127: } else { Chris@127: Chris@127: // Zoom in or out Chris@127: Chris@127: int newZoomLevel = m_zoomLevel; Chris@127: Chris@127: while (count > 0) { Chris@127: if (newZoomLevel <= 2) { Chris@127: newZoomLevel = 1; Chris@127: break; Chris@127: } Chris@127: newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, Chris@127: ZoomConstraint::RoundDown); Chris@127: --count; Chris@127: } Chris@127: Chris@127: while (count < 0) { Chris@127: newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, Chris@127: ZoomConstraint::RoundUp); Chris@127: ++count; Chris@127: } Chris@127: Chris@127: if (newZoomLevel != m_zoomLevel) { Chris@127: setZoomLevel(newZoomLevel); Chris@127: } Chris@127: } Chris@127: Chris@127: emit paneInteractedWith(); Chris@127: } Chris@127: Chris@132: void Chris@132: Pane::horizontalThumbwheelMoved(int value) Chris@132: { Chris@137: //!!! dupe with updateHeadsUpDisplay Chris@137: Chris@132: int count = 0; Chris@132: int level = 1; Chris@137: Chris@137: Chris@137: //!!! pull out into function (presumably in View) Chris@137: bool haveConstraint = false; Chris@137: for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); Chris@137: ++i) { Chris@137: if ((*i)->getZoomConstraint() && !(*i)->supportsOtherZoomLevels()) { Chris@137: haveConstraint = true; Chris@137: break; Chris@137: } Chris@132: } Chris@132: Chris@137: if (haveConstraint) { Chris@137: while (true) { Chris@137: if (m_hthumb->getMaximumValue() - value == count) break; Chris@137: int newLevel = getZoomConstraintBlockSize(level + 1, Chris@137: ZoomConstraint::RoundUp); Chris@137: if (newLevel == level) break; Chris@137: level = newLevel; Chris@137: if (++count == 50) break; Chris@137: } Chris@137: } else { Chris@137: while (true) { Chris@137: if (m_hthumb->getMaximumValue() - value == count) break; Chris@137: int step = level / 10; Chris@137: int pwr = 0; Chris@137: while (step > 0) { Chris@137: ++pwr; Chris@137: step /= 2; Chris@137: } Chris@137: step = 1; Chris@137: while (pwr > 0) { Chris@137: step *= 2; Chris@137: --pwr; Chris@137: } Chris@137: // std::cerr << level << std::endl; Chris@137: level += step; Chris@137: if (++count == 100 || level > 262144) break; Chris@137: } Chris@137: } Chris@137: Chris@137: std::cerr << "new level is " << level << std::endl; Chris@132: setZoomLevel(level); Chris@132: } Chris@132: Chris@132: void Chris@132: Pane::verticalThumbwheelMoved(int value) Chris@132: { Chris@133: Layer *layer = 0; 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@133: } Chris@132: } Chris@132: Chris@127: bool Chris@127: Pane::editSelectionStart(QMouseEvent *e) Chris@127: { Chris@127: if (!m_identifyFeatures || Chris@127: !m_manager || Chris@127: m_manager->getToolMode() != ViewManager::EditMode) { Chris@127: 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@127: Pane::editSelectionEnd(QMouseEvent *e) Chris@127: { Chris@127: if (m_editingSelection.isEmpty()) return false; Chris@127: Chris@127: int offset = m_mousePos.x() - m_clickPos.x(); Chris@127: Layer *layer = getSelectedLayer(); Chris@127: Chris@127: if (offset == 0 || !layer) { Chris@127: m_editingSelection = Selection(); Chris@127: 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@127: long f0 = getFrameForX(p0); Chris@127: long f1 = getFrameForX(p1); Chris@127: Chris@127: Selection newSelection(f0, f1); Chris@127: Chris@127: if (m_editingSelectionEdge == 0) { Chris@127: Chris@127: CommandHistory::getInstance()->startCompoundOperation Chris@127: (tr("Drag Selection"), true); Chris@127: Chris@127: layer->moveSelection(m_editingSelection, f0); Chris@127: Chris@127: } else { Chris@127: Chris@127: CommandHistory::getInstance()->startCompoundOperation Chris@127: (tr("Resize Selection"), true); Chris@127: Chris@127: if (m_editingSelectionEdge < 0) { Chris@127: f1 = m_editingSelection.getEndFrame(); Chris@127: } else { Chris@127: f0 = m_editingSelection.getStartFrame(); Chris@127: } Chris@127: Chris@127: newSelection = Selection(f0, f1); Chris@127: 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@127: ViewManager::ToolMode mode = m_manager->getToolMode(); Chris@127: // std::cerr << "Pane::toolModeChanged(" << mode << ")" << std::endl; Chris@127: Chris@127: switch (mode) { Chris@127: Chris@127: case ViewManager::NavigateMode: Chris@127: setCursor(Qt::PointingHandCursor); Chris@127: break; Chris@127: Chris@127: case ViewManager::SelectMode: Chris@127: setCursor(Qt::ArrowCursor); Chris@127: break; Chris@127: Chris@127: case ViewManager::EditMode: Chris@127: setCursor(Qt::UpArrowCursor); Chris@127: break; Chris@127: Chris@127: case ViewManager::DrawMode: Chris@127: setCursor(Qt::CrossCursor); Chris@127: break; Chris@127: /* Chris@127: case ViewManager::TextMode: Chris@127: setCursor(Qt::IBeamCursor); Chris@127: 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@133: Pane::zoomLevelChanged() Chris@133: { 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@133: Layer *layer = 0; 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@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@133: Layer *layer = 0; 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@127: QString Chris@127: Pane::toXmlString(QString indent, QString extraAttributes) const Chris@127: { Chris@127: return View::toXmlString Chris@127: (indent, Chris@127: QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") Chris@127: .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); Chris@127: } Chris@127: Chris@127: Chris@127: #ifdef INCLUDE_MOCFILES Chris@127: #include "Pane.moc.cpp" Chris@127: #endif Chris@127: