comparison widgets/PropertyBox.cpp @ 218:21a5e4e7cb92

* Add current value to context help for dials in property boxes, and update the text when the value is changed
author Chris Cannam
date Mon, 05 Mar 2007 12:00:32 +0000
parents 34bbbcb3c01f
children e6d0b097d102
comparison
equal deleted inserted replaced
217:bd2d0346da0e 218:21a5e4e7cb92
36 #include <QHBoxLayout> 36 #include <QHBoxLayout>
37 #include <QVBoxLayout> 37 #include <QVBoxLayout>
38 #include <QPushButton> 38 #include <QPushButton>
39 #include <QLabel> 39 #include <QLabel>
40 #include <QFrame> 40 #include <QFrame>
41 #include <QApplication>
41 42
42 #include <cassert> 43 #include <cassert>
43 #include <iostream> 44 #include <iostream>
44 #include <cmath> 45 #include <cmath>
45 46
546 (name, UnitDatabase::getInstance()->getUnitId(unit)); 547 (name, UnitDatabase::getInstance()->getUnitId(unit));
547 } 548 }
548 } else if (type != PropertyContainer::InvalidProperty) { 549 } else if (type != PropertyContainer::InvalidProperty) {
549 m_container->setPropertyWithCommand(name, value); 550 m_container->setPropertyWithCommand(name, value);
550 } 551 }
552
553 updateContextHelp(obj);
551 } 554 }
552 555
553 void 556 void
554 PropertyBox::playGainChanged(float gain) 557 PropertyBox::playGainChanged(float gain)
555 { 558 {
560 } 563 }
561 564
562 void 565 void
563 PropertyBox::playGainDialChanged(int dialValue) 566 PropertyBox::playGainDialChanged(int dialValue)
564 { 567 {
568 QObject *obj = sender();
565 float gain = pow(10, float(dialValue) / 20.0); 569 float gain = pow(10, float(dialValue) / 20.0);
566 emit changePlayGain(gain); 570 emit changePlayGain(gain);
571 updateContextHelp(obj);
567 } 572 }
568 573
569 void 574 void
570 PropertyBox::playPanChanged(float pan) 575 PropertyBox::playPanChanged(float pan)
571 { 576 {
576 } 581 }
577 582
578 void 583 void
579 PropertyBox::playPanDialChanged(int dialValue) 584 PropertyBox::playPanDialChanged(int dialValue)
580 { 585 {
586 QObject *obj = sender();
581 float pan = float(dialValue) / 50.0; 587 float pan = float(dialValue) / 50.0;
582 if (pan < -1.0) pan = -1.0; 588 if (pan < -1.0) pan = -1.0;
583 if (pan > 1.0) pan = 1.0; 589 if (pan > 1.0) pan = 1.0;
584 emit changePlayPan(pan); 590 emit changePlayPan(pan);
591 updateContextHelp(obj);
585 } 592 }
586 593
587 void 594 void
588 PropertyBox::editPlugin() 595 PropertyBox::editPlugin()
589 { 596 {
637 } 644 }
638 645
639 void 646 void
640 PropertyBox::mouseEnteredWidget() 647 PropertyBox::mouseEnteredWidget()
641 { 648 {
642 QWidget *w = dynamic_cast<QWidget *>(sender()); 649 updateContextHelp(sender());
650 }
651
652 void
653 PropertyBox::updateContextHelp(QObject *o)
654 {
655 QWidget *w = dynamic_cast<QWidget *>(o);
643 if (!w) return; 656 if (!w) return;
644 657
645 if (!m_container) return; 658 if (!m_container) return;
646 QString cname = m_container->getPropertyContainerName(); 659 QString cname = m_container->getPropertyContainerName();
647 if (cname == "") return; 660 if (cname == "") return;
648 661
649 QString wname = w->objectName(); 662 QString wname = w->objectName();
663
664 QString extraText;
665 AudioDial *dial = dynamic_cast<AudioDial *>(w);
666 if (dial) {
667 float mv = dial->mappedValue();
668 QString unit = "";
669 if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit();
670 if (unit != "") {
671 extraText = tr(" (current value: %1%2)").arg(mv).arg(unit);
672 } else {
673 extraText = tr(" (current value: %1)").arg(mv);
674 }
675 }
650 676
651 if (w == m_showButton) { 677 if (w == m_showButton) {
652 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname)); 678 emit contextHelpChanged(tr("Toggle Visibility of %1").arg(cname));
653 } else if (w == m_playButton) { 679 } else if (w == m_playButton) {
654 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname)); 680 emit contextHelpChanged(tr("Toggle Playback of %1").arg(cname));
656 return; 682 return;
657 } else if (dynamic_cast<NotifyingCheckBox *>(w)) { 683 } else if (dynamic_cast<NotifyingCheckBox *>(w)) {
658 emit contextHelpChanged(tr("Toggle %1 property of %2") 684 emit contextHelpChanged(tr("Toggle %1 property of %2")
659 .arg(wname).arg(cname)); 685 .arg(wname).arg(cname));
660 } else { 686 } else {
661 emit contextHelpChanged(tr("Adjust %1 property of %2") 687 emit contextHelpChanged(tr("Adjust %1 property of %2%3")
662 .arg(wname).arg(cname)); 688 .arg(wname).arg(cname).arg(extraText));
663 } 689 }
664 } 690 }
665 691
666 void 692 void
667 PropertyBox::mouseLeftWidget() 693 PropertyBox::mouseLeftWidget()
668 { 694 {
669 emit contextHelpChanged(""); 695 if (!(QApplication::mouseButtons() & Qt::LeftButton)) {
670 } 696 emit contextHelpChanged("");
671 697 }
672 698 }
699
700