From b81f5bffa2772eb9bd3c67fb35485ab1ee2d96e7 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 5 Sep 2008 20:41:05 +0000 Subject: [FIX] Moving stuff for the move to the new name, Sigma Game Engine (sigen for short) git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@249 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- sigmodr/ObjectUI.cpp | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 sigmodr/ObjectUI.cpp (limited to 'sigmodr/ObjectUI.cpp') diff --git a/sigmodr/ObjectUI.cpp b/sigmodr/ObjectUI.cpp new file mode 100644 index 00000000..834a31f5 --- /dev/null +++ b/sigmodr/ObjectUI.cpp @@ -0,0 +1,149 @@ +/* + * 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" + +// Pokemodr includes +#include "ValidationDialog.h" + +// Pokemod includes +#include "../pokemod/Object.h" +#include "../pokemod/Pokemod.h" + +// KDE includes +#include +#include +#include +#include + +Pokemodr::ObjectUI::ObjectUI(QWidget* parent) : + QWidget(parent), + m_changed(false), + m_validator(NULL), + m_object(NULL), + m_object_mod(NULL) +{ + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(changed(bool)), SLOT(setChanged(bool))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(contextMenu(QPoint))); +} + +Pokemodr::ObjectUI::~ObjectUI() +{ + delete m_object_mod; +} + +void Pokemodr::ObjectUI::reload() +{ + refreshGui(); + setGui(); +} + +bool Pokemodr::ObjectUI::isChanged() const +{ + return m_changed; +} + +const Pokemod::Pokemod* Pokemodr::ObjectUI::pokemod() const +{ + return qobject_cast(m_object->pokemod()); +} + +const Pokemod::Pokemod::Object* Pokemodr::ObjectUI::original() const +{ + return m_object; +} + +Pokemod::Object* Pokemodr::ObjectUI::original() +{ + return m_object; +} + +const Pokemod::Object* Pokemodr::ObjectUI::modified() const +{ + return m_object_mod; +} + +Pokemod::Object* Pokemodr::ObjectUI::modified() +{ + return m_object_mod; +} + +void Pokemodr::ObjectUI::setChanged(const bool changed) +{ + m_changed = changed; +} + +void Pokemodr::ObjectUI::errorMessage(const QString& message) +{ + KMessageBox::error(this, message, "Error"); +} + +void Pokemodr::ObjectUI::warningMessage(const QString& message) +{ + KMessageBox::warningContinueCancel(this, message, "Warning"); +} + +void Pokemodr::ObjectUI::initGui() +{ +} + +void Pokemodr::ObjectUI::refreshGui() +{ +} + +void Pokemodr::ObjectUI::contextMenu(const QPoint& pos) +{ + KMenu* menu = new KMenu; + menu->addAction("&Apply", this, SLOT(apply())); + menu->addAction("&Discard", this, SLOT(discard())); + menu->addSeparator(); + KAction* validate = new KAction("&Validate", this); + connect(validate, SIGNAL(triggered()), this, SLOT(validate())); + validate->setEnabled(!m_changed); + menu->addAction(validate); + menu->popup(mapToGlobal(pos)); +} + +void Pokemodr::ObjectUI::validate() +{ + apply(); + m_validator->show(); +} + +void Pokemodr::ObjectUI::setObjects(Pokemod::Object* original, Pokemod::Object* modified) +{ + m_object = original; + m_object_mod = modified; + if (m_validator) + delete m_validator; + m_validator = new ValidationDialog(m_object, this); + connect(m_object_mod, SIGNAL(changed()), this, SIGNAL(changed())); + connect(m_object_mod, SIGNAL(changed()), this, SLOT(setGui())); + connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(setGui())); + connect(m_object_mod, SIGNAL(error(QString)), this, SLOT(errorMessage(QString))); + connect(m_object_mod, SIGNAL(warning(QString)), this, SLOT(warningMessage(QString))); + init(); +} + +void Pokemodr::ObjectUI::init() +{ + initGui(); + reload(); + emit(changed(false)); +} -- cgit