diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-17 23:34:36 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-17 23:34:36 +0000 |
| commit | 6679f5cffa9d35a23b76605ddfbf3257f882b6ee (patch) | |
| tree | c8e41854a60b64e8569939bca6b827807175ef9a /pokemodr/PokemodUI.cpp | |
| parent | 05980e883719b1c8ebde1bd2fcbf4f8c16df7ad6 (diff) | |
[FIX] Frac -> Fraction
[FIX] ImageCache and Ini removed
[FIX] Fraction/Point widgets moved to pokemodr
[FIX] Copy ctors made for pokemod classes
[FIX] Ctors in pokemod fixed
[FIX] Copyright headers fixed in pokemodr
[FIX] PokeModr updated to new API and fixed in some places
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@99 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/PokemodUI.cpp')
| -rw-r--r-- | pokemodr/PokemodUI.cpp | 279 |
1 files changed, 116 insertions, 163 deletions
diff --git a/pokemodr/PokemodUI.cpp b/pokemodr/PokemodUI.cpp index 57ec83ea..63561a2e 100644 --- a/pokemodr/PokemodUI.cpp +++ b/pokemodr/PokemodUI.cpp @@ -1,49 +1,48 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: pokegen/PokemodUI.cpp -// Purpose: Pokemod UI form handling -// Author: Ben Boeckel -// Modified by: Ben Boeckel -// Created: Fri Feb 22 16:30:10 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 <http://www.gnu.org/licenses/>. -///////////////////////////////////////////////////////////////////////////// +/* + * Copyright 2008 Ben Boeckel <MathStuf@gmail.com> + * + * 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 <http://www.gnu.org/licenses/>. + */ -#include <QMetaObject> +// Qt includes #include <QSize> +// General includes #include <BugCatcher.h> #include <Exception.h> -#include <ImageCache.h> +// Pokemod includes #include <Item.h> #include <Map.h> #include <MapWarp.h> +// PokeModr includes #include "FileDialog.h" -#include "PokemodUI.h" #include "TypechartWidgetItem.h" -PokemodUI::PokemodUI(Pokemod* p, QWidget* parent) : +// Header include +#include "PokemodUI.h" + +PokemodUI::PokemodUI(Pokemod* pokemod, QWidget* parent) : ObjectUI(parent), - lastMap(-1), - pokemod(p), - pokemod_mod(new Pokemod(*p)) + m_lastMap(-1), + m_pokemod(pokemod), + m_pokemod_mod(new Pokemod(*pokemod)) { setupUi(this); QMetaObject::connectSlotsByName(this); - setObjects(pokemod, pokemod_mod); + setObjects(m_pokemod, m_pokemod_mod); connect(this, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool))); init(); } @@ -51,21 +50,21 @@ PokemodUI::PokemodUI(Pokemod* p, QWidget* parent) : void PokemodUI::refreshGui() { varMap->clear(); - for (int i = 0; i < pokemod->getPokemod()->getMapCount(); ++i) + for (int i = 0; i < m_pokemod->mapCount(); ++i) { - const Map* m = pokemod->getPokemod()->getMap(i); - varMap->addItem(m->getName()); - varMap->setItemData(i, m->getId()); + const Map* map = m_pokemod->map(i); + varMap->addItem(map->name()); + varMap->setItemData(i, map->id()); } - varTypechart->setRowCount(pokemod->getTypeCount()); - varTypechart->setColumnCount(pokemod->getTypeCount()); + varTypechart->setRowCount(m_pokemod->typeCount()); + varTypechart->setColumnCount(m_pokemod->typeCount()); QStringList types; - Matrix<Frac>* tc = pokemod->getTypeChart(); - for (int i = 0; i < pokemod->getTypeCount(); ++i) + Matrix<Fraction>* typeChart = m_pokemod->typeChart(); + for (int i = 0; i < m_pokemod->typeCount(); ++i) { - types << pokemod->getItem(i)->getName(); - for (int j = 0; j < pokemod->getTypeCount(); ++j) - static_cast<TypechartWidgetItem*>(varTypechart->item(i, j))->setData(Qt::EditRole, qVariantFromValue(static_cast<void*>(&(*tc)(i, j)))); + types << m_pokemod->item(i)->name(); +// for (int j = 0; j < m_pokemod->typeCount(); ++j) +// static_cast<TypechartWidgetItem*>(varTypechart->item(i, j))->setData(Qt::EditRole, QVariant::fromValue((*typeChart)(i, j))); } varTypechart->setVerticalHeaderLabels(types); varTypechart->setHorizontalHeaderLabels(types); @@ -73,164 +72,128 @@ void PokemodUI::refreshGui() void PokemodUI::setGui() { - const bool resetWarps = (pokemod_mod->getStartMap() == lastMap); - varTitle->setText(pokemod_mod->getTitle()); - varVersion->setText(pokemod_mod->getVersion()); - varDescription->setText(pokemod_mod->getDescription()); - varMap->setCurrentIndex(varMap->findData(pokemod_mod->getStartMap())); - lastMap = pokemod_mod->getStartMap(); + const bool resetWarps = (m_pokemod_mod->startMap() == m_lastMap); + varTitle->setText(m_pokemod_mod->title()); + varVersion->setText(m_pokemod_mod->version()); + varDescription->setText(m_pokemod_mod->description()); + varMap->setCurrentIndex(varMap->findData(m_pokemod_mod->startMap())); + m_lastMap = m_pokemod_mod->startMap(); if (resetWarps) { varWarp->clear(); - int index = pokemod->getMapIndex(pokemod_mod->getStartMap()); + int index = m_pokemod->mapIndex(m_pokemod_mod->startMap()); if (index != INT_MAX) { try { - const Map* m = pokemod->getMap(index); - for (int i = 0; i < m->getWarpCount(); ++i) + const Map* map = m_pokemod->map(index); + for (int i = 0; i < map->warpCount(); ++i) { - const MapWarp* w = m->getWarp(i); - varWarp->addItem(w->getName()); - varWarp->setItemData(i, w->getId()); + const MapWarp* warp = map->warp(i); + varWarp->addItem(warp->name()); + varWarp->setItemData(i, warp->id()); } } - catch (BoundsException& e) + catch (BoundsException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } } } - varWarp->setCurrentIndex(varWarp->findData(pokemod_mod->getStartWarp())); - varSuperPCUsername->setText(pokemod_mod->getSuperPCUname()); - varSuperPCPassword->setText(pokemod_mod->getSuperPCPasswd()); - try - { - varWalkSkin->setIcon(ImageCache::open(pokemod->getWalkSkin())); - } - catch (OpenException& e) - { - } - try - { - varBikeSkin->setIcon(ImageCache::open(pokemod->getBikeSkin())); - } - catch (OpenException& e) - { - } - try - { - varFlySkin->setIcon(ImageCache::open(pokemod->getFlySkin())); - } - catch (OpenException& e) - { - } - try - { - varSurfSkin->setIcon(ImageCache::open(pokemod->getSurfSkin())); - } - catch (OpenException& e) - { - } - try - { - varFishSkin->setIcon(ImageCache::open(pokemod->getFishSkin())); - } - catch (OpenException& e) - { - } - try - { - varSurfFishSkin->setIcon(ImageCache::open(pokemod->getSurfFishSkin())); - } - catch (OpenException& e) - { - } + varWarp->setCurrentIndex(varWarp->findData(m_pokemod_mod->startWarp())); + varSuperPCUsername->setText(m_pokemod_mod->superPCUname()); + varSuperPCPassword->setText(m_pokemod_mod->superPCPasswd()); + varWalkSkin->setIcon(m_pokemod->walkSkin()); + varBikeSkin->setIcon(m_pokemod->bikeSkin()); + varFlySkin->setIcon(m_pokemod->flySkin()); + varSurfSkin->setIcon(m_pokemod->surfSkin()); + varFishSkin->setIcon(m_pokemod->fishSkin()); + varSurfFishSkin->setIcon(m_pokemod->surfFishSkin()); } void PokemodUI::on_buttonApply_clicked() { - *pokemod = *pokemod_mod; + *m_pokemod = *m_pokemod_mod; emit(changed(false)); } void PokemodUI::on_buttonDiscard_clicked() { - *pokemod_mod = *pokemod; + *m_pokemod_mod = *m_pokemod; setGui(); emit(changed(false)); } -void PokemodUI::on_varTitle_textChanged(const QString& t) +void PokemodUI::on_varTitle_textChanged(const QString& title) { - pokemod_mod->setTitle(t); + m_pokemod_mod->setTitle(title); emit(changed(true)); } -void PokemodUI::on_varVersion_textChanged(const QString& v) +void PokemodUI::on_varVersion_textChanged(const QString& version) { - pokemod_mod->setVersion(v); + m_pokemod_mod->setVersion(version); emit(changed(true)); } void PokemodUI::on_varDescription_textChanged() { - pokemod_mod->setDescription(varDescription->toPlainText()); + m_pokemod_mod->setDescription(varDescription->toPlainText()); emit(changed(true)); } -void PokemodUI::on_varMap_currentIndexChanged(const int s) +void PokemodUI::on_varMap_currentIndexChanged(const int map) { try { - pokemod_mod->setStartMap(s); + m_pokemod_mod->setStartMap(map); emit(changed(true)); } - catch (BoundsException& e) + catch (BoundsException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); setGui(); } } -void PokemodUI::on_varWarp_currentIndexChanged(const int s) +void PokemodUI::on_varWarp_currentIndexChanged(const int warp) { try { - pokemod_mod->setStartWarp(s); + m_pokemod_mod->setStartWarp(warp); emit(changed(true)); } - catch (BoundsException& e) + catch (BoundsException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); setGui(); } } -void PokemodUI::on_varSuperPCUsername_textChanged(const QString& u) +void PokemodUI::on_varSuperPCUsername_textChanged(const QString& username) { - pokemod_mod->setSuperPCUname(u); + m_pokemod_mod->setSuperPCUname(username); emit(changed(true)); } -void PokemodUI::on_varSuperPCPassword_textChanged(const QString& p) +void PokemodUI::on_varSuperPCPassword_textChanged(const QString& password) { - pokemod_mod->setSuperPCPasswd(p); + m_pokemod_mod->setSuperPCPasswd(password); emit(changed(true)); } void PokemodUI::on_varWalkSkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setWalkSkin(dlg.selectedUrl()); + m_pokemod->setWalkSkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -238,16 +201,16 @@ void PokemodUI::on_varWalkSkin_pressed() void PokemodUI::on_varBikeSkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setBikeSkin(dlg.selectedUrl()); + m_pokemod->setBikeSkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -255,16 +218,16 @@ void PokemodUI::on_varBikeSkin_pressed() void PokemodUI::on_varFlySkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setFlySkin(dlg.selectedUrl()); + m_pokemod->setFlySkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -272,16 +235,16 @@ void PokemodUI::on_varFlySkin_pressed() void PokemodUI::on_varSurfSkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setSurfSkin(dlg.selectedUrl()); + m_pokemod->setSurfSkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -289,16 +252,16 @@ void PokemodUI::on_varSurfSkin_pressed() void PokemodUI::on_varFishSkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setFishSkin(dlg.selectedUrl()); + m_pokemod->setFishSkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -306,16 +269,16 @@ void PokemodUI::on_varFishSkin_pressed() void PokemodUI::on_varSurfFishSkin_pressed() { - FileDialog dlg("*.png", QSize(192, 168)); - if (dlg.show()) + FileDialog dialog(QSize(192, 168)); + if (dialog.exec()) { try { - pokemod->setSurfFishSkin(dlg.selectedUrl()); + m_pokemod->setSurfFishSkin(QPixmap(dialog.selectedFile())); } - catch (SaveException& e) + catch (SaveException& exception) { - BugCatcher::report(e); + BugCatcher::report(exception); } setGui(); } @@ -323,23 +286,13 @@ void PokemodUI::on_varSurfFishSkin_pressed() void PokemodUI::on_varTypechart_currentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) { - disconnect(varEffectivenessNum, SIGNAL(valueChanged(int)), static_cast<TypechartWidgetItem*>(previous), SLOT(setNum(int))); - disconnect(varEffectivenessDenom, SIGNAL(valueChanged(int)), static_cast<TypechartWidgetItem*>(previous), SLOT(setDenom(int))); - TypechartWidgetItem* twi = static_cast<TypechartWidgetItem*>(current); - varEffectivenessNum->setValue(static_cast<Frac*>(twi->data(Qt::EditRole).value<void*>())->getNum()); - varEffectivenessNum->setMaximum(static_cast<Frac*>(twi->data(Qt::EditRole).value<void*>())->getDenom()); - varEffectivenessDenom->setValue(static_cast<Frac*>(twi->data(Qt::EditRole).value<void*>())->getDenom()); - connect(varEffectivenessNum, SIGNAL(valueChanged(int)), twi, SLOT(setNum(int))); - connect(varEffectivenessDenom, SIGNAL(valueChanged(int)), twi, SLOT(setDenom(int))); -} - -void PokemodUI::on_varEffectivenessNum_valueChanged() -{ - emit(changed(true)); + disconnect(varEffectiveness, SIGNAL(valueChanged(Fraction)), static_cast<TypechartWidgetItem*>(previous), SLOT(setValue(Fraction))); + TypechartWidgetItem* widgetItem = static_cast<TypechartWidgetItem*>(current); +// varEffectiveness->setValue(widgetItem->data(Qt::EditRole).value<Fraction>()); + connect(varEffectiveness, SIGNAL(valueChanged(Fraction)), widgetItem, SLOT(setValue(Fraction))); } -void PokemodUI::on_varEffectivenessDenom_valueChanged(const int e) +void PokemodUI::on_varEffectiveness_valueChanged() { - varEffectivenessNum->setMaximum(e); emit(changed(true)); } |
