PointerCoordinates.cpp   PointerCoordinates.cpp 
skipping to change at line 32 skipping to change at line 32
#include "StelApp.hpp" #include "StelApp.hpp"
#include "StelCore.hpp" #include "StelCore.hpp"
#include "SkyGui.hpp" #include "SkyGui.hpp"
#include "StelLocaleMgr.hpp" #include "StelLocaleMgr.hpp"
#include "StelModuleMgr.hpp" #include "StelModuleMgr.hpp"
#include "StelFileMgr.hpp" #include "StelFileMgr.hpp"
#include "StelGui.hpp" #include "StelGui.hpp"
#include "StelGuiItems.hpp" #include "StelGuiItems.hpp"
#include "StelObjectMgr.hpp" #include "StelObjectMgr.hpp"
#include "StelUtils.hpp" #include "StelUtils.hpp"
#include "SolarSystem.hpp"
#include "PointerCoordinates.hpp" #include "PointerCoordinates.hpp"
#include "PointerCoordinatesWindow.hpp" #include "PointerCoordinatesWindow.hpp"
#include <QFontMetrics> #include <QFontMetrics>
#include <QSettings> #include <QSettings>
#include <QPixmap> #include <QPixmap>
#include <QPair> #include <QPair>
#include <QMetaEnum> #include <QMetaEnum>
#include <cmath> #include <cmath>
skipping to change at line 64 skipping to change at line 65
info.displayedName = N_("Pointer Coordinates"); info.displayedName = N_("Pointer Coordinates");
info.authors = "Alexander Wolf"; info.authors = "Alexander Wolf";
info.contact = "http://stellarium.org"; info.contact = "http://stellarium.org";
info.description = N_("This plugin shows the coordinates of the mous e pointer."); info.description = N_("This plugin shows the coordinates of the mous e pointer.");
info.version = POINTERCOORDINATES_PLUGIN_VERSION; info.version = POINTERCOORDINATES_PLUGIN_VERSION;
return info; return info;
} }
PointerCoordinates::PointerCoordinates() PointerCoordinates::PointerCoordinates()
: currentPlace(TopRight) : currentPlace(TopRight)
, currentCoordinateSystem(RaDecJ2000)
, flagShowCoordinates(false) , flagShowCoordinates(false)
, flagEnableAtStartup(false) , flagEnableAtStartup(false)
, flagShowCoordinatesButton(false) , flagShowCoordinatesButton(false)
, textColor(Vec3f(1,0.5,0)) , textColor(Vec3f(1,0.5,0))
, coordinatesPoint(Vec3d(0,0,0)) , coordinatesPoint(Vec3d(0,0,0))
, fontSize(14) , fontSize(14)
, toolbarButton(NULL) , toolbarButton(NULL)
{ {
setObjectName("PointerCoordinates"); setObjectName("PointerCoordinates");
mainWindow = new PointerCoordinatesWindow(); mainWindow = new PointerCoordinatesWindow();
skipping to change at line 95 skipping to change at line 97
{ {
if (!conf->childGroups().contains("PointerCoordinates")) if (!conf->childGroups().contains("PointerCoordinates"))
{ {
qDebug() << "PointerCoordinates: no coordinates section exis ts in main config file - creating with defaults"; qDebug() << "PointerCoordinates: no coordinates section exis ts in main config file - creating with defaults";
restoreDefaultConfiguration(); restoreDefaultConfiguration();
} }
// populate settings from main config file. // populate settings from main config file.
loadConfiguration(); loadConfiguration();
addAction("actionShow_MousePointer_Coordinates", N_("Pointer Coordin ates"), N_("Show equatorial coordinates (J2000.0) of the mouse pointer"), " enabled", ""); addAction("actionShow_MousePointer_Coordinates", N_("Pointer Coordin ates"), N_("Show coordinates of the mouse pointer"), "enabled", "");
enableCoordinates(getFlagEnableAtStartup()); enableCoordinates(getFlagEnableAtStartup());
setFlagShowCoordinatesButton(flagShowCoordinatesButton); setFlagShowCoordinatesButton(flagShowCoordinatesButton);
} }
void PointerCoordinates::deinit() void PointerCoordinates::deinit()
{ {
// //
} }
skipping to change at line 126 skipping to change at line 128
QPoint p = QCursor::pos(); // get screen coordinates of mouse cursor QPoint p = QCursor::pos(); // get screen coordinates of mouse cursor
Vec3d mousePosition; Vec3d mousePosition;
float wh = prj->getViewportWidth()/2; // get half of width of the sc reen float wh = prj->getViewportWidth()/2; // get half of width of the sc reen
float hh = prj->getViewportHeight()/2; // get half of height of the screen float hh = prj->getViewportHeight()/2; // get half of height of the screen
float mx = p.x()-wh; // point 0 in center of the screen, axis X dire cted to right float mx = p.x()-wh; // point 0 in center of the screen, axis X dire cted to right
float my = p.y()-hh; // point 0 in center of the screen, axis Y dire cted to bottom float my = p.y()-hh; // point 0 in center of the screen, axis Y dire cted to bottom
// calculate position of mouse cursor via position of center of the screen (and invert axis Y) // calculate position of mouse cursor via position of center of the screen (and invert axis Y)
prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+ hh+1-my, mousePosition); prj->unProject(prj->getViewportPosX()+wh+mx, prj->getViewportPosY()+ hh+1-my, mousePosition);
double dec_j2000, ra_j2000; QString coordsText;
StelUtils::rectToSphe(&ra_j2000,&dec_j2000,mousePosition); // Calcul double cx, cy;
ate RA/DE (J2000.0) and show it... switch (getCurrentCoordinateSystem())
QString coordsText = QString("%1/%2").arg(StelUtils::radToHmsStr(ra_ {
j2000, true)).arg(StelUtils::radToDmsStr(dec_j2000, true)); case RaDecJ2000:
{
StelUtils::rectToSphe(&cx,&cy,mousePosition); // Cal
culate RA/DE (J2000.0) and show it...
coordsText = QString("%1: %2/%3")
.arg(qc_("RA/Dec (J2000.0)", "abbrev
iated in the plugin"))
.arg(StelUtils::radToHmsStr(cx, true
))
.arg(StelUtils::radToDmsStr(cy, true
));
break;
}
case RaDec:
{
StelUtils::rectToSphe(&cx,&cy,core->j2000ToEquinoxEq
u(mousePosition)); // Calculate RA/DE and show it...
coordsText = QString("%1: %2/%3")
.arg(qc_("RA/Dec", "abbreviated in t
he plugin"))
.arg(StelUtils::radToHmsStr(cx, true
))
.arg(StelUtils::radToDmsStr(cy, true
));
break;
}
case AltAzi:
{
StelUtils::rectToSphe(&cy,&cx,core->j2000ToAltAz(mou
sePosition, StelCore::RefractionAuto));
cy = 3.*M_PI - cy; // N is zero, E is 90 degrees
if (cy > M_PI*2)
cy -= M_PI*2;
coordsText = QString("%1: %2/%3")
.arg(qc_("Az/Alt", "abbreviated in t
he plugin"))
.arg(StelUtils::radToDmsStr(cy))
.arg(StelUtils::radToDmsStr(cx));
break;
}
case Galactic:
{
StelUtils::rectToSphe(&cx,&cy,core->j2000ToGalactic(
mousePosition)); // Calculate galactic position and show it...
coordsText = QString("%1: %2/%3")
.arg(qc_("Gal. Long/Lat", "abbreviat
ed in the plugin"))
.arg(StelUtils::radToDmsStr(cx, true
))
.arg(StelUtils::radToDmsStr(cy, true
));
break;
}
case Ecliptic:
{
double lambda, beta;
StelUtils::rectToSphe(&cx,&cy,core->j2000ToEquinoxEq
u(mousePosition));
StelUtils::ctRadec2Ecl(cx, cy, GETSTELMODULE(SolarSy
stem)->getEarth()->getRotObliquity(2451545.0), &lambda, &beta); // Calculat
e ecliptic position and show it...
if (lambda<0) lambda+=2.0*M_PI;
coordsText = QString("%1: %2/%3")
.arg(qc_("Ecl. Long/Lat (J2000.0)",
"abbreviated in the plugin"))
.arg(StelUtils::radToDmsStr(lambda,
true))
.arg(StelUtils::radToDmsStr(beta, tr
ue));
break;
}
case HourAngle:
{
Vec3d v = core->j2000ToAltAz(mousePosition, StelCore
::RefractionAuto);
StelUtils::rectToSphe(&cx,&cy,Mat4d::zrotation(-core
->getLocalSiderealTime()+((core->getDeltaT(core->getJDay())/240.)*M_PI/180.
))*core->altAzToEquinoxEqu(v, StelCore::RefractionOff));
cx = 2.*M_PI-cx;
coordsText = QString("%1: %2/%3")
.arg(qc_("HA/Dec", "abbreviated in t
he plugin"))
.arg(StelUtils::radToHmsStr(cx))
.arg(StelUtils::radToDmsStr(cy));
break;
}
}
sPainter.drawText(getCoordinatesPlace(coordsText).first, getCoordina tesPlace(coordsText).second, coordsText); sPainter.drawText(getCoordinatesPlace(coordsText).first, getCoordina tesPlace(coordsText).second, coordsText);
} }
void PointerCoordinates::enableCoordinates(bool b) void PointerCoordinates::enableCoordinates(bool b)
{ {
flagShowCoordinates = b; flagShowCoordinates = b;
} }
double PointerCoordinates::getCallOrder(StelModuleActionName actionName) co nst double PointerCoordinates::getCallOrder(StelModuleActionName actionName) co nst
skipping to change at line 178 skipping to change at line 245
void PointerCoordinates::loadConfiguration(void) void PointerCoordinates::loadConfiguration(void)
{ {
conf->beginGroup("PointerCoordinates"); conf->beginGroup("PointerCoordinates");
setFlagEnableAtStartup(conf->value("enable_at_startup", false).toBoo l()); setFlagEnableAtStartup(conf->value("enable_at_startup", false).toBoo l());
textColor = StelUtils::strToVec3f(conf->value("text_color", "1,0.5,0 ").toString()); textColor = StelUtils::strToVec3f(conf->value("text_color", "1,0.5,0 ").toString());
setFontSize(conf->value("font_size", 14).toInt()); setFontSize(conf->value("font_size", 14).toInt());
flagShowCoordinatesButton = conf->value("flag_show_button", true).to Bool(); flagShowCoordinatesButton = conf->value("flag_show_button", true).to Bool();
setCurrentCoordinatesPlaceKey(conf->value("current_displaying_place" , "TopRight").toString()); setCurrentCoordinatesPlaceKey(conf->value("current_displaying_place" , "TopRight").toString());
setCurrentCoordinateSystemKey(conf->value("current_coordinate_system
", "RaDecJ2000").toString());
QStringList cc = conf->value("custom_coordinates", "1,1").toString()
.split(",");
setCustomCoordinatesPlace(cc[0].toInt(), cc[1].toInt());
conf->endGroup(); conf->endGroup();
} }
void PointerCoordinates::saveConfiguration(void) void PointerCoordinates::saveConfiguration(void)
{ {
conf->beginGroup("PointerCoordinates"); conf->beginGroup("PointerCoordinates");
conf->setValue("enable_at_startup", getFlagEnableAtStartup()); conf->setValue("enable_at_startup", getFlagEnableAtStartup());
conf->setValue("flag_show_button", getFlagShowCoordinatesButton()); conf->setValue("flag_show_button", getFlagShowCoordinatesButton());
conf->setValue("current_displaying_place", getCurrentCoordinatesPlac eKey()); conf->setValue("current_displaying_place", getCurrentCoordinatesPlac eKey());
conf->setValue("current_coordinate_system", getCurrentCoordinateSyst
emKey());
QPair<int, int> cc = getCustomCoordinatesPlace();
conf->setValue("custom_coordinates", QString("%1,%2").arg(cc.first).
arg(cc.second));
//conf->setValue("text_color", "1,0.5,0"); //conf->setValue("text_color", "1,0.5,0");
conf->setValue("font_size", getFontSize()); conf->setValue("font_size", getFontSize());
conf->endGroup(); conf->endGroup();
} }
void PointerCoordinates::setFlagShowCoordinatesButton(bool b) void PointerCoordinates::setFlagShowCoordinatesButton(bool b)
{ {
if (gui!=NULL) if (gui!=NULL)
{ {
skipping to change at line 235 skipping to change at line 308
} }
setCurrentCoordinatesPlace(coordPlace); setCurrentCoordinatesPlace(coordPlace);
} }
//Get the current place of the string with coordinates //Get the current place of the string with coordinates
QString PointerCoordinates::getCurrentCoordinatesPlaceKey() const QString PointerCoordinates::getCurrentCoordinatesPlaceKey() const
{ {
return metaObject()->enumerator(metaObject()->indexOfEnumerator("Coo rdinatesPlace")).key(currentPlace); return metaObject()->enumerator(metaObject()->indexOfEnumerator("Coo rdinatesPlace")).key(currentPlace);
} }
void PointerCoordinates::setCurrentCoordinateSystemKey(QString key)
{
const QMetaEnum& en = metaObject()->enumerator(metaObject()->indexOf
Enumerator("CoordinateSystem"));
CoordinateSystem coordSystem = (CoordinateSystem)en.keyToValue(key.t
oLatin1().data());
if (coordSystem<0)
{
qWarning() << "Unknown coordinate system: " << key << "setti
ng \"RaDecJ2000\" instead";
coordSystem = RaDecJ2000;
}
setCurrentCoordinateSystem(coordSystem);
}
QString PointerCoordinates::getCurrentCoordinateSystemKey() const
{
return metaObject()->enumerator(metaObject()->indexOfEnumerator("Coo
rdinateSystem")).key(currentCoordinateSystem);
}
QPair<int, int> PointerCoordinates::getCoordinatesPlace(QString text) QPair<int, int> PointerCoordinates::getCoordinatesPlace(QString text)
{ {
int x = 0, y = 0; int x = 0, y = 0;
float coeff = 1.5; float coeff = 1.5;
QFontMetrics fm(font); QFontMetrics fm(font);
QSize fs = fm.size(Qt::TextSingleLine, text); QSize fs = fm.size(Qt::TextSingleLine, text);
switch(getCurrentCoordinatesPlace()) switch(getCurrentCoordinatesPlace())
{ {
case TopCenter: case TopCenter:
{
x = gui->getSkyGui()->getSkyGuiWidth()/2 - fs.width( )/2; x = gui->getSkyGui()->getSkyGuiWidth()/2 - fs.width( )/2;
y = gui->getSkyGui()->getSkyGuiHeight() - fs.height( )*coeff; y = gui->getSkyGui()->getSkyGuiHeight() - fs.height( )*coeff;
break; break;
}
case TopRight: case TopRight:
{
x = 3*gui->getSkyGui()->getSkyGuiWidth()/4 - fs.widt h()/2; x = 3*gui->getSkyGui()->getSkyGuiWidth()/4 - fs.widt h()/2;
y = gui->getSkyGui()->getSkyGuiHeight() - fs.height( )*coeff; y = gui->getSkyGui()->getSkyGuiHeight() - fs.height( )*coeff;
break; break;
}
case RightBottomCorner: case RightBottomCorner:
{
x = gui->getSkyGui()->getSkyGuiWidth() - fs.width() - 10*coeff; x = gui->getSkyGui()->getSkyGuiWidth() - fs.width() - 10*coeff;
y = fs.height(); y = fs.height();
break; break;
}
case Custom:
{
QPair<int, int> xy = getCustomCoordinatesPlace();
x = xy.first;
y = gui->getSkyGui()->getSkyGuiHeight() - xy.second
- fs.height();
break;
}
} }
return qMakePair(x, y); return qMakePair(x, y);
} }
void PointerCoordinates::setCustomCoordinatesPlace(int x, int y)
{
customPosition = qMakePair(x, y);
}
 End of changes. 14 change blocks. 
6 lines changed or deleted 140 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/