| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "customelements.h" |
| 7 |
|
| 8 |
#include <avogadro/qtgui/customelementdialog.h> |
| 9 |
#include <avogadro/qtgui/molecule.h> |
| 10 |
|
| 11 |
#include <QAction> |
| 12 |
|
| 13 |
using Avogadro::QtGui::Molecule; |
| 14 |
|
| 15 |
namespace Avogadro::QtPlugins { |
| 16 |
|
| 17 |
CustomElements::CustomElements(QObject* parent_) |
| 18 |
: Avogadro::QtGui::ExtensionPlugin(parent_), m_molecule(nullptr), |
| 19 |
m_reassignAction(new QAction(tr("Reassign &Custom Elements…"), this)) |
| 20 |
{ |
| 21 |
connect(m_reassignAction, SIGNAL(triggered()), SLOT(reassign())); |
| 22 |
|
| 23 |
updateReassignAction(); |
| 24 |
} |
| 25 |
|
| 26 |
CustomElements::~CustomElements() {} |
| 27 |
|
| 28 |
QString CustomElements::description() const |
| 29 |
{ |
| 30 |
return tr("Manipulate custom element types in the current molecule."); |
| 31 |
} |
| 32 |
|
| 33 |
QList<QAction*> CustomElements::actions() const |
| 34 |
{ |
| 35 |
return QList<QAction*>() << m_reassignAction; |
| 36 |
} |
| 37 |
|
| 38 |
QStringList CustomElements::menuPath(QAction*) const |
| 39 |
{ |
| 40 |
return QStringList() << tr("&Build"); |
| 41 |
} |
| 42 |
|
| 43 |
void CustomElements::setMolecule(QtGui::Molecule* mol) |
| 44 |
{ |
| 45 |
if (m_molecule != mol) { |
| 46 |
if (m_molecule) |
| 47 |
m_molecule->disconnect(this); |
| 48 |
|
| 49 |
m_molecule = mol; |
| 50 |
|
| 51 |
if (m_molecule) |
| 52 |
connect(m_molecule, SIGNAL(changed(uint)), SLOT(moleculeChanged(uint))); |
| 53 |
|
| 54 |
updateReassignAction(); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
void CustomElements::moleculeChanged(unsigned int c) |
| 59 |
{ |
| 60 |
auto changes = static_cast<Molecule::MoleculeChanges>(c); |
| 61 |
if (changes & Molecule::Atoms && |
| 62 |
(changes & (Molecule::Added | Molecule::Modified))) { |
| 63 |
updateReassignAction(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
void CustomElements::reassign() |
| 68 |
{ |
| 69 |
if (m_molecule) { |
| 70 |
QtGui::CustomElementDialog::resolve(qobject_cast<QWidget*>(parent()), |
| 71 |
*m_molecule); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
void CustomElements::updateReassignAction() |
| 76 |
{ |
| 77 |
m_reassignAction->setEnabled(m_molecule && m_molecule->hasCustomElements()); |
| 78 |
} |
| 79 |
|
| 80 |
} // namespace Avogadro::QtPlugins |