Chris@172
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@172
|
2
|
Chris@172
|
3 /*
|
Chris@172
|
4 Sonic Visualiser
|
Chris@172
|
5 An audio file viewer and annotation editor.
|
Chris@172
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 QMUL.
|
Chris@172
|
8
|
Chris@172
|
9 This program is free software; you can redistribute it and/or
|
Chris@172
|
10 modify it under the terms of the GNU General Public License as
|
Chris@172
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@172
|
12 License, or (at your option) any later version. See the file
|
Chris@172
|
13 COPYING included with this distribution for more information.
|
Chris@172
|
14 */
|
Chris@172
|
15
|
Chris@172
|
16 #ifndef _PANNER_H_
|
Chris@172
|
17 #define _PANNER_H_
|
Chris@172
|
18
|
Chris@172
|
19 #include <QWidget>
|
Chris@172
|
20
|
Chris@172
|
21 class Panner : public QWidget
|
Chris@172
|
22 {
|
Chris@172
|
23 Q_OBJECT
|
Chris@172
|
24
|
Chris@172
|
25 public:
|
Chris@172
|
26 Panner(QWidget *parent = 0);
|
Chris@172
|
27 virtual ~Panner();
|
Chris@172
|
28
|
Chris@173
|
29 void setDefaultRectCentre(float, float);
|
Chris@173
|
30
|
Chris@174
|
31 void setThumbColour(QColor colour);
|
Chris@174
|
32 void setAlpha(int backgroundAlpha, int thumbAlpha);
|
Chris@174
|
33
|
Chris@188
|
34 void getRectExtents(float &x0, float &y0, float &width, float &height);
|
Chris@188
|
35
|
Chris@172
|
36 virtual QSize sizeHint() const;
|
Chris@172
|
37
|
Chris@172
|
38 signals:
|
Chris@172
|
39 /**
|
Chris@172
|
40 * Emitted when the panned rectangle is dragged or otherwise
|
Chris@172
|
41 * moved. Arguments are x0, y0, width and height of the rectangle
|
Chris@172
|
42 * in the range 0 -> 1 as proportions of the width and height of
|
Chris@172
|
43 * the whole widget.
|
Chris@172
|
44 */
|
Chris@172
|
45 void rectExtentsChanged(float, float, float, float);
|
Chris@172
|
46
|
Chris@172
|
47 /**
|
Chris@172
|
48 * Emitted when the rectangle is dragged or otherwise moved (as
|
Chris@172
|
49 * well as extentsChanged). Arguments are the centre coordinates
|
Chris@172
|
50 * of the rectangle in the range 0 -> 1 as proportions of the
|
Chris@172
|
51 * width and height of the whole widget.
|
Chris@172
|
52 */
|
Chris@172
|
53 void rectCentreMoved(float, float);
|
Chris@172
|
54
|
Chris@188
|
55 /**
|
Chris@188
|
56 * Emitted when the panner is double-clicked (for the "customer"
|
Chris@188
|
57 * code to pop up a value editing dialog, for example).
|
Chris@188
|
58 */
|
Chris@188
|
59 void doubleClicked();
|
Chris@188
|
60
|
Chris@189
|
61 void mouseEntered();
|
Chris@189
|
62 void mouseLeft();
|
Chris@189
|
63
|
Chris@172
|
64 public slots:
|
Chris@172
|
65 /**
|
Chris@172
|
66 * Set the extents of the panned rectangle within the overall
|
Chris@172
|
67 * panner widget. Coordinates are in the range 0 -> 1 in both axes,
|
Chris@172
|
68 * with 0 at the top in the y axis.
|
Chris@172
|
69 */
|
Chris@172
|
70 void setRectExtents(float x0, float y0, float width, float height);
|
Chris@172
|
71
|
Chris@172
|
72 /**
|
Chris@172
|
73 * Set the width of the panned rectangle as a fraction (0 -> 1) of
|
Chris@172
|
74 * that of the whole panner widget.
|
Chris@172
|
75 */
|
Chris@172
|
76 void setRectWidth(float width);
|
Chris@172
|
77
|
Chris@172
|
78 /**
|
Chris@172
|
79 * Set the height of the panned rectangle as a fraction (0 -> 1)
|
Chris@172
|
80 * of that of the whole panner widget.
|
Chris@172
|
81 */
|
Chris@172
|
82 void setRectHeight(float height);
|
Chris@172
|
83
|
Chris@172
|
84 /**
|
Chris@172
|
85 * Set the location of the centre of the panned rectangle on the x
|
Chris@172
|
86 * axis, as a proportion (0 -> 1) of the width of the whole panner
|
Chris@172
|
87 * widget.
|
Chris@172
|
88 */
|
Chris@172
|
89 void setRectCentreX(float x);
|
Chris@172
|
90
|
Chris@172
|
91 /**
|
Chris@172
|
92 * Set the location of the centre of the panned rectangle on the y
|
Chris@172
|
93 * axis, as a proportion (0 -> 1) of the height of the whole panner
|
Chris@172
|
94 * widget.
|
Chris@172
|
95 */
|
Chris@172
|
96 void setRectCentreY(float y);
|
Chris@172
|
97
|
Chris@188
|
98 void resetToDefault();
|
Chris@188
|
99
|
Chris@172
|
100 protected:
|
Chris@189
|
101 virtual void mousePressEvent(QMouseEvent *e);
|
Chris@189
|
102 virtual void mouseDoubleClickEvent(QMouseEvent *e);
|
Chris@189
|
103 virtual void mouseMoveEvent(QMouseEvent *e);
|
Chris@189
|
104 virtual void mouseReleaseEvent(QMouseEvent *e);
|
Chris@189
|
105 virtual void wheelEvent(QWheelEvent *e);
|
Chris@189
|
106 virtual void paintEvent(QPaintEvent *e);
|
Chris@189
|
107 virtual void enterEvent(QEvent *);
|
Chris@189
|
108 virtual void leaveEvent(QEvent *);
|
Chris@189
|
109
|
Chris@172
|
110 void normalise();
|
Chris@172
|
111 void emitAndUpdate();
|
Chris@172
|
112
|
Chris@172
|
113 float m_rectX;
|
Chris@172
|
114 float m_rectY;
|
Chris@172
|
115 float m_rectWidth;
|
Chris@172
|
116 float m_rectHeight;
|
Chris@173
|
117
|
Chris@173
|
118 float m_defaultCentreX;
|
Chris@173
|
119 float m_defaultCentreY;
|
Chris@173
|
120 bool m_defaultsSet;
|
Chris@173
|
121
|
Chris@174
|
122 QColor m_thumbColour;
|
Chris@174
|
123 int m_backgroundAlpha;
|
Chris@174
|
124 int m_thumbAlpha;
|
Chris@174
|
125
|
Chris@173
|
126 float centreX() const { return m_rectX + m_rectWidth/2; }
|
Chris@173
|
127 float centreY() const { return m_rectY + m_rectHeight/2; }
|
Chris@173
|
128
|
Chris@173
|
129 bool m_clicked;
|
Chris@173
|
130 QPoint m_clickPos;
|
Chris@173
|
131 float m_dragStartX;
|
Chris@173
|
132 float m_dragStartY;
|
Chris@172
|
133 };
|
Chris@172
|
134
|
Chris@172
|
135 #endif
|
Chris@172
|
136
|