From fdd0eec1d145fb8ac97b4cc9aaed5218214416ec Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 15 May 2008 19:55:43 +0000 Subject: [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 --- pokemodr/ObjectUI.cpp | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 pokemodr/ObjectUI.cpp (limited to 'pokemodr/ObjectUI.cpp') 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 + * + * 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 . + */ + +// Header include +#include "ObjectUI.h" + +// Pokemod includes +#include "../pokemod/Object.h" + +// Qt includes +#include +#include + +// KDE includes +#include + +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)); +} -- cgit