[Marble-commits] KDE/kdeedu/marble/src/plugins/render/earthquake
Dennis Nienhüser
earthwings at gentoo.org
Sun Dec 26 00:01:13 CET 2010
SVN commit 1209222 by nienhueser:
Use three different colors to indicate magnitude ranges instead of a gradient. This is easier to distinguish. Show some information (magnitude, depth, date) in a tooltip.
M +48 -10 EarthquakeItem.cpp
M +15 -0 EarthquakeItem.h
M +6 -0 EarthquakeModel.cpp
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakeItem.cpp #1209221:1209222
@@ -23,10 +23,11 @@
QFont EarthquakeItem::s_font = QFont( "Sans Serif", 8 );
EarthquakeItem::EarthquakeItem( QObject *parent )
- : AbstractDataPluginItem( parent ), m_magnitude( 0.0 )
+ : AbstractDataPluginItem( parent ), m_magnitude( 0.0 ), m_depth( 0.0 )
{
// The size of an item without a text is 0
setSize( QSize( 0, 0 ) );
+ s_font.setBold( true );
}
EarthquakeItem::~EarthquakeItem()
@@ -60,6 +61,8 @@
void EarthquakeItem::setMagnitude( double magnitude )
{
m_magnitude = magnitude;
+ setSize( QSize( m_magnitude * 10, m_magnitude * 10 ) );
+ updateTooltip();
}
void EarthquakeItem::paint( GeoPainter *painter, ViewportParams *viewport,
@@ -79,16 +82,15 @@
// Draws the circle with circles' center as rectangle's top-left corner.
QRect arcRect( width / -2, height / -2, width, height );
- QRadialGradient gradient( 0, 0, width / 2 );
- QColor outerRed = oxygenBrickRed4;
- outerRed.setAlpha( 200 );
- gradient.setColorAt( 0.0, outerRed );
- QColor innerRed = oxygenBrickRed4;
- innerRed.setAlpha( 100 );
- gradient.setColorAt( 1.0, innerRed );
+ QColor color = oxygenBrickRed4;
+ if ( magnitude() < 5.0 ) {
+ color = oxygenSunYellow6;
+ } else if ( magnitude() < 6.0 ) {
+ color = oxygenHotOrange4;
+ }
painter->setPen( QPen( Qt::NoPen ) );
- QBrush brush( gradient );
- brush.setColor( oxygenBrickRed4 );
+ QBrush brush( color );
+ brush.setColor( color );
painter->setBrush( brush );
painter->drawEllipse( arcRect );
@@ -108,12 +110,48 @@
QRect magnitudeRect = metrics.boundingRect( magnitudeText );
painter->setBrush( QBrush() );
painter->setPen( QPen() );
+ painter->setFont( s_font );
painter->drawText( QPoint( magnitudeRect.width() / -2, magnitudeRect.height() / 2 ), magnitudeText );
// Restore the old painter state.
painter->restore();
}
+void EarthquakeItem::setDateTime( const QDateTime &dateTime )
+{
+ m_dateTime = dateTime;
+ updateTooltip();
}
+QDateTime EarthquakeItem::dateTime() const
+{
+ return m_dateTime;
+}
+
+double EarthquakeItem::depth() const
+{
+ return m_depth;
+}
+
+void EarthquakeItem::setDepth( double depth )
+{
+ m_depth = depth;
+ updateTooltip();
+}
+
+void EarthquakeItem::updateTooltip()
+{
+ QString html = "<table cellpadding=\"2\">";
+ if ( m_dateTime.isValid() ) {
+ html += "<tr><td align=\"right\">Date</td>";
+ html += "<td>" + m_dateTime.toString( Qt::SystemLocaleShortDate ) + "</td></tr>";
+ }
+ html += "<tr><td align=\"right\">Magnitude</td><td>" + QString::number( m_magnitude ) + "</td></tr>";
+ html += "<tr><td align=\"right\">Depth</td><td>" + QString::number( m_depth ) + " km</td></tr>";
+ html += "</table>";
+ setToolTip( html );
+}
+
+}
+
#include "EarthquakeItem.moc"
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakeItem.h #1209221:1209222
@@ -48,9 +48,24 @@
void setMagnitude( double magnitude );
+ void setDateTime( const QDateTime &dateTime );
+
+ QDateTime dateTime() const;
+
+ /** Earthquake's depth in km */
+ double depth() const;
+
+ void setDepth( double depth );
+
private:
+ void updateTooltip();
+
double m_magnitude;
+ double m_depth;
+
+ QDateTime m_dateTime;
+
static QFont s_font;
QPixmap m_seismograph;
--- trunk/KDE/kdeedu/marble/src/plugins/render/earthquake/EarthquakeModel.cpp #1209221:1209222
@@ -73,6 +73,9 @@
double longitude = iterator.value().property( "lng" ).toNumber();
double latitude = iterator.value().property( "lat" ).toNumber();
double magnitude = iterator.value().property( "magnitude" ).toNumber();
+ QString data = iterator.value().property( "datetime" ).toString();
+ QDateTime date = QDateTime::fromString( data, "yyyy-MM-dd hh:mm:ss" );
+ double depth = iterator.value().property( "depth" ).toNumber();
if( !itemExists( eqid ) ) {
// If it does not exists, create it
@@ -82,6 +85,9 @@
item->setCoordinate( coordinates );
item->setTarget( "earth" );
item->setMagnitude( magnitude );
+ item->setDateTime( date );
+ item->setDepth( depth );
+
addItemToList( item );
}
}
More information about the Marble-commits
mailing list