Mercurial > hg > svgui
comparison widgets/LevelPanWidget.cpp @ 924:cfcdec324712 tonioni
No, we'll not handle mute separately -- make bottom level be muted. Also add support for enable/disable
author | Chris Cannam |
---|---|
date | Tue, 24 Mar 2015 15:48:12 +0000 |
parents | 2a9f1eb6e0ed |
children | 76f4b81b766d |
comparison
equal
deleted
inserted
replaced
923:2a9f1eb6e0ed | 924:cfcdec324712 |
---|---|
23 #include <iostream> | 23 #include <iostream> |
24 | 24 |
25 using std::cerr; | 25 using std::cerr; |
26 using std::endl; | 26 using std::endl; |
27 | 27 |
28 static const int maxLevel = 5; | 28 static const int maxLevel = 4; |
29 static const int maxPan = 2; // range is -maxPan to maxPan | 29 static const int maxPan = 2; // range is -maxPan to maxPan |
30 | 30 |
31 LevelPanWidget::LevelPanWidget(QWidget *parent) : | 31 LevelPanWidget::LevelPanWidget(QWidget *parent) : |
32 QWidget(parent), | 32 QWidget(parent), |
33 m_level(maxLevel), | 33 m_level(maxLevel), |
161 void | 161 void |
162 LevelPanWidget::toCell(QPointF loc, int &level, int &pan) const | 162 LevelPanWidget::toCell(QPointF loc, int &level, int &pan) const |
163 { | 163 { |
164 double w = width(), h = height(); | 164 double w = width(), h = height(); |
165 int npan = maxPan * 2 + 1; | 165 int npan = maxPan * 2 + 1; |
166 double wcell = w / npan, hcell = h / maxLevel; | 166 int nlevel = maxLevel + 1; |
167 double wcell = w / npan, hcell = h / nlevel; | |
167 level = int((h - loc.y()) / hcell) + 1; | 168 level = int((h - loc.y()) / hcell) + 1; |
168 if (level < 1) level = 1; | 169 if (level < 0) level = 0; |
169 if (level > maxLevel) level = maxLevel; | 170 if (level > maxLevel) level = maxLevel; |
170 pan = int(loc.x() / wcell) - maxPan; | 171 pan = int(loc.x() / wcell) - maxPan; |
171 if (pan < -maxPan) pan = -maxPan; | 172 if (pan < -maxPan) pan = -maxPan; |
172 if (pan > maxPan) pan = maxPan; | 173 if (pan > maxPan) pan = maxPan; |
173 } | 174 } |
175 QSizeF | 176 QSizeF |
176 LevelPanWidget::cellSize() const | 177 LevelPanWidget::cellSize() const |
177 { | 178 { |
178 double w = width(), h = height(); | 179 double w = width(), h = height(); |
179 int npan = maxPan * 2 + 1; | 180 int npan = maxPan * 2 + 1; |
180 double wcell = w / npan, hcell = h / maxLevel; | 181 int nlevel = maxLevel + 1; |
182 double wcell = w / npan, hcell = h / nlevel; | |
181 return QSizeF(wcell, hcell); | 183 return QSizeF(wcell, hcell); |
182 } | 184 } |
183 | 185 |
184 QPointF | 186 QPointF |
185 LevelPanWidget::cellCentre(int level, int pan) const | 187 LevelPanWidget::cellCentre(int level, int pan) const |
186 { | 188 { |
187 QSizeF cs = cellSize(); | 189 QSizeF cs = cellSize(); |
188 return QPointF(cs.width() * (pan + maxPan) + cs.width() / 2., | 190 return QPointF(cs.width() * (pan + maxPan) + cs.width() / 2., |
189 height() - cs.height() * level + cs.height() / 2.); | 191 height() - cs.height() * (level + 1) + cs.height() / 2.); |
190 } | 192 } |
191 | 193 |
192 QSizeF | 194 QSizeF |
193 LevelPanWidget::cellLightSize() const | 195 LevelPanWidget::cellLightSize() const |
194 { | 196 { |
233 pen.setWidthF(cellLightSize().width() + thin); | 235 pen.setWidthF(cellLightSize().width() + thin); |
234 pen.setCapStyle(Qt::RoundCap); | 236 pen.setCapStyle(Qt::RoundCap); |
235 paint.setPen(pen); | 237 paint.setPen(pen); |
236 | 238 |
237 for (int pan = -maxPan; pan <= maxPan; ++pan) { | 239 for (int pan = -maxPan; pan <= maxPan; ++pan) { |
238 paint.drawLine(cellCentre(1, pan), cellCentre(maxLevel, pan)); | 240 paint.drawLine(cellCentre(0, pan), cellCentre(maxLevel, pan)); |
239 } | 241 } |
240 | 242 |
241 pen.setColor(Qt::black); | 243 if (isEnabled()) { |
244 pen.setColor(Qt::black); | |
245 } else { | |
246 pen.setColor(Qt::darkGray); | |
247 } | |
248 | |
242 pen.setWidthF(thin); | 249 pen.setWidthF(thin); |
243 pen.setCapStyle(Qt::FlatCap); | 250 pen.setCapStyle(Qt::FlatCap); |
244 paint.setPen(pen); | 251 paint.setPen(pen); |
245 | 252 |
246 for (int level = 1; level <= m_level; ++level) { | 253 for (int level = 0; level <= m_level; ++level) { |
247 // level starts at 1 because we handle mute separately | 254 if (isEnabled()) { |
248 paint.setBrush(mapper.map(level)); | 255 paint.setBrush(mapper.map(level)); |
249 paint.drawEllipse(cellLightRect(level, m_pan)); | 256 } |
250 } | 257 QRectF clr = cellLightRect(level, m_pan); |
251 } | 258 if (m_level == 0) { |
252 | 259 paint.drawLine(clr.topLeft(), clr.bottomRight()); |
253 | 260 paint.drawLine(clr.bottomLeft(), clr.topRight()); |
261 } else { | |
262 paint.drawEllipse(clr); | |
263 } | |
264 } | |
265 } | |
266 | |
267 |