diff --git a/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp b/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp index 2198c02ad1..42d72b17e7 100644 --- a/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp +++ b/avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp @@ -8,10 +8,10 @@ #include "histogramwidget.h" #include +#include #include #include #include -#include #include #include @@ -84,6 +84,18 @@ QStringList ColorOpacityMap::menuPath(QAction*) const return QStringList() << tr("&Extensions"); } +void ColorOpacityMap::setActiveWidget(QWidget* widget) +{ + auto vtkWidget = qobject_cast(widget); + if (vtkWidget) { + m_vtkWidget = true; + updateActions(); + } else { + m_vtkWidget = false; + updateActions(); + } +} + void ColorOpacityMap::setMolecule(QtGui::Molecule* mol) { if (m_molecule == mol) @@ -114,9 +126,8 @@ void ColorOpacityMap::moleculeChanged(unsigned int c) void ColorOpacityMap::updateActions() { - // Just leave it enabled, if you click on it it will be empty... foreach (QAction* action, m_actions) - action->setEnabled(true); + action->setEnabled(m_vtkWidget); } void ColorOpacityMap::updateHistogram() @@ -124,6 +135,9 @@ void ColorOpacityMap::updateHistogram() auto widget = ActiveObjects::instance().activeWidget(); auto vtkWidget = qobject_cast(widget); + if (vtkWidget == nullptr) + m_vtkWidget = false; + if (widget && vtkWidget && widget != m_activeWidget) { if (m_activeWidget) disconnect(widget, nullptr, this, nullptr); @@ -132,6 +146,7 @@ void ColorOpacityMap::updateHistogram() } if (vtkWidget && m_molecule && m_molecule->cubeCount()) { + m_vtkWidget = true; vtkNew table; auto imageData = vtkWidget->imageData(); auto lut = vtkWidget->lut(); diff --git a/avogadro/qtplugins/coloropacitymap/coloropacitymap.h b/avogadro/qtplugins/coloropacitymap/coloropacitymap.h index 725fe6c326..463fc59f60 100644 --- a/avogadro/qtplugins/coloropacitymap/coloropacitymap.h +++ b/avogadro/qtplugins/coloropacitymap/coloropacitymap.h @@ -31,6 +31,8 @@ public slots: void moleculeChanged(unsigned int changes); + void setActiveWidget(QWidget* widget) override; + private slots: void updateActions(); @@ -48,6 +50,7 @@ private slots: HistogramWidget* m_histogramWidget = nullptr; QScopedPointer m_displayDialogAction; + bool m_vtkWidget = false; QWidget* m_activeWidget = nullptr; };