diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-02-26 01:14:23 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-02-26 01:14:23 -0500 |
| commit | a7f0f1c9496014f87a29f9dda239e0bf03d9cbdd (patch) | |
| tree | efded3513ff93452b83a75d40987091b81a1b3c0 /sigmodr/widgets/FractionWidget.cpp | |
| parent | 3f9dc2eda97999a1f2708db987d1c0d118e77755 (diff) | |
| download | sigen-a7f0f1c9496014f87a29f9dda239e0bf03d9cbdd.tar.gz sigen-a7f0f1c9496014f87a29f9dda239e0bf03d9cbdd.tar.xz sigen-a7f0f1c9496014f87a29f9dda239e0bf03d9cbdd.zip | |
Moved Script and Fraction widgets to sigmodr/corewidgets
Diffstat (limited to 'sigmodr/widgets/FractionWidget.cpp')
| -rw-r--r-- | sigmodr/widgets/FractionWidget.cpp | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/sigmodr/widgets/FractionWidget.cpp b/sigmodr/widgets/FractionWidget.cpp deleted file mode 100644 index 4388661e..00000000 --- a/sigmodr/widgets/FractionWidget.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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 "FractionWidget.h" - -// KDE includes -#include <KIntNumInput> -#include <KLineEdit> - -// Qt includes -#include <QtCore/QFile> -#include <QtUiTools/QUiLoader> - -// C includes -#include <climits> - -using namespace Sigcore; -using namespace Sigmodr::Widgets; - -FractionWidget::FractionWidget(QWidget* parent, const Fraction& value) : - QWidget(parent), - m_value(value), - m_behavior(Any) -{ - QFile file(":/gui/weather.ui"); - file.open(QFile::ReadOnly); - QWidget *formWidget = QUiLoader().load(&file, this); - file.close(); - ui_numerator = formWidget->findChild<KIntNumInput*>("varNumerator"); - ui_denominator = formWidget->findChild<KIntNumInput*>("varDenominator"); - ui_value = formWidget->findChild<KLineEdit*>("varValue"); - connect(ui_numerator, SIGNAL(valueChanged(int)), this, SLOT(numeratorChanged(int))); - connect(ui_denominator, SIGNAL(valueChanged(int)), this, SLOT(denominatorChanged(int))); - connect(this, SIGNAL(valueChanged(Fraction)), SLOT(updateValue())); - connect(this, SIGNAL(valueChanged(Fraction)), SLOT(resetRanges())); - connect(this, SIGNAL(behaviorChanged(Behavior)), SLOT(resetRanges())); - resetRanges(); -} - -FractionWidget::Behavior FractionWidget::behavior() const -{ - return m_behavior; -} - -Fraction FractionWidget::value() const -{ - return m_value; -} - -void FractionWidget::setBehavior(const Behavior behavior) -{ - m_behavior = behavior; - emit(behaviorChanged(m_behavior)); -} - -void FractionWidget::setValue(const Fraction& value) -{ - if (!ui_value->text().isEmpty() && (m_value == value)) - return; - m_value = value; - emit(valueChanged(m_value)); -} - -void FractionWidget::updateValue() -{ - ui_value->setText(QString::number(double(m_value), 'g', 7)); -} - -void FractionWidget::numeratorChanged(const int numerator) -{ - m_value.setNumerator(numerator); - emit(valueChanged(m_value)); -} - -void FractionWidget::denominatorChanged(const int denominator) -{ - m_value.setDenominator(denominator); - emit(valueChanged(m_value)); -} - -void FractionWidget::resetRanges() -{ - ui_numerator->setValue(m_value.numerator()); - ui_denominator->setValue(m_value.denominator()); - int numMin = 0; - int numMax = INT_MAX; - int denomMin = 1; - int denomMax = INT_MAX; - switch (m_behavior) - { - case NonZero: - numMin = 1; - case Proper: - numMax = m_value.denominator(); - break; - case Improper: - denomMax = m_value.numerator(); - case AnyButZero: - numMin = 1; - default: - break; - } - ui_numerator->setRange(numMin, numMax); - ui_denominator->setRange(denomMin, denomMax); -} |
