comparison widgets/LevelPanWidget.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents c49a48fcc364
children e8368466fa34
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
122 void 122 void
123 LevelPanWidget::setLevel(float flevel) 123 LevelPanWidget::setLevel(float flevel)
124 { 124 {
125 int level = audioLevelToLevel(flevel, m_includeMute); 125 int level = audioLevelToLevel(flevel, m_includeMute);
126 if (level != m_level) { 126 if (level != m_level) {
127 m_level = level; 127 m_level = level;
128 float convertsTo = getLevel(); 128 float convertsTo = getLevel();
129 if (fabsf(convertsTo - flevel) > 1e-5) { 129 if (fabsf(convertsTo - flevel) > 1e-5) {
130 emitLevelChanged(); 130 emitLevelChanged();
131 } 131 }
132 update(); 132 update();
133 } 133 }
134 } 134 }
135 135
136 float 136 float
137 LevelPanWidget::getLevel() const 137 LevelPanWidget::getLevel() const
245 if (!m_editing) return; 245 if (!m_editing) return;
246 246
247 int level, pan; 247 int level, pan;
248 toCell(rect(), e->pos(), level, pan); 248 toCell(rect(), e->pos(), level, pan);
249 if (level == m_level && pan == m_pan) { 249 if (level == m_level && pan == m_pan) {
250 return; 250 return;
251 } 251 }
252 if (level != m_level) { 252 if (level != m_level) {
253 m_level = level; 253 m_level = level;
254 emitLevelChanged(); 254 emitLevelChanged();
255 } 255 }
256 if (pan != m_pan) { 256 if (pan != m_pan) {
257 m_pan = pan; 257 m_pan = pan;
258 emitPanChanged(); 258 emitPanChanged();
259 } 259 }
260 update(); 260 update();
261 } 261 }
262 262
263 void 263 void
264 LevelPanWidget::wheelEvent(QWheelEvent *e) 264 LevelPanWidget::wheelEvent(QWheelEvent *e)
265 { 265 {
266 if (e->modifiers() & Qt::ControlModifier) { 266 if (e->modifiers() & Qt::ControlModifier) {
267 if (e->delta() > 0) { 267 if (e->delta() > 0) {
268 if (m_pan < maxPan) { 268 if (m_pan < maxPan) {
269 ++m_pan; 269 ++m_pan;
270 emitPanChanged(); 270 emitPanChanged();
271 update(); 271 update();
272 } 272 }
273 } else { 273 } else {
274 if (m_pan > -maxPan) { 274 if (m_pan > -maxPan) {
275 --m_pan; 275 --m_pan;
276 emitPanChanged(); 276 emitPanChanged();
277 update(); 277 update();
278 } 278 }
279 } 279 }
280 } else { 280 } else {
281 if (e->delta() > 0) { 281 if (e->delta() > 0) {
282 if (m_level < maxLevel) { 282 if (m_level < maxLevel) {
283 ++m_level; 283 ++m_level;
284 emitLevelChanged(); 284 emitLevelChanged();
285 update(); 285 update();
286 } 286 }
287 } else { 287 } else {
288 if (m_level > 0) { 288 if (m_level > 0) {
289 --m_level; 289 --m_level;
290 emitLevelChanged(); 290 emitLevelChanged();
291 update(); 291 update();
292 } 292 }
293 } 293 }
294 } 294 }
295 } 295 }
296 296
297 void 297 void
298 LevelPanWidget::toCell(QRectF rect, QPointF loc, int &level, int &pan) const 298 LevelPanWidget::toCell(QRectF rect, QPointF loc, int &level, int &pan) const
326 QPointF 326 QPointF
327 LevelPanWidget::cellCentre(QRectF rect, int level, int pan) const 327 LevelPanWidget::cellCentre(QRectF rect, int level, int pan) const
328 { 328 {
329 QSizeF cs = cellSize(rect); 329 QSizeF cs = cellSize(rect);
330 return QPointF(rect.x() + cs.width() * (pan + maxPan) + cs.width() / 2., 330 return QPointF(rect.x() + cs.width() * (pan + maxPan) + cs.width() / 2.,
331 rect.y() + rect.height() - cs.height() * (level + 1) + cs.height() / 2.); 331 rect.y() + rect.height() - cs.height() * (level + 1) + cs.height() / 2.);
332 } 332 }
333 333
334 QSizeF 334 QSizeF
335 LevelPanWidget::cellLightSize(QRectF rect) const 335 LevelPanWidget::cellLightSize(QRectF rect) const
336 { 336 {
344 LevelPanWidget::cellLightRect(QRectF rect, int level, int pan) const 344 LevelPanWidget::cellLightRect(QRectF rect, int level, int pan) const
345 { 345 {
346 QSizeF cls = cellLightSize(rect); 346 QSizeF cls = cellLightSize(rect);
347 QPointF cc = cellCentre(rect, level, pan); 347 QPointF cc = cellCentre(rect, level, pan);
348 return QRectF(cc.x() - cls.width() / 2., 348 return QRectF(cc.x() - cls.width() / 2.,
349 cc.y() - cls.height() / 2., 349 cc.y() - cls.height() / 2.,
350 cls.width(), 350 cls.width(),
351 cls.height()); 351 cls.height());
352 } 352 }
353 353
354 double 354 double
355 LevelPanWidget::thinLineWidth(QRectF rect) const 355 LevelPanWidget::thinLineWidth(QRectF rect) const
356 { 356 {
386 pen.setCapStyle(Qt::RoundCap); 386 pen.setCapStyle(Qt::RoundCap);
387 paint.setPen(pen); 387 paint.setPen(pen);
388 paint.setBrush(Qt::NoBrush); 388 paint.setBrush(Qt::NoBrush);
389 389
390 for (int pan = -maxPan; pan <= maxPan; ++pan) { 390 for (int pan = -maxPan; pan <= maxPan; ++pan) {
391 paint.drawLine(cellCentre(rect, 0, pan), cellCentre(rect, maxLevel, pan)); 391 paint.drawLine(cellCentre(rect, 0, pan), cellCentre(rect, maxLevel, pan));
392 } 392 }
393 393
394 if (m_monitorLeft > 0.f || m_monitorRight > 0.f) { 394 if (m_monitorLeft > 0.f || m_monitorRight > 0.f) {
395 paint.setPen(Qt::NoPen); 395 paint.setPen(Qt::NoPen);
396 for (int pan = -maxPan; pan <= maxPan; ++pan) { 396 for (int pan = -maxPan; pan <= maxPan; ++pan) {
411 paint.setPen(pen); 411 paint.setPen(pen);
412 paint.setBrush(Qt::NoBrush); 412 paint.setBrush(Qt::NoBrush);
413 } 413 }
414 414
415 if (isEnabled()) { 415 if (isEnabled()) {
416 pen.setColor(Qt::black); 416 pen.setColor(Qt::black);
417 } else { 417 } else {
418 pen.setColor(Qt::darkGray); 418 pen.setColor(Qt::darkGray);
419 } 419 }
420 420
421 if (!asIfEditable && m_includeMute && m_level == 0) { 421 if (!asIfEditable && m_includeMute && m_level == 0) {
422 pen.setWidthF(thin * 2); 422 pen.setWidthF(thin * 2);
423 pen.setCapStyle(Qt::RoundCap); 423 pen.setCapStyle(Qt::RoundCap);
432 pen.setWidthF(thin); 432 pen.setWidthF(thin);
433 pen.setCapStyle(Qt::FlatCap); 433 pen.setCapStyle(Qt::FlatCap);
434 paint.setPen(pen); 434 paint.setPen(pen);
435 435
436 for (int level = 0; level <= m_level; ++level) { 436 for (int level = 0; level <= m_level; ++level) {
437 if (isEnabled()) { 437 if (isEnabled()) {
438 paint.setBrush(level_to_colour(level)); 438 paint.setBrush(level_to_colour(level));
439 } 439 }
440 QRectF clr = cellLightRect(rect, level, m_pan); 440 QRectF clr = cellLightRect(rect, level, m_pan);
441 if (m_includeMute && m_level == 0) { 441 if (m_includeMute && m_level == 0) {
442 paint.drawLine(clr.topLeft(), clr.bottomRight()); 442 paint.drawLine(clr.topLeft(), clr.bottomRight());
443 paint.drawLine(clr.bottomLeft(), clr.topRight()); 443 paint.drawLine(clr.bottomLeft(), clr.topRight());
444 } else { 444 } else {
445 paint.drawEllipse(clr); 445 paint.drawEllipse(clr);
446 } 446 }
447 } 447 }
448 } 448 }
449 449
450 void 450 void
451 LevelPanWidget::paintEvent(QPaintEvent *) 451 LevelPanWidget::paintEvent(QPaintEvent *)