annotate widgets/AudioDial.cpp @ 1513:0586e6492785 time-frequency-boxes

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