Chris@929
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@929
|
2
|
Chris@929
|
3 /*
|
Chris@929
|
4 Sonic Visualiser
|
Chris@929
|
5 An audio file viewer and annotation editor.
|
Chris@929
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@929
|
7
|
Chris@929
|
8 This program is free software; you can redistribute it and/or
|
Chris@929
|
9 modify it under the terms of the GNU General Public License as
|
Chris@929
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@929
|
11 License, or (at your option) any later version. See the file
|
Chris@929
|
12 COPYING included with this distribution for more information.
|
Chris@929
|
13 */
|
Chris@929
|
14
|
Chris@929
|
15 #include "LevelPanToolButton.h"
|
Chris@929
|
16 #include "LevelPanWidget.h"
|
Chris@929
|
17
|
Chris@929
|
18 #include <QMenu>
|
Chris@929
|
19 #include <QWidgetAction>
|
Chris@929
|
20 #include <QImage>
|
Chris@936
|
21 #include <QStylePainter>
|
Chris@936
|
22 #include <QStyleOptionToolButton>
|
Chris@929
|
23
|
Chris@929
|
24 #include <iostream>
|
Chris@929
|
25 using std::cerr;
|
Chris@929
|
26 using std::endl;
|
Chris@929
|
27
|
Chris@929
|
28 LevelPanToolButton::LevelPanToolButton(QWidget *parent) :
|
Chris@929
|
29 QToolButton(parent),
|
Chris@930
|
30 m_pixels(32),
|
Chris@942
|
31 m_pixelsBig(32 * 3),
|
Chris@930
|
32 m_muted(false),
|
Chris@930
|
33 m_savedLevel(1.f)
|
Chris@929
|
34 {
|
Chris@929
|
35 m_lpw = new LevelPanWidget();
|
Chris@929
|
36
|
Chris@929
|
37 connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float)));
|
Chris@930
|
38 connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float)));
|
Chris@929
|
39
|
Chris@929
|
40 connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float)));
|
Chris@932
|
41 connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(update()));
|
Chris@930
|
42
|
Chris@930
|
43 connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked()));
|
Chris@929
|
44
|
Chris@929
|
45 QMenu *menu = new QMenu();
|
Chris@929
|
46 QWidgetAction *wa = new QWidgetAction(menu);
|
Chris@929
|
47 wa->setDefaultWidget(m_lpw);
|
Chris@929
|
48 menu->addAction(wa);
|
Chris@929
|
49
|
Chris@936
|
50 setPopupMode(InstantPopup);
|
Chris@929
|
51 setMenu(menu);
|
Chris@1191
|
52 setToolTip(tr("Click to adjust level and pan"));
|
Chris@929
|
53
|
Chris@932
|
54 setImageSize(m_pixels);
|
Chris@942
|
55 setBigImageSize(m_pixelsBig);
|
Chris@929
|
56 }
|
Chris@929
|
57
|
Chris@929
|
58 LevelPanToolButton::~LevelPanToolButton()
|
Chris@929
|
59 {
|
Chris@929
|
60 }
|
Chris@929
|
61
|
Chris@929
|
62 float
|
Chris@929
|
63 LevelPanToolButton::getLevel() const
|
Chris@929
|
64 {
|
Chris@929
|
65 return m_lpw->getLevel();
|
Chris@929
|
66 }
|
Chris@929
|
67
|
Chris@929
|
68 float
|
Chris@929
|
69 LevelPanToolButton::getPan() const
|
Chris@929
|
70 {
|
Chris@929
|
71 return m_lpw->getPan();
|
Chris@929
|
72 }
|
Chris@929
|
73
|
Chris@940
|
74 bool
|
Chris@940
|
75 LevelPanToolButton::includesMute() const
|
Chris@940
|
76 {
|
Chris@940
|
77 return m_lpw->includesMute();
|
Chris@940
|
78 }
|
Chris@940
|
79
|
Chris@929
|
80 void
|
Chris@929
|
81 LevelPanToolButton::setImageSize(int pixels)
|
Chris@929
|
82 {
|
Chris@929
|
83 m_pixels = pixels;
|
Chris@932
|
84
|
Chris@932
|
85 QPixmap px(m_pixels, m_pixels);
|
Chris@932
|
86 px.fill(Qt::transparent);
|
Chris@932
|
87 setIcon(px);
|
Chris@942
|
88 }
|
Chris@932
|
89
|
Chris@942
|
90 void
|
Chris@942
|
91 LevelPanToolButton::setBigImageSize(int pixels)
|
Chris@942
|
92 {
|
Chris@942
|
93 m_pixelsBig = pixels;
|
Chris@942
|
94
|
Chris@942
|
95 m_lpw->setFixedWidth(m_pixelsBig);
|
Chris@942
|
96 m_lpw->setFixedHeight(m_pixelsBig);
|
Chris@929
|
97 }
|
Chris@929
|
98
|
Chris@929
|
99 void
|
Chris@929
|
100 LevelPanToolButton::setLevel(float level)
|
Chris@929
|
101 {
|
Chris@929
|
102 m_lpw->setLevel(level);
|
Chris@932
|
103 update();
|
Chris@929
|
104 }
|
Chris@929
|
105
|
Chris@929
|
106 void
|
Chris@929
|
107 LevelPanToolButton::setPan(float pan)
|
Chris@929
|
108 {
|
Chris@929
|
109 m_lpw->setPan(pan);
|
Chris@932
|
110 update();
|
Chris@930
|
111 }
|
Chris@930
|
112
|
Chris@930
|
113 void
|
Chris@1187
|
114 LevelPanToolButton::setMonitoringLevels(float left, float right)
|
Chris@1187
|
115 {
|
Chris@1187
|
116 m_lpw->setMonitoringLevels(left, right);
|
Chris@1187
|
117 update();
|
Chris@1187
|
118 }
|
Chris@1187
|
119
|
Chris@1187
|
120 void
|
Chris@940
|
121 LevelPanToolButton::setIncludeMute(bool include)
|
Chris@940
|
122 {
|
Chris@940
|
123 m_lpw->setIncludeMute(include);
|
Chris@940
|
124 update();
|
Chris@940
|
125 }
|
Chris@940
|
126
|
Chris@940
|
127 void
|
Chris@933
|
128 LevelPanToolButton::setEnabled(bool enabled)
|
Chris@933
|
129 {
|
Chris@933
|
130 m_lpw->setEnabled(enabled);
|
Chris@933
|
131 QToolButton::setEnabled(enabled);
|
Chris@933
|
132 }
|
Chris@933
|
133
|
Chris@933
|
134 void
|
Chris@930
|
135 LevelPanToolButton::selfLevelChanged(float level)
|
Chris@930
|
136 {
|
Chris@930
|
137 if (level > 0.f) {
|
Chris@930
|
138 m_muted = false;
|
Chris@930
|
139 } else {
|
Chris@930
|
140 m_muted = true;
|
Chris@930
|
141 m_savedLevel = 1.f;
|
Chris@930
|
142 }
|
Chris@932
|
143 update();
|
Chris@930
|
144 }
|
Chris@930
|
145
|
Chris@930
|
146 void
|
Chris@930
|
147 LevelPanToolButton::selfClicked()
|
Chris@930
|
148 {
|
Chris@930
|
149 cerr << "selfClicked" << endl;
|
Chris@930
|
150
|
Chris@930
|
151 if (m_muted) {
|
Chris@930
|
152 m_muted = false;
|
Chris@930
|
153 m_lpw->setLevel(m_savedLevel);
|
Chris@931
|
154 emit levelChanged(m_savedLevel);
|
Chris@930
|
155 } else {
|
Chris@930
|
156 m_savedLevel = m_lpw->getLevel();
|
Chris@930
|
157 m_muted = true;
|
Chris@930
|
158 m_lpw->setLevel(0.f);
|
Chris@931
|
159 emit levelChanged(0.f);
|
Chris@930
|
160 }
|
Chris@932
|
161 update();
|
Chris@929
|
162 }
|
Chris@929
|
163
|
Chris@929
|
164 void
|
Chris@936
|
165 LevelPanToolButton::paintEvent(QPaintEvent *)
|
Chris@929
|
166 {
|
Chris@936
|
167 QStylePainter p(this);
|
Chris@936
|
168 QStyleOptionToolButton opt;
|
Chris@936
|
169 initStyleOption(&opt);
|
Chris@936
|
170 opt.features &= (~QStyleOptionToolButton::HasMenu);
|
Chris@936
|
171 p.drawComplexControl(QStyle::CC_ToolButton, opt);
|
Chris@936
|
172
|
Chris@934
|
173 if (m_pixels >= height()) {
|
Chris@934
|
174 setImageSize(height()-1);
|
Chris@934
|
175 }
|
Chris@936
|
176
|
Chris@932
|
177 double margin = (double(height()) - m_pixels) / 2.0;
|
Chris@932
|
178 m_lpw->renderTo(this, QRectF(margin, margin, m_pixels, m_pixels), false);
|
Chris@929
|
179 }
|
Chris@929
|
180
|
Chris@1180
|
181 void
|
Chris@1180
|
182 LevelPanToolButton::enterEvent(QEvent *e)
|
Chris@1180
|
183 {
|
Chris@1180
|
184 QToolButton::enterEvent(e);
|
Chris@1180
|
185 emit mouseEntered();
|
Chris@1180
|
186 }
|
Chris@932
|
187
|
Chris@1180
|
188 void
|
Chris@1180
|
189 LevelPanToolButton::leaveEvent(QEvent *e)
|
Chris@1180
|
190 {
|
Chris@1180
|
191 QToolButton::enterEvent(e);
|
Chris@1180
|
192 emit mouseLeft();
|
Chris@1180
|
193 }
|
Chris@1180
|
194
|
Chris@1180
|
195
|