Chris@172: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@172: Chris@172: /* Chris@172: Sonic Visualiser Chris@172: An audio file viewer and annotation editor. Chris@172: Centre for Digital Music, Queen Mary, University of London. Chris@182: This file copyright 2006 QMUL. Chris@172: Chris@172: This program is free software; you can redistribute it and/or Chris@172: modify it under the terms of the GNU General Public License as Chris@172: published by the Free Software Foundation; either version 2 of the Chris@172: License, or (at your option) any later version. See the file Chris@172: COPYING included with this distribution for more information. Chris@172: */ Chris@172: Chris@1303: #ifndef SV_PANNER_H Chris@1303: #define SV_PANNER_H Chris@172: Chris@172: #include Chris@172: Chris@1303: #include "WheelCounter.h" Chris@1303: Chris@172: class Panner : public QWidget Chris@172: { Chris@172: Q_OBJECT Chris@172: Chris@172: public: Chris@172: Panner(QWidget *parent = 0); Chris@172: virtual ~Panner(); Chris@172: Chris@173: void setDefaultRectCentre(float, float); Chris@173: Chris@174: void setThumbColour(QColor colour); Chris@174: void setAlpha(int backgroundAlpha, int thumbAlpha); Chris@174: Chris@256: /** Chris@256: * Set the amount the scroll() function or mouse wheel movement Chris@256: * makes the panner rectangle move by. The default value of 0 Chris@256: * means to select a value automatically based on the dimensions Chris@256: * of the panner rectangle. Chris@256: */ Chris@256: void setScrollUnit(float unit); Chris@256: Chris@188: void getRectExtents(float &x0, float &y0, float &width, float &height); Chris@188: Chris@172: virtual QSize sizeHint() const; Chris@172: Chris@172: signals: Chris@172: /** Chris@172: * Emitted when the panned rectangle is dragged or otherwise Chris@172: * moved. Arguments are x0, y0, width and height of the rectangle Chris@172: * in the range 0 -> 1 as proportions of the width and height of Chris@172: * the whole widget. Chris@172: */ Chris@172: void rectExtentsChanged(float, float, float, float); Chris@172: Chris@172: /** Chris@172: * Emitted when the rectangle is dragged or otherwise moved (as Chris@172: * well as extentsChanged). Arguments are the centre coordinates Chris@172: * of the rectangle in the range 0 -> 1 as proportions of the Chris@172: * width and height of the whole widget. Chris@172: */ Chris@172: void rectCentreMoved(float, float); Chris@172: Chris@188: /** Chris@188: * Emitted when the panner is double-clicked (for the "customer" Chris@188: * code to pop up a value editing dialog, for example). Chris@188: */ Chris@188: void doubleClicked(); Chris@188: Chris@189: void mouseEntered(); Chris@189: void mouseLeft(); Chris@189: Chris@172: public slots: Chris@172: /** Chris@172: * Set the extents of the panned rectangle within the overall Chris@172: * panner widget. Coordinates are in the range 0 -> 1 in both axes, Chris@172: * with 0 at the top in the y axis. Chris@172: */ Chris@172: void setRectExtents(float x0, float y0, float width, float height); Chris@172: Chris@172: /** Chris@172: * Set the width of the panned rectangle as a fraction (0 -> 1) of Chris@172: * that of the whole panner widget. Chris@172: */ Chris@172: void setRectWidth(float width); Chris@172: Chris@172: /** Chris@172: * Set the height of the panned rectangle as a fraction (0 -> 1) Chris@172: * of that of the whole panner widget. Chris@172: */ Chris@172: void setRectHeight(float height); Chris@172: Chris@172: /** Chris@172: * Set the location of the centre of the panned rectangle on the x Chris@172: * axis, as a proportion (0 -> 1) of the width of the whole panner Chris@172: * widget. Chris@172: */ Chris@172: void setRectCentreX(float x); Chris@172: Chris@172: /** Chris@172: * Set the location of the centre of the panned rectangle on the y Chris@172: * axis, as a proportion (0 -> 1) of the height of the whole panner Chris@172: * widget. Chris@172: */ Chris@172: void setRectCentreY(float y); Chris@172: Chris@256: /** Chris@256: * Move up (if up is true) or down a bit. This is basically the Chris@256: * same action as rolling the mouse wheel one notch. Chris@256: */ Chris@256: void scroll(bool up); Chris@256: Chris@1303: /** Chris@1303: * Move up (if up is true) or down a bit. This is basically the Chris@1303: * same action as rolling the mouse wheel n notches. Chris@1303: */ Chris@1303: void scroll(bool up, int n); Chris@1303: Chris@188: void resetToDefault(); Chris@188: Chris@172: protected: Chris@189: virtual void mousePressEvent(QMouseEvent *e); Chris@189: virtual void mouseDoubleClickEvent(QMouseEvent *e); Chris@189: virtual void mouseMoveEvent(QMouseEvent *e); Chris@189: virtual void mouseReleaseEvent(QMouseEvent *e); Chris@189: virtual void wheelEvent(QWheelEvent *e); Chris@189: virtual void paintEvent(QPaintEvent *e); Chris@189: virtual void enterEvent(QEvent *); Chris@189: virtual void leaveEvent(QEvent *); Chris@189: Chris@172: void normalise(); Chris@172: void emitAndUpdate(); Chris@172: Chris@172: float m_rectX; Chris@172: float m_rectY; Chris@172: float m_rectWidth; Chris@172: float m_rectHeight; Chris@256: float m_scrollUnit; Chris@173: Chris@173: float m_defaultCentreX; Chris@173: float m_defaultCentreY; Chris@173: bool m_defaultsSet; Chris@173: Chris@174: QColor m_thumbColour; Chris@174: int m_backgroundAlpha; Chris@174: int m_thumbAlpha; Chris@174: Chris@173: float centreX() const { return m_rectX + m_rectWidth/2; } Chris@173: float centreY() const { return m_rectY + m_rectHeight/2; } Chris@173: Chris@173: bool m_clicked; Chris@173: QPoint m_clickPos; Chris@173: float m_dragStartX; Chris@173: float m_dragStartY; Chris@1303: Chris@1303: WheelCounter m_wheelCounter; Chris@172: }; Chris@172: Chris@172: #endif Chris@172: