1 /*
2 * Stellarium
3 * This file Copyright (C) 2008 Matthew Gates
4 * Horizon system labels (c) 2015 Georg Zotti
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19 */
20
21 #include "LabelMgr.hpp"
22 #include "StelObjectMgr.hpp"
23 #include "StelApp.hpp"
24 #include "StarMgr.hpp"
25 #include "StelCore.hpp"
26 #include "StelLocaleMgr.hpp"
27 #include "StelModuleMgr.hpp"
28
29 #include "StelProjector.hpp"
30 #include "StelModule.hpp"
31 #include "StelObject.hpp"
32 #include "StelObjectType.hpp"
33 #include "StelUtils.hpp"
34 #include "VecMath.hpp"
35 #include "StelPainter.hpp"
36
37 #include <QString>
38 #include <QDebug>
39 #include <QTimer>
40
41 // Base class from which other label types inherit
42 class StelLabel
43 {
44 public:
45 StelLabel(const QString& text, const QFont& font, const Vec3f& color);
~StelLabel()46 virtual ~StelLabel() {;}
47
48 //! draw the label on the sky
49 //! @param core the StelCore object
50 virtual bool draw(StelCore* core, StelPainter& sPainter) = 0;
51 //! update fade for on/off action
52 virtual void update(double deltaTime);
53 //! Set the duration used for the fade in / fade out of the label.
54 void setFadeDuration(float duration);
55 //! Set the font color used for the font
56 void setFontColor(const Vec3f& color);
57 //! Show or hide the label. It will fade in/out.
58 void setFlagShow(bool b);
59 //! Get value of flag used to turn on and off the label
60 bool getFlagShow(void) const;
61 //! Get value of flag used to turn on and off the label
62 void setText(const QString& newText);
63
64 QString labelText;
65 QFont labelFont;
66 Vec3f labelColor;
67 LinearFader labelFader;
68 bool autoDelete;
69 int id;
70 QTimer* timer;
71 };
72
73 //! @class SkyLabel
74 //! Used to create user labels which are bound to some object on the celestial sphere.
75 //! The object in question can be any existing StelObject or celestial coordinates.
76 class SkyLabel : public StelLabel
77 {
78 public:
79 //! @enum Style determined the way the object to which the label is bound
80 //! is indicated.
81 enum Style {
82 TextOnly, //!< Just put the label near the object
83 Line //!< Draw a line from the label text to the object
84 };
85
86 //! Constructor of a SkyLabel which is attached to an existing object
87 //! @param text the text which will be displayed
88 //! @param bindObject a pointer to an existing object to which the label will be attached
89 //! @param font a pointer to the font to use for this label
90 //! @param color choose a color for the label
91 //! @param side which side of the object to draw the label, values N, S, E, W, NE, NW, SE, SW, C (C is centred on the object)
92 //! @param distance the distance from the object to draw the label. If < 0.0, placement is automatic.
93 //! @param style determines how the label is drawn
94 SkyLabel(const QString& text, StelObjectP bindObject, const QFont& font, Vec3f color,
95 QString side="NE", double distance=-1.0, SkyLabel::Style style=TextOnly);
96
97 virtual ~SkyLabel();
98 // SkyLabel(const QString& text, Vec3d coords, QString side="NE", double distance=-1.0, SkyLabel::Style style=TextOnly, double enclosureSize=-1.0);
99
100 //! Draw the label on the sky
101 //! @param core the StelCore object
102 //! @param sPainter the StelPainter to use for drawing operations
103 virtual bool draw(StelCore* core, StelPainter& sPainter);
104
105 static SkyLabel::Style stringToStyle(const QString& s);
106
107 private:
108 StelObjectP labelObject;
109 QString labelSide;
110 double labelDistance;
111 SkyLabel::Style labelStyle;
112 };
113
114 //! @class HorizonLabel
115 //! Used to create user labels which are bound to azimuthal coordinates.
116 class HorizonLabel : public StelLabel
117 {
118 public:
119 //! Constructor of a HorizonLabel which is to be displayed on an alt-azimuthal position.
120 //! @param text the text for the label
121 //! @param az the azimuth, degrees
122 //! @param alt the altitude, degrees
123 //! @param font the font to use
124 //! @param color the color for the label
125 HorizonLabel(const QString& text, const float az, const float alt, const QFont& font, const Vec3f& color);
126 virtual ~HorizonLabel();
127
128 //! draw the label on the screen
129 //! @param core the StelCore object
130 //! @param sPainter the StelPainter to use for drawing operations
131 virtual bool draw(StelCore* core, StelPainter& sPainter);
132 private:
133 Vec3d altaz; // the vector to the coordinates
134 };
135
136 //! @class EquatorialLabel
137 //! Used to create user labels which are bound to equatorial coordinates.
138 class EquatorialLabel : public StelLabel
139 {
140 public:
141 //! Constructor of a EquatorialJ2000Label which is to be displayed on an equatorial position.
142 //! @param text the text for the label
143 //! @param ra the R.A., hours
144 //! @param dec the declination, degrees
145 //! @param font the font to use
146 //! @param color the color for the label
147 //! @param j2000epoch if true, the label starts displayed in equatorial coordinates for epoch J2000.0
148 EquatorialLabel(const QString& text, const float ra, const float dec, const QFont& font, const Vec3f& color, QString side="NE", double distance=-1.0, bool j2000epoch=true);
149 virtual ~EquatorialLabel();
150
151 //! draw the label on the screen
152 //! @param core the StelCore object
153 //! @param sPainter the StelPainter to use for drawing operations
154 virtual bool draw(StelCore* core, StelPainter& sPainter);
155 private:
156 Vec3d equPos; // the vector to the coordinates
157 QString labelSide;
158 double labelDistance;
159 };
160
161
162 //! @class ScreenLabel
163 //! Used to create user labels which are bound to a fixed point on the screen.
164 class ScreenLabel : public StelLabel
165 {
166 public:
167 //! Constructor of a ScreenLabel which is to be displayed at a fixed position on the screen.
168 //! @param text the text for the label
169 //! @param x the x-position on the screen (pixels from the left side)
170 //! @param y the y-position on the screen (pixels from the top side)
171 //! @param font the font to use
172 //! @param color the color for the label
173 ScreenLabel(const QString& text, int x, int y, const QFont& font, const Vec3f& color);
174 virtual ~ScreenLabel();
175
176 //! draw the label on the screen
177 //! @param core the StelCore object
178 //! @param sPainter the StelPainter to use for drawing operations
179 virtual bool draw(StelCore* core, StelPainter& sPainter);
180
181 private:
182 int screenX;
183 int screenY;
184 };
185
186 /////////////////////
187 // StelLabel class //
188 /////////////////////
StelLabel(const QString & text,const QFont & font,const Vec3f & color)189 StelLabel::StelLabel(const QString& text, const QFont& font, const Vec3f& color)
190 : labelText(text),
191 labelFont(font),
192 labelColor(color),
193 autoDelete(false),
194 id(0),
195 timer(Q_NULLPTR)
196 {
197 }
198
update(double deltaTime)199 void StelLabel::update(double deltaTime)
200 {
201 labelFader.update(static_cast<int>(deltaTime*1000));
202 }
203
setFadeDuration(float duration)204 void StelLabel::setFadeDuration(float duration)
205 {
206 labelFader.setDuration(static_cast<int>(1000.f*duration));
207 }
208
setFontColor(const Vec3f & color)209 void StelLabel::setFontColor(const Vec3f& color)
210 {
211 labelColor = color;
212 }
213
setFlagShow(bool b)214 void StelLabel::setFlagShow(bool b)
215 {
216 labelFader = b;
217 }
218
getFlagShow(void) const219 bool StelLabel::getFlagShow(void) const
220 {
221 return labelFader;
222 }
223
setText(const QString & newText)224 void StelLabel::setText(const QString& newText)
225 {
226 labelText = newText;
227 }
228
stringToStyle(const QString & s)229 SkyLabel::Style SkyLabel::stringToStyle(const QString& s)
230 {
231 if (s=="Line")
232 return SkyLabel::Line;
233 else
234 return SkyLabel::TextOnly;
235 }
236
237 ////////////////////
238 // SkyLabel class //
239 ////////////////////
SkyLabel(const QString & text,StelObjectP bindObject,const QFont & font,Vec3f color,QString side,double distance,SkyLabel::Style style)240 SkyLabel::SkyLabel(const QString& text, StelObjectP bindObject, const QFont& font,
241 Vec3f color, QString side, double distance, SkyLabel::Style style)
242 : StelLabel(text, font, color),
243 labelObject(bindObject),
244 labelSide(side),
245 labelDistance(distance),
246 labelStyle(style)
247 {
248 }
249
~SkyLabel()250 SkyLabel::~SkyLabel()
251 {
252 }
253
draw(StelCore * core,StelPainter & sPainter)254 bool SkyLabel::draw(StelCore* core, StelPainter& sPainter)
255 {
256 if(labelFader.getInterstate() <= 0.f)
257 return false;
258
259 Vec3d objectPos = labelObject->getJ2000EquatorialPos(core);
260 Vec3d labelXY;
261 // Compute 2D pos and return if outside screen
262 if (!sPainter.getProjector()->project(objectPos,labelXY))
263 return false;
264
265 sPainter.setFont(labelFont);
266
267 double xOffset(0.);
268 double yOffset(0.);
269 char hJustify = 'c';
270 char vJustify = 'c';
271
272 if (labelSide.toUpper().contains("N"))
273 {
274 yOffset = 1.0;
275 vJustify = 'b'; // bottom justify text
276 }
277 else if (labelSide.toUpper().contains("S"))
278 {
279 yOffset = -1.0;
280 vJustify = 't'; // top justufy text
281 }
282
283 if (labelSide.toUpper().contains("E"))
284 {
285 xOffset = 1.0;
286 hJustify = 'l'; // right justify text
287 }
288 else if (labelSide.toUpper().contains("W"))
289 {
290 xOffset = -1.0;
291 hJustify = 'r'; // left justify text
292 }
293
294 if (labelDistance >= 0.0)
295 {
296 xOffset *= labelDistance;
297 yOffset *= labelDistance;
298 }
299 else
300 {
301 float shift = 4.f + static_cast<float>(labelObject->getAngularSize(core))*M_PI_180f*sPainter.getProjector()->getPixelPerRadAtCenter()/1.8f;
302 // use the object size
303 xOffset *= static_cast<double>(shift);
304 yOffset *= static_cast<double>(shift);
305 }
306
307 double jxOffset(0.);
308 double jyOffset(0.);
309 if (hJustify == 'r')
310 jxOffset = sPainter.getFontMetrics().boundingRect(labelText).width();
311 else if (hJustify == 'c')
312 jxOffset = sPainter.getFontMetrics().boundingRect(labelText).width() / 2.;
313
314 if (vJustify == 't')
315 jyOffset = sPainter.getFontMetrics().height();
316 else if (vJustify == 'c')
317 jyOffset = sPainter.getFontMetrics().height() / 2.;
318
319 sPainter.setColor(labelColor, labelFader.getInterstate());
320 sPainter.drawText(static_cast<float>(labelXY[0]+xOffset-jxOffset), static_cast<float>(labelXY[1]+yOffset-jyOffset), labelText, 0, 0, 0, false);
321
322 if (labelStyle == SkyLabel::Line)
323 {
324 sPainter.setBlending(true);
325
326 // screen coordinates of object
327 Vec3d objXY;
328 sPainter.getProjector()->project(objectPos,objXY);
329
330 float lineEndX = static_cast<float>(labelXY[0]+xOffset);
331 float lineEndY = static_cast<float>(labelXY[1]+yOffset);
332
333 if (vJustify == 'b')
334 lineEndY -= 5;
335 else if (vJustify == 't')
336 lineEndY += 5;
337
338 if (hJustify == 'l')
339 lineEndX -= 5;
340 else if (hJustify == 'r')
341 lineEndX += 5;
342
343 sPainter.setColor(labelColor, labelFader.getInterstate());
344
345 sPainter.drawLine2d(lineEndX,lineEndY,static_cast<float>(objXY[0]), static_cast<float>(objXY[1]));
346 }
347
348 return true;
349 }
350
351 ///////////////////////
352 // HorizonLabel class //
353 ///////////////////////
HorizonLabel(const QString & text,const float az,const float alt,const QFont & font,const Vec3f & color)354 HorizonLabel::HorizonLabel(const QString& text, const float az, const float alt, const QFont& font, const Vec3f& color)
355 : StelLabel(text, font, color)
356 {
357 StelUtils::spheToRect((180.0f-az)*M_PI_180f, alt*M_PI_180f, altaz);
358 }
359
~HorizonLabel()360 HorizonLabel::~HorizonLabel()
361 {
362 }
363
draw(StelCore * core,StelPainter & sPainter)364 bool HorizonLabel::draw(StelCore *core, StelPainter& sPainter)
365 {
366 if (labelFader.getInterstate() <= 0.f)
367 return false;
368
369 sPainter.setColor(labelColor, labelFader.getInterstate());
370 sPainter.setFont(labelFont);
371 StelProjectorP keepProj=sPainter.getProjector(); // we must reset after painting!
372 StelProjectorP altazProjector=core->getProjection(StelCore::FrameAltAz, StelCore::RefractionOff);
373 sPainter.setProjector(altazProjector);
374 sPainter.drawText(altaz, labelText, 0, 0, 0, false);
375 sPainter.setProjector(keepProj);
376 return true;
377 }
378
379 ///////////////////////
380 // EquatorialLabel class //
381 ///////////////////////
EquatorialLabel(const QString & text,const float ra,const float dec,const QFont & font,const Vec3f & color,QString side,double distance,bool j2000epoch)382 EquatorialLabel::EquatorialLabel(const QString& text, const float ra, const float dec, const QFont& font, const Vec3f& color, QString side, double distance, bool j2000epoch)
383 : StelLabel(text, font, color),
384 labelSide(side),
385 labelDistance(distance)
386 {
387 StelUtils::spheToRect(ra, dec, equPos);
388 if (!j2000epoch)
389 equPos = StelApp::getInstance().getCore()->equinoxEquToJ2000(equPos);
390 }
391
~EquatorialLabel()392 EquatorialLabel::~EquatorialLabel()
393 {
394 }
395
draw(StelCore * core,StelPainter & sPainter)396 bool EquatorialLabel::draw(StelCore *core, StelPainter& sPainter)
397 {
398 if (labelFader.getInterstate() <= 0.f)
399 return false;
400
401 Vec3d labelXY;
402 // Compute 2D pos and return if outside screen
403 if (!sPainter.getProjector()->project(equPos, labelXY))
404 return false;
405
406 sPainter.setColor(labelColor, labelFader.getInterstate());
407 sPainter.setFont(labelFont);
408
409 double xOffset(0.);
410 double yOffset(0.);
411 char hJustify = 'c';
412 char vJustify = 'c';
413 if (labelSide.toUpper().contains("N"))
414 {
415 yOffset = 1.0;
416 vJustify = 'b'; // bottom justify text
417 }
418 else if (labelSide.toUpper().contains("S"))
419 {
420 yOffset = -1.0;
421 vJustify = 't'; // top justufy text
422 }
423
424 if (labelSide.toUpper().contains("E"))
425 {
426 xOffset = 1.0;
427 hJustify = 'l'; // right justify text
428 }
429 else if (labelSide.toUpper().contains("W"))
430 {
431 xOffset = -1.0;
432 hJustify = 'r'; // left justify text
433 }
434
435 if (labelDistance >= 0.0)
436 {
437 xOffset *= labelDistance;
438 yOffset *= labelDistance;
439 }
440
441 double jxOffset(0.);
442 double jyOffset(0.);
443 if (hJustify == 'r')
444 jxOffset = sPainter.getFontMetrics().boundingRect(labelText).width();
445 else if (hJustify == 'c')
446 jxOffset = sPainter.getFontMetrics().boundingRect(labelText).width() / 2.;
447
448 if (vJustify == 't')
449 jyOffset = sPainter.getFontMetrics().height();
450 else if (vJustify == 'c')
451 jyOffset = sPainter.getFontMetrics().height() / 2.;
452
453 StelProjectorP keepProj=sPainter.getProjector(); // we must reset after painting!
454 StelProjectorP altazProjector=core->getProjection(StelCore::FrameJ2000, StelCore::RefractionAuto);
455 sPainter.setProjector(altazProjector);
456 sPainter.drawText(static_cast<float>(labelXY[0]+xOffset-jxOffset), static_cast<float>(labelXY[1]+yOffset-jyOffset), labelText, 0, 0, 0, false);
457 sPainter.setProjector(keepProj);
458 return true;
459 }
460
461 ///////////////////////
462 // ScreenLabel class //
463 ///////////////////////
ScreenLabel(const QString & text,int x,int y,const QFont & font,const Vec3f & color)464 ScreenLabel::ScreenLabel(const QString& text, int x, int y, const QFont& font, const Vec3f& color)
465 : StelLabel(text, font, color)
466 {
467 QFontMetrics metrics(font);
468 StelCore* core = StelApp::getInstance().getCore();
469 const double ppx = core->getCurrentStelProjectorParams().devicePixelsPerPixel;
470 screenX = x*ppx;
471 screenY = core->getProjection2d()->getViewportHeight() - (y*ppx + metrics.height());
472 }
473
~ScreenLabel()474 ScreenLabel::~ScreenLabel()
475 {
476 }
477
draw(StelCore *,StelPainter & sPainter)478 bool ScreenLabel::draw(StelCore*, StelPainter& sPainter)
479 {
480 if (labelFader.getInterstate() <= 0.f)
481 return false;
482
483 sPainter.setColor(labelColor, labelFader.getInterstate());
484 sPainter.setFont(labelFont);
485 sPainter.drawText(screenX, screenY, labelText, 0, 0, 0, false);
486 return true;
487 }
488
489 ///////////////////////
490 // LabelMgr class //
491 ///////////////////////
LabelMgr()492 LabelMgr::LabelMgr() : counter(0)
493 {
494 setObjectName("LabelMgr");
495 }
496
~LabelMgr()497 LabelMgr::~LabelMgr()
498 {
499 }
500
init()501 void LabelMgr::init()
502 {
503 }
504
draw(StelCore * core)505 void LabelMgr::draw(StelCore* core)
506 {
507 StelPainter sPainter(core->getProjection(StelCore::FrameJ2000));
508 for (auto* l : qAsConst(allLabels))
509 {
510 l->draw(core, sPainter);
511 }
512 }
513
messageTimeout2()514 void LabelMgr::messageTimeout2()
515 {
516 QObject* obj = QObject::sender();
517 for (auto* l : qAsConst(allLabels))
518 {
519 if (l->timer == obj)
520 {
521 deleteLabel(l->id);
522 return;
523 }
524 }
525 }
526
messageTimeout1()527 void LabelMgr::messageTimeout1()
528 {
529 QObject* obj = QObject::sender();
530 for (auto* l : qAsConst(allLabels))
531 {
532 if (l->timer == obj)
533 {
534 disconnect(l->timer, SIGNAL(timeout()), this, SLOT(messageTimeout1()));
535 connect(l->timer, SIGNAL(timeout()), this, SLOT(messageTimeout2()));
536 l->setFlagShow(false);
537 l->timer->setInterval(l->labelFader.getDuration()*1000);
538 l->timer->start();
539 return;
540 }
541 }
542 }
543
appendLabel(StelLabel * l,int autoDeleteTimeoutMs)544 int LabelMgr::appendLabel(StelLabel* l, int autoDeleteTimeoutMs)
545 {
546 if (autoDeleteTimeoutMs > 0)
547 {
548 QTimer* timer = new QTimer(this);
549 l->timer = timer;
550 timer->setSingleShot(true);
551 timer->setInterval(autoDeleteTimeoutMs);
552 connect(timer, SIGNAL(timeout()), this, SLOT(messageTimeout1()));
553 timer->start();
554 }
555
556 counter++;
557 l->id = counter;
558 allLabels[counter] = l;
559 return counter;
560 }
561
labelObject(const QString & text,const QString & objectName,bool visible,float fontSize,const QString & fontColor,const QString & side,double labelDistance,const QString & style,bool autoDelete,int autoDeleteTimeoutMs)562 int LabelMgr::labelObject(const QString& text,
563 const QString& objectName,
564 bool visible,
565 float fontSize,
566 const QString& fontColor,
567 const QString& side,
568 double labelDistance,
569 const QString& style,
570 bool autoDelete,
571 int autoDeleteTimeoutMs)
572 {
573 return labelObject(text, objectName, visible, fontSize, Vec3f().setFromHtmlColor(fontColor), side, labelDistance, style, autoDelete, autoDeleteTimeoutMs);
574 }
labelObject(const QString & text,const QString & objectName,bool visible,float fontSize,const Vec3f & fontColor,const QString & side,double labelDistance,const QString & style,bool autoDelete,int autoDeleteTimeoutMs)575 int LabelMgr::labelObject(const QString& text,
576 const QString& objectName,
577 bool visible,
578 float fontSize,
579 const Vec3f& fontColor,
580 const QString& side,
581 double labelDistance,
582 const QString& style,
583 bool autoDelete,
584 int autoDeleteTimeoutMs)
585 {
586 QFont font;
587 font.setPixelSize(static_cast<int>(fontSize));
588 StelObjectP obj = GETSTELMODULE(StelObjectMgr)->searchByName(objectName);
589 if (!obj)
590 {
591 qWarning() << "LabelMgr::labelObject object not found: " << objectName;
592 return -1;
593 }
594
595 StelLabel* l = new SkyLabel(text, obj, font, fontColor, side, labelDistance, SkyLabel::stringToStyle(style));
596 if (l==Q_NULLPTR)
597 return -1;
598
599 if (visible)
600 l->setFlagShow(true);
601
602 l->autoDelete = autoDelete;
603
604 return appendLabel(l, autoDeleteTimeoutMs);
605 }
606
labelHorizon(const QString & text,float az,float alt,bool visible,float fontSize,const QString & fontColor,bool autoDelete,int autoDeleteTimeoutMs)607 int LabelMgr::labelHorizon(const QString& text,
608 float az,
609 float alt,
610 bool visible,
611 float fontSize,
612 const QString& fontColor,
613 bool autoDelete,
614 int autoDeleteTimeoutMs)
615 {
616 return labelHorizon(text, az, alt, visible, fontSize, Vec3f().setFromHtmlColor(fontColor), autoDelete, autoDeleteTimeoutMs);
617 }
labelHorizon(const QString & text,float az,float alt,bool visible,float fontSize,const Vec3f & fontColor,bool autoDelete,int autoDeleteTimeoutMs)618 int LabelMgr::labelHorizon(const QString& text,
619 float az,
620 float alt,
621 bool visible,
622 float fontSize,
623 const Vec3f& fontColor,
624 bool autoDelete,
625 int autoDeleteTimeoutMs)
626 {
627 QFont font;
628 font.setPixelSize(static_cast<int>(fontSize));
629 HorizonLabel* l = new HorizonLabel(text, az, alt, font, fontColor);
630 if (l==Q_NULLPTR)
631 return -1;
632
633 if (visible)
634 l->setFlagShow(true);
635
636 l->autoDelete = autoDelete;
637
638 return appendLabel(l, autoDeleteTimeoutMs);
639 }
640
labelEquatorial(const QString & text,const QString & ra,const QString & dec,bool visible,float fontSize,const QString & fontColor,const QString & side,double labelDistance,bool autoDelete,int autoDeleteTimeoutMs,bool j2000epoch)641 int LabelMgr::labelEquatorial(const QString& text,
642 const QString& ra,
643 const QString& dec,
644 bool visible,
645 float fontSize,
646 const QString& fontColor,
647 const QString &side,
648 double labelDistance,
649 bool autoDelete,
650 int autoDeleteTimeoutMs,
651 bool j2000epoch)
652 {
653 return labelEquatorial(text, ra, dec, visible, fontSize, Vec3f().setFromHtmlColor(fontColor), side, labelDistance, autoDelete, autoDeleteTimeoutMs, j2000epoch);
654 }
labelEquatorial(const QString & text,const QString & ra,const QString & dec,bool visible,float fontSize,const Vec3f & fontColor,const QString & side,double labelDistance,bool autoDelete,int autoDeleteTimeoutMs,bool j2000epoch)655 int LabelMgr::labelEquatorial(const QString& text,
656 const QString& ra,
657 const QString& dec,
658 bool visible,
659 float fontSize,
660 const Vec3f& fontColor,
661 const QString &side,
662 double labelDistance,
663 bool autoDelete,
664 int autoDeleteTimeoutMs,
665 bool j2000epoch)
666 {
667 QFont font;
668 font.setPixelSize(static_cast<int>(fontSize));
669 double dRA = StelUtils::getDecAngle(ra);
670 double dDec = StelUtils::getDecAngle(dec);
671 EquatorialLabel* l = new EquatorialLabel(text, dRA, dDec, font, fontColor, side, labelDistance, j2000epoch);
672 if (l==Q_NULLPTR)
673 return -1;
674
675 if (visible)
676 l->setFlagShow(true);
677
678 l->autoDelete = autoDelete;
679
680 return appendLabel(l, autoDeleteTimeoutMs);
681 }
682
labelScreen(const QString & text,int x,int y,bool visible,float fontSize,const QString & fontColor,bool autoDelete,int autoDeleteTimeoutMs)683 int LabelMgr::labelScreen(const QString& text,
684 int x,
685 int y,
686 bool visible,
687 float fontSize,
688 const QString& fontColor,
689 bool autoDelete,
690 int autoDeleteTimeoutMs)
691 {
692 return labelScreen(text, x, y, visible, fontSize, Vec3f().setFromHtmlColor(fontColor), autoDelete, autoDeleteTimeoutMs);
693 }
labelScreen(const QString & text,int x,int y,bool visible,float fontSize,const Vec3f & fontColor,bool autoDelete,int autoDeleteTimeoutMs)694 int LabelMgr::labelScreen(const QString& text,
695 int x,
696 int y,
697 bool visible,
698 float fontSize,
699 const Vec3f& fontColor,
700 bool autoDelete,
701 int autoDeleteTimeoutMs)
702 {
703 QFont font;
704 font.setPixelSize(static_cast<int>(fontSize));
705 ScreenLabel* l = new ScreenLabel(text, x, y, font, fontColor);
706 if (l==Q_NULLPTR)
707 return -1;
708
709 if (visible)
710 l->setFlagShow(true);
711
712 l->autoDelete = autoDelete;
713
714 return appendLabel(l, autoDeleteTimeoutMs);
715 }
716
getLabelShow(int id) const717 bool LabelMgr::getLabelShow(int id) const
718 {
719 if (allLabels.contains(id)) // mistake-proofing!
720 return allLabels[id]->getFlagShow();
721 else
722 return false;
723 }
724
setLabelShow(int id,bool show)725 void LabelMgr::setLabelShow(int id, bool show)
726 {
727 if (allLabels.contains(id)) // mistake-proofing!
728 allLabels[id]->setFlagShow(show);
729 }
730
setLabelText(int id,const QString & newText)731 void LabelMgr::setLabelText(int id, const QString& newText)
732 {
733 if (allLabels.contains(id)) // mistake-proofing!
734 allLabels[id]->setText(newText);
735 }
736
deleteLabel(int id)737 void LabelMgr::deleteLabel(int id)
738 {
739 if (id<0 || !allLabels.contains(id))
740 return;
741
742 if (allLabels[id]->timer != Q_NULLPTR)
743 allLabels[id]->timer->deleteLater();
744
745 delete allLabels[id];
746 allLabels.remove(id);
747 }
748
update(double deltaTime)749 void LabelMgr::update(double deltaTime)
750 {
751 for (auto* l : qAsConst(allLabels))
752 l->update(deltaTime);
753 }
754
getCallOrder(StelModuleActionName actionName) const755 double LabelMgr::getCallOrder(StelModuleActionName actionName) const
756 {
757 if (actionName==StelModule::ActionDraw)
758 return StelApp::getInstance().getModuleMgr().getModule("LandscapeMgr")->getCallOrder(actionName)+11;
759 return 0;
760 }
761
deleteAllLabels(void)762 int LabelMgr::deleteAllLabels(void)
763 {
764 int count=0;
765 for (auto* l : qAsConst(allLabels))
766 {
767 delete l;
768 count++;
769 }
770 allLabels.clear();
771 return count;
772 }
773