/* * 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)); }