29 const int symbolSize = 15;
30 const int bRectWidth = 100;
31 const int bRectHeight = 45;
32 const int maxHScalePixels = 200;
33 const int maxVScalePixels = 100;
34 const int xSymbolSpacing = 100;
35 const int ySymbolSpacing = 70;
39 : m_Painter(0), m_SkyMap(
SkyMap::Instance()), m_DeletePainter(false), m_Type(LT_FULL),
40 m_Orientation(orientation), m_Position(pos), m_PositionFloating(QPoint(0, 0)),
41 m_cScheme(
KStarsData::Instance()->colorScheme()), m_DrawFrame(false), m_SymbolSize(symbolSize),
42 m_BRectWidth(bRectWidth), m_BRectHeight(bRectHeight), m_MaxHScalePixels(maxHScalePixels),
43 m_MaxVScalePixels(maxVScalePixels), m_XSymbolSpacing(xSymbolSpacing), m_YSymbolSpacing(ySymbolSpacing)
50 if(m_Painter && m_DeletePainter)
69 width = 40 + m_MaxHScalePixels;
83 width = 7 * m_XSymbolSpacing;
84 height = 20 + m_SymbolSize + m_BRectHeight;
90 width = 160 + m_MaxHScalePixels;
97 width = 7 * m_XSymbolSpacing;
98 height = 20 + m_SymbolSize + m_BRectHeight + 70;
115 height = 40 + m_MaxVScalePixels;
129 height = 7 * m_YSymbolSpacing;
136 height = 100 + m_MaxVScalePixels;
143 height = 100 + 7 * m_YSymbolSpacing + m_MaxVScalePixels;
159 return QSize(width, height);
170 m_DeletePainter =
true;
187 m_PositionFloating = positionToDeviceCoord(painter->device());
190 m_Painter->translate(m_PositionFloating.x(), m_PositionFloating.y());
192 m_Painter->setFont(m_Font);
194 QBrush backgroundBrush(m_BgColor, Qt::SolidPattern);
195 QPen backgroundPen(m_cScheme->
colorNamed(
"SNameColor"));
196 backgroundPen.setStyle(Qt::SolidLine);
199 m_Painter->
setBrush(backgroundBrush);
200 m_Painter->
setPen(backgroundPen);
205 m_Painter->drawRect(1, 1, size.width(), size.height());
211 noLinePen.setStyle(Qt::NoPen);
213 m_Painter->
setPen(noLinePen);
214 m_Painter->drawRect(1, 1, size.width(), size.height());
216 m_Painter->
setPen(backgroundPen);
219 switch(m_Orientation)
227 paintScale(QPointF(20, 20));
233 paintMagnitudes(QPointF(20, 20));
239 paintSymbols(QPointF(20, 20));
245 paintMagnitudes(QPointF(20, 20));
246 paintScale(QPointF(150, 20));
252 paintSymbols(QPointF(20, 20));
253 paintMagnitudes(QPointF(10, 40 + m_SymbolSize + m_BRectHeight));
254 paintScale(QPointF(200, 40 + m_SymbolSize + m_BRectHeight));
270 paintScale(QPointF(20, 20));
276 paintMagnitudes(QPointF(20, 20));
282 paintSymbols(QPointF(20, 20));
288 paintMagnitudes(QPointF(7, 20));
289 paintScale(QPointF(20, 80));
295 paintSymbols(QPointF(30, 20));
296 paintMagnitudes(QPointF(7, 30 + 7 * m_YSymbolSpacing));
297 paintScale(QPointF(20, 90 + 7 * m_YSymbolSpacing));
322 m_Position = prevPos;
336 m_Position = prevPos;
339 void Legend::paintSymbols(QPointF pos)
346 switch(m_Orientation)
351 QString label1 = i18n(
"Open Cluster") +
"\n" + i18n(
"Asterism");
352 paintSymbol(QPointF(x, y), 3, 1, 0, label1);
353 x += m_XSymbolSpacing;
356 paintSymbol(QPointF(x, y), 4, 1, 0, i18n(
"Globular Cluster"));
357 x += m_XSymbolSpacing;
360 QString label3 = i18n(
"Gaseous Nebula") +
"\n" + i18n(
"Dark Nebula");
361 paintSymbol(QPointF(x, y), 5, 1, 0, label3);
362 x += m_XSymbolSpacing;
365 paintSymbol(QPointF(x, y), 6, 1, 0, i18n(
"Planetary Nebula"));
366 x += m_XSymbolSpacing;
369 paintSymbol(QPointF(x, y), 7, 1, 0, i18n(
"Supernova Remnant"));
370 x += m_XSymbolSpacing;
373 QString label6 = i18n(
"Galaxy") +
"\n" + i18n(
"Quasar");
374 paintSymbol(QPointF(x, y), 8, 0.5, 60, label6);
375 x += m_XSymbolSpacing;
378 paintSymbol(QPointF(x, y), 14, 1, 0, i18n(
"Galactic Cluster"));
386 QString label1 = i18n(
"Open Cluster") +
"\n" + i18n(
"Asterism");
387 paintSymbol(QPointF(x, y), 3, 1, 0, label1);
388 y += m_YSymbolSpacing;
391 paintSymbol(QPointF(x, y), 4, 1, 0, i18n(
"Globular Cluster"));
392 y += m_YSymbolSpacing;
395 QString label3 = i18n(
"Gaseous Nebula") +
"\n" + i18n(
"Dark Nebula");
396 paintSymbol(QPointF(x, y), 5, 1, 0, label3);
397 y += m_YSymbolSpacing;
400 paintSymbol(QPointF(x, y), 6, 1, 0, i18n(
"Planetary Nebula"));
401 y += m_YSymbolSpacing;
404 paintSymbol(QPointF(x, y), 7, 1, 0, i18n(
"Supernova Remnant"));
405 y += m_YSymbolSpacing;
408 QString label6 = i18n(
"Galaxy") +
"\n" + i18n(
"Quasar");
409 paintSymbol(QPointF(x, y), 8, 0.5, 60, label6);
410 y += m_YSymbolSpacing;
413 paintSymbol(QPointF(x, y), 14, 1, 0, i18n(
"Galactic Cluster"));
421 void Legend::paintSymbol(QPointF pos,
int type,
float e,
float angle, QString label)
425 qreal bRectHalfWidth = m_BRectWidth / 2;
429 QRectF bRect(QPoint(x - bRectHalfWidth, y + m_SymbolSize), QPoint(x + bRectHalfWidth, y + m_SymbolSize + m_BRectHeight));
432 m_Painter->drawText(bRect, label, QTextOption(Qt::AlignHCenter));
435 void Legend::paintMagnitudes(QPointF pos)
440 m_Painter->drawText(x, y, i18n(
"Star Magnitudes:"));
443 for(
int i = 1; i <= 9; i += 2)
446 m_Painter->drawText(x + i * 10 - 4, y + 20, QString::number(i));
450 void Legend::paintScale(QPointF pos)
452 qreal maxScalePixels;
454 switch(m_Orientation)
458 maxScalePixels = m_MaxHScalePixels;
464 maxScalePixels = m_MaxVScalePixels;
478 if(maxArcsec >= 3600)
480 deg = maxArcsec / 3600;
481 lab = QString::number(deg) + QString::fromWCharArray(L
"\u00B0");
484 else if(maxArcsec >= 60)
486 arcmin = maxArcsec / 60;
487 lab = QString::number(arcmin) +
'\'';
493 lab = QString::number(arcsec) +
"\"";
496 int actualArcsec = 3600 * deg + 60 * arcmin + arcsec;
503 switch(m_Orientation)
507 m_Painter->drawText(pos, i18n(
"Chart Scale:"));
510 m_Painter->drawLine(x, y, x + size, y);
512 m_Painter->drawLine(x, y - 5, x, y + 5);
513 m_Painter->drawLine(x + size, y - 5, x + size, y + 5);
516 QRectF bRect(QPoint(x, y), QPoint(x + size, y + 20));
517 m_Painter->drawText(bRect, lab, QTextOption(Qt::AlignHCenter));
524 m_Painter->drawText(pos, i18n(
"Chart Scale:"));
528 m_Painter->drawLine(x, y, x, y + size);
530 m_Painter->drawLine(x - 5, y, x + 5, y);
531 m_Painter->drawLine(x - 5, y + size, x + 5, y + size);
534 QRectF bRect(QPoint(x + 5, y), QPoint(x + 20, y + size));
536 m_Painter->drawText(bRect, lab, QTextOption(Qt::AlignVCenter));
545 QPoint Legend::positionToDeviceCoord(QPaintDevice *pd)
558 return QPoint(pd->width() - legendSize.width(), 0);
563 return QPoint(0, pd->height() - legendSize.height());
568 return QPoint(pd->width() - legendSize.width(), pd->height() - legendSize.height());
579 m_Painter( 0 ), m_SkyMap( o.m_SkyMap ), m_DeletePainter( o.m_DeletePainter ),
580 m_Type( o.m_Type ),m_Orientation( o.m_Orientation ),m_Position( o.m_Position ),
581 m_PositionFloating( o.m_PositionFloating ), m_cScheme( o.m_cScheme ),m_Font( o.m_Font ),
582 m_BgColor( o.m_BgColor ),m_DrawFrame( o.m_DrawFrame ), m_SymbolSize( o.m_SymbolSize ),
583 m_BRectWidth( o.m_BRectWidth ),m_BRectHeight( o.m_BRectHeight ),
584 m_MaxHScalePixels( o.m_MaxHScalePixels ),m_MaxVScalePixels( o.m_MaxVScalePixels ),
585 m_XSymbolSpacing( o.m_XSymbolSpacing ),m_YSymbolSpacing( o.m_YSymbolSpacing ) {
virtual bool drawPointSource(SkyPoint *loc, float mag, char sp= 'A')
Draw a point source (e.g., a star).
KStarsData is the backbone of KStars.
QSize calculateSize()
Calculates size of legend that will be painted using current settings.
QColor colorNamed(const QString &name) const
Retrieve a color by name.
virtual void setBrush(const QBrush &brush)
Set the brush of the painter.
virtual void begin()
Begin painting.
The QPainter-based painting backend.
float starWidth(float mag) const
Get the width of a star of magnitude mag.
LEGEND_POSITION
Legend position enumeration.
LEGEND_TYPE
Legend type enumeration.
LEGEND_ORIENTATION
Legend orientation enumeration.
Legend class is used for painting legends on class inheriting QPaintDevice.
virtual void setPen(const QPen &pen)
Set the pen of the painter.
virtual void drawDeepSkySymbol(const QPointF &pos, int type, float size, float e, float positionAngle)
static double zoomFactor()
Get Zoom Factor, in pixels per radian.
This is the canvas on which the sky is painted.
void paintLegend(QPaintDevice *pd)
Paint legend on passed QPaintDevice at selected position.
virtual void end()
End and finalize painting.
Legend(LEGEND_ORIENTATION orientation=LO_HORIZONTAL, LEGEND_POSITION pos=LP_FLOATING)
Constructor.