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

marble

  • sources
  • kde-4.14
  • 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 bool EarthquakeItem::initialized() const
39 {
40  return m_magnitude > 0.0;
41 }
42 
43 bool EarthquakeItem::operator<( const AbstractDataPluginItem *other ) const
44 {
45  // Larger magnitude first
46  const EarthquakeItem* item = dynamic_cast<const EarthquakeItem*>( other );
47  return item ? magnitude() > item->magnitude() : false;
48 }
49 
50 double EarthquakeItem::magnitude() const
51 {
52  return m_magnitude;
53 }
54 
55 void EarthquakeItem::setMagnitude( double magnitude )
56 {
57  m_magnitude = magnitude;
58  setSize( QSize( m_magnitude * 10, m_magnitude * 10 ) );
59  updateTooltip();
60 }
61 
62 void EarthquakeItem::paint( QPainter *painter )
63 {
64  // Save the old painter state.
65  painter->save();
66 
67  // Draw the arch into the given rect.
68  qreal width = magnitude() * 10;
69  qreal height = magnitude() * 10;
70 
71  // Draws the circle with circles' center as rectangle's top-left corner.
72  QRect arcRect( 0, 0, width, height );
73  QColor color = Oxygen::brickRed4;
74  if ( magnitude() < 5.0 ) {
75  color = Oxygen::sunYellow6;
76  } else if ( magnitude() < 6.0 ) {
77  color = Oxygen::hotOrange4;
78  }
79  painter->setPen( QPen( Qt::NoPen ) );
80  QBrush brush( color );
81  brush.setColor( color );
82  painter->setBrush( brush );
83  painter->drawEllipse( arcRect );
84 
85  // Draws the seismograph
86  QSvgRenderer renderer( QString( ":/seismograph.svg" ) );
87  renderer.render( painter, QRectF( 0.0, 0.0, width, height ) );
88 
89  // Draws magnitude of the earthquake
90  QFontMetrics metrics( s_font );
91  QString magnitudeText = QString::number( magnitude() );
92  QRect magnitudeRect = metrics.boundingRect( magnitudeText );
93  painter->setBrush( QBrush() );
94  painter->setPen( QPen() );
95  painter->setFont( s_font );
96  painter->drawText( QPoint( (arcRect.width() - magnitudeRect.width()) / 2, (arcRect.height() - magnitudeRect.height()) / 2 + metrics.ascent() ), magnitudeText );
97 
98  // Restore the old painter state.
99  painter->restore();
100 }
101 
102 void EarthquakeItem::setDateTime( const QDateTime &dateTime )
103 {
104  m_dateTime = dateTime;
105  updateTooltip();
106 }
107 
108 QDateTime EarthquakeItem::dateTime() const
109 {
110  return m_dateTime;
111 }
112 
113 double EarthquakeItem::depth() const
114 {
115  return m_depth;
116 }
117 
118 void EarthquakeItem::setDepth( double depth )
119 {
120  m_depth = depth;
121  updateTooltip();
122 }
123 
124 void EarthquakeItem::updateTooltip()
125 {
126  QString html = "<table cellpadding=\"2\">";
127  if ( m_dateTime.isValid() ) {
128  html += "<tr><td align=\"right\">Date</td>";
129  html += "<td>" + m_dateTime.toString( Qt::SystemLocaleShortDate ) + "</td></tr>";
130  }
131  html += "<tr><td align=\"right\">Magnitude</td><td>" + QString::number( m_magnitude ) + "</td></tr>";
132  html += "<tr><td align=\"right\">Depth</td><td>" + QString::number( m_depth ) + " km</td></tr>";
133  html += "</table>";
134  setToolTip( html );
135 }
136 
137 }
138 
139 #include "EarthquakeItem.moc"
Marble::EarthquakeItem::setDateTime
void setDateTime(const QDateTime &dateTime)
Definition: EarthquakeItem.cpp:102
QDateTime::toString
QString toString(Qt::DateFormat format) const
QFontMetrics::ascent
int ascent() const
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
QSvgRenderer::render
void render(QPainter *painter)
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
QFont
QSvgRenderer
QPainter::save
void save()
Marble::EarthquakeItem::initialized
bool initialized() const
Definition: EarthquakeItem.cpp:38
QRect::height
int height() const
QBrush
QPoint
QFontMetrics
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
Marble::EarthquakeItem::magnitude
double magnitude() const
Definition: EarthquakeItem.cpp:50
QRect
QFontMetrics::boundingRect
QRect boundingRect(QChar ch) const
QPainter::setFont
void setFont(const QFont &font)
EarthquakeItem.h
QString::number
QString number(int n, int base)
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:62
QObject
QPainter::setPen
void setPen(const QColor &color)
QPainter::drawEllipse
void drawEllipse(const QRectF &rectangle)
QPainter
Marble::MarbleGraphicsItem::ItemCoordinateCache
Definition: MarbleGraphicsItem.h:41
Marble::Oxygen::sunYellow6
QColor const sunYellow6
Definition: MarbleColors.h:78
QPainter::setBrush
void setBrush(const QBrush &brush)
QPainter::drawText
void drawText(const QPointF &position, const QString &text)
QString
QColor
QSize
ViewportParams.h
This file contains the headers for ViewportParams.
QDateTime::isValid
bool isValid() const
QPainter::restore
void restore()
Marble::Oxygen::brickRed4
QColor const brickRed4
Definition: MarbleColors.h:32
QRect::width
int width() const
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:113
QRectF
Marble::EarthquakeItem::~EarthquakeItem
~EarthquakeItem()
Definition: EarthquakeItem.cpp:33
QPen
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
QBrush::setColor
void setColor(const QColor &color)
QDateTime
Marble::EarthquakeItem::operator<
bool operator<(const AbstractDataPluginItem *other) const
Definition: EarthquakeItem.cpp:43
Marble::EarthquakeItem::dateTime
QDateTime dateTime() const
Definition: EarthquakeItem.cpp:108
Marble::EarthquakeItem::setMagnitude
void setMagnitude(double magnitude)
Definition: EarthquakeItem.cpp:55
Marble::EarthquakeItem::setDepth
void setDepth(double depth)
Definition: EarthquakeItem.cpp:118
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:38 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
  • 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