annotate widgets/AudioDial.cpp @ 1571:9cd77efef37c

Model -> layer, + word wrap
author Chris Cannam
date Wed, 15 Jan 2020 13:58:11 +0000
parents bdf284b29722
children e5464dc2f6cf
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@1443 77 m_knobColor(Qt::black), // shorthand for "background colour" in paint()
Chris@1443 78 m_meterColor(Qt::white), // shorthand for "foreground colour" in paint()
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@1408 84 m_rangeMapper(nullptr)
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@1443 134 if (knobColor == Qt::black) {
Chris@1476 135 knobColor = palette().window().color().lighter(150);
Chris@1443 136 }
Chris@1443 137 bool knobIsDark =
Chris@1443 138 (knobColor.red() + knobColor.green() + knobColor.blue() <= 384);
Chris@0 139
Chris@0 140 QColor meterColor(m_meterColor);
Chris@1443 141 if (!isEnabled()) {
Chris@1266 142 meterColor = palette().mid().color();
Chris@1443 143 } else if (m_meterColor == Qt::white) {
Chris@1443 144 if (knobIsDark) {
Chris@1545 145 meterColor = palette().text().color();
Chris@1443 146 } else {
Chris@1443 147 meterColor = palette().highlight().color();
Chris@1443 148 }
Chris@1443 149 }
Chris@0 150
Chris@1443 151 QColor notchColor(palette().dark().color());
Chris@1443 152 if (knobIsDark) {
Chris@1545 153 notchColor = palette().text().color();
Chris@1443 154 }
Chris@1443 155
Chris@0 156 int m_size = width() < height() ? width() : height();
Chris@0 157 int scale = 1;
Chris@249 158 int width = m_size - 2*scale;
Chris@0 159
Chris@0 160 paint.begin(this);
Chris@0 161 paint.setRenderHint(QPainter::Antialiasing, true);
Chris@0 162 paint.translate(1, 1);
Chris@0 163
Chris@0 164 QPen pen;
Chris@0 165 QColor c;
Chris@0 166
Chris@0 167 // Knob body and face...
Chris@0 168
Chris@0 169 c = knobColor;
Chris@0 170 pen.setColor(knobColor);
Chris@0 171 pen.setWidth(scale * 2);
Chris@0 172 pen.setCapStyle(Qt::FlatCap);
Chris@1266 173
Chris@0 174 paint.setPen(pen);
Chris@0 175 paint.setBrush(c);
Chris@0 176
Chris@0 177 int indent = (int)(width * 0.15 + 1);
Chris@0 178
Chris@0 179 paint.drawEllipse(indent-1, indent-1, width-2*indent, width-2*indent);
Chris@0 180
Chris@0 181 pen.setWidth(3 * scale);
Chris@0 182 int pos = indent-1 + (width-2*indent) / 20;
Chris@0 183 int darkWidth = (width-2*indent) * 3 / 4;
Chris@0 184 while (darkWidth) {
Chris@1443 185 if (knobIsDark) {
Chris@1476 186 c = c.darker(102);
Chris@1443 187 } else {
Chris@1476 188 c = c.lighter(102);
Chris@1443 189 }
Chris@1266 190 pen.setColor(c);
Chris@1266 191 paint.setPen(pen);
Chris@1266 192 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 193 if (!--darkWidth) break;
Chris@1266 194 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 195 if (!--darkWidth) break;
Chris@1266 196 paint.drawEllipse(pos, pos, darkWidth, darkWidth);
Chris@1266 197 ++pos; --darkWidth;
Chris@0 198 }
Chris@0 199
Chris@0 200 // Tick notches...
Chris@0 201
Chris@34 202 if ( notchesVisible() ) {
Chris@1443 203 pen.setColor(notchColor);
Chris@1266 204 pen.setWidth(scale);
Chris@1266 205 paint.setPen(pen);
Chris@1266 206 for (int i = 0; i < numTicks; ++i) {
Chris@1266 207 int div = numTicks;
Chris@1266 208 if (div > 1) --div;
Chris@1266 209 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div,
Chris@1266 210 width, true);
Chris@1266 211 }
Chris@0 212 }
Chris@0 213
Chris@0 214 // The bright metering bit...
Chris@0 215
Chris@0 216 c = meterColor;
Chris@0 217 pen.setColor(c);
Chris@0 218 pen.setWidth(indent);
Chris@0 219 paint.setPen(pen);
Chris@0 220
Chris@682 221 // cerr << "degrees " << degrees << ", gives us " << -(degrees - 45) * 16 << endl;
Chris@0 222
Chris@0 223 int arcLen = -(degrees - 45) * 16;
Chris@0 224 if (arcLen == 0) arcLen = -16;
Chris@0 225
Chris@0 226 paint.drawArc(indent/2, indent/2,
Chris@1266 227 width-indent, width-indent, (180 + 45) * 16, arcLen);
Chris@0 228
Chris@0 229 paint.setBrush(Qt::NoBrush);
Chris@0 230
Chris@0 231 // Shadowing...
Chris@0 232
Chris@0 233 pen.setWidth(scale);
Chris@0 234 paint.setPen(pen);
Chris@0 235
Chris@0 236 // Knob shadow...
Chris@0 237
Chris@0 238 int shadowAngle = -720;
Chris@1443 239 if (knobIsDark) {
Chris@1476 240 c = knobColor.lighter();
Chris@1443 241 } else {
Chris@1476 242 c = knobColor.darker();
Chris@1443 243 }
Chris@0 244 for (int arc = 120; arc < 2880; arc += 240) {
Chris@1266 245 pen.setColor(c);
Chris@1266 246 paint.setPen(pen);
Chris@1266 247 paint.drawArc(indent, indent,
Chris@1266 248 width-2*indent, width-2*indent, shadowAngle + arc, 240);
Chris@1266 249 paint.drawArc(indent, indent,
Chris@1266 250 width-2*indent, width-2*indent, shadowAngle - arc, 240);
Chris@1443 251 if (knobIsDark) {
Chris@1476 252 c = c.darker(110);
Chris@1443 253 } else {
Chris@1476 254 c = c.lighter(110);
Chris@1443 255 }
Chris@0 256 }
Chris@0 257
Chris@738 258 // Scale shadow, omitting the bottom part...
Chris@0 259
Chris@0 260 shadowAngle = 2160;
Chris@738 261 c = palette().shadow().color();
Chris@738 262 for (int i = 0; i < 5; ++i) {
Chris@1266 263 pen.setColor(c);
Chris@1266 264 paint.setPen(pen);
Chris@738 265 int arc = i * 240 + 120;
Chris@1266 266 paint.drawArc(scale/2, scale/2,
Chris@1266 267 width-scale, width-scale, shadowAngle + arc, 240);
Chris@1476 268 c = c.lighter(110);
Chris@738 269 }
Chris@738 270 c = palette().shadow().color();
Chris@738 271 for (int i = 0; i < 12; ++i) {
Chris@1266 272 pen.setColor(c);
Chris@1266 273 paint.setPen(pen);
Chris@738 274 int arc = i * 240 + 120;
Chris@1266 275 paint.drawArc(scale/2, scale/2,
Chris@1266 276 width-scale, width-scale, shadowAngle - arc, 240);
Chris@1476 277 c = c.lighter(110);
Chris@0 278 }
Chris@0 279
Chris@0 280 // Scale ends...
Chris@0 281
Chris@1443 282 if (knobIsDark) {
Chris@1443 283 pen.setColor(palette().mid().color());
Chris@1443 284 } else {
Chris@1443 285 pen.setColor(palette().shadow().color());
Chris@1443 286 }
Chris@0 287 pen.setWidth(scale);
Chris@0 288 paint.setPen(pen);
Chris@0 289 for (int i = 0; i < numTicks; ++i) {
Chris@1266 290 if (i != 0 && i != numTicks - 1) continue;
Chris@1266 291 int div = numTicks;
Chris@1266 292 if (div > 1) --div;
Chris@1266 293 drawTick(paint, AUDIO_DIAL_MIN + (AUDIO_DIAL_MAX - AUDIO_DIAL_MIN) * i / div,
Chris@1266 294 width, false);
Chris@0 295 }
Chris@0 296
Chris@0 297 // Pointer notch...
Chris@0 298
Chris@908 299 double hyp = double(width) / 2.0;
Chris@908 300 double len = hyp - indent;
Chris@0 301 --len;
Chris@0 302
Chris@908 303 double x0 = hyp;
Chris@908 304 double y0 = hyp;
Chris@0 305
Chris@908 306 double x = hyp - len * sin(angle);
Chris@908 307 double y = hyp + len * cos(angle);
Chris@0 308
Chris@1443 309 c = notchColor;
Chris@1443 310 if (isEnabled()) {
Chris@1443 311 if (knobIsDark) {
Chris@1476 312 c = c.lighter(130);
Chris@1443 313 } else {
Chris@1476 314 c = c.darker(130);
Chris@1443 315 }
Chris@1443 316 }
Chris@1443 317 pen.setColor(c);
Chris@0 318 pen.setWidth(scale * 2);
Chris@0 319 paint.setPen(pen);
Chris@0 320 paint.drawLine(int(x0), int(y0), int(x), int(y));
Chris@0 321
Chris@0 322 paint.end();
Chris@0 323 }
Chris@0 324
Chris@0 325
Chris@0 326 void AudioDial::drawTick(QPainter &paint,
Chris@1266 327 double angle, int size, bool internal)
Chris@0 328 {
Chris@908 329 double hyp = double(size) / 2.0;
Chris@908 330 double x0 = hyp - (hyp - 1) * sin(angle);
Chris@908 331 double y0 = hyp + (hyp - 1) * cos(angle);
Chris@0 332
Chris@0 333 // cerr << "drawTick: angle " << angle << ", size " << size << ", internal " << internal << endl;
Chris@0 334
Chris@0 335 if (internal) {
Chris@0 336
Chris@1266 337 double len = hyp / 4;
Chris@1266 338 double x1 = hyp - (hyp - len) * sin(angle);
Chris@1266 339 double y1 = hyp + (hyp - len) * cos(angle);
Chris@1266 340
Chris@1266 341 paint.drawLine(int(x0), int(y0), int(x1), int(y1));
Chris@0 342
Chris@0 343 } else {
Chris@0 344
Chris@1266 345 double len = hyp / 4;
Chris@1266 346 double x1 = hyp - (hyp + len) * sin(angle);
Chris@1266 347 double y1 = hyp + (hyp + len) * cos(angle);
Chris@0 348
Chris@1266 349 paint.drawLine(int(x0), int(y0), int(x1), int(y1));
Chris@0 350 }
Chris@0 351 }
Chris@0 352
Chris@0 353
Chris@0 354 void AudioDial::setKnobColor(const QColor& color)
Chris@0 355 {
Chris@0 356 m_knobColor = color;
Chris@0 357 update();
Chris@0 358 }
Chris@0 359
Chris@0 360
Chris@0 361 void AudioDial::setMeterColor(const QColor& color)
Chris@0 362 {
Chris@0 363 m_meterColor = color;
Chris@0 364 update();
Chris@0 365 }
Chris@0 366
Chris@0 367
Chris@0 368 void AudioDial::setMouseDial(bool mouseDial)
Chris@0 369 {
Chris@0 370 m_mouseDial = mouseDial;
Chris@0 371 }
Chris@0 372
Chris@0 373
Chris@34 374 void AudioDial::setDefaultValue(int defaultValue)
Chris@34 375 {
Chris@34 376 m_defaultValue = defaultValue;
Chris@344 377 if (m_rangeMapper) {
Chris@344 378 m_defaultMappedValue = m_rangeMapper->getValueForPosition(defaultValue);
Chris@344 379 }
Chris@34 380 }
Chris@34 381
Chris@219 382 void AudioDial::setValue(int value)
Chris@219 383 {
Chris@219 384 QDial::setValue(value);
Chris@219 385 updateMappedValue(value);
Chris@219 386 }
Chris@219 387
Chris@908 388 void AudioDial::setDefaultMappedValue(double value)
Chris@344 389 {
Chris@344 390 m_defaultMappedValue = value;
Chris@344 391 if (m_rangeMapper) {
Chris@344 392 m_defaultValue = m_rangeMapper->getPositionForValue(value);
Chris@344 393 }
Chris@344 394 }
Chris@219 395
Chris@908 396 void AudioDial::setMappedValue(double mappedValue)
Chris@177 397 {
Chris@177 398 if (m_rangeMapper) {
Chris@177 399 int newPosition = m_rangeMapper->getPositionForValue(mappedValue);
Chris@190 400 bool changed = (m_mappedValue != mappedValue);
Chris@177 401 m_mappedValue = mappedValue;
Chris@177 402 m_noMappedUpdate = true;
Chris@587 403 SVDEBUG << "AudioDial::setMappedValue(" << mappedValue << "): new position is " << newPosition << endl;
Chris@177 404 if (newPosition != value()) {
Chris@177 405 setValue(newPosition);
Chris@190 406 } else if (changed) {
Chris@177 407 emit valueChanged(newPosition);
Chris@177 408 }
Chris@177 409 m_noMappedUpdate = false;
Chris@177 410 } else {
Chris@187 411 setValue(int(mappedValue));
Chris@177 412 }
Chris@177 413 }
Chris@177 414
Chris@177 415
Chris@168 416 void AudioDial::setShowToolTip(bool show)
Chris@168 417 {
Chris@168 418 m_showTooltip = show;
Chris@168 419 m_noMappedUpdate = true;
Chris@168 420 updateMappedValue(value());
Chris@168 421 m_noMappedUpdate = false;
Chris@168 422 }
Chris@168 423
Chris@168 424
Chris@908 425 double AudioDial::mappedValue() const
Chris@167 426 {
Chris@168 427 if (m_rangeMapper) {
Chris@587 428 // SVDEBUG << "AudioDial::mappedValue(): value = " << value() << ", mappedValue = " << m_mappedValue << endl;
Chris@168 429 return m_mappedValue;
Chris@168 430 }
Chris@168 431 return value();
Chris@168 432 }
Chris@168 433
Chris@168 434
Chris@168 435 void AudioDial::updateMappedValue(int value)
Chris@168 436 {
Chris@170 437 if (!m_noMappedUpdate) {
Chris@170 438 if (m_rangeMapper) {
Chris@168 439 m_mappedValue = m_rangeMapper->getValueForPosition(value);
Chris@170 440 } else {
Chris@170 441 m_mappedValue = value;
Chris@168 442 }
Chris@168 443 }
Chris@168 444
Chris@168 445 if (m_showTooltip) {
Chris@168 446 QString name = objectName();
Chris@1147 447 QString label;
Chris@1147 448 if (m_rangeMapper) {
Chris@1147 449 label = m_rangeMapper->getLabel(value);
Chris@1147 450 }
Chris@168 451 QString text;
Chris@1147 452 if (label != "") {
Chris@1147 453 if (name != "") {
Chris@1147 454 text = tr("%1: %2").arg(name).arg(label);
Chris@1147 455 } else {
Chris@1147 456 text = label;
Chris@1147 457 }
Chris@168 458 } else {
Chris@1147 459 QString unit = "";
Chris@1147 460 if (m_rangeMapper) {
Chris@1147 461 unit = m_rangeMapper->getUnit();
Chris@1147 462 }
Chris@1147 463 if (name != "") {
Chris@1147 464 text = tr("%1: %2%3").arg(name).arg(m_mappedValue).arg(unit);
Chris@1147 465 } else {
Chris@1147 466 text = tr("%2%3").arg(m_mappedValue).arg(unit);
Chris@1147 467 }
Chris@168 468 }
Chris@168 469 setToolTip(text);
Chris@168 470 }
Chris@167 471 }
Chris@167 472
Chris@344 473 void
Chris@344 474 AudioDial::setToDefault()
Chris@344 475 {
Chris@344 476 if (m_rangeMapper) {
Chris@344 477 setMappedValue(m_defaultMappedValue);
Chris@344 478 return;
Chris@344 479 }
Chris@344 480 int dv = m_defaultValue;
Chris@344 481 if (dv < minimum()) dv = minimum();
Chris@344 482 if (dv > maximum()) dv = maximum();
Chris@344 483 setValue(m_defaultValue);
Chris@344 484 }
Chris@167 485
Chris@0 486 // Alternate mouse behavior event handlers.
Chris@0 487 void AudioDial::mousePressEvent(QMouseEvent *mouseEvent)
Chris@0 488 {
Chris@0 489 if (m_mouseDial) {
Chris@1266 490 QDial::mousePressEvent(mouseEvent);
Chris@187 491 } else if (mouseEvent->button() == Qt::MidButton ||
Chris@187 492 ((mouseEvent->button() == Qt::LeftButton) &&
Chris@187 493 (mouseEvent->modifiers() & Qt::ControlModifier))) {
Chris@344 494 setToDefault();
Chris@187 495 } else if (mouseEvent->button() == Qt::LeftButton) {
Chris@1266 496 m_mousePressed = true;
Chris@1266 497 m_posMouse = mouseEvent->pos();
Chris@34 498 }
Chris@34 499 }
Chris@34 500
Chris@34 501
Chris@34 502 void AudioDial::mouseDoubleClickEvent(QMouseEvent *mouseEvent)
Chris@34 503 {
Chris@187 504 //!!! needs a common base class with Thumbwheel
Chris@187 505
Chris@34 506 if (m_mouseDial) {
Chris@1266 507 QDial::mouseDoubleClickEvent(mouseEvent);
Chris@187 508 } else if (mouseEvent->button() != Qt::LeftButton) {
Chris@187 509 return;
Chris@187 510 }
Chris@167 511
Chris@187 512 bool ok = false;
Chris@167 513
Chris@187 514 if (m_rangeMapper) {
Chris@187 515
Chris@908 516 double min = m_rangeMapper->getValueForPosition(minimum());
Chris@908 517 double max = m_rangeMapper->getValueForPosition(maximum());
Chris@187 518
Chris@187 519 if (min > max) {
Chris@908 520 double tmp = min;
Chris@187 521 min = max;
Chris@187 522 max = tmp;
Chris@187 523 }
Chris@167 524
Chris@187 525 QString unit = m_rangeMapper->getUnit();
Chris@187 526
Chris@187 527 QString text;
Chris@187 528 if (objectName() != "") {
Chris@187 529 if (unit != "") {
Chris@187 530 text = tr("New value for %1, from %2 to %3 %4:")
Chris@187 531 .arg(objectName()).arg(min).arg(max).arg(unit);
Chris@167 532 } else {
Chris@187 533 text = tr("New value for %1, from %2 to %3:")
Chris@187 534 .arg(objectName()).arg(min).arg(max);
Chris@167 535 }
Chris@187 536 } else {
Chris@187 537 if (unit != "") {
Chris@187 538 text = tr("Enter a new value from %1 to %2 %3:")
Chris@187 539 .arg(min).arg(max).arg(unit);
Chris@187 540 } else {
Chris@187 541 text = tr("Enter a new value from %1 to %2:")
Chris@187 542 .arg(min).arg(max);
Chris@168 543 }
Chris@187 544 }
Chris@187 545
Chris@908 546 double newValue = QInputDialog::getDouble
Chris@187 547 (this,
Chris@187 548 tr("Enter new value"),
Chris@187 549 text,
Chris@187 550 m_mappedValue,
Chris@187 551 min,
Chris@187 552 max,
Chris@187 553 4,
Chris@187 554 &ok);
Chris@187 555
Chris@187 556 if (ok) {
Chris@187 557 setMappedValue(newValue);
Chris@187 558 }
Chris@187 559
Chris@187 560 } else {
Chris@187 561
Chris@616 562 int newPosition = QInputDialog::getInt
Chris@187 563 (this,
Chris@187 564 tr("Enter new value"),
Chris@187 565 tr("Enter a new value from %1 to %2:")
Chris@187 566 .arg(minimum()).arg(maximum()),
Chris@395 567 value(), minimum(), maximum(), singleStep(), &ok);
Chris@187 568
Chris@187 569 if (ok) {
Chris@187 570 setValue(newPosition);
Chris@167 571 }
Chris@0 572 }
Chris@0 573 }
Chris@0 574
Chris@0 575
Chris@0 576 void AudioDial::mouseMoveEvent(QMouseEvent *mouseEvent)
Chris@0 577 {
Chris@0 578 if (m_mouseDial) {
Chris@1266 579 QDial::mouseMoveEvent(mouseEvent);
Chris@0 580 } else if (m_mousePressed) {
Chris@1266 581 const QPoint& posMouse = mouseEvent->pos();
Chris@1266 582 int v = QDial::value()
Chris@1266 583 + (posMouse.x() - m_posMouse.x())
Chris@1266 584 + (m_posMouse.y() - posMouse.y());
Chris@1266 585 if (v > QDial::maximum())
Chris@1266 586 v = QDial::maximum();
Chris@1266 587 else
Chris@1266 588 if (v < QDial::minimum())
Chris@1266 589 v = QDial::minimum();
Chris@1266 590 m_posMouse = posMouse;
Chris@1266 591 QDial::setValue(v);
Chris@0 592 }
Chris@0 593 }
Chris@0 594
Chris@0 595
Chris@0 596 void AudioDial::mouseReleaseEvent(QMouseEvent *mouseEvent)
Chris@0 597 {
Chris@0 598 if (m_mouseDial) {
Chris@1266 599 QDial::mouseReleaseEvent(mouseEvent);
Chris@0 600 } else if (m_mousePressed) {
Chris@1266 601 m_mousePressed = false;
Chris@0 602 }
Chris@0 603 }
Chris@0 604
Chris@189 605 void
Chris@189 606 AudioDial::enterEvent(QEvent *e)
Chris@189 607 {
Chris@189 608 QDial::enterEvent(e);
Chris@189 609 emit mouseEntered();
Chris@189 610 }
Chris@189 611
Chris@189 612 void
Chris@189 613 AudioDial::leaveEvent(QEvent *e)
Chris@189 614 {
Chris@189 615 QDial::enterEvent(e);
Chris@189 616 emit mouseLeft();
Chris@189 617 }
Chris@189 618