summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-15 06:22:44 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-15 06:22:44 +0000
commit3db0d88626ef92b2f7dc24fb7db6503495749fbe (patch)
tree3ebdb1df0eac2fd53d9f470b4f47604d1f5ac260
parent5944fb084ba725c14162ac6e59de60f45e1cc86c (diff)
downloadsigen-3db0d88626ef92b2f7dc24fb7db6503495749fbe.tar.gz
sigen-3db0d88626ef92b2f7dc24fb7db6503495749fbe.tar.xz
sigen-3db0d88626ef92b2f7dc24fb7db6503495749fbe.zip
[FIX] More things are coded for the main window
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@135 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog7
-rw-r--r--pokemodr/PokeModrUI.cpp41
-rw-r--r--pokemodr/PokeModrUI.h5
-rw-r--r--pokemodr/PokemodTree.cpp29
-rw-r--r--pokemodr/PokemodTree.h10
-rw-r--r--pokemodr/TODO4
-rw-r--r--pokemodr/models/BaseModel.cpp4
-rw-r--r--pokemodr/models/BaseModel.h6
8 files changed, 73 insertions, 33 deletions
diff --git a/Changelog b/Changelog
index 5a909e3a..d8e91f4f 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,11 @@
-----------------
+Rev: 135
+Date: 15 May 2008
+User: MathStuf
+-----------------
+[FIX] More things are coded for the main window
+
+-----------------
Rev: 134
Date: 15 May 2008
User: MathStuf
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index 6a9ea1b1..80341383 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -46,12 +46,12 @@
PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* parent) :
KMainWindow(parent),
m_config(config),
- m_recent(new KRecentFilesAction("&Recent Files...", this)),
- m_clipboard(NULL)
+ m_recent(new KRecentFilesAction("&Recent Files...", this))
{
setupUi(this);
QMetaObject::connectSlotsByName(this);
m_recent->loadEntries(history);
+ // TODO: Somehow get KAction/KMenus into the ui files
KMenuBar* menubar = new KMenuBar(this);
KMenu* menuFile = new KMenu("&File", menubar);
menuFile->addAction(KStandardAction::openNew(this, SLOT(newPokemod()), menuFile));
@@ -135,11 +135,7 @@ void PokeModrUI::closeEvent(QCloseEvent* event)
void PokeModrUI::setChangedTitle(const bool changed)
{
- // TODO: set the title
-// if (formPanel->widget())
-// setWindowTitle(QString::fromUtf8("%1%2 - PokéModr").arg(static_cast<ObjectUI*>(formPanel->widget())->original()->pokemod()->title()).arg(c ? "*" : ""));
-// else
-// setWindowTitle(QString::fromUtf8("PokéModr"));
+ setWindowTitle(QString::fromUtf8("%1%2 - PokéModr").arg(treePokemod->description(treePokemod->currentIndex())).arg(changed ? "*" : ""));
}
void PokeModrUI::newPokemod()
@@ -231,30 +227,17 @@ void PokeModrUI::quit()
void PokeModrUI::cutObject()
{
- // TODO: cut the item
-// if (!treePokemod->currentItem())
-// return;
-// if (m_clipboard)
-// delete m_clipboard;
-// m_clipboard = static_cast<PokeModTreeItem*>(treePokemod->currentItem())->cut();
+ m_clipboard = treePokemod->cut(treePokemod->currentIndex());
}
void PokeModrUI::copyObject()
{
- // TODO: copy the item
-// if (!treePokemod->currentItem())
-// return;
-// if (m_clipboard)
-// delete m_clipboard;
-// m_clipboard = static_cast<PokeModTreeItem*>(treePokemod->currentItem())->copy();
+ m_clipboard = treePokemod->copy(treePokemod->currentIndex());
}
void PokeModrUI::pasteObject()
{
- // TODO: paste the item
-// if (!m_clipboard || !treePokemod->currentItem())
-// return;
-// static_cast<PokeModTreeItem*>(treePokemod->currentItem())->paste(m_clipboard);
+ treePokemod->paste(treePokemod->currentIndex(), m_clipboard);
}
void PokeModrUI::preferences()
@@ -270,7 +253,6 @@ void PokeModrUI::on_splitter_splitterMoved()
void PokeModrUI::on_treePokemod_clicked(const QModelIndex& index)
{
- // TODO: update the panel with the new widget needed
QWidget* widget = treePokemod->editorWidget(index);
if (widget)
{
@@ -279,6 +261,8 @@ void PokeModrUI::on_treePokemod_clicked(const QModelIndex& index)
if (!static_cast<ObjectUI*>(formPanel->widget())->close())
return;
}
+ connect(widget, SIGNAL(changed(bool)), this, SLOT(setChangedTitle(bool)));
+ setChangedTitle(false);
formPanel->setWidget(widget);
formPanel->show();
}
@@ -286,10 +270,7 @@ void PokeModrUI::on_treePokemod_clicked(const QModelIndex& index)
void PokeModrUI::on_treePokemod_customContextMenuRequested(const QPoint& position)
{
- // TODO: figure out which item was clicked
-// if (treePokemod->itemAt(position))
-// static_cast<PokeModTreeItem*>(treePokemod->itemAt(position))->makeMenu(position);
-// else
-// {
-// }
+ KMenu* menu = treePokemod->contextMenu(treePokemod->indexAt(position));
+ if (menu)
+ menu->popup(mapToGlobal(position));
}
diff --git a/pokemodr/PokeModrUI.h b/pokemodr/PokeModrUI.h
index b35562e6..b8b78267 100644
--- a/pokemodr/PokeModrUI.h
+++ b/pokemodr/PokeModrUI.h
@@ -22,6 +22,9 @@
#include <KConfigGroup>
#include <KMainWindow>
+// Qt includes
+#include <QDomDocument>
+
// Form include
#include "ui_pokemodr.h"
@@ -60,7 +63,7 @@ class PokeModrUI : public KMainWindow, private Ui::formPokeModr
private:
KConfigGroup m_config;
KRecentFilesAction* m_recent;
- Object* m_clipboard;
+ QDomDocument m_clipboard;
};
#endif
diff --git a/pokemodr/PokemodTree.cpp b/pokemodr/PokemodTree.cpp
index e075af83..8b7712d5 100644
--- a/pokemodr/PokemodTree.cpp
+++ b/pokemodr/PokemodTree.cpp
@@ -30,7 +30,36 @@ PokemodTree::PokemodTree(QWidget* parent) :
header()->hide();
}
+QString PokemodTree::description(const QModelIndex& index)
+{
+ return QString("%1: %2").arg(model()->data(index, BaseModel::TypeRole).toString()).arg(model()->data(index, Qt::DisplayRole).toString());
+}
+
QWidget* PokemodTree::editorWidget(const QModelIndex& index)
{
return model()->data(index, BaseModel::WidgetRole).value<QWidget*>();
}
+
+KMenu* PokemodTree::contextMenu(const QModelIndex& index)
+{
+ // FIXME: QVariant cant get a KMenu* out of it
+ return static_cast<KMenu*>(model()->data(index, BaseModel::ContextMenuRole).value<void*>());
+}
+
+QDomDocument PokemodTree::cut(const QModelIndex& index)
+{
+ // TODO: actually cut out the item
+ return copy(index);
+}
+
+QDomDocument PokemodTree::copy(const QModelIndex& index)
+{
+ QDomDocument xml;
+ xml.setContent(model()->data(index, BaseModel::XmlRole).toString());
+ return xml;
+}
+
+void PokemodTree::paste(const QModelIndex& index, const QDomDocument& data)
+{
+ model()->setData(index, data.toString(), BaseModel::XmlRole);
+}
diff --git a/pokemodr/PokemodTree.h b/pokemodr/PokemodTree.h
index 45d37f11..7828680a 100644
--- a/pokemodr/PokemodTree.h
+++ b/pokemodr/PokemodTree.h
@@ -19,8 +19,12 @@
#define __POKEMODR_POKEMODTREE__
// Qt includes
+#include <QDomDocument>
#include <QTreeView>
+// Forward declarations
+class KMenu;
+
class PokemodTree : public QTreeView
{
Q_OBJECT
@@ -28,7 +32,13 @@ class PokemodTree : public QTreeView
public:
PokemodTree(QWidget* parent = 0);
+ QString description(const QModelIndex& index);
QWidget* editorWidget(const QModelIndex& index);
+ KMenu* contextMenu(const QModelIndex& index);
+
+ QDomDocument cut(const QModelIndex& index);
+ QDomDocument copy(const QModelIndex& index);
+ void paste(const QModelIndex& index, const QDomDocument& data);
};
#endif
diff --git a/pokemodr/TODO b/pokemodr/TODO
index 8936281c..adaf0254 100644
--- a/pokemodr/TODO
+++ b/pokemodr/TODO
@@ -9,5 +9,9 @@ Set sub class stuff by passing it on to subclasses via setData
TilemapModel is (probably) wrong
+Models:
+ TypeRole
+ ContextMenuRole
+
Test code:
BaseModel -> BaseObjectModel in GroupModel
diff --git a/pokemodr/models/BaseModel.cpp b/pokemodr/models/BaseModel.cpp
index 75e1b3d6..761ff3e7 100644
--- a/pokemodr/models/BaseModel.cpp
+++ b/pokemodr/models/BaseModel.cpp
@@ -114,6 +114,10 @@ QVariant GroupModel::data(int role) const
{
if (role == Qt::DisplayRole)
return m_name;
+ else if (role == BaseModel::ContextMenuRole)
+ {
+ // TODO: Make KMenu for group
+ }
return QVariant();
}
diff --git a/pokemodr/models/BaseModel.h b/pokemodr/models/BaseModel.h
index 4e308ce5..f690e5d0 100644
--- a/pokemodr/models/BaseModel.h
+++ b/pokemodr/models/BaseModel.h
@@ -56,8 +56,10 @@ class BaseModel
virtual QString type() const = 0;
- static const int XmlRole = Qt::UserRole;
- static const int WidgetRole = Qt::UserRole + 1;
+ static const int TypeRole = Qt::UserRole;
+ static const int XmlRole = Qt::UserRole + 1;
+ static const int WidgetRole = Qt::UserRole + 2;
+ static const int ContextMenuRole = Qt::UserRole + 3;
protected:
Object* m_object;
QString m_name;