Mercurial > hg > svgui
comparison widgets/Thumbwheel.cpp @ 190:53835534a9d3
* Allow user to activate a pane by clicking on the tab for its currently active
layer. Formerly nothing happened if you clicked on the tab that was already
topmost in a given property stack, because the tab widget only emitted a signal
if the current tab changed. We want this to switch focus back to the pane if
another one has been active in the mean time.
* Make the thumbwheels look a bit round.
author | Chris Cannam |
---|---|
date | Mon, 22 Jan 2007 15:42:00 +0000 |
parents | 5b7472db612b |
children | 3ed71a9d578b |
comparison
equal
deleted
inserted
replaced
189:5b7472db612b | 190:53835534a9d3 |
---|---|
14 */ | 14 */ |
15 | 15 |
16 #include "Thumbwheel.h" | 16 #include "Thumbwheel.h" |
17 | 17 |
18 #include "base/RangeMapper.h" | 18 #include "base/RangeMapper.h" |
19 #include "base/Profiler.h" | |
19 | 20 |
20 #include <QMouseEvent> | 21 #include <QMouseEvent> |
21 #include <QPaintEvent> | 22 #include <QPaintEvent> |
22 #include <QWheelEvent> | 23 #include <QWheelEvent> |
23 #include <QInputDialog> | 24 #include <QInputDialog> |
24 #include <QPainter> | 25 #include <QPainter> |
26 #include <QPainterPath> | |
25 | 27 |
26 #include <cmath> | 28 #include <cmath> |
27 #include <iostream> | 29 #include <iostream> |
28 | 30 |
29 Thumbwheel::Thumbwheel(Qt::Orientation orientation, | 31 Thumbwheel::Thumbwheel(Qt::Orientation orientation, |
134 void | 136 void |
135 Thumbwheel::setMappedValue(float mappedValue) | 137 Thumbwheel::setMappedValue(float mappedValue) |
136 { | 138 { |
137 if (m_rangeMapper) { | 139 if (m_rangeMapper) { |
138 int newValue = m_rangeMapper->getPositionForValue(mappedValue); | 140 int newValue = m_rangeMapper->getPositionForValue(mappedValue); |
141 bool changed = (m_mappedValue != mappedValue); | |
139 m_mappedValue = mappedValue; | 142 m_mappedValue = mappedValue; |
140 m_noMappedUpdate = true; | 143 m_noMappedUpdate = true; |
141 std::cerr << "Thumbwheel::setMappedValue(" << mappedValue << "): new value is " << newValue << std::endl; | 144 std::cerr << "Thumbwheel::setMappedValue(" << mappedValue << "): new value is " << newValue << std::endl; |
142 if (newValue != getValue()) { | 145 if (newValue != getValue()) { |
143 setValue(newValue); | 146 setValue(newValue); |
144 } | 147 changed = true; |
145 emit valueChanged(newValue); | 148 } |
149 if (changed) emit valueChanged(newValue); | |
146 m_noMappedUpdate = false; | 150 m_noMappedUpdate = false; |
147 } else { | 151 } else { |
148 setValue(int(mappedValue)); | 152 int v = int(mappedValue); |
149 emit valueChanged(int(mappedValue)); | 153 if (v != getValue()) { |
154 setValue(v); | |
155 emit valueChanged(v); | |
156 } | |
150 } | 157 } |
151 } | 158 } |
152 | 159 |
153 int | 160 int |
154 Thumbwheel::getDefaultValue() const | 161 Thumbwheel::getDefaultValue() const |
412 } | 419 } |
413 | 420 |
414 void | 421 void |
415 Thumbwheel::paintEvent(QPaintEvent *) | 422 Thumbwheel::paintEvent(QPaintEvent *) |
416 { | 423 { |
424 Profiler profiler("Thumbwheel::paintEvent", true); | |
425 | |
417 QPainter paint(this); | 426 QPainter paint(this); |
418 paint.fillRect(rect(), palette().background().color()); | 427 paint.fillRect(rect(), palette().background().color()); |
419 paint.setRenderHint(QPainter::Antialiasing, false); | 428 |
429 paint.setRenderHint(QPainter::Antialiasing, true); | |
420 | 430 |
421 int bw = 3; | 431 int bw = 3; |
422 | 432 |
423 for (int i = 0; i < bw; ++i) { | 433 float w = width(); |
434 float w0 = 0.5; | |
435 float w1 = w - 0.5; | |
436 | |
437 float h = height(); | |
438 float h0 = 0.5; | |
439 float h1 = h - 0.5; | |
440 | |
441 for (int i = bw-1; i >= 0; --i) { | |
442 // for (int i = 0; i < 1; ++i) { | |
443 | |
424 int grey = (i + 1) * (256 / (bw + 1)); | 444 int grey = (i + 1) * (256 / (bw + 1)); |
425 QColor fc = QColor(grey, grey, grey); | 445 QColor fc = QColor(grey, grey, grey); |
426 paint.setPen(fc); | 446 paint.setPen(fc); |
427 paint.drawRect(i, i, width() - i*2 - 1, height() - i*2 - 1); | 447 |
428 } | 448 QPainterPath path; |
429 | 449 |
430 paint.setClipRect(QRect(bw, bw, width() - bw*2, height() - bw*2)); | 450 if (m_orientation == Qt::Horizontal) { |
451 path.moveTo(w0 + i, h0 + i + 2); | |
452 path.quadTo(w/2, i * 1.25, w1 - i, h0 + i + 2); | |
453 path.lineTo(w1 - i, h1 - i - 2); | |
454 path.quadTo(w/2, h - i * 1.25, w0 + i, h1 - i - 2); | |
455 path.closeSubpath(); | |
456 } else { | |
457 path.moveTo(w0 + i + 2, h0 + i); | |
458 path.quadTo(i * 1.25, h/2, w0 + i + 2, h1 - i); | |
459 path.lineTo(w1 - i - 2, h1 - i); | |
460 path.quadTo(w - i * 1.25, h/2, w1 - i - 2, h0 + i); | |
461 path.closeSubpath(); | |
462 } | |
463 | |
464 paint.drawPath(path); | |
465 } | |
466 | |
467 | |
468 if (m_orientation == Qt::Horizontal) { | |
469 paint.setClipRect(QRect(bw, bw+1, width() - bw*2, height() - bw*2 - 2)); | |
470 } else { | |
471 paint.setClipRect(QRect(bw+1, bw, width() - bw*2 - 2, height() - bw*2)); | |
472 } | |
431 | 473 |
432 float radians = m_rotation * 1.5f * M_PI; | 474 float radians = m_rotation * 1.5f * M_PI; |
433 | 475 |
434 // std::cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << std::endl; | 476 // std::cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << std::endl; |
435 | 477 |
436 int w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2; | 478 w = (m_orientation == Qt::Horizontal ? width() : height()) - bw*2; |
437 | 479 |
438 // total number of notches on the entire wheel | 480 // total number of notches on the entire wheel |
439 int notches = 25; | 481 int notches = 25; |
440 | 482 |
441 // radius of the wheel including invisible part | 483 // radius of the wheel including invisible part |
442 int radius = w / 2 + 2; | 484 int radius = w / 2 + 2; |
443 | |
444 paint.setRenderHint(QPainter::Antialiasing, true); | |
445 | 485 |
446 for (int i = 0; i < notches; ++i) { | 486 for (int i = 0; i < notches; ++i) { |
447 | 487 |
448 float a0 = (2.f * M_PI * i) / notches + radians; | 488 float a0 = (2.f * M_PI * i) / notches + radians; |
449 float a1 = a0 + M_PI / (notches * 2); | 489 float a1 = a0 + M_PI / (notches * 2); |