AngleSpinBox.cpp   AngleSpinBox.cpp 
skipping to change at line 21 skipping to change at line 21
* 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. *
* * * *
* You should have received a copy of the GNU General Public License * * You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the * * along with this program; if not, write to the *
* Free Software Foundation, Inc., * * Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************************************** */ ************************************************************************** */
#include "AngleSpinBox.hpp" #include "AngleSpinBox.hpp"
#include "Translator.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 <cmath>
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),
skipping to change at line 84 skipping to change at line 84
default: default:
return(QLocale().negativeSign()); return(QLocale().negativeSign());
break; break;
} }
} }
AngleSpinBox::~AngleSpinBox() AngleSpinBox::~AngleSpinBox()
{ {
} }
AngleSpinBox::AngleSpinboxSection AngleSpinBox::getCurrentSection() const
{
int cusorPos = lineEdit()->cursorPosition();
const QString str = lineEdit()->text();
int cPosMin = str.indexOf(QRegExp("[+-"+q_("N")+q_("S")+q_("E")+q_("
W")+"]"), 0);
int cPosMax = cPosMin+1;
if (cPosMin==0)
{
// No prefix
cPosMax=0;
}
else if (cusorPos>=cPosMin && cusorPos<cPosMax)
return SectionPrefix;
cPosMin = cPosMax;
cPosMax = str.indexOf(QRegExp(QString("[h%1]").arg(QChar(176))), 0)+
1;
if (cusorPos>=cPosMin && cusorPos<cPosMax)
return SectionDegreesHours;
cPosMin = cPosMax;
cPosMax = str.indexOf(QRegExp("[m']"), 0)+1;
if (cusorPos>=cPosMin && cusorPos<cPosMax)
return SectionMinutes;
cPosMin = cPosMax;
cPosMax = str.indexOf(QRegExp("[s\"]"), 0)+1;
if (cusorPos>=cPosMin && cusorPos<cPosMax)
return SectionSeconds;
return SectionNone;
}
void AngleSpinBox::stepBy (int steps) void AngleSpinBox::stepBy (int steps)
{ {
switch (angleSpinBoxFormat) const int cusorPos = lineEdit()->cursorPosition();
{ const AngleSpinBox::AngleSpinboxSection sec = getCurrentSection();
case DMSLetters: switch (sec)
case DMSSymbols: {
case SectionPrefix:
{ {
radAngle += ((steps*2*M_PI) / (360*60.0)); radAngle = -radAngle;
break; break;
} }
case HMSLetters: case SectionDegreesHours:
case HMSSymbols: case SectionNone:
{ {
radAngle += ((steps*2*M_PI) / (24*60.0)); if (angleSpinBoxFormat==DMSLetters || angleSpinBoxFo
rmat==DMSSymbols || angleSpinBoxFormat==DecimalDeg)
radAngle += M_PI/180.*steps;
else
radAngle += M_PI/12.*steps;
break; break;
} }
case DecimalDeg: case SectionMinutes:
{ {
radAngle += ((steps*2*M_PI) / (360*10.0)); if (angleSpinBoxFormat==DMSLetters || angleSpinBoxFo
rmat==DMSSymbols || angleSpinBoxFormat==DecimalDeg)
radAngle += M_PI/180.*steps/60.;
else
radAngle += M_PI/12.*steps/60.;
break;
}
case SectionSeconds:
{
if (angleSpinBoxFormat==DMSLetters || angleSpinBoxFo
rmat==DMSSymbols || angleSpinBoxFormat==DecimalDeg)
radAngle += M_PI/180.*steps/3600.;
else
radAngle += M_PI/12.*steps/3600.;
break; break;
} }
default: default:
{ {
qWarning() << "AngleSpinBox::stepBy - WARNING - unkn own display format";
return; return;
break;
} }
} }
formatText(); formatText();
lineEdit()->setCursorPosition(cusorPos);
emit(valueChanged()); emit(valueChanged());
} }
QValidator::State AngleSpinBox::validate(QString& input, int& pos) const QValidator::State AngleSpinBox::validate(QString& input, int& pos) const
{ {
QValidator::State state; QValidator::State state;
stringToDouble(input, &state); stringToDouble(input, &state);
pos = pos; // shut up the compiler pos = pos; // shut up the compiler
return state; return state;
} }
skipping to change at line 275 skipping to change at line 323
} }
void AngleSpinBox::setRadians(double radians) void AngleSpinBox::setRadians(double radians)
{ {
radAngle = radians; radAngle = radians;
formatText(); formatText();
} }
void AngleSpinBox::setDegrees(double degrees) void AngleSpinBox::setDegrees(double degrees)
{ {
radAngle = (degrees / 360.0) * M_PI * 2; radAngle = degrees * M_PI/180.;
formatText(); formatText();
} }
void AngleSpinBox::formatText(void) void AngleSpinBox::formatText(void)
{ {
switch (angleSpinBoxFormat) switch (angleSpinBoxFormat)
{ {
case DMSLetters: case DMSLetters:
case DMSSymbols: case DMSSymbols:
{ {
 End of changes. 12 change blocks. 
14 lines changed or deleted 67 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/