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@338: #include "base/Preferences.h"
Chris@127: #include "layer/WaveformLayer.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 <QPaintEvent>
Chris@127: #include <QPainter>
Chris@257: #include <QBitmap>
Chris@312: #include <QDragEnterEvent>
Chris@312: #include <QDropEvent>
Chris@257: #include <QCursor>
Chris@316: #include <QTextStream>
Chris@616: #include <QMimeData>
Chris@316: 
Chris@127: #include <iostream>
Chris@127: #include <cmath>
Chris@127: 
Chris@133: //!!! for HUD -- pull out into a separate class
Chris@133: #include <QFrame>
Chris@133: #include <QGridLayout>
Chris@133: #include <QPushButton>
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@682: 
Chris@682: 
Chris@127: 
Chris@267: QCursor *Pane::m_measureCursor1 = 0;
Chris@267: QCursor *Pane::m_measureCursor2 = 0;
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@237:     m_headsUpDisplay(0),
Chris@237:     m_vpan(0),
Chris@237:     m_hthumb(0),
Chris@237:     m_vthumb(0),
Chris@290:     m_reset(0),
Chris@290:     m_mouseInWidget(false)
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@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@682:     cerr << "Have " << count+1 << " zoom levels" << endl;
Chris@132: */
Chris@133: 
Chris@188:     Layer *layer = 0;
Chris@188:     if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1);
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@133:         m_hthumb->setFixedWidth(70);
Chris@133:         m_hthumb->setFixedHeight(16);
Chris@133:         m_hthumb->setDefaultValue(0);
Chris@165:         m_hthumb->setSpeed(0.6);
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@173:         m_vpan->setFixedWidth(12);
Chris@172:         m_vpan->setFixedHeight(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@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@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@189:         m_reset->setFixedHeight(16);
Chris@189:         m_reset->setFixedWidth(16);
Chris@499:         m_reset->setIcon(QPixmap(":/icons/zoom-reset.png"));
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@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@682: //            cerr << level << endl;
Chris@137:             level += step;
Chris@137:             if (++count == 100 || level > 262144) break;
Chris@137:         }
Chris@133:     }
Chris@133: 
Chris@682: //    cerr << "Have " << count << " zoom levels" << 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@682: //    cerr << "set value to " << count-current << endl;
Chris@682: 
Chris@682: //    cerr << "default value is " << m_hthumb->getDefaultValue() << endl;
Chris@133: 
Chris@133:     if (count != 50 && m_hthumb->getDefaultValue() == 0) {
Chris@133:         m_hthumb->setDefaultValue(count - current);
Chris@682: //        cerr << "set default value to " << m_hthumb->getDefaultValue() << endl;
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@133:         width() > 120 && height() > 100) {
Chris@165:         if (!m_headsUpDisplay->isVisible()) {
Chris@165:             m_headsUpDisplay->show();
Chris@165:         }
Chris@204:         if (haveVThumb) {
Chris@204:             m_headsUpDisplay->setFixedHeight(m_vthumb->height() + m_hthumb->height());
Chris@133:             m_headsUpDisplay->move(width() - 86, height() - 86);
Chris@133:         } else {
Chris@204:             m_headsUpDisplay->setFixedHeight(m_hthumb->height());
Chris@204:             m_headsUpDisplay->move(width() - 86, height() - 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@208:     Layer *layer = 0;
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@174:     float vmin, vmax, dmin, dmax;
Chris@174:     if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) {
Chris@174:         float y0 = (dmin - vmin) / (vmax - vmin);
Chris@174:         float y1 = (dmax - vmin) / (vmax - vmin);
Chris@174:         m_vpan->blockSignals(true);
Chris@174:         m_vpan->setRectExtents(0, 1.0 - y1, 1, 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@127:     if (layer == getSelectedLayer() &&
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,
gyorgyf@645:                      bool &closeToLeft,
gyorgyf@645:                      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@753:             if (getSelectedLayer() && getSelectedLayer()->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()) {
gyorgyf@645:     if (m_mousePos != m_clickPos &&
gyorgyf@645:         getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) {
gyorgyf@645:         return true;
gyorgyf@645:     }
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@711:     ViewManager::ToolMode toolMode = m_manager->getToolModeFor(this);
Chris@259: 
Chris@127:     if (m_manager &&
Chris@290: //        !m_manager->isPlaying() &&
Chris@290:         m_mouseInWidget &&
Chris@259:         toolMode == ViewManager::MeasureMode) {
Chris@127: 
Chris@127:         for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127:             --vi;
Chris@127: 
Chris@127:             std::vector<QRect> 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@268:     Layer *topLayer = getTopLayer();
Chris@277:     bool haveSomeTimeXAxis = false;
Chris@268: 
Chris@258:     const Model *waveformModel = 0; // just for reporting purposes
Chris@326:     const Model *workModel = 0;
Chris@326: 
Chris@127:     for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@127:         --vi;
Chris@277:         if (!haveSomeTimeXAxis && (*vi)->hasTimeXAxis()) {
Chris@277:             haveSomeTimeXAxis = true;
Chris@277:         }
Chris@127:         if (dynamic_cast<WaveformLayer *>(*vi)) {
Chris@127:             waveformModel = (*vi)->getModel();
Chris@326:             workModel = waveformModel;
Chris@326:         } else {
Chris@326:             Model *m = (*vi)->getModel();
Chris@326:             if (dynamic_cast<WaveFileModel *>(m)) {
Chris@326:                 workModel = m;
Chris@326:             } else if (m && dynamic_cast<WaveFileModel *>(m->getSourceModel())) {
Chris@326:                 workModel = m->getSourceModel();
Chris@326:             }
Chris@127:         }
Chris@326:                 
Chris@326:         if (waveformModel && workModel && haveSomeTimeXAxis) break;
Chris@258:     }
Chris@127: 
Chris@261:     m_scaleWidth = 0;
Chris@261: 
Chris@759:     if (workModel) {
Chris@759:         drawModelTimeExtents(r, paint, workModel);
Chris@759:     }
Chris@759: 
Chris@261:     if (m_manager && m_manager->shouldShowVerticalScale() && topLayer) {
Chris@261:         drawVerticalScale(r, topLayer, paint);
Chris@261:     }
Chris@261: 
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@261:     int 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@261:         m_manager &&
Chris@261:         m_manager->shouldShowDuration()) {
Chris@261:         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@326:         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@326:         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@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@276: size_t
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@258:     Layer *scaleLayer = 0;
Chris@258: 
Chris@261:     float min, max;
Chris@261:     bool log;
Chris@261:     QString unit;
Chris@258: 
Chris@261:     // If the top layer has no scale and reports no display
Chris@261:     // extents, but does report a unit, then the scale should be
Chris@261:     // drawn from any underlying layer with a scale and that unit.
Chris@261:     // If the top layer has no scale and no value extents at all,
Chris@261:     // then the scale should be drawn from any underlying layer
Chris@261:     // with a scale regardless of unit.
Chris@258: 
Chris@607:     int sw = topLayer->getVerticalScaleWidth
Chris@607:         (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@258: 
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@261:                 for (LayerList::iterator vi = m_layers.end();
Chris@261:                      vi != m_layers.begin(); ) {
Chris@261:                         
Chris@261:                     --vi;
Chris@261:                         
Chris@261:                     if ((*vi) == topLayer) 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@261:                 for (LayerList::iterator vi = m_layers.end();
Chris@261:                      vi != m_layers.begin(); ) {
Chris@258:                         
Chris@261:                     --vi;
Chris@258:                         
Chris@261:                     if ((*vi) == topLayer) 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@258:         
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@287:         paint.setPen(getForeground());
Chris@287:         paint.setBrush(getBackground());
Chris@258:         paint.drawRect(0, -1, m_scaleWidth, height()+1);
Chris@258:         
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@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@277: Pane::drawCentreLine(int sampleRate, QPainter &paint, bool omitLine)
Chris@261: {
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@261:     paint.setPen(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@261:     LayerList::iterator vi = m_layers.end();
Chris@261:     
Chris@261:     if (vi != m_layers.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@127:             drawVisibleText(paint, x, y, text, 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@261:         drawVisibleText(paint, x, y, text, OutlinedText);
Chris@261:     }
Chris@261: }
Chris@127: 
Chris@261: void
Chris@759: Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model)
Chris@759: {
Chris@759:     int x0 = getXForFrame(model->getStartFrame());
Chris@759:     int x1 = getXForFrame(model->getEndFrame());
Chris@759: 
Chris@759:     int lw = 10;
Chris@759: 
Chris@759:     paint.save();
Chris@759: 
Chris@759:     QBrush brush;
Chris@759: 
Chris@759:     if (hasLightBackground()) {
Chris@759:         brush = QBrush(QColor("#f8f8f8"));
Chris@759:         paint.setPen(Qt::black);
Chris@759:     } else {
Chris@759:         brush = QBrush(QColor("#101010"));
Chris@759:         paint.setPen(Qt::white);
Chris@759:     }
Chris@759: 
Chris@759:     if (x0 > r.x()) {
Chris@759:         paint.fillRect(0, 0, x0, height(), brush);
Chris@759:         paint.drawLine(x0, 0, x0, height());
Chris@759:     }
Chris@759: 
Chris@759:     if (x1 < r.x() + r.width()) {
Chris@759:         paint.fillRect(x1, 0, width() - x1, height(), brush);
Chris@759:         paint.drawLine(x1, 0, x1, height());
Chris@759:     }
Chris@759: 
Chris@759:     paint.restore();
Chris@759: }
Chris@759: 
Chris@759: void
Chris@326: Pane::drawAlignmentStatus(QRect r, QPainter &paint, const Model *model,
Chris@326:                           bool down)
Chris@320: {
Chris@320:     const Model *reference = model->getAlignmentReference();
Chris@320: /*
Chris@320:     if (!reference) {
Chris@682:         cerr << "Pane[" << this << "]::drawAlignmentStatus: No reference" << endl;
Chris@320:     } else if (reference == model) {
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@320:     if (reference == model) {
Chris@320:         text = tr("Reference");
Chris@320:     } else if (!reference) {
Chris@320:         text = tr("Unaligned");
Chris@320:     } else {
Chris@320:         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@320:     drawVisibleText(paint, m_scaleWidth + 5,
Chris@326:                     paint.fontMetrics().ascent() + y, text, 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@326: Pane::drawWorkTitle(QRect r, QPainter &paint, const Model *model)
Chris@326: {
Chris@326:     QString title = model->getTitle();
Chris@326:     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@326:     drawVisibleText(paint, m_scaleWidth + 5,
Chris@326:                     paint.fontMetrics().ascent() + y, text, 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@300:     if (m_manager->getZoomWheelsEnabled()) {
Chris@300:         lly -= 20;
Chris@300:     }
Chris@300: 
Chris@300:     if (r.y() + r.height() < lly - int(m_layers.size()) * fontHeight) {
Chris@261:         return;
Chris@127:     }
Chris@127: 
Chris@294:     QStringList texts;
Chris@299:     std::vector<QPixmap> pixmaps;
Chris@294:     for (LayerList::iterator i = m_layers.begin(); i != m_layers.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@261:         llx -= 36;
Chris@261:     }
Chris@261:     
Chris@300:     if (r.x() + r.width() >= llx - fontAscent - 3) {
gyorgyf@645:     
Chris@261:         for (size_t 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@261:             drawVisibleText(paint, llx,
Chris@261:                             lly - fontHeight + fontAscent,
Chris@261:                             texts[i], 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@577:     long 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@577:     long newStart = getFrameForX(p0);
Chris@577:     long 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@577:     int 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@577:     drawVisibleText(paint, p0 + 2, fontAscent + fontHeight + 4, startText, OutlinedText);
Chris@577:     drawVisibleText(paint, p1 + 2, fontAscent + fontHeight + 4, endText, OutlinedText);
Chris@577:     drawVisibleText(paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText);
Chris@577:     drawVisibleText(paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, 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@261: Pane::drawDurationAndRate(QRect r, const Model *waveformModel,
Chris@261:                           int 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@261:     size_t modelRate = waveformModel->getSampleRate();
Chris@301:     size_t nativeRate = waveformModel->getNativeRate();
Chris@261:     size_t playbackRate = m_manager->getPlaybackSampleRate();
Chris@261:     size_t outputRate = m_manager->getOutputSampleRate();
Chris@261:         
Chris@261:     QString srNote = "";
Chris@127: 
Chris@301:     // Show (R) for waveform models that have been resampled or will
Chris@301:     // be resampled on playback, and (X) for waveform models that will
Chris@301:     // be played at the wrong rate because their rate differs from the
Chris@261:     // current playback rate (which is not necessarily that of the
Chris@261:     // main model).
Chris@127: 
Chris@261:     if (playbackRate != 0) {
Chris@261:         if (modelRate == playbackRate) {
Chris@301:             if (modelRate != outputRate || modelRate != nativeRate) {
Chris@301:                 srNote = " " + tr("(R)");
Chris@301:             }
Chris@261:         } else {
Chris@261:             srNote = " " + tr("(X)");
Chris@261:         }
Chris@127:     }
Chris@127: 
Chris@261:     QString desc = tr("%1 / %2Hz%3")
Chris@261:         .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@384:         drawVisibleText(paint, x,
Chris@261:                         height() - fontHeight + fontAscent - 6,
Chris@261:                         desc, OutlinedText);
Chris@261:     }
Chris@127: }
Chris@127: 
Chris@227: bool
Chris@229: Pane::render(QPainter &paint, int xorigin, size_t f0, size_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@227:         for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@227:             --vi;
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@227:             (*vi)->paintVerticalScale
Chris@607:                 (this, m_manager->shouldShowVerticalColourScale(),
Chris@607:                  paint, QRect(xorigin, 0, m_scaleWidth, height()));
Chris@227:             
Chris@227:             paint.restore();
Chris@227:             break;
Chris@227:         }
Chris@227:     }
Chris@227: 
Chris@227:     return true;
Chris@227: }
Chris@227: 
Chris@227: QImage *
Chris@229: Pane::toNewImage(size_t f0, size_t f1)
Chris@227: {
Chris@227:     size_t x0 = f0 / getZoomLevel();
Chris@227:     size_t x1 = f1 / getZoomLevel();
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@227:         for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@227:             --vi;
Chris@227:             QPainter paint(image);
Chris@607:             m_scaleWidth = (*vi)->getVerticalScaleWidth
Chris@607:                 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@227:             break;
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@227:         return 0;
Chris@227:     } else {
Chris@227:         delete paint;
Chris@227:         return image;
Chris@227:     }
Chris@227: }
Chris@227: 
Chris@229: QSize
Chris@229: Pane::getImageSize(size_t f0, size_t f1)
Chris@229: {
Chris@229:     QSize s = View::getImageSize(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@229:         for (LayerList::iterator vi = m_layers.end(); vi != m_layers.begin(); ) {
Chris@229:             --vi;
Chris@607:             sw = (*vi)->getVerticalScaleWidth
Chris@607:                 (this, m_manager->shouldShowVerticalColourScale(), paint);
Chris@229:             break;
Chris@229:         }
Chris@229:     }
Chris@229:     
Chris@229:     return QSize(sw + s.width(), s.height());
Chris@229: }
Chris@229: 
Chris@222: size_t
Chris@222: Pane::getFirstVisibleFrame() const
Chris@222: {
Chris@222:     long f0 = getFrameForX(m_scaleWidth);
Chris@222:     size_t f = View::getFirstVisibleFrame();
Chris@222:     if (f0 < 0 || f0 < long(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@127:     long testFrame = getFrameForX(x - 5);
Chris@127:     if (testFrame < 0) {
gyorgyf@645:     testFrame = getFrameForX(x);
gyorgyf@645:     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@174: bool
Chris@174: Pane::canTopLayerMoveVertical()
Chris@174: {
Chris@174:     float 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@174: Pane::getTopLayerDisplayExtents(float &vmin, float &vmax,
Chris@188:                                 float &dmin, float &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@174: Pane::setTopLayerDisplayExtents(float dmin, float 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@753:     for (int i = int(m_layers.size()) - 1; i >= 0; --i) {
Chris@753:         if (LayerFactory::getInstance()->getLayerType(m_layers[i]) ==
Chris@753:             LayerFactory::FlexiNotes) {
Chris@753:             return m_layers[i];
Chris@753:         }
Chris@753:     }
Chris@753:     return 0;
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@174:         float vmin, vmax, dmin, dmax;
Chris@174:         if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
Chris@174:             m_dragStartMinValue = dmin;
Chris@136:         }
Chris@136: 
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@713:             int mouseFrame = getFrameForX(e->x());
Chris@713:             size_t resolution = 1;
Chris@713:             int snapFrame = mouseFrame;
gyorgyf@645:     
Chris@713:             Layer *layer = getSelectedLayer();
Chris@713:             if (layer && !m_shiftPressed) {
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;
gyorgyf@645:         }
gyorgyf@645: 
Chris@713:         update();
Chris@127: 
Chris@127:     } else if (mode == ViewManager::DrawMode) {
Chris@127: 
Chris@713:         Layer *layer = getSelectedLayer();
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@713:         Layer *layer = getSelectedLayer();
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@127: Pane::mouseReleaseEvent(QMouseEvent *e)
Chris@127: {
Chris@127:     if (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@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:             }
gyorgyf@645:         }
justin@726:         else if (m_manager && !m_manager->haveInProgressSelection()) {
justin@726:             
justin@726:             //cerr << "JTEST: release without selection" << endl;
justin@727:             // Get frame location of mouse
justin@726:             int mouseFrame = getFrameForX(e->x());
justin@726:             //cerr << "JTEST: frame location of click is " << mouseFrame << endl;
justin@726:             // Move play head to that frame location
justin@726:             int playbackFrame = fmax(0,mouseFrame);
justin@726:             m_manager->setPlaybackFrame(playbackFrame);
justin@726:         }
Chris@713:     
Chris@713:         update();
Chris@713: 
Chris@713:     } else if (mode == ViewManager::DrawMode) {
Chris@713: 
Chris@713:         Layer *layer = getSelectedLayer();
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: 
gyorgyf@645:         Layer *layer = getSelectedLayer();
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@343:                 Layer *layer = getSelectedLayer();
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@127:     if (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<FlexiNoteLayer *>(getTopFlexiNoteLayer());
Chris@753:             if (layer) {
Chris@753:                 layer->mouseMoveEvent(this, e); //!!! ew
Chris@753:                 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@127:         if (!m_manager->isPlaying()) {
Chris@127: 
Chris@272:             bool updating = false;
Chris@272: 
Chris@326:             if (getSelectedLayer() &&
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@272:             if (!updating && mode == ViewManager::MeasureMode &&
Chris@272:                 m_manager && !m_manager->isPlaying()) {
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: 
gyorgyf@649:         Layer *layer = getSelectedLayer();
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: 
gyorgyf@649:         Layer *layer = getSelectedLayer();
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: 
gyorgyf@649:                 Layer *layer = getSelectedLayer();
gyorgyf@649: 
gyorgyf@649:                 if (layer && layer->isLayerEditable()) {
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@343:                     Layer *layer = getSelectedLayer();
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@551:                 Layer *layer = getSelectedLayer();
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@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@174:     int w = x1 - x0;
gyorgyf@645:         
Chris@174:     long newStartFrame = getFrameForX(x0);
gyorgyf@645:         
Chris@174:     long visibleFrames = getEndFrame() - getStartFrame();
Chris@174:     if (newStartFrame <= -visibleFrames) {
Chris@174:         newStartFrame  = -visibleFrames + 1;
Chris@174:     }
gyorgyf@645:         
Chris@174:     if (newStartFrame >= long(getModelsEndFrame())) {
Chris@174:         newStartFrame  = getModelsEndFrame() - 1;
Chris@174:     }
gyorgyf@645:         
Chris@174:     float ratio = float(w) / float(width());
Chris@682: //	cerr << "ratio: " << ratio << endl;
Chris@174:     size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio);
Chris@174:     if (newZoomLevel < 1) newZoomLevel = 1;
Chris@174: 
Chris@682: //	cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << endl;
Chris@174:     setZoomLevel(getZoomConstraintBlockSize(newZoomLevel));
Chris@174:     setStartFrame(newStartFrame);
Chris@174: 
Chris@174:     QString unit;
Chris@174:     float min, max;
Chris@174:     bool log;
Chris@174:     Layer *layer = 0;
Chris@174:     for (LayerList::const_iterator i = m_layers.begin();
Chris@174:          i != m_layers.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@174:             min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min);
Chris@174:             max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max);
Chris@174:         }
Chris@174:         float rmin = min + ((max - min) * (height() - y1)) / height();
Chris@174:         float 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@522:             rmin = powf(10, rmin);
Chris@522:             rmax = powf(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@343:          !(m_manager && m_manager->isPlaying())); // resist vert
Chris@174: 
Chris@343:     if (m_dragMode == HorizontalDrag ||
Chris@343:         m_dragMode == FreeDrag) {
Chris@174: 
Chris@174:         long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x());
Chris@174: 
Chris@174:         size_t newCentreFrame = m_dragCentreFrame;
gyorgyf@645:         
Chris@174:         if (frameOff < 0) {
Chris@174:             newCentreFrame -= frameOff;
Chris@174:         } else if (newCentreFrame >= size_t(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@174:         float vmin = 0.f, vmax = 0.f;
Chris@174:         float 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@174:             float perpix = (dmax - dmin) / height();
Chris@174:             float 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@174:             float newmin = m_dragStartMinValue + valdiff;
Chris@174:             float 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@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@174:     int mouseFrame = getFrameForX(e->x());
Chris@174:     size_t resolution = 1;
Chris@174:     int snapFrameLeft = mouseFrame;
Chris@174:     int snapFrameRight = mouseFrame;
gyorgyf@645:     
Chris@174:     Layer *layer = getSelectedLayer();
Chris@174:     if (layer && !m_shiftPressed) {
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@174: 	
Chris@682: //	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@174:     size_t min, max;
gyorgyf@645:     
Chris@248:     if (m_selectionStartFrame > size_t(snapFrameLeft)) {
Chris@174:         min = snapFrameLeft;
Chris@174:         max = m_selectionStartFrame;
Chris@248:     } else if (size_t(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@174:     if (m_manager) {
Chris@333:         m_manager->setInProgressSelection(Selection(alignToReference(min),
Chris@333:                                                     alignToReference(max)),
Chris@174:                                           !m_resizing && !m_ctrlPressed);
Chris@174:     }
Chris@174: 
Chris@259:     edgeScrollMaybe(e->x());
Chris@259: 
Chris@259:     update();
Chris@259: }
Chris@259: 
Chris@259: void
Chris@259: Pane::edgeScrollMaybe(int x)
Chris@259: {
Chris@259:     int mouseFrame = getFrameForX(x);
Chris@259: 
Chris@174:     bool doScroll = false;
Chris@174:     if (!m_manager) doScroll = true;
Chris@174:     if (!m_manager->isPlaying()) doScroll = true;
Chris@174:     if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
Chris@174: 
Chris@174:     if (doScroll) {
Chris@174:         int offset = mouseFrame - getStartFrame();
Chris@174:         int available = getEndFrame() - getStartFrame();
Chris@259:         int move = 0;
Chris@174:         if (offset >= available * 0.95) {
Chris@259:             move = int(offset - available * 0.95) + 1;
Chris@259:         } else if (offset <= available * 0.10) {
Chris@259:              move = int(available * 0.10 - offset) + 1;
Chris@259:              move = -move;
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@682: //    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@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@716:         m_manager->clearInProgressSelection();
Chris@716:         emit doubleClickSelectInvoked(getFrameForX(e->x()));
Chris@716:         return;
Chris@716:     }
Chris@716: 
Chris@127:     if (mode == ViewManager::NavigateMode ||
Chris@127:         mode == ViewManager::EditMode) {
Chris@127: 
matthiasm@660:         Layer *layer = getSelectedLayer();
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@255:         long 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@255:         float 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;
matthiasm@660:         Layer *layer = getSelectedLayer();
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: {
Chris@682:     //cerr << "wheelEvent, delta " << e->delta() << endl;
Chris@127: 
Chris@127:     int count = e->delta();
Chris@127: 
Chris@127:     if (count > 0) {
gyorgyf@645:     if (count >= 120) count /= 120;
gyorgyf@645:     else count = 1;
Chris@127:     } 
Chris@127: 
Chris@127:     if (count < 0) {
gyorgyf@645:     if (count <= -120) count /= 120;
gyorgyf@645:     else count = -1;
Chris@127:     }
Chris@127: 
Chris@127:     if (e->modifiers() & Qt::ControlModifier) {
Chris@127: 
gyorgyf@645:     // Scroll left or right, rapidly
gyorgyf@645: 
gyorgyf@645:     if (getStartFrame() < 0 && 
gyorgyf@645:         getEndFrame() >= getModelsEndFrame()) return;
gyorgyf@645: 
gyorgyf@645:     long delta = ((width() / 2) * count * m_zoomLevel);
gyorgyf@645: 
gyorgyf@645:     if (int(m_centreFrame) < delta) {
gyorgyf@645:         setCentreFrame(0);
gyorgyf@645:     } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) {
gyorgyf@645:         setCentreFrame(getModelsEndFrame());
gyorgyf@645:     } else {
gyorgyf@645:         setCentreFrame(m_centreFrame - delta);
gyorgyf@645:     }
Chris@127: 
Chris@256:     } else if (e->modifiers() & Qt::ShiftModifier) {
Chris@256: 
Chris@256:         // Zoom vertically
Chris@256: 
Chris@256:         if (m_vpan) {
Chris@256:             m_vpan->scroll(e->delta() > 0);
Chris@256:         }
Chris@256: 
Chris@256:     } else if (e->modifiers() & Qt::AltModifier) {
Chris@256: 
Chris@256:         // Zoom vertically
Chris@256: 
Chris@256:         if (m_vthumb) {
Chris@256:             m_vthumb->scroll(e->delta() > 0);
Chris@256:         }
Chris@256: 
Chris@127:     } else {
Chris@127: 
gyorgyf@645:     // Zoom in or out
gyorgyf@645: 
gyorgyf@645:     int newZoomLevel = m_zoomLevel;
Chris@127:   
gyorgyf@645:     while (count > 0) {
gyorgyf@645:         if (newZoomLevel <= 2) {
gyorgyf@645:         newZoomLevel = 1;
gyorgyf@645:         break;
gyorgyf@645:         }
gyorgyf@645:         newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, 
gyorgyf@645:                               ZoomConstraint::RoundDown);
gyorgyf@645:         --count;
gyorgyf@645:     }
gyorgyf@645:     
gyorgyf@645:     while (count < 0) {
gyorgyf@645:         newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1,
gyorgyf@645:                               ZoomConstraint::RoundUp);
gyorgyf@645:         ++count;
gyorgyf@645:     }
gyorgyf@645:     
gyorgyf@645:     if (newZoomLevel != m_zoomLevel) {
gyorgyf@645:         setZoomLevel(newZoomLevel);
gyorgyf@645:     }
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@682: //            cerr << level << endl;
Chris@137:             level += step;
Chris@137:             if (++count == 100 || level > 262144) break;
Chris@137:         }
Chris@137:     }
Chris@137:         
Chris@682: //    cerr << "new level is " << level << 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@174:         updateVerticalPanner();
Chris@133:     }
Chris@132: }    
Chris@132: 
Chris@174: void
Chris@174: Pane::verticalPannerMoved(float x0, float y0, float w, float h)
Chris@174: {
Chris@174:     float vmin, vmax, dmin, dmax;
Chris@174:     if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return;
Chris@174:     float y1 = y0 + h;
Chris@174:     float newmax = vmin + ((1.0 - y0) * (vmax - vmin));
Chris@174:     float 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@188:     float 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@188:                             unit, vmin, vmax, this);
Chris@188:     dialog.setRange(dmin, dmax);
Chris@188: 
Chris@188:     if (dialog.exec() == QDialog::Accepted) {
Chris@188:         dialog.getRange(dmin, dmax);
Chris@188:         setTopLayerDisplayExtents(dmin, dmax);
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@127:     Layer *layer = getSelectedLayer();
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@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) {
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@224: Pane::viewZoomLevelChanged(View *v, unsigned long 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@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@187:     if (m_vthumb) {
Chris@187:         RangeMapper *rm = 0;
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@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@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@189:     Layer *layer = getSelectedLayer();
Chris@189:     if (layer && layer->isLayerEditable()) {
Chris@189:         editable = true;
Chris@189:     }
Chris@189:         
Chris@189:     if (mode == ViewManager::NavigateMode) {
Chris@189: 
Chris@189:         help = tr("Click and drag to navigate");
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<QWidget *>(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: