annotate widgets/AudioDial.cpp @ 1343:5f3e374746b6 zoom

Fix crash when scrolling beyond end of waveform (+ fix compiler warnings)
author Chris Cannam
date Thu, 27 Sep 2018 16:20:58 +0100
parents a34a2a25907c
children c8a6fd3f9dff
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7
Chris@59 8 This program is free software; you can redistribute it and/or
Chris@59 9 modify it under the terms of the GNU General Public License as
Chris@59 10 published by the Free Software Foundation; either version 2 of the
Chris@59 11 License, or (at your option) any later version. See the file
Chris@59 12 COPYING included with this distribution for more information.
Chris@0 13 */
Chris@0 14
Chris@0 15 /**
Chris@0 16 * A rotary dial widget.
Chris@0 17 *
Chris@0 18 * Based on an original design by Thorsten Wilms.
Chris@0 19 *
Chris@0 20 * Implemented as a widget for the Rosegarden MIDI and audio sequencer
Chris@0 21 * and notation editor by Chris Cannam.
Chris@0 22 *
Chris@0 23 * Extracted into a standalone Qt3 widget by Pedro Lopez-Cabanillas
Chris@0 24 * and adapted for use in QSynth.
Chris@0 25 *
Chris@0 26 * Ported to Qt4 by Chris Cannam.
Chris@0 27 *
Chris@168 28 * This file copyright 2003-2006 Chris Cannam, copyright 2005 Pedro
Chris@182 29 * Lopez-Cabanillas, copyright 2006 Queen Mary, University of London.
Chris@0 30 *
Chris@0 31 * This program is free software; you can redistribute it and/or
Chris@0 32 * modify it under the terms of the GNU General Public License as
Chris@0 33 * published by the Free Software Foundation; either version 2 of the
Chris@0 34 * License, or (at your option) any later version. See the file
Chris@0 35 * COPYING included with this distribution for more information.
Chris@0 36 */
Chris@0 37
Chris@0 38 #include "AudioDial.h"
Chris@0 39
Chris@167 40 #include "base/RangeMapper.h"
Chris@167 41
Chris@0 42 #include <cmath>
Chris@0 43 #include <iostream>
Chris@0 44
Chris@0 45 #include <QTimer>
Chris@0 46 #include <QPainter>
Chris@0 47 #include <QPixmap>
Chris@0 48 #include <QColormap>
Chris@0 49 #include <QMouseEvent>
Chris@0 50 #include <QPaintEvent>
Chris@34 51 #include <QInputDialog>
Chris@0 52
Chris@382 53 #include "base/Profiler.h"
Chris@382 54
Chris@682 55
Chris@682 56
Chris@0 57
Chris@0 58
Chris@0 59 //!!! Pedro updated his version to use my up/down response code from RG -- need to grab that code in preference to this version from Rui
Chris@0 60
Chris@0 61
Chris@0 62 //-------------------------------------------------------------------------
Chris@0 63 // AudioDial - Instance knob widget class.
Chris@0 64 //
Chris@0 65
Chris@0 66 #define AUDIO_DIAL_MIN (0.25 * M_PI)
Chris@0 67 #define AUDIO_DIAL_MAX (1.75 * M_PI)
Chris@0 68 #define AUDIO_DIAL_RANGE (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN)
Chris@0 69
Chris@0 70
Chris@212 71 //static int dialsExtant = 0;
Chris@189 72
Chris@189 73
Chris@0 74 // Constructor.
Chris@0 75 AudioDial::AudioDial(QWidget *parent) :
Chris@0 76 QDial(parent),
Chris@170 77 m_knobColor(Qt::black),
Chris@170 78 m_meterColor(Qt::white),
Chris@167 79 m_defaultValue(0),
Chris@344 80 m_defaultMappedValue(0),
Chris@168 81 m_mappedValue(0),
Chris@168 82 m_noMappedUpdate(false),
Chris@187 83 m_showTooltip(true),
Chris@167 84 m_rangeMapper(0)
Chris@0 85 {
Chris@0 86 m_mouseDial = false;
Chris@0 87 m_mousePressed = false;
Chris@212 88 // ++dialsExtant;
Chris@0 89 }
Chris@0 90
Chris@0 91
Chris@0 92 // Destructor.
Chris@0 93 AudioDial::~AudioDial (void)
Chris@0 94 {
Chris@167 95 delete m_rangeMapper;
Chris@212 96 // --dialsExtant;
Chris@167 97 }
Chris@167 98
Chris@167 99
Chris@167 100 void AudioDial::setRangeMapper(RangeMapper *mapper)
Chris@167 101 {
Chris@682 102 // cerr << "AudioDial[" << this << "][\"" << objectName() << "\"::setRangeMapper(" << mapper << ") [current is " << m_rangeMapper << "] (have " << dialsExtant << " dials extant)" << endl;
Chris@189 103
Chris@187 104 if (m_rangeMapper == mapper) return;
Chris@187 105
Chris@170 106 if (!m_rangeMapper && mapper) {
Chris@168 107 connect(this, SIGNAL(valueChanged(int)),
Chris@168 108 this, SLOT(updateMappedValue(int)));
Chris@168 109 }
Chris@170 110
Chris@167 111 delete m_rangeMapper;
Chris@167 112 m_rangeMapper = mapper;
Chris@170 113
Chris@187 114 updateMappedValue(value());
Chris@0 115 }
Chris@0 116
Chris@0 117
Chris@0 118 void AudioDial::paintEvent(QPaintEvent *)
Chris@0 119 {
Chris@382 120 Profiler profiler("AudioDial::paintEvent");
Chris@382 121
Chris@0 122 QPainter paint;
Chris@0 123
Chris@908 124 double angle = AUDIO_DIAL_MIN // offset
Chris@1266 125 + (AUDIO_DIAL_RANGE *
Chris@1266 126 (double(QDial::value() - QDial::minimum()) /
Chris@1266 127 (double(QDial::maximum() - QDial::minimum()))));
Chris@0 128 int degrees = int(angle * 180.0 / M_PI);
Chris@0 129
Chris@0 130 int ns = notchSize();
Chris@0 131 int numTicks = 1 + (maximum() + ns - minimum()) / ns;
Chris@1266 132
Chris@0 133 QColor knobColor(m_knobColor);
Chris@0 134 if (knobColor == Qt::black)
Chris@1266 135 knobColor = palette().window().color();
Chris@0 136
Chris@0 137 QColor meterColor(m_meterColor);
Chris@0 138 if (!isEnabled())
Chris@1266 139 meterColor = palette().mid().color();
Chris@0 140 else if (m_meterColor == Qt::white)
Chris@1266 141 meterColor = palette().highlight().color();
Chris@0 142
Chris@0 143 int m_size = width() < height() ? width() : height();
Chris@0 144 int scale = 1;
Chris@249 145 int width = m_size - 2*scale;
Chris@0 146
Chris@0 147 paint.begin(this);
Chris@0 148 paint.setRenderHint(QPainter::Antialiasing, true);
Chris@0 149 paint.translate(1, 1);
Chris@0 150
Chris@0 151 QPen pen;
Chris@0 152 QColor c;
Chris@0 153
Chris@0 154 // Knob body and face...
Chris@0 155
Chris@0 156 c = knobColor;
Chris@0 157 pen.setColor(knobColor);
Chris@0 158 pen.setWidth(scale * 2);
Chris@0 159 pen.setCapStyle(Qt::FlatCap);
Chris@1266 160
Chris@0 161 paint.setPen(pen);
Chris@0 162 paint.setBrush(c);
Chris@0 163
Chris@0 164 int indent = (int)(width * 0.15 + 1);
Chris@0 165
Chris@0 166 paint.drawEllipse(indent-1, indent-1, width-2*indent, width-2*indent);
Chris@0 167
Chris@0 168 pen.setWidth(3 * scale);
Chris@0 169 int pos = indent-1 + (width-2*indent) / 20;
Chris@0 170 int darkWidth = (width-2*indent) * 3 / 4;
Chris@0 171 while (darkWidth) {
Chris@1266 172 c = c.light(102);
Chris@1266 173 pen.setColor(c);
Chris@1266 174 paint.setPen(pen);
Chris@1266 175 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 176 if (!--darkWidth) break;
Chris@1266 177 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 178 if (!--darkWidth) break;
Chris@1266 179 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 180 ++pos; --darkWidth;
Chris@0 181 }
Chris@0 182
Chris@0 183 // Tick notches...
Chris@0 184
Chris@34 185 if ( notchesVisible() ) {
Chris@1266 186 // cerr << "Notches visible" << endl;
Chris@1266 187 pen.setColor(palette().dark().color());
Chris@1266 188 pen.setWidth(scale);
Chris@1266 189 paint.setPen(pen);
Chris@1266 190 for (int i = 0; i < numTicks; ++i) {
Chris@1266 191 int div = numTicks;
Chris@1266 192 if (div > 1) --div;
Chris@1266 193 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div,
Chris@1266 194 width, true);
Chris@1266 195 }
Chris@0 196 }
Chris@0 197
Chris@0 198 // The bright metering bit...
Chris@0 199
Chris@0 200 c = meterColor;
Chris@0 201 pen.setColor(c);
Chris@0 202 pen.setWidth(indent);
Chris@0 203 paint.setPen(pen);
Chris@0 204
Chris@682 205 // cerr << "degrees " << degrees << ", gives us " << -(degrees - 45) * 16 << endl;
Chris@0 206
Chris@0 207 int arcLen = -(degrees - 45) * 16;
Chris@0 208 if (arcLen == 0) arcLen = -16;
Chris@0 209
Chris@0 210 paint.drawArc(indent/2, indent/2,
Chris@1266 211 width-indent, width-indent, (180 + 45) * 16, arcLen);
Chris@0 212
Chris@0 213 paint.setBrush(Qt::NoBrush);
Chris@0 214
Chris@0 215 // Shadowing...
Chris@0 216
Chris@0 217 pen.setWidth(scale);
Chris@0 218 paint.setPen(pen);
Chris@0 219
Chris@0 220 // Knob shadow...
Chris@0 221
Chris@0 222 int shadowAngle = -720;
Chris@0 223 c = knobColor.dark();
Chris@0 224 for (int arc = 120; arc < 2880; arc += 240) {
Chris@1266 225 pen.setColor(c);
Chris@1266 226 paint.setPen(pen);
Chris@1266 227 paint.drawArc(indent, indent,
Chris@1266 228 width-2*indent, width-2*indent, shadowAngle + arc, 240);
Chris@1266 229 paint.drawArc(indent, indent,
Chris@1266 230 width-2*indent, width-2*indent, shadowAngle - arc, 240);
Chris@1266 231 c = c.light(110);
Chris@0 232 }
Chris@0 233
Chris@738 234 // Scale shadow, omitting the bottom part...
Chris@0 235
Chris@0 236 shadowAngle = 2160;
Chris@738 237 c = palette().shadow().color();
Chris@738 238 for (int i = 0; i < 5; ++i) {
Chris@1266 239 pen.setColor(c);
Chris@1266 240 paint.setPen(pen);
Chris@738 241 int arc = i * 240 + 120;
Chris@1266 242 paint.drawArc(scale/2, scale/2,
Chris@1266 243 width-scale, width-scale, shadowAngle + arc, 240);
Chris@1266 244 c = c.light(110);
Chris@738 245 }
Chris@738 246 c = palette().shadow().color();
Chris@738 247 for (int i = 0; i < 12; ++i) {
Chris@1266 248 pen.setColor(c);
Chris@1266 249 paint.setPen(pen);
Chris@738 250 int arc = i * 240 + 120;
Chris@1266 251 paint.drawArc(scale/2, scale/2,
Chris@1266 252 width-scale, width-scale, shadowAngle - arc, 240);
Chris@1266 253 c = c.light(110);
Chris@0 254 }
Chris@0 255
Chris@0 256 // Scale ends...
Chris@0 257
Chris@738 258 pen.setColor(palette().shadow().color());
Chris@0 259 pen.setWidth(scale);
Chris@0 260 paint.setPen(pen);
Chris@0 261 for (int i = 0; i < numTicks; ++i) {
Chris@1266 262 if (i != 0 && i != numTicks - 1) continue;
Chris@1266 263 int div = numTicks;
Chris@1266 264 if (div > 1) --div;
Chris@1266 265 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div,
Chris@1266 266 width, false);
Chris@0 267 }
Chris@0 268
Chris@0 269 // Pointer notch...
Chris@0 270
Chris@908 271 double hyp = double(width) / 2.0;
Chris@908 272 double len = hyp - indent;
Chris@0 273 --len;
Chris@0 274
Chris@908 275 double x0 = hyp;
Chris@908 276 double y0 = hyp;
Chris@0 277
Chris@908 278 double x = hyp - len * sin(angle);
Chris@908 279 double y = hyp + len * cos(angle);
Chris@0 280
Chris@0 281 c = palette().dark().color();
Chris@0 282 pen.setColor(isEnabled() ? c.dark(130) : c);
Chris@0 283 pen.setWidth(scale * 2);
Chris@0 284 paint.setPen(pen);
Chris@0 285 paint.drawLine(int(x0), int(y0), int(x), int(y));
Chris@0 286
Chris@0 287 paint.end();
Chris@0 288 }
Chris@0 289
Chris@0 290
Chris@0 291 void AudioDial::drawTick(QPainter &paint,
Chris@1266 292 double angle, int size, bool internal)
Chris@0 293 {
Chris@908 294 double hyp = double(size) / 2.0;
Chris@908 295 double x0 = hyp - (hyp - 1) * sin(angle);
Chris@908 296 double y0 = hyp + (hyp - 1) * cos(angle);
Chris@0 297
Chris@0 298 // cerr << "drawTick: angle " << angle << ", size " << size << ", internal " << internal << endl;
Chris@0 299
Chris@0 300 if (internal) {
Chris@0 301
Chris@1266 302 double len = hyp / 4;
Chris@1266 303 double x1 = hyp - (hyp - len) * sin(angle);
Chris@1266 304 double y1 = hyp + (hyp - len) * cos(angle);
Chris@1266 305
Chris@1266 306 paint.drawLine(int(x0), int(y0), int(x1), int(y1));
Chris@0 307
Chris@0 308 } else {
Chris@0 309
Chris@1266 310 double len = hyp / 4;
Chris@1266 311 double x1 = hyp - (hyp + len) * sin(angle);
Chris@1266 312 double y1 = hyp + (hyp + len) * cos(angle);
Chris@0 313
Chris@1266 314 paint.drawLine(int(x0), int(y0), int(x1), int(y1));
Chris@0 315 }
Chris@0 316 }
Chris@0 317
Chris@0 318
Chris@0 319 void AudioDial::setKnobColor(const QColor& color)
Chris@0 320 {
Chris@0 321 m_knobColor = color;
Chris@0 322 update();
Chris@0 323 }
Chris@0 324
Chris@0 325
Chris@0 326 void AudioDial::setMeterColor(const QColor& color)
Chris@0 327 {
Chris@0 328 m_meterColor = color;
Chris@0 329 update();
Chris@0 330 }
Chris@0 331
Chris@0 332
Chris@0 333 void AudioDial::setMouseDial(bool mouseDial)
Chris@0 334 {
Chris@0 335 m_mouseDial = mouseDial;
Chris@0 336 }
Chris@0 337
Chris@0 338
Chris@34 339 void AudioDial::setDefaultValue(int defaultValue)
Chris@34 340 {
Chris@34 341 m_defaultValue = defaultValue;
Chris@344 342 if (m_rangeMapper) {
Chris@344 343 m_defaultMappedValue = m_rangeMapper->getValueForPosition(defaultValue);
Chris@344 344 }
Chris@34 345 }
Chris@34 346
Chris@219 347 void AudioDial::setValue(int value)
Chris@219 348 {
Chris@219 349 QDial::setValue(value);
Chris@219 350 updateMappedValue(value);
Chris@219 351 }
Chris@219 352
Chris@908 353 void AudioDial::setDefaultMappedValue(double value)
Chris@344 354 {
Chris@344 355 m_defaultMappedValue = value;
Chris@344 356 if (m_rangeMapper) {
Chris@344 357 m_defaultValue = m_rangeMapper->getPositionForValue(value);
Chris@344 358 }
Chris@344 359 }
Chris@219 360
Chris@908 361 void AudioDial::setMappedValue(double mappedValue)
Chris@177 362 {
Chris@177 363 if (m_rangeMapper) {
Chris@177 364 int newPosition = m_rangeMapper->getPositionForValue(mappedValue);
Chris@190 365 bool changed = (m_mappedValue != mappedValue);
Chris@177 366 m_mappedValue = mappedValue;
Chris@177 367 m_noMappedUpdate = true;
Chris@587 368 SVDEBUG << "AudioDial::setMappedValue(" << mappedValue << "): new position is " << newPosition << endl;
Chris@177 369 if (newPosition != value()) {
Chris@177 370 setValue(newPosition);
Chris@190 371 } else if (changed) {
Chris@177 372 emit valueChanged(newPosition);
Chris@177 373 }
Chris@177 374 m_noMappedUpdate = false;
Chris@177 375 } else {
Chris@187 376 setValue(int(mappedValue));
Chris@177 377 }
Chris@177 378 }
Chris@177 379
Chris@177 380
Chris@168 381 void AudioDial::setShowToolTip(bool show)
Chris@168 382 {
Chris@168 383 m_showTooltip = show;
Chris@168 384 m_noMappedUpdate = true;
Chris@168 385 updateMappedValue(value());
Chris@168 386 m_noMappedUpdate = false;
Chris@168 387 }
Chris@168 388
Chris@168 389
Chris@908 390 double AudioDial::mappedValue() const
Chris@167 391 {
Chris@168 392 if (m_rangeMapper) {
Chris@587 393 // SVDEBUG << "AudioDial::mappedValue(): value = " << value() << ", mappedValue = " << m_mappedValue << endl;
Chris@168 394 return m_mappedValue;
Chris@168 395 }
Chris@168 396 return value();
Chris@168 397 }
Chris@168 398
Chris@168 399
Chris@168 400 void AudioDial::updateMappedValue(int value)
Chris@168 401 {
Chris@170 402 if (!m_noMappedUpdate) {
Chris@170 403 if (m_rangeMapper) {
Chris@168 404 m_mappedValue = m_rangeMapper->getValueForPosition(value);
Chris@170 405 } else {
Chris@170 406 m_mappedValue = value;
Chris@168 407 }
Chris@168 408 }
Chris@168 409
Chris@168 410 if (m_showTooltip) {
Chris@168 411 QString name = objectName();
Chris@1147 412 QString label;
Chris@1147 413 if (m_rangeMapper) {
Chris@1147 414 label = m_rangeMapper->getLabel(value);
Chris@1147 415 }
Chris@168 416 QString text;
Chris@1147 417 if (label != "") {
Chris@1147 418 if (name != "") {
Chris@1147 419 text = tr("%1: %2").arg(name).arg(label);
Chris@1147 420 } else {
Chris@1147 421 text = label;
Chris@1147 422 }
Chris@168 423 } else {
Chris@1147 424 QString unit = "";
Chris@1147 425 if (m_rangeMapper) {
Chris@1147 426 unit = m_rangeMapper->getUnit();
Chris@1147 427 }
Chris@1147 428 if (name != "") {
Chris@1147 429 text = tr("%1: %2%3").arg(name).arg(m_mappedValue).arg(unit);
Chris@1147 430 } else {
Chris@1147 431 text = tr("%2%3").arg(m_mappedValue).arg(unit);
Chris@1147 432 }
Chris@168 433 }
Chris@168 434 setToolTip(text);
Chris@168 435 }
Chris@167 436 }
Chris@167 437
Chris@344 438 void
Chris@344 439 AudioDial::setToDefault()
Chris@344 440 {
Chris@344 441 if (m_rangeMapper) {
Chris@344 442 setMappedValue(m_defaultMappedValue);
Chris@344 443 return;
Chris@344 444 }
Chris@344 445 int dv = m_defaultValue;
Chris@344 446 if (dv < minimum()) dv = minimum();
Chris@344 447 if (dv > maximum()) dv = maximum();
Chris@344 448 setValue(m_defaultValue);
Chris@344 449 }
Chris@167 450
Chris@0 451 // Alternate mouse behavior event handlers.
Chris@0 452 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent)
Chris@0 453 {
Chris@0 454 if (m_mouseDial) {
Chris@1266 455 QDial::mousePressEvent(mouseEvent);
Chris@187 456 } else if (mouseEvent->button() == Qt::MidButton ||
Chris@187 457 ((mouseEvent->button() == Qt::LeftButton) &&
Chris@187 458 (mouseEvent->modifiers() & Qt::ControlModifier))) {
Chris@344 459 setToDefault();
Chris@187 460 } else if (mouseEvent->button() == Qt::LeftButton) {
Chris@1266 461 m_mousePressed = true;
Chris@1266 462 m_posMouse = mouseEvent->pos();
Chris@34 463 }
Chris@34 464 }
Chris@34 465
Chris@34 466
Chris@34 467 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent)
Chris@34 468 {
Chris@187 469 //!!! needs a common base class with Thumbwheel
Chris@187 470
Chris@34 471 if (m_mouseDial) {
Chris@1266 472 QDial::mouseDoubleClickEvent(mouseEvent);
Chris@187 473 } else if (mouseEvent->button() != Qt::LeftButton) {
Chris@187 474 return;
Chris@187 475 }
Chris@167 476
Chris@187 477 bool ok = false;
Chris@167 478
Chris@187 479 if (m_rangeMapper) {
Chris@187 480
Chris@908 481 double min = m_rangeMapper->getValueForPosition(minimum());
Chris@908 482 double max = m_rangeMapper->getValueForPosition(maximum());
Chris@187 483
Chris@187 484 if (min > max) {
Chris@908 485 double tmp = min;
Chris@187 486 min = max;
Chris@187 487 max = tmp;
Chris@187 488 }
Chris@167 489
Chris@187 490 QString unit = m_rangeMapper->getUnit();
Chris@187 491
Chris@187 492 QString text;
Chris@187 493 if (objectName() != "") {
Chris@187 494 if (unit != "") {
Chris@187 495 text = tr("New value for %1, from %2 to %3 %4:")
Chris@187 496 .arg(objectName()).arg(min).arg(max).arg(unit);
Chris@167 497 } else {
Chris@187 498 text = tr("New value for %1, from %2 to %3:")
Chris@187 499 .arg(objectName()).arg(min).arg(max);
Chris@167 500 }
Chris@187 501 } else {
Chris@187 502 if (unit != "") {
Chris@187 503 text = tr("Enter a new value from %1 to %2 %3:")
Chris@187 504 .arg(min).arg(max).arg(unit);
Chris@187 505 } else {
Chris@187 506 text = tr("Enter a new value from %1 to %2:")
Chris@187 507 .arg(min).arg(max);
Chris@168 508 }
Chris@187 509 }
Chris@187 510
Chris@908 511 double newValue = QInputDialog::getDouble
Chris@187 512 (this,
Chris@187 513 tr("Enter new value"),
Chris@187 514 text,
Chris@187 515 m_mappedValue,
Chris@187 516 min,
Chris@187 517 max,
Chris@187 518 4,
Chris@187 519 &ok);
Chris@187 520
Chris@187 521 if (ok) {
Chris@187 522 setMappedValue(newValue);
Chris@187 523 }
Chris@187 524
Chris@187 525 } else {
Chris@187 526
Chris@616 527 int newPosition = QInputDialog::getInt
Chris@187 528 (this,
Chris@187 529 tr("Enter new value"),
Chris@187 530 tr("Enter a new value from %1 to %2:")
Chris@187 531 .arg(minimum()).arg(maximum()),
Chris@395 532 value(), minimum(), maximum(), singleStep(), &ok);
Chris@187 533
Chris@187 534 if (ok) {
Chris@187 535 setValue(newPosition);
Chris@167 536 }
Chris@0 537 }
Chris@0 538 }
Chris@0 539
Chris@0 540
Chris@0 541 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent)
Chris@0 542 {
Chris@0 543 if (m_mouseDial) {
Chris@1266 544 QDial::mouseMoveEvent(mouseEvent);
Chris@0 545 } else if (m_mousePressed) {
Chris@1266 546 const QPoint& posMouse = mouseEvent->pos();
Chris@1266 547 int v = QDial::value()
Chris@1266 548 + (posMouse.x() - m_posMouse.x())
Chris@1266 549 + (m_posMouse.y() - posMouse.y());
Chris@1266 550 if (v > QDial::maximum())
Chris@1266 551 v = QDial::maximum();
Chris@1266 552 else
Chris@1266 553 if (v < QDial::minimum())
Chris@1266 554 v = QDial::minimum();
Chris@1266 555 m_posMouse = posMouse;
Chris@1266 556 QDial::setValue(v);
Chris@0 557 }
Chris@0 558 }
Chris@0 559
Chris@0 560
Chris@0 561 void AudioDial::mouseReleaseEvent(QMouseEvent *mouseEvent)
Chris@0 562 {
Chris@0 563 if (m_mouseDial) {
Chris@1266 564 QDial::mouseReleaseEvent(mouseEvent);
Chris@0 565 } else if (m_mousePressed) {
Chris@1266 566 m_mousePressed = false;
Chris@0 567 }
Chris@0 568 }
Chris@0 569
Chris@189 570 void
Chris@189 571 AudioDial::enterEvent(QEvent *e)
Chris@189 572 {
Chris@189 573 QDial::enterEvent(e);
Chris@189 574 emit mouseEntered();
Chris@189 575 }
Chris@189 576
Chris@189 577 void
Chris@189 578 AudioDial::leaveEvent(QEvent *e)
Chris@189 579 {
Chris@189 580 QDial::enterEvent(e);
Chris@189 581 emit mouseLeft();
Chris@189 582 }
Chris@189 583