Mercurial > hg > svgui
comparison widgets/Panner.cpp @ 172:d0b95a8cac96
* A start to a panner widget to go with thumbwheels
author | Chris Cannam |
---|---|
date | Wed, 18 Oct 2006 16:38:30 +0000 |
parents | |
children | 9c40dc10c88c |
comparison
equal
deleted
inserted
replaced
171:78d523e8433e | 172:d0b95a8cac96 |
---|---|
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 Chris Cannam. | |
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 #include "Panner.h" | |
17 | |
18 #include <QMouseEvent> | |
19 #include <QPaintEvent> | |
20 #include <QWheelEvent> | |
21 #include <QPainter> | |
22 | |
23 #include <iostream> | |
24 | |
25 Panner::Panner(QWidget *parent) : | |
26 QWidget(parent), | |
27 m_rectX(0), | |
28 m_rectY(0), | |
29 m_rectWidth(1), | |
30 m_rectHeight(1) | |
31 { | |
32 } | |
33 | |
34 Panner::~Panner() | |
35 { | |
36 } | |
37 | |
38 void | |
39 Panner::mousePressEvent(QMouseEvent *e) | |
40 { | |
41 } | |
42 | |
43 void | |
44 Panner::mouseDoubleClickEvent(QMouseEvent *e) | |
45 { | |
46 } | |
47 | |
48 void | |
49 Panner::mouseMoveEvent(QMouseEvent *e) | |
50 { | |
51 } | |
52 | |
53 void | |
54 Panner::mouseReleaseEvent(QMouseEvent *e) | |
55 { | |
56 } | |
57 | |
58 void | |
59 Panner::wheelEvent(QWheelEvent *e) | |
60 { | |
61 } | |
62 | |
63 void | |
64 Panner::paintEvent(QPaintEvent *e) | |
65 { | |
66 QPainter paint(this); | |
67 paint.fillRect(rect(), palette().background().color()); | |
68 paint.setRenderHint(QPainter::Antialiasing, false); | |
69 paint.setPen(palette().dark().color()); | |
70 paint.setBrush(palette().highlight().color()); | |
71 paint.drawRect(QRectF(width() * m_rectX, height() - height() * m_rectY, | |
72 width() * m_rectWidth, height() * m_rectHeight)); | |
73 } | |
74 | |
75 void | |
76 Panner::normalise() | |
77 { | |
78 if (m_rectWidth > 1.0) m_rectWidth = 1.0; | |
79 if (m_rectHeight > 1.0) m_rectHeight = 1.0; | |
80 if (m_rectX + m_rectWidth > 1.0) m_rectX = 1.0 - m_rectWidth; | |
81 if (m_rectX < 0) m_rectX = 0; | |
82 if (m_rectY + m_rectHeight > 1.0) m_rectY = 1.0 - m_rectHeight; | |
83 if (m_rectY < 0) m_rectY = 0; | |
84 } | |
85 | |
86 void | |
87 Panner::emitAndUpdate() | |
88 { | |
89 emit rectExtentsChanged(m_rectX, m_rectY, m_rectWidth, m_rectHeight); | |
90 emit rectCentreMoved(m_rectX + (m_rectWidth/2), m_rectY + (m_rectHeight/2)); | |
91 update(); | |
92 } | |
93 | |
94 void | |
95 Panner::setRectExtents(float x0, float y0, float width, float height) | |
96 { | |
97 if (m_rectX == x0 && | |
98 m_rectY == y0 && | |
99 m_rectWidth == width && | |
100 m_rectHeight == height) { | |
101 return; | |
102 } | |
103 m_rectX = x0; | |
104 m_rectY = y0; | |
105 m_rectWidth = width; | |
106 m_rectHeight = height; | |
107 normalise(); | |
108 emitAndUpdate(); | |
109 } | |
110 | |
111 void | |
112 Panner::setRectWidth(float width) | |
113 { | |
114 if (m_rectWidth == width) return; | |
115 m_rectWidth = width; | |
116 normalise(); | |
117 emitAndUpdate(); | |
118 } | |
119 | |
120 void | |
121 Panner::setRectHeight(float height) | |
122 { | |
123 if (m_rectHeight == height) return; | |
124 m_rectHeight = height; | |
125 normalise(); | |
126 emitAndUpdate(); | |
127 } | |
128 | |
129 void | |
130 Panner::setRectCentreX(float x) | |
131 { | |
132 float x0 = x - m_rectWidth/2; | |
133 if (x0 == m_rectX) return; | |
134 m_rectX = x0; | |
135 normalise(); | |
136 emitAndUpdate(); | |
137 } | |
138 | |
139 void | |
140 Panner::setRectCentreY(float y) | |
141 { | |
142 float y0 = y - m_rectWidth/2; | |
143 if (y0 == m_rectY) return; | |
144 m_rectY = y0; | |
145 normalise(); | |
146 emitAndUpdate(); | |
147 } | |
148 | |
149 QSize | |
150 Panner::sizeHint() const | |
151 { | |
152 return QSize(30, 30); | |
153 } | |
154 | |
155 | |
156 |