comparison widgets/Thumbwheel.cpp @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents 54e6be7ebe11
children a34a2a25907c
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
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 int w = m_cache.width();
459 int h = m_cache.height();
460 int bw = 3; // border width
458 461
459 QRect subclip; 462 QRect subclip;
460 if (m_orientation == Qt::Horizontal) { 463 if (m_orientation == Qt::Horizontal) {
461 subclip = QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2); 464 subclip = QRect(bw, bw+1, w - bw*2, h - bw*2 - 2);
462 } else { 465 } else {
463 subclip = QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2); 466 subclip = QRect(bw+1, bw, w - bw*2 - 2, h - bw*2);
464 } 467 }
465 468
466 QPainter paint(&m_cache); 469 QPainter paint(&m_cache);
467 paint.setClipRect(rect()); 470 paint.setClipRect(m_cache.rect());
468 paint.fillRect(subclip, palette().background().color()); 471 paint.fillRect(subclip, palette().background().color());
469 472
470 paint.setRenderHint(QPainter::Antialiasing, true); 473 paint.setRenderHint(QPainter::Antialiasing, true);
471 474
472 double w = width();
473 double w0 = 0.5; 475 double w0 = 0.5;
474 double w1 = w - 0.5; 476 double w1 = w - 0.5;
475 477
476 double h = height();
477 double h0 = 0.5; 478 double h0 = 0.5;
478 double h1 = h - 0.5; 479 double h1 = h - 0.5;
479 480
480 for (int i = bw-1; i >= 0; --i) { 481 for (int i = bw-1; i >= 0; --i) {
481 482
506 507
507 double radians = m_rotation * 1.5f * M_PI; 508 double radians = m_rotation * 1.5f * M_PI;
508 509
509 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl; 510 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl;
510 511
511 w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2; 512 int ww = (m_orientation == Qt::Horizontal ? w : h) - bw*2; // wheel width
512 513
513 // total number of notches on the entire wheel 514 // total number of notches on the entire wheel
514 int notches = 25; 515 int notches = 25;
515 516
516 // radius of the wheel including invisible part 517 // radius of the wheel including invisible part
517 int radius = int(w / 2 + 2); 518 int radius = int(ww / 2 + 2);
518 519
519 for (int i = 0; i < notches; ++i) { 520 for (int i = 0; i < notches; ++i) {
520 521
521 double a0 = (2.0 * M_PI * i) / notches + radians; 522 double a0 = (2.0 * M_PI * i) / notches + radians;
522 double a1 = a0 + M_PI / (notches * 2); 523 double a1 = a0 + M_PI / (notches * 2);
523 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians; 524 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians;
524 525
525 double depth = cos((a0 + a2) / 2); 526 double depth = cos((a0 + a2) / 2);
526 if (depth < 0) continue; 527 if (depth < 0) continue;
527 528
528 double x0 = radius * sin(a0) + w/2; 529 double x0 = radius * sin(a0) + ww/2;
529 double x1 = radius * sin(a1) + w/2; 530 double x1 = radius * sin(a1) + ww/2;
530 double x2 = radius * sin(a2) + w/2; 531 double x2 = radius * sin(a2) + ww/2;
531 if (x2 < 0 || x0 > w) continue; 532 if (x2 < 0 || x0 > ww) continue;
532 533
533 if (x0 < 0) x0 = 0; 534 if (x0 < 0) x0 = 0;
534 if (x2 > w) x2 = w; 535 if (x2 > ww) x2 = ww;
535 536
536 x0 += bw; 537 x0 += bw;
537 x1 += bw; 538 x1 += bw;
538 x2 += bw; 539 x2 += bw;
539 540
555 } else { 556 } else {
556 prop = 0.f; 557 prop = 0.f;
557 } 558 }
558 559
559 if (m_orientation == Qt::Horizontal) { 560 if (m_orientation == Qt::Horizontal) {
560 paint.drawRect(QRectF(x1, height() - (height() - bw*2) * prop - bw, 561 paint.drawRect(QRectF(x1, h - (h - bw*2) * prop - bw,
561 x2 - x1, height() * prop)); 562 x2 - x1, h * prop));
562 } else { 563 } else {
563 paint.drawRect(QRectF(bw, x1, (width() - bw*2) * prop, x2 - x1)); 564 paint.drawRect(QRectF(bw, x1, (w - bw*2) * prop, x2 - x1));
564 } 565 }
565 } 566 }
566 567
567 paint.setPen(fc); 568 paint.setPen(fc);
568 paint.setBrush(palette().background().color()); 569 paint.setBrush(palette().background().color());
569 570
570 if (m_orientation == Qt::Horizontal) { 571 if (m_orientation == Qt::Horizontal) {
571 paint.drawRect(QRectF(x0, bw, x1 - x0, height() - bw*2)); 572 paint.drawRect(QRectF(x0, bw, x1 - x0, h - bw*2));
572 } else { 573 } else {
573 paint.drawRect(QRectF(bw, x0, width() - bw*2, x1 - x0)); 574 paint.drawRect(QRectF(bw, x0, w - bw*2, x1 - x0));
574 } 575 }
575 } 576 }
576 577
577 QPainter paint2(this); 578 QPainter paint2(this);
578 paint2.drawImage(0, 0, m_cache); 579 paint2.drawImage(rect(), m_cache, m_cache.rect());
579 } 580 }
580 581
581 QSize 582 QSize
582 Thumbwheel::sizeHint() const 583 Thumbwheel::sizeHint() const
583 { 584 {