diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-05-15 19:55:43 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-05-15 19:55:43 +0000 |
| commit | fdd0eec1d145fb8ac97b4cc9aaed5218214416ec (patch) | |
| tree | 2389a0d53fe3eaa644ccb220345995feec748823 /pokemodr/ObjectUI.cpp | |
| parent | 77124f3f105ea3837022d20a49028309a211c4b0 (diff) | |
| download | sigen-fdd0eec1d145fb8ac97b4cc9aaed5218214416ec.tar.gz sigen-fdd0eec1d145fb8ac97b4cc9aaed5218214416ec.tar.xz sigen-fdd0eec1d145fb8ac97b4cc9aaed5218214416ec.zip | |
[FIX] Refactored out connections made within widgets
[FIX] Flag, Fractiona, and Point widgets fixed to only emit signals when actually changed
[FIX] Pokemod classes now emit signals
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@138 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/ObjectUI.cpp')
| -rw-r--r-- | pokemodr/ObjectUI.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/pokemodr/ObjectUI.cpp b/pokemodr/ObjectUI.cpp new file mode 100644 index 00000000..29423d8c --- /dev/null +++ b/pokemodr/ObjectUI.cpp @@ -0,0 +1,145 @@ +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +// Header include +#include "ObjectUI.h" + +// Pokemod includes +#include "../pokemod/Object.h" + +// Qt includes +#include <QCloseEvent> +#include <QMetaObject> + +// KDE includes +#include <KMessageBox> + +ObjectUI::ObjectUI(QWidget* parent) : + QWidget(parent), + m_changed(false), + m_object(NULL), + m_object_mod(NULL) +{ + connect(this, SIGNAL(changed(bool)), SLOT(setChanged(bool))); + connect(this, SIGNAL(changed()), SLOT(setChanged())); +} + +ObjectUI::~ObjectUI() +{ + if (m_changed) + { +// if (KMessageBox::questionYesNo(this, "You have unsaved changes, would you like to save them?", QString("Unsaved %1").arg(m_object->className())) == KMessageBox::Yes) +// apply(); +// else +// discard(); + } + delete m_object_mod; +} + +void ObjectUI::closeEvent(QCloseEvent* event) +{ + if (m_changed) + { + switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", QString("Unsaved %1").arg(m_object->className()))) + { + case KMessageBox::Yes: + event->accept(); + apply(); + break; + case KMessageBox::No: + event->accept(); + discard(); + break; + case KMessageBox::Cancel: + event->ignore(); + break; + } + } +} + +void ObjectUI::reload() +{ + refreshGui(); + setGui(); +} + +bool ObjectUI::isChanged() const +{ + return m_changed; +} + +const Object* ObjectUI::original() const +{ + return m_object; +} + +Object* ObjectUI::original() +{ + return m_object; +} + +const Object* ObjectUI::modified() const +{ + return m_object_mod; +} + +Object* ObjectUI::modified() +{ + return m_object_mod; +} + +void ObjectUI::setChanged(const bool changed) +{ + m_changed = changed; +} + +void ObjectUI::errorMessage(const QString& message) +{ + KMessageBox::error(this, message, "Error"); +} + +void ObjectUI::warningMessage(const QString& message) +{ + KMessageBox::warningContinueCancel(this, message, "Warning"); +} + +void ObjectUI::initGui() +{ +} + +void ObjectUI::refreshGui() +{ +} + +void ObjectUI::setObjects(Object* original, Object* modified) +{ + m_object = original; + m_object_mod = modified; + connect(m_object_mod, SIGNAL(changed()), this, SIGNAL(changed())); + connect(m_object_mod, SIGNAL(error(const QString&)), this, SLOT(setGui())); + connect(m_object_mod, SIGNAL(error(const QString&)), this, SLOT(errorMessage(const QString&))); + connect(m_object_mod, SIGNAL(warning(const QString&)), this, SLOT(warningMessage(const QString&))); + connect(m_object_mod, SIGNAL(changed()), this, SLOT(setChanged())); + connect(m_object_mod, SIGNAL(changed()), this, SLOT(setGui())); +} + +void ObjectUI::init() +{ + initGui(); + reload(); + emit(changed(false)); +} |
