/* * 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 "PokeModrUI.h" // PokeModr includes #include "ObjectUI.h" #include "PokemodTreeModel.h" // Pokemod includes #include "../pokemod/Pokemod.h" // Qt includes #include #include // KDE includes #include #include #include #include #include #include #include #include #include #include #include #include PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* parent) : KMainWindow(parent), m_config(config), m_recent(new KRecentFilesAction("&Recent Files...", this)), m_clipboard(NULL) { setupUi(this); QMetaObject::connectSlotsByName(this); m_recent->loadEntries(history); KMenuBar* menubar = new KMenuBar(this); KMenu* menuFile = new KMenu("&File", menubar); menuFile->addAction(KStandardAction::openNew(this, SLOT(newPokemod()), menuFile)); menuFile->addAction(KStandardAction::open(this, SLOT(openPokemod()), menuFile)); menuFile->addAction(KStandardAction::openRecent(this, SLOT(openPokemod(const KUrl&)), menuFile)); menuFile->addSeparator(); menuFile->addAction(KStandardAction::save(this, SLOT(savePokemod()), menuFile)); menuFile->addAction(KStandardAction::saveAs(this, SLOT(saveAsPokemod()), menuFile)); menuFile->addSeparator(); menuFile->addAction(KStandardAction::quit(this, SLOT(quit()), menuFile)); menubar->addMenu(menuFile); KMenu* menuEdit = new KMenu("&Edit", menubar); menuEdit->addAction(KStandardAction::cut(menuEdit)); menuEdit->addAction(KStandardAction::copy(menuEdit)); menuEdit->addAction(KStandardAction::paste(menuEdit)); menuEdit->addSeparator(); KAction* menuCut = new KAction(KIcon("edit-cut"), "Cu&t Object", menuEdit); menuCut->setShortcut(KShortcut("Alt+X")); menuEdit->addAction(menuCut); connect(menuCut, SIGNAL(triggered()), this, SLOT(cutObject())); KAction* menuCopy = new KAction(KIcon("edit-copy"), "Cop&y Object", menuEdit); menuCopy->setShortcut(KShortcut("Alt+C")); menuEdit->addAction(menuCopy); connect(menuCopy, SIGNAL(triggered()), this, SLOT(copyObject())); KAction* menuPaste = new KAction(KIcon("edit-paste"), "Past&e Object", menuEdit); menuPaste->setShortcut(KShortcut("Alt+V")); menuEdit->addAction(menuPaste); connect(menuPaste, SIGNAL(triggered()), this, SLOT(pasteObject())); menuEdit->addSeparator(); menuEdit->addAction(KStandardAction::preferences(this, SLOT(preferences()), menuEdit)); menubar->addMenu(menuEdit); menubar->addMenu(customHelpMenu(false)); setMenuBar(menubar); KToolBar* toolbar = new KToolBar("toolbar", this, Qt::TopToolBarArea, false, true, true); toolbar->addAction(KStandardAction::openNew(this, SLOT(newPokemod()), toolbar)); toolbar->addAction(KStandardAction::open(this, SLOT(openPokemod()), toolbar)); toolbar->addAction(KStandardAction::openRecent(this, SLOT(openPokemod(const KUrl&)), toolbar)); toolbar->addSeparator(); toolbar->addAction(KStandardAction::save(this, SLOT(savePokemod()), toolbar)); toolbar->addAction(KStandardAction::saveAs(this, SLOT(saveAsPokemod()), toolbar)); toolbar->addSeparator(); toolbar->addAction(KStandardAction::cut(toolbar)); toolbar->addAction(KStandardAction::copy(toolbar)); toolbar->addAction(KStandardAction::paste(toolbar)); toolbar->addSeparator(); KAction* toolbarCut = new KAction(KIcon("edit-cut"), "Cu&t Object", toolbar); toolbar->addAction(toolbarCut); connect(toolbarCut, SIGNAL(triggered()), this, SLOT(cutObject())); KAction* toolbarCopy = new KAction(KIcon("edit-copy"), "Cop&y Object", toolbar); toolbar->addAction(toolbarCopy); connect(toolbarCopy, SIGNAL(triggered()), this, SLOT(copyObject())); KAction* toolbarPaste = new KAction(KIcon("edit-paste"), "Past&e Object", toolbar); toolbar->addAction(toolbarPaste); connect(toolbarPaste, SIGNAL(triggered()), this, SLOT(pasteObject())); toolbar->addSeparator(); toolbar->addAction(KStandardAction::preferences(this, SLOT(preferences()), toolbar)); toolbar->addSeparator(); toolbar->addAction(KStandardAction::quit(this, SLOT(quit()), toolbar)); addToolBar(toolbar); splitter->setSizes(QList() << config.readEntry("treeWidth", 100) << config.readEntry("panelWidth", 100)); // if (config.readEntry("reloadOnStart", false)) // { // for (int i = 0; i < config.readEntry("openedFiles", 0); ++i) // openPokeMod(recent.urls().at(i)); // } setAutoSaveSettings("MainWindow", true); treePokemod->setModel(new PokemodTreeModel(QStringList(), treePokemod)); } PokeModrUI::~PokeModrUI() { // delete m_recent; // on_actionQuit_triggered(); } void PokeModrUI::closeEvent(QCloseEvent* event) { quit(); event->accept(); } void PokeModrUI::setChangedTitle(const bool changed) { // TODO: set the title // if (formPanel->widget()) // setWindowTitle(QString::fromUtf8("%1%2 - PokéModr").arg(static_cast(formPanel->widget())->original()->pokemod()->title()).arg(c ? "*" : "")); // else // setWindowTitle(QString::fromUtf8("PokéModr")); } void PokeModrUI::newPokemod() { // TODO: add a blank pokemod to the tree } void PokeModrUI::openPokemod() { QFile file(KFileDialog::getOpenFileName(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMods"), this)); if (file.open(QIODevice::ReadOnly)) { // TODO: open the file into the tree file.close(); } } void PokeModrUI::openPokemod(const KUrl& path) { if (path.isLocalFile()) { // m_pokemods.append(new Pokemod(path.path())); m_recent->addUrl(path); m_recent->saveEntries(m_config); } } void PokeModrUI::savePokemod() { // TODO: Save the current pokemod with the object open // if (!treePokemod->currentItem()) // return; // static_cast(treePokemod->currentItem())->save(); // static_cast(static_cast(treePokemod->currentItem())->object())->pokemod()->save(); } void PokeModrUI::saveAsPokemod() { // TODO: Save the current pokemod to a new file // if (!treePokemod->currentItem()) // return; // QString dir = KFileDialog::existingDirectory(KUrl(KStandardDirs::locateLocal("data", "pokegen/pokemods", true)), this, QString::fromUtf8("Open PokéMod")); // if (dir != "") // { // static_cast(treePokemod->currentItem())->save(); // static_cast(treePokemod->currentItem())->pokemod()->setPath(dir); // } } void PokeModrUI::closePokeMod() { // TODO: Close the Pokemod with the current editor open // if (formPanel->widget()) // { // ObjectUI* o = static_cast(formPanel->widget()); // const Pokemod* p = o->original()->pokemod(); // if (!o->close()) // return; // switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", "Unsaved PokéMod")) // { // case KMessageBox::Yes: // on_actionSave_triggered(); // case KMessageBox::No: // break; // case KMessageBox::Cancel: // return; // } // for (QMutableListIterator i(m_pokemods); i.hasNext(); i.next()) // { // if (i.value() == p) // { // i.remove(); // break; // } // } // delete p; // } } void PokeModrUI::quit() { // TODO: clean up the tree // while (m_pokemods.size()) // closePokeMod(); // if (m_clipboard) // delete m_clipboard; close(); } void PokeModrUI::cutObject() { // TODO: cut the item // if (!treePokemod->currentItem()) // return; // if (m_clipboard) // delete m_clipboard; // m_clipboard = static_cast(treePokemod->currentItem())->cut(); } void PokeModrUI::copyObject() { // TODO: copy the item // if (!treePokemod->currentItem()) // return; // if (m_clipboard) // delete m_clipboard; // m_clipboard = static_cast(treePokemod->currentItem())->copy(); } void PokeModrUI::pasteObject() { // TODO: paste the item // if (!m_clipboard || !treePokemod->currentItem()) // return; // static_cast(treePokemod->currentItem())->paste(m_clipboard); } void PokeModrUI::preferences() { // TODO: preferences } void PokeModrUI::on_splitter_splitterMoved() { m_config.writeEntry("treeWidth", splitter->sizes()[0]); m_config.writeEntry("panelWidth", splitter->sizes()[1]); } void PokeModrUI::on_treePokemod_clicked(const QModelIndex& index) { // TODO: update the panel with the new widget needed QWidget* widget = treePokemod->editorWidget(index); if (widget) { if (formPanel->widget()) { if (!static_cast(formPanel->widget())->close()) return; } formPanel->setWidget(widget); formPanel->show(); } } void PokeModrUI::on_treePokemod_customContextMenuRequested(const QPoint& position) { // TODO: figure out which item was clicked // if (treePokemod->itemAt(position)) // static_cast(treePokemod->itemAt(position))->makeMenu(position); // else // { // } }