/* * 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 "MapUI.h" // PokeModr includes #include "TileDelegate.h" #include "TilemapModel.h" // Pokemod includes #include "../pokemod/Map.h" #include "../pokemod/MapWarp.h" #include "../pokemod/Pokemod.h" // Qt includes #include // KDE includes #include MapUI::MapUI(Map* map, QWidget* parent) : ObjectUI(parent), m_delegate(new TileDelegate(this)) { setupUi(this); setObjects(map, new Map(*map)); m_model = new TilemapModel(this, static_cast(modified())->map(), pokemod()); } MapUI::~MapUI() { delete m_model; delete m_delegate; } void MapUI::initGui() { varType->addItems(Map::TypeStr); varTilemap->horizontalHeader()->setResizeMode(QHeaderView::Fixed); varTilemap->verticalHeader()->setResizeMode(QHeaderView::Fixed); varTilemap->horizontalHeader()->setDefaultSectionSize(64); varTilemap->verticalHeader()->setDefaultSectionSize(64); varTilemap->setModel(m_model); varTilemap->setItemDelegate(m_delegate); } void MapUI::refreshGui() { varFlyWarp->clear(); for (int i = 0; i < static_cast(original())->warpCount(); ++i) { const MapWarp* warp = static_cast(original())->warp(i); varFlyWarp->addItem(warp->name(), warp->id()); } } void MapUI::setGui() { varName->setText(static_cast(modified())->name()); boxFlyWarp->setChecked((static_cast(modified())->flyWarp() == INT_MAX) ? Qt::Unchecked : Qt::Checked); varFlyWarp->setCurrentIndex(varFlyWarp->findData(static_cast(modified())->flyWarp())); varType->setCurrentIndex(static_cast(modified())->type()); buttonDeleteColumn->setEnabled(0 < m_model->columnCount()); buttonDeleteRow->setEnabled(0 < m_model->rowCount()); } void MapUI::apply() { *static_cast(original()) = *static_cast(modified()); emit(changed(false)); } void MapUI::discard() { *static_cast(modified()) = *static_cast(original()); setGui(); emit(changed(false)); } void MapUI::on_varName_textChanged(const QString& name) { const int cursor = varName->cursorPosition(); static_cast(modified())->setName(name); varName->setCursorPosition(cursor); } void MapUI::on_boxFlyWarp_toggled() { static_cast(modified())->setFlyWarp(-1); } void MapUI::on_varFlyWarp_activated(const int flyWarp) { static_cast(modified())->setFlyWarp(varFlyWarp->itemData(flyWarp).toInt()); } void MapUI::on_varType_activated(const int type) { static_cast(modified())->setType(type); } void MapUI::on_buttonAddColumn_pressed() { m_model->addColumn(); emit(changed(true)); } void MapUI::on_buttonAddRow_pressed() { m_model->addRow(); emit(changed(true)); } void MapUI::on_buttonDeleteColumn_pressed() { m_model->removeColumns(varTilemap->currentIndex().column(), 1); emit(changed(true)); } void MapUI::on_buttonDeleteRow_pressed() { m_model->removeRows(varTilemap->currentIndex().row(), 1); emit(changed(true)); } void MapUI::on_buttonInsertColumn_pressed() { m_model->insertColumns(varTilemap->currentIndex().column(), 1); emit(changed(true)); } void MapUI::on_buttonInsertRow_pressed() { m_model->insertRows(varTilemap->currentIndex().row(), 1); emit(changed(true)); }