| 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 "hydrogens.h" |
| 7 |
|
| 8 |
#include <avogadro/qtgui/hydrogentools.h> |
| 9 |
#include <avogadro/qtgui/molecule.h> |
| 10 |
|
| 11 |
#include <QtGui/QKeySequence> |
| 12 |
#include <QAction> |
| 13 |
|
| 14 |
#include <QtCore/QStringList> |
| 15 |
|
| 16 |
namespace Avogadro::QtPlugins { |
| 17 |
|
| 18 |
Hydrogens::Hydrogens(QObject* parent_) |
| 19 |
: Avogadro::QtGui::ExtensionPlugin(parent_), m_molecule(nullptr) |
| 20 |
{ |
| 21 |
auto* action = new QAction(tr("&Adjust Hydrogens"), this); |
| 22 |
action->setShortcut(QKeySequence("Ctrl+Alt+H")); |
| 23 |
action->setProperty("menu priority", 760); |
| 24 |
connect(action, SIGNAL(triggered()), SLOT(adjustHydrogens())); |
| 25 |
m_actions.append(action); |
| 26 |
|
| 27 |
action = new QAction(tr("Add Hydrogens"), this); |
| 28 |
action->setProperty("menu priority", 750); |
| 29 |
connect(action, SIGNAL(triggered()), SLOT(addHydrogens())); |
| 30 |
m_actions.append(action); |
| 31 |
|
| 32 |
action = new QAction(tr("Remove E&xtra Hydrogens"), this); |
| 33 |
action->setProperty("menu priority", 740); |
| 34 |
connect(action, SIGNAL(triggered()), SLOT(removeHydrogens())); |
| 35 |
m_actions.append(action); |
| 36 |
|
| 37 |
action = new QAction(tr("&Remove All Hydrogens"), this); |
| 38 |
action->setProperty("menu priority", 730); |
| 39 |
connect(action, SIGNAL(triggered()), SLOT(removeAllHydrogens())); |
| 40 |
m_actions.append(action); |
| 41 |
} |
| 42 |
|
| 43 |
Hydrogens::~Hydrogens() {} |
| 44 |
|
| 45 |
QString Hydrogens::description() const |
| 46 |
{ |
| 47 |
return tr("Add/remove hydrogens from the current molecule."); |
| 48 |
} |
| 49 |
|
| 50 |
QList<QAction*> Hydrogens::actions() const |
| 51 |
{ |
| 52 |
return m_actions; |
| 53 |
} |
| 54 |
|
| 55 |
QStringList Hydrogens::menuPath(QAction*) const |
| 56 |
{ |
| 57 |
return QStringList() << tr("&Build") << tr("&Hydrogens"); |
| 58 |
} |
| 59 |
|
| 60 |
void Hydrogens::setMolecule(QtGui::Molecule* mol) |
| 61 |
{ |
| 62 |
m_molecule = mol; |
| 63 |
} |
| 64 |
|
| 65 |
void Hydrogens::adjustHydrogens() |
| 66 |
{ |
| 67 |
if (m_molecule) { |
| 68 |
QtGui::HydrogenTools::adjustHydrogens(*(m_molecule->undoMolecule()), |
| 69 |
QtGui::HydrogenTools::AddAndRemove); |
| 70 |
// Assume molecule changes... |
| 71 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Bonds | |
| 72 |
QtGui::Molecule::Added | QtGui::Molecule::Removed); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
void Hydrogens::addHydrogens() |
| 77 |
{ |
| 78 |
if (m_molecule) { |
| 79 |
QtGui::HydrogenTools::adjustHydrogens(*(m_molecule->undoMolecule()), |
| 80 |
QtGui::HydrogenTools::Add); |
| 81 |
// Assume molecule changes... |
| 82 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Bonds | |
| 83 |
QtGui::Molecule::Added); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
void Hydrogens::removeHydrogens() |
| 88 |
{ |
| 89 |
if (m_molecule) { |
| 90 |
QtGui::HydrogenTools::adjustHydrogens(*(m_molecule->undoMolecule()), |
| 91 |
QtGui::HydrogenTools::Remove); |
| 92 |
// Assume molecule changes... |
| 93 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Bonds | |
| 94 |
QtGui::Molecule::Removed); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
void Hydrogens::removeAllHydrogens() |
| 99 |
{ |
| 100 |
if (m_molecule) { |
| 101 |
QtGui::HydrogenTools::removeAllHydrogens(*(m_molecule->undoMolecule())); |
| 102 |
// Assume molecule changes... |
| 103 |
m_molecule->emitChanged(QtGui::Molecule::Atoms | QtGui::Molecule::Bonds | |
| 104 |
QtGui::Molecule::Removed); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
} // namespace Avogadro::QtPlugins |