/* * 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 "MapScene.h" // Sigmodr includes #include "EffectItem.h" #include "TileItem.h" #include "TrainerItem.h" #include "WarpItem.h" // Sigmod includes #include "../sigmod/Map.h" #include "../sigmod/MapEffect.h" #include "../sigmod/MapTile.h" #include "../sigmod/MapTrainer.h" #include "../sigmod/MapWarp.h" #include "../sigmod/Tile.h" // KDE includes #include #include Sigmodr::MapScene::MapScene(Sigmod::Map* map, QObject* parent) : QGraphicsScene(parent), m_map(map) { connect(this, SIGNAL(changed(QList)), this, SIGNAL(changed())); for (int i = 0; i < m_map->effectCount(); ++i) addItem(new EffectItem(m_map->effect(i), this)); for (int i = 0; i < m_map->tileCount(); ++i) addItem(new TileItem(m_map->tile(i), this)); for (int i = 0; i < m_map->trainerCount(); ++i) addItem(new TrainerItem(m_map->trainer(i), this)); for (int i = 0; i < m_map->warpCount(); ++i) addItem(new WarpItem(m_map->warp(i), this)); typeChanged("Warps"); } void Sigmodr::MapScene::addTile() { KDialog* dialog = new KDialog; dialog->setCaption("New Tile"); KComboBox* combo = new KComboBox; for (int i = 0; i < m_map->sigmod()->tileCount(); ++i) combo->addItem(m_map->sigmod()->tile(i)->name()); dialog->setMainWidget(combo); if (dialog->exec() == KDialog::Ok) { Sigmod::MapTile* tile = m_map->newTile(); tile->setTile(m_map->sigmod()->tile(combo->currentIndex())->id()); TileItem* item = new TileItem(tile, this); addItem(item); m_tiles[tile] = item; } delete dialog; } void Sigmodr::MapScene::removeTiles() { QList items = selectedItems(); foreach (QGraphicsItem* item, items) { if (m_effects.key(static_cast(item))) { Sigmod::MapEffect* effect = m_effects.key(static_cast(item)); m_map->deleteEffectById(effect->id()); delete m_effects[effect]; m_effects.remove(effect); } else if (m_tiles.key(static_cast(item))) { Sigmod::MapTile* tile = m_tiles.key(static_cast(item)); m_map->deleteTileById(tile->id()); delete m_tiles[tile]; m_tiles.remove(tile); } else if (m_trainers.key(static_cast(item))) { Sigmod::MapTrainer* trainer = m_trainers.key(static_cast(item)); m_map->deleteTrainerById(trainer->id()); delete m_trainers[trainer]; m_trainers.remove(trainer); } else if (m_warps.key(static_cast(item))) { Sigmod::MapWarp* warp = m_warps.key(static_cast(item)); m_map->deleteWarpById(warp->id()); delete m_warps[warp]; m_warps.remove(warp); } } } void Sigmodr::MapScene::typeChanged(const QString& type) { QGraphicsItem::GraphicsItemFlags effectFlags = 0; QGraphicsItem::GraphicsItemFlags tileFlags = 0; QGraphicsItem::GraphicsItemFlags trainerFlags = 0; QGraphicsItem::GraphicsItemFlags warpFlags = 0; if (type == "Effects") effectFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; else if (type == "Tiles") tileFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; else if (type == "Trainers") trainerFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; else if (type == "Warps") warpFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; foreach (EffectItem* effect, m_effects) effect->setFlags(effectFlags); foreach (TileItem* tile, m_tiles) tile->setFlags(tileFlags); foreach (TrainerItem* trainer, m_trainers) trainer->setFlags(trainerFlags); foreach (WarpItem* warp, m_warps) warp->setFlags(warpFlags); }