8#include "xplanetimageviewer.h"
10#include "dialogs/timedialog.h"
11#include "ksnotification.h"
13#include <QtConcurrent>
25#include <QResizeEvent>
27#include <QTemporaryFile>
30#include <QApplication>
39#include <QInputDialog>
46 JUPITER, GANYMEDE, IO, CALLISTO, EUROPA,
47 SATURN, TITAN, MIMAS, ENCELADUS, TETHYS, DIONE, RHEA, HYPERION, IAPETUS, PHOEBE,
48 URANUS, UMBRIEL, ARIEL, MIRANDA, TITANIA, OBERON,
52XPlanetImageLabel::XPlanetImageLabel(
QWidget *parent) :
QFrame(parent)
62void XPlanetImageLabel::setImage(
const QImage &img)
70void XPlanetImageLabel::invertPixels()
73 m_Image.invertPixels();
84 if (m_Pix.width() <
width())
85 x = (
width() - m_Pix.width()) / 2;
93 if (event->size() == m_Pix.size())
99void XPlanetImageLabel::refreshImage()
123bool XPlanetImageLabel::event(
QEvent *event)
126 return gestureEvent(
dynamic_cast<QGestureEvent *
>(event));
133 pinchTriggered(
dynamic_cast<QPinchGesture *
>(pinch));
138void XPlanetImageLabel::pinchTriggered(
QPinchGesture *gesture)
147void XPlanetImageLabel::mousePressEvent(
QMouseEvent *e)
149 m_MouseButtonDown =
true;
154void XPlanetImageLabel::mouseReleaseEvent(
QMouseEvent *e)
156 m_MouseButtonDown =
false;
160void XPlanetImageLabel::mouseMoveEvent(
QMouseEvent *e)
162 if(m_MouseButtonDown)
165 int dx = newPoint.
x() - m_LastMousePoint.x();
166 int dy = newPoint.
y() - m_LastMousePoint.y();
168 emit changeLocation(QPoint(dx, dy));
170 emit changePosition(QPoint(dx, dy));
171 m_LastMousePoint = newPoint;
188 setXPlanetDate(KStarsData::Instance()->ut());
203 m_ObjectNames <<
i18n(
"Sun") <<
i18n(
"Mercury") <<
i18n(
"Venus");
204 m_objectDefaultFOVs << 0.74818 << 0.004 << 0.02;
205 m_ObjectNames <<
i18n(
"Earth") <<
i18n(
"Moon");
206 m_objectDefaultFOVs << 1.0 << 0.74818;
207 m_ObjectNames <<
i18n(
"Mars") <<
i18n(
"Phobos") <<
i18n(
"Deimos");
208 m_objectDefaultFOVs << 0.00865 << 0.00002 << 0.00002;
209 m_ObjectNames <<
i18n(
"Jupiter") <<
i18n(
"Ganymede") <<
i18n(
"Io") <<
i18n(
"Callisto") <<
i18n(
"Europa");
210 m_objectDefaultFOVs << 0.02 << 0.0005 << 0.0004 << 0.0005 << 0.0003;
212 m_objectDefaultFOVs << 0.02 << 0.0003 << 0.00002 << 0.00003 << 0.00007 << 0.00007 << 0.0001 << 0.00002 << 0.0001 << 0.00002;
213 m_ObjectNames <<
i18n(
"Uranus") <<
i18n(
"Umbriel") <<
i18n(
"Ariel") <<
i18n(
"Miranda") <<
i18n(
"Titania") <<
i18n(
"Oberon");
214 m_objectDefaultFOVs << 0.00256 << 0.00004 << 0.00004 << 0.00002 << 0.00005 << 0.00005;
215 m_ObjectNames <<
i18n(
"Neptune") <<
i18n(
"Triton");
216 m_objectDefaultFOVs << 0.00114 << 0.0001;
218 m_CurrentObjectIndex = m_ObjectNames.indexOf(obj);
219 if (m_CurrentObjectIndex < 0)
221 m_CurrentObjectIndex = 13;
222 m_ObjectName = m_ObjectNames.at(m_CurrentObjectIndex);
225 objectSelector->
addItems(m_ObjectNames);
226 objectSelector->
setToolTip(
i18n(
"This allows you to select a new object/target for XPlanet to view"));
227 selectorsLayout->
addWidget(objectSelector);
229 connect(objectSelector, SIGNAL(currentIndexChanged(
int)),
this, SLOT(updateXPlanetObject(
int)));
231 m_CurrentOriginIndex = EARTH;
232 m_OriginName = m_ObjectNames.at(EARTH);
236 m_OriginSelector->addItems(m_ObjectNames);
237 m_OriginSelector->setToolTip(
i18n(
"This allows you to select a viewing location"));
238 selectorsLayout->
addWidget(m_OriginSelector);
239 m_OriginSelector->setCurrentIndex(EARTH);
240 connect(m_OriginSelector, SIGNAL(currentIndexChanged(
int)),
this, SLOT(updateXPlanetOrigin(
int)));
242 m_lat = Options::xplanetLatitude().toDouble();
243 m_lon = Options::xplanetLongitude().toDouble();
248 m_PositionDisplay =
new QLabel(
this);
249 m_PositionDisplay->setToolTip(
i18n(
"XPlanet Latitude, Longitude, and object radius in %. This is only valid when viewing the object from the same object"));
250 updatePositionDisplay();
251 m_PositionDisplay->setDisabled(
true);
252 selectorsLayout->
addWidget(m_PositionDisplay);
259 resetXPlanetLocation->
setToolTip(
i18n(
"Reset XPlanet Location to the location specified in the XPlanet Options"));
260 selectorsLayout->
addWidget(resetXPlanetLocation);
261 connect(resetXPlanetLocation, SIGNAL(clicked()),
this, SLOT(resetLocation()));
266 m_FreeRotate->setMaximumSize(
QSize(32, 32));
267 m_FreeRotate->setMinimumSize(
QSize(32, 32));
268 m_FreeRotate->setCheckable(
true);
269 m_FreeRotate->setToolTip(
i18n(
"Hover over target and freely rotate view with mouse in XPlanet Viewer"));
270 selectorsLayout->
addWidget(m_FreeRotate);
271 connect(m_FreeRotate, SIGNAL(clicked()),
this, SLOT(slotFreeRotate()));
278 reCenterB->
setToolTip(
i18n(
"Recenters the XPlanet image once it has been moved"));
280 connect(reCenterB, SIGNAL(clicked()),
this, SLOT(reCenterXPlanet()));
289 connect(saveB, SIGNAL(clicked()),
this, SLOT(saveFileToDisk()));
294 mainLayout->
addWidget(viewControlsWidget);
298 m_FOVEdit =
new NonLinearDoubleSpinBox();
299 m_FOVEdit->setDecimals(5);
302 for(
double i = .0001; i < 100; i *= 1.5)
304 m_FOVEdit->setRecommendedValues(possibleValues);
305 m_FOVEdit->setToolTip(
i18n(
"Sets the FOV to the Specified value. Note: has no effect if hovering over object."));
306 viewControlsLayout->
addWidget(m_FOVEdit);
308 if (Options::xplanetFOV())
311 m_FOV = m_objectDefaultFOVs.at( m_CurrentObjectIndex);
312 m_FOVEdit->setValue(m_FOV);
314 connect(m_FOVEdit, SIGNAL(valueChanged(
double)),
this, SLOT(updateXPlanetFOVEdit()));
319 m_KStarsFOV->setMaximumSize(
QSize(32, 32));
320 m_KStarsFOV->setMinimumSize(
QSize(32, 32));
321 m_KStarsFOV->setToolTip(
i18n(
"Zoom to the current KStars FOV. Note: has no effect if hovering over object."));
322 viewControlsLayout->
addWidget(m_KStarsFOV);
323 connect(m_KStarsFOV, SIGNAL(clicked()),
this, SLOT(setKStarsXPlanetFOV()));
328 m_setFOV->setMaximumSize(
QSize(32, 32));
329 m_setFOV->setMinimumSize(
QSize(32, 32));
330 m_setFOV->setToolTip(
i18n(
"Zoom to a specific FOV. This has no effect when hovering over an object"));
332 connect(m_setFOV, SIGNAL(clicked()),
this, SLOT(setFOVfromList()));
337 m_NoFOV->setMaximumSize(
QSize(32, 32));
338 m_NoFOV->setMinimumSize(
QSize(32, 32));
339 m_NoFOV->setToolTip(
i18n(
"Optimum FOV for the target, FOV parameter not specified. Note: has no effect if hovering over object."));
341 connect(m_NoFOV, SIGNAL(clicked()),
this, SLOT(resetXPlanetFOV()));
349 m_RotateEdit->setRange(-180, 180);
350 m_RotateEdit->setValue(0);
351 m_RotateEdit->setSingleStep(10);
352 m_RotateEdit->setToolTip(
i18n(
"Set the view rotation to the desired angle"));
353 viewControlsLayout->
addWidget(m_RotateEdit);
354 connect(m_RotateEdit, SIGNAL(valueChanged(
int)),
this, SLOT(updateXPlanetRotationEdit()));
362 viewControlsLayout->
addWidget(invertRotation);
363 connect(invertRotation, SIGNAL(clicked()),
this, SLOT(invertXPlanetRotation()));
371 viewControlsLayout->
addWidget(resetRotation);
372 connect(resetRotation, SIGNAL(clicked()),
this, SLOT(resetXPlanetRotation()));
388 invertB->
setToolTip(
i18n(
"Reverse colors of the image. This is useful to enhance contrast at times. This affects "
389 "only the display and not the saving."));
391 connect(invertB, SIGNAL(clicked()),
this, SLOT(invertColors()));
398 m_XPlanetTime = KStarsData::Instance()->lt();
405 setTime->
setToolTip(
i18n(
"Allows you to set the XPlanet time to a different date/time from KStars"));
407 connect(setTime, SIGNAL(clicked()),
this, SLOT(setXPlanetTime()));
414 kstarsTime->
setToolTip(
i18n(
"Sets the XPlanet time to the current KStars time"));
416 connect(kstarsTime, SIGNAL(clicked()),
this, SLOT(setXPlanetTimetoKStarsTime()));
418 m_XPlanetTimeDisplay =
new QLabel(
this);
419 m_XPlanetTimeDisplay->setToolTip(
i18n(
"Current XPlanet Time"));
420 timeLayout->
addWidget(m_XPlanetTimeDisplay);
422 m_XPlanetTimeDisplay->setText(
i18n(
"%1, %2", m_XPlanetTime.date().toString(), m_XPlanetTime.time().toString()));
425 m_TimeSlider->setTracking(
false);
426 connect(m_TimeSlider, SIGNAL(sliderMoved(
int)),
this, SLOT(timeSliderDisplay(
int)));
428 m_TimeSlider->setRange(-100, 100);
429 m_TimeSlider->setToolTip(
i18n(
"This sets the time step from the current XPlanet time, good for viewing events"));
430 connect(m_TimeSlider, SIGNAL(valueChanged(
int)),
this, SLOT(updateXPlanetTime(
int)));
433 m_TimeEdit->setRange(-10000, 10000);
434 m_TimeEdit->setMaximumWidth(50);
435 m_TimeEdit->setToolTip(
i18n(
"This sets the time step from the current XPlanet time"));
437 connect(m_TimeEdit, SIGNAL(valueChanged(
int)),
this, SLOT(updateXPlanetTimeEdit()));
439 m_CurrentTimeUnitIndex = MINS;
441 timeLayout->
addWidget(m_TimeUnitsSelect);
442 m_TimeUnitsSelect->addItem(
i18n(
"years"));
443 m_TimeUnitsSelect->addItem(
i18n(
"months"));
444 m_TimeUnitsSelect->addItem(
i18n(
"days"));
445 m_TimeUnitsSelect->addItem(
i18n(
"hours"));
446 m_TimeUnitsSelect->addItem(
i18n(
"minutes"));
447 m_TimeUnitsSelect->addItem(
i18n(
"seconds"));
448 m_TimeUnitsSelect->setCurrentIndex(MINS);
449 m_TimeUnitsSelect->setToolTip(
i18n(
"Lets you change the units for the timestep in the animation"));
450 connect(m_TimeUnitsSelect, SIGNAL(currentIndexChanged(
int)),
this, SLOT(updateXPlanetTimeUnits(
int)));
452 m_XPlanetTimer =
new QTimer(
this);
453 m_XPlanetTimer->setInterval(Options::xplanetAnimationDelay());
454 connect(m_XPlanetTimer, SIGNAL(timeout()),
this, SLOT(incrementXPlanetTime()));
459 m_RunTime->setCheckable(
true);
460 m_RunTime->setMaximumSize(
QSize(32, 32));
461 m_RunTime->setMinimumSize(
QSize(32, 32));
462 m_RunTime->setToolTip(
i18n(
"Lets you run the animation"));
464 connect(m_RunTime, SIGNAL(clicked()),
this, SLOT(toggleXPlanetRun()));
471 resetTime->
setToolTip(
i18n(
"Resets the animation to 0 timesteps from the current XPlanet Time"));
473 connect(resetTime, SIGNAL(clicked()),
this, SLOT(resetXPlanetTime()));
476 m_View->setAutoFillBackground(
false);
477 m_Caption =
new QLabel(page);
478 m_Caption->setAutoFillBackground(
true);
480 m_Caption->setText(m_ObjectName);
489 connect(m_View, SIGNAL(zoomIn()),
this, SLOT(zoomInXPlanetFOV()));
490 connect(m_View, SIGNAL(zoomOut()),
this, SLOT(zoomOutXPlanetFOV()));
491 connect(m_View, SIGNAL(changePosition(
QPoint)),
this, SLOT(changeXPlanetPosition(
QPoint)));
492 connect(m_View, SIGNAL(changeLocation(
QPoint)),
this, SLOT(changeXPlanetLocation(
QPoint)));
498 m_Caption->setPalette(p);
499 m_View->setPalette(p);
502 if(Options::xplanetUseFIFO())
504 connect(&watcherTimeout, SIGNAL(timeout()), &fifoImageLoadWatcher, SLOT(cancel()));
505 connect(&fifoImageLoadWatcher, SIGNAL(
finished()),
this, SLOT(showImage()));
512 for (
auto &button : qButtons)
513 button->setAutoDefault(
false);
515 updateXPlanetTime(0);
524void XPlanetImageViewer::startXplanet()
530 if(!setupOutputFile())
533 QString xPlanetLocation = Options::xplanetPath();
535 if (Options::xplanetIsInternal())
542 KSNotification::error(
i18n(
"Xplanet binary path is empty in config panel."));
547 const QFileInfo xPlanetLocationInfo(xPlanetLocation);
548 if (!xPlanetLocationInfo.exists() || !xPlanetLocationInfo.isExecutable())
550 KSNotification::error(
i18n(
"The configured Xplanet binary does not exist or is not executable."));
555 QProcess *xplanetProc =
new QProcess(
this);
561 args <<
"-body" << m_ObjectName.toLower();
563 args <<
"-date" << m_Date;
565 args <<
"-glare" << Options::xplanetGlare();
566 args <<
"-base_magnitude" << Options::xplanetMagnitude();
568 args <<
"-light_time";
580 if (Options::xplanetConfigFile())
581 args <<
"-config" << Options::xplanetConfigFilePath();
582 if (Options::xplanetStarmap())
583 args <<
"-starmap" << Options::xplanetStarmapPath();
584 if (Options::xplanetArcFile())
585 args <<
"-arc_file" << Options::xplanetArcFilePath();
586 if (!m_File.fileName().isEmpty())
587 args <<
"-output" << m_File.fileName() <<
"-quality" << Options::xplanetQuality();
590 if (Options::xplanetLabel())
592 args <<
"-fontsize" << Options::xplanetFontSize() <<
"-color"
593 <<
"0x" + Options::xplanetColor().
mid(1) <<
"-date_format" << Options::xplanetDateFormat();
595 if (Options::xplanetLabelGMT())
599 if (!Options::xplanetLabelString().isEmpty())
600 args <<
"-label_string"
601 <<
"\"" + Options::xplanetLabelString() +
"\"";
602 if (Options::xplanetLabelTL())
605 else if (Options::xplanetLabelTR())
608 else if (Options::xplanetLabelBR())
611 else if (Options::xplanetLabelBL())
617 if (Options::xplanetMarkerFile())
618 args <<
"-marker_file" << Options::xplanetMarkerFilePath();
619 if (Options::xplanetMarkerBounds())
620 args <<
"-markerbounds" << Options::xplanetMarkerBoundsPath();
626 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
628 if (Options::xplanetRandom())
634 args <<
"-origin" << m_OriginName;
639 args <<
"-center" <<
"+" +
QString::number(Options::xplanetWidth() / 2 + center.x()) +
"+" +
QString::number(Options::xplanetHeight() / 2 + center.y());
642 if (Options::xplanetProjection())
644 switch (Options::xplanetProjection())
647 args <<
"-projection"
651 args <<
"-projection"
655 args <<
"-projection"
659 args <<
"-projection"
663 args <<
"-projection"
667 args <<
"-projection"
671 args <<
"-projection"
675 args <<
"-projection"
679 args <<
"-projection"
683 args <<
"-projection"
687 args <<
"-projection"
691 args <<
"-projection"
695 args <<
"-projection"
701 if (Options::xplanetBackground())
703 if (Options::xplanetBackgroundImage())
704 args <<
"-background" << Options::xplanetBackgroundImagePath();
706 args <<
"-background"
707 <<
"0x" + Options::xplanetBackgroundColorValue().
mid(1);
713 args <<
"-searchdir" << searchDir;
717 QString searchDir = xPlanetLocationInfo.dir().absolutePath() +
QDir::separator() +
"xplanet";
718 args <<
"-searchdir" << searchDir;
722 args <<
"-num_times" <<
"1";
724 m_XPlanetRunning =
true;
725 m_ImageLoadSucceeded =
false;
726 uint32_t timeout = Options::xplanetTimeout();
730 if(Options::xplanetUseFIFO())
732#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
737 watcherTimeout.setSingleShot(
true);
738 watcherTimeout.start(timeout);
742 xplanetProc->
start(xPlanetLocation, args);
748 m_XPlanetRunning =
false;
754 m_Caption->setText(
i18n(
"XPlanet View: %1 from %2 on %3", m_ObjectName, m_OriginName, m_DateText));
756 m_Caption->setText(
i18n(
"XPlanet View: %1 from %2 on %3 at FOV: %4 deg", m_ObjectName, m_OriginName, m_DateText, m_FOV));
760 if(Options::xplanetUseFIFO())
766 if(m_ImageLoadSucceeded)
770 KSNotification::error(
i18n(
"Loading of the image of object %1 failed.", m_ObjectName));
777 if(Options::xplanetUseFIFO())
778 fifoImageLoadWatcher.cancel();
783bool XPlanetImageViewer::setupOutputFile()
786 if(Options::xplanetUseFIFO())
788 if(m_File.fileName().contains(
"xplanetfifo") && m_File.exists())
791 kstarsTempDir.mkpath(
".");
792 m_File.setFileName(kstarsTempDir.filePath(QString(
"xplanetfifo%1.png").arg(
QUuid::createUuid().
toString().mid(1, 8)).toLatin1()));
793 if (mkfifo(m_File.fileName().toLatin1(), S_IRUSR | S_IWUSR) < 0)
795 KSNotification::error(
i18n(
"Error making FIFO file %1: %2.", m_File.fileName(), strerror(errno)));
804 xPlanetDirPath.mkpath(
".");
805 m_File.setFileName(xPlanetDirPath.filePath(m_ObjectName +
".png"));
809void XPlanetImageViewer::zoomInXPlanetFOV()
811 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
814 updatePositionDisplay();
819 m_FOVEdit->stepDown();
825void XPlanetImageViewer::zoomOutXPlanetFOV()
827 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
832 updatePositionDisplay();
844void XPlanetImageViewer::updatePositionDisplay()
849void XPlanetImageViewer::updateXPlanetTime(
int timeShift)
852 KStarsDateTime shiftedXPlanetTime;
853 switch(m_CurrentTimeUnitIndex)
856 shiftedXPlanetTime = m_XPlanetTime.
addDays(timeShift * 365);
860 shiftedXPlanetTime = m_XPlanetTime.
addDays(timeShift * 30);
864 shiftedXPlanetTime = m_XPlanetTime.
addDays(timeShift);
868 shiftedXPlanetTime = m_XPlanetTime.
addSecs(timeShift * 3600);
872 shiftedXPlanetTime = m_XPlanetTime.
addSecs(timeShift * 60);
876 shiftedXPlanetTime = m_XPlanetTime.
addSecs(timeShift);
880 setXPlanetDate(shiftedXPlanetTime);
882 if(m_TimeEdit->value() != timeShift)
883 m_TimeEdit->setValue(timeShift);
888void XPlanetImageViewer::updateXPlanetObject(
int objectIndex)
890 center = QPoint(0, 0);
891 m_CurrentObjectIndex = objectIndex;
892 m_ObjectName = m_ObjectNames.at(objectIndex);
894 setWindowTitle(
i18nc(
"@title:window",
"XPlanet Solar System Simulator: %1", m_ObjectName));
895 if(m_FreeRotate->isChecked())
896 m_OriginSelector->setCurrentIndex(m_CurrentObjectIndex);
897 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
903void XPlanetImageViewer::updateXPlanetOrigin(
int originIndex)
905 center = QPoint(0, 0);
906 m_CurrentOriginIndex = originIndex;
907 m_OriginName = m_ObjectNames.at(originIndex);
908 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
909 m_FreeRotate->setChecked(
true);
911 m_FreeRotate->setChecked(
false);
916void XPlanetImageViewer::changeXPlanetLocation(
QPoint delta)
918 if(m_CurrentObjectIndex == m_CurrentOriginIndex)
920 double newLon = m_lon + delta.
x();
921 double newLat = m_lat + delta.
y();
923 newLat = qBound(-90.0, newLat, 90.0);
928 updatePositionDisplay();
933void XPlanetImageViewer::changeXPlanetPosition(
QPoint delta)
935 center.setX(center.x() + delta.
x());
936 center.setY(center.y() + delta.
y());
940void XPlanetImageViewer::reCenterXPlanet()
942 center = QPoint(0, 0);
946void XPlanetImageViewer::resetLocation()
948 m_lat = Options::xplanetLatitude().toDouble();
949 m_lon = Options::xplanetLongitude().toDouble();
951 updatePositionDisplay();
955void XPlanetImageViewer::slotFreeRotate()
957 if(m_FreeRotate->isChecked())
958 m_OriginSelector->setCurrentIndex(m_CurrentObjectIndex);
960 m_OriginSelector->setCurrentIndex(EARTH);
963void XPlanetImageViewer::updateStates()
965 if(m_FreeRotate->isChecked())
967 m_FOVEdit->setDisabled(
true);
968 m_KStarsFOV->setDisabled(
true);
969 m_NoFOV->setDisabled(
true);
971 m_PositionDisplay->setDisabled(
false);
975 m_FOVEdit->setDisabled(
false);
976 m_KStarsFOV->setDisabled(
false);
977 m_NoFOV->setDisabled(
false);
979 m_PositionDisplay->setDisabled(
true);
986 KStarsDateTime utTime = KStarsData::Instance()->
geo()->LTtoUT(time);
994void XPlanetImageViewer::updateXPlanetTimeUnits(
int units)
996 m_CurrentTimeUnitIndex = units;
997 updateXPlanetTimeEdit();
1000void XPlanetImageViewer::updateXPlanetTimeEdit()
1002 if(m_TimeSlider->isSliderDown())
1004 int timeShift = m_TimeEdit->value();
1005 if(m_TimeSlider->value() != timeShift)
1008 if(timeShift > m_TimeSlider->maximum() + 100)
1009 m_TimeSlider->setMaximum(timeShift);
1010 if(timeShift < m_TimeSlider->minimum() - 100)
1011 m_TimeSlider->setMinimum(timeShift);
1012 m_TimeSlider->setValue(timeShift);
1015 updateXPlanetTime(timeShift);
1018void XPlanetImageViewer::timeSliderDisplay(
int timeShift)
1020 m_TimeEdit->setValue(timeShift);
1023void XPlanetImageViewer::incrementXPlanetTime()
1025 if(!m_XPlanetRunning)
1027 int timeShift = m_TimeEdit->value();
1028 if(m_TimeSlider->maximum() <= timeShift)
1029 m_TimeSlider->setMaximum(timeShift + 100);
1030 if(m_TimeEdit->maximum() <= timeShift)
1031 m_TimeEdit->setMaximum(timeShift + 100);
1032 m_TimeSlider->setValue(timeShift + 1);
1036void XPlanetImageViewer::setXPlanetTime()
1038 QPointer<TimeDialog> timedialog =
new TimeDialog(m_XPlanetTime, KStarsData::Instance()->
geo(),
this);
1041 m_XPlanetTime = timedialog->selectedDateTime();
1042 m_XPlanetTimeDisplay->setText(
i18n(
"%1, %2", m_XPlanetTime.date().toString(), m_XPlanetTime.time().toString()));
1044 m_TimeSlider->setRange(-100, 100);
1045 if(m_TimeSlider->value() != timeShift)
1046 m_TimeSlider->setValue(timeShift);
1048 updateXPlanetTime(timeShift);
1052void XPlanetImageViewer::setXPlanetTimetoKStarsTime()
1054 m_XPlanetTime = KStarsData::Instance()->
lt();
1055 m_XPlanetTimeDisplay->setText(
i18n(
"%1, %2", m_XPlanetTime.date().toString(), m_XPlanetTime.time().toString()));
1057 m_TimeSlider->setRange(-100, 100);
1058 if(m_TimeSlider->value() != timeShift)
1059 m_TimeSlider->setValue(timeShift);
1061 updateXPlanetTime(timeShift);
1064void XPlanetImageViewer::resetXPlanetTime()
1067 m_TimeSlider->setRange(-100, 100);
1068 if(m_TimeSlider->value() != timeShift)
1069 m_TimeSlider->setValue(timeShift);
1071 updateXPlanetTime(timeShift);
1074void XPlanetImageViewer::toggleXPlanetRun()
1076 if(m_XPlanetTimer->isActive())
1078 m_XPlanetTimer->stop();
1080 if(Options::xplanetUseFIFO())
1081 fifoImageLoadWatcher.cancel();
1086 m_XPlanetTimer->setInterval(Options::xplanetAnimationDelay());
1087 m_XPlanetTimer->start();
1091void XPlanetImageViewer::updateXPlanetFOVEdit()
1093 m_FOV = m_FOVEdit->value();
1097void XPlanetImageViewer::resetXPlanetFOV()
1099 m_FOV = m_objectDefaultFOVs.at(m_CurrentObjectIndex);
1100 m_FOVEdit->setValue(m_FOV);
1104void XPlanetImageViewer::setKStarsXPlanetFOV()
1107 m_FOVEdit->setValue(m_FOV);
1110void XPlanetImageViewer::setFOVfromList()
1112 if (!KStarsData::Instance()->getAvailableFOVs().isEmpty())
1115 QMap<QString, const FOV *> nameToFovMap;
1116 for (
const FOV *f : KStarsData::Instance()->getAvailableFOVs())
1118 nameToFovMap.
insert(f->name(), f);
1121 const FOV *fov =
nullptr;
1123 i18n(
"FOV to render in XPlanet:"), nameToFovMap.
keys(), 0,
1127 m_FOV = fov->sizeX() / 60 ;
1128 m_FOVEdit->setValue(m_FOV);
1134void XPlanetImageViewer::updateXPlanetRotationEdit()
1136 m_Rotation = m_RotateEdit->value();
1140void XPlanetImageViewer::resetXPlanetRotation()
1142 m_RotateEdit->setValue(0);
1145void XPlanetImageViewer::invertXPlanetRotation()
1147 m_RotateEdit->setValue(180);
1154 if (!m_Image.load(m_File.fileName()))
1156 m_ImageLoadSucceeded =
false;
1159 m_ImageLoadSucceeded =
true;
1162 imageLoadSucceeded =
false;
1167bool XPlanetImageViewer::showImage()
1174 int w = deskRect.
width();
1175 int h = deskRect.
height();
1179 else if (m_Image.
height() <= h && m_Image.
width() > w)
1181 else if (m_Image.
width() > w && m_Image.
height() > h)
1184 float fx = float(w) / float(m_Image.
width());
1185 float fy = float(h) / float(m_Image.
height());
1187 m_Image = m_Image.
scaled(
int(m_Image.
width() * fy), h);
1189 m_Image = m_Image.
scaled(w,
int(m_Image.
height() * fx));
1195 m_View->setImage(m_Image);
1196 w = m_Image.width();
1200 if (m_Caption->width() > w)
1201 w = m_Caption->width();
1203 resize(w, m_Image.height());
1206 m_View->refreshImage();
1218void XPlanetImageViewer::saveFileToDisk()
1222 saveDialog.setDefaultSuffix(
"png");
1228 if(saveDialog.selectedFiles().isEmpty())
1230 QString newFileName = saveDialog.selectedFiles().first();
1234 m_LastFile = newFileName;
1236 saveFile(newFileName);
1241void XPlanetImageViewer::saveFile(
const QString &fileName)
1245 if (! m_Image.save(fileName,
"png"))
1247 KSNotification::error(
i18n(
"Saving of the image to %1 failed.", fileName));
1254void XPlanetImageViewer::invertColors()
1258 m_View->invertPixels();
const KStarsDateTime & lt() const
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
KStarsDateTime addDays(int nd) const
Modify the Date/Time by adding a number of days.
KStarsDateTime addSecs(double s) const
static KStars * Instance()
XPlanet Image viewer QFrame for the KPlanetImageViewer for KStars.
XPlanetImageViewer(const QString &obj, QWidget *parent=nullptr)
Create xplanet image viewer from Object.
~XPlanetImageViewer() override
Destructor.
bool loadImage()
loadImage Load image and display it
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
char * toString(const EngineQuery &query)
GeoCoordinates geo(const QVariant &location)
virtual void setSpacing(int spacing) override
void addItems(const QStringList &texts)
void setCurrentIndex(int index)
QString applicationDirPath()
QString toString(QStringView format, QCalendar cal) const const
QString toString(QStringView format, QCalendar cal) const const
QDialog(QWidget *parent, Qt::WindowFlags f)
void finished(int result)
void setModal(bool modal)
virtual bool event(QEvent *e) override
void restoreOverrideCursor()
QIcon fromTheme(const QString &name)
QImage scaled(const QSize &size, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
void setContentsMargins(const QMargins &margins)
QList< T > mid(qsizetype pos, qsizetype length) const const
QStatusBar * statusBar() const const
iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
QPoint globalPos() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QList< T > findChildren(Qt::FindChildOptions options) const const
QObject * parent() const const
bool begin(QPaintDevice *device)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
void start(OpenMode mode)
bool waitForFinished(int msecs)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
void showMessage(const QString &message, int timeout)
bool isEmpty() const const
QString number(double n, char format, int precision)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
MouseEventSynthesizedBySystem
QFuture< T > run(Function function,...)
QString toString(QStringView format) const const
Qt::MouseEventSource source() const const
QPoint angleDelta() const const