diff --git a/src/qprojectM/qpreseteditordialog.cpp b/src/qprojectM/qpreseteditordialog.cpp index 925820d53..c30cdaeec 100644 --- a/src/qprojectM/qpreseteditordialog.cpp +++ b/src/qprojectM/qpreseteditordialog.cpp @@ -1,11 +1,13 @@ #include "qpreseteditordialog.hpp" #include #include +#include + QPresetEditorDialog::QPresetEditorDialog(QProjectMWidget * widget, QWidget * parent, Qt::WindowFlags f): QDialog(parent,f), _qprojectMWidget(widget) { _ui.setupUi(this); connect(_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(buttonBoxHandler(QAbstractButton*))); - + } void QPresetEditorDialog::setPreset(QString url, const QModelIndex & index) { @@ -18,14 +20,15 @@ void QPresetEditorDialog::setPreset(QString url, const QModelIndex & index) { _ui.presetTextEdit->loadPresetText(url); this->setWindowTitle(QString("Preset Editor - %1 [*]").arg(url)); - _ui.presetTextEdit->setWindowModified(false); + this->setWindowModified(false); connect(_ui.presetTextEdit, SIGNAL(textChanged()), this, SLOT(updateWindowTitle())); + connect(_ui.presetTextEdit, SIGNAL(applyRequested()), this, SLOT(saveAndNotify()), Qt::DirectConnection); } void QPresetEditorDialog::updateWindowTitle() { - _ui.presetTextEdit->setWindowModified(true); + this->setWindowModified(true); } const QString & QPresetEditorDialog::presetUrl() const { @@ -49,6 +52,15 @@ void QPresetEditorDialog::saveFile() { textStream << _ui.presetTextEdit->toPlainText(); textStream.flush(); + this->setWindowModified(false); +} + +void QPresetEditorDialog::saveAndNotify() { + + qDebug() << "save and notify"; + saveFile(); + + emit(presetModified(m_index)); } void QPresetEditorDialog::buttonBoxHandler(QAbstractButton * button) { @@ -57,10 +69,7 @@ void QPresetEditorDialog::buttonBoxHandler(QAbstractButton * button) { this->hide(); break; case QDialogButtonBox::Apply: - qDebug() << "pre file save"; - saveFile(); - qDebug() << "emitting preset mod"; - emit(presetModified(m_index)); + saveAndNotify(); break; case QDialogButtonBox::Reset: revertBuffer(); diff --git a/src/qprojectM/qpreseteditordialog.hpp b/src/qprojectM/qpreseteditordialog.hpp index ff92d64a3..e0a17f4ae 100644 --- a/src/qprojectM/qpreseteditordialog.hpp +++ b/src/qprojectM/qpreseteditordialog.hpp @@ -17,11 +17,15 @@ class QPresetEditorDialog : public QDialog { } signals: void presetModified(const QModelIndex &); + protected: + //void keyReleaseEvent(QKeyEvent * e); + public slots: + private slots: void buttonBoxHandler(QAbstractButton * button); void saveFile(); - + void saveAndNotify(); void updateWindowTitle(); private: diff --git a/src/qprojectM/qpreseteditordialog.ui b/src/qprojectM/qpreseteditordialog.ui index 69dd14b82..6f67cd48a 100644 --- a/src/qprojectM/qpreseteditordialog.ui +++ b/src/qprojectM/qpreseteditordialog.ui @@ -50,7 +50,7 @@ Qt::Vertical - QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::Reset + QDialogButtonBox::Apply|QDialogButtonBox::NoButton|QDialogButtonBox::Reset diff --git a/src/qprojectM/qpresettextedit.cpp b/src/qprojectM/qpresettextedit.cpp index 5bf8018d3..58ce4f378 100644 --- a/src/qprojectM/qpresettextedit.cpp +++ b/src/qprojectM/qpresettextedit.cpp @@ -23,6 +23,23 @@ #include #include +#include + +void QPresetTextEdit::keyReleaseEvent(QKeyEvent * e) { + qDebug() << "KEY RELEASE"; + switch (e->key()) { + case Qt::Key_S: + if (e->modifiers() & Qt::ControlModifier) { + qDebug() << "control s"; + emit(applyRequested()); + } + e->accept(); + break; + default: + e->ignore(); + } + +} bool QPresetTextEdit::loadPresetText(QString url) { QFile qfile(url); @@ -43,5 +60,5 @@ bool QPresetTextEdit::loadPresetText(QString url) { this->setPlainText(out.readAll()); - + return true; } \ No newline at end of file diff --git a/src/qprojectM/qpresettextedit.hpp b/src/qprojectM/qpresettextedit.hpp index bed796083..61116c1fe 100644 --- a/src/qprojectM/qpresettextedit.hpp +++ b/src/qprojectM/qpresettextedit.hpp @@ -33,7 +33,11 @@ class QPresetTextEdit: public QTextEdit bool loadPresetText(QString url); - + void keyReleaseEvent(QKeyEvent * e); + + signals: + void applyRequested(); + public slots: private: