Mercurial > hg > svgui
comparison widgets/LevelPanWidget.cpp @ 1304:a575dae05fbf
Experiment with rounded rects
author | Chris Cannam |
---|---|
date | Fri, 22 Jun 2018 17:51:47 +0100 |
parents | 13f5f84fbfad |
children | 21342513c252 |
comparison
equal
deleted
inserted
replaced
1303:13f5f84fbfad | 1304:a575dae05fbf |
---|---|
374 double tw = ceil(rect.width() / (maxPan * 2. * 10.)); | 374 double tw = ceil(rect.width() / (maxPan * 2. * 10.)); |
375 double th = ceil(rect.height() / (m_maxNotch/2 * 10.)); | 375 double th = ceil(rect.height() / (m_maxNotch/2 * 10.)); |
376 return std::min(th, tw); | 376 return std::min(th, tw); |
377 } | 377 } |
378 | 378 |
379 double | |
380 LevelPanWidget::cornerRadius(QRectF rect) const | |
381 { | |
382 QSizeF cs = cellSize(rect); | |
383 double m = std::min(cs.width(), cs.height()); | |
384 return m / 5; | |
385 } | |
386 | |
379 QRectF | 387 QRectF |
380 LevelPanWidget::cellOutlineRect(QRectF rect, int row, int col) const | 388 LevelPanWidget::cellOutlineRect(QRectF rect, int row, int col) const |
381 { | 389 { |
382 QRectF clr = cellLightRect(rect, row, col); | 390 QRectF clr = cellLightRect(rect, row, col); |
383 double adj = thinLineWidth(rect)/2; | 391 double adj = thinLineWidth(rect)/2; |
402 paint.setRenderHint(QPainter::Antialiasing, true); | 410 paint.setRenderHint(QPainter::Antialiasing, true); |
403 | 411 |
404 QPen pen; | 412 QPen pen; |
405 | 413 |
406 double thin = thinLineWidth(rect); | 414 double thin = thinLineWidth(rect); |
415 double radius = cornerRadius(rect); | |
407 | 416 |
408 QColor columnBackground = QColor(180, 180, 180); | 417 QColor columnBackground = QColor(180, 180, 180); |
409 pen.setColor(columnBackground); | 418 paint.setPen(Qt::NoPen); |
410 pen.setWidthF(cellLightSize(rect).width() + thin); | 419 paint.setBrush(columnBackground); |
411 pen.setCapStyle(Qt::RoundCap); | |
412 paint.setPen(pen); | |
413 paint.setBrush(Qt::NoBrush); | |
414 | 420 |
415 for (int pan = -maxPan; pan <= maxPan; ++pan) { | 421 for (int pan = -maxPan; pan <= maxPan; ++pan) { |
416 paint.drawLine(cellCentre(rect, 0, pan), | 422 QRectF top = cellOutlineRect(rect, m_maxNotch/2 - 1, pan); |
417 cellCentre(rect, m_maxNotch/2 - 1, pan)); | 423 QRectF bottom = cellOutlineRect(rect, 0, pan); |
424 paint.drawRoundedRect(QRectF(top.x(), | |
425 top.y(), | |
426 top.width(), | |
427 bottom.y() + bottom.height() - top.y()), | |
428 radius, radius); | |
418 } | 429 } |
419 | 430 |
420 bool monitoring = (m_monitorLeft > 0.f || m_monitorRight > 0.f); | 431 bool monitoring = (m_monitorLeft > 0.f || m_monitorRight > 0.f); |
421 | 432 |
422 if (isEnabled()) { | 433 if (isEnabled()) { |
450 paint.drawLine(clr.bottomLeft(), clr.topRight()); | 461 paint.drawLine(clr.bottomLeft(), clr.topRight()); |
451 } else { | 462 } else { |
452 for (int notch = 1; notch <= m_notch; notch += 2) { | 463 for (int notch = 1; notch <= m_notch; notch += 2) { |
453 if (isEnabled() && !monitoring) { | 464 if (isEnabled() && !monitoring) { |
454 paint.setBrush(notchToColour(notch)); | 465 paint.setBrush(notchToColour(notch)); |
466 } else { | |
467 paint.setBrush(Qt::NoBrush); | |
455 } | 468 } |
456 QRectF clr = cellLightRect(rect, notch/2, m_pan); | 469 QRectF clr = cellLightRect(rect, notch/2, m_pan); |
457 paint.drawEllipse(clr); | 470 paint.drawRoundedRect(clr, radius, radius); |
458 } | 471 } |
459 if (m_notch % 2 != 0) { | 472 if (m_notch % 2 != 0) { |
460 QRectF clr = cellOutlineRect(rect, (m_notch-1)/2, m_pan); | 473 QRectF clr = cellOutlineRect(rect, (m_notch-1)/2, m_pan); |
461 paint.save(); | 474 paint.save(); |
462 paint.setPen(Qt::NoPen); | 475 paint.setPen(Qt::NoPen); |
463 paint.setBrush(columnBackground); | 476 paint.setBrush(columnBackground); |
464 paint.drawPie(clr, 0, 180 * 16); | 477 paint.drawRoundedRect(QRectF(clr.x(), |
478 clr.y(), | |
479 clr.width(), | |
480 clr.height()/4 + thin), | |
481 radius, radius); | |
482 paint.drawRect(QRectF(clr.x(), | |
483 clr.y() + clr.height()/4 - thin, | |
484 clr.width(), | |
485 clr.height()/4 + thin)); | |
465 paint.restore(); | 486 paint.restore(); |
466 } | 487 } |
467 } | 488 } |
468 } | 489 } |
469 | 490 |
488 } else { | 509 } else { |
489 paint.drawEllipse(clr); | 510 paint.drawEllipse(clr); |
490 } | 511 } |
491 } | 512 } |
492 } | 513 } |
493 paint.setPen(pen); | |
494 paint.setBrush(Qt::NoBrush); | |
495 } | 514 } |
496 } | 515 } |
497 | 516 |
498 void | 517 void |
499 LevelPanWidget::paintEvent(QPaintEvent *) | 518 LevelPanWidget::paintEvent(QPaintEvent *) |