diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-02-23 11:20:47 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-02-23 11:20:47 -0500 |
| commit | 7aff48012c3040a675543a0ff3d23af6cb8a8638 (patch) | |
| tree | 6dd17b90d1f1c6ba9b0b7c5ddc40c2a849c25286 /sigmodr/widgets/CoinListItemUI.cpp | |
| parent | 25ec942048336dde5e1a17e6c75e15e4f8d8290d (diff) | |
Started restructuring how sigmodr is built and moving things into libraries
Diffstat (limited to 'sigmodr/widgets/CoinListItemUI.cpp')
| -rw-r--r-- | sigmodr/widgets/CoinListItemUI.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/sigmodr/widgets/CoinListItemUI.cpp b/sigmodr/widgets/CoinListItemUI.cpp new file mode 100644 index 00000000..7910ed59 --- /dev/null +++ b/sigmodr/widgets/CoinListItemUI.cpp @@ -0,0 +1,110 @@ +/* + * Copyright 2008-2009 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/>. + */ + +// Header include +#include "CoinListItemUI.h" + +// Sigmod includes +#include "../sigmod/CoinListItem.h" +#include "../sigmod/Item.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Species.h" + +// Qt includes +#include <QtGui/QButtonGroup> + +Sigmodr::CoinListItemUI::CoinListItemUI(Sigmod::CoinListItem* item, QWidget* parent) : + ObjectUI(parent), + m_buttonGroup(new QButtonGroup(this)), + m_lastType(-1) +{ + setupUi(this); + setObjects(item, new Sigmod::CoinListItem(*item)); +} + +Sigmodr::CoinListItemUI::~CoinListItemUI() +{ +} + +void Sigmodr::CoinListItemUI::initGui() +{ + setTabOrder(varItem, varSpecies); + setTabOrder(varSpecies, varObject); + setTabOrder(varObject, varCost); + m_buttonGroup->addButton(varItem, Sigmod::CoinListItem::Item); + m_buttonGroup->addButton(varSpecies, Sigmod::CoinListItem::Species); + connect(m_buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(typeChanged(int))); +} + +void Sigmodr::CoinListItemUI::setGui() +{ + bool resetObjects = (qobject_cast<Sigmod::CoinListItem*>(modified())->type() != m_lastType); + m_buttonGroup->button(qobject_cast<Sigmod::CoinListItem*>(modified())->type())->setChecked(true); + m_lastType = qobject_cast<Sigmod::CoinListItem*>(modified())->type(); + if (resetObjects) + { + const bool blocked = varObject->blockSignals(true); + varObject->clear(); + if (qobject_cast<Sigmod::CoinListItem*>(modified())->type() == Sigmod::CoinListItem::Item) + { + for (int i = 0; i < sigmod()->itemCount(); ++i) + { + const Sigmod::Item* item = sigmod()->item(i); + varObject->addItem(item->name(), item->id()); + } + } + else + { + for (int i = 0; i < sigmod()->speciesCount(); ++i) + { + const Sigmod::Species* species = sigmod()->species(i); + varObject->addItem(species->name(), species->id()); + } + } + varObject->blockSignals(blocked); + } + varObject->setCurrentIndex(varObject->findData(qobject_cast<Sigmod::CoinListItem*>(modified())->object())); + varCost->setValue(qobject_cast<Sigmod::CoinListItem*>(modified())->cost()); +} + +void Sigmodr::CoinListItemUI::apply() +{ + *qobject_cast<Sigmod::CoinListItem*>(original()) = *qobject_cast<Sigmod::CoinListItem*>(modified()); + emit(changed(false)); +} + +void Sigmodr::CoinListItemUI::discard() +{ + *qobject_cast<Sigmod::CoinListItem*>(modified()) = *qobject_cast<Sigmod::CoinListItem*>(original()); + setGui(); + emit(changed(false)); +} + +void Sigmodr::CoinListItemUI::typeChanged(const int type) +{ + qobject_cast<Sigmod::CoinListItem*>(modified())->setType(Sigmod::CoinListItem::Type(type)); +} + +void Sigmodr::CoinListItemUI::on_varObject_activated(const int obey) +{ + qobject_cast<Sigmod::CoinListItem*>(modified())->setObject(varObject->itemData(obey).toInt()); +} + +void Sigmodr::CoinListItemUI::on_varCost_valueChanged(const int cost) +{ + qobject_cast<Sigmod::CoinListItem*>(modified())->setCost(cost); +} |
