Mercurial > hg > svgui
changeset 132:5d3a483856ff
* Add Thumbwheel widget for all our zooming needs
* Use QSettings to save/restore window size and position -- precursor to
switching our preferences to QSettings as well -- wish I'd noticed it sooner
* Only suspend writes (not reads from the underlying cache objects) from the
fft caches when repainting the spectrogram -- performance should now be
significantly better
author | Chris Cannam |
---|---|
date | Thu, 03 Aug 2006 15:40:11 +0000 |
parents | eaae73b6bd28 |
children | 9e6b3e239b9d |
files | layer/SpectrogramLayer.cpp view/Pane.cpp view/Pane.h view/View.cpp widgets/Fader.cpp widgets/Fader.h widgets/Thumbwheel.cpp widgets/Thumbwheel.h widgets/widgets.pro |
diffstat | 9 files changed, 384 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/SpectrogramLayer.cpp Thu Aug 03 12:42:15 2006 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Aug 03 15:40:11 2006 +0000 @@ -1941,7 +1941,7 @@ MagnitudeRange overallMag = m_viewMags[v]; bool overallMagChanged = false; - fft->suspend(); + fft->suspendWrites(); for (int x = 0; x < w; ++x) {
--- a/view/Pane.cpp Thu Aug 03 12:42:15 2006 +0000 +++ b/view/Pane.cpp Thu Aug 03 15:40:11 2006 +0000 @@ -22,6 +22,7 @@ #include "ViewManager.h" #include "base/CommandHistory.h" #include "layer/WaveformLayer.h" +#include "widgets/Thumbwheel.h" #include <QPaintEvent> #include <QPainter> @@ -43,6 +44,29 @@ { setObjectName("Pane"); setMouseTracking(true); +/* + int count = 0; + int currentLevel = 1; + int level = 1; + while (true) { + if (getZoomLevel() == level) currentLevel = count; + int newLevel = getZoomConstraintBlockSize(level + 1, + ZoomConstraint::RoundUp); + if (newLevel == level) break; + if (newLevel == 131072) break; //!!! just because + level = newLevel; + ++count; + } + + std::cerr << "Have " << count+1 << " zoom levels" << std::endl; +*/ +/* + Thumbwheel *thumbwheel = new Thumbwheel(0, 40, 5, + Qt::Vertical, this); + thumbwheel->move(10, 10); + connect(thumbwheel, SIGNAL(valueChanged(int)), this, + SLOT(horizontalThumbwheelMoved(int))); +*/ } bool @@ -969,6 +993,29 @@ emit paneInteractedWith(); } +void +Pane::horizontalThumbwheelMoved(int value) +{ + int count = 0; + int level = 1; + while (true) { + if (value == count) break; + int newLevel = getZoomConstraintBlockSize(level + 1, + ZoomConstraint::RoundUp); + if (newLevel == level) break; + level = newLevel; + ++count; + } + + std::cerr << "new level is " << level << std::endl; + setZoomLevel(level); +} + +void +Pane::verticalThumbwheelMoved(int value) +{ +} + bool Pane::editSelectionStart(QMouseEvent *e) {
--- a/view/Pane.h Thu Aug 03 12:42:15 2006 +0000 +++ b/view/Pane.h Thu Aug 03 15:40:11 2006 +0000 @@ -55,6 +55,9 @@ public slots: virtual void toolModeChanged(); + virtual void horizontalThumbwheelMoved(int value); + virtual void verticalThumbwheelMoved(int value); + protected: virtual void paintEvent(QPaintEvent *e); virtual void mousePressEvent(QMouseEvent *e);
--- a/view/View.cpp Thu Aug 03 12:42:15 2006 +0000 +++ b/view/View.cpp Thu Aug 03 15:40:11 2006 +0000 @@ -923,10 +923,10 @@ bool metUnscrollable = false; for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { - std::cerr << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << std::endl; - std::cerr << "(name is " << (*i)->objectName().toStdString() << ")" - << std::endl; - std::cerr << "View::getScrollableBackLayers: I am " << this << std::endl; +// std::cerr << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << std::endl; +// std::cerr << "(name is " << (*i)->objectName().toStdString() << ")" +// << std::endl; +// std::cerr << "View::getScrollableBackLayers: I am " << this << std::endl; if ((*i)->isLayerDormant(this)) continue; if ((*i)->isLayerOpaque()) { // You can't see anything behind an opaque layer! @@ -1069,6 +1069,9 @@ } else { i->second->setText(i->first->getPropertyContainerName()); + +// std::cerr << this << "::checkProgress: completion " << completion << std::endl; + i->second->setValue(completion); i->second->move(0, ph - i->second->height());
--- a/widgets/Fader.cpp Thu Aug 03 12:42:15 2006 +0000 +++ b/widgets/Fader.cpp Thu Aug 03 15:40:11 2006 +0000 @@ -121,6 +121,13 @@ void +Fader::mouseReleaseEvent(QMouseEvent *ev) +{ + mouseMoveEvent(ev); +} + + +void Fader::mouseDoubleClickEvent(QMouseEvent *) { setValue(1.0);
--- a/widgets/Fader.h Thu Aug 03 12:42:15 2006 +0000 +++ b/widgets/Fader.h Thu Aug 03 15:40:11 2006 +0000 @@ -71,6 +71,7 @@ virtual void mousePressEvent(QMouseEvent *ev); virtual void mouseDoubleClickEvent(QMouseEvent *ev); virtual void mouseMoveEvent(QMouseEvent *ev); + virtual void mouseReleaseEvent(QMouseEvent *ev); virtual void wheelEvent( QWheelEvent *ev ); virtual void paintEvent(QPaintEvent *ev);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/Thumbwheel.cpp Thu Aug 03 15:40:11 2006 +0000 @@ -0,0 +1,246 @@ +/* -*- 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 2006 Chris Cannam. + + 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 "Thumbwheel.h" + +#include <QMouseEvent> +#include <QPaintEvent> +#include <QWheelEvent> +#include <QPainter> + +#include <cmath> +#include <iostream> + +Thumbwheel::Thumbwheel(int min, int max, int defaultValue, + Qt::Orientation orientation, + QWidget *parent) : + QWidget(parent), + m_min(min), + m_max(max), + m_default(defaultValue), + m_value((min + max) / 2), + m_orientation(orientation), + m_tracking(true), + m_showScale(true), + m_clicked(false), + m_clickValue(m_value) +{ + if (max <= min) max = min + 1; + m_speed = float(max - min) / 300.f; +} + +Thumbwheel::~Thumbwheel() +{ +} + +void +Thumbwheel::setValue(int value) +{ + if (value < m_min) value = m_min; + if (value > m_max) value = m_max; + m_value = value; + update(); +} + +int +Thumbwheel::getValue() const +{ + return m_value; +} + +void +Thumbwheel::setSpeed(float speed) +{ + m_speed = speed; +} + +float +Thumbwheel::getSpeed() const +{ + return m_speed; +} + +void +Thumbwheel::setTracking(bool tracking) +{ + m_tracking = tracking; +} + +bool +Thumbwheel::getTracking() const +{ + return m_tracking; +} + +void +Thumbwheel::setShowScale(bool showScale) +{ + m_showScale = showScale; +} + +bool +Thumbwheel::getShowScale() const +{ + return m_showScale; +} + +void +Thumbwheel::mousePressEvent(QMouseEvent *e) +{ + m_clicked = true; + m_clickPos = e->pos(); + m_clickValue = m_value; +} + +void +Thumbwheel::mouseDoubleClickEvent(QMouseEvent *) +{ + setValue(m_default); + emit valueChanged(getValue()); +} + +void +Thumbwheel::mouseMoveEvent(QMouseEvent *e) +{ + int dist = 0; + if (m_orientation == Qt::Horizontal) { + dist = e->x() - m_clickPos.x(); + } else { + dist = e->y() - m_clickPos.y(); + } + int value = m_clickValue + lrintf(m_speed * dist); + if (value < m_min) value = m_min; + if (value > m_max) value = m_max; + if (value != m_value) { + setValue(value); + if (m_tracking) emit valueChanged(getValue()); + } +} + +void +Thumbwheel::mouseReleaseEvent(QMouseEvent *e) +{ + bool reallyTracking = m_tracking; + m_tracking = true; + mouseMoveEvent(e); + m_tracking = reallyTracking; +} + +void +Thumbwheel::wheelEvent(QWheelEvent *e) +{ + int step = lrintf(m_speed); + if (step == 0) step = 1; + + if (e->delta() > 0) { + setValue(m_value + step); + } else { + setValue(m_value - step); + } + + emit valueChanged(getValue()); +} + +void +Thumbwheel::paintEvent(QPaintEvent *) +{ + float distance = float(m_value - m_min) / float(m_max - m_min); + float rotation = distance * 1.5f * M_PI; + +// std::cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << std::endl; + + int w = (m_orientation == Qt::Horizontal ? width() : height()); + + // total number of notches on the entire wheel + int notches = 25; + + // radius of the wheel including invisible part + int radius = w / 2 + 2; + + QPainter paint(this); + paint.fillRect(rect(), palette().background().color()); + paint.setRenderHint(QPainter::Antialiasing, true); + + for (int i = 0; i < notches; ++i) { + + float a0 = (2.f * M_PI * i) / notches + rotation; + float a1 = a0 + M_PI / (notches * 2); + float a2 = (2.f * M_PI * (i + 1)) / notches + rotation; + + float depth = cosf((a0 + a2) / 2); + if (depth < 0) continue; + + float x0 = radius * sinf(a0) + w/2; + float x1 = radius * sinf(a1) + w/2; + float x2 = radius * sinf(a2) + w/2; + if (x2 < 0 || x0 > w) continue; + + if (x0 < 0) x0 = 0; + if (x2 > w) x2 = w; + + int grey = lrintf(255 * depth); + QColor fc = QColor(grey, grey, grey); + QColor oc = palette().dark().color(); + + paint.setPen(oc); + paint.setBrush(fc); + + if (m_orientation == Qt::Horizontal) { + paint.drawRect(QRectF(x1, 0, x2 - x1, height())); + } else { + paint.drawRect(QRectF(0, x1, width(), x2 - x1)); + } + + if (m_showScale) { + + paint.setBrush(oc); + + float prop; + if (i >= notches / 4) { + prop = float(notches - (((i - float(notches) / 4.f) * 4.f) / 3.f)) + / notches; + } else { + prop = 0.f; + } + + if (m_orientation == Qt::Horizontal) { + paint.drawRect(QRectF(x1, height() - height() * prop, + x2 - x1, height() * prop)); + } else { + paint.drawRect(QRectF(0, x1, width() * prop, x2 - x1)); + } + } + + paint.setPen(oc); + paint.setBrush(palette().background().color()); + + if (m_orientation == Qt::Horizontal) { + paint.drawRect(QRectF(x0, 0, x1 - x0, height())); + } else { + paint.drawRect(QRectF(0, x0, width(), x1 - x0)); + } + } +} + +QSize +Thumbwheel::sizeHint() const +{ + if (m_orientation == Qt::Horizontal) { + return QSize(80, 12); + } else { + return QSize(12, 80); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/Thumbwheel.h Thu Aug 03 15:40:11 2006 +0000 @@ -0,0 +1,68 @@ +/* -*- 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 2006 Chris Cannam. + + 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 _THUMBWHEEL_H_ +#define _THUMBWHEEL_H_ + +#include <QWidget> + +class Thumbwheel : public QWidget +{ + Q_OBJECT + +public: + Thumbwheel(int min, int max, int defaultValue, + Qt::Orientation orientation, QWidget *parent = 0); + virtual ~Thumbwheel(); + + void setSpeed(float speed); + float getSpeed() const; + + void setTracking(bool tracking); + bool getTracking() const; + + void setShowScale(bool show); + bool getShowScale() const; + + void setValue(int value); + int getValue() const; + + virtual void mousePressEvent(QMouseEvent *e); + virtual void mouseDoubleClickEvent(QMouseEvent *e); + virtual void mouseMoveEvent(QMouseEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *e); + virtual void wheelEvent(QWheelEvent *e); + virtual void paintEvent(QPaintEvent *e); + + QSize sizeHint() const; + +signals: + void valueChanged(int); + +private: + int m_min; + int m_max; + int m_default; + int m_value; + Qt::Orientation m_orientation; + float m_speed; + bool m_tracking; + bool m_showScale; + bool m_clicked; + QPoint m_clickPos; + int m_clickValue; +}; + +#endif
--- a/widgets/widgets.pro Thu Aug 03 12:42:15 2006 +0000 +++ b/widgets/widgets.pro Thu Aug 03 15:40:11 2006 +0000 @@ -23,7 +23,8 @@ PluginParameterBox.h \ PluginParameterDialog.h \ PropertyBox.h \ - PropertyStack.h + PropertyStack.h \ + Thumbwheel.h SOURCES += AudioDial.cpp \ Fader.cpp \ ItemEditDialog.cpp \ @@ -33,4 +34,5 @@ PluginParameterBox.cpp \ PluginParameterDialog.cpp \ PropertyBox.cpp \ - PropertyStack.cpp + PropertyStack.cpp \ + Thumbwheel.cpp