diff options
Diffstat (limited to 'pokemodr/FractionWidget.cpp')
| -rw-r--r-- | pokemodr/FractionWidget.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/pokemodr/FractionWidget.cpp b/pokemodr/FractionWidget.cpp new file mode 100644 index 00000000..8ef3ff95 --- /dev/null +++ b/pokemodr/FractionWidget.cpp @@ -0,0 +1,85 @@ +/* + * 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/>. + */ + +// Qt includes +#include <QMetaObject> +#include <QString> + +// Header include +#include "FractionWidget.h" + +FractionWidget::FractionWidget(QWidget* parent, const Fraction& value) : + QWidget(parent), + m_behavior(-1), + m_value(value) +{ + setupUi(this); + QMetaObject::connectSlotsByName(this); + connect(this, SIGNAL(valueChanged(Fraction)), SLOT(updateValue())); +} + +void FractionWidget::setBehavior(const int behavior) +{ + m_behavior = behavior; + m_value = Fraction(1, 1); + varDenominator->setValue(1); + varNumerator->setValue(1); + emit(valueChanged(m_value)); +} + +void FractionWidget::setValue(const Fraction& value) +{ + m_value = value; + varDenominator->setValue(m_value.denominator()); + varNumerator->setValue(m_value.numerator()); + emit(valueChanged(m_value)); +} + +int FractionWidget::behavior() const +{ + return m_behavior; +} + +Fraction FractionWidget::value() const +{ + return m_value; +} + +void FractionWidget::on_varNumerator_valueChanged(const int& numerator) +{ + m_value.setNumerator(numerator); + if (0 < m_behavior) + varDenominator->setMaximum(numerator); + else + varDenominator->setMaximum(INT_MAX); + emit(valueChanged(m_value)); +} + +void FractionWidget::on_varDenominator_valueChanged(const int& denominator) +{ + m_value.setDenominator(denominator); + if (m_behavior < 0) + varNumerator->setMaximum(denominator); + else + varNumerator->setMaximum(INT_MAX); + emit(valueChanged(m_value)); +} + +void FractionWidget::updateValue() +{ + varValue->setText(QString::number(m_value, 'g', 7)); +} |
