summaryrefslogtreecommitdiffstats
path: root/pokemodr/ObjectUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-06-19 02:06:10 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-06-19 02:06:10 +0000
commit6dd3d36c4552565756dcedab2ddd44e90a553252 (patch)
tree85fce9e5b97bd3a5f9f60b8d427ca8155d76609f /pokemodr/ObjectUI.cpp
parent5d7d71ddb75f636f94028da346f43565ffb798df (diff)
downloadsigen-6dd3d36c4552565756dcedab2ddd44e90a553252.tar.gz
sigen-6dd3d36c4552565756dcedab2ddd44e90a553252.tar.xz
sigen-6dd3d36c4552565756dcedab2ddd44e90a553252.zip
[FIX] Validation works in Pokémodr
[FIX] Macros moved to their own file [FIX] Macros for subclasses added [FIX] Key shortcuts added to context menu items [FIX] Rules had a redundant field git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@212 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/ObjectUI.cpp')
-rw-r--r--pokemodr/ObjectUI.cpp100
1 files changed, 99 insertions, 1 deletions
diff --git a/pokemodr/ObjectUI.cpp b/pokemodr/ObjectUI.cpp
index caef8956..8e96c79e 100644
--- a/pokemodr/ObjectUI.cpp
+++ b/pokemodr/ObjectUI.cpp
@@ -22,16 +22,30 @@
#include "../pokemod/Object.h"
#include "../pokemod/Pokemod.h"
+// Qt includes
+#include <QLabel>
+#include <QTreeWidget>
+#include <QVBoxLayout>
+
// KDE includes
+#include <KAction>
+#include <KColorScheme>
+#include <KDialog>
+#include <KMenu>
#include <KMessageBox>
+#include <KProgressDialog>
+// #include <KStatefulBrush>
Pokemodr::ObjectUI::ObjectUI(QWidget* parent) :
QWidget(parent),
m_changed(false),
m_object(NULL),
- m_object_mod(NULL)
+ m_object_mod(NULL),
+ m_valTree(NULL)
{
+ setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(changed(bool)), SLOT(setChanged(bool)));
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), SLOT(contextMenu(const QPoint&)));
}
Pokemodr::ObjectUI::~ObjectUI()
@@ -98,6 +112,90 @@ 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()
+{
+ KProgressDialog* progress = new KProgressDialog(this, "Validating", "Please wait");
+ progress->progressBar()->setRange(0, 0);
+ progress->setAllowCancel(false);
+ progress->setModal(true);
+ progress->show();
+ if (!m_valTree)
+ m_valTree = new QTreeWidget;
+ m_valTree->setHeaderHidden(true);
+ m_parents.clear();
+ m_warnings = 0;
+ m_errors = 0;
+ m_valTree->clear();
+ connect(m_object, SIGNAL(valMessage(const QString&)), this, SLOT(addMessage(const QString&)));
+ connect(m_object, SIGNAL(valWarning(const QString&)), this, SLOT(addWarning(const QString&)));
+ connect(m_object, SIGNAL(valError(const QString&)), this, SLOT(addError(const QString&)));
+ m_object->validate();
+ delete progress;
+ KDialog* dialog = new KDialog(this);
+ dialog->setCaption("Validation Messages");
+ dialog->setButtons(KDialog::Ok);
+ QWidget* widget = new QWidget(this);
+ QVBoxLayout* layout = new QVBoxLayout(widget);
+ layout->addWidget(new QLabel(QString("Warnings: %1\nErrors: %2").arg(m_warnings).arg(m_errors), widget));
+ layout->addWidget(m_valTree);
+ dialog->setMainWidget(widget);
+ dialog->exec();
+ delete dialog;
+ m_valTree = NULL;
+ disconnect(m_object, SIGNAL(valMessage(const QString&)), this, SLOT(addMessage(const QString&)));
+ disconnect(m_object, SIGNAL(valWarning(const QString&)), this, SLOT(addWarning(const QString&)));
+ disconnect(m_object, SIGNAL(valError(const QString&)), this, SLOT(addError(const QString&)));
+}
+
+void Pokemodr::ObjectUI::addMessage(const QString& msg)
+{
+ QTreeWidgetItem* item;
+ if (msg.startsWith("++"))
+ {
+ if (m_parents.size())
+ item = new QTreeWidgetItem(m_parents.top(), QStringList(msg.mid(2)));
+ else
+ item = new QTreeWidgetItem(m_valTree, QStringList(msg.mid(2)));
+ m_parents.push(item);
+ }
+ else if (msg.startsWith("--"))
+ m_parents.pop();
+ else
+ {
+ item = new QTreeWidgetItem(m_parents.top(), QStringList(msg));
+ item->setBackground(0, KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground).brush(QPalette::Normal));
+ }
+}
+
+void Pokemodr::ObjectUI::addWarning(const QString& msg)
+{
+ ++m_warnings;
+ QTreeWidgetItem* item;
+ item = new QTreeWidgetItem(m_parents.top(), QStringList(msg));
+ item->setBackground(0, KStatefulBrush(KColorScheme::View, KColorScheme::NeutralBackground).brush(QPalette::Normal));
+}
+
+void Pokemodr::ObjectUI::addError(const QString& msg)
+{
+ ++m_errors;
+ QTreeWidgetItem* item;
+ item = new QTreeWidgetItem(m_parents.top(), QStringList(msg));
+ item->setBackground(0, KStatefulBrush(KColorScheme::View, KColorScheme::NegativeBackground).brush(QPalette::Normal));
+}
+
void Pokemodr::ObjectUI::setObjects(Pokemod::Object* original, Pokemod::Object* modified)
{
m_object = original;