summaryrefslogtreecommitdiffstats
path: root/sigmodr/SigmodrUI.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-02-26 01:36:34 -0500
committerBen Boeckel <MathStuf@gmail.com>2009-02-26 01:36:34 -0500
commit3abbb3a0104d83b65d6efd8b1cda84a7f325e76e (patch)
tree9b7b85acb13802fdfaea82a36cf3af4c81c755c4 /sigmodr/SigmodrUI.cpp
parente6061a847fd007f75d1ec22f2dfb8eed30c845c4 (diff)
downloadsigen-3abbb3a0104d83b65d6efd8b1cda84a7f325e76e.tar.gz
sigen-3abbb3a0104d83b65d6efd8b1cda84a7f325e76e.tar.xz
sigen-3abbb3a0104d83b65d6efd8b1cda84a7f325e76e.zip
Update sigmodr to reflect all code changes and the build
Diffstat (limited to 'sigmodr/SigmodrUI.cpp')
-rw-r--r--sigmodr/SigmodrUI.cpp185
1 files changed, 97 insertions, 88 deletions
diff --git a/sigmodr/SigmodrUI.cpp b/sigmodr/SigmodrUI.cpp
index 5252b81f..c58654cd 100644
--- a/sigmodr/SigmodrUI.cpp
+++ b/sigmodr/SigmodrUI.cpp
@@ -18,17 +18,21 @@
// Header include
#include "SigmodrUI.h"
-// Configuration includes
-#include "SigmodrPreferences.h"
-
// Sigmodr includes
-#include "ObjectUI.h"
+#include "SigmodrPreferences.h"
#include "SigmodrPreferencesWidget.h"
-#include "SigmodTreeModel.h"
+
+// Sigmodr tree includes
+#include <sigmodr/tree/BaseModel.h>
+#include <sigmodr/tree/SigmodrTree.h>
+#include <sigmodr/tree/SigmodrTreeModel.h>
+
+// Sigmodr widget includes
+#include <sigmodr/widgets/ObjectUI.h>
// Sigmod includes
-#include "../sigmod/Rules.h"
-#include "../sigmod/Sigmod.h"
+#include <sigmod/Game.h>
+#include <sigmod/Rules.h>
// KDE includes
#include <KAction>
@@ -60,7 +64,12 @@
#include <QtGui/QDragEnterEvent>
#include <QtGui/QDropEvent>
-Sigmodr::SigmodrUI::SigmodrUI(QWidget* parent) :
+using namespace Sigmod;
+using namespace Sigmodr::Widgets;
+using namespace Sigmodr::Tree;
+using namespace Sigmodr;
+
+SigmodrUI::SigmodrUI(QWidget* parent) :
KXmlGuiWindow(parent)
{
setupUi(this);
@@ -74,33 +83,33 @@ Sigmodr::SigmodrUI::SigmodrUI(QWidget* parent) :
if (args && args->count())
{
for(int i = 0; i < args->count(); ++i)
- openSigmod(args->url(i));
+ openGame(args->url(i));
args->clear();
}
else if (SigmodrPreferences::reloadOnStart())
{
QStringList urls = SigmodrPreferences::openFiles();
foreach (const QString& url, urls)
- openSigmod(KUrl(url));
+ openGame(KUrl(url));
}
setAutoSaveSettings("MainWindow", true);
}
-Sigmodr::SigmodrUI::~SigmodrUI()
+SigmodrUI::~SigmodrUI()
{
- closeAllSigmods(true);
+ closeAllGames(true);
SigmodrPreferences::self()->writeConfig();
KGlobal::config()->sync();
}
-void Sigmodr::SigmodrUI::dragEnterEvent(QDragEnterEvent* event)
+void SigmodrUI::dragEnterEvent(QDragEnterEvent* event)
{
const QMimeData* data = event->mimeData();
if (data->hasFormat("application/x-sigmod+xml") || data->hasFormat("text/uri-list"))
event->acceptProposedAction();
}
-void Sigmodr::SigmodrUI::dropEvent(QDropEvent* event)
+void SigmodrUI::dropEvent(QDropEvent* event)
{
const QMimeData* data = event->mimeData();
bool loaded = false;
@@ -115,7 +124,7 @@ void Sigmodr::SigmodrUI::dropEvent(QDropEvent* event)
{
if (xml.doctype().name() == "Sigmod")
{
- treeSigmod->addSigmod(new Sigmod::Sigmod(xml.documentElement()));
+ treeSigmod->addGame(new Game(xml.documentElement()));
loaded = true;
}
else
@@ -128,62 +137,62 @@ void Sigmodr::SigmodrUI::dropEvent(QDropEvent* event)
{
QList<QUrl> urls = data->urls();
foreach (const QUrl& url, urls)
- loaded = openSigmod(url);
+ loaded = openGame(url);
}
if (loaded)
event->acceptProposedAction();
}
-void Sigmodr::SigmodrUI::update()
+void SigmodrUI::update()
{
treeSigmod->update(treeSigmod->currentIndex());
}
-void Sigmodr::SigmodrUI::closeEvent(QCloseEvent* event)
+void SigmodrUI::closeEvent(QCloseEvent* event)
{
KRecentFilesAction *recent = qobject_cast<KRecentFilesAction*>(actionCollection()->action(KStandardAction::name(KStandardAction::OpenRecent)));
recent->saveEntries(KGlobal::config()->group("Recent Files"));
- if (closeAllSigmods())
+ if (closeAllGames())
event->accept();
else
event->ignore();
}
-void Sigmodr::SigmodrUI::resizeEvent(QResizeEvent* event)
+void SigmodrUI::resizeEvent(QResizeEvent* event)
{
event->accept();
on_splitter_splitterMoved();
}
-void Sigmodr::SigmodrUI::setChangedTitle(const bool changed)
+void SigmodrUI::setChangedTitle(const bool changed)
{
setCaption(treeSigmod->description(treeSigmod->currentIndex()), changed);
}
-void Sigmodr::SigmodrUI::setDirty(const bool dirty)
+void SigmodrUI::setDirty(const bool dirty)
{
- const Sigmod::Sigmod* sigmod = static_cast<Sigmod::Object*>(treeSigmod->currentIndex().internalPointer())->sigmod();
- treeSigmod->setDirty(sigmod, dirty);
+ const Game* game = static_cast<Object*>(treeSigmod->currentIndex().internalPointer())->game();
+ treeSigmod->setDirty(game, dirty);
setChangedTitle(dirty);
actionCollection()->action("file_save")->setEnabled(dirty);
}
-void Sigmodr::SigmodrUI::newSigmod()
+void SigmodrUI::newGame()
{
- treeSigmod->addSigmod(new Sigmod::Sigmod);
+ treeSigmod->addGame(new Game);
}
-void Sigmodr::SigmodrUI::openSigmod()
+void SigmodrUI::openGame()
{
KUrl::List urls = KFileDialog::getOpenUrls(KUrl("kfiledialog:///sigmod"), "*.smod|Sigmod files", this);
foreach (const KUrl& url, urls)
{
if (!url.isEmpty())
- openSigmod(url);
+ openGame(url);
}
}
-bool Sigmodr::SigmodrUI::openSigmod(const KUrl& url)
+bool SigmodrUI::openGame(const KUrl& url)
{
bool opened = false;
if (treeSigmod->isOpen(url))
@@ -194,13 +203,13 @@ bool Sigmodr::SigmodrUI::openSigmod(const KUrl& url)
if (url.isValid())
{
if (url.isLocalFile())
- opened = openSigmod(url.path());
+ opened = openGame(url.path());
else
{
QString temp;
if (KIO::NetAccess::download(url, temp, this))
{
- opened = openSigmod(temp, true);
+ opened = openGame(temp, true);
KIO::NetAccess::removeTempFile(temp);
}
else
@@ -214,7 +223,7 @@ bool Sigmodr::SigmodrUI::openSigmod(const KUrl& url)
return opened;
}
-bool Sigmodr::SigmodrUI::openSigmod(const QString& path, const bool isRemote)
+bool SigmodrUI::openGame(const QString& path, const bool isRemote)
{
QFile file(path);
if (file.open(QIODevice::ReadOnly))
@@ -227,7 +236,7 @@ bool Sigmodr::SigmodrUI::openSigmod(const QString& path, const bool isRemote)
{
if (xml.doctype().name() == "Sigmod")
{
- treeSigmod->addSigmod(new Sigmod::Sigmod(xml.documentElement()), isRemote ? KUrl() : KUrl(path));
+ treeSigmod->addGame(new Game(xml.documentElement()), isRemote ? KUrl() : KUrl(path));
return true;
}
else
@@ -242,31 +251,31 @@ bool Sigmodr::SigmodrUI::openSigmod(const QString& path, const bool isRemote)
return false;
}
-void Sigmodr::SigmodrUI::saveSigmod()
+void SigmodrUI::saveGame()
{
- saveSigmod(treeSigmod->currentSigmod());
+ saveGame(treeSigmod->currentGame());
}
-void Sigmodr::SigmodrUI::saveSigmod(const Sigmod::Sigmod* sigmod)
+void SigmodrUI::saveGame(const Game* game)
{
- const KUrl url = treeSigmod->url(sigmod);
+ const KUrl url = treeSigmod->url(game);
if (url.isEmpty())
- saveAsSigmod(sigmod);
+ saveAsGame(game);
else
- saveSigmod(sigmod, url);
+ saveGame(game, url);
}
-bool Sigmodr::SigmodrUI::saveSigmod(const Sigmod::Sigmod* sigmod, const KUrl& url)
+bool SigmodrUI::saveGame(const Game* game, const KUrl& url)
{
- if (sigmod)
+ if (game)
{
if (url.isLocalFile())
{
QFile file(url.path());
if (file.open(QIODevice::WriteOnly))
{
- file.write(Sigmod::Object::xml(sigmod).toByteArray());
- treeSigmod->setDirty(sigmod, false);
+ file.write(Object::xml(game).toByteArray());
+ treeSigmod->setDirty(game, false);
file.close();
return true;
}
@@ -278,10 +287,10 @@ bool Sigmodr::SigmodrUI::saveSigmod(const Sigmod::Sigmod* sigmod, const KUrl& ur
KTemporaryFile temp;
if (temp.open())
{
- temp.write(Sigmod::Object::xml(sigmod).toByteArray());
+ temp.write(Object::xml(game).toByteArray());
if (KIO::NetAccess::upload(temp.fileName(), url, this))
{
- treeSigmod->setDirty(sigmod, false);
+ treeSigmod->setDirty(game, false);
return true;
}
else
@@ -295,39 +304,39 @@ bool Sigmodr::SigmodrUI::saveSigmod(const Sigmod::Sigmod* sigmod, const KUrl& ur
return false;
}
-void Sigmodr::SigmodrUI::saveAsSigmod()
+void SigmodrUI::saveAsGame()
{
- saveAsSigmod(treeSigmod->currentSigmod());
+ saveAsGame(treeSigmod->currentGame());
}
-void Sigmodr::SigmodrUI::saveAsSigmod(const Sigmod::Sigmod* sigmod)
+void SigmodrUI::saveAsGame(const Game* game)
{
- if (sigmod)
+ if (game)
{
KUrl url = KFileDialog::getSaveUrl(KUrl("kfiledialog:///sigmod"), "*.smod|Sigmod files", this, "Open Sigmod");
if (!url.isEmpty())
{
- if (saveSigmod(sigmod, url))
- treeSigmod->setUrl(sigmod, url);
+ if (saveGame(game, url))
+ treeSigmod->setUrl(game, url);
}
}
}
-void Sigmodr::SigmodrUI::downloadSigmod()
+void SigmodrUI::downloadGame()
{
KNS::Engine engine(this);
if (engine.init("sigmod.knsrc"))
engine.downloadDialogModal();
}
-void Sigmodr::SigmodrUI::uploadSigmod()
+void SigmodrUI::uploadGame()
{
- uploadSigmod(treeSigmod->currentSigmod());
+ uploadGame(treeSigmod->currentGame());
}
-void Sigmodr::SigmodrUI::uploadSigmod(const Sigmod::Sigmod* sigmod)
+void SigmodrUI::uploadGame(const Game* game)
{
- KUrl url = treeSigmod->url(sigmod);
+ KUrl url = treeSigmod->url(game);
if (url == KUrl())
{
KMessageBox::error(this, "The Sigmod has not been saved!", "Upload error");
@@ -346,17 +355,17 @@ void Sigmodr::SigmodrUI::uploadSigmod(const Sigmod::Sigmod* sigmod)
}
}
-void Sigmodr::SigmodrUI::closeSigmod()
+void SigmodrUI::closeGame()
{
- closeSigmod(treeSigmod->currentSigmod());
+ closeGame(treeSigmod->currentGame());
setChangedTitle(treeSigmod->dirty());
}
-bool Sigmodr::SigmodrUI::closeSigmod(const Sigmod::Sigmod* sigmod, const bool force)
+bool SigmodrUI::closeGame(const Game* game, const bool force)
{
- if (sigmod)
+ if (game)
{
- if (treeSigmod->dirty(sigmod))
+ if (treeSigmod->dirty(game))
{
int result;
if (force)
@@ -366,48 +375,48 @@ bool Sigmodr::SigmodrUI::closeSigmod(const Sigmod::Sigmod* sigmod, const bool fo
switch (result)
{
case KMessageBox::Yes:
- saveSigmod(sigmod);
+ saveGame(game);
case KMessageBox::No:
break;
case KMessageBox::Cancel:
return false;
}
}
- treeSigmod->deleteSigmod(sigmod);
+ treeSigmod->deleteGame(game);
if (formPanel->widget())
delete formPanel->takeWidget();
}
return true;
}
-bool Sigmodr::SigmodrUI::closeAllSigmods(const bool force)
+bool SigmodrUI::closeAllGames(const bool force)
{
- QList<const Sigmod::Sigmod*> sigmods = treeSigmod->openedSigmods();
- if (sigmods.size())
+ QList<const Game*> games = treeSigmod->openedGames();
+ if (games.size())
SigmodrPreferences::setOpenFiles(treeSigmod->urls());
- for (int i = 0; i < sigmods.size(); )
+ for (int i = 0; i < games.size(); )
{
- if (closeSigmod(sigmods[i], force))
- sigmods.removeAt(i);
+ if (closeGame(games[i], force))
+ games.removeAt(i);
else
++i;
}
- if (!sigmods.size() || force)
+ if (!games.size() || force)
close();
- return !sigmods.size();
+ return !games.size();
}
-void Sigmodr::SigmodrUI::copyObject()
+void SigmodrUI::copyObject()
{
m_clipboard = treeSigmod->copy(treeSigmod->currentIndex());
}
-void Sigmodr::SigmodrUI::pasteObject()
+void SigmodrUI::pasteObject()
{
treeSigmod->paste(treeSigmod->currentIndex(), m_clipboard);
}
-void Sigmodr::SigmodrUI::preferences()
+void SigmodrUI::preferences()
{
if (KConfigDialog::showDialog("sigmodr-prefs"))
return;
@@ -418,7 +427,7 @@ void Sigmodr::SigmodrUI::preferences()
dialog->exec();
}
-void Sigmodr::SigmodrUI::toggleMenubar()
+void SigmodrUI::toggleMenubar()
{
if (menuBar()->isVisible())
menuBar()->hide();
@@ -426,7 +435,7 @@ void Sigmodr::SigmodrUI::toggleMenubar()
menuBar()->show();
}
-void Sigmodr::SigmodrUI::on_splitter_splitterMoved()
+void SigmodrUI::on_splitter_splitterMoved()
{
SigmodrPreferences::setTreeWidth(splitter->sizes()[0]);
SigmodrPreferences::setPanelWidth(splitter->sizes()[1]);
@@ -458,13 +467,13 @@ void Sigmodr::SigmodrUI::on_treeSigmod_clicked(const QModelIndex& index)
connect(buttonApply, SIGNAL(clicked()), widget, SLOT(apply()));
connect(buttonApply, SIGNAL(clicked()), this, SLOT(setDirty()));
connect(buttonReset, SIGNAL(clicked()), widget, SLOT(discard()));
- setChangedTitle(treeSigmod->dirty(treeSigmod->currentSigmod()));
+ setChangedTitle(treeSigmod->dirty(treeSigmod->currentGame()));
formPanel->setWidget(widget);
formPanel->show();
}
}
-void Sigmodr::SigmodrUI::on_treeSigmod_customContextMenuRequested(const QPoint& position)
+void SigmodrUI::on_treeSigmod_customContextMenuRequested(const QPoint& position)
{
QModelIndex index = treeSigmod->indexAt(position);
KMenu* menu = treeSigmod->contextMenu(index);
@@ -483,16 +492,16 @@ void Sigmodr::SigmodrUI::on_treeSigmod_customContextMenuRequested(const QPoint&
}
}
-void Sigmodr::SigmodrUI::setupActions()
+void SigmodrUI::setupActions()
{
- KStandardAction::openNew(this, SLOT(newSigmod()), actionCollection());
- KStandardAction::open(this, SLOT(openSigmod()), actionCollection());
- KRecentFilesAction* recent = KStandardAction::openRecent(this, SLOT(openSigmod(const KUrl&)), actionCollection());
+ KStandardAction::openNew(this, SLOT(newGame()), actionCollection());
+ KStandardAction::open(this, SLOT(openGame()), actionCollection());
+ KRecentFilesAction* recent = KStandardAction::openRecent(this, SLOT(openGame(const KUrl&)), actionCollection());
recent->loadEntries(KGlobal::config()->group("Recent Files"));
- KStandardAction::save(this, SLOT(saveSigmod()), actionCollection());
- KStandardAction::saveAs(this, SLOT(saveAsSigmod()), actionCollection());
- KStandardAction::close(this, SLOT(closeSigmod()), actionCollection());
- KStandardAction::quit(this, SLOT(closeAllSigmods()), actionCollection());
+ KStandardAction::save(this, SLOT(saveGame()), actionCollection());
+ KStandardAction::saveAs(this, SLOT(saveAsGame()), actionCollection());
+ KStandardAction::close(this, SLOT(closeGame()), actionCollection());
+ KStandardAction::quit(this, SLOT(closeAllGames()), actionCollection());
KStandardAction::cut(actionCollection());
KStandardAction::copy(actionCollection());
KStandardAction::paste(actionCollection());
@@ -500,13 +509,13 @@ void Sigmodr::SigmodrUI::setupActions()
download->setText(i18n("Download"));
download->setIcon(KIcon("arrow-down-double"));
download->setShortcut(Qt::CTRL + Qt::Key_D);
- connect(download, SIGNAL(triggered()), this, SLOT(downloadSigmod()));
+ connect(download, SIGNAL(triggered()), this, SLOT(downloadGame()));
KAction* upload = actionCollection()->addAction("upload_sigmod");
upload->setText(i18n("Upload"));
upload->setIcon(KIcon("arrow-up-double"));
upload->setShortcut(Qt::CTRL + Qt::Key_U);
upload->setEnabled(false);
- connect(upload, SIGNAL(triggered()), this, SLOT(uploadSigmod()));
+ connect(upload, SIGNAL(triggered()), this, SLOT(uploadGame()));
KStandardAction::showMenubar(this, SLOT(toggleMenubar()), actionCollection());
KStandardAction::configureToolbars(this, SLOT(configureToolbars()), actionCollection());
createStandardStatusBarAction();