9#include "colorscheme.h"
10#include "kstarsdata.h"
12#include "skyqpainter.h"
19const int symbolSize = 15;
20const int bRectWidth = 100;
21const int bRectHeight = 45;
22const int maxHScalePixels = 200;
23const int maxVScalePixels = 100;
24const int xSymbolSpacing = 100;
25const int ySymbolSpacing = 70;
28Legend::Legend(LEGEND_ORIENTATION orientation, LEGEND_POSITION pos)
29 : m_SkyMap(
SkyMap::Instance()), m_Orientation(orientation),
30 m_Position(pos), m_PositionFloating(
QPoint(0, 0)), m_cScheme(
KStarsData::Instance()->colorScheme()),
31 m_SymbolSize(symbolSize), m_BRectWidth(bRectWidth), m_BRectHeight(bRectHeight),
32 m_MaxHScalePixels(maxHScalePixels), m_MaxVScalePixels(maxVScalePixels), m_XSymbolSpacing(xSymbolSpacing),
33 m_YSymbolSpacing(ySymbolSpacing)
35 m_BgColor = m_cScheme->colorNamed(
"SkyColor");
40 if (m_Painter !=
nullptr && m_DeletePainter)
46QSize Legend::calculateSize()
51 switch (m_Orientation)
59 width = 40 + m_MaxHScalePixels;
64 case LT_MAGNITUDES_ONLY:
73 width = 7 * m_XSymbolSpacing;
74 height = 20 + m_SymbolSize + m_BRectHeight;
78 case LT_SCALE_MAGNITUDES:
80 width = 160 + m_MaxHScalePixels;
87 width = 7 * m_XSymbolSpacing;
88 height = 20 + m_SymbolSize + m_BRectHeight + 70;
106 height = 40 + m_MaxVScalePixels;
110 case LT_MAGNITUDES_ONLY:
117 case LT_SYMBOLS_ONLY:
120 height = 7 * m_YSymbolSpacing;
124 case LT_SCALE_MAGNITUDES:
127 height = 100 + m_MaxVScalePixels;
134 height = 100 + 7 * m_YSymbolSpacing + m_MaxVScalePixels;
151 return QSize(width, height);
162 m_DeletePainter =
true;
165 paintLegend(m_Painter);
172 if (!m_DeletePainter)
177 if (m_Position != LP_FLOATING)
179 m_PositionFloating = positionToDeviceCoord(painter->
device());
182 m_Painter->
translate(m_PositionFloating.
x(), m_PositionFloating.
y());
191 m_Painter->
setBrush(backgroundBrush);
192 m_Painter->
setPen(backgroundPen);
194 QSize size = calculateSize();
205 m_Painter->
setPen(noLinePen);
208 m_Painter->
setPen(backgroundPen);
211 switch (m_Orientation)
223 case LT_MAGNITUDES_ONLY:
225 paintMagnitudes(
QPointF(20, 20));
229 case LT_SYMBOLS_ONLY:
235 case LT_SCALE_MAGNITUDES:
237 paintMagnitudes(
QPointF(20, 20));
245 paintMagnitudes(
QPointF(10, 40 + m_SymbolSize + m_BRectHeight));
246 paintScale(
QPointF(200, 40 + m_SymbolSize + m_BRectHeight));
267 case LT_MAGNITUDES_ONLY:
269 paintMagnitudes(
QPointF(20, 20));
273 case LT_SYMBOLS_ONLY:
279 case LT_SCALE_MAGNITUDES:
281 paintMagnitudes(
QPointF(7, 20));
289 paintMagnitudes(
QPointF(7, 30 + 7 * m_YSymbolSpacing));
290 paintScale(
QPointF(20, 90 + 7 * m_YSymbolSpacing));
306void Legend::paintLegend(
QPaintDevice *pd, LEGEND_TYPE type, LEGEND_POSITION pos)
308 LEGEND_TYPE prevType = m_Type;
309 LEGEND_POSITION prevPos = m_Position;
317 m_Position = prevPos;
320void Legend::paintLegend(
SkyQPainter *painter, LEGEND_TYPE type, LEGEND_POSITION pos)
322 LEGEND_TYPE prevType = m_Type;
323 LEGEND_POSITION prevPos = m_Position;
328 paintLegend(painter);
331 m_Position = prevPos;
334void Legend::paintSymbols(
QPointF pos)
341 switch (m_Orientation)
343 case Legend::LO_HORIZONTAL:
347 paintSymbol(
QPointF(x, y), 3, 1, 0, label1);
348 x += m_XSymbolSpacing;
351 paintSymbol(
QPointF(x, y), 4, 1, 0,
i18n(
"Globular Cluster"));
352 x += m_XSymbolSpacing;
356 paintSymbol(
QPointF(x, y), 5, 1, 0, label3);
357 x += m_XSymbolSpacing;
360 paintSymbol(
QPointF(x, y), 6, 1, 0,
i18n(
"Planetary Nebula"));
361 x += m_XSymbolSpacing;
364 paintSymbol(
QPointF(x, y), 7, 1, 0,
i18n(
"Supernova Remnant"));
365 x += m_XSymbolSpacing;
369 paintSymbol(
QPointF(x, y), 8, 0.5, 60, label6);
370 x += m_XSymbolSpacing;
373 paintSymbol(
QPointF(x, y), 14, 1, 0,
i18n(
"Galactic Cluster"));
378 case Legend::LO_VERTICAL:
382 paintSymbol(
QPointF(x, y), 3, 1, 0, label1);
383 y += m_YSymbolSpacing;
386 paintSymbol(
QPointF(x, y), 4, 1, 0,
i18n(
"Globular Cluster"));
387 y += m_YSymbolSpacing;
391 paintSymbol(
QPointF(x, y), 5, 1, 0, label3);
392 y += m_YSymbolSpacing;
395 paintSymbol(
QPointF(x, y), 6, 1, 0,
i18n(
"Planetary Nebula"));
396 y += m_YSymbolSpacing;
399 paintSymbol(
QPointF(x, y), 7, 1, 0,
i18n(
"Supernova Remnant"));
400 y += m_YSymbolSpacing;
404 paintSymbol(
QPointF(x, y), 8, 0.5, 60, label6);
405 y += m_YSymbolSpacing;
408 paintSymbol(
QPointF(x, y), 14, 1, 0,
i18n(
"Galactic Cluster"));
417void Legend::paintSymbol(
QPointF pos,
int type,
float e,
float angle,
QString label)
421 qreal bRectHalfWidth = (qreal)m_BRectWidth / 2;
424 m_Painter->drawDeepSkySymbol(pos, type, m_SymbolSize, e, angle);
425 QRectF bRect(
QPoint(x - bRectHalfWidth, y + m_SymbolSize),
426 QPoint(x + bRectHalfWidth, y + m_SymbolSize + m_BRectHeight));
432void Legend::paintMagnitudes(
QPointF pos)
440 for (
int i = 1; i <= 9; i += 2)
447void Legend::paintScale(
QPointF pos)
449 qreal maxScalePixels;
451 switch (m_Orientation)
455 maxScalePixels = m_MaxHScalePixels;
461 maxScalePixels = m_MaxVScalePixels;
469 qreal maxArcsec = maxScalePixels * 57.3 * 3600 / Options::zoomFactor();
476 if (maxArcsec >= 3600)
478 deg = maxArcsec / 3600;
482 else if (maxArcsec >= 60)
484 arcmin = maxArcsec / 60;
494 int actualArcsec = 3600 * deg + 60 * arcmin + arcsec;
496 qreal size = actualArcsec * Options::zoomFactor() / 57.3 / 3600;
501 switch (m_Orientation)
508 m_Painter->
drawLine(x, y, x + size, y);
510 m_Painter->
drawLine(x, y - 5, x, y + 5);
511 m_Painter->
drawLine(x + size, y - 5, x + size, y + 5);
526 m_Painter->
drawLine(x, y, x, y + size);
528 m_Painter->
drawLine(x - 5, y, x + 5, y);
529 m_Painter->
drawLine(x - 5, y + size, x + 5, y + size);
546 QSize legendSize = calculateSize();
577Legend::Legend(
const Legend &o)
578 : m_Painter(nullptr), m_SkyMap(o.m_SkyMap), m_DeletePainter(o.m_DeletePainter), m_Type(o.m_Type),
579 m_Orientation(o.m_Orientation), m_Position(o.m_Position), m_PositionFloating(o.m_PositionFloating),
580 m_cScheme(o.m_cScheme), m_Font(o.m_Font), m_BgColor(o.m_BgColor), m_DrawFrame(o.m_DrawFrame),
581 m_SymbolSize(o.m_SymbolSize), m_BRectWidth(o.m_BRectWidth), m_BRectHeight(o.m_BRectHeight),
582 m_MaxHScalePixels(o.m_MaxHScalePixels), m_MaxVScalePixels(o.m_MaxVScalePixels),
583 m_XSymbolSpacing(o.m_XSymbolSpacing), m_YSymbolSpacing(o.m_YSymbolSpacing)
589 m_SkyMap = o.m_SkyMap;
590 m_DeletePainter = o.m_DeletePainter;
592 m_Orientation = o.m_Orientation;
593 m_Position = o.m_Position;
594 m_PositionFloating = o.m_PositionFloating;
595 m_cScheme = o.m_cScheme;
597 m_BgColor = o.m_BgColor;
598 m_DrawFrame = o.m_DrawFrame;
599 m_SymbolSize = o.m_SymbolSize;
600 m_BRectWidth = o.m_BRectWidth;
601 m_BRectHeight = o.m_BRectHeight;
602 m_MaxHScalePixels = o.m_MaxHScalePixels;
603 m_MaxVScalePixels = o.m_MaxVScalePixels;
604 m_XSymbolSpacing = o.m_XSymbolSpacing;
605 m_YSymbolSpacing = o.m_YSymbolSpacing;
QColor colorNamed(const QString &name) const
Retrieve a color by name.
KStarsData is the backbone of KStars.
This is the canvas on which the sky is painted.
float starWidth(float mag) const
Get the width of a star of magnitude mag.
The QPainter-based painting backend.
void end() override
End and finalize painting.
bool drawPointSource(const SkyPoint *loc, float mag, char sp='A') override
Draw a point source (e.g., a star).
void setBrush(const QBrush &brush) override
Set the brush of the painter.
void setPen(const QPen &pen) override
Set the pen of the painter.
void begin() override
Begin painting.
QString i18n(const char *text, const TYPE &arg...)
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QPaintDevice * device() const const
void drawLine(const QLine &line)
void drawRect(const QRect &rectangle)
void drawText(const QPoint &position, const QString &text)
void setFont(const QFont &font)
void translate(const QPoint &offset)
void setStyle(Qt::PenStyle style)
QString fromWCharArray(const wchar_t *string, qsizetype size)
QString number(double n, char format, int precision)