comparison widgets/Panner.h @ 0:fc9323a41f5a

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