Mercurial > hg > svgui
comparison widgets/Thumbwheel.cpp @ 1192:bf509e47e324 levelpanwidget
Retina thumbwheels
author | Chris Cannam |
---|---|
date | Thu, 15 Dec 2016 15:12:44 +0000 |
parents | 4a578a360011 |
children | 54e6be7ebe11 |
comparison
equal
deleted
inserted
replaced
1191:91aac85406fb | 1192:bf509e47e324 |
---|---|
443 { | 443 { |
444 Profiler profiler("Thumbwheel::paintEvent"); | 444 Profiler profiler("Thumbwheel::paintEvent"); |
445 | 445 |
446 if (!m_cache.isNull()) { | 446 if (!m_cache.isNull()) { |
447 QPainter paint(this); | 447 QPainter paint(this); |
448 paint.drawImage(0, 0, m_cache); | 448 paint.drawImage(rect(), m_cache, m_cache.rect()); |
449 return; | 449 return; |
450 } | 450 } |
451 | 451 |
452 Profiler profiler2("Thumbwheel::paintEvent (no cache)"); | 452 Profiler profiler2("Thumbwheel::paintEvent (no cache)"); |
453 | 453 |
454 m_cache = QImage(size(), QImage::Format_ARGB32); | 454 QSize imageSize = size() * devicePixelRatio(); |
455 m_cache = QImage(imageSize, QImage::Format_ARGB32); | |
455 m_cache.fill(Qt::transparent); | 456 m_cache.fill(Qt::transparent); |
456 | 457 |
457 int bw = 3; | 458 double w = m_cache.width(); |
459 double h = m_cache.height(); | |
460 | |
461 int bw = 3; // border width | |
458 | 462 |
459 QRect subclip; | 463 QRect subclip; |
460 if (m_orientation == Qt::Horizontal) { | 464 if (m_orientation == Qt::Horizontal) { |
461 subclip = QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2); | 465 subclip = QRect(bw, bw+1, w - bw*2, h - bw*2 - 2); |
462 } else { | 466 } else { |
463 subclip = QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2); | 467 subclip = QRect(bw+1, bw, w - bw*2 - 2, h - bw*2); |
464 } | 468 } |
465 | 469 |
466 QPainter paint(&m_cache); | 470 QPainter paint(&m_cache); |
467 paint.setClipRect(rect()); | 471 paint.setClipRect(m_cache.rect()); |
468 paint.fillRect(subclip, palette().background().color()); | 472 paint.fillRect(subclip, palette().background().color()); |
469 | 473 |
470 paint.setRenderHint(QPainter::Antialiasing, true); | 474 paint.setRenderHint(QPainter::Antialiasing, true); |
471 | 475 |
472 double w = width(); | |
473 double w0 = 0.5; | 476 double w0 = 0.5; |
474 double w1 = w - 0.5; | 477 double w1 = w - 0.5; |
475 | 478 |
476 double h = height(); | |
477 double h0 = 0.5; | 479 double h0 = 0.5; |
478 double h1 = h - 0.5; | 480 double h1 = h - 0.5; |
479 | 481 |
480 for (int i = bw-1; i >= 0; --i) { | 482 for (int i = bw-1; i >= 0; --i) { |
481 | 483 |
506 | 508 |
507 double radians = m_rotation * 1.5f * M_PI; | 509 double radians = m_rotation * 1.5f * M_PI; |
508 | 510 |
509 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl; | 511 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl; |
510 | 512 |
511 w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2; | 513 int ww = (m_orientation == Qt::Horizontal ? w : h) - bw*2; // wheel width |
512 | 514 |
513 // total number of notches on the entire wheel | 515 // total number of notches on the entire wheel |
514 int notches = 25; | 516 int notches = 25; |
515 | 517 |
516 // radius of the wheel including invisible part | 518 // radius of the wheel including invisible part |
517 int radius = int(w / 2 + 2); | 519 int radius = int(ww / 2 + 2); |
518 | 520 |
519 for (int i = 0; i < notches; ++i) { | 521 for (int i = 0; i < notches; ++i) { |
520 | 522 |
521 double a0 = (2.0 * M_PI * i) / notches + radians; | 523 double a0 = (2.0 * M_PI * i) / notches + radians; |
522 double a1 = a0 + M_PI / (notches * 2); | 524 double a1 = a0 + M_PI / (notches * 2); |
523 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians; | 525 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians; |
524 | 526 |
525 double depth = cos((a0 + a2) / 2); | 527 double depth = cos((a0 + a2) / 2); |
526 if (depth < 0) continue; | 528 if (depth < 0) continue; |
527 | 529 |
528 double x0 = radius * sin(a0) + w/2; | 530 double x0 = radius * sin(a0) + ww/2; |
529 double x1 = radius * sin(a1) + w/2; | 531 double x1 = radius * sin(a1) + ww/2; |
530 double x2 = radius * sin(a2) + w/2; | 532 double x2 = radius * sin(a2) + ww/2; |
531 if (x2 < 0 || x0 > w) continue; | 533 if (x2 < 0 || x0 > ww) continue; |
532 | 534 |
533 if (x0 < 0) x0 = 0; | 535 if (x0 < 0) x0 = 0; |
534 if (x2 > w) x2 = w; | 536 if (x2 > ww) x2 = ww; |
535 | 537 |
536 x0 += bw; | 538 x0 += bw; |
537 x1 += bw; | 539 x1 += bw; |
538 x2 += bw; | 540 x2 += bw; |
539 | 541 |
555 } else { | 557 } else { |
556 prop = 0.f; | 558 prop = 0.f; |
557 } | 559 } |
558 | 560 |
559 if (m_orientation == Qt::Horizontal) { | 561 if (m_orientation == Qt::Horizontal) { |
560 paint.drawRect(QRectF(x1, height() - (height() - bw*2) * prop - bw, | 562 paint.drawRect(QRectF(x1, h - (h - bw*2) * prop - bw, |
561 x2 - x1, height() * prop)); | 563 x2 - x1, h * prop)); |
562 } else { | 564 } else { |
563 paint.drawRect(QRectF(bw, x1, (width() - bw*2) * prop, x2 - x1)); | 565 paint.drawRect(QRectF(bw, x1, (w - bw*2) * prop, x2 - x1)); |
564 } | 566 } |
565 } | 567 } |
566 | 568 |
567 paint.setPen(fc); | 569 paint.setPen(fc); |
568 paint.setBrush(palette().background().color()); | 570 paint.setBrush(palette().background().color()); |
569 | 571 |
570 if (m_orientation == Qt::Horizontal) { | 572 if (m_orientation == Qt::Horizontal) { |
571 paint.drawRect(QRectF(x0, bw, x1 - x0, height() - bw*2)); | 573 paint.drawRect(QRectF(x0, bw, x1 - x0, h - bw*2)); |
572 } else { | 574 } else { |
573 paint.drawRect(QRectF(bw, x0, width() - bw*2, x1 - x0)); | 575 paint.drawRect(QRectF(bw, x0, w - bw*2, x1 - x0)); |
574 } | 576 } |
575 } | 577 } |
576 | 578 |
577 QPainter paint2(this); | 579 QPainter paint2(this); |
578 paint2.drawImage(0, 0, m_cache); | 580 paint2.drawImage(rect(), m_cache, m_cache.rect()); |
579 } | 581 } |
580 | 582 |
581 QSize | 583 QSize |
582 Thumbwheel::sizeHint() const | 584 Thumbwheel::sizeHint() const |
583 { | 585 { |