comparison widgets/Thumbwheel.cpp @ 946:36cddc3de023 alignment_view

Merge from default branch
author Chris Cannam
date Mon, 20 Apr 2015 09:19:52 +0100
parents 4a578a360011
children bf509e47e324
comparison
equal deleted inserted replaced
897:499b637f2a26 946:36cddc3de023
133 emit valueChanged(getValue()); 133 emit valueChanged(getValue());
134 } 134 }
135 } 135 }
136 136
137 void 137 void
138 Thumbwheel::setMappedValue(float mappedValue) 138 Thumbwheel::setMappedValue(double mappedValue)
139 { 139 {
140 if (m_rangeMapper) { 140 if (m_rangeMapper) {
141 int newValue = m_rangeMapper->getPositionForValue(mappedValue); 141 int newValue = m_rangeMapper->getPositionForValue(mappedValue);
142 bool changed = (m_mappedValue != mappedValue); 142 bool changed = (m_mappedValue != mappedValue);
143 m_mappedValue = mappedValue; 143 m_mappedValue = mappedValue;
200 Thumbwheel::getValue() const 200 Thumbwheel::getValue() const
201 { 201 {
202 return m_value; 202 return m_value;
203 } 203 }
204 204
205 float 205 double
206 Thumbwheel::getMappedValue() const 206 Thumbwheel::getMappedValue() const
207 { 207 {
208 if (m_rangeMapper) { 208 if (m_rangeMapper) {
209 // SVDEBUG << "Thumbwheel::getMappedValue(): value = " << getValue() << ", mappedValue = " << m_mappedValue << endl; 209 // SVDEBUG << "Thumbwheel::getMappedValue(): value = " << getValue() << ", mappedValue = " << m_mappedValue << endl;
210 return m_mappedValue; 210 return m_mappedValue;
238 } 238 }
239 239
240 void 240 void
241 Thumbwheel::scroll(bool up) 241 Thumbwheel::scroll(bool up)
242 { 242 {
243 int step = lrintf(m_speed); 243 int step = int(lrintf(m_speed));
244 if (step == 0) step = 1; 244 if (step == 0) step = 1;
245 245
246 if (up) { 246 if (up) {
247 setValue(m_value + step); 247 setValue(m_value + step);
248 } else { 248 } else {
325 325
326 bool ok = false; 326 bool ok = false;
327 327
328 if (m_rangeMapper) { 328 if (m_rangeMapper) {
329 329
330 float min = m_rangeMapper->getValueForPosition(m_min); 330 double min = m_rangeMapper->getValueForPosition(m_min);
331 float max = m_rangeMapper->getValueForPosition(m_max); 331 double max = m_rangeMapper->getValueForPosition(m_max);
332 332
333 if (min > max) { 333 if (min > max) {
334 float tmp = min; 334 double tmp = min;
335 min = max; 335 min = max;
336 max = tmp; 336 max = tmp;
337 } 337 }
338 338
339 QString unit = m_rangeMapper->getUnit(); 339 QString unit = m_rangeMapper->getUnit();
355 text = tr("Enter a new value from %1 to %2:") 355 text = tr("Enter a new value from %1 to %2:")
356 .arg(min).arg(max); 356 .arg(min).arg(max);
357 } 357 }
358 } 358 }
359 359
360 float newValue = QInputDialog::getDouble 360 double newValue = QInputDialog::getDouble
361 (this, 361 (this,
362 tr("Enter new value"), 362 tr("Enter new value"),
363 text, 363 text,
364 m_mappedValue, 364 m_mappedValue,
365 min, 365 min,
396 dist = e->x() - m_clickPos.x(); 396 dist = e->x() - m_clickPos.x();
397 } else { 397 } else {
398 dist = e->y() - m_clickPos.y(); 398 dist = e->y() - m_clickPos.y();
399 } 399 }
400 400
401 float rotation = m_clickRotation + (m_speed * dist) / 100; 401 float rotation = m_clickRotation + (m_speed * float(dist)) / 100;
402 if (rotation < 0.f) rotation = 0.f; 402 if (rotation < 0.f) rotation = 0.f;
403 if (rotation > 1.f) rotation = 1.f; 403 if (rotation > 1.f) rotation = 1.f;
404 int value = lrintf(m_min + (m_max - m_min) * m_rotation); 404 int value = int(lrintf(float(m_min) + float(m_max - m_min) * m_rotation));
405 if (value != m_value) { 405 if (value != m_value) {
406 setValue(value); 406 setValue(value);
407 if (m_tracking) emit valueChanged(getValue()); 407 if (m_tracking) emit valueChanged(getValue());
408 m_rotation = rotation; 408 m_rotation = rotation;
409 } else if (fabsf(rotation - m_rotation) > 0.001) { 409 } else if (fabsf(rotation - m_rotation) > 0.001) {
424 } 424 }
425 425
426 void 426 void
427 Thumbwheel::wheelEvent(QWheelEvent *e) 427 Thumbwheel::wheelEvent(QWheelEvent *e)
428 { 428 {
429 int step = lrintf(m_speed); 429 int step = int(lrintf(m_speed));
430 if (step == 0) step = 1; 430 if (step == 0) step = 1;
431 431
432 if (e->delta() > 0) { 432 if (e->delta() > 0) {
433 setValue(m_value + step); 433 setValue(m_value + step);
434 } else { 434 } else {
467 paint.setClipRect(rect()); 467 paint.setClipRect(rect());
468 paint.fillRect(subclip, palette().background().color()); 468 paint.fillRect(subclip, palette().background().color());
469 469
470 paint.setRenderHint(QPainter::Antialiasing, true); 470 paint.setRenderHint(QPainter::Antialiasing, true);
471 471
472 float w = width(); 472 double w = width();
473 float w0 = 0.5; 473 double w0 = 0.5;
474 float w1 = w - 0.5; 474 double w1 = w - 0.5;
475 475
476 float h = height(); 476 double h = height();
477 float h0 = 0.5; 477 double h0 = 0.5;
478 float h1 = h - 0.5; 478 double h1 = h - 0.5;
479 479
480 for (int i = bw-1; i >= 0; --i) { 480 for (int i = bw-1; i >= 0; --i) {
481 481
482 int grey = (i + 1) * (256 / (bw + 1)); 482 int grey = (i + 1) * (256 / (bw + 1));
483 QColor fc = QColor(grey, grey, grey); 483 QColor fc = QColor(grey, grey, grey);
502 paint.drawPath(path); 502 paint.drawPath(path);
503 } 503 }
504 504
505 paint.setClipRect(subclip); 505 paint.setClipRect(subclip);
506 506
507 float radians = m_rotation * 1.5f * M_PI; 507 double radians = m_rotation * 1.5f * M_PI;
508 508
509 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl; 509 // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl;
510 510
511 w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2; 511 w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2;
512 512
516 // radius of the wheel including invisible part 516 // radius of the wheel including invisible part
517 int radius = int(w / 2 + 2); 517 int radius = int(w / 2 + 2);
518 518
519 for (int i = 0; i < notches; ++i) { 519 for (int i = 0; i < notches; ++i) {
520 520
521 float a0 = (2.f * M_PI * i) / notches + radians; 521 double a0 = (2.0 * M_PI * i) / notches + radians;
522 float a1 = a0 + M_PI / (notches * 2); 522 double a1 = a0 + M_PI / (notches * 2);
523 float a2 = (2.f * M_PI * (i + 1)) / notches + radians; 523 double a2 = (2.0 * M_PI * (i + 1)) / notches + radians;
524 524
525 float depth = cosf((a0 + a2) / 2); 525 double depth = cos((a0 + a2) / 2);
526 if (depth < 0) continue; 526 if (depth < 0) continue;
527 527
528 float x0 = radius * sinf(a0) + w/2; 528 double x0 = radius * sin(a0) + w/2;
529 float x1 = radius * sinf(a1) + w/2; 529 double x1 = radius * sin(a1) + w/2;
530 float x2 = radius * sinf(a2) + w/2; 530 double x2 = radius * sin(a2) + w/2;
531 if (x2 < 0 || x0 > w) continue; 531 if (x2 < 0 || x0 > w) continue;
532 532
533 if (x0 < 0) x0 = 0; 533 if (x0 < 0) x0 = 0;
534 if (x2 > w) x2 = w; 534 if (x2 > w) x2 = w;
535 535
536 x0 += bw; 536 x0 += bw;
537 x1 += bw; 537 x1 += bw;
538 x2 += bw; 538 x2 += bw;
539 539
540 int grey = lrintf(120 * depth); 540 int grey = int(lrint(120 * depth));
541 541
542 QColor fc = QColor(grey, grey, grey); 542 QColor fc = QColor(grey, grey, grey);
543 QColor oc = palette().highlight().color(); 543 QColor oc = palette().highlight().color();
544 544
545 paint.setPen(fc); 545 paint.setPen(fc);
546 546
547 if (m_showScale) { 547 if (m_showScale) {
548 548
549 paint.setBrush(oc); 549 paint.setBrush(oc);
550 550
551 float prop; 551 double prop;
552 if (i >= notches / 4) { 552 if (i >= notches / 4) {
553 prop = float(notches - (((i - float(notches) / 4.f) * 4.f) / 3.f)) 553 prop = double(notches - (((i - double(notches) / 4.f) * 4.f) / 3.f))
554 / notches; 554 / notches;
555 } else { 555 } else {
556 prop = 0.f; 556 prop = 0.f;
557 } 557 }
558 558