• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • skycomponents
skylabeler.h
Go to the documentation of this file.
1 /***************************************************************************
2  skylabeler.h - K Desktop Planetarium
3  -------------------
4  begin : 2007-07-10
5  copyright : (C) 2007 by James B. Bowlin
6  email : bowlin@mindspring.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef SKYLABELER_H
19 #define SKYLABELER_H
20 
21 #include <QFontMetricsF>
22 #include <QList>
23 #include <QVector>
24 #include <QPainter>
25 #include <QPicture>
26 #include <QFont>
27 
28 #include "skylabel.h"
29 
30 class QString;
31 class QPointF;
32 class SkyMap;
33 class Projector;
34 struct LabelRun;
35 
36 typedef QList<LabelRun*> LabelRow;
37 typedef QVector<LabelRow*> ScreenRows;
38 
39 
112 class SkyLabeler
113 {
114 protected:
115  SkyLabeler();
116  SkyLabeler( SkyLabeler& skyLabler );
117 
118 public:
119  enum label_t {
120  STAR_LABEL,
121  ASTEROID_LABEL,
122  COMET_LABEL,
123  PLANET_LABEL,
124  JUPITER_MOON_LABEL,
125  SATURN_MOON_LABEL,
126  DEEP_SKY_LABEL,
127  CONSTEL_NAME_LABEL,
128  SATELLITE_LABEL,
129  RUDE_LABEL,
130  NUM_LABEL_TYPES
131  } ;
132 
133 
134  //----- Static Methods ----------------------------------------------//
135 
136  static SkyLabeler* Instance();
137 
144  static double ZoomOffset();
145 
149  inline static void AddLabel(SkyObject *obj, label_t type)
150  {
151  pinstance->addLabel( obj, type );
152  }
153 
154 
155  //--------------------------------------------------------------------//
156  ~SkyLabeler();
157 
167  void reset( SkyMap* skyMap );
168 
173  void draw(QPainter& p);
174 
175  //----- Font Setting -----//
176 
180  void setZoomFont();
181 
185  void setPen(const QPen& pen);
186 
192  void setFont( const QFont& font );
193 
198  void shrinkFont( int delta );
199 
204  void useStdFont();
205 
211  void resetFont();
212 
216  QFontMetricsF& fontMetrics() { return m_fontMetrics; }
217 
218 
219  //----- Drawing/Adding Labels -----//
220 
225  void getMargins( const QString& text, float *left,
226  float *right, float *top, float *bot );
227 
234  bool drawGuideLabel( QPointF& o, const QString& text, double angle );
235 
243  bool drawNameLabel( SkyObject* obj, const QPointF& _p );
244 
251  void drawRudeNameLabel( SkyObject* obj, const QPointF& _p );
252 
256  void addLabel( SkyObject *obj, label_t type );
257 
264  void drawQueuedLabels();
265 
270  void drawQueuedLabelsType( SkyLabeler::label_t type );
271 
272 
273  //----- Marking Regions -----//
274 
284  bool markText( const QPointF& p, const QString& text);
285 
290  bool markRegion( qreal left, qreal right, qreal top, qreal bot );
291 
292  //----- Diagnostics and Information -----//
293 
301  float fillRatio();
302 
312  float hitRatio();
313 
318  void printInfo();
319 
320  int hits() { return m_hits; };
321  int marks() { return m_marks; }
322 
323 private:
324  ScreenRows screenRows;
325 
326  int m_maxX;
327  int m_maxY;
328  int m_size;
329  int m_minDeltaX;
330 
331  int m_marks;
332  int m_hits;
333  int m_misses;
334  int m_elements;
335  int m_errors;
336 
337  qreal m_yScale;
338  double m_offset;
339 
340  QFont m_stdFont, m_skyFont;
341  QFontMetricsF m_fontMetrics;
342 
343  QPainter m_p;
344  QPicture m_picture;
345 
346  QVector<LabelList> labelList;
347 
348  const Projector* m_proj;
349 
350  static SkyLabeler* pinstance;
351 };
352 
353 #endif
SkyLabeler::SkyLabeler
SkyLabeler()
Definition: skylabeler.cpp:79
SkyLabeler::RUDE_LABEL
Definition: skylabeler.h:129
SkyLabeler::setZoomFont
void setZoomFont()
adjusts the font in psky to be smaller if we are zoomed out.
Definition: skylabeler.cpp:56
SkyLabeler::CONSTEL_NAME_LABEL
Definition: skylabeler.h:127
SkyLabeler::printInfo
void printInfo()
diagnostic, prints some brief statistics to the console.
Definition: skylabeler.cpp:513
SkyLabeler::drawRudeNameLabel
void drawRudeNameLabel(SkyObject *obj, const QPointF &_p)
draw the object's name label on the map, without checking for overlap with other labels.
Definition: skylabeler.cpp:478
SkyLabeler::STAR_LABEL
Definition: skylabeler.h:120
SkyLabeler::marks
int marks()
Definition: skylabeler.h:321
SkyLabeler::fillRatio
float fillRatio()
diagnostic.
Definition: skylabeler.cpp:501
SkyLabeler::setFont
void setFont(const QFont &font)
tells the labeler the font you will be using so it can figure out the height and width of the labels...
Definition: skylabeler.cpp:167
skylabel.h
SkyLabeler::label_t
label_t
Definition: skylabeler.h:119
SkyLabeler::getMargins
void getMargins(const QString &text, float *left, float *right, float *top, float *bot)
sets four margins for help in keeping labels entirely on the screen.
Definition: skylabeler.cpp:195
SkyLabeler::COMET_LABEL
Definition: skylabeler.h:122
SkyLabeler::SATURN_MOON_LABEL
Definition: skylabeler.h:125
SkyLabeler::JUPITER_MOON_LABEL
Definition: skylabeler.h:124
SkyLabeler::markRegion
bool markRegion(qreal left, qreal right, qreal top, qreal bot)
Works just like markText() above but for an arbitrary rectangular region bounded by top...
Definition: skylabeler.cpp:299
SkyLabeler::ZoomOffset
static double ZoomOffset()
returns the zoom dependent label offset.
Definition: skylabeler.cpp:71
SkyLabeler::Instance
static SkyLabeler * Instance()
Definition: skylabeler.cpp:49
Projector
This class serves as an interface to handle projections.
Definition: projector.h:49
SkyLabeler::hitRatio
float hitRatio()
diagnostic, the number of times mark() returned true divided by the total number of times mark was ca...
Definition: skylabeler.cpp:507
SkyLabeler::useStdFont
void useStdFont()
sets the font in SkyLabeler and in psky to the font psky had originally when reset() was called...
Definition: skylabeler.cpp:185
SkyLabeler::~SkyLabeler
~SkyLabeler()
Definition: skylabeler.cpp:93
SkyLabeler::reset
void reset(SkyMap *skyMap)
clears the virtual screen (if needed) and resizes the virtual screen (if needed) to match skyMap...
Definition: skylabeler.cpp:209
SkyLabeler::markText
bool markText(const QPointF &p, const QString &text)
tells the labeler the location and text of a label you want to draw.
Definition: skylabeler.cpp:291
SkyLabeler::DEEP_SKY_LABEL
Definition: skylabeler.h:126
SkyLabeler::drawQueuedLabelsType
void drawQueuedLabelsType(SkyLabeler::label_t type)
a convenience routine that draws all the labels from a single buffer.
Definition: skylabeler.cpp:466
LabelRow
QList< LabelRun * > LabelRow
Definition: skylabeler.h:34
SkyLabeler::PLANET_LABEL
Definition: skylabeler.h:123
SkyLabeler::fontMetrics
QFontMetricsF & fontMetrics()
returns the fontMetricsF we have already created.
Definition: skylabeler.h:216
SkyLabeler::drawGuideLabel
bool drawGuideLabel(QPointF &o, const QString &text, double angle)
Tries to draw the text at the position and angle specified.
Definition: skylabeler.cpp:104
SkyLabeler::shrinkFont
void shrinkFont(int delta)
decreases the size of the font in psky and in the SkyLabeler by the delta points. ...
Definition: skylabeler.cpp:178
SkyLabeler::SATELLITE_LABEL
Definition: skylabeler.h:128
SkyLabeler::hits
int hits()
Definition: skylabeler.h:320
SkyMap
This is the canvas on which the sky is painted.
Definition: skymap.h:72
SkyLabeler::drawQueuedLabels
void drawQueuedLabels()
draws the labels stored in all the buffers.
Definition: skylabeler.cpp:435
SkyLabeler::setPen
void setPen(const QPen &pen)
sets the pen used for drawing labels on the sky.
Definition: skylabeler.cpp:173
SkyLabeler::drawNameLabel
bool drawNameLabel(SkyObject *obj, const QPointF &_p)
Tries to draw a label for an object.
Definition: skylabeler.cpp:151
SkyLabeler::resetFont
void resetFont()
sets the font in SkyLabeler and in psky back to the zoom dependent value that was set in reset()...
Definition: skylabeler.cpp:190
SkyLabeler::addLabel
void addLabel(SkyObject *obj, label_t type)
queues the label in the "type" buffer for later drawing.
Definition: skylabeler.cpp:427
SkyLabeler
The purpose of this class is to prevent labels from overlapping.
Definition: skylabeler.h:112
SkyLabeler::draw
void draw(QPainter &p)
Draws labels using the given painter.
Definition: skylabeler.cpp:274
SkyLabeler::ASTEROID_LABEL
Definition: skylabeler.h:121
SkyObject
Provides all necessary information about an object in the sky: its coordinates, name(s), type, magnitude, and QStringLists of URLs for images and webpages regarding the object.
Definition: skyobject.h:46
SkyLabeler::NUM_LABEL_TYPES
Rude labels block other labels FIXME: find a better solution.
Definition: skylabeler.h:130
ScreenRows
QVector< LabelRow * > ScreenRows
Definition: skylabeler.h:37
SkyLabeler::AddLabel
static void AddLabel(SkyObject *obj, label_t type)
static version of addLabel() below.
Definition: skylabeler.h:149
QList
LabelRun
struct LabelRun LabelRun
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal