• 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
  • widgets
infoboxwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  fovwidget.cpp - description
3  -------------------
4  begin : 20 Aug 2009
5  copyright : (C) 2009 by Khudyakov Alexey
6  email : alexey.skladnoy@gmail.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 #include "infoboxwidget.h"
19 
20 #include "kstarsdata.h"
21 #include "colorscheme.h"
22 #include "ksutils.h"
23 #include <QPainter>
24 #include <QMouseEvent>
25 #include <QFontMetrics>
26 
27 const int InfoBoxWidget::padX = 6;
28 const int InfoBoxWidget::padY = 2;
29 
30 InfoBoxes::~InfoBoxes()
31 {}
32 
33 InfoBoxes::InfoBoxes(QWidget* parent) : QWidget(parent) {
34  setMouseTracking( true );
35 }
36 
37 
38 void InfoBoxes::addInfoBox(InfoBoxWidget* ibox)
39 {
40  ibox->setParent(this);
41  m_boxes.append(ibox);
42 }
43 
44 void InfoBoxes::resizeEvent(QResizeEvent*) {
45  foreach(InfoBoxWidget* w, m_boxes)
46  w->adjust();
47 }
48 
49 /* ================================================================ */
50 
51 InfoBoxWidget::InfoBoxWidget(bool shade, const QPoint& pos, int anchor, const QStringList& str, QWidget* parent) :
52  QWidget(parent),
53  m_strings(str),
54  m_adjusted(false),
55  m_grabbed(false),
56  m_shaded(shade),
57  m_anchor(anchor)
58 {
59  move(pos);
60  updateSize();
61 }
62 
63 InfoBoxWidget::~InfoBoxWidget()
64 {}
65 
66 void InfoBoxWidget::updateSize() {
67  QFontMetrics fm(font());
68  int w = 0;
69  foreach(const QString& str, m_strings)
70  w = qMax(w, fm.width(str));
71  int h = fm.height() * (m_shaded ? 1 : m_strings.size());
72  // Add padding
73  resize(w + 2*padX, h + 2*padY + 2);
74  adjust();
75 }
76 
77 void InfoBoxWidget::slotTimeChanged() {
78  KStarsData* data = KStarsData::Instance();
79 
80  m_strings.clear();
81  m_strings <<
82  i18nc( "Local Time", "LT: " ) +
83  KGlobal::locale()->formatTime( data->lt().time(), true ) + " " +
84  KGlobal::locale()->formatDate( data->lt().date() );
85  m_strings <<
86  i18nc( "Universal Time", "UT: " ) +
87  KGlobal::locale()->formatTime( data->ut().time(), true ) + " " +
88  KGlobal::locale()->formatDate( data->ut().date() );
89 
90  QString STString;
91  STString = STString.sprintf( "%02d:%02d:%02d ", data->lst()->hour(), data->lst()->minute(), data->lst()->second() );
92  //Don't use KLocale::formatNumber() for Julian Day because we don't want
93  //thousands-place separators
94  QString JDString = QString::number( data->ut().djd(), 'f', 2 );
95  JDString.replace( '.', KGlobal::locale()->decimalSymbol() );
96  m_strings <<
97  i18nc( "Sidereal Time", "ST: " ) + STString +
98  i18nc( "Julian Day", "JD: " ) + JDString;
99  updateSize();
100  update();
101 }
102 
103 void InfoBoxWidget::slotGeoChanged() {
104  GeoLocation* geo = KStarsData::Instance()->geo();
105 
106  m_strings.clear();
107  m_strings << geo->fullName();
108  m_strings <<
109  i18nc( "Longitude", "Long:" ) + ' ' +
110  KGlobal::locale()->formatNumber( geo->lng()->Degrees(),3) + " " +
111  i18nc( "Latitude", "Lat:" ) + ' ' +
112  KGlobal::locale()->formatNumber( geo->lat()->Degrees(),3);
113  updateSize();
114  update();
115 }
116 
117 void InfoBoxWidget::slotObjectChanged(SkyObject* obj) {
118  setPoint( obj->translatedLongName(), obj );
119 }
120 
121 void InfoBoxWidget::slotPointChanged(SkyPoint* p) {
122  setPoint( i18n("nothing"), p);
123 }
124 
125 void InfoBoxWidget::setPoint(QString name, SkyPoint* p) {
126  m_strings.clear();
127  m_strings << name;
128  m_strings <<
129  i18nc( "Right Ascension", "RA" ) + ": " + p->ra().toHMSString() + " " +
130  i18nc( "Declination", "Dec" ) + ": " + p->dec().toDMSString(true);
131  m_strings <<
132  i18nc( "Azimuth", "Az" ) + ": " + p->az().toDMSString(true) + " " +
133  i18nc( "Altitude", "Alt" ) + ": " + p->alt().toDMSString(true);
134  updateSize();
135  update();
136 }
137 
138 void InfoBoxWidget::adjust() {
139  if( !isVisible() )
140  return;
141  // X axis
142  int newX = x();
143  int maxX = parentWidget()->width() - width();
144  if( m_anchor & AnchorRight ) {
145  newX = maxX;
146  } else {
147  newX = KSUtils::clamp(newX, 0, maxX);
148  if( newX == maxX )
149  m_anchor |= AnchorRight;
150  }
151  // Y axis
152  int newY = y();
153  int maxY = parentWidget()->height() - height();
154  if( m_anchor & AnchorBottom ) {
155  newY = maxY;
156  } else {
157  newY = KSUtils::clamp(newY, 0, maxY);
158  if( newY == maxY )
159  m_anchor |= AnchorBottom;
160  }
161  // Do move
162  m_adjusted = true;
163  move(newX, newY);
164 }
165 
166 void InfoBoxWidget::paintEvent(QPaintEvent*)
167 {
168  // If widget contain no strings return
169  if( m_strings.empty() )
170  return;
171  // Start with painting
172  ColorScheme* cs = KStarsData::Instance()->colorScheme();
173  QPainter p;
174  p.begin( this );
175 
176  // Draw background
177  QColor colBG = cs->colorNamed( "BoxBGColor" );
178  colBG.setAlpha(127);
179  p.fillRect( contentsRect(), colBG );
180  // Draw border
181  if( m_grabbed ) {
182  p.setPen( cs->colorNamed( "BoxGrabColor" ) );
183  p.drawRect( 0, 0, width()-1, height()-1 );
184  }
185  // Draw text
186  int h = QFontMetrics( font() ).height();
187  int y = 0;
188  p.setPen( cs->colorNamed( "BoxTextColor" ) );
189  foreach(const QString& str, m_strings) {
190  y += h;
191  p.drawText( padX, padY + y, str);
192  }
193  // Done
194  p.end();
195 }
196 
197 void InfoBoxWidget::mouseMoveEvent(QMouseEvent * event) {
198  m_grabbed = true;
199  // X axis
200  int newX = x() + event->x();
201  int maxX = parentWidget()->width() - width();
202  if( newX > maxX ) {
203  newX = maxX;
204  m_anchor |= AnchorRight;
205  } else {
206  if( newX < 0 )
207  newX = 0;
208  m_anchor &= ~AnchorRight;
209  }
210  // Y axis
211  int newY = y() + event->y();
212  int maxY = parentWidget()->height() - height();
213  if( newY > maxY ) {
214  newY = maxY;
215  m_anchor |= AnchorBottom;
216  } else {
217  if( newY < 0 )
218  newY = 0;
219  m_anchor &= ~AnchorBottom;
220  }
221  // Do move
222  m_adjusted = true;
223  move(newX, newY);
224 }
225 
226 void InfoBoxWidget::mousePressEvent(QMouseEvent*) {
227  emit clicked();
228 }
229 
230 void InfoBoxWidget::showEvent(QShowEvent*) {
231  if( !m_adjusted )
232  adjust();
233 }
234 
235 void InfoBoxWidget::mouseDoubleClickEvent(QMouseEvent*) {
236  m_shaded = !m_shaded;
237  updateSize();
238  update();
239 }
240 
241 void InfoBoxWidget::mouseReleaseEvent(QMouseEvent*) {
242  m_grabbed = false;
243 }
244 
245 #include "infoboxwidget.moc"
dms::hour
int hour() const
Definition: dms.h:104
SkyPoint::ra
const dms & ra() const
Definition: skypoint.h:171
InfoBoxWidget::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *event)
Definition: infoboxwidget.cpp:197
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SkyPoint::az
const dms & az() const
Definition: skypoint.h:177
dms::minute
int minute() const
Definition: dms.cpp:174
KStarsData::colorScheme
ColorScheme * colorScheme()
Definition: kstarsdata.h:149
QWidget
KStarsData::lst
dms * lst()
Definition: kstarsdata.h:161
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
dms::Degrees
const double & Degrees() const
Definition: dms.h:98
GeoLocation::lng
const dms * lng() const
Definition: geolocation.h:76
ColorScheme::colorNamed
QColor colorNamed(const QString &name) const
Retrieve a color by name.
Definition: colorscheme.cpp:97
KStarsData::geo
GeoLocation * geo()
Definition: kstarsdata.h:164
InfoBoxWidget::slotGeoChanged
void slotGeoChanged()
Set information about location.
Definition: infoboxwidget.cpp:103
InfoBoxWidget::paintEvent
virtual void paintEvent(QPaintEvent *event)
Definition: infoboxwidget.cpp:166
dms::second
int second() const
Definition: dms.cpp:182
InfoBoxWidget::AnchorRight
Definition: infoboxwidget.h:55
InfoBoxWidget::mousePressEvent
virtual void mousePressEvent(QMouseEvent *event)
Definition: infoboxwidget.cpp:226
InfoBoxes::addInfoBox
void addInfoBox(InfoBoxWidget *ibox)
Definition: infoboxwidget.cpp:38
SkyPoint
The sky coordinates of a point in the sky.
Definition: skypoint.h:50
InfoBoxWidget::adjust
void adjust()
Adjust widget's postion.
Definition: infoboxwidget.cpp:138
KStarsData::lt
const KStarsDateTime & lt() const
Definition: kstarsdata.h:137
GeoLocation
Contains all relevant information for specifying a location on Earth: City Name, State/Province name...
Definition: geolocation.h:39
InfoBoxWidget::AnchorBottom
Definition: infoboxwidget.h:56
KStarsDateTime::djd
long double djd() const
Definition: kstarsdatetime.h:145
i18nc
i18nc("string from libindi, used in the config dialog","100x")
SkyObject::translatedLongName
QString translatedLongName() const
Definition: skyobject.h:145
InfoBoxes::InfoBoxes
InfoBoxes(QWidget *parent=0)
Definition: infoboxwidget.cpp:33
InfoBoxWidget::~InfoBoxWidget
virtual ~InfoBoxWidget()
Destructor.
Definition: infoboxwidget.cpp:63
ColorScheme
This class stores all of the adjustable colors in KStars, in a QMap object keyed by the names of the ...
Definition: colorscheme.h:38
SkyPoint::dec
const dms & dec() const
Definition: skypoint.h:174
InfoBoxWidget::mouseDoubleClickEvent
virtual void mouseDoubleClickEvent(QMouseEvent *event)
Definition: infoboxwidget.cpp:235
InfoBoxes::~InfoBoxes
virtual ~InfoBoxes()
Definition: infoboxwidget.cpp:30
InfoBoxWidget
Small optianally transparent box for display of text messages.
Definition: infoboxwidget.h:48
InfoBoxWidget::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *event)
Definition: infoboxwidget.cpp:241
infoboxwidget.h
InfoBoxWidget::InfoBoxWidget
InfoBoxWidget(bool shade, const QPoint &pos, int anchor=0, const QStringList &str=QStringList(), QWidget *parent=0)
Create one infobox.
Definition: infoboxwidget.cpp:51
GeoLocation::lat
const dms * lat() const
Definition: geolocation.h:79
InfoBoxWidget::slotPointChanged
void slotPointChanged(SkyPoint *p)
Set information about pointing.
Definition: infoboxwidget.cpp:121
InfoBoxWidget::clicked
void clicked()
Emitted when widget is clicked.
InfoBoxWidget::slotObjectChanged
void slotObjectChanged(SkyObject *obj)
Set information about object.
Definition: infoboxwidget.cpp:117
GeoLocation::fullName
QString fullName() const
Definition: geolocation.cpp:56
KSUtils::clamp
T clamp(T x, T min, T max)
Clamp value into range.
Definition: ksutils.h:59
InfoBoxes::resizeEvent
virtual void resizeEvent(QResizeEvent *event)
Definition: infoboxwidget.cpp:44
kstarsdata.h
KStarsData::ut
const KStarsDateTime & ut() const
Definition: kstarsdata.h:140
SkyPoint::alt
const dms & alt() const
Definition: skypoint.h:180
ksutils.h
InfoBoxWidget::slotTimeChanged
void slotTimeChanged()
Set information about time.
Definition: infoboxwidget.cpp:77
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
colorscheme.h
InfoBoxWidget::showEvent
virtual void showEvent(QShowEvent *event)
Definition: infoboxwidget.cpp:230
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