Chris@923: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@923: 
Chris@923: /*
Chris@923:     Sonic Visualiser
Chris@923:     An audio file viewer and annotation editor.
Chris@923:     Centre for Digital Music, Queen Mary, University of London.
Chris@923:     
Chris@923:     This program is free software; you can redistribute it and/or
Chris@923:     modify it under the terms of the GNU General Public License as
Chris@923:     published by the Free Software Foundation; either version 2 of the
Chris@923:     License, or (at your option) any later version.  See the file
Chris@923:     COPYING included with this distribution for more information.
Chris@923: */
Chris@923: 
Chris@923: #ifndef LEVEL_PAN_WIDGET_H
Chris@923: #define LEVEL_PAN_WIDGET_H
Chris@923: 
Chris@923: #include <QWidget>
Chris@923: 
Chris@923: /**
Chris@923:  * A simple widget for coarse level and pan control.
Chris@923:  */
Chris@923: 
Chris@923: class LevelPanWidget : public QWidget
Chris@923: {
Chris@923:     Q_OBJECT
Chris@923: 
Chris@923: public:
Chris@923:     LevelPanWidget(QWidget *parent = 0);
Chris@923:     ~LevelPanWidget();
Chris@923:     
Chris@923:     /// Return level as a gain value in the range [0,1]
Chris@923:     float getLevel() const; 
Chris@923:     
Chris@923:     /// Return pan as a value in the range [-1,1]
Chris@923:     float getPan() const;
Chris@923: 
Chris@923:     /// Find out whether the widget is editable
Chris@923:     bool isEditable() const;
Chris@923: 
Chris@940:     /// Discover whether the level range includes muting or not
Chris@940:     bool includesMute() const;
Chris@940: 
Chris@929:     /// Draw a suitably sized copy of the widget's contents to the given device
Chris@929:     void renderTo(QPaintDevice *, QRectF, bool asIfEditable) const;
Chris@929: 
Chris@929:     QSize sizeHint() const;
Chris@929:                                                
Chris@923: public slots:
Chris@923:     /// Set level in the range [0,1] -- will be rounded
Chris@923:     void setLevel(float);
Chris@923: 
Chris@923:     /// Set pan in the range [-1,1] -- will be rounded
Chris@923:     void setPan(float);
Chris@923: 
Chris@923:     /// Specify whether the widget is editable or read-only (default editable)
Chris@923:     void setEditable(bool);
Chris@940: 
Chris@940:     /// Specify whether the level range should include muting or not
Chris@940:     void setIncludeMute(bool);
Chris@923:     
Chris@923: signals:
Chris@923:     void levelChanged(float);
Chris@923:     void panChanged(float);
Chris@923: 
Chris@923: protected:
Chris@923:     virtual void mousePressEvent(QMouseEvent *ev);
Chris@923:     virtual void mouseMoveEvent(QMouseEvent *ev);
Chris@923:     virtual void mouseReleaseEvent(QMouseEvent *ev);
Chris@923:     virtual void wheelEvent(QWheelEvent *ev);
Chris@923:     virtual void paintEvent(QPaintEvent *ev);
Chris@923: 
Chris@923:     void emitLevelChanged();
Chris@923:     void emitPanChanged();
Chris@923:     
Chris@923:     int m_level;
Chris@923:     int m_pan;
Chris@923:     bool m_editable;
Chris@940:     bool m_includeMute;
Chris@923: 
Chris@929:     QSizeF cellSize(QRectF) const;
Chris@929:     QPointF cellCentre(QRectF, int level, int pan) const;
Chris@929:     QSizeF cellLightSize(QRectF) const;
Chris@929:     QRectF cellLightRect(QRectF, int level, int pan) const;
Chris@929:     double thinLineWidth(QRectF) const;
Chris@929:     void toCell(QRectF, QPointF loc, int &level, int &pan) const;
Chris@923: };
Chris@923: 
Chris@923: #endif