# HG changeset patch # User Chris Cannam # Date 1168638776 0 # Node ID dd573e090eed305477a1e9c73f00b058cbc3da8d # Parent e7cf6044c2a0d6341952deb25888d6bfe5ecbedb * Add range input dialog * Make Panner support middle-click/ctrl-left-click to reset and emit doubleClicked when doubleClicked instead of resetting * Use range input dialog to enter new values for panner on double-click diff -r e7cf6044c2a0 -r dd573e090eed layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Fri Jan 12 14:49:18 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Fri Jan 12 21:52:56 2007 +0000 @@ -1894,6 +1894,10 @@ x1 = v->width(); } + //!!! This width should really depend on how fast the machine is + //at redrawing the spectrogram. We could fairly easily time that, + //in this function, and adjust accordingly. The following is + //probably about as small as the block width should go. int paintBlockWidth = (300000 / zoomLevel); if (paintBlockWidth < 20) paintBlockWidth = 20; diff -r e7cf6044c2a0 -r dd573e090eed view/Pane.cpp --- a/view/Pane.cpp Fri Jan 12 14:49:18 2007 +0000 +++ b/view/Pane.cpp Fri Jan 12 21:52:56 2007 +0000 @@ -34,6 +34,7 @@ #include #include "widgets/Thumbwheel.h" #include "widgets/Panner.h" +#include "widgets/RangeInputDialog.h" using std::cerr; using std::endl; @@ -77,6 +78,9 @@ std::cerr << "Have " << count+1 << " zoom levels" << std::endl; */ + Layer *layer = 0; + if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); + if (!m_headsUpDisplay) { m_headsUpDisplay = new QFrame(this); @@ -103,6 +107,8 @@ m_vpan->setAlpha(80, 130); connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)), this, SLOT(verticalPannerMoved(float, float, float, float))); + connect(m_vpan, SIGNAL(doubleClicked()), + this, SLOT(editVerticalPannerExtents())); m_vthumb = new Thumbwheel(Qt::Vertical); m_vthumb->setObjectName(tr("Vertical Zoom")); @@ -112,12 +118,18 @@ connect(m_vthumb, SIGNAL(valueChanged(int)), this, SLOT(verticalThumbwheelMoved(int))); + if (layer) { + RangeMapper *rm = layer->getNewVerticalZoomRangeMapper(); + if (rm) m_vthumb->setRangeMapper(rm); + } + QPushButton *reset = new QPushButton; reset->setFixedHeight(16); reset->setFixedWidth(16); layout->addWidget(reset, 1, 2); connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); + connect(reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault())); } int count = 0; @@ -179,8 +191,6 @@ // std::cerr << "set default value to " << m_hthumb->getDefaultValue() << std::endl; } - Layer *layer = 0; - if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); if (layer) { int defaultStep = 0; int max = layer->getVerticalZoomSteps(defaultStep); @@ -702,15 +712,18 @@ bool Pane::getTopLayerDisplayExtents(float &vmin, float &vmax, - float &dmin, float &dmax) + float &dmin, float &dmax, + QString *unit) { Layer *layer = 0; if (getLayerCount() > 0) layer = getLayer(getLayerCount() - 1); if (!layer) return false; bool vlog; QString vunit; - return (layer->getValueExtents(vmin, vmax, vlog, vunit) && - layer->getDisplayExtents(dmin, dmax)); + bool rv = (layer->getValueExtents(vmin, vmax, vlog, vunit) && + layer->getDisplayExtents(dmin, dmax)); + if (unit) *unit = vunit; + return rv; } bool @@ -1415,6 +1428,31 @@ setTopLayerDisplayExtents(newmin, newmax); } +void +Pane::editVerticalPannerExtents() +{ + if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; + + float vmin, vmax, dmin, dmax; + QString unit; + if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) + || vmax == vmin) { + return; + } + + RangeInputDialog dialog(tr("Enter new range"), + tr("New vertical display range, from %1 to %2 %4:") + .arg(vmin).arg(vmax).arg(unit), + unit, vmin, vmax, this); + dialog.setRange(dmin, dmax); + + if (dialog.exec() == QDialog::Accepted) { + dialog.getRange(dmin, dmax); + setTopLayerDisplayExtents(dmin, dmax); + updateVerticalPanner(); + } +} + bool Pane::editSelectionStart(QMouseEvent *e) { diff -r e7cf6044c2a0 -r dd573e090eed view/Pane.h --- a/view/Pane.h Fri Jan 12 14:49:18 2007 +0000 +++ b/view/Pane.h Fri Jan 12 21:52:56 2007 +0000 @@ -63,6 +63,7 @@ virtual void verticalThumbwheelMoved(int value); virtual void verticalZoomChanged(); virtual void verticalPannerMoved(float x, float y, float w, float h); + virtual void editVerticalPannerExtents(); virtual void propertyContainerSelected(View *, PropertyContainer *pc); @@ -88,7 +89,8 @@ bool canTopLayerMoveVertical(); bool getTopLayerDisplayExtents(float &valueMin, float &valueMax, - float &displayMin, float &displayMax); + float &displayMin, float &displayMax, + QString *unit = 0); bool setTopLayerDisplayExtents(float displayMin, float displayMax); void dragTopLayer(QMouseEvent *e); diff -r e7cf6044c2a0 -r dd573e090eed widgets/Panner.cpp --- a/widgets/Panner.cpp Fri Jan 12 14:49:18 2007 +0000 +++ b/widgets/Panner.cpp Fri Jan 12 21:52:56 2007 +0000 @@ -53,20 +53,26 @@ void Panner::mousePressEvent(QMouseEvent *e) { - if (e->button() == Qt::LeftButton) { + if (e->button() == Qt::MidButton || + ((e->button() == Qt::LeftButton) && + (e->modifiers() & Qt::ControlModifier))) { + resetToDefault(); + } else if (e->button() == Qt::LeftButton) { m_clicked = true; m_clickPos = e->pos(); m_dragStartX = m_rectX; m_dragStartY = m_rectY; - } else if (e->button() == Qt::MidButton) { - resetToDefault(); } } void Panner::mouseDoubleClickEvent(QMouseEvent *e) { - resetToDefault(); + if (e->button() != Qt::LeftButton) { + return; + } + + emit doubleClicked(); } void @@ -158,6 +164,15 @@ } void +Panner::getRectExtents(float &x0, float &y0, float &width, float &height) +{ + x0 = m_rectX; + y0 = m_rectY; + width = m_rectWidth; + height = m_rectHeight; +} + +void Panner::setRectExtents(float x0, float y0, float width, float height) { std::cerr << "Panner::setRectExtents(" << x0 << ", " << y0 << ", " diff -r e7cf6044c2a0 -r dd573e090eed widgets/Panner.h --- a/widgets/Panner.h Fri Jan 12 14:49:18 2007 +0000 +++ b/widgets/Panner.h Fri Jan 12 21:52:56 2007 +0000 @@ -31,6 +31,8 @@ void setThumbColour(QColor colour); void setAlpha(int backgroundAlpha, int thumbAlpha); + void getRectExtents(float &x0, float &y0, float &width, float &height); + virtual void mousePressEvent(QMouseEvent *e); virtual void mouseDoubleClickEvent(QMouseEvent *e); virtual void mouseMoveEvent(QMouseEvent *e); @@ -57,6 +59,12 @@ */ void rectCentreMoved(float, float); + /** + * Emitted when the panner is double-clicked (for the "customer" + * code to pop up a value editing dialog, for example). + */ + void doubleClicked(); + public slots: /** * Set the extents of the panned rectangle within the overall @@ -91,10 +99,11 @@ */ void setRectCentreY(float y); + void resetToDefault(); + protected: void normalise(); void emitAndUpdate(); - void resetToDefault(); float m_rectX; float m_rectY; diff -r e7cf6044c2a0 -r dd573e090eed widgets/RangeInputDialog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/RangeInputDialog.cpp Fri Jan 12 21:52:56 2007 +0000 @@ -0,0 +1,134 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2007 QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#include "RangeInputDialog.h" + +#include +#include +#include +#include +#include + +RangeInputDialog::RangeInputDialog(QString title, QString message, + QString unit, float min, float max, + QWidget *parent) : + QDialog(parent) +{ + QGridLayout *grid = new QGridLayout; + setLayout(grid); + + setWindowTitle(title); + + QLabel *messageLabel = new QLabel; + messageLabel->setText(message); + grid->addWidget(messageLabel, 0, 0, 1, 5); + + m_rangeStart = new QDoubleSpinBox; + m_rangeStart->setDecimals(4); + m_rangeStart->setMinimum(min); + m_rangeStart->setMaximum(max); + m_rangeStart->setSuffix(unit); + grid->addWidget(m_rangeStart, 1, 1); + connect(m_rangeStart, SIGNAL(valueChanged(double)), + this, SLOT(rangeStartChanged(double))); + + grid->addWidget(new QLabel(tr(" to ")), 1, 2); + + m_rangeEnd = new QDoubleSpinBox; + m_rangeEnd->setDecimals(4); + m_rangeEnd->setMinimum(min); + m_rangeEnd->setMaximum(max); + m_rangeEnd->setSuffix(unit); + grid->addWidget(m_rangeEnd, 1, 3); + connect(m_rangeEnd, SIGNAL(valueChanged(double)), + this, SLOT(rangeEndChanged(double))); + + QHBoxLayout *hbox = new QHBoxLayout; + grid->addLayout(hbox, 2, 0, 1, 5); + + QPushButton *ok = new QPushButton(tr("OK"), this); + ok->setDefault(true); + + QPushButton *cancel = new QPushButton(tr("Cancel"), this); + + QSize bs = ok->sizeHint().expandedTo(cancel->sizeHint()); + ok->setFixedSize(bs); + cancel->setFixedSize(bs); + + hbox->addStretch(); + hbox->addWidget(ok); + hbox->addWidget(cancel); + + QObject::connect(ok, SIGNAL(clicked()), this, SLOT(accept())); + QObject::connect(cancel, SIGNAL(clicked()), this, SLOT(reject())); +} + +RangeInputDialog::~RangeInputDialog() +{ +} + +void +RangeInputDialog::getRange(float &min, float &max) +{ + min = float(m_rangeStart->value()); + max = float(m_rangeEnd->value()); + + if (min > max) { + float tmp = min; + min = max; + max = tmp; + } +} + +void +RangeInputDialog::setRange(float start, float end) +{ + if (start > end) { + float tmp = start; + start = end; + end = tmp; + } + + blockSignals(true); + m_rangeStart->setValue(start); + m_rangeEnd->setValue(end); + blockSignals(false); +} + +void +RangeInputDialog::rangeStartChanged(double min) +{ + double max = m_rangeEnd->value(); + if (min > max) { + double tmp = min; + min = max; + max = tmp; + } + emit rangeChanged(float(min), float(max)); +} + + +void +RangeInputDialog::rangeEndChanged(double max) +{ + double min = m_rangeStart->value(); + if (min > max) { + double tmp = min; + min = max; + max = tmp; + } + emit rangeChanged(float(min), float(max)); +} + diff -r e7cf6044c2a0 -r dd573e090eed widgets/RangeInputDialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/RangeInputDialog.h Fri Jan 12 21:52:56 2007 +0000 @@ -0,0 +1,50 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2007 QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _RANGE_INPUT_DIALOG_H_ +#define _RANGE_INPUT_DIALOG_H_ + +#include +#include + +class QDoubleSpinBox; + +class RangeInputDialog : public QDialog +{ + Q_OBJECT + +public: + RangeInputDialog(QString title, QString message, QString unit, + float min, float max, QWidget *parent = 0); + virtual ~RangeInputDialog(); + + void getRange(float &start, float &end); + +signals: + void rangeChanged(float start, float end); + +public slots: + void setRange(float start, float end); + +protected slots: + void rangeStartChanged(double); + void rangeEndChanged(double); + +protected: + QDoubleSpinBox *m_rangeStart; + QDoubleSpinBox *m_rangeEnd; +}; + +#endif diff -r e7cf6044c2a0 -r dd573e090eed widgets/Thumbwheel.cpp --- a/widgets/Thumbwheel.cpp Fri Jan 12 14:49:18 2007 +0000 +++ b/widgets/Thumbwheel.cpp Fri Jan 12 21:52:56 2007 +0000 @@ -278,7 +278,7 @@ void Thumbwheel::mouseDoubleClickEvent(QMouseEvent *mouseEvent) { - //!!! needs a common base class with AudioDial + //!!! needs a common base class with AudioDial (and Panner?) if (mouseEvent->button() != Qt::LeftButton) { return; diff -r e7cf6044c2a0 -r dd573e090eed widgets/widgets.pro --- a/widgets/widgets.pro Fri Jan 12 14:49:18 2007 +0000 +++ b/widgets/widgets.pro Fri Jan 12 21:52:56 2007 +0000 @@ -25,6 +25,7 @@ PluginParameterDialog.h \ PropertyBox.h \ PropertyStack.h \ + RangeInputDialog.h \ SubdividingMenu.h \ Thumbwheel.h \ WindowShapePreview.h \ @@ -40,6 +41,7 @@ PluginParameterDialog.cpp \ PropertyBox.cpp \ PropertyStack.cpp \ + RangeInputDialog.cpp \ SubdividingMenu.cpp \ Thumbwheel.cpp \ WindowShapePreview.cpp \