# HG changeset patch # User Chris Cannam # Date 1160668058 0 # Node ID 793df5f0c6cba6ba778c3a9224d7ecfff065619e # Parent 11949d0b2739ae6f3655dc4a73a2a462f7f5bdce * Make the thumbwheel widget much smoother to use, and fix a bug in positioning diff -r 11949d0b2739 -r 793df5f0c6cb view/Pane.cpp --- a/view/Pane.cpp Thu Oct 12 14:56:28 2006 +0000 +++ b/view/Pane.cpp Thu Oct 12 15:47:38 2006 +0000 @@ -88,6 +88,7 @@ m_hthumb->setFixedWidth(70); m_hthumb->setFixedHeight(16); m_hthumb->setDefaultValue(0); + m_hthumb->setSpeed(0.6); connect(m_hthumb, SIGNAL(valueChanged(int)), this, SLOT(horizontalThumbwheelMoved(int))); @@ -188,16 +189,16 @@ if (m_manager && m_manager->getZoomWheelsEnabled() && width() > 120 && height() > 100) { + if (!m_headsUpDisplay->isVisible()) { + m_headsUpDisplay->show(); + connect(m_manager, SIGNAL(zoomLevelChanged()), + this, SLOT(zoomLevelChanged())); + } if (m_vthumb->isVisible()) { m_headsUpDisplay->move(width() - 86, height() - 86); } else { m_headsUpDisplay->move(width() - 86, height() - 51); } - if (!m_headsUpDisplay->isVisible()) { - m_headsUpDisplay->show(); - connect(m_manager, SIGNAL(zoomLevelChanged()), - this, SLOT(zoomLevelChanged())); - } } else { m_headsUpDisplay->hide(); if (m_manager) { diff -r 11949d0b2739 -r 793df5f0c6cb widgets/Thumbwheel.cpp --- a/widgets/Thumbwheel.cpp Thu Oct 12 14:56:28 2006 +0000 +++ b/widgets/Thumbwheel.cpp Thu Oct 12 15:47:38 2006 +0000 @@ -30,13 +30,14 @@ m_max(100), m_default(50), m_value(50), + m_rotation(0.5), m_orientation(orientation), - m_speed(0.25), + m_speed(1.0), m_tracking(true), m_showScale(true), m_clicked(false), m_atDefault(true), - m_clickValue(m_value) + m_clickRotation(m_rotation) { } @@ -53,6 +54,9 @@ if (m_max <= m_min) m_max = m_min + 1; if (m_value < m_min) m_value = m_min; if (m_value > m_max) m_value = m_max; + + m_rotation = float(m_value - m_min) / float(m_max - m_min); + update(); } int @@ -70,6 +74,9 @@ if (m_min >= m_max) m_min = m_max - 1; if (m_value < m_min) m_value = m_min; if (m_value > m_max) m_value = m_max; + + m_rotation = float(m_value - m_min) / float(m_max - m_min); + update(); } int @@ -86,6 +93,7 @@ m_default = deft; if (m_atDefault) { setValue(m_default); + m_atDefault = true; // setValue unsets this emit valueChanged(getValue()); } } @@ -99,12 +107,19 @@ void Thumbwheel::setValue(int value) { - if (m_value == value) return; - m_atDefault = false; +// std::cerr << "Thumbwheel::setValue(" << value << ") (from " << m_value +// << ", rotation " << m_rotation << ")" << std::endl; - if (value < m_min) value = m_min; - if (value > m_max) value = m_max; - m_value = value; + if (m_value != value) { + + m_atDefault = false; + + if (value < m_min) value = m_min; + if (value > m_max) value = m_max; + m_value = value; + } + + m_rotation = float(m_value - m_min) / float(m_max - m_min); update(); } @@ -165,7 +180,7 @@ if (e->button() == Qt::LeftButton) { m_clicked = true; m_clickPos = e->pos(); - m_clickValue = m_value; + m_clickRotation = m_rotation; } else if (e->button() == Qt::MidButton) { resetToDefault(); } @@ -187,13 +202,19 @@ } else { dist = e->y() - m_clickPos.y(); } - int value = m_clickValue + lrintf(m_speed * dist); - if (value < m_min) value = m_min; - if (value > m_max) value = m_max; + + float rotation = m_clickRotation + (m_speed * dist) / 100; + if (rotation < 0.f) rotation = 0.f; + if (rotation > 1.f) rotation = 1.f; + int value = lrintf(m_min + (m_max - m_min) * m_rotation); if (value != m_value) { setValue(value); if (m_tracking) emit valueChanged(getValue()); - } + m_rotation = rotation; + } else if (fabsf(rotation - m_rotation) > 0.001) { + m_rotation = rotation; + repaint(); + } } void @@ -240,8 +261,7 @@ paint.setClipRect(QRect(bw, bw, width() - bw*2, height() - bw*2)); - float distance = float(m_value - m_min) / float(m_max - m_min); - float rotation = distance * 1.5f * M_PI; + float radians = m_rotation * 1.5f * M_PI; // std::cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << std::endl; @@ -257,9 +277,9 @@ for (int i = 0; i < notches; ++i) { - float a0 = (2.f * M_PI * i) / notches + rotation; + float a0 = (2.f * M_PI * i) / notches + radians; float a1 = a0 + M_PI / (notches * 2); - float a2 = (2.f * M_PI * (i + 1)) / notches + rotation; + float a2 = (2.f * M_PI * (i + 1)) / notches + radians; float depth = cosf((a0 + a2) / 2); if (depth < 0) continue; diff -r 11949d0b2739 -r 793df5f0c6cb widgets/Thumbwheel.h --- a/widgets/Thumbwheel.h Thu Oct 12 14:56:28 2006 +0000 +++ b/widgets/Thumbwheel.h Thu Oct 12 15:47:38 2006 +0000 @@ -61,6 +61,7 @@ int m_max; int m_default; int m_value; + float m_rotation; Qt::Orientation m_orientation; float m_speed; bool m_tracking; @@ -68,7 +69,7 @@ bool m_clicked; bool m_atDefault; QPoint m_clickPos; - int m_clickValue; + float m_clickRotation; }; #endif