Mercurial > hg > svgui
comparison widgets/PropertyBox.cpp @ 1587:2108af725460
Add context menus to property box controls
author | Chris Cannam |
---|---|
date | Fri, 27 Mar 2020 14:36:11 +0000 |
parents | 284a38c43721 |
children | 26e80a450e74 |
comparison
equal
deleted
inserted
replaced
1586:bbc3f537564c | 1587:2108af725460 |
---|---|
27 #include "LEDButton.h" | 27 #include "LEDButton.h" |
28 #include "IconLoader.h" | 28 #include "IconLoader.h" |
29 #include "LevelPanWidget.h" | 29 #include "LevelPanWidget.h" |
30 #include "LevelPanToolButton.h" | 30 #include "LevelPanToolButton.h" |
31 #include "WidgetScale.h" | 31 #include "WidgetScale.h" |
32 #include "MenuTitle.h" | |
32 | 33 |
33 #include "NotifyingCheckBox.h" | 34 #include "NotifyingCheckBox.h" |
34 #include "NotifyingComboBox.h" | 35 #include "NotifyingComboBox.h" |
35 #include "NotifyingPushButton.h" | 36 #include "NotifyingPushButton.h" |
36 #include "NotifyingToolButton.h" | 37 #include "NotifyingToolButton.h" |
46 #include <QFrame> | 47 #include <QFrame> |
47 #include <QApplication> | 48 #include <QApplication> |
48 #include <QColorDialog> | 49 #include <QColorDialog> |
49 #include <QInputDialog> | 50 #include <QInputDialog> |
50 #include <QDir> | 51 #include <QDir> |
52 #include <QMenu> | |
51 | 53 |
52 #include <cassert> | 54 #include <cassert> |
53 #include <iostream> | 55 #include <iostream> |
54 #include <cmath> | 56 #include <cmath> |
55 | 57 |
56 //#define DEBUG_PROPERTY_BOX 1 | 58 //#define DEBUG_PROPERTY_BOX 1 |
57 | 59 |
58 PropertyBox::PropertyBox(PropertyContainer *container) : | 60 PropertyBox::PropertyBox(PropertyContainer *container) : |
59 m_container(container), | 61 m_container(container), |
60 m_showButton(nullptr), | 62 m_showButton(nullptr), |
61 m_playButton(nullptr) | 63 m_playButton(nullptr), |
64 m_lastContextMenu(nullptr) | |
62 { | 65 { |
63 #ifdef DEBUG_PROPERTY_BOX | 66 #ifdef DEBUG_PROPERTY_BOX |
64 SVDEBUG << "PropertyBox[" << this << "(\"" << | 67 SVDEBUG << "PropertyBox[" << this << "(\"" << |
65 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl; | 68 container->getPropertyContainerName() << "\" at " << container << ")]::PropertyBox" << endl; |
66 #endif | 69 #endif |
116 PropertyBox::~PropertyBox() | 119 PropertyBox::~PropertyBox() |
117 { | 120 { |
118 #ifdef DEBUG_PROPERTY_BOX | 121 #ifdef DEBUG_PROPERTY_BOX |
119 SVDEBUG << "PropertyBox[" << this << "]::~PropertyBox" << endl; | 122 SVDEBUG << "PropertyBox[" << this << "]::~PropertyBox" << endl; |
120 #endif | 123 #endif |
124 delete m_lastContextMenu; | |
121 } | 125 } |
122 | 126 |
123 void | 127 void |
124 PropertyBox::populateViewPlayFrame() | 128 PropertyBox::populateViewPlayFrame() |
125 { | 129 { |
325 connect(button, SIGNAL(mouseEntered()), | 329 connect(button, SIGNAL(mouseEntered()), |
326 this, SLOT(mouseEnteredWidget())); | 330 this, SLOT(mouseEnteredWidget())); |
327 connect(button, SIGNAL(mouseLeft()), | 331 connect(button, SIGNAL(mouseLeft()), |
328 this, SLOT(mouseLeftWidget())); | 332 this, SLOT(mouseLeftWidget())); |
329 button->setToolTip(propertyLabel); | 333 button->setToolTip(propertyLabel); |
334 | |
335 button->setContextMenuPolicy(Qt::CustomContextMenu); | |
336 connect(button, SIGNAL(customContextMenuRequested(const QPoint &)), | |
337 this, SLOT(contextMenuRequested(const QPoint &))); | |
330 | 338 |
331 if (existing) { | 339 if (existing) { |
332 groupLayout->replaceWidget(existing, button); | 340 groupLayout->replaceWidget(existing, button); |
333 delete existing; | 341 delete existing; |
334 } else { | 342 } else { |
420 connect(cb, SIGNAL(mouseLeft()), | 428 connect(cb, SIGNAL(mouseLeft()), |
421 this, SLOT(mouseLeftWidget())); | 429 this, SLOT(mouseLeftWidget())); |
422 | 430 |
423 cb->setToolTip(propertyLabel); | 431 cb->setToolTip(propertyLabel); |
424 | 432 |
433 cb->setContextMenuPolicy(Qt::CustomContextMenu); | |
434 connect(cb, SIGNAL(customContextMenuRequested(const QPoint &)), | |
435 this, SLOT(contextMenuRequested(const QPoint &))); | |
436 | |
425 if (existing) { | 437 if (existing) { |
426 groupLayout->replaceWidget(existing, cb); | 438 groupLayout->replaceWidget(existing, cb); |
427 delete existing; | 439 delete existing; |
428 } else { | 440 } else { |
429 groupLayout->addWidget(cb, 0, groupLayout->columnCount()); | 441 groupLayout->addWidget(cb, 0, groupLayout->columnCount()); |
533 this, SLOT(mouseEnteredWidget())); | 545 this, SLOT(mouseEnteredWidget())); |
534 connect(cb, SIGNAL(mouseLeft()), | 546 connect(cb, SIGNAL(mouseLeft()), |
535 this, SLOT(mouseLeftWidget())); | 547 this, SLOT(mouseLeftWidget())); |
536 | 548 |
537 cb->setToolTip(propertyLabel); | 549 cb->setToolTip(propertyLabel); |
550 | |
551 cb->setContextMenuPolicy(Qt::CustomContextMenu); | |
552 connect(cb, SIGNAL(customContextMenuRequested(const QPoint &)), | |
553 this, SLOT(contextMenuRequested(const QPoint &))); | |
554 | |
538 groupLayout->addWidget(cb, 0, groupLayout->columnCount()); | 555 groupLayout->addWidget(cb, 0, groupLayout->columnCount()); |
539 m_propertyControllers[name] = cb; | 556 m_propertyControllers[name] = cb; |
540 } else if (existing != cb) { | 557 } else if (existing != cb) { |
541 groupLayout->replaceWidget(existing, cb); | 558 groupLayout->replaceWidget(existing, cb); |
542 delete existing; | 559 delete existing; |
665 | 682 |
666 updateContextHelp(obj); | 683 updateContextHelp(obj); |
667 } | 684 } |
668 | 685 |
669 void | 686 void |
687 PropertyBox::contextMenuRequested(const QPoint &pos) | |
688 { | |
689 QObject *obj = sender(); | |
690 QString name = obj->objectName(); | |
691 | |
692 PropertyContainer::PropertyType type = m_container->getPropertyType(name); | |
693 QString label = m_container->getPropertyLabel(name); | |
694 int min = 0, max = 0, value = 0, deflt = 0; | |
695 value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt); | |
696 | |
697 delete m_lastContextMenu; | |
698 QMenu *m = new QMenu; | |
699 m_lastContextMenu = m; | |
700 | |
701 if (auto button = qobject_cast<QAbstractButton *>(obj)) { | |
702 if (value > 0) { | |
703 MenuTitle::addTitle(m, tr("%1: On").arg(label)); | |
704 } else { | |
705 MenuTitle::addTitle(m, tr("%1: Off").arg(label)); | |
706 } | |
707 | |
708 m->addAction(tr("&Reset to Default"), | |
709 [=]() { | |
710 button->setChecked(deflt > 0); | |
711 }); | |
712 | |
713 } else if (auto cb = qobject_cast<QComboBox *>(obj)) { | |
714 MenuTitle::addTitle(m, tr("%1: %2").arg(label).arg(cb->itemText(value))); | |
715 m->addAction(tr("&Reset to Default"), | |
716 [=]() { | |
717 cb->setCurrentIndex(deflt); | |
718 }); | |
719 } else { | |
720 // AudioDial has its own context menu, we don't handle it here | |
721 return; | |
722 } | |
723 | |
724 m->popup(qobject_cast<QWidget *>(sender())->mapToGlobal(pos)); | |
725 } | |
726 | |
727 void | |
670 PropertyBox::playAudibleChanged(bool audible) | 728 PropertyBox::playAudibleChanged(bool audible) |
671 { | 729 { |
672 m_playButton->setChecked(audible); | 730 m_playButton->setChecked(audible); |
673 } | 731 } |
674 | 732 |