AngleSpinBox.cpp   AngleSpinBox.cpp 
/************************************************************************** * /************************************************************************** *
* Copyright (C) 2008 Matthew Gates * * Copyright (C) 2008 Matthew Gates *
* Copyright (C) 2015 Georg Zotti (min/max limits) *
* * * *
* This program is free software; you can redistribute it and/or modify * * 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 * * it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or * * the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of * * but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
skipping to change at line 27 skipping to change at line 28
* 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. * * 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. *
************************************************************************** */ ************************************************************************** */
#include "AngleSpinBox.hpp" #include "AngleSpinBox.hpp"
#include "StelTranslator.hpp" #include "StelTranslator.hpp"
#include <QDebug> #include <QDebug>
#include <QString> #include <QString>
#include <QLineEdit> #include <QLineEdit>
#include <QWidget> #include <QWidget>
#include <QLocale> #include <QLocale>
#include <cmath> #include <limits>
AngleSpinBox::AngleSpinBox(QWidget* parent, DisplayFormat format, PrefixTyp e prefix) AngleSpinBox::AngleSpinBox(QWidget* parent, DisplayFormat format, PrefixTyp e prefix)
: QAbstractSpinBox(parent), : QAbstractSpinBox(parent),
angleSpinBoxFormat(format), angleSpinBoxFormat(format),
currentPrefixType(prefix), currentPrefixType(prefix),
decimalPlaces(2), decimalPlaces(2),
radAngle(0.0) radAngle(0.0),
minRad(-std::numeric_limits<double>::max()),
maxRad( std::numeric_limits<double>::max())
{ {
connect(this, SIGNAL(editingFinished()), this, SLOT(updateValue())); connect(this, SIGNAL(editingFinished()), this, SLOT(updateValue()));
formatText(); formatText();
setWrapping(false); // but should be set true for longitudinal cycli ng
} }
const QString AngleSpinBox::positivePrefix(PrefixType prefix) const QString AngleSpinBox::positivePrefix(PrefixType prefix)
{ {
switch(prefix) switch(prefix)
{ {
case NormalPlus: case NormalPlus:
return("+"); return("+");
break; break;
case Longitude: case Longitude:
skipping to change at line 124 skipping to change at line 128
cPosMax = str.indexOf(QRegExp("[s\"]"), 0)+1; cPosMax = str.indexOf(QRegExp("[s\"]"), 0)+1;
if (cursorPos > cPosMin && cursorPos <= cPosMax) { if (cursorPos > cPosMin && cursorPos <= cPosMax) {
return SectionSeconds; return SectionSeconds;
} }
return SectionNone; return SectionNone;
} }
void AngleSpinBox::stepBy (int steps) void AngleSpinBox::stepBy (int steps)
{ {
const int cusorPos = lineEdit()->cursorPosition(); const int cursorPos = lineEdit()->cursorPosition();
const AngleSpinBox::AngleSpinboxSection sec = getCurrentSection(); const AngleSpinBox::AngleSpinboxSection sec = getCurrentSection();
switch (sec) switch (sec)
{ {
case SectionPrefix: case SectionPrefix:
{ {
radAngle = -radAngle; radAngle = -radAngle;
break; break;
} }
case SectionDegreesHours: case SectionDegreesHours:
{ {
skipping to change at line 166 skipping to change at line 170
radAngle += M_PI/180.*steps/3600.; radAngle += M_PI/180.*steps/3600.;
else else
radAngle += M_PI/12.*steps/3600.; radAngle += M_PI/12.*steps/3600.;
break; break;
} }
default: default:
{ {
return; return;
} }
} }
if (wrapping())
{
if (radAngle > maxRad)
radAngle=minRad+(radAngle-maxRad);
else if (radAngle < minRad)
radAngle=maxRad-(minRad-radAngle);
}
radAngle=qMin(radAngle, maxRad);
radAngle=qMax(radAngle, minRad);
formatText(); formatText();
lineEdit()->setCursorPosition(cusorPos); lineEdit()->setCursorPosition(cursorPos);
emit(valueChanged()); emit(valueChanged());
} }
QValidator::State AngleSpinBox::validate(QString& input, int& pos) const QValidator::State AngleSpinBox::validate(QString& input, int& pos) const
{ {
Q_UNUSED(pos); Q_UNUSED(pos);
QValidator::State state; QValidator::State state;
stringToDouble(input, &state); stringToDouble(input, &state);
return state; return state;
} }
skipping to change at line 198 skipping to change at line 211
return (StepUpEnabled|StepDownEnabled); return (StepUpEnabled|StepDownEnabled);
} }
double AngleSpinBox::valueRadians() double AngleSpinBox::valueRadians()
{ {
return radAngle; return radAngle;
} }
double AngleSpinBox::valueDegrees() double AngleSpinBox::valueDegrees()
{ {
return (radAngle*360.)/(2.*M_PI); return radAngle*(180./M_PI);
} }
double AngleSpinBox::stringToDouble(QString input, QValidator::State* state , PrefixType prefix) const double AngleSpinBox::stringToDouble(QString input, QValidator::State* state , PrefixType prefix) const
{ {
if (prefix==Unknown) if (prefix==Unknown)
{ {
prefix=currentPrefixType; prefix=currentPrefixType;
} }
int sign=1; int sign=1;
if (input.startsWith(negativePrefix(prefix), Qt::CaseInsensitive)) if (input.startsWith(negativePrefix(prefix), Qt::CaseInsensitive))
skipping to change at line 327 skipping to change at line 340
void AngleSpinBox::updateValue(void) void AngleSpinBox::updateValue(void)
{ {
QValidator::State state; QValidator::State state;
double a = stringToDouble(lineEdit()->text(), &state); double a = stringToDouble(lineEdit()->text(), &state);
if (state != QValidator::Acceptable) if (state != QValidator::Acceptable)
return; return;
if (radAngle == a) if (radAngle == a)
return; return;
radAngle = a; radAngle = a;
if (wrapping())
{
if (radAngle > maxRad)
radAngle=minRad+(radAngle-maxRad);
else if (radAngle < minRad)
radAngle=maxRad-(minRad-radAngle);
}
radAngle=qMin(radAngle, maxRad);
radAngle=qMax(radAngle, minRad);
formatText(); formatText();
emit(valueChanged()); emit(valueChanged());
} }
void AngleSpinBox::setRadians(double radians) void AngleSpinBox::setRadians(double radians)
{ {
radAngle = radians; radAngle = radians;
formatText(); formatText();
} }
 End of changes. 9 change blocks. 
5 lines changed or deleted 29 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/