bug fixes and ctrl-s saves/updates the preset

git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@887 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
w1z7ard
2008-03-02 09:07:48 +00:00
parent bc1e66ed4b
commit f5fc1c579e
5 changed files with 45 additions and 11 deletions

View File

@ -1,11 +1,13 @@
#include "qpreseteditordialog.hpp"
#include <QFile>
#include <QMessageBox>
#include <QKeyEvent>
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();

View File

@ -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:

View File

@ -50,7 +50,7 @@
<enum>Qt::Vertical</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::NoButton|QDialogButtonBox::Reset</set>
</property>
</widget>
</widget>

View File

@ -23,6 +23,23 @@
#include <QFile>
#include <QMessageBox>
#include <QKeyEvent>
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;
}

View File

@ -33,7 +33,11 @@ class QPresetTextEdit: public QTextEdit
bool loadPresetText(QString url);
void keyReleaseEvent(QKeyEvent * e);
signals:
void applyRequested();
public slots:
private: