| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <QDir>
|
| | #include <QFile>
|
| | #include <QFileInfo>
|
| | #include <QMessageBox>
|
| |
|
| | #include "Dialogs/DlgMacroRecordImp.h"
|
| | #include "ui_DlgMacroRecord.h"
|
| | #include "Application.h"
|
| | #include "FileDialog.h"
|
| | #include "Macro.h"
|
| | #include "MainWindow.h"
|
| |
|
| |
|
| | using namespace Gui::Dialog;
|
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | DlgMacroRecordImp::DlgMacroRecordImp(QWidget* parent, Qt::WindowFlags fl)
|
| | : QDialog(parent, fl)
|
| | , WindowParameter("Macro")
|
| | , ui(new Ui_DlgMacroRecord)
|
| | {
|
| | ui->setupUi(this);
|
| | setupConnections();
|
| |
|
| |
|
| | this->macroPath = QString::fromUtf8(
|
| | getWindowParameter()->GetASCII("MacroPath", App::Application::getUserMacroDir().c_str()).c_str()
|
| | );
|
| | this->macroPath = QDir::toNativeSeparators(QDir(this->macroPath).path() + QDir::separator());
|
| |
|
| |
|
| | ui->lineEditMacroPath->setText(macroPath);
|
| |
|
| |
|
| | this->macroManager = Application::Instance->macroManager();
|
| |
|
| |
|
| | this->macroManager->isOpen() ? ui->buttonStart->setEnabled(false)
|
| | : ui->buttonStop->setEnabled(false);
|
| | }
|
| |
|
| | |
| | |
| |
|
| | DlgMacroRecordImp::~DlgMacroRecordImp() = default;
|
| |
|
| | void DlgMacroRecordImp::setupConnections()
|
| | {
|
| |
|
| | connect(ui->buttonStart, &QPushButton::clicked,
|
| | this, &DlgMacroRecordImp::onButtonStartClicked);
|
| | connect(ui->buttonStop, &QPushButton::clicked,
|
| | this, &DlgMacroRecordImp::onButtonStopClicked);
|
| | connect(ui->buttonClose, &QPushButton::clicked,
|
| | this, &DlgMacroRecordImp::onButtonCloseClicked);
|
| | connect(ui->pushButtonChooseDir, &QPushButton::clicked,
|
| | this, &DlgMacroRecordImp::onButtonChooseDirClicked);
|
| | connect(ui->lineEditMacroPath, &QLineEdit::textChanged,
|
| | this, &DlgMacroRecordImp::onMacroPathTextChanged);
|
| |
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroRecordImp::onButtonStartClicked()
|
| | {
|
| |
|
| | if (ui->lineEditPath->text().isEmpty()) {
|
| | QMessageBox::information(
|
| | getMainWindow(),
|
| | tr("Macro recorder"),
|
| | tr("Specify a place to save first.")
|
| | );
|
| | return;
|
| | }
|
| |
|
| | QDir dir(macroPath);
|
| | if (!dir.exists()) {
|
| | QMessageBox::information(
|
| | getMainWindow(),
|
| | tr("Macro recorder"),
|
| | tr("The macro directory does not exist. Choose another one.")
|
| | );
|
| | return;
|
| | }
|
| |
|
| |
|
| | QString fn = this->macroPath + ui->lineEditPath->text();
|
| | if (!fn.endsWith(QLatin1String(".FCMacro"))) {
|
| | fn += QLatin1String(".FCMacro");
|
| | }
|
| |
|
| | QFileInfo fi(fn);
|
| | if (fi.isFile() && fi.exists()) {
|
| | if (QMessageBox::question(
|
| | this,
|
| | tr("Existing macro"),
|
| | tr("The macro '%1' already exists. Overwrite it?").arg(fn),
|
| | QMessageBox::Yes | QMessageBox::No,
|
| | QMessageBox::No
|
| | )
|
| | == QMessageBox::No) {
|
| | return;
|
| | }
|
| | }
|
| |
|
| | QFile file(fn);
|
| | if (!file.open(QFile::WriteOnly)) {
|
| | QMessageBox::information(
|
| | getMainWindow(),
|
| | tr("Macro recorder"),
|
| | tr("You have no write permission for the directory. Choose another one.")
|
| | );
|
| | return;
|
| | }
|
| | file.close();
|
| |
|
| |
|
| | this->macroManager->open(MacroManager::File, fn.toUtf8().constData());
|
| |
|
| | ui->buttonStart->setEnabled(false);
|
| | ui->buttonStop->setEnabled(true);
|
| | ui->buttonClose->setEnabled(false);
|
| | QDialog::accept();
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroRecordImp::onButtonCloseClicked()
|
| | {
|
| | if (this->macroManager->isOpen()) {
|
| | this->macroManager->cancel();
|
| | }
|
| |
|
| | QDialog::reject();
|
| | }
|
| |
|
| | |
| | |
| |
|
| | void DlgMacroRecordImp::onButtonStopClicked()
|
| | {
|
| | if (this->macroManager->isOpen()) {
|
| |
|
| | this->macroManager->commit();
|
| | }
|
| |
|
| | ui->buttonStart->setEnabled(true);
|
| | ui->buttonStop->setEnabled(false);
|
| | ui->buttonClose->setEnabled(true);
|
| | QDialog::accept();
|
| | }
|
| |
|
| | void DlgMacroRecordImp::onButtonChooseDirClicked()
|
| | {
|
| | QString newDir
|
| | = QFileDialog::getExistingDirectory(nullptr, tr("Choose macro directory"), macroPath);
|
| | if (!newDir.isEmpty()) {
|
| | macroPath = QDir::toNativeSeparators(newDir + QDir::separator());
|
| | ui->lineEditMacroPath->setText(macroPath);
|
| | getWindowParameter()->SetASCII("MacroPath", macroPath.toUtf8());
|
| | }
|
| | }
|
| |
|
| | void DlgMacroRecordImp::onMacroPathTextChanged(const QString& newDir)
|
| | {
|
| | macroPath = newDir;
|
| | }
|
| |
|
| |
|
| | #include "moc_DlgMacroRecordImp.cpp"
|
| |
|