summaryrefslogtreecommitdiffstats
path: root/sigmodr/ObjectUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sigmodr/ObjectUI.cpp')
-rw-r--r--sigmodr/ObjectUI.cpp149
1 files changed, 149 insertions, 0 deletions
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 <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"
+
+// Pokemodr includes
+#include "ValidationDialog.h"
+
+// Pokemod includes
+#include "../pokemod/Object.h"
+#include "../pokemod/Pokemod.h"
+
+// KDE includes
+#include <KAction>
+#include <KDialog>
+#include <KMenu>
+#include <KMessageBox>
+
+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<const Pokemod::Pokemod*>(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));
+}