| 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 "vibrationdialog.h" |
| 7 |
|
| 8 |
#include "ui_vibrationdialog.h" |
| 9 |
#include "vibrationmodel.h" |
| 10 |
|
| 11 |
#include <avogadro/core/molecule.h> |
| 12 |
|
| 13 |
namespace Avogadro::QtPlugins { |
| 14 |
|
| 15 |
VibrationDialog::VibrationDialog(QWidget* parent_, Qt::WindowFlags f) |
| 16 |
: QDialog(parent_, f), m_ui(new Ui::VibrationDialog) |
| 17 |
{ |
| 18 |
m_ui->setupUi(this); |
| 19 |
|
| 20 |
m_ui->tableView->verticalHeader()->setVisible(true); |
| 21 |
m_ui->tableView->horizontalHeader()->setSectionResizeMode( |
| 22 |
QHeaderView::Stretch); |
| 23 |
m_ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows); |
| 24 |
m_ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection); |
| 25 |
|
| 26 |
connect(m_ui->amplitudeSlider, SIGNAL(sliderMoved(int)), |
| 27 |
SIGNAL(amplitudeChanged(int))); |
| 28 |
connect(m_ui->startButton, SIGNAL(clicked(bool)), this, |
| 29 |
SLOT(changeAnimation())); |
| 30 |
} |
| 31 |
|
| 32 |
VibrationDialog::~VibrationDialog() |
| 33 |
{ |
| 34 |
delete m_ui; |
| 35 |
} |
| 36 |
|
| 37 |
void VibrationDialog::changeAnimation() |
| 38 |
{ |
| 39 |
const QString start = tr("Start Animation"); |
| 40 |
const QString stop = tr("Stop Animation"); |
| 41 |
|
| 42 |
if (m_ui->startButton->text() == start) { |
| 43 |
m_ui->startButton->setText(stop); |
| 44 |
m_ui->startButton->setIcon(QIcon::fromTheme("media-playback-pause")); |
| 45 |
emit startAnimation(); |
| 46 |
} else { |
| 47 |
m_ui->startButton->setText(start); |
| 48 |
m_ui->startButton->setIcon(QIcon::fromTheme("media-playback-start")); |
| 49 |
emit stopAnimation(); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
void VibrationDialog::setMolecule(QtGui::Molecule* molecule) |
| 54 |
{ |
| 55 |
if (m_ui->tableView->selectionModel()) { |
| 56 |
disconnect(m_ui->tableView->selectionModel(), |
| 57 |
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), this, |
| 58 |
SLOT(selectRow(QModelIndex))); |
| 59 |
} |
| 60 |
|
| 61 |
auto* model = new VibrationModel(this); |
| 62 |
model->setMolecule(molecule); |
| 63 |
m_ui->tableView->setModel(model); |
| 64 |
connect(m_ui->tableView->selectionModel(), |
| 65 |
SIGNAL(currentRowChanged(QModelIndex, QModelIndex)), |
| 66 |
SLOT(selectRow(QModelIndex))); |
| 67 |
|
| 68 |
Core::Array<double> freqs = molecule->vibrationFrequencies(); |
| 69 |
for (size_t i = 0; i < freqs.size(); ++i) { |
| 70 |
if (freqs[i] > 0.5) { |
| 71 |
m_ui->tableView->selectRow(static_cast<int>(i)); |
| 72 |
emit modeChanged(i); |
| 73 |
break; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
int VibrationDialog::currentMode() const |
| 79 |
{ |
| 80 |
return m_ui->tableView->currentIndex().row(); |
| 81 |
} |
| 82 |
|
| 83 |
void VibrationDialog::selectRow(QModelIndex idx) |
| 84 |
{ |
| 85 |
emit modeChanged(idx.row()); |
| 86 |
} |
| 87 |
|
| 88 |
} // namespace Avogadro::QtPlugins |