Mercurial > hg > svgui
changeset 172:d0b95a8cac96
* A start to a panner widget to go with thumbwheels
author | Chris Cannam |
---|---|
date | Wed, 18 Oct 2006 16:38:30 +0000 |
parents | 78d523e8433e |
children | 9c40dc10c88c |
files | view/Pane.cpp view/Pane.h widgets/Panner.cpp widgets/Panner.h widgets/widgets.pro |
diffstat | 5 files changed, 270 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/view/Pane.cpp Tue Oct 17 18:54:43 2006 +0000 +++ b/view/Pane.cpp Wed Oct 18 16:38:30 2006 +0000 @@ -33,6 +33,7 @@ #include <QGridLayout> #include <QPushButton> #include "widgets/Thumbwheel.h" +#include "widgets/Panner.h" using std::cerr; using std::endl; @@ -84,16 +85,21 @@ m_headsUpDisplay->setLayout(layout); m_hthumb = new Thumbwheel(Qt::Horizontal); - layout->addWidget(m_hthumb, 1, 0); + layout->addWidget(m_hthumb, 1, 0, 2, 1); m_hthumb->setFixedWidth(70); m_hthumb->setFixedHeight(16); m_hthumb->setDefaultValue(0); m_hthumb->setSpeed(0.6); connect(m_hthumb, SIGNAL(valueChanged(int)), this, SLOT(horizontalThumbwheelMoved(int))); - + + m_vpan = new Panner; + layout->addWidget(m_vpan, 0, 1); + m_vpan->setFixedWidth(16); + m_vpan->setFixedHeight(70); + m_vthumb = new Thumbwheel(Qt::Vertical); - layout->addWidget(m_vthumb, 0, 1); + layout->addWidget(m_vthumb, 0, 2); m_vthumb->setFixedWidth(16); m_vthumb->setFixedHeight(70); connect(m_vthumb, SIGNAL(valueChanged(int)), this, @@ -102,7 +108,7 @@ QPushButton *reset = new QPushButton; reset->setFixedHeight(16); reset->setFixedWidth(16); - layout->addWidget(reset, 1, 1); + layout->addWidget(reset, 1, 2); connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); }
--- a/view/Pane.h Tue Oct 17 18:54:43 2006 +0000 +++ b/view/Pane.h Wed Oct 18 16:38:30 2006 +0000 @@ -28,6 +28,7 @@ class QPaintEvent; class Layer; class Thumbwheel; +class Panner; class Pane : public View { @@ -108,6 +109,7 @@ DragMode m_dragMode; QWidget *m_headsUpDisplay; + Panner *m_vpan; Thumbwheel *m_hthumb; Thumbwheel *m_vthumb; };
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/Panner.cpp Wed Oct 18 16:38:30 2006 +0000 @@ -0,0 +1,156 @@ +/* -*- 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 <QMouseEvent> +#include <QPaintEvent> +#include <QWheelEvent> +#include <QPainter> + +#include <iostream> + +Panner::Panner(QWidget *parent) : + QWidget(parent), + m_rectX(0), + m_rectY(0), + m_rectWidth(1), + m_rectHeight(1) +{ +} + +Panner::~Panner() +{ +} + +void +Panner::mousePressEvent(QMouseEvent *e) +{ +} + +void +Panner::mouseDoubleClickEvent(QMouseEvent *e) +{ +} + +void +Panner::mouseMoveEvent(QMouseEvent *e) +{ +} + +void +Panner::mouseReleaseEvent(QMouseEvent *e) +{ +} + +void +Panner::wheelEvent(QWheelEvent *e) +{ +} + +void +Panner::paintEvent(QPaintEvent *e) +{ + QPainter paint(this); + paint.fillRect(rect(), palette().background().color()); + paint.setRenderHint(QPainter::Antialiasing, false); + 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)); +} + +void +Panner::normalise() +{ + if (m_rectWidth > 1.0) m_rectWidth = 1.0; + if (m_rectHeight > 1.0) m_rectHeight = 1.0; + if (m_rectX + m_rectWidth > 1.0) m_rectX = 1.0 - m_rectWidth; + 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; +} + +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)); + update(); +} + +void +Panner::setRectExtents(float x0, float y0, float width, float height) +{ + if (m_rectX == x0 && + m_rectY == y0 && + m_rectWidth == width && + m_rectHeight == height) { + return; + } + m_rectX = x0; + m_rectY = y0; + m_rectWidth = width; + m_rectHeight = height; + normalise(); + emitAndUpdate(); +} + +void +Panner::setRectWidth(float width) +{ + if (m_rectWidth == width) return; + m_rectWidth = width; + normalise(); + emitAndUpdate(); +} + +void +Panner::setRectHeight(float height) +{ + if (m_rectHeight == height) return; + m_rectHeight = height; + normalise(); + emitAndUpdate(); +} + +void +Panner::setRectCentreX(float x) +{ + float x0 = x - m_rectWidth/2; + if (x0 == m_rectX) return; + m_rectX = x0; + normalise(); + emitAndUpdate(); +} + +void +Panner::setRectCentreY(float y) +{ + float y0 = y - m_rectWidth/2; + if (y0 == m_rectY) return; + m_rectY = y0; + normalise(); + emitAndUpdate(); +} + +QSize +Panner::sizeHint() const +{ + return QSize(30, 30); +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/Panner.h Wed Oct 18 16:38:30 2006 +0000 @@ -0,0 +1,100 @@ +/* -*- 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 _PANNER_H_ +#define _PANNER_H_ + +#include <QWidget> + +class Panner : public QWidget +{ + Q_OBJECT + +public: + Panner(QWidget *parent = 0); + virtual ~Panner(); + + 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); + + virtual QSize sizeHint() const; + +signals: + /** + * Emitted when the panned rectangle is dragged or otherwise + * moved. Arguments are x0, y0, width and height of the rectangle + * in the range 0 -> 1 as proportions of the width and height of + * the whole widget. + */ + void rectExtentsChanged(float, float, float, float); + + /** + * Emitted when the rectangle is dragged or otherwise moved (as + * well as extentsChanged). Arguments are the centre coordinates + * of the rectangle in the range 0 -> 1 as proportions of the + * width and height of the whole widget. + */ + void rectCentreMoved(float, float); + +public slots: + /** + * Set the extents of the panned rectangle within the overall + * panner widget. Coordinates are in the range 0 -> 1 in both axes, + * with 0 at the top in the y axis. + */ + void setRectExtents(float x0, float y0, float width, float height); + + /** + * Set the width of the panned rectangle as a fraction (0 -> 1) of + * that of the whole panner widget. + */ + void setRectWidth(float width); + + /** + * Set the height of the panned rectangle as a fraction (0 -> 1) + * of that of the whole panner widget. + */ + void setRectHeight(float height); + + /** + * Set the location of the centre of the panned rectangle on the x + * axis, as a proportion (0 -> 1) of the width of the whole panner + * widget. + */ + void setRectCentreX(float x); + + /** + * Set the location of the centre of the panned rectangle on the y + * axis, as a proportion (0 -> 1) of the height of the whole panner + * widget. + */ + void setRectCentreY(float y); + +protected: + void normalise(); + void emitAndUpdate(); + + float m_rectX; + float m_rectY; + float m_rectWidth; + float m_rectHeight; +}; + +#endif +
--- a/widgets/widgets.pro Tue Oct 17 18:54:43 2006 +0000 +++ b/widgets/widgets.pro Wed Oct 18 16:38:30 2006 +0000 @@ -20,6 +20,7 @@ LayerTree.h \ LEDButton.h \ ListInputDialog.h \ + Panner.h \ PluginParameterBox.h \ PluginParameterDialog.h \ PropertyBox.h \ @@ -34,6 +35,7 @@ LayerTree.cpp \ LEDButton.cpp \ ListInputDialog.cpp \ + Panner.cpp \ PluginParameterBox.cpp \ PluginParameterDialog.cpp \ PropertyBox.cpp \