Panner.h
Go to the documentation of this file.
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 SV_PANNER_H
17 #define SV_PANNER_H
18 
19 #include <QWidget>
20 
21 #include "WheelCounter.h"
22 
23 class Panner : public QWidget
24 {
25  Q_OBJECT
26 
27 public:
28  Panner(QWidget *parent = 0);
29  virtual ~Panner();
30 
31  void setDefaultRectCentre(float, float);
32 
33  void setThumbColour(QColor colour);
34  void setAlpha(int backgroundAlpha, int thumbAlpha);
35 
42  void setScrollUnit(float unit);
43 
44  void getRectExtents(float &x0, float &y0, float &width, float &height);
45 
46  QSize sizeHint() const override;
47 
48 signals:
55  void rectExtentsChanged(float, float, float, float);
56 
63  void rectCentreMoved(float, float);
64 
69  void doubleClicked();
70 
71  void mouseEntered();
72  void mouseLeft();
73 
74 public slots:
80  void setRectExtents(float x0, float y0, float width, float height);
81 
86  void setRectWidth(float width);
87 
92  void setRectHeight(float height);
93 
99  void setRectCentreX(float x);
100 
106  void setRectCentreY(float y);
107 
112  void scroll(bool up);
113 
118  void scroll(bool up, int n);
119 
120  void resetToDefault();
121 
122 protected:
123  void mousePressEvent(QMouseEvent *e) override;
124  void mouseDoubleClickEvent(QMouseEvent *e) override;
125  void mouseMoveEvent(QMouseEvent *e) override;
126  void mouseReleaseEvent(QMouseEvent *e) override;
127  void wheelEvent(QWheelEvent *e) override;
128  void paintEvent(QPaintEvent *e) override;
129  void enterEvent(QEvent *) override;
130  void leaveEvent(QEvent *) override;
131 
132  void normalise();
133  void emitAndUpdate();
134 
135  float m_rectX;
136  float m_rectY;
137  float m_rectWidth;
140 
144 
148 
149  float centreX() const { return m_rectX + m_rectWidth/2; }
150  float centreY() const { return m_rectY + m_rectHeight/2; }
151 
152  bool m_clicked;
153  QPoint m_clickPos;
156 
158 };
159 
160 #endif
161 
void mouseDoubleClickEvent(QMouseEvent *e) override
Definition: Panner.cpp:105
void normalise()
Definition: Panner.cpp:192
float m_rectHeight
Definition: Panner.h:138
void mouseReleaseEvent(QMouseEvent *e) override
Definition: Panner.cpp:132
void getRectExtents(float &x0, float &y0, float &width, float &height)
Definition: Panner.cpp:217
int m_backgroundAlpha
Definition: Panner.h:146
Panner(QWidget *parent=0)
Definition: Panner.cpp:28
int m_thumbAlpha
Definition: Panner.h:147
void scroll(bool up)
Move up (if up is true) or down a bit.
Definition: Panner.cpp:65
float m_dragStartY
Definition: Panner.h:155
void setScrollUnit(float unit)
Set the amount the scroll() function or mouse wheel movement makes the panner rectangle move by...
Definition: Panner.cpp:59
float centreX() const
Definition: Panner.h:149
void mouseEntered()
bool m_defaultsSet
Definition: Panner.h:143
void mousePressEvent(QMouseEvent *e) override
Definition: Panner.cpp:90
QPoint m_clickPos
Definition: Panner.h:153
float m_rectX
Definition: Panner.h:135
void leaveEvent(QEvent *) override
Definition: Panner.cpp:154
void setRectWidth(float width)
Set the width of the panned rectangle as a fraction (0 -> 1) of that of the whole panner widget...
Definition: Panner.cpp:248
Manage the little bit of tedious book-keeping associated with translating vertical wheel events into ...
Definition: WheelCounter.h:24
Definition: Panner.h:23
bool m_clicked
Definition: Panner.h:152
QSize sizeHint() const override
Definition: Panner.cpp:286
void setRectHeight(float height)
Set the height of the panned rectangle as a fraction (0 -> 1) of that of the whole panner widget...
Definition: Panner.cpp:257
virtual ~Panner()
Definition: Panner.cpp:47
void mouseLeft()
void setThumbColour(QColor colour)
void setRectCentreY(float y)
Set the location of the centre of the panned rectangle on the y axis, as a proportion (0 -> 1) of the...
Definition: Panner.cpp:276
void emitAndUpdate()
Definition: Panner.cpp:209
void wheelEvent(QWheelEvent *e) override
Definition: Panner.cpp:141
void paintEvent(QPaintEvent *e) override
Definition: Panner.cpp:160
void rectExtentsChanged(float, float, float, float)
Emitted when the panned rectangle is dragged or otherwise moved.
float centreY() const
Definition: Panner.h:150
float m_dragStartX
Definition: Panner.h:154
WheelCounter m_wheelCounter
Definition: Panner.h:157
void doubleClicked()
Emitted when the panner is double-clicked (for the "customer" code to pop up a value editing dialog...
float m_defaultCentreX
Definition: Panner.h:141
void resetToDefault()
Definition: Panner.cpp:300
float m_rectY
Definition: Panner.h:136
void enterEvent(QEvent *) override
Definition: Panner.cpp:148
void setRectCentreX(float x)
Set the location of the centre of the panned rectangle on the x axis, as a proportion (0 -> 1) of the...
Definition: Panner.cpp:266
float m_rectWidth
Definition: Panner.h:137
void setDefaultRectCentre(float, float)
Definition: Panner.cpp:292
float m_defaultCentreY
Definition: Panner.h:142
void setRectExtents(float x0, float y0, float width, float height)
Set the extents of the panned rectangle within the overall panner widget.
Definition: Panner.cpp:226
QColor m_thumbColour
Definition: Panner.h:145
void mouseMoveEvent(QMouseEvent *e) override
Definition: Panner.cpp:115
void rectCentreMoved(float, float)
Emitted when the rectangle is dragged or otherwise moved (as well as extentsChanged).
void setAlpha(int backgroundAlpha, int thumbAlpha)
Definition: Panner.cpp:52
float m_scrollUnit
Definition: Panner.h:139