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

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • src
  • plugins
  • render
  • earthquake
EarthquakeItem.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2010 Utku Aydin <utkuaydin34@gmail.com>
9 //
10 
11 #include "EarthquakeItem.h"
12 #include "ViewportParams.h"
13 
14 #include <QFontMetrics>
15 #include <QPainter>
16 #include <QPixmap>
17 #include <QSvgRenderer>
18 
19 namespace Marble
20 {
21 
22 // That's the font we will use to paint.
23 const QFont EarthquakeItem::s_font = QFont( "Sans Serif", 8, QFont::Bold );
24 
25 EarthquakeItem::EarthquakeItem( QObject *parent )
26  : AbstractDataPluginItem( parent ), m_magnitude( 0.0 ), m_depth( 0.0 )
27 {
28  // The size of an item without a text is 0
29  setSize( QSize( 0, 0 ) );
30  setCacheMode( ItemCoordinateCache );
31 }
32 
33 EarthquakeItem::~EarthquakeItem()
34 {
35  // nothing to do
36 }
37 
38 QString EarthquakeItem::itemType() const
39 {
40  // Our itemType:
41  return "earthquakeItem";
42 }
43 
44 bool EarthquakeItem::initialized() const
45 {
46  return m_magnitude > 0.0;
47 }
48 
49 bool EarthquakeItem::operator<( const AbstractDataPluginItem *other ) const
50 {
51  // Larger magnitude first
52  const EarthquakeItem* item = dynamic_cast<const EarthquakeItem*>( other );
53  return item ? magnitude() > item->magnitude() : false;
54 }
55 
56 double EarthquakeItem::magnitude() const
57 {
58  return m_magnitude;
59 }
60 
61 void EarthquakeItem::setMagnitude( double magnitude )
62 {
63  m_magnitude = magnitude;
64  setSize( QSize( m_magnitude * 10, m_magnitude * 10 ) );
65  updateTooltip();
66 }
67 
68 void EarthquakeItem::paint( QPainter *painter )
69 {
70  // Save the old painter state.
71  painter->save();
72 
73  // Draw the arch into the given rect.
74  qreal width = magnitude() * 10;
75  qreal height = magnitude() * 10;
76 
77  // Draws the circle with circles' center as rectangle's top-left corner.
78  QRect arcRect( 0, 0, width, height );
79  QColor color = Oxygen::brickRed4;
80  if ( magnitude() < 5.0 ) {
81  color = Oxygen::sunYellow6;
82  } else if ( magnitude() < 6.0 ) {
83  color = Oxygen::hotOrange4;
84  }
85  painter->setPen( QPen( Qt::NoPen ) );
86  QBrush brush( color );
87  brush.setColor( color );
88  painter->setBrush( brush );
89  painter->drawEllipse( arcRect );
90 
91  // Draws the seismograph
92  QSvgRenderer renderer( QString( ":/seismograph.svg" ) );
93  renderer.render( painter, QRectF( 0.0, 0.0, width, height ) );
94 
95  // Draws magnitude of the earthquake
96  QFontMetrics metrics( s_font );
97  QString magnitudeText = QString::number( magnitude() );
98  QRect magnitudeRect = metrics.boundingRect( magnitudeText );
99  painter->setBrush( QBrush() );
100  painter->setPen( QPen() );
101  painter->setFont( s_font );
102  painter->drawText( QPoint( (arcRect.width() - magnitudeRect.width()) / 2, (arcRect.height() - magnitudeRect.height()) / 2 + metrics.ascent() ), magnitudeText );
103 
104  // Restore the old painter state.
105  painter->restore();
106 }
107 
108 void EarthquakeItem::setDateTime( const QDateTime &dateTime )
109 {
110  m_dateTime = dateTime;
111  updateTooltip();
112 }
113 
114 QDateTime EarthquakeItem::dateTime() const
115 {
116  return m_dateTime;
117 }
118 
119 double EarthquakeItem::depth() const
120 {
121  return m_depth;
122 }
123 
124 void EarthquakeItem::setDepth( double depth )
125 {
126  m_depth = depth;
127  updateTooltip();
128 }
129 
130 void EarthquakeItem::updateTooltip()
131 {
132  QString html = "<table cellpadding=\"2\">";
133  if ( m_dateTime.isValid() ) {
134  html += "<tr><td align=\"right\">Date</td>";
135  html += "<td>" + m_dateTime.toString( Qt::SystemLocaleShortDate ) + "</td></tr>";
136  }
137  html += "<tr><td align=\"right\">Magnitude</td><td>" + QString::number( m_magnitude ) + "</td></tr>";
138  html += "<tr><td align=\"right\">Depth</td><td>" + QString::number( m_depth ) + " km</td></tr>";
139  html += "</table>";
140  setToolTip( html );
141 }
142 
143 }
144 
145 #include "EarthquakeItem.moc"
Marble::EarthquakeItem::setDateTime
void setDateTime(const QDateTime &dateTime)
Definition: EarthquakeItem.cpp:108
QPainter
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
Marble::EarthquakeItem::initialized
bool initialized() const
Definition: EarthquakeItem.cpp:44
QObject
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
Marble::EarthquakeItem::magnitude
double magnitude() const
Definition: EarthquakeItem.cpp:56
EarthquakeItem.h
Marble::EarthquakeItem::EarthquakeItem
EarthquakeItem(QObject *parent)
Definition: EarthquakeItem.cpp:25
Marble::EarthquakeItem::paint
void paint(QPainter *painter)
Paints the item in item coordinates.
Definition: EarthquakeItem.cpp:68
Marble::EarthquakeItem::itemType
QString itemType() const
Returns the type of this specific item.
Definition: EarthquakeItem.cpp:38
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
Marble::Oxygen::sunYellow6
QColor const sunYellow6
Definition: MarbleColors.h:78
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::Oxygen::brickRed4
QColor const brickRed4
Definition: MarbleColors.h:32
Marble::MarbleGraphicsItem::setCacheMode
void setCacheMode(CacheMode mode)
Set the cache mode of the item.
Definition: MarbleGraphicsItem.cpp:159
Marble::EarthquakeItem::depth
double depth() const
Earthquake's depth in km.
Definition: EarthquakeItem.cpp:119
Marble::EarthquakeItem::~EarthquakeItem
~EarthquakeItem()
Definition: EarthquakeItem.cpp:33
Marble::EarthquakeItem
Definition: EarthquakeItem.h:23
Marble::AbstractDataPluginItem::setToolTip
void setToolTip(const QString &toolTip)
Set the tool tip for the item.
Definition: AbstractDataPluginItem.cpp:76
Marble::EarthquakeItem::operator<
bool operator<(const AbstractDataPluginItem *other) const
Definition: EarthquakeItem.cpp:49
Marble::EarthquakeItem::dateTime
QDateTime dateTime() const
Definition: EarthquakeItem.cpp:114
Marble::EarthquakeItem::setMagnitude
void setMagnitude(double magnitude)
Definition: EarthquakeItem.cpp:61
Marble::EarthquakeItem::setDepth
void setDepth(double depth)
Definition: EarthquakeItem.cpp:124
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:49 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • 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