7 #include "scriptbuilder.h"
10 #include "scriptfunction.h"
12 #include "kstarsdata.h"
14 #include "ksnotification.h"
15 #include "kstarsdatetime.h"
16 #include "dialogs/finddialog.h"
17 #include "dialogs/locationdialog.h"
18 #include "widgets/dmsbox.h"
19 #include "widgets/timespinbox.h"
20 #include "widgets/timestepbox.h"
22 #include <KLocalizedString>
23 #include <KMessageBox>
24 #include <KIO/StoredTransferJob>
25 #include <KIO/CopyJob>
28 #include <QApplication>
29 #include <QFontMetrics>
30 #include <QTreeWidget>
31 #include <QTextStream>
32 #include <QFileDialog>
33 #include <QStandardPaths>
38 OptionsTreeViewWidget::OptionsTreeViewWidget(
QWidget *p) :
QFrame(p)
45 otvw.reset(
new OptionsTreeViewWidget(
this));
50 setLayout(mainLayout);
52 setWindowTitle(
i18nc(
"@title:window",
"Options"));
56 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
57 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
62 void OptionsTreeView::resizeColumns()
65 int maxwidth[3] = { 0, 0, 0 };
68 for (
int i = 0; i < optionsList()->topLevelItemCount(); ++i)
73 for (
int j = 0; j < topitem->
childCount(); ++j)
77 for (
int icol = 0; icol < 3; ++icol)
81 #if QT_VERSION >= QT_VERSION_CHECK(5,11,0)
89 w += 2 * optionsList()->indentation();
92 if (w > maxwidth[icol])
100 for (
int icol = 0; icol < 3; ++icol)
103 qDebug() << Q_FUNC_INFO <<
QString(
"max width of column %1: %2").
arg(icol).
arg(maxwidth[icol]);
105 optionsList()->setColumnWidth(icol, maxwidth[icol]);
119 snw =
new ScriptNameWidget(
this);
124 setLayout(mainLayout);
126 setWindowTitle(
i18nc(
"@title:window",
"Script Data"));
130 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
131 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
135 connect(snw->ScriptName, SIGNAL(textChanged(
QString)),
this, SLOT(slotEnableOkButton()));
138 ScriptNameDialog::~ScriptNameDialog()
143 void ScriptNameDialog::slotEnableOkButton()
145 okB->setEnabled(!snw->ScriptName->text().isEmpty());
153 ScriptBuilder::ScriptBuilder(
QWidget *parent)
154 :
QDialog(parent), UnsavedChanges(false), checkForChanges(true), currentFileURL(), currentDir(
QDir::homePath()),
155 currentScriptName(), currentAuthor()
160 sb =
new ScriptBuilderUI(
this);
165 setLayout(mainLayout);
167 setWindowTitle(
i18nc(
"@title:window",
"Script Builder"));
171 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(slotClose()));
177 i18n(
"Point the display at the specified location. %1 can be the name "
178 "of an object, a cardinal point on the compass, or 'zenith'.",
180 false,
"QString",
"dir"));
182 "addLabel",
i18n(
"Add a name label to the object named %1.",
QString(
"name")),
false,
"QString",
"name"));
183 KStarsFunctionList.append(
185 false,
"QString",
"name"));
187 "addTrail",
i18n(
"Add a trail to the solar system body named %1.",
QString(
"name")),
false,
"QString",
"name"));
189 "removeTrail",
i18n(
"Remove the trail from the solar system body named %1.",
QString(
"name")),
false,
"QString",
192 i18n(
"Point the display at the specified RA/Dec coordinates. RA is "
193 "expressed in Hours; Dec is expressed in Degrees."),
194 false,
"double",
"ra",
"double",
"dec"));
197 i18n(
"Point the display at the specified Alt/Az coordinates. Alt and Az are expressed in Degrees."),
false,
198 "double",
"alt",
"double",
"az"));
199 KStarsFunctionList.append(
new ScriptFunction(
"zoomIn",
i18n(
"Increase the display Zoom Level."),
false));
200 KStarsFunctionList.append(
new ScriptFunction(
"zoomOut",
i18n(
"Decrease the display Zoom Level."),
false));
201 KStarsFunctionList.append(
202 new ScriptFunction(
"defaultZoom",
i18n(
"Set the display Zoom Level to its default value."),
false));
203 KStarsFunctionList.append(
204 new ScriptFunction(
"zoom",
i18n(
"Set the display Zoom Level manually."),
false,
"double",
"z"));
205 KStarsFunctionList.append(
206 new ScriptFunction(
"setLocalTime",
i18n(
"Set the system clock to the specified Local Time."),
false,
"int",
207 "year",
"int",
"month",
"int",
"day",
"int",
"hour",
"int",
"minute",
"int",
"second"));
209 "waitFor",
i18n(
"Pause script execution for specified number of seconds."),
false,
"double",
"sec"));
211 i18n(
"Halt script execution until the specified key is pressed. Only "
212 "single-key strokes are possible; use 'space' for the spacebar."),
213 false,
"QString",
"key"));
215 "setTracking",
i18n(
"Set whether the display is tracking the current location."),
false,
"bool",
"track"));
217 "changeViewOption",
i18n(
"Change view option named %1 to value %2.",
QString(
"opName"),
QString(
"opValue")),
218 false,
"QString",
"opName",
"QString",
"opValue"));
220 "setGeoLocation",
i18n(
"Set the geographic location to the city specified by city, province and country."),
221 false,
"QString",
"cityName",
"QString",
"provinceName",
"QString",
"countryName"));
223 "setColor",
i18n(
"Set the color named %1 to the value %2.",
QString(
"colorName"),
QString(
"value")),
false,
224 "QString",
"colorName",
"QString",
"value"));
225 KStarsFunctionList.append(
new ScriptFunction(
"loadColorScheme",
i18n(
"Load the color scheme specified by name."),
226 false,
"QString",
"name"));
227 KStarsFunctionList.append(
228 new ScriptFunction(
"exportImage",
i18n(
"Export the sky image to the file, with specified width and height."),
229 false,
"QString",
"fileName",
"int",
"width",
"int",
"height"));
230 KStarsFunctionList.append(
232 i18n(
"Print the sky image to a printer or file. If %1 is true, it will show the print "
233 "dialog. If %2 is true, it will use the Star Chart color scheme for printing.",
235 false,
"bool",
"usePrintDialog",
"bool",
"useChartColors"));
236 SimClockFunctionList.append(
new ScriptFunction(
"stop",
i18n(
"Halt the simulation clock."),
true));
237 SimClockFunctionList.append(
new ScriptFunction(
"start",
i18n(
"Start the simulation clock."),
true));
239 i18n(
"Set the timescale of the simulation clock to specified scale. "
240 " 1.0 means real-time; 2.0 means twice real-time; etc."),
241 true,
"double",
"scale"));
247 for (
auto &item : KStarsFunctionList)
250 for (
auto &item : SimClockFunctionList)
256 sb->FunctionTree->setColumnCount(1);
258 sb->FunctionTree->setSortingEnabled(
false);
264 sb->SaveAsButton->setIcon(
286 argLookToward =
new ArgLookToward(sb->ArgStack);
287 argFindObject =
new ArgFindObject(sb->ArgStack);
288 argSetRaDec =
new ArgSetRaDec(sb->ArgStack);
289 argSetAltAz =
new ArgSetAltAz(sb->ArgStack);
290 argSetLocalTime =
new ArgSetLocalTime(sb->ArgStack);
291 argWaitFor =
new ArgWaitFor(sb->ArgStack);
292 argWaitForKey =
new ArgWaitForKey(sb->ArgStack);
293 argSetTracking =
new ArgSetTrack(sb->ArgStack);
294 argChangeViewOption =
new ArgChangeViewOption(sb->ArgStack);
295 argSetGeoLocation =
new ArgSetGeoLocation(sb->ArgStack);
296 argTimeScale =
new ArgTimeScale(sb->ArgStack);
297 argZoom =
new ArgZoom(sb->ArgStack);
298 argExportImage =
new ArgExportImage(sb->ArgStack);
299 argPrintImage =
new ArgPrintImage(sb->ArgStack);
300 argSetColor =
new ArgSetColor(sb->ArgStack);
301 argLoadColorScheme =
new ArgLoadColorScheme(sb->ArgStack);
303 sb->ArgStack->addWidget(argBlank);
304 sb->ArgStack->addWidget(argLookToward);
305 sb->ArgStack->addWidget(argFindObject);
306 sb->ArgStack->addWidget(argSetRaDec);
307 sb->ArgStack->addWidget(argSetAltAz);
308 sb->ArgStack->addWidget(argSetLocalTime);
309 sb->ArgStack->addWidget(argWaitFor);
310 sb->ArgStack->addWidget(argWaitForKey);
311 sb->ArgStack->addWidget(argSetTracking);
312 sb->ArgStack->addWidget(argChangeViewOption);
313 sb->ArgStack->addWidget(argSetGeoLocation);
314 sb->ArgStack->addWidget(argTimeScale);
315 sb->ArgStack->addWidget(argZoom);
316 sb->ArgStack->addWidget(argExportImage);
317 sb->ArgStack->addWidget(argPrintImage);
318 sb->ArgStack->addWidget(argSetColor);
319 sb->ArgStack->addWidget(argLoadColorScheme);
321 sb->ArgStack->setCurrentIndex(0);
326 otv->resize(sb->width(), 0.5 * sb->height());
329 otv->resizeColumns();
332 connect(sb->FunctionTree, SIGNAL(itemDoubleClicked(
QTreeWidgetItem*,
int)),
this, SLOT(slotAddFunction()));
333 connect(sb->FunctionTree, SIGNAL(itemClicked(
QTreeWidgetItem*,
int)),
this, SLOT(slotShowDoc()));
334 connect(sb->UpButton, SIGNAL(clicked()),
this, SLOT(slotMoveFunctionUp()));
335 connect(sb->ScriptListBox, SIGNAL(itemClicked(
QListWidgetItem*)),
this, SLOT(slotArgWidget()));
336 connect(sb->DownButton, SIGNAL(clicked()),
this, SLOT(slotMoveFunctionDown()));
337 connect(sb->CopyButton, SIGNAL(clicked()),
this, SLOT(slotCopyFunction()));
338 connect(sb->RemoveButton, SIGNAL(clicked()),
this, SLOT(slotRemoveFunction()));
339 connect(sb->NewButton, SIGNAL(clicked()),
this, SLOT(slotNew()));
340 connect(sb->OpenButton, SIGNAL(clicked()),
this, SLOT(slotOpen()));
341 connect(sb->SaveButton, SIGNAL(clicked()),
this, SLOT(slotSave()));
342 connect(sb->SaveAsButton, SIGNAL(clicked()),
this, SLOT(slotSaveAs()));
343 connect(sb->AddButton, SIGNAL(clicked()),
this, SLOT(slotAddFunction()));
344 connect(sb->RunButton, SIGNAL(clicked()),
this, SLOT(slotRunScript()));
347 connect(argSetGeoLocation->FindCityButton, SIGNAL(clicked()),
this, SLOT(slotFindCity()));
348 connect(argLookToward->FindButton, SIGNAL(clicked()),
this, SLOT(slotFindObject()));
349 connect(argChangeViewOption->TreeButton, SIGNAL(clicked()),
this, SLOT(slotShowOptions()));
350 connect(argFindObject->FindButton, SIGNAL(clicked()),
this, SLOT(slotFindObject()));
352 connect(argLookToward->FocusEdit, SIGNAL(editTextChanged(
QString)),
this, SLOT(slotLookToward()));
353 connect(argFindObject->NameEdit, SIGNAL(textChanged(
QString)),
this, SLOT(slotArgFindObject()));
354 connect(argSetRaDec->RABox, SIGNAL(textChanged(
QString)),
this, SLOT(slotRa()));
355 connect(argSetRaDec->DecBox, SIGNAL(textChanged(
QString)),
this, SLOT(slotDec()));
356 connect(argSetAltAz->AltBox, SIGNAL(textChanged(
QString)),
this, SLOT(slotAlt()));
357 connect(argSetAltAz->AzBox, SIGNAL(textChanged(
QString)),
this, SLOT(slotAz()));
358 connect(argSetLocalTime->DateWidget, SIGNAL(dateChanged(
QDate)),
this, SLOT(slotChangeDate()));
359 connect(argSetLocalTime->TimeBox, SIGNAL(timeChanged(
QTime)),
this, SLOT(slotChangeTime()));
360 connect(argWaitFor->DelayBox, SIGNAL(valueChanged(
int)),
this, SLOT(slotWaitFor()));
361 connect(argWaitForKey->WaitKeyEdit, SIGNAL(textChanged(
QString)),
this, SLOT(slotWaitForKey()));
362 connect(argSetTracking->CheckTrack, SIGNAL(stateChanged(
int)),
this, SLOT(slotTracking()));
363 connect(argChangeViewOption->OptionName, SIGNAL(activated(
QString)),
this, SLOT(slotViewOption()));
364 connect(argChangeViewOption->OptionValue, SIGNAL(textChanged(
QString)),
this, SLOT(slotViewOption()));
365 connect(argSetGeoLocation->CityName, SIGNAL(textChanged(
QString)),
this, SLOT(slotChangeCity()));
366 connect(argSetGeoLocation->ProvinceName, SIGNAL(textChanged(
QString)),
this, SLOT(slotChangeProvince()));
367 connect(argSetGeoLocation->CountryName, SIGNAL(textChanged(
QString)),
this, SLOT(slotChangeCountry()));
368 connect(argTimeScale->TimeScale, SIGNAL(scaleChanged(
float)),
this, SLOT(slotTimeScale()));
369 connect(argZoom->ZoomBox, SIGNAL(textChanged(
QString)),
this, SLOT(slotZoom()));
370 connect(argExportImage->ExportFileName, SIGNAL(textChanged(
QString)),
this, SLOT(slotExportImage()));
371 connect(argExportImage->ExportWidth, SIGNAL(valueChanged(
int)),
this, SLOT(slotExportImage()));
372 connect(argExportImage->ExportHeight, SIGNAL(valueChanged(
int)),
this, SLOT(slotExportImage()));
373 connect(argPrintImage->UsePrintDialog, SIGNAL(toggled(
bool)),
this, SLOT(slotPrintImage()));
374 connect(argPrintImage->UseChartColors, SIGNAL(toggled(
bool)),
this, SLOT(slotPrintImage()));
375 connect(argSetColor->ColorName, SIGNAL(activated(
QString)),
this, SLOT(slotChangeColorName()));
376 connect(argSetColor->ColorValue, SIGNAL(changed(
QColor)),
this, SLOT(slotChangeColor()));
377 connect(argLoadColorScheme->SchemeList, SIGNAL(itemClicked(
QListWidgetItem*)),
this, SLOT(slotLoadColorScheme()));
380 sb->CopyButton->setEnabled(
false);
381 sb->AddButton->setEnabled(
false);
382 sb->RemoveButton->setEnabled(
false);
383 sb->UpButton->setEnabled(
false);
384 sb->DownButton->setEnabled(
false);
385 sb->SaveButton->setEnabled(
false);
386 sb->SaveAsButton->setEnabled(
false);
387 sb->RunButton->setEnabled(
false);
390 ScriptBuilder::~ScriptBuilder()
392 while (!KStarsFunctionList.isEmpty())
393 delete KStarsFunctionList.takeFirst();
395 while (!SimClockFunctionList.isEmpty())
396 delete SimClockFunctionList.takeFirst();
398 while (!ScriptList.isEmpty())
399 delete ScriptList.takeFirst();
402 void ScriptBuilder::initViewOptions()
404 otv->optionsList()->setRootIsDecorated(
true);
409 fields <<
"ShowInfoBoxes" <<
i18n(
"Toggle display of all InfoBoxes") <<
i18n(
"bool");
412 fields <<
"ShowTimeBox" <<
i18n(
"Toggle display of Time InfoBox") <<
i18n(
"bool");
415 fields <<
"ShowGeoBox" <<
i18n(
"Toggle display of Geographic InfoBox") <<
i18n(
"bool");
418 fields <<
"ShowFocusBox" <<
i18n(
"Toggle display of Focus InfoBox") <<
i18n(
"bool");
421 fields <<
"ShadeTimeBox" <<
i18n(
"(un)Shade Time InfoBox") <<
i18n(
"bool");
424 fields <<
"ShadeGeoBox" <<
i18n(
"(un)Shade Geographic InfoBox") <<
i18n(
"bool");
427 fields <<
"ShadeFocusBox" <<
i18n(
"(un)Shade Focus InfoBox") <<
i18n(
"bool");
431 argChangeViewOption->OptionName->addItem(
"ShowInfoBoxes");
432 argChangeViewOption->OptionName->addItem(
"ShowTimeBox");
433 argChangeViewOption->OptionName->addItem(
"ShowGeoBox");
434 argChangeViewOption->OptionName->addItem(
"ShowFocusBox");
435 argChangeViewOption->OptionName->addItem(
"ShadeTimeBox");
436 argChangeViewOption->OptionName->addItem(
"ShadeGeoBox");
437 argChangeViewOption->OptionName->addItem(
"ShadeFocusBox");
441 fields <<
"ShowMainToolBar" <<
i18n(
"Toggle display of main toolbar") <<
i18n(
"bool");
444 fields <<
"ShowViewToolBar" <<
i18n(
"Toggle display of view toolbar") <<
i18n(
"bool");
448 argChangeViewOption->OptionName->addItem(
"ShowMainToolBar");
449 argChangeViewOption->OptionName->addItem(
"ShowViewToolBar");
453 fields <<
"ShowStars" <<
i18n(
"Toggle display of Stars") <<
i18n(
"bool");
456 fields <<
"ShowDeepSky" <<
i18n(
"Toggle display of all deep-sky objects") <<
i18n(
"bool");
463 fields <<
"ShowSolarSystem" <<
i18n(
"Toggle display of all solar system bodies") <<
i18n(
"bool");
466 fields <<
"ShowSun" <<
i18n(
"Toggle display of Sun") <<
i18n(
"bool");
469 fields <<
"ShowMoon" <<
i18n(
"Toggle display of Moon") <<
i18n(
"bool");
472 fields <<
"ShowMercury" <<
i18n(
"Toggle display of Mercury") <<
i18n(
"bool");
475 fields <<
"ShowVenus" <<
i18n(
"Toggle display of Venus") <<
i18n(
"bool");
478 fields <<
"ShowMars" <<
i18n(
"Toggle display of Mars") <<
i18n(
"bool");
481 fields <<
"ShowJupiter" <<
i18n(
"Toggle display of Jupiter") <<
i18n(
"bool");
484 fields <<
"ShowSaturn" <<
i18n(
"Toggle display of Saturn") <<
i18n(
"bool");
487 fields <<
"ShowUranus" <<
i18n(
"Toggle display of Uranus") <<
i18n(
"bool");
490 fields <<
"ShowNeptune" <<
i18n(
"Toggle display of Neptune") <<
i18n(
"bool");
496 fields <<
"ShowAsteroids" <<
i18n(
"Toggle display of Asteroids") <<
i18n(
"bool");
499 fields <<
"ShowComets" <<
i18n(
"Toggle display of Comets") <<
i18n(
"bool");
503 argChangeViewOption->OptionName->addItem(
"ShowStars");
504 argChangeViewOption->OptionName->addItem(
"ShowDeepSky");
505 argChangeViewOption->OptionName->addItem(
"ShowSolarSystem");
506 argChangeViewOption->OptionName->addItem(
"ShowSun");
507 argChangeViewOption->OptionName->addItem(
"ShowMoon");
508 argChangeViewOption->OptionName->addItem(
"ShowMercury");
509 argChangeViewOption->OptionName->addItem(
"ShowVenus");
510 argChangeViewOption->OptionName->addItem(
"ShowMars");
511 argChangeViewOption->OptionName->addItem(
"ShowJupiter");
512 argChangeViewOption->OptionName->addItem(
"ShowSaturn");
513 argChangeViewOption->OptionName->addItem(
"ShowUranus");
514 argChangeViewOption->OptionName->addItem(
"ShowNeptune");
516 argChangeViewOption->OptionName->addItem(
"ShowAsteroids");
517 argChangeViewOption->OptionName->addItem(
"ShowComets");
520 fields <<
"ShowCLines" <<
i18n(
"Toggle display of constellation lines") <<
i18n(
"bool");
523 fields <<
"ShowCBounds" <<
i18n(
"Toggle display of constellation boundaries") <<
i18n(
"bool");
526 fields <<
"ShowCNames" <<
i18n(
"Toggle display of constellation names") <<
i18n(
"bool");
529 fields <<
"ShowMilkyWay" <<
i18n(
"Toggle display of Milky Way") <<
i18n(
"bool");
532 fields <<
"ShowGrid" <<
i18n(
"Toggle display of the coordinate grid") <<
i18n(
"bool");
535 fields <<
"ShowEquator" <<
i18n(
"Toggle display of the celestial equator") <<
i18n(
"bool");
538 fields <<
"ShowEcliptic" <<
i18n(
"Toggle display of the ecliptic") <<
i18n(
"bool");
541 fields <<
"ShowHorizon" <<
i18n(
"Toggle display of the horizon line") <<
i18n(
"bool");
544 fields <<
"ShowGround" <<
i18n(
"Toggle display of the opaque ground") <<
i18n(
"bool");
547 fields <<
"ShowStarNames" <<
i18n(
"Toggle display of star name labels") <<
i18n(
"bool");
550 fields <<
"ShowStarMagnitudes" <<
i18n(
"Toggle display of star magnitude labels") <<
i18n(
"bool");
553 fields <<
"ShowAsteroidNames" <<
i18n(
"Toggle display of asteroid name labels") <<
i18n(
"bool");
556 fields <<
"ShowCometNames" <<
i18n(
"Toggle display of comet name labels") <<
i18n(
"bool");
559 fields <<
"ShowPlanetNames" <<
i18n(
"Toggle display of planet name labels") <<
i18n(
"bool");
562 fields <<
"ShowPlanetImages" <<
i18n(
"Toggle display of planet images") <<
i18n(
"bool");
566 argChangeViewOption->OptionName->addItem(
"ShowCLines");
567 argChangeViewOption->OptionName->addItem(
"ShowCBounds");
568 argChangeViewOption->OptionName->addItem(
"ShowCNames");
569 argChangeViewOption->OptionName->addItem(
"ShowMilkyWay");
570 argChangeViewOption->OptionName->addItem(
"ShowGrid");
571 argChangeViewOption->OptionName->addItem(
"ShowEquator");
572 argChangeViewOption->OptionName->addItem(
"ShowEcliptic");
573 argChangeViewOption->OptionName->addItem(
"ShowHorizon");
574 argChangeViewOption->OptionName->addItem(
"ShowGround");
575 argChangeViewOption->OptionName->addItem(
"ShowStarNames");
576 argChangeViewOption->OptionName->addItem(
"ShowStarMagnitudes");
577 argChangeViewOption->OptionName->addItem(
"ShowAsteroidNames");
578 argChangeViewOption->OptionName->addItem(
"ShowCometNames");
579 argChangeViewOption->OptionName->addItem(
"ShowPlanetNames");
580 argChangeViewOption->OptionName->addItem(
"ShowPlanetImages");
583 fields <<
"UseLatinConstellNames" <<
i18n(
"Show Latin constellation names") <<
i18n(
"bool");
586 fields <<
"UseLocalConstellNames" <<
i18n(
"Show constellation names in local language") <<
i18n(
"bool");
589 fields <<
"UseAbbrevConstellNames" <<
i18n(
"Show IAU-standard constellation abbreviations") <<
i18n(
"bool");
593 argChangeViewOption->OptionName->addItem(
"UseLatinConstellNames");
594 argChangeViewOption->OptionName->addItem(
"UseLocalConstellNames");
595 argChangeViewOption->OptionName->addItem(
"UseAbbrevConstellNames");
598 fields <<
"HideOnSlew" <<
i18n(
"Toggle whether objects hidden while slewing display") <<
i18n(
"bool");
601 fields <<
"SlewTimeScale" <<
i18n(
"Timestep threshold (in seconds) for hiding objects") <<
i18n(
"double");
604 fields <<
"HideStars" <<
i18n(
"Hide faint stars while slewing?") <<
i18n(
"bool");
607 fields <<
"HidePlanets" <<
i18n(
"Hide solar system bodies while slewing?") <<
i18n(
"bool");
610 fields <<
"HideMilkyWay" <<
i18n(
"Hide Milky Way while slewing?") <<
i18n(
"bool");
613 fields <<
"HideCNames" <<
i18n(
"Hide constellation names while slewing?") <<
i18n(
"bool");
616 fields <<
"HideCLines" <<
i18n(
"Hide constellation lines while slewing?") <<
i18n(
"bool");
619 fields <<
"HideCBounds" <<
i18n(
"Hide constellation boundaries while slewing?") <<
i18n(
"bool");
622 fields <<
"HideGrid" <<
i18n(
"Hide coordinate grid while slewing?") <<
i18n(
"bool");
626 argChangeViewOption->OptionName->addItem(
"HideOnSlew");
627 argChangeViewOption->OptionName->addItem(
"SlewTimeScale");
628 argChangeViewOption->OptionName->addItem(
"HideStars");
629 argChangeViewOption->OptionName->addItem(
"HidePlanets");
630 argChangeViewOption->OptionName->addItem(
"HideMilkyWay");
631 argChangeViewOption->OptionName->addItem(
"HideCNames");
632 argChangeViewOption->OptionName->addItem(
"HideCLines");
633 argChangeViewOption->OptionName->addItem(
"HideCBounds");
634 argChangeViewOption->OptionName->addItem(
"HideGrid");
637 fields <<
"UseAltAz" <<
i18n(
"Use Horizontal coordinates? (otherwise, use Equatorial)") <<
i18n(
"bool");
640 fields <<
"ZoomFactor" <<
i18n(
"Set the Zoom Factor") <<
i18n(
"double");
643 fields <<
"FOVName" <<
i18n(
"Select angular size for the FOV symbol (in arcmin)") <<
i18n(
"double");
646 fields <<
"FOVShape" <<
i18n(
"Select shape for the FOV symbol (0=Square, 1=Circle, 2=Crosshairs, 4=Bullseye)")
650 fields <<
"FOVColor" <<
i18n(
"Select color for the FOV symbol") <<
i18n(
"string");
653 fields <<
"UseAnimatedSlewing" <<
i18n(
"Use animated slewing? (otherwise, \"snap\" to new focus)") <<
i18n(
"bool");
656 fields <<
"UseRefraction" <<
i18n(
"Correct for atmospheric refraction?") <<
i18n(
"bool");
659 fields <<
"UseAutoLabel" <<
i18n(
"Automatically attach name label to centered object?") <<
i18n(
"bool");
662 fields <<
"UseHoverLabel" <<
i18n(
"Attach temporary name label when hovering mouse over an object?")
666 fields <<
"UseAutoTrail" <<
i18n(
"Automatically add trail to centered solar system body?") <<
i18n(
"bool");
669 fields <<
"FadePlanetTrails" <<
i18n(
"Planet trails fade to sky color? (otherwise color is constant)")
674 argChangeViewOption->OptionName->addItem(
"UseAltAz");
675 argChangeViewOption->OptionName->addItem(
"ZoomFactor");
676 argChangeViewOption->OptionName->addItem(
"FOVName");
677 argChangeViewOption->OptionName->addItem(
"FOVSize");
678 argChangeViewOption->OptionName->addItem(
"FOVShape");
679 argChangeViewOption->OptionName->addItem(
"FOVColor");
680 argChangeViewOption->OptionName->addItem(
"UseRefraction");
681 argChangeViewOption->OptionName->addItem(
"UseAutoLabel");
682 argChangeViewOption->OptionName->addItem(
"UseHoverLabel");
683 argChangeViewOption->OptionName->addItem(
"UseAutoTrail");
684 argChangeViewOption->OptionName->addItem(
"AnimateSlewing");
685 argChangeViewOption->OptionName->addItem(
"FadePlanetTrails");
708 fields <<
"starLabelDensity" <<
i18n(
"magnitude of faintest star labeled on map") <<
i18n(
"double");
711 fields <<
"magLimitHideStar" <<
i18n(
"magnitude of brightest star hidden while slewing") <<
i18n(
"double");
714 fields <<
"magLimitAsteroid" <<
i18n(
"magnitude of faintest asteroid drawn on map") <<
i18n(
"double");
718 fields <<
"asteroidLabelDensity" <<
i18n(
"magnitude of faintest asteroid labeled on map") <<
i18n(
"double");
721 fields <<
"maxRadCometName" <<
i18n(
"comets nearer to the Sun than this (in AU) are labeled on map")
728 argChangeViewOption->OptionName->addItem(
"magLimitDrawDeepSky");
729 argChangeViewOption->OptionName->addItem(
"magLimitDrawDeepSkyZoomOut");
730 argChangeViewOption->OptionName->addItem(
"starLabelDensity");
731 argChangeViewOption->OptionName->addItem(
"magLimitHideStar");
732 argChangeViewOption->OptionName->addItem(
"magLimitAsteroid");
733 argChangeViewOption->OptionName->addItem(
"asteroidLabelDensity");
734 argChangeViewOption->OptionName->addItem(
"maxRadCometName");
739 argSetColor->ColorName->addItem(KStarsData::Instance()->colorScheme()->nameAt(i));
743 argLoadColorScheme->SchemeList->addItem(
i18nc(
"use default color scheme",
"Default Colors"));
744 argLoadColorScheme->SchemeList->addItem(
i18nc(
"use 'star chart' color scheme",
"Star Chart"));
745 argLoadColorScheme->SchemeList->addItem(
i18nc(
"use 'night vision' color scheme",
"Night Vision"));
746 argLoadColorScheme->SchemeList->addItem(
i18nc(
"use 'moonless night' color scheme",
"Moonless Night"));
756 while (!stream.atEnd())
758 line = stream.readLine();
759 argLoadColorScheme->SchemeList->addItem(line.
left(line.
indexOf(
':')));
766 void ScriptBuilder::slotNew()
772 sb->ScriptListBox->clear();
773 sb->ArgStack->setCurrentWidget(argBlank);
775 sb->CopyButton->setEnabled(
false);
776 sb->RemoveButton->setEnabled(
false);
777 sb->RunButton->setEnabled(
false);
778 sb->SaveAsButton->setEnabled(
false);
780 currentFileURL.clear();
781 currentScriptName.clear();
785 void ScriptBuilder::slotOpen()
797 "*.kstars|" +
i18nc(
"Filter by file type: KStars Scripts.",
"KStars Scripts (*.kstars)"));
799 if (currentFileURL.isValid())
801 currentDir = currentFileURL.toLocalFile();
804 sb->ScriptListBox->clear();
805 sb->ArgStack->setCurrentWidget(argBlank);
807 if (currentFileURL.isLocalFile())
809 fname = currentFileURL.toLocalFile();
816 KSNotification::sorry(
i18n(
"Could not download remote file."),
i18n(
"Download Error"));
822 KSNotification::sorry(
i18n(
"Could not open file %1.", f.fileName()),
i18n(
"Could Not Open File"));
823 currentFileURL.clear();
832 else if (!currentFileURL.url().isEmpty())
834 KSNotification::sorry(
i18n(
"Invalid URL: %1", currentFileURL.url()),
i18n(
"Invalid URL"));
835 currentFileURL.clear();
840 void ScriptBuilder::slotSave()
846 if (currentScriptName.isEmpty())
851 currentScriptName = snd->scriptName();
852 currentAuthor = snd->authorName();
860 bool newFilename =
false;
861 if (currentFileURL.isEmpty())
865 "*.kstars|" +
i18nc(
"Filter by file type: KStars Scripts.",
"KStars Scripts (*.kstars)"));
869 if (currentFileURL.isValid())
871 currentDir = currentFileURL.toLocalFile();
873 if (currentFileURL.isLocalFile())
875 fname = currentFileURL.toLocalFile();
878 if (newFilename ==
true &&
QFile::exists(currentFileURL.toLocalFile()))
881 i18n(
"A file named \"%1\" already exists. "
883 currentFileURL.fileName()),
886 if (r == KMessageBox::Cancel)
902 KSNotification::sorry(
message,
i18n(
"Could Not Open File"));
903 currentFileURL.clear();
908 writeScript(ostream);
913 chmod(fname.
toLatin1(), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
922 QString message =
i18n(
"Could not upload image to remote location: %1", currentFileURL.url());
923 KSNotification::sorry(
message,
i18n(
"Could not upload file"));
927 setUnsavedChanges(
false);
932 KSNotification::sorry(
message,
i18n(
"Invalid URL"));
933 currentFileURL.clear();
937 void ScriptBuilder::slotSaveAs()
939 currentFileURL.clear();
940 currentScriptName.clear();
944 void ScriptBuilder::saveWarning()
949 QString message =
i18n(
"The current script has unsaved changes. Would you like to save before closing it?");
952 if (ans == KMessageBox::Yes)
955 setUnsavedChanges(
false);
957 else if (ans == KMessageBox::No)
959 setUnsavedChanges(
false);
966 void ScriptBuilder::slotRunScript()
985 KSNotification::sorry(
message,
i18n(
"Could Not Open File"));
986 currentFileURL.clear();
991 writeScript(ostream);
996 chmod(
QFile::encodeName(f.fileName()), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
1007 p.
start(f.fileName(), arguments);
1010 qDebug() << Q_FUNC_INFO <<
"Process did not start.";
1014 qApp->processEvents();
1029 void ScriptBuilder::writeScript(
QTextStream &ostream)
1032 QString dbus_call =
"dbus-send --dest=org.kde.kstars --print-reply ";
1033 QString main_method =
"/KStars org.kde.kstars.";
1034 QString clock_method =
"/KStars/SimClock org.kde.kstars.SimClock.";
1037 ostream <<
"#!/bin/bash\n";
1038 ostream <<
"#KStars DBus script: " << currentScriptName <<
'\n';
1039 ostream <<
"#by " << currentAuthor <<
'\n';
1048 if (sf->isClockFunction())
1050 ostream << dbus_call << clock_method << sf->scriptLine() <<
'\n';
1054 ostream << dbus_call << main_method << sf->scriptLine() <<
'\n';
1063 void ScriptBuilder::readScript(
QTextStream &istream)
1066 QString service_name =
"org.kde.kstars.";
1069 while (!istream.
atEnd())
1074 if (line.
contains(
"#KStars DBus script: "))
1082 if (line.
left(4) ==
"dbus")
1087 service_name +=
"SimClock.";
1104 if (parseFunction(fn_name, line))
1106 sb->ScriptListBox->addItem(ScriptList.last()->name());
1108 ScriptList.
last()->setValid(
true);
1111 qWarning() <<
i18n(
"Could not parse script. Line was: %1", line);
1117 if (sb->ScriptListBox->count())
1119 sb->ScriptListBox->setCurrentItem(
nullptr);
1124 bool ScriptBuilder::parseFunction(
const QString &fn_name,
const QString &fn_args)
1175 fn <<
match.captured(0).remove(
"\"");
1179 for (
auto &sf : KStarsFunctionList)
1181 if (fn_name == sf->name())
1195 for (
int i = 0; i < sf->numArgs(); ++i)
1196 ScriptList.last()->setArg(i, fn[i]);
1203 if (fn_name == sf->name())
1205 if (fn.
count() != sf->numArgs())
1210 for (
int i = 0; i < sf->numArgs(); ++i)
1211 ScriptList.last()->setArg(i, fn[i]);
1222 void ScriptBuilder::setUnsavedChanges(
bool b)
1224 if (checkForChanges)
1227 sb->SaveButton->setEnabled(b);
1231 void ScriptBuilder::slotCopyFunction()
1233 if (!UnsavedChanges)
1234 setUnsavedChanges(
true);
1236 int Pos = sb->ScriptListBox->currentRow() + 1;
1239 for (
int i = 0; i < ScriptList[Pos - 1]->numArgs(); ++i)
1240 ScriptList[Pos]->setArg(i, ScriptList[Pos - 1]->argVal(i));
1242 sb->ScriptListBox->insertItem(Pos, ScriptList[Pos]->
name());
1244 sb->ScriptListBox->setCurrentRow(Pos);
1248 void ScriptBuilder::slotRemoveFunction()
1250 setUnsavedChanges(
true);
1252 int Pos = sb->ScriptListBox->currentRow();
1253 ScriptList.removeAt(Pos);
1254 sb->ScriptListBox->takeItem(Pos);
1255 if (sb->ScriptListBox->count() == 0)
1257 sb->ArgStack->setCurrentWidget(argBlank);
1258 sb->CopyButton->setEnabled(
false);
1259 sb->RemoveButton->setEnabled(
false);
1260 sb->RunButton->setEnabled(
false);
1261 sb->SaveAsButton->setEnabled(
false);
1266 if (Pos == sb->ScriptListBox->count())
1270 sb->ScriptListBox->setCurrentRow(Pos);
1275 void ScriptBuilder::slotAddFunction()
1280 if (currentItem ==
nullptr || currentItem->
parent() ==
nullptr)
1283 for (
auto &sc : KStarsFunctionList)
1285 if (sc->prototype() == currentItem->
text(0))
1292 for (
auto &sc : SimClockFunctionList)
1294 if (sc->prototype() == currentItem->
text(0))
1301 if (found ==
nullptr)
1304 setUnsavedChanges(
true);
1306 int Pos = sb->ScriptListBox->currentRow() + 1;
1309 sb->ScriptListBox->insertItem(Pos, ScriptList[Pos]->
name());
1310 sb->ScriptListBox->setCurrentRow(Pos);
1314 void ScriptBuilder::slotMoveFunctionUp()
1316 if (sb->ScriptListBox->currentRow() > 0)
1318 setUnsavedChanges(
true);
1321 QString t = sb->ScriptListBox->currentItem()->text();
1322 unsigned int n = sb->ScriptListBox->currentRow();
1325 ScriptList.insert(n - 1, tmp);
1327 sb->ScriptListBox->takeItem(n);
1328 sb->ScriptListBox->insertItem(n - 1, t);
1329 sb->ScriptListBox->setCurrentRow(n - 1);
1334 void ScriptBuilder::slotMoveFunctionDown()
1336 if (sb->ScriptListBox->currentRow() > -1 && sb->ScriptListBox->currentRow() < ((
int)sb->ScriptListBox->count()) - 1)
1338 setUnsavedChanges(
true);
1340 QString t = sb->ScriptListBox->currentItem()->text();
1341 unsigned int n = sb->ScriptListBox->currentRow();
1344 ScriptList.insert(n + 1, tmp);
1346 sb->ScriptListBox->takeItem(n);
1347 sb->ScriptListBox->insertItem(n + 1, t);
1348 sb->ScriptListBox->setCurrentRow(n + 1);
1353 void ScriptBuilder::slotArgWidget()
1356 if (sb->ScriptListBox->currentRow() == -1)
1358 sb->CopyButton->setEnabled(
false);
1359 sb->RemoveButton->setEnabled(
false);
1360 sb->UpButton->setEnabled(
false);
1361 sb->DownButton->setEnabled(
false);
1363 else if (sb->ScriptListBox->count() == 1)
1365 sb->CopyButton->setEnabled(
true);
1366 sb->RemoveButton->setEnabled(
true);
1367 sb->UpButton->setEnabled(
false);
1368 sb->DownButton->setEnabled(
false);
1370 else if (sb->ScriptListBox->currentRow() == 0)
1372 sb->CopyButton->setEnabled(
true);
1373 sb->RemoveButton->setEnabled(
true);
1374 sb->UpButton->setEnabled(
false);
1375 sb->DownButton->setEnabled(
true);
1377 else if (sb->ScriptListBox->currentRow() == ((
int)sb->ScriptListBox->count()) - 1)
1379 sb->CopyButton->setEnabled(
true);
1380 sb->RemoveButton->setEnabled(
true);
1381 sb->UpButton->setEnabled(
true);
1382 sb->DownButton->setEnabled(
false);
1386 sb->CopyButton->setEnabled(
true);
1387 sb->RemoveButton->setEnabled(
true);
1388 sb->UpButton->setEnabled(
true);
1389 sb->DownButton->setEnabled(
true);
1393 if (sb->ScriptListBox->count())
1395 sb->RunButton->setEnabled(
true);
1396 sb->SaveAsButton->setEnabled(
true);
1400 sb->RunButton->setEnabled(
false);
1401 sb->SaveAsButton->setEnabled(
false);
1402 setUnsavedChanges(
false);
1406 if (sb->ScriptListBox->currentRow() > -1 && sb->ScriptListBox->currentRow() < ((
int)sb->ScriptListBox->count()))
1408 unsigned int n = sb->ScriptListBox->currentRow();
1411 checkForChanges =
false;
1413 if (sf->name() ==
"lookTowards")
1415 sb->ArgStack->setCurrentWidget(argLookToward);
1417 argLookToward->FocusEdit->setEditText(s);
1419 else if (sf->name() ==
"addLabel" || sf->name() ==
"removeLabel" || sf->name() ==
"addTrail" ||
1420 sf->name() ==
"removeTrail")
1422 sb->ArgStack->setCurrentWidget(argFindObject);
1424 argFindObject->NameEdit->setText(s);
1426 else if (sf->name() ==
"setRaDec")
1429 double r(0.0), d(0.0);
1432 sb->ArgStack->setCurrentWidget(argSetRaDec);
1438 argSetRaDec->RABox->clear();
1442 argSetRaDec->RABox->show(ra);
1449 argSetRaDec->DecBox->clear();
1451 argSetRaDec->DecBox->show(
dms(d));
1453 else if (sf->name() ==
"setAltAz")
1456 double x(0.0), y(0.0);
1458 sb->ArgStack->setCurrentWidget(argSetAltAz);
1464 argSetAltAz->AzBox->clear();
1466 argSetAltAz->AltBox->show(
dms(y));
1468 argSetAltAz->AltBox->clear();
1473 argSetAltAz->AzBox->show(
dms(x));
1475 else if (sf->name() ==
"zoomIn")
1477 sb->ArgStack->setCurrentWidget(argBlank);
1480 else if (sf->name() ==
"zoomOut")
1482 sb->ArgStack->setCurrentWidget(argBlank);
1485 else if (sf->name() ==
"defaultZoom")
1487 sb->ArgStack->setCurrentWidget(argBlank);
1490 else if (sf->name() ==
"zoom")
1492 sb->ArgStack->setCurrentWidget(argZoom);
1496 argZoom->ZoomBox->setText(sf->argVal(0));
1498 argZoom->ZoomBox->setText(
"2000.");
1500 else if (sf->name() ==
"exportImage")
1502 sb->ArgStack->setCurrentWidget(argExportImage);
1506 w = sf->argVal(1).
toInt(&ok);
1508 h = sf->argVal(2).
toInt(&ok);
1511 argExportImage->ExportWidth->setValue(w);
1512 argExportImage->ExportHeight->setValue(h);
1516 argExportImage->ExportWidth->setValue(SkyMap::Instance()->width());
1517 argExportImage->ExportHeight->setValue(SkyMap::Instance()->height());
1520 else if (sf->name() ==
"printImage")
1522 if (sf->argVal(0) ==
i18n(
"true"))
1523 argPrintImage->UsePrintDialog->setChecked(
true);
1525 argPrintImage->UsePrintDialog->setChecked(
false);
1526 if (sf->argVal(1) ==
i18n(
"true"))
1527 argPrintImage->UseChartColors->setChecked(
true);
1529 argPrintImage->UseChartColors->setChecked(
false);
1531 else if (sf->name() ==
"setLocalTime")
1533 sb->ArgStack->setCurrentWidget(argSetLocalTime);
1535 int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
1537 year = sf->argVal(0).
toInt(&ok);
1539 month = sf->argVal(1).
toInt(&ok);
1541 day = sf->argVal(2).
toInt(&ok);
1543 argSetLocalTime->DateWidget->setDate(
QDate(year, month, day));
1547 hour = sf->argVal(3).
toInt(&ok);
1551 min = sf->argVal(4).
toInt(&ok);
1553 sec = sf->argVal(5).
toInt(&ok);
1555 argSetLocalTime->TimeBox->setTime(
QTime(hour, min, sec));
1559 else if (sf->name() ==
"waitFor")
1561 sb->ArgStack->setCurrentWidget(argWaitFor);
1563 int sec = sf->argVal(0).
toInt(&ok);
1565 argWaitFor->DelayBox->setValue(sec);
1567 argWaitFor->DelayBox->setValue(0);
1569 else if (sf->name() ==
"waitForKey")
1571 sb->ArgStack->setCurrentWidget(argWaitForKey);
1572 if (sf->argVal(0).
length() == 1 || sf->argVal(0).
toLower() ==
"space")
1573 argWaitForKey->WaitKeyEdit->setText(sf->argVal(0));
1575 argWaitForKey->WaitKeyEdit->setText(
QString());
1577 else if (sf->name() ==
"setTracking")
1579 sb->ArgStack->setCurrentWidget(argSetTracking);
1580 if (sf->argVal(0) ==
i18n(
"true"))
1581 argSetTracking->CheckTrack->setChecked(
true);
1583 argSetTracking->CheckTrack->setChecked(
false);
1585 else if (sf->name() ==
"changeViewOption")
1587 sb->ArgStack->setCurrentWidget(argChangeViewOption);
1588 argChangeViewOption->OptionName->setCurrentIndex(argChangeViewOption->OptionName->findText(sf->argVal(0)));
1589 argChangeViewOption->OptionValue->setText(sf->argVal(1));
1591 else if (sf->name() ==
"setGeoLocation")
1593 sb->ArgStack->setCurrentWidget(argSetGeoLocation);
1594 argSetGeoLocation->CityName->setText(sf->argVal(0));
1595 argSetGeoLocation->ProvinceName->setText(sf->argVal(1));
1596 argSetGeoLocation->CountryName->setText(sf->argVal(2));
1598 else if (sf->name() ==
"setColor")
1600 sb->ArgStack->setCurrentWidget(argSetColor);
1602 sf->setArg(0,
"SkyColor");
1603 argSetColor->ColorName->setCurrentIndex(
1604 argSetColor->ColorName->findText(KStarsData::Instance()->colorScheme()->nameFromKey(sf->argVal(0))));
1605 argSetColor->ColorValue->setColor(
QColor(sf->argVal(1).
remove(
'\\')));
1607 else if (sf->name() ==
"loadColorScheme")
1609 sb->ArgStack->setCurrentWidget(argLoadColorScheme);
1610 argLoadColorScheme->SchemeList->setCurrentItem(
1613 else if (sf->name() ==
"stop")
1615 sb->ArgStack->setCurrentWidget(argBlank);
1618 else if (sf->name() ==
"start")
1620 sb->ArgStack->setCurrentWidget(argBlank);
1623 else if (sf->name() ==
"setClockScale")
1625 sb->ArgStack->setCurrentWidget(argTimeScale);
1627 double ts = sf->argVal(0).
toDouble(&ok);
1629 argTimeScale->TimeScale->tsbox()->changeScale(
float(ts));
1631 argTimeScale->TimeScale->tsbox()->changeScale(0.0);
1634 checkForChanges =
true;
1638 void ScriptBuilder::slotShowDoc()
1643 if (currentItem ==
nullptr || currentItem->
parent() ==
nullptr)
1646 for (
auto &sc : KStarsFunctionList)
1648 if (sc->prototype() == currentItem->
text(0))
1655 for (
auto &sc : SimClockFunctionList)
1657 if (sc->prototype() == currentItem->
text(0))
1664 if (found ==
nullptr)
1666 sb->AddButton->setEnabled(
false);
1667 qWarning() <<
i18n(
"Function index out of bounds.");
1671 sb->AddButton->setEnabled(
true);
1672 sb->FuncDoc->setHtml(found->description());
1676 void ScriptBuilder::slotFindCity()
1682 if (ld->selectedCity())
1685 argSetGeoLocation->CityName->setText(ld->selectedCityName());
1686 if (!ld->selectedProvinceName().isEmpty())
1688 argSetGeoLocation->ProvinceName->setText(ld->selectedProvinceName());
1692 argSetGeoLocation->ProvinceName->clear();
1694 argSetGeoLocation->CountryName->setText(ld->selectedCountryName());
1696 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1697 if (sf->name() ==
"setGeoLocation")
1699 setUnsavedChanges(
true);
1701 sf->setArg(0, ld->selectedCityName());
1702 sf->setArg(1, ld->selectedProvinceName());
1703 sf->setArg(2, ld->selectedCountryName());
1707 warningMismatch(
"setGeoLocation");
1714 void ScriptBuilder::slotFindObject()
1716 if (FindDialog::Instance()->exec() ==
QDialog::Accepted && FindDialog::Instance()->targetObject())
1718 setUnsavedChanges(
true);
1720 if (sender() == argLookToward->FindButton)
1721 argLookToward->FocusEdit->setEditText(FindDialog::Instance()->targetObject()->
name());
1723 argFindObject->NameEdit->setText(FindDialog::Instance()->targetObject()->
name());
1727 void ScriptBuilder::slotShowOptions()
1732 argChangeViewOption->OptionName->setCurrentIndex(
1733 argChangeViewOption->OptionName->findText(otv->optionsList()->currentItem()->text(0)));
1737 void ScriptBuilder::slotLookToward()
1739 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1741 if (sf->name() ==
"lookTowards")
1743 setUnsavedChanges(
true);
1745 sf->setArg(0, argLookToward->FocusEdit->currentText());
1750 warningMismatch(
"lookTowards");
1754 void ScriptBuilder::slotArgFindObject()
1756 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1758 if (sf->name() ==
"addLabel" || sf->name() ==
"removeLabel" || sf->name() ==
"addTrail" ||
1759 sf->name() ==
"removeTrail")
1761 setUnsavedChanges(
true);
1763 sf->setArg(0, argFindObject->NameEdit->text());
1768 warningMismatch(sf->name());
1772 void ScriptBuilder::slotRa()
1774 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1776 if (sf->name() ==
"setRaDec")
1779 if (argSetRaDec->RABox->text().isEmpty())
1783 dms ra = argSetRaDec->RABox->createDms(&ok);
1786 setUnsavedChanges(
true);
1795 sf->setValid(
false);
1800 warningMismatch(
"setRaDec");
1804 void ScriptBuilder::slotDec()
1806 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1808 if (sf->name() ==
"setRaDec")
1811 if (argSetRaDec->DecBox->text().isEmpty())
1815 dms dec = argSetRaDec->DecBox->createDms(&ok);
1818 setUnsavedChanges(
true);
1820 sf->setArg(1,
QString(
"%1").arg(
dec.Degrees()));
1827 sf->setValid(
false);
1832 warningMismatch(
"setRaDec");
1836 void ScriptBuilder::slotAz()
1838 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1840 if (sf->name() ==
"setAltAz")
1843 if (argSetAltAz->AzBox->text().isEmpty())
1847 dms az = argSetAltAz->AzBox->createDms(&ok);
1850 setUnsavedChanges(
true);
1858 sf->setValid(
false);
1863 warningMismatch(
"setAltAz");
1867 void ScriptBuilder::slotAlt()
1869 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1871 if (sf->name() ==
"setAltAz")
1874 if (argSetAltAz->AltBox->text().isEmpty())
1878 dms alt = argSetAltAz->AltBox->createDms(&ok);
1881 setUnsavedChanges(
true);
1890 sf->setValid(
false);
1895 warningMismatch(
"setAltAz");
1899 void ScriptBuilder::slotChangeDate()
1901 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1903 if (sf->name() ==
"setLocalTime")
1905 setUnsavedChanges(
true);
1907 QDate date = argSetLocalTime->DateWidget->date();
1911 sf->setArg(2,
QString(
"%1").arg(date.
day()));
1917 warningMismatch(
"setLocalTime");
1921 void ScriptBuilder::slotChangeTime()
1923 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1925 if (sf->name() ==
"setLocalTime")
1927 setUnsavedChanges(
true);
1929 QTime time = argSetLocalTime->TimeBox->time();
1939 warningMismatch(
"setLocalTime");
1943 void ScriptBuilder::slotWaitFor()
1945 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1947 if (sf->name() ==
"waitFor")
1950 int delay = argWaitFor->DelayBox->text().toInt(&ok);
1954 setUnsavedChanges(
true);
1956 sf->setArg(0,
QString(
"%1").arg(delay));
1961 sf->setValid(
false);
1966 warningMismatch(
"waitFor");
1970 void ScriptBuilder::slotWaitForKey()
1972 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
1974 if (sf->name() ==
"waitForKey")
1980 if (sKey.
length() == 1 || sKey ==
"space")
1982 setUnsavedChanges(
true);
1984 sf->setArg(0, sKey);
1989 sf->setValid(
false);
1994 warningMismatch(
"waitForKey");
1998 void ScriptBuilder::slotTracking()
2000 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2002 if (sf->name() ==
"setTracking")
2004 setUnsavedChanges(
true);
2006 sf->setArg(0, (argSetTracking->CheckTrack->isChecked() ?
i18n(
"true") :
i18n(
"false")));
2011 warningMismatch(
"setTracking");
2015 void ScriptBuilder::slotViewOption()
2017 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2019 if (sf->name() ==
"changeViewOption")
2021 if (argChangeViewOption->OptionName->currentIndex() >= 0 && argChangeViewOption->OptionValue->text().length())
2023 setUnsavedChanges(
true);
2025 sf->setArg(0, argChangeViewOption->OptionName->currentText());
2026 sf->setArg(1, argChangeViewOption->OptionValue->text());
2031 sf->setValid(
false);
2036 warningMismatch(
"changeViewOption");
2040 void ScriptBuilder::slotChangeCity()
2042 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2044 if (sf->name() ==
"setGeoLocation")
2046 QString city = argSetGeoLocation->CityName->text();
2050 setUnsavedChanges(
true);
2052 sf->setArg(0, city);
2053 if (sf->argVal(2).
length())
2059 sf->setValid(
false);
2064 warningMismatch(
"setGeoLocation");
2068 void ScriptBuilder::slotChangeProvince()
2070 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2072 if (sf->name() ==
"setGeoLocation")
2074 QString province = argSetGeoLocation->ProvinceName->text();
2078 setUnsavedChanges(
true);
2080 sf->setArg(1, province);
2092 warningMismatch(
"setGeoLocation");
2096 void ScriptBuilder::slotChangeCountry()
2098 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2100 if (sf->name() ==
"setGeoLocation")
2106 setUnsavedChanges(
true);
2108 sf->setArg(2, country);
2109 if (sf->argVal(0).
length())
2115 sf->setValid(
false);
2120 warningMismatch(
"setGeoLocation");
2124 void ScriptBuilder::slotTimeScale()
2126 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2128 if (sf->name() ==
"setClockScale")
2130 setUnsavedChanges(
true);
2132 sf->setArg(0,
QString(
"%1").arg(argTimeScale->TimeScale->tsbox()->timeScale()));
2137 warningMismatch(
"setClockScale");
2141 void ScriptBuilder::slotZoom()
2143 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2145 if (sf->name() ==
"zoom")
2147 setUnsavedChanges(
true);
2150 argZoom->ZoomBox->text().toDouble(&ok);
2153 sf->setArg(0, argZoom->ZoomBox->text());
2159 warningMismatch(
"zoom");
2163 void ScriptBuilder::slotExportImage()
2165 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2167 if (sf->name() ==
"exportImage")
2169 setUnsavedChanges(
true);
2171 sf->setArg(0, argExportImage->ExportFileName->url().url());
2172 sf->setArg(1,
QString(
"%1").arg(argExportImage->ExportWidth->value()));
2173 sf->setArg(2,
QString(
"%1").arg(argExportImage->ExportHeight->value()));
2178 warningMismatch(
"exportImage");
2182 void ScriptBuilder::slotPrintImage()
2184 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2186 if (sf->name() ==
"printImage")
2188 setUnsavedChanges(
true);
2190 sf->setArg(0, (argPrintImage->UsePrintDialog->isChecked() ?
i18n(
"true") :
i18n(
"false")));
2191 sf->setArg(1, (argPrintImage->UseChartColors->isChecked() ?
i18n(
"true") :
i18n(
"false")));
2196 warningMismatch(
"exportImage");
2200 void ScriptBuilder::slotChangeColorName()
2202 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2204 if (sf->name() ==
"setColor")
2206 setUnsavedChanges(
true);
2208 argSetColor->ColorValue->setColor(KStarsData::Instance()->colorScheme()->colorAt(argSetColor->ColorName->currentIndex()));
2209 sf->setArg(0, KStarsData::Instance()->colorScheme()->keyAt(argSetColor->ColorName->currentIndex()));
2210 QString cname(argSetColor->ColorValue->color().name());
2212 sf->setArg(1, cname);
2217 warningMismatch(
"setColor");
2221 void ScriptBuilder::slotChangeColor()
2223 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2225 if (sf->name() ==
"setColor")
2227 setUnsavedChanges(
true);
2229 sf->setArg(0, KStarsData::Instance()->colorScheme()->keyAt(argSetColor->ColorName->currentIndex()));
2230 QString cname(argSetColor->ColorValue->color().name());
2232 sf->setArg(1, cname);
2237 warningMismatch(
"setColor");
2241 void ScriptBuilder::slotLoadColorScheme()
2243 ScriptFunction *sf = ScriptList[sb->ScriptListBox->currentRow()];
2245 if (sf->name() ==
"loadColorScheme")
2247 setUnsavedChanges(
true);
2249 sf->setArg(0,
'\"' + argLoadColorScheme->SchemeList->currentItem()->text() +
'\"');
2254 warningMismatch(
"loadColorScheme");
2258 void ScriptBuilder::slotClose()
2262 if (!UnsavedChanges)
2265 sb->ScriptListBox->clear();
2266 sb->ArgStack->setCurrentWidget(argBlank);
2274 void ScriptBuilder::slotINDIStartDeviceName()
2276 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2278 if ( sf->name() ==
"startINDI" )
2280 setUnsavedChanges(
true );
2282 sf->setArg(0, argStartINDI->deviceName->text());
2283 sf->setArg(1, argStartINDI->LocalButton->isChecked() ?
"true" :
"false");
2288 warningMismatch(
"startINDI" );
2293 void ScriptBuilder::slotINDIStartDeviceMode()
2296 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2298 if ( sf->name() ==
"startINDI" )
2300 setUnsavedChanges(
true );
2302 sf->setArg(1, argStartINDI->LocalButton->isChecked() ?
"true" :
"false");
2307 warningMismatch(
"startINDI" );
2312 void ScriptBuilder::slotINDISetDevice()
2315 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2317 if ( sf->name() ==
"setINDIDevice" )
2319 setUnsavedChanges(
true );
2321 sf->setArg(0, argSetDeviceINDI->deviceName->text());
2326 warningMismatch(
"startINDI" );
2330 void ScriptBuilder::slotINDIShutdown()
2333 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2335 if ( sf->name() ==
"shutdownINDI" )
2337 if (argShutdownINDI->deviceName->text().isEmpty())
2339 sf->setValid(
false);
2343 if (sf->argVal(0) != argShutdownINDI->deviceName->text())
2344 setUnsavedChanges(
true );
2346 sf->setArg(0, argShutdownINDI->deviceName->text());
2351 warningMismatch(
"shutdownINDI" );
2356 void ScriptBuilder::slotINDISwitchDeviceConnection()
2359 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2361 if ( sf->name() ==
"switchINDI" )
2364 if (sf->argVal(0) != (argSwitchINDI->OnButton->isChecked() ?
"true" :
"false"))
2365 setUnsavedChanges(
true );
2367 sf->setArg(0, argSwitchINDI->OnButton->isChecked() ?
"true" :
"false");
2372 warningMismatch(
"switchINDI" );
2377 void ScriptBuilder::slotINDISetPortDevicePort()
2379 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2381 if ( sf->name() ==
"setINDIPort" )
2384 if (argSetPortINDI->devicePort->text().isEmpty())
2386 sf->setValid(
false);
2390 if (sf->argVal(0) != argSetPortINDI->devicePort->text())
2391 setUnsavedChanges(
true );
2393 sf->setArg(0, argSetPortINDI->devicePort->text());
2398 warningMismatch(
"setINDIPort" );
2403 void ScriptBuilder::slotINDISetTargetCoordDeviceRA()
2405 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2407 if ( sf->name() ==
"setINDITargetCoord" )
2410 if ( argSetTargetCoordINDI->RABox->text().isEmpty() )
2412 sf->setValid(
false);
2417 dms ra = argSetTargetCoordINDI->RABox->createDms(&ok);
2421 if (sf->argVal(0) !=
QString(
"%1" ).arg( ra.
Hours() ))
2422 setUnsavedChanges(
true );
2425 if ( ( ! sf->argVal(1).
isEmpty() ))
2426 sf->setValid(
true );
2428 sf->setValid(
false);
2434 sf->setValid(
false );
2439 warningMismatch(
"setINDITargetCoord" );
2444 void ScriptBuilder::slotINDISetTargetCoordDeviceDEC()
2446 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2448 if ( sf->name() ==
"setINDITargetCoord" )
2451 if ( argSetTargetCoordINDI->DecBox->text().isEmpty() )
2453 sf->setValid(
false);
2458 dms dec = argSetTargetCoordINDI->DecBox->createDms(&ok);
2462 if (sf->argVal(1) !=
QString(
"%1" ).arg(
dec.Degrees() ))
2463 setUnsavedChanges(
true );
2465 sf->setArg( 1,
QString(
"%1" ).arg(
dec.Degrees() ) );
2466 if ( ( ! sf->argVal(0).
isEmpty() ))
2467 sf->setValid(
true );
2469 sf->setValid(
false);
2475 sf->setValid(
false );
2480 warningMismatch(
"setINDITargetCoord" );
2485 void ScriptBuilder::slotINDIsetCoreProperty(SequenceJob::SJ_TargetName,TargetName()
2488 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2490 if ( sf->name() ==
"setINDITargetName" )
2492 if (argsetCoreProperty(SequenceJob::SJ_TargetName,INDI->targetName->text().isEmpty())
2494 sf->setValid(false);
2498 if (sf->argVal(0) != argsetCoreProperty(SequenceJob::SJ_TargetName,INDI->targetName->text())
2499 setUnsavedChanges(
true );
2501 sf->setArg(0, argsetCoreProperty(SequenceJob::SJ_TargetName,INDI->targetName->text());
2506 warningMismatch(
"setINDITargetName" );
2511 void ScriptBuilder::slotINDISetActionName()
2513 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2515 if ( sf->name() ==
"setINDIAction" )
2517 if (argSetActionINDI->actionName->text().isEmpty())
2519 sf->setValid(
false);
2523 if (sf->argVal(0) != argSetActionINDI->actionName->text())
2524 setUnsavedChanges(
true );
2526 sf->setArg(0, argSetActionINDI->actionName->text());
2531 warningMismatch(
"setINDIAction" );
2536 void ScriptBuilder::slotINDIWaitForActionName()
2538 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2540 if ( sf->name() ==
"waitForINDIAction" )
2542 if (argWaitForActionINDI->actionName->text().isEmpty())
2544 sf->setValid(
false);
2548 if (sf->argVal(0) != argWaitForActionINDI->actionName->text())
2549 setUnsavedChanges(
true );
2551 sf->setArg(0, argWaitForActionINDI->actionName->text());
2556 warningMismatch(
"waitForINDIAction" );
2561 void ScriptBuilder::slotINDISetFocusSpeed()
2563 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2565 if ( sf->name() ==
"setINDIFocusSpeed" )
2568 if (sf->argVal(0).
toInt() != argSetFocusSpeedINDI->speedIN->value())
2569 setUnsavedChanges(
true );
2571 sf->setArg(0,
QString(
"%1").arg(argSetFocusSpeedINDI->speedIN->value()));
2576 warningMismatch(
"setINDIFocusSpeed" );
2581 void ScriptBuilder::slotINDIStartFocusDirection()
2583 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2585 if ( sf->name() ==
"startINDIFocus" )
2587 if (sf->argVal(0) != argStartFocusINDI->directionCombo->currentText())
2588 setUnsavedChanges(
true );
2590 sf->setArg(0, argStartFocusINDI->directionCombo->currentText());
2595 warningMismatch(
"startINDIFocus" );
2600 void ScriptBuilder::slotINDISetFocusTimeout()
2602 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2604 if ( sf->name() ==
"setINDIFocusTimeout" )
2606 if (sf->argVal(0).
toInt() != argSetFocusTimeoutINDI->timeOut->value())
2607 setUnsavedChanges(
true );
2609 sf->setArg(0,
QString(
"%1").arg(argSetFocusTimeoutINDI->timeOut->value()));
2614 warningMismatch(
"setINDIFocusTimeout" );
2619 void ScriptBuilder::slotINDISetGeoLocationDeviceLong()
2621 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2623 if ( sf->name() ==
"setINDIGeoLocation" )
2626 if ( argSetGeoLocationINDI->longBox->text().isEmpty())
2628 sf->setValid(
false);
2633 dms longitude = argSetGeoLocationINDI->longBox->createDms(&ok);
2638 setUnsavedChanges(
true );
2641 if ( ! sf->argVal(1).
isEmpty() )
2642 sf->setValid(
true );
2644 sf->setValid(
false);
2650 sf->setValid(
false );
2655 warningMismatch(
"setINDIGeoLocation" );
2660 void ScriptBuilder::slotINDISetGeoLocationDeviceLat()
2662 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2664 if ( sf->name() ==
"setINDIGeoLocation" )
2667 if ( argSetGeoLocationINDI->latBox->text().isEmpty() )
2669 sf->setValid(
false);
2674 dms latitude = argSetGeoLocationINDI->latBox->createDms(&ok);
2679 setUnsavedChanges(
true );
2682 if ( ! sf->argVal(0).
isEmpty() )
2683 sf->setValid(
true );
2685 sf->setValid(
false);
2691 sf->setValid(
false );
2696 warningMismatch(
"setINDIGeoLocation" );
2701 void ScriptBuilder::slotINDIStartExposureTimeout()
2703 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2705 if ( sf->name() ==
"startINDIExposure" )
2708 if (sf->argVal(0).
toInt() != argStartExposureINDI->timeOut->value())
2709 setUnsavedChanges(
true );
2711 sf->setArg(0,
QString(
"%1").arg(argStartExposureINDI->timeOut->value()));
2716 warningMismatch(
"startINDIExposure" );
2721 void ScriptBuilder::slotINDISetUTC()
2723 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2725 if ( sf->name() ==
"setINDIUTC" )
2728 if (argSetUTCINDI->UTC->text().isEmpty())
2730 sf->setValid(
false);
2734 if (sf->argVal(0) != argSetUTCINDI->UTC->text())
2735 setUnsavedChanges(
true );
2737 sf->setArg(0, argSetUTCINDI->UTC->text());
2742 warningMismatch(
"setINDIUTC" );
2747 void ScriptBuilder::slotINDISetScopeAction()
2749 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2751 if ( sf->name() ==
"setINDIScopeAction" )
2754 if (sf->argVal(0) != argSetScopeActionINDI->actionCombo->currentText())
2755 setUnsavedChanges(
true );
2757 sf->setArg(0, argSetScopeActionINDI->actionCombo->currentText());
2758 sf->setINDIProperty(
"CHECK");
2763 warningMismatch(
"setINDIScopeAction" );
2768 void ScriptBuilder::slotINDISetFrameType()
2770 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2772 if ( sf->name() ==
"setINDIFrameType" )
2775 if (sf->argVal(0) != argSetFrameTypeINDI->typeCombo->currentText())
2776 setUnsavedChanges(
true );
2778 sf->setArg(0, argSetFrameTypeINDI->typeCombo->currentText());
2783 warningMismatch(
"setINDIFrameType" );
2788 void ScriptBuilder::slotINDISetCCDTemp()
2790 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2792 if ( sf->name() ==
"setINDICCDTemp" )
2795 if (sf->argVal(0).
toInt() != argSetCCDTempINDI->temp->value())
2796 setUnsavedChanges(
true );
2798 sf->setArg(0,
QString(
"%1").arg(argSetCCDTempINDI->temp->value()));
2803 warningMismatch(
"setINDICCDTemp" );
2808 void ScriptBuilder::slotINDISetFilterNum()
2811 ScriptFunction * sf = ScriptList[ sb->ScriptListBox->currentRow() ];
2813 if ( sf->name() ==
"setINDIFilterNum" )
2816 if (sf->argVal(0).
toInt() != argSetFilterNumINDI->filter_num->value())
2817 setUnsavedChanges(
true );
2819 sf->setArg(0,
QString(
"%1").arg(argSetFilterNumINDI->filter_num->value()));
2824 warningMismatch(
"setINDIFilterNum" );
2831 void ScriptBuilder::warningMismatch(
const QString &expected)
const
2833 qWarning() <<
i18n(
"Mismatch between function and Arg widget (expected %1.)",
QString(expected));