14 #include "ui_StarsConfigWidget.h"
19 #include <QContextMenuEvent>
21 #include <QColorDialog>
45 m_renderStars( true ),
46 m_renderConstellationLines( true ),
47 m_renderConstellationLabels( true ),
49 m_renderDsoLabels( true ),
52 m_renderEcliptic( true ),
53 m_renderCelestialEquator( true ),
54 m_renderCelestialPole( true ),
55 m_starsLoaded( false ),
56 m_starPixmapsCreated( false ),
57 m_constellationsLoaded( false ),
58 m_dsosLoaded( false ),
59 m_zoomSunMoon( true ),
60 m_viewSolarSystemLabel( true ),
61 m_magnitudeLimit( 100 ),
62 m_zoomCoefficient( 4 ),
70 m_constellationsAction(0),
82 delete m_constellationsAction;
83 delete m_sunMoonAction;
84 delete m_planetsAction;
95 return QString(
"SPECIFIED_ALWAYS" );
110 return tr(
"Stars" );
115 return tr(
"&Stars" );
130 return tr(
"A plugin that shows the Starry Sky and the Sun." );
143 <<
PluginAuthor(
"Timothy Lanzi",
"trlanzi@gmail.com" );
148 return QIcon(
":/icons/stars.png");
162 if (!m_configDialog) {
165 ui_configWidget =
new Ui::StarsConfigWidget;
166 ui_configWidget->setupUi( m_configDialog );
173 connect( ui_configWidget->m_constellationColorButton, SIGNAL(clicked()),
this,
176 connect( ui_configWidget->m_constellationLabelColorButton, SIGNAL(clicked()),
this,
179 connect( ui_configWidget->m_dsoLabelColorButton, SIGNAL(clicked()),
this,
182 connect( ui_configWidget->m_eclipticColorButton, SIGNAL(clicked()),
this,
185 connect( ui_configWidget->m_celestialEquatorColorButton, SIGNAL(clicked()),
this,
188 connect( ui_configWidget->m_celestialPoleColorButton, SIGNAL(clicked()),
this,
192 return m_configDialog;
199 settings[
"nameIndex"] = m_nameIndex;
200 settings[
"renderStars"] = m_renderStars;
201 settings[
"renderConstellationLines"] = m_renderConstellationLines;
202 settings[
"renderConstellationLabels"] = m_renderConstellationLabels;
203 settings[
"renderDsos"] = m_renderDsos;
204 settings[
"renderDsoLabels"] = m_renderDsoLabels;
205 settings[
"renderSun"] = m_renderSun;
206 settings[
"renderMoon"] = m_renderMoon;
209 foreach (
const QString &key, m_renderPlanet.
keys())
211 settings[
"renderPlanet"] = planetState.
join(
QChar(
'|'));
213 settings[
"renderEcliptic"] = m_renderEcliptic;
214 settings[
"renderCelestialEquator"] = m_renderCelestialEquator;
215 settings[
"renderCelestialPole"] = m_renderCelestialPole;
216 settings[
"zoomSunMoon"] = m_zoomSunMoon;
217 settings[
"viewSolarSystemLabel"] = m_viewSolarSystemLabel;
218 settings[
"magnitudeLimit"] = m_magnitudeLimit;
219 settings[
"constellationBrush"] = m_constellationBrush.
color().
rgb();
220 settings[
"constellationLabelBrush"] = m_constellationLabelBrush.
color().
rgb();
221 settings[
"dsoLabelBrush"] = m_dsoLabelBrush.
color().
rgb();
222 settings[
"eclipticBrush"] = m_eclipticBrush.
color().
rgb();
223 settings[
"celestialEaquatorBrush"] = m_celestialEquatorBrush.
color().
rgb();
224 settings[
"celestialPoleBrush"] = m_celestialPoleBrush.
color().
rgb();
233 m_nameIndex = readSetting<int>(
settings,
"nameIndex", 0 );
234 m_renderStars = readSetting<bool>(
settings,
"renderStars", true );
235 m_renderConstellationLines = readSetting<bool>(
settings,
"renderConstellationLines", true );
236 m_renderConstellationLabels = readSetting<bool>(
settings,
"renderConstellationLabels", true );
237 m_renderDsos = readSetting<bool>(
settings,
"renderDsos", true );
238 m_renderDsoLabels = readSetting<bool>(
settings,
"renderDsoLabels",
true);
239 m_renderSun = readSetting<bool>(
settings,
"renderSun", true );
240 m_renderMoon = readSetting<bool>(
settings,
"renderMoon", true );
242 m_renderPlanet.
clear();
243 const QString renderPlanet = readSetting<QString>(
settings,
"renderPlanet",
"" );
245 foreach(
const QString state, renderStates) {
247 if (stateList.
size() == 2)
248 m_renderPlanet[stateList[0]] = (
bool)stateList[1].toInt();
251 m_renderEcliptic = readSetting<bool>(
settings,
"renderEcliptic", true );
252 m_renderCelestialEquator = readSetting<bool>(
settings,
"renderCelestialEquator", true );
253 m_renderCelestialPole = readSetting<bool>(
settings,
"renderCelestialPole", true );
254 m_zoomSunMoon = readSetting<bool>(
settings,
"zoomSunMoon", true );
255 m_viewSolarSystemLabel = readSetting<bool>(
settings,
"viewSolarSystemLabel", true );
256 m_magnitudeLimit = readSetting<int>(
settings,
"magnitudeLimit", 100 );
258 m_constellationBrush =
QColor( readSetting<QRgb>( settings,
"constellationBrush", defaultColor.rgb() ) );
259 m_constellationLabelBrush =
QColor( readSetting<QRgb>( settings,
"constellationLabelBrush", defaultColor.rgb()) );
260 m_dsoLabelBrush =
QColor( readSetting<QRgb>( settings,
"dsoLabelBrush", defaultColor.rgb() ) );
261 m_eclipticBrush =
QColor( readSetting<QRgb>( settings,
"eclipticBrush", defaultColor.rgb() ) );
262 m_celestialEquatorBrush =
QColor( readSetting<QRgb>( settings,
"celestialEquatorBrush", defaultColor.rgb() ) );
263 m_celestialPoleBrush =
QColor( readSetting<QRgb>( settings,
"celestialPoleBrush", defaultColor.rgb() ) );
266 QPixmap StarsPlugin::starPixmap(qreal
mag,
int colorId)
const
269 return m_pixN1Stars.
at(colorId);
270 }
else if ( mag < 0 ) {
271 return m_pixP0Stars.
at(colorId);
272 }
else if ( mag < 1 ) {
273 return m_pixP1Stars.
at(colorId);
274 }
else if ( mag < 2 ) {
275 return m_pixP2Stars.
at(colorId);
276 }
else if ( mag < 3 ) {
277 return m_pixP3Stars.
at(colorId);
278 }
else if ( mag < 4 ) {
279 return m_pixP4Stars.
at(colorId);
280 }
else if ( mag < 5 ) {
281 return m_pixP5Stars.
at(colorId);
282 }
else if ( mag < 6 ) {
283 return m_pixP6Stars.
at(colorId);
285 return m_pixP7Stars.
at(colorId);
291 void StarsPlugin::prepareNames()
295 if ( !names.open( QIODevice::ReadOnly ) ) {
300 while ( !in.atEnd() ) {
303 if ( list.
size() == 3 ) {
304 m_nativeHash[ list.
at( 0 ) ] =
tr( list.
at( 1 ).toUtf8().constData() );
305 m_abbrHash[ list.
at( 0 ) ] = list.
at( 2 );
314 switch (m_nameIndex) {
318 return m_nativeHash[
name];
320 return m_abbrHash[
name];
328 if ( !m_configDialog ) {
332 ui_configWidget->constellationNamesComboBox->setCurrentIndex(m_nameIndex);
334 Qt::CheckState
const constellationLineState = m_renderConstellationLines ? Qt::Checked : Qt::Unchecked;
335 ui_configWidget->m_viewConstellationLinesCheckbox->setCheckState( constellationLineState );
337 Qt::CheckState
const constellationLabelState = m_renderConstellationLabels ? Qt::Checked : Qt::Unchecked;
338 ui_configWidget->m_viewConstellationLabelsCheckbox->setCheckState( constellationLabelState );
340 Qt::CheckState
const dsoState = m_renderDsos ? Qt::Checked : Qt::Unchecked;
341 ui_configWidget->m_viewDsosCheckbox->setCheckState( dsoState );
343 Qt::CheckState
const dsoLabelState = m_renderDsoLabels ? Qt::Checked : Qt::Unchecked;
344 ui_configWidget->m_viewDsoLabelCheckbox->setCheckState( dsoLabelState );
346 Qt::CheckState
const sunState = m_renderSun ? Qt::Checked : Qt::Unchecked;
347 ui_configWidget->m_solarSystemListWidget->item( 0 )->setCheckState( sunState );
349 Qt::CheckState
const moonState = m_renderMoon ? Qt::Checked : Qt::Unchecked;
350 ui_configWidget->m_solarSystemListWidget->item( 1 )->setCheckState( moonState );
352 Qt::CheckState
const mercuryState = m_renderPlanet[
"mercury"] ? Qt::Checked : Qt::Unchecked;
353 ui_configWidget->m_solarSystemListWidget->item( 2 )->setCheckState(mercuryState);
355 Qt::CheckState
const venusState = m_renderPlanet[
"venus"] ? Qt::Checked : Qt::Unchecked;
356 ui_configWidget->m_solarSystemListWidget->item( 3 )->setCheckState(venusState);
358 Qt::CheckState
const marsState = m_renderPlanet[
"mars"] ? Qt::Checked : Qt::Unchecked;
359 ui_configWidget->m_solarSystemListWidget->item( 5 )->setCheckState(marsState);
361 Qt::CheckState
const jupiterState = m_renderPlanet[
"jupiter"] ? Qt::Checked : Qt::Unchecked;
362 ui_configWidget->m_solarSystemListWidget->item( 6 )->setCheckState(jupiterState);
364 Qt::CheckState
const saturnState = m_renderPlanet[
"saturn"] ? Qt::Checked : Qt::Unchecked;
365 ui_configWidget->m_solarSystemListWidget->item( 7 )->setCheckState(saturnState);
367 Qt::CheckState
const uranusState = m_renderPlanet[
"uranus"] ? Qt::Checked : Qt::Unchecked;
368 ui_configWidget->m_solarSystemListWidget->item( 8 )->setCheckState(uranusState);
370 Qt::CheckState
const neptuneState = m_renderPlanet[
"neptune"] ? Qt::Checked : Qt::Unchecked;
371 ui_configWidget->m_solarSystemListWidget->item( 9 )->setCheckState(neptuneState);
373 Qt::CheckState
const eclipticState = m_renderEcliptic ? Qt::Checked : Qt::Unchecked;
374 ui_configWidget->m_viewEclipticCheckbox->setCheckState( eclipticState );
376 Qt::CheckState
const celestialEquatorState = m_renderCelestialEquator ? Qt::Checked : Qt::Unchecked;
377 ui_configWidget->m_viewCelestialEquatorCheckbox->setCheckState( celestialEquatorState );
379 Qt::CheckState
const celestialPoleState = m_renderCelestialPole ? Qt::Checked : Qt::Unchecked;
380 ui_configWidget->m_viewCelestialPoleCheckbox->setCheckState( celestialPoleState );
382 Qt::CheckState
const zoomSunMoonState = m_zoomSunMoon ? Qt::Checked : Qt::Unchecked;
383 ui_configWidget->m_zoomSunMoonCheckbox->setCheckState( zoomSunMoonState );
385 Qt::CheckState
const viewSolarSystemLabelState = m_viewSolarSystemLabel ? Qt::Checked : Qt::Unchecked;
386 ui_configWidget->m_viewSolarSystemLabelCheckbox->setCheckState( viewSolarSystemLabelState );
388 int magState = m_magnitudeLimit;
389 if ( magState < ui_configWidget->m_magnitudeSlider->minimum() ) {
390 magState = ui_configWidget->m_magnitudeSlider->minimum();
392 else if ( magState > ui_configWidget->m_magnitudeSlider->maximum() ) {
393 magState = ui_configWidget->m_magnitudeSlider->maximum();
396 ui_configWidget->m_magnitudeSlider->setValue(magState);
399 constellationPalette.
setColor( QPalette::Button, m_constellationBrush.
color() );
400 ui_configWidget->m_constellationColorButton->setPalette( constellationPalette );
403 constellationLabelPalette.
setColor( QPalette::Button, m_constellationLabelBrush.
color() );
404 ui_configWidget->m_constellationLabelColorButton->setPalette( constellationLabelPalette );
407 dsoLabelPalette.
setColor( QPalette::Button, m_dsoLabelBrush.
color() );
408 ui_configWidget->m_dsoLabelColorButton->setPalette( dsoLabelPalette );
411 eclipticPalette.
setColor( QPalette::Button, m_eclipticBrush.
color() );
412 ui_configWidget->m_eclipticColorButton->setPalette( eclipticPalette );
415 celestialEquatorPalette.
setColor( QPalette::Button, m_celestialEquatorBrush.
color() );
416 ui_configWidget->m_celestialEquatorColorButton->setPalette( celestialEquatorPalette );
419 celestialPolePalette.
setColor( QPalette::Button, m_celestialPoleBrush.
color() );
420 ui_configWidget->m_celestialPoleColorButton->setPalette( celestialPolePalette );
427 m_nameIndex = ui_configWidget->constellationNamesComboBox->currentIndex();
428 m_renderConstellationLines = ui_configWidget->m_viewConstellationLinesCheckbox->checkState() == Qt::Checked;
429 m_renderConstellationLabels = ui_configWidget->m_viewConstellationLabelsCheckbox->checkState() == Qt::Checked;
430 m_renderDsos = ui_configWidget->m_viewDsosCheckbox->checkState() == Qt::Checked;
431 m_renderDsoLabels = ui_configWidget->m_viewDsoLabelCheckbox->checkState() == Qt::Checked;
432 m_renderSun = ui_configWidget->m_solarSystemListWidget->item( 0 )->checkState() == Qt::Checked;
433 m_renderMoon = ui_configWidget->m_solarSystemListWidget->item( 1 )->checkState() == Qt::Checked;
435 m_renderPlanet[
"mercury"] = ui_configWidget->m_solarSystemListWidget->item( 2 )->checkState()
437 m_renderPlanet[
"venus"] = ui_configWidget->m_solarSystemListWidget->item( 3 )->checkState()
439 m_renderPlanet[
"mars"] = ui_configWidget->m_solarSystemListWidget->item( 5 )->checkState()
441 m_renderPlanet[
"jupiter"] = ui_configWidget->m_solarSystemListWidget->item( 6 )->checkState()
443 m_renderPlanet[
"saturn"] = ui_configWidget->m_solarSystemListWidget->item( 7 )->checkState()
445 m_renderPlanet[
"uranus"] = ui_configWidget->m_solarSystemListWidget->item( 8 )->checkState()
447 m_renderPlanet[
"neptune"] = ui_configWidget->m_solarSystemListWidget->item( 9 )->checkState()
450 m_renderEcliptic = ui_configWidget->m_viewEclipticCheckbox->checkState() == Qt::Checked;
451 m_renderCelestialEquator = ui_configWidget->m_viewCelestialEquatorCheckbox->checkState() == Qt::Checked;
452 m_renderCelestialPole = ui_configWidget->m_viewCelestialPoleCheckbox->checkState() == Qt::Checked;
453 m_zoomSunMoon = ui_configWidget->m_zoomSunMoonCheckbox->checkState() == Qt::Checked;
454 m_viewSolarSystemLabel = ui_configWidget->m_viewSolarSystemLabelCheckbox->checkState() == Qt::Checked;
455 m_magnitudeLimit = ui_configWidget->m_magnitudeSlider->value();
456 m_constellationBrush =
QBrush( ui_configWidget->m_constellationColorButton->palette().color( QPalette::Button) );
457 m_constellationLabelBrush =
QBrush( ui_configWidget->m_constellationLabelColorButton->palette().color( QPalette::Button) );
458 m_dsoLabelBrush =
QBrush( ui_configWidget->m_dsoLabelColorButton->palette().color( QPalette::Button) );
459 m_eclipticBrush =
QBrush( ui_configWidget->m_eclipticColorButton->palette().color( QPalette::Button) );
460 m_celestialEquatorBrush =
QBrush( ui_configWidget->m_celestialEquatorColorButton->palette().color( QPalette::Button) );
461 m_celestialPoleBrush =
QBrush( ui_configWidget->m_celestialPoleColorButton->palette().color( QPalette::Button) );
470 QPalette palette = ui_configWidget->m_constellationColorButton->palette();
471 palette.
setColor( QPalette::Button, c );
472 ui_configWidget->m_constellationColorButton->setPalette( palette );
481 QPalette palette = ui_configWidget->m_constellationLabelColorButton->palette();
482 palette.
setColor( QPalette::Button, c );
483 ui_configWidget->m_constellationLabelColorButton->setPalette( palette );
492 QPalette palette = ui_configWidget->m_dsoLabelColorButton->palette();
493 palette.
setColor( QPalette::Button, c );
494 ui_configWidget->m_dsoLabelColorButton->setPalette( palette );
503 QPalette palette = ui_configWidget->m_eclipticColorButton->palette();
504 palette.
setColor( QPalette::Button, c );
505 ui_configWidget->m_eclipticColorButton->setPalette( palette );
514 QPalette palette = ui_configWidget->m_celestialEquatorColorButton->palette();
515 palette.
setColor( QPalette::Button, c );
516 ui_configWidget->m_celestialEquatorColorButton->setPalette( palette );
525 QPalette palette = ui_configWidget->m_celestialPoleColorButton->palette();
526 palette.
setColor( QPalette::Button, c );
527 ui_configWidget->m_celestialPoleColorButton->setPalette( palette );
531 void StarsPlugin::loadStars()
538 starFile.open( QIODevice::ReadOnly );
544 if ( magic != 0x73746172 ) {
551 if ( version > 004 ) {
552 mDebug() <<
"stars.dat: file too new.";
556 if ( version == 003 ) {
557 mDebug() <<
"stars.dat: file version no longer supported.";
571 while ( !in.atEnd() ) {
572 if ( version >= 2 ) {
582 if ( version >= 4 ) {
586 StarPoint star(
id, ( qreal )( ra ), ( qreal )( de ), ( qreal )( mag ), colorId );
591 m_idHash[id] = starIndex;
601 m_starsLoaded =
true;
604 void StarsPlugin::createStarPixmaps()
618 pixSmallStars.
clear();
629 m_pixN1Stars.
clear();
630 for (
int p=0; p < pixBigStars.
size(); ++p) {
631 int width = 1.0*pixBigStars.
at(p).width();
632 m_pixN1Stars.
append(pixBigStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
635 m_pixP0Stars.
clear();
636 for (
int p=0; p < pixBigStars.
size(); ++p) {
637 int width = 0.90*pixBigStars.
at(p).width();
638 m_pixP0Stars.
append(pixBigStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
641 m_pixP1Stars.
clear();
642 for (
int p=0; p < pixBigStars.
size(); ++p) {
643 int width = 0.80*pixBigStars.
at(p).width();
644 m_pixP1Stars.
append(pixBigStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
647 m_pixP2Stars.
clear();
648 for (
int p=0; p < pixBigStars.
size(); ++p) {
649 int width = 0.70*pixBigStars.
at(p).width();
650 m_pixP2Stars.
append(pixBigStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
653 m_pixP3Stars.
clear();
654 for (
int p=0; p < pixSmallStars.
size(); ++p) {
656 m_pixP3Stars.
append(pixSmallStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
659 m_pixP4Stars.
clear();
660 for (
int p=0; p < pixSmallStars.
size(); ++p) {
662 m_pixP4Stars.
append(pixSmallStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
665 m_pixP5Stars.
clear();
666 for (
int p=0; p < pixSmallStars.
size(); ++p) {
668 m_pixP5Stars.
append(pixSmallStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
671 m_pixP6Stars.
clear();
672 for (
int p=0; p < pixSmallStars.
size(); ++p) {
674 m_pixP6Stars.
append(pixSmallStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
677 m_pixP7Stars.
clear();
678 for (
int p=0; p < pixSmallStars.
size(); ++p) {
680 m_pixP7Stars.
append(pixSmallStars.
at(p).scaledToWidth(width,Qt::SmoothTransformation));
683 m_starPixmapsCreated =
true;
686 void StarsPlugin::loadConstellations()
689 m_constellations.clear();
692 constellationFile.open( QIODevice::ReadOnly );
697 while ( !in.atEnd() ) {
698 line = in.readLine();
711 indexList = in.readLine();
714 if ( indexList.
isNull() ) {
718 Constellation constellation(
this, line, indexList );
719 m_constellations << constellation;
722 m_constellationsLoaded =
true;
726 void StarsPlugin::loadDsos()
732 dsoFile.open( QIODevice::ReadOnly );
736 while ( !in.atEnd() ) {
737 line = in.readLine();
754 double raH = entries.
at( 1 ).toDouble();
755 double raM = entries.
at( 2 ).toDouble();
756 double raS = entries.
at( 3 ).toDouble();
757 double decD = entries.
at( 4 ).toDouble();
758 double decM = entries.
at( 5 ).toDouble();
759 double decS = entries.
at( 6 ).toDouble();
761 double raRad = ( raH+raM/60.0+raS/3600.0 )*15.0*
M_PI/180.0;
765 decRad = ( decD+decM/60.0+decS/3600.0 )*
M_PI/180.0;
768 decRad = ( decD-decM/60.0-decS/3600.0 )*
M_PI/180.0;
771 DsoPoint dso(
id, ( qreal )( raRad ), ( qreal )( decRad ) );
783 Q_UNUSED( renderPos )
791 if ( doRender != m_doRender ) {
794 this, SLOT(requestRepaint()) );
797 this, SLOT(requestRepaint()) );
800 m_doRender = doRender;
811 QString const pname = planetId.
at(0).
toUpper() + planetId.right(planetId.size() - 1);
816 qreal skyRotationAngle = -atan2(skyVector[1], skyVector[0]);
821 const qreal skyRadius = 0.6 * sqrt( ( qreal )viewport->
width() * viewport->
width() + viewport->
height() * viewport->
height() );
824 if (!m_starPixmapsCreated) {
826 m_starPixmapsCreated =
true;
831 if ( !m_starsLoaded ) {
833 m_starsLoaded =
true;
836 if ( !m_constellationsLoaded ) {
837 loadConstellations();
838 m_constellationsLoaded =
true;
841 if ( !m_dsosLoaded ) {
846 const qreal earthRadius = viewport->
radius();
849 QPen polesPen( m_celestialPoleBrush, 2, Qt::SolidLine );
850 QPen constellationPenSolid( m_constellationBrush, 1, Qt::SolidLine );
851 QPen constellationPenDash( m_constellationBrush, 1, Qt::DashLine );
852 QPen constellationLabelPen( m_constellationLabelBrush, 1, Qt::SolidLine );
853 QPen eclipticPen( m_eclipticBrush, 1, Qt::DotLine );
854 QPen equatorPen( m_celestialEquatorBrush, 1, Qt::DotLine );
855 QPen dsoLabelPen (m_dsoLabelBrush, 1, Qt::SolidLine);
862 if ( m_renderCelestialPole ) {
865 painter->
setPen( polesPen );
871 if ( qpos1.
v[
Q_Z] < 0 ) {
872 const int x1 = ( int )( viewport->
width() / 2 + skyRadius * qpos1.
v[
Q_X] );
873 const int y1 = ( int )( viewport->
height() / 2 - skyRadius * qpos1.
v[
Q_Y] );
874 painter->
drawLine( x1, y1, x1+10, y1 );
875 painter->
drawLine( x1+5, y1-5, x1+5, y1+5 );
876 painter->
drawText( x1+8, y1+12,
"NP" );
882 if ( qpos2.
v[
Q_Z] < 0 ) {
883 const int x1 = ( int )( viewport->
width() / 2 + skyRadius * qpos2.
v[
Q_X] );
884 const int y1 = ( int )( viewport->
height() / 2 - skyRadius * qpos2.
v[
Q_Y] );
885 painter->
drawLine( x1, y1, x1+10, y1 );
886 painter->
drawLine( x1+5, y1-5, x1+5, y1+5 );
887 painter->
drawText( x1+8, y1+12,
"SP" );
891 if( m_renderEcliptic ) {
893 matrix eclipticAxisMatrix;
894 (eclipticAxis * skyAxis).inverse().toMatrix( eclipticAxisMatrix );
896 painter->
setPen(eclipticPen);
900 for (
int i = 0; i <= 36; ++i) {
905 int x = ( int )( viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X] );
906 int y = ( int )( viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y] );
908 if ( qpos.
v[
Q_Z] < 0 && previousX >= 0 ) painter->
drawLine(previousX, previousY, x, y);
915 if( m_renderCelestialEquator ) {
916 painter->
setPen(equatorPen);
920 for (
int i = 0; i <= 36; ++i) {
925 int x = ( int )( viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X] );
926 int y = ( int )( viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y] );
928 if ( qpos.
v[
Q_Z] < 0 && previousX > 0 ) painter->
drawLine(previousX, previousY, x, y);
935 if ( m_renderDsos ) {
936 painter->
setPen(dsoLabelPen);
938 for (
int d = 0; d < m_dsos.size(); ++d ) {
939 Quaternion qpos = m_dsos.at( d ).quaternion();
942 if ( qpos.
v[
Q_Z] > 0 ) {
946 qreal earthCenteredX = qpos.
v[
Q_X] * skyRadius;
947 qreal earthCenteredY = qpos.
v[
Q_Y] * skyRadius;
951 && ( ( earthCenteredX * earthCenteredX
952 + earthCenteredY * earthCenteredY )
953 < earthRadius * earthRadius ) ) {
958 const int x = ( int )( viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X] );
959 const int y = ( int )( viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y] );
962 if ( x < 0 || x >= viewport->
width() ||
963 y < 0 || y >= viewport->
height() ) {
971 painter->
drawImage(
QRectF( x-size/2, y-size/2, size, size ),m_dsoImage );
972 if (m_renderDsoLabels) {
973 painter->
drawText( x+8, y+12, m_dsos.at( d ).id() );
978 if ( m_renderConstellationLines || m_renderConstellationLabels )
981 for (
int c = 0; c < m_constellations.size(); ++c ) {
985 painter->
setPen( constellationPenSolid );
987 for (
int s = 0; s < ( m_constellations.at( c ).size() - 1 ); ++s ) {
988 int starId1 = m_constellations.at( c ).at( s );
989 int starId2 = m_constellations.at( c ).at( s + 1 );
991 if ( starId1 == -1 || starId2 == -1 ) {
994 }
else if ( starId1 == -2 || starId2 == -2 ) {
995 painter->
setPen( constellationPenDash );
996 }
else if ( starId1 == -3 || starId2 == -3 ) {
997 painter->
setPen( constellationPenSolid );
1000 int idx1 = m_idHash.
value( starId1,-1 );
1001 int idx2 = m_idHash.
value( starId2,-1 );
1005 mDebug() <<
"unknown star, "
1006 << starId1 <<
", in constellation "
1007 << m_constellations.at( c ).name();
1012 mDebug() <<
"unknown star, "
1013 << starId1 <<
", in constellation "
1014 << m_constellations.at( c ).name();
1018 Quaternion q1 = m_stars.at( idx1 ).quaternion();
1020 Quaternion q2 = m_stars.at( idx2 ).quaternion();
1025 if ( q1.
v[
Q_Z] > 0 || q2.
v[
Q_Z] > 0 ) {
1031 int x1 = ( int )( viewport->
width() / 2 + skyRadius * q1.
v[
Q_X] );
1032 int y1 = ( int )( viewport->
height() / 2 - skyRadius * q1.
v[
Q_Y] );
1033 int x2 = ( int )( viewport->
width() / 2 + skyRadius * q2.
v[
Q_X] );
1034 int y2 = ( int )( viewport->
height() / 2 - skyRadius * q2.
v[
Q_Y] );
1037 xMean = xMean + x1 + x2;
1038 yMean = yMean + y1 + y2;
1039 endptCount = endptCount + 2;
1041 if ( m_renderConstellationLines ) {
1042 painter->
drawLine( x1, y1, x2, y2 );
1048 if ( endptCount > 0 ) {
1049 xMean = xMean / endptCount;
1050 yMean = yMean / endptCount;
1053 if ( endptCount < 1 || xMean < 0 || xMean >= viewport->
width()
1054 || yMean < 0 || yMean >= viewport->
height() )
1057 painter->
setPen( constellationLabelPen );
1058 if ( m_renderConstellationLabels ) {
1059 painter->
drawText( xMean, yMean, m_constellations.at( c ).name() );
1067 for (
int s = 0; s < m_stars.size(); ++s ) {
1068 Quaternion qpos = m_stars.at(s).quaternion();
1072 if ( qpos.
v[
Q_Z] > 0 ) {
1076 qreal earthCenteredX = qpos.
v[
Q_X] * skyRadius;
1077 qreal earthCenteredY = qpos.
v[
Q_Y] * skyRadius;
1080 if ( qpos.
v[
Q_Z] < 0
1081 && ( ( earthCenteredX * earthCenteredX
1082 + earthCenteredY * earthCenteredY )
1083 < earthRadius * earthRadius ) ) {
1088 const int x = ( int )( viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X] );
1089 const int y = ( int )( viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y] );
1092 if ( x < 0 || x >= viewport->
width()
1093 || y < 0 || y >= viewport->
height() )
1097 if ( m_stars.at(s).magnitude() < m_magnitudeLimit ) {
1100 int colorId = m_stars.at(s).colorId();
1101 QPixmap s_pixmap = starPixmap(m_stars.at(s).magnitude(), colorId);
1102 int sizeX = s_pixmap.
width();
1103 int sizeY = s_pixmap.
height();
1104 painter->
drawPixmap( x-sizeX/2, y-sizeY/2 ,s_pixmap );
1108 if ( m_renderSun ) {
1113 ra = 15.0 * sys.
DmsDegF( ra );
1119 if ( qpos.
v[
Q_Z] <= 0 ) {
1121 qreal deltaX = glow.
width() / 2.;
1122 qreal deltaY = glow.
height() / 2.;
1123 int x = (int)(viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X]);
1124 int y = (int)(viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y]);
1126 bool glowDrawn =
false;
1127 if (!(x < -glow.
width() || x >= viewport->
width() ||
1129 painter->
drawPixmap( x - deltaX, y - deltaY, glow );
1134 double diameter = 0.0, mag = 0.0;
1136 const int coefficient = m_zoomSunMoon ? m_zoomCoefficient : 1;
1137 const qreal size = skyRadius * qSin(diameter) * coefficient;
1138 const qreal factor = size/m_pixmapSun.
width();
1140 Qt::SmoothTransformation);
1141 deltaX = sun.
width() / 2.;
1142 deltaY = sun.
height() / 2.;
1143 x = (int)(viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X]);
1144 y = (int)(viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y]);
1146 painter->
drawPixmap( x - deltaX, y - deltaY, sun );
1150 if (m_viewSolarSystemLabel)
1151 painter->
drawText(x+deltaX*1.5, y+deltaY*1.5,
tr(
"Sun"));
1155 if ( m_renderMoon &&
marbleModel()->planetId() ==
"earth" ) {
1167 if ( qpos.
v[
Q_Z] <= 0 ) {
1169 const int coefficient = m_zoomSunMoon ? m_zoomCoefficient : 1;
1173 const qreal size = skyRadius * qSin(sys.
getDiamMoon()) * coefficient;
1174 qreal deltaX = size / 2.;
1175 qreal deltaY = size / 2.;
1176 const int x = (int)(viewport->
width() / 2 + skyRadius * qpos.
v[
Q_X]);
1177 const int y = (int)(viewport->
height() / 2 - skyRadius * qpos.
v[
Q_Y]);
1180 if (!(x < -size || x >= viewport->
width() ||
1181 y < -size || y >= viewport->
height())) {
1183 double phase = 0.0, ildisk = 0.0, amag = 0.0;
1189 if (ildisk < 0.05) {
1192 }
else if (ildisk < 0.95) {
1194 qreal ellipseWidth = 2 * qAbs(ildisk-0.5) * moon.
width();
1195 halfEllipseRect.
setX((fullMoonRect.
width() - ellipseWidth) * 0.5);
1196 halfEllipseRect.
setWidth(ellipseWidth);
1202 path.
arcTo(fullMoonRect, -90, -180);
1203 path.
arcTo(halfEllipseRect, 90, -180);
1206 path.
arcTo(fullMoonRect, 90, 180);
1207 path.
arcTo(halfEllipseRect, -90, -180);
1212 path.
arcTo(fullMoonRect, -90, 180);
1213 path.
arcTo(halfEllipseRect, 90, 180);
1216 path.
arcTo(fullMoonRect, 90, -180);
1217 path.
arcTo(halfEllipseRect, -90, 180);
1225 overlay.
begin(&moon);
1226 overlay.
setPen(Qt::NoPen);
1233 if (viewport->
polarity() < 0) angle += 180;
1236 const qreal factor = size / moon.
size().
width();
1238 Qt::SmoothTransformation);
1240 painter->
drawPixmap( x - deltaX, y - deltaY, moon );
1243 if (m_viewSolarSystemLabel)
1249 foreach(
const QString &planet, m_renderPlanet.
keys()) {
1250 if (m_renderPlanet[planet])
1251 renderPlanet(planet, painter, sys, viewport, skyRadius, skyAxisMatrix);
1260 void StarsPlugin::renderPlanet(
const QString &planetId,
1265 matrix &skyAxisMatrix)
const
1267 double ra(.0), decl(.0), diam(.0),
mag(.0), phase(.0);
1271 if (planetId ==
"venus") {
1275 }
else if (planetId ==
"mars") {
1279 }
else if (planetId ==
"jupiter") {
1283 }
else if (planetId ==
"mercury") {
1287 }
else if (planetId ==
"saturn") {
1291 }
else if (planetId ==
"uranus") {
1295 }
else if (planetId ==
"neptune") {
1308 qpos.rotateAroundAxis( skyAxisMatrix );
1310 if ( qpos.v[
Q_Z] <= 0 ) {
1311 QPixmap planetPixmap = starPixmap(mag, color);
1313 qreal deltaX = planetPixmap.
width() / 2.;
1314 qreal deltaY = planetPixmap.
height() / 2.;
1315 const int x = (int)(viewport->
width() / 2 + skyRadius * qpos.v[
Q_X]);
1316 const int y = (int)(viewport->
height() / 2 - skyRadius * qpos.v[
Q_Y]);
1318 if (!(x < 0 || x >= viewport->
width() ||
1319 y < 0 || y >= viewport->
height())) {
1320 painter->
drawPixmap( x - deltaX, y - deltaY, planetPixmap );
1324 if (m_viewSolarSystemLabel)
1325 painter->
drawText(x+deltaX, y+deltaY, Planet(planetId).
name());
1329 void StarsPlugin::requestRepaint()
1334 void StarsPlugin::toggleSunMoon()
1339 const bool changed = !(m_renderSun || m_renderMoon);
1340 m_renderSun = changed;
1341 m_renderMoon = changed;
1343 m_viewSolarSystemLabel =
true;
1346 Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
1347 if ( m_configDialog ) {
1348 ui_configWidget->m_solarSystemListWidget->item( 0 )->setCheckState( state );
1349 ui_configWidget->m_solarSystemListWidget->item( 1 )->setCheckState( state );
1350 ui_configWidget->m_viewSolarSystemLabelCheckbox->setChecked(m_viewSolarSystemLabel);
1356 void StarsPlugin::toggleDsos()
1361 const bool changed = !(m_renderDsos || m_renderDsoLabels);
1362 m_renderDsos = changed;
1363 m_renderDsoLabels = changed;
1365 Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
1366 if ( m_configDialog ) {
1367 ui_configWidget->m_viewDsosCheckbox->setChecked(state);
1368 ui_configWidget->m_viewDsoLabelCheckbox->setChecked(state);
1374 void StarsPlugin::toggleConstellations()
1379 const bool changed = !(m_renderConstellationLines || m_renderConstellationLabels);
1380 m_renderConstellationLines = changed;
1381 m_renderConstellationLabels = changed;
1383 Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
1384 if ( m_configDialog ) {
1385 ui_configWidget->m_viewConstellationLinesCheckbox->setChecked( state );
1386 ui_configWidget->m_viewConstellationLabelsCheckbox->setChecked( state );
1392 void StarsPlugin::togglePlanets()
1397 const bool changed = !planetsAction->
isChecked();
1398 m_renderPlanet[
"venus"] = changed;
1399 m_renderPlanet[
"mars"] = changed;
1400 m_renderPlanet[
"jupiter"] = changed;
1401 m_renderPlanet[
"mercury"] = changed;
1402 m_renderPlanet[
"saturn"] = changed;
1403 m_renderPlanet[
"uranus"] = changed;
1404 m_renderPlanet[
"neptune"] = changed;
1406 Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
1407 if ( m_configDialog ) {
1409 ui_configWidget->m_solarSystemListWidget->item(2)->setCheckState(state);
1410 ui_configWidget->m_solarSystemListWidget->item(3)->setCheckState(state);
1411 ui_configWidget->m_solarSystemListWidget->item(5)->setCheckState(state);
1412 ui_configWidget->m_solarSystemListWidget->item(6)->setCheckState(state);
1413 ui_configWidget->m_solarSystemListWidget->item(7)->setCheckState(state);
1414 ui_configWidget->m_solarSystemListWidget->item(8)->setCheckState(state);
1415 ui_configWidget->m_solarSystemListWidget->item(9)->setCheckState(state);
1428 if( e->
type() == QEvent::ContextMenu )
1432 if( widget && menuEvent )
1434 qreal mouseLon, mouseLat;
1435 const bool aboveMap = widget->
geoCoordinates( menuEvent->
x(), menuEvent->
y(),
1449 bool scheduleConfigAction =
false;
1450 if (!m_contextMenu) {
1451 m_contextMenu =
new QMenu;
1452 scheduleConfigAction =
true;
1455 if (!m_constellationsAction) {
1456 m_constellationsAction =
1457 m_contextMenu->addAction(
tr(
"Show &Constellations"),
1458 this, SLOT(toggleConstellations()) );
1461 m_constellationsAction->setCheckable(
true );
1462 m_constellationsAction->setChecked(
1463 m_renderConstellationLines || m_renderConstellationLabels );
1466 if (!m_sunMoonAction) {
1467 m_sunMoonAction = m_contextMenu->addAction(
tr(
"Show &Sun and Moon"),
1468 this, SLOT(toggleSunMoon()) );
1471 m_sunMoonAction->setCheckable(
true );
1472 m_sunMoonAction->setChecked( m_renderSun || m_renderMoon || m_viewSolarSystemLabel );
1474 if (!m_planetsAction) {
1475 m_planetsAction = m_contextMenu->addAction(
tr(
"Show &Planets"),
1476 this, SLOT(togglePlanets()));
1479 m_planetsAction->setCheckable(
true );
1480 if (m_renderPlanet[
"venus"] || m_renderPlanet[
"mars"] ||
1481 m_renderPlanet[
"jupiter"] || m_renderPlanet[
"mercury"] ||
1482 m_renderPlanet[
"saturn"] || m_renderPlanet[
"uranus"] ||
1483 m_renderPlanet[
"neptune"]) {
1485 m_planetsAction->setChecked(
true );
1487 m_planetsAction->setChecked(
false );
1491 m_dsoAction = m_contextMenu->addAction(
tr(
"Show &Deep Sky Objects"),
1492 this, SLOT(toggleDsos()) );
1495 m_dsoAction->setCheckable(
true );
1496 m_dsoAction->setChecked( m_renderDsos || m_renderDsoLabels );
1498 if (scheduleConfigAction) {
1501 m_contextMenu->addSeparator();
1502 QAction *configAction = m_contextMenu->addAction(
tr(
"&Configure..." ) );
1503 connect( configAction, SIGNAL(triggered()), dialog, SLOT(exec()) );
1519 #include "StarsPlugin.moc"
void addEllipse(const QRectF &boundingRectangle)
void toMatrix(matrix &m) const
bool isInitialized() const
bool visible() const
is visible
void getUranus(double &ra, double &decl)
bool visible() const
Check visibility of the float item.
QString description() const
Returns a user description of the plugin.
bool load(QIODevice *device, const char *format)
void setCentralBody(const char *pname)
double angle(double vec1[3], double vec2[3])
QPixmap copy(int x, int y, int width, int height) const
void setRenderHint(RenderHint hint, bool on)
static QString path(const QString &relativePath)
void append(const T &value)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
bool eventFilter(QObject *object, QEvent *e)
bool render(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Renders the content provided by the layer on the viewport.
void repaintNeeded(QRegion dirtyRegion=QRegion())
This signal is emitted if an update of the view is needed.
void getPhysSun(double &pdiam, double &pmag)
void getJupiter(double &ra, double &decl)
A painter that allows to draw geometric primitives on the map.
QStringList renderPosition() const
Preferred level in the layer stack for the rendering.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
bool eventFilter(QObject *, QEvent *)
This file contains the headers for MarbleModel.
QDialog * configDialog()
Returns a pointer to the configuration dialog of the plugin.
const T & at(int i) const
void celestialPoleGetColor()
QStringList backendTypes() const
Returns the name(s) of the backend that the plugin can render This method should return the name of t...
QString renderPolicy() const
Return how the plugin settings should be used.
void moveTo(const QPointF &point)
void getNeptune(double &ra, double &decl)
static double DmsDegF(double h)
Projection projection() const
QString join(const QString &separator) const
void drawLine(const QLineF &line)
const Planet * planet() const
Returns the planet object for the current map.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
QDateTime dateTime() const
Returns the internal date and time.
void rotateAroundAxis(const Quaternion &q)
void setHeight(qreal height)
const QColor & color() const
QList< Key > keys() const
void getLunarPhase(double &phase, double &ildisk, double &amag)
QString number(int n, int base)
bool contains(const QPointF &point) const
Returns true if the Item contains point in parent coordinates.
void append(const T &value)
Layer of a GeoScene document.
void setPen(const QColor &color)
void settingsChanged(QString nameId)
This signal is emitted if the settings of the RenderPlugin changed.
The abstract class for float item plugins.
bool mapCoversViewport() const
QIcon icon() const
Returns an icon for the plugin.
virtual RenderType renderType() const
Render type of the plugin.
QHash< QString, QVariant > settings() const
Settings of the plugin.
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
void setBrush(const QBrush &brush)
bool load(const QString &fileName, const char *format, QFlags< Qt::ImageConversionFlag > flags)
A public class that controls what is visible in the viewport of a Marble map.
#define Q_EXPORT_PLUGIN2(a, b)
const T value(const Key &key) const
void drawImage(const GeoDataCoordinates ¢erPosition, const QImage &image)
Draws an image at the given position. The image is placed with its center located at the given center...
void constellationLabelGetColor()
QColor getColor(const QColor &initial, QWidget *parent, const QString &title, QFlags< QColorDialog::ColorDialogOption > options)
This file contains the headers for ViewportParams.
QString guiString() const
String that should be displayed in GUI.
void constellationGetColor()
qreal centerLatitude() const
void celestialEquatorGetColor()
void drawText(const GeoDataCoordinates &position, const QString &text)
Draws the given text at a given geographic position. The text is drawn starting at the given position...
const T & at(int i) const
The data model (not based on QAbstractModel) for a MarbleWidget.
QString nameId() const
Returns the unique name of the plugin.
QString copyrightYears() const
QByteArray toLatin1() const
void getVenus(double &ra, double &decl)
void drawPath(const QPainterPath &path)
Quaternion inverse() const
void getPhysUranus(double &pdiam, double &pmag, double &pphase)
QColor const aluminumGray5
qreal centerLongitude() const
void getSun(double &ra, double &decl)
void setWidth(qreal width)
void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
void getPhysVenus(double &pdiam, double &pmag, double &pphase)
const QChar at(int position) const
void getMercury(double &ra, double &decl)
QString assembledConstellation(const QString &name)
void getSaturn(double &ra, double &decl)
QString name() const
Returns the user-visible name of the plugin.
void getMoon(double &ra, double &decl)
qreal epsilon() const
obliquity of the ecliptic plane
void getPhysSaturn(double &pdiam, double &pmag, double &pphase)
bool enabled() const
is enabled
void getPhysJupiter(double &pdiam, double &pmag, double &pphase)
StarsPlugin(const MarbleModel *marbleModel=0)
void getPhysMars(double &pdiam, double &pmag, double &pphase)
const MarbleModel * marbleModel() const
Access to the MarbleModel.
void setCurrentMJD(int year, int month, int day, int hour, int min, double sec)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
virtual QHash< QString, QVariant > settings() const
Settings of the plugin.
bool begin(QPaintDevice *device)
RenderType
A Type of plugin.
void arcTo(const QRectF &rectangle, qreal startAngle, qreal sweepLength)
void getPhysNeptune(double &pdiam, double &pmag, double &pphase)
QDebug mDebug()
a function to replace qDebug() in Marble library code
void drawPixmap(const GeoDataCoordinates ¢erPosition, const QPixmap &pixmap)
Draws a pixmap at the given position. The pixmap is placed with its center located at the given cente...
The abstract class that creates a renderable item.
virtual void setSettings(const QHash< QString, QVariant > &settings)
Set the settings of the plugin.
static Quaternion fromEuler(qreal pitch, qreal yaw, qreal roll)
QList< PluginAuthor > pluginAuthors() const
static Quaternion fromSpherical(qreal lon, qreal lat)
used to generate Quaternion from longitude and latitude
Vec3 getPlanetocentric(double ra, double decl)
void getMars(double &ra, double &decl)
void getPhysMercury(double &pdiam, double &pmag, double &pphase)