/////////////////////////////////////////////////////////////////////////////
// Name: pokegen/MapUI.cpp
// Purpose: Map UI form handling
// Author: Ben Boeckel
// Modified by: Ben Boeckel
// Created: Sat Feb 2 00:50:25 2008
// Copyright: ©2007-2008 Ben Boeckel and Nerdy Productions
// Licence:
// 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 .
/////////////////////////////////////////////////////////////////////////////
#include
#include
#include
#include
#include
#include
#include "MapUI.h"
MapUI::MapUI(Map* m, QWidget* parent) :
ObjectUI(parent),
map(m),
map_mod(new Map(m->getPokemod(), *m, m->getId())),
model(new TilemapModel(this, map_mod->getMap(), map->getPokemod())),
delegate(new TileDelegate(this))
{
setupUi(this);
QMetaObject::connectSlotsByName(this);
setObjects(map, map_mod);
connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setDisabled(bool)));
for (int i = 0; i < map->getWarpCount(); ++i)
{
const MapWarp* w = map->getWarp(i);
varFlyWarp->addItem(w->getName());
varFlyWarp->setItemData(i, w->getId());
}
varType->addItems(Map::TypeStr);
varTilemap->setModel(model);
varTilemap->setItemDelegate(delegate);
setGui();
}
// KToolbar MapUI::getToolbar(QWidget* parent)
// {
//
// }
void MapUI::setGui()
{
varName->setText(map_mod->getName());
boxFlyWarp->setChecked((map_mod->getFlyWarp() == -1) ? Qt::Unchecked : Qt::Checked);
varFlyWarp->setCurrentIndex(varFlyWarp->findData(map_mod->getFlyWarp()));
varType->setCurrentIndex(map_mod->getType());
}
void MapUI::on_buttonApply_clicked()
{
*map = *map_mod;
emit(changed(false));
}
void MapUI::on_buttonDiscard_clicked()
{
*map_mod = *map;
emit(changed(false));
setGui();
}
void MapUI::on_varName_textChanged(const QString& n)
{
map_mod->setName(n);
emit(changed(true));
}
void MapUI::on_boxFlyWarp_toggled()
{
map_mod->setFlyWarp(-1);
emit(changed(true));
}
void MapUI::on_varFlyWarp_currentIndexChanged(const int f)
{
try
{
map_mod->setFlyWarp(varFlyWarp->itemData(f).toInt());
emit(changed(true));
}
catch (BoundsException& e)
{
BugCatcher::report(e);
setGui();
}
}
void MapUI::on_varType_currentIndexChanged(const int t)
{
try
{
map_mod->setType(t);
emit(changed(true));
}
catch (BoundsException& e)
{
BugCatcher::report(e);
setGui();
}
}
void MapUI::on_buttonAddColumn_pressed()
{
model->insertColumns(varTilemap->currentIndex().column(), 1);
}
void MapUI::on_buttonAddRow_pressed()
{
model->insertRows(varTilemap->currentIndex().row(), 1);
}
void MapUI::on_buttonDeleteColumn_pressed()
{
model->removeColumns(varTilemap->currentIndex().column(), 1);
}
void MapUI::on_buttonDeleteRow_pressed()
{
model->removeRows(varTilemap->currentIndex().row(), 1);
}