changeset 1602:a798a7b5e215

Further removal of Qt 5.6+-only APIs
author Chris Cannam
date Wed, 29 Apr 2020 14:46:37 +0100
parents 4739a1b2266f
children f12c25651f96
files widgets/AudioDial.cpp widgets/LevelPanToolButton.cpp widgets/PropertyBox.cpp widgets/PropertyBox.h widgets/Thumbwheel.cpp
diffstat 5 files changed, 35 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/widgets/AudioDial.cpp	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/AudioDial.cpp	Wed Apr 29 14:46:37 2020 +0100
@@ -117,14 +117,8 @@
         MenuTitle::addTitle(m, m_title);
     }
 
-    m->addAction(tr("&Edit..."),
-                 [=]() {
-                     edit();
-                 });
-    m->addAction(tr("&Reset to Default"),
-                 [=]() {
-                     setToDefault();
-                 });
+    m->addAction(tr("&Edit..."), this, SLOT(edit()));
+    m->addAction(tr("&Reset to Default"), this, SLOT(setToDefault()));
 
     m->popup(mapToGlobal(pos));
 }
--- a/widgets/LevelPanToolButton.cpp	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/LevelPanToolButton.cpp	Wed Apr 29 14:46:37 2020 +0100
@@ -227,10 +227,7 @@
     
     MenuTitle::addTitle(m, title);
 
-    m->addAction(tr("&Reset to Default"),
-                 [=]() {
-                     m_lpw->setToDefault();
-                 });
+    m->addAction(tr("&Reset to Default"), m_lpw, SLOT(setToDefault()));
 
     m->popup(mapToGlobal(pos));
 }
--- a/widgets/PropertyBox.cpp	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/PropertyBox.cpp	Wed Apr 29 14:46:37 2020 +0100
@@ -61,7 +61,8 @@
     m_container(container),
     m_showButton(nullptr),
     m_playButton(nullptr),
-    m_lastContextMenu(nullptr)
+    m_lastContextMenu(nullptr),
+    m_contextMenuOn(nullptr)
 {
 #ifdef DEBUG_PROPERTY_BOX
     SVDEBUG << "PropertyBox[" << this << "(\"" <<
@@ -695,26 +696,24 @@
 
     delete m_lastContextMenu;
     QMenu *m = new QMenu;
+
     m_lastContextMenu = m;
+    m_contextMenuOn = obj;
 
-    if (auto button = qobject_cast<QAbstractButton *>(obj)) {
+    if (qobject_cast<QAbstractButton *>(obj)) {
         if (value > 0) {
             MenuTitle::addTitle(m, tr("%1: On").arg(label));
         } else {
             MenuTitle::addTitle(m, tr("%1: Off").arg(label));
         }
-
-        m->addAction(tr("&Reset to Default"),
-                     [=]() {
-                         button->setChecked(deflt > 0);
-                     });
+        m->addAction(tr("&Reset to Default"), this,
+                     SLOT(propertyControllerResetRequested()));
 
     } else if (auto cb = qobject_cast<QComboBox *>(obj)) {
         MenuTitle::addTitle(m, tr("%1: %2").arg(label).arg(cb->itemText(value)));
-        m->addAction(tr("&Reset to Default"),
-                     [=]() {
-                         cb->setCurrentIndex(deflt);
-                     });
+        m->addAction(tr("&Reset to Default"), this,
+                     SLOT(propertyControllerResetRequested()));
+
     } else {
         // AudioDial has its own context menu, we don't handle it here
         return;
@@ -724,6 +723,24 @@
 }
 
 void
+PropertyBox::propertyControllerResetRequested()
+{
+    if (!m_contextMenuOn) return;
+    
+    QString name = m_contextMenuOn->objectName();
+    
+    QString label = m_container->getPropertyLabel(name);
+    int min = 0, max = 0, value = 0, deflt = 0;
+    value = m_container->getPropertyRangeAndValue(name, &min, &max, &deflt);
+    
+    if (auto button = qobject_cast<QAbstractButton *>(m_contextMenuOn)) {
+        button->setChecked(deflt > 0);
+    } else if (auto cb = qobject_cast<QComboBox *>(m_contextMenuOn)) {
+        cb->setCurrentIndex(deflt);
+    }
+}
+
+void
 PropertyBox::playAudibleChanged(bool audible)
 {
     m_playButton->setChecked(audible);
--- a/widgets/PropertyBox.h	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/PropertyBox.h	Wed Apr 29 14:46:37 2020 +0100
@@ -54,6 +54,7 @@
 protected slots:
     void propertyControllerChanged(int);
     void propertyControllerChanged(bool);
+    void propertyControllerResetRequested();
 
     void playAudibleChanged(bool);
     void playAudibleButtonChanged(bool);
@@ -85,6 +86,7 @@
     LEDButton *m_showButton;
     QToolButton *m_playButton;
     QMenu *m_lastContextMenu;
+    QObject *m_contextMenuOn;
     std::map<QString, QGridLayout *> m_groupLayouts;
     std::map<QString, QWidget *> m_propertyControllers;
 };
--- a/widgets/Thumbwheel.cpp	Wed Apr 29 14:23:51 2020 +0100
+++ b/widgets/Thumbwheel.cpp	Wed Apr 29 14:46:37 2020 +0100
@@ -81,14 +81,8 @@
         MenuTitle::addTitle(m, m_title);
     }
 
-    m->addAction(tr("&Edit..."),
-                 [=]() {
-                     edit();
-                 });
-    m->addAction(tr("&Reset to Default"),
-                 [=]() {
-                     resetToDefault();
-                 });
+    m->addAction(tr("&Edit..."), this, SLOT(edit()));
+    m->addAction(tr("&Reset to Default"), this, SLOT(resetToDefault()));
 
     m->popup(mapToGlobal(pos));
 }