| 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 "constraintsextension.h" |
| 7 |
#include "constraintsdialog.h" |
| 8 |
#include "constraintsmodel.h" |
| 9 |
|
| 10 |
#include <QAction> |
| 11 |
#include <QDebug> |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <iostream> |
| 15 |
|
| 16 |
namespace Avogadro { |
| 17 |
namespace QtPlugins { |
| 18 |
ConstraintsExtension::ConstraintsExtension(QObject* p) : ExtensionPlugin(p) |
| 19 |
{ |
| 20 |
QAction* action = new QAction(this); |
| 21 |
action->setEnabled(true); |
| 22 |
action->setText(tr("Constraints…")); |
| 23 |
connect(action, SIGNAL(triggered()), SLOT(openDialog())); |
| 24 |
m_actions.push_back(action); |
| 25 |
} |
| 26 |
|
| 27 |
ConstraintsExtension::~ConstraintsExtension() |
| 28 |
{ |
| 29 |
if (m_dialog) |
| 30 |
m_dialog->deleteLater(); |
| 31 |
} |
| 32 |
|
| 33 |
QList<QAction*> ConstraintsExtension::actions() const |
| 34 |
{ |
| 35 |
return m_actions; |
| 36 |
} |
| 37 |
|
| 38 |
QStringList ConstraintsExtension::menuPath(QAction*) const |
| 39 |
{ |
| 40 |
return QStringList() << tr("&Extensions") << tr("&Calculate"); |
| 41 |
} |
| 42 |
|
| 43 |
void ConstraintsExtension::openDialog() |
| 44 |
{ |
| 45 |
if (m_dialog == nullptr) { |
| 46 |
m_dialog = new ConstraintsDialog(qobject_cast<QWidget*>(parent())); |
| 47 |
} |
| 48 |
|
| 49 |
// update the constraints before we show the dialog |
| 50 |
if (m_molecule != nullptr) |
| 51 |
m_dialog->setMolecule(m_molecule); |
| 52 |
|
| 53 |
m_dialog->updateConstraints(); |
| 54 |
|
| 55 |
m_dialog->show(); |
| 56 |
m_dialog->raise(); |
| 57 |
m_dialog->activateWindow(); |
| 58 |
} |
| 59 |
|
| 60 |
void ConstraintsExtension::setMolecule(QtGui::Molecule* mol) |
| 61 |
{ |
| 62 |
if (mol != m_molecule) { |
| 63 |
m_molecule = mol; |
| 64 |
} |
| 65 |
|
| 66 |
if (m_dialog != nullptr) |
| 67 |
m_dialog->setMolecule(mol); |
| 68 |
} |
| 69 |
|
| 70 |
} // namespace QtPlugins |
| 71 |
} // namespace Avogadro |