Skip to content

Commit

Permalink
Turn off Color Opacity Map unless a VTK widget is active
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Dec 7, 2023
1 parent d1f1560 commit 6b290e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
21 changes: 18 additions & 3 deletions avogadro/qtplugins/coloropacitymap/coloropacitymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include "histogramwidget.h"

#include <QAction>
#include <QDebug>
#include <QDialog>
#include <QMessageBox>
#include <QString>
#include <QDebug>

#include <avogadro/core/crystaltools.h>
#include <avogadro/core/cube.h>
Expand Down Expand Up @@ -84,6 +84,18 @@ QStringList ColorOpacityMap::menuPath(QAction*) const
return QStringList() << tr("&Extensions");
}

void ColorOpacityMap::setActiveWidget(QWidget* widget)
{
auto vtkWidget = qobject_cast<VTK::vtkGLWidget*>(widget);
if (vtkWidget) {
m_vtkWidget = true;
updateActions();
} else {
m_vtkWidget = false;
updateActions();
}
}

void ColorOpacityMap::setMolecule(QtGui::Molecule* mol)
{
if (m_molecule == mol)
Expand Down Expand Up @@ -114,16 +126,18 @@ 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()
{
auto widget = ActiveObjects::instance().activeWidget();
auto vtkWidget = qobject_cast<VTK::vtkGLWidget*>(widget);

if (vtkWidget == nullptr)
m_vtkWidget = false;

if (widget && vtkWidget && widget != m_activeWidget) {
if (m_activeWidget)
disconnect(widget, nullptr, this, nullptr);
Expand All @@ -132,6 +146,7 @@ void ColorOpacityMap::updateHistogram()
}

if (vtkWidget && m_molecule && m_molecule->cubeCount()) {
m_vtkWidget = true;
vtkNew<vtkTable> table;
auto imageData = vtkWidget->imageData();
auto lut = vtkWidget->lut();
Expand Down
3 changes: 3 additions & 0 deletions avogadro/qtplugins/coloropacitymap/coloropacitymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public slots:

void moleculeChanged(unsigned int changes);

void setActiveWidget(QWidget* widget) override;

private slots:
void updateActions();

Expand All @@ -48,6 +50,7 @@ private slots:
HistogramWidget* m_histogramWidget = nullptr;
QScopedPointer<QAction> m_displayDialogAction;

bool m_vtkWidget = false;
QWidget* m_activeWidget = nullptr;
};

Expand Down

0 comments on commit 6b290e3

Please sign in to comment.