# HG changeset patch # User Chris Cannam # Date 1161251847 0 # Node ID 9c40dc10c88cd683d6b997621d9e8b42b64f079b # Parent d0b95a8cac96cfcc6ab708e7efce18315461b341 * Rename the existing Panner to Overview (big duh!) * Fixes to the new Panner. diff -r d0b95a8cac96 -r 9c40dc10c88c view/Overview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/view/Overview.cpp Thu Oct 19 09:57:27 2006 +0000 @@ -0,0 +1,213 @@ +/* -*- 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 "Overview.h" +#include "layer/Layer.h" +#include "data/model/Model.h" +#include "base/ZoomConstraint.h" + +#include +#include +#include + +using std::cerr; +using std::endl; + +Overview::Overview(QWidget *w) : + View(w, false), + m_clickedInRange(false) +{ + setObjectName(tr("Overview")); + m_followPan = false; + m_followZoom = false; +} + +void +Overview::modelChanged(size_t startFrame, size_t endFrame) +{ + View::modelChanged(startFrame, endFrame); +} + +void +Overview::modelReplaced() +{ + View::modelReplaced(); +} + +void +Overview::registerView(View *widget) +{ + m_widgets.insert(widget); + update(); +} + +void +Overview::unregisterView(View *widget) +{ + m_widgets.erase(widget); + update(); +} + +void +Overview::viewManagerCentreFrameChanged(void *p, unsigned long f, bool) +{ +// std::cerr << "Overview[" << this << "]::viewManagerCentreFrameChanged(" +// << p << ", " << f << ")" << std::endl; + + if (p == this) return; + if (m_widgets.find(p) != m_widgets.end()) { + update(); + } +} + +void +Overview::viewManagerZoomLevelChanged(void *p, unsigned long z, bool) +{ + if (p == this) return; + if (m_widgets.find(p) != m_widgets.end()) { + update(); + } +} + +void +Overview::viewManagerPlaybackFrameChanged(unsigned long f) +{ + bool changed = false; + + if (getXForFrame(m_playPointerFrame) != getXForFrame(f)) changed = true; + m_playPointerFrame = f; + + if (changed) update(); +} + +void +Overview::paintEvent(QPaintEvent *e) +{ + // Recalculate zoom in case the size of the widget has changed. + + size_t startFrame = getModelsStartFrame(); + size_t frameCount = getModelsEndFrame() - getModelsStartFrame(); + int zoomLevel = frameCount / width(); + if (zoomLevel < 1) zoomLevel = 1; + zoomLevel = getZoomConstraintBlockSize(zoomLevel, + ZoomConstraint::RoundUp); + if (zoomLevel != m_zoomLevel) { + m_zoomLevel = zoomLevel; + emit zoomLevelChanged(this, m_zoomLevel, m_followZoom); + } + size_t centreFrame = startFrame + m_zoomLevel * (width() / 2); + if (centreFrame > (startFrame + getModelsEndFrame())/2) { + centreFrame = (startFrame + getModelsEndFrame())/2; + } + if (centreFrame != m_centreFrame) { + m_centreFrame = centreFrame; + emit centreFrameChanged(this, m_centreFrame, false); + } + + View::paintEvent(e); + + QPainter paint; + paint.begin(this); + + QRect r(rect()); + + if (e) { + r = e->rect(); + paint.setClipRect(r); + } + + paint.setPen(Qt::black); + + int y = 0; + + int prevx0 = -10; + int prevx1 = -10; + + for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { + if (!*i) continue; + + View *w = (View *)*i; + + long f0 = w->getFrameForX(0); + long f1 = w->getFrameForX(w->width()); + + int x0 = getXForFrame(f0); + int x1 = getXForFrame(f1); + + if (x0 != prevx0 || x1 != prevx1) { + y += height() / 10 + 1; + prevx0 = x0; + prevx1 = x1; + } + + if (x1 <= x0) x1 = x0 + 1; + + paint.drawRect(x0, y, x1 - x0, height() - 2 * y); + } + + paint.end(); +} + +void +Overview::mousePressEvent(QMouseEvent *e) +{ + m_clickPos = e->pos(); + for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { + if (*i) { + m_clickedInRange = true; + m_dragCentreFrame = ((View *)*i)->getCentreFrame(); + break; + } + } +} + +void +Overview::mouseReleaseEvent(QMouseEvent *e) +{ + if (m_clickedInRange) { + mouseMoveEvent(e); + } + m_clickedInRange = false; +} + +void +Overview::mouseMoveEvent(QMouseEvent *e) +{ + if (!m_clickedInRange) return; + + long xoff = int(e->x()) - int(m_clickPos.x()); + long frameOff = xoff * m_zoomLevel; + + size_t newCentreFrame = m_dragCentreFrame; + if (frameOff > 0) { + newCentreFrame += frameOff; + } else if (newCentreFrame >= size_t(-frameOff)) { + newCentreFrame += frameOff; + } else { + newCentreFrame = 0; + } + + if (newCentreFrame >= getModelsEndFrame()) { + newCentreFrame = getModelsEndFrame(); + if (newCentreFrame > 0) --newCentreFrame; + } + + if (std::max(m_centreFrame, newCentreFrame) - + std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) { + emit centreFrameChanged(this, newCentreFrame, true); + } +} + + diff -r d0b95a8cac96 -r 9c40dc10c88c view/Overview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/view/Overview.h Thu Oct 19 09:57:27 2006 +0000 @@ -0,0 +1,67 @@ +/* -*- 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 _OVERVIEW_H_ +#define _OVERVIEW_H_ + +#include "View.h" + +#include + +class QWidget; +class QPaintEvent; +class Layer; +class View; + +#include + +class Overview : public View +{ + Q_OBJECT + +public: + Overview(QWidget *parent = 0); + + void registerView(View *widget); + void unregisterView(View *widget); + + virtual QString getPropertyContainerIconName() const { return "panner"; } + +public slots: + virtual void modelChanged(size_t startFrame, size_t endFrame); + virtual void modelReplaced(); + + virtual void viewManagerCentreFrameChanged(void *, unsigned long, bool); + virtual void viewManagerZoomLevelChanged(void *, unsigned long, bool); + virtual void viewManagerPlaybackFrameChanged(unsigned long); + +protected: + virtual void paintEvent(QPaintEvent *e); + virtual void mousePressEvent(QMouseEvent *e); + virtual void mouseReleaseEvent(QMouseEvent *e); + virtual void mouseMoveEvent(QMouseEvent *e); + virtual bool shouldLabelSelections() const { return false; } + + QPoint m_clickPos; + QPoint m_mousePos; + bool m_clickedInRange; + size_t m_dragCentreFrame; + + typedef std::set WidgetSet; + WidgetSet m_widgets; +}; + +#endif + diff -r d0b95a8cac96 -r 9c40dc10c88c view/Pane.cpp --- a/view/Pane.cpp Wed Oct 18 16:38:30 2006 +0000 +++ b/view/Pane.cpp Thu Oct 19 09:57:27 2006 +0000 @@ -85,7 +85,7 @@ m_headsUpDisplay->setLayout(layout); m_hthumb = new Thumbwheel(Qt::Horizontal); - layout->addWidget(m_hthumb, 1, 0, 2, 1); + layout->addWidget(m_hthumb, 1, 0, 1, 2); m_hthumb->setFixedWidth(70); m_hthumb->setFixedHeight(16); m_hthumb->setDefaultValue(0); @@ -95,8 +95,9 @@ m_vpan = new Panner; layout->addWidget(m_vpan, 0, 1); - m_vpan->setFixedWidth(16); + m_vpan->setFixedWidth(12); m_vpan->setFixedHeight(70); +// m_vpan->setRectExtents(0.1, 0.1, 0.4, 0.4); m_vthumb = new Thumbwheel(Qt::Vertical); layout->addWidget(m_vthumb, 0, 2); @@ -559,7 +560,7 @@ if (m_manager->getZoomWheelsEnabled()) { lly -= 20; - llx -= 20; + llx -= 36; } if (r.x() + r.width() >= llx) { diff -r d0b95a8cac96 -r 9c40dc10c88c view/Panner.cpp --- a/view/Panner.cpp Wed Oct 18 16:38:30 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,216 +0,0 @@ -/* -*- 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 "Panner.h" -#include "layer/Layer.h" -#include "data/model/Model.h" -#include "base/ZoomConstraint.h" - -#include -#include -#include - -using std::cerr; -using std::endl; - -Panner::Panner(QWidget *w) : - View(w, false), - m_clickedInRange(false) -{ - setObjectName(tr("Panner")); - m_followPan = false; - m_followZoom = false; -} - -void -Panner::modelChanged(size_t startFrame, size_t endFrame) -{ - View::modelChanged(startFrame, endFrame); -} - -void -Panner::modelReplaced() -{ - View::modelReplaced(); -} - -void -Panner::registerView(View *widget) -{ - m_widgets.insert(widget); - update(); -} - -void -Panner::unregisterView(View *widget) -{ - m_widgets.erase(widget); - update(); -} - -void -Panner::viewManagerCentreFrameChanged(void *p, unsigned long f, bool) -{ -// std::cerr << "Panner[" << this << "]::viewManagerCentreFrameChanged(" -// << p << ", " << f << ")" << std::endl; - - if (p == this) return; - if (m_widgets.find(p) != m_widgets.end()) { - update(); - } -} - -void -Panner::viewManagerZoomLevelChanged(void *p, unsigned long z, bool) -{ - if (p == this) return; - if (m_widgets.find(p) != m_widgets.end()) { - update(); - } -} - -void -Panner::viewManagerPlaybackFrameChanged(unsigned long f) -{ - bool changed = false; - - if (getXForFrame(m_playPointerFrame) != getXForFrame(f)) changed = true; - m_playPointerFrame = f; - - if (changed) update(); -} - -void -Panner::paintEvent(QPaintEvent *e) -{ - // Recalculate zoom in case the size of the widget has changed. - - size_t startFrame = getModelsStartFrame(); - size_t frameCount = getModelsEndFrame() - getModelsStartFrame(); - int zoomLevel = frameCount / width(); - if (zoomLevel < 1) zoomLevel = 1; - zoomLevel = getZoomConstraintBlockSize(zoomLevel, - ZoomConstraint::RoundUp); - if (zoomLevel != m_zoomLevel) { - m_zoomLevel = zoomLevel; - emit zoomLevelChanged(this, m_zoomLevel, m_followZoom); - } - size_t centreFrame = startFrame + m_zoomLevel * (width() / 2); - if (centreFrame > (startFrame + getModelsEndFrame())/2) { - centreFrame = (startFrame + getModelsEndFrame())/2; - } - if (centreFrame != m_centreFrame) { - m_centreFrame = centreFrame; - emit centreFrameChanged(this, m_centreFrame, false); - } - - View::paintEvent(e); - - QPainter paint; - paint.begin(this); - - QRect r(rect()); - - if (e) { - r = e->rect(); - paint.setClipRect(r); - } - - paint.setPen(Qt::black); - - int y = 0; - - int prevx0 = -10; - int prevx1 = -10; - - for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { - if (!*i) continue; - - View *w = (View *)*i; - - long f0 = w->getFrameForX(0); - long f1 = w->getFrameForX(w->width()); - - int x0 = getXForFrame(f0); - int x1 = getXForFrame(f1); - - if (x0 != prevx0 || x1 != prevx1) { - y += height() / 10 + 1; - prevx0 = x0; - prevx1 = x1; - } - - if (x1 <= x0) x1 = x0 + 1; - - paint.drawRect(x0, y, x1 - x0, height() - 2 * y); - } - - paint.end(); -} - -void -Panner::mousePressEvent(QMouseEvent *e) -{ - m_clickPos = e->pos(); - for (WidgetSet::iterator i = m_widgets.begin(); i != m_widgets.end(); ++i) { - if (*i) { - m_clickedInRange = true; - m_dragCentreFrame = ((View *)*i)->getCentreFrame(); - break; - } - } -} - -void -Panner::mouseReleaseEvent(QMouseEvent *e) -{ - if (m_clickedInRange) { - mouseMoveEvent(e); - } - m_clickedInRange = false; -} - -void -Panner::mouseMoveEvent(QMouseEvent *e) -{ - if (!m_clickedInRange) return; - - long xoff = int(e->x()) - int(m_clickPos.x()); - long frameOff = xoff * m_zoomLevel; - - size_t newCentreFrame = m_dragCentreFrame; - if (frameOff > 0) { - newCentreFrame += frameOff; - } else if (newCentreFrame >= size_t(-frameOff)) { - newCentreFrame += frameOff; - } else { - newCentreFrame = 0; - } - - if (newCentreFrame >= getModelsEndFrame()) { - newCentreFrame = getModelsEndFrame(); - if (newCentreFrame > 0) --newCentreFrame; - } - - if (std::max(m_centreFrame, newCentreFrame) - - std::min(m_centreFrame, newCentreFrame) > size_t(m_zoomLevel)) { - emit centreFrameChanged(this, newCentreFrame, true); - } -} - -#ifdef INCLUDE_MOCFILES -#include "Panner.moc.cpp" -#endif - diff -r d0b95a8cac96 -r 9c40dc10c88c view/Panner.h --- a/view/Panner.h Wed Oct 18 16:38:30 2006 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* -*- 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 _PAN_WIDGET_H_ -#define _PAN_WIDGET_H_ - -#include "View.h" - -#include - -class QWidget; -class QPaintEvent; -class Layer; -class View; - -#include - -class Panner : public View -{ - Q_OBJECT - -public: - Panner(QWidget *parent = 0); - - void registerView(View *widget); - void unregisterView(View *widget); - - virtual QString getPropertyContainerIconName() const { return "panner"; } - -public slots: - virtual void modelChanged(size_t startFrame, size_t endFrame); - virtual void modelReplaced(); - - virtual void viewManagerCentreFrameChanged(void *, unsigned long, bool); - virtual void viewManagerZoomLevelChanged(void *, unsigned long, bool); - virtual void viewManagerPlaybackFrameChanged(unsigned long); - -protected: - virtual void paintEvent(QPaintEvent *e); - virtual void mousePressEvent(QMouseEvent *e); - virtual void mouseReleaseEvent(QMouseEvent *e); - virtual void mouseMoveEvent(QMouseEvent *e); - virtual bool shouldLabelSelections() const { return false; } - - QPoint m_clickPos; - QPoint m_mousePos; - bool m_clickedInRange; - size_t m_dragCentreFrame; - - typedef std::set WidgetSet; - WidgetSet m_widgets; -}; - -#endif - diff -r d0b95a8cac96 -r 9c40dc10c88c view/view.pro --- a/view/view.pro Wed Oct 18 16:38:30 2006 +0000 +++ b/view/view.pro Thu Oct 19 09:57:27 2006 +0000 @@ -14,5 +14,13 @@ MOC_DIR = tmp_moc # Input -HEADERS += Pane.h PaneStack.h Panner.h View.h ViewManager.h -SOURCES += Pane.cpp PaneStack.cpp Panner.cpp View.cpp ViewManager.cpp +HEADERS += Overview.h \ + Pane.h \ + PaneStack.h \ + View.h \ + ViewManager.h +SOURCES += Overview.cpp \ + Pane.cpp \ + PaneStack.cpp \ + View.cpp \ + ViewManager.cpp diff -r d0b95a8cac96 -r 9c40dc10c88c widgets/Panner.cpp --- a/widgets/Panner.cpp Wed Oct 18 16:38:30 2006 +0000 +++ b/widgets/Panner.cpp Thu Oct 19 09:57:27 2006 +0000 @@ -27,7 +27,11 @@ m_rectX(0), m_rectY(0), m_rectWidth(1), - m_rectHeight(1) + m_rectHeight(1), + m_defaultCentreX(0), + m_defaultCentreY(0), + m_defaultsSet(false), + m_clicked(false) { } @@ -38,38 +42,81 @@ void Panner::mousePressEvent(QMouseEvent *e) { + 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(); } void Panner::mouseMoveEvent(QMouseEvent *e) { + if (!m_clicked) return; + + float dx = float(e->pos().x() - m_clickPos.x()) / float(width()); + float dy = float(e->pos().y() - m_clickPos.y()) / float(height()); + + m_rectX = m_dragStartX + dx; + m_rectY = m_dragStartY + dy; + + normalise(); + emitAndUpdate(); } void Panner::mouseReleaseEvent(QMouseEvent *e) { + if (!m_clicked) return; + + mouseMoveEvent(e); + m_clicked = false; } void Panner::wheelEvent(QWheelEvent *e) { + if (e->delta() > 0) { + m_rectY += 0.1; + } else { + m_rectY -= 0.1; + } + + normalise(); + emitAndUpdate(); } void Panner::paintEvent(QPaintEvent *e) { QPainter paint(this); - paint.fillRect(rect(), palette().background().color()); paint.setRenderHint(QPainter::Antialiasing, false); + + QColor bg(palette().background().color()); + bg.setAlpha(80); + paint.setPen(palette().dark().color()); - paint.setBrush(palette().highlight().color()); - paint.drawRect(QRectF(width() * m_rectX, height() - height() * m_rectY, - width() * m_rectWidth, height() * m_rectHeight)); + paint.setBrush(bg); + paint.drawRect(0, 0, width(), height()); + + QColor hl(palette().highlight().color()); + hl.setAlpha(80); + + paint.setBrush(hl); + + paint.drawRect(lrintf(width() * m_rectX), + lrintf(height() * m_rectY), + lrintf(width() * m_rectWidth), + lrintf(height() * m_rectHeight)); } void @@ -81,13 +128,19 @@ if (m_rectX < 0) m_rectX = 0; if (m_rectY + m_rectHeight > 1.0) m_rectY = 1.0 - m_rectHeight; if (m_rectY < 0) m_rectY = 0; + + if (!m_defaultsSet) { + m_defaultCentreX = centreX(); + m_defaultCentreY = centreY(); + m_defaultsSet = true; + } } void Panner::emitAndUpdate() { emit rectExtentsChanged(m_rectX, m_rectY, m_rectWidth, m_rectHeight); - emit rectCentreMoved(m_rectX + (m_rectWidth/2), m_rectY + (m_rectHeight/2)); + emit rectCentreMoved(centreX(), centreY()); update(); } @@ -100,10 +153,12 @@ m_rectHeight == height) { return; } + m_rectX = x0; m_rectY = y0; m_rectWidth = width; m_rectHeight = height; + normalise(); emitAndUpdate(); } @@ -139,7 +194,7 @@ void Panner::setRectCentreY(float y) { - float y0 = y - m_rectWidth/2; + float y0 = y - m_rectHeight/2; if (y0 == m_rectY) return; m_rectY = y0; normalise(); @@ -152,5 +207,24 @@ return QSize(30, 30); } +void +Panner::setDefaultRectCentre(float cx, float cy) +{ + m_defaultCentreX = cx; + m_defaultCentreY = cy; + m_defaultsSet = true; +} +void +Panner::resetToDefault() +{ + float x0 = m_defaultCentreX - m_rectWidth/2; + float y0 = m_defaultCentreY - m_rectHeight/2; + if (x0 == m_rectX && y0 == m_rectY) return; + m_rectX = x0; + m_rectY = y0; + normalise(); + emitAndUpdate(); +} + diff -r d0b95a8cac96 -r 9c40dc10c88c widgets/Panner.h --- a/widgets/Panner.h Wed Oct 18 16:38:30 2006 +0000 +++ b/widgets/Panner.h Thu Oct 19 09:57:27 2006 +0000 @@ -26,6 +26,8 @@ Panner(QWidget *parent = 0); virtual ~Panner(); + void setDefaultRectCentre(float, float); + virtual void mousePressEvent(QMouseEvent *e); virtual void mouseDoubleClickEvent(QMouseEvent *e); virtual void mouseMoveEvent(QMouseEvent *e); @@ -89,11 +91,24 @@ protected: void normalise(); void emitAndUpdate(); + void resetToDefault(); float m_rectX; float m_rectY; float m_rectWidth; float m_rectHeight; + + float m_defaultCentreX; + float m_defaultCentreY; + bool m_defaultsSet; + + float centreX() const { return m_rectX + m_rectWidth/2; } + float centreY() const { return m_rectY + m_rectHeight/2; } + + bool m_clicked; + QPoint m_clickPos; + float m_dragStartX; + float m_dragStartY; }; #endif