[Marble-commits] KDE/kdeedu/marble/src
Bastian Holst
bastianholst at gmx.de
Sun Aug 2 08:16:17 CEST 2009
SVN commit 1005786 by bholst:
Introducing ToolTips for Marble's Online Services. Episode 2: Wikipedia Plugin.
M +1 -1 lib/MarbleWidgetInputHandler.cpp
M +9 -0 lib/graphicsview/MarbleGraphicsItem.cpp
M +5 -0 lib/graphicsview/MarbleGraphicsItem.h
M +19 -1 plugins/render/wikipedia/GeonamesParser.cpp
M +1 -0 plugins/render/wikipedia/GeonamesParser.h
M +34 -0 plugins/render/wikipedia/WikipediaItem.cpp
M +8 -0 plugins/render/wikipedia/WikipediaItem.h
--- trunk/KDE/kdeedu/marble/src/lib/MarbleWidgetInputHandler.cpp #1005785:1005786
@@ -178,7 +178,7 @@
QToolTip::showText( m_widget->mapToGlobal( m_toolTipPosition ),
m_lastToolTipItem->toolTip(),
m_widget,
- m_widget->geometry() );
+ m_lastToolTipItem->containsRect( m_toolTipPosition ).toRect() );
}
}
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsItem.cpp #1005785:1005786
@@ -134,6 +134,15 @@
return false;
}
+QRectF MarbleGraphicsItem::containsRect( const QPointF& point ) const
+{
+ foreach( const QRectF& rect, d->boundingRects() ) {
+ if( rect.contains( point ) )
+ return rect;
+ }
+ return QRectF();
+}
+
QSizeF MarbleGraphicsItem::size() const
{
return p()->m_size;
--- trunk/KDE/kdeedu/marble/src/lib/graphicsview/MarbleGraphicsItem.h #1005785:1005786
@@ -59,6 +59,11 @@
* Returns true if the Item contains @p point in parent coordinates.
*/
bool contains( const QPointF& point ) const;
+
+ /**
+ * Returns the rect of one represenation of the object that is at the given position.
+ */
+ QRectF containsRect( const QPointF& point ) const;
/**
* Returns the size of the item
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/GeonamesParser.cpp #1005785:1005786
@@ -100,6 +100,8 @@
readLatitude( item );
else if( name() == "wikipediaUrl" )
readUrl( item );
+ else if( name() == "summary" )
+ readSummary( item );
else if( name() == "thumbnailImg" )
readThumbnailImage( item );
else
@@ -119,7 +121,7 @@
break;
if( isCharacters() ) {
- item->setId( text().toString() );
+ item->setName( text().toString() );
}
}
}
@@ -172,6 +174,22 @@
}
}
+void GeonamesParser::readSummary( WikipediaItem *item ) {
+ Q_ASSERT( isStartElement()
+ && name() == "summary" );
+
+ while( !atEnd() ) {
+ readNext();
+
+ if( isEndElement() )
+ break;
+
+ if( isCharacters() ) {
+ item->setSummary( text().toString() );
+ }
+ }
+}
+
void GeonamesParser::readThumbnailImage( WikipediaItem *item ) {
Q_ASSERT( isStartElement()
&& name() == "thumbnailImg" );
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/GeonamesParser.h #1005785:1005786
@@ -37,6 +37,7 @@
void readLongitude( WikipediaItem *item );
void readLatitude( WikipediaItem *item );
void readUrl( WikipediaItem *item );
+ void readSummary( WikipediaItem *item );
void readThumbnailImage( WikipediaItem *item );
QList<WikipediaItem *> *m_list;
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/WikipediaItem.cpp #1005785:1005786
@@ -50,6 +50,11 @@
return id();
}
+void WikipediaItem::setName( const QString& name ) {
+ setId( name );
+ updateToolTip();
+}
+
QString WikipediaItem::itemType() const {
return "wikipediaItem";
}
@@ -134,6 +139,15 @@
m_thumbnailImageUrl = thumbnailImageUrl;
}
+QString WikipediaItem::summary() {
+ return m_summary;
+}
+
+void WikipediaItem::setSummary( const QString& summary ) {
+ m_summary = summary;
+ updateToolTip();
+}
+
QAction *WikipediaItem::action() {
m_action->setText( id() );
return m_action;
@@ -161,6 +175,7 @@
if ( settings != m_settings ) {
m_settings = settings;
updateSize();
+ updateToolTip();
update();
}
}
@@ -174,6 +189,25 @@
}
}
+void WikipediaItem::updateToolTip() {
+ QString toolTip;
+ toolTip += "<html><head><meta name=\"qrichtext\" content=\"1\" />";
+ toolTip += "<style type=\"text/css\">\\np, li { white-space: pre-wrap; }\\n</style></head>";
+ toolTip += "<body style=\" font-family:'Sans Serif'; font-size:9pt; font-weight:400; ";
+ toolTip += "font-style:normal;\"><p style=\" margin-top:0px; margin-bottom:0px; ";
+ toolTip += "margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">";
+ if ( summary().isEmpty() ) {
+ toolTip += "%1";
+ }
+ else {
+ toolTip += tr( "%1:<br>%2", "Title:\nSummary" );
+ }
+
+ toolTip += "</p></body></html>\n";
+
+ setToolTip( toolTip.arg( name() ).arg( summary() ) );
+}
+
bool WikipediaItem::showThumbnail() {
return m_settings.value( "showThumbnails", false ).toBool() && !m_thumbnail.isNull();
}
--- trunk/KDE/kdeedu/marble/src/plugins/render/wikipedia/WikipediaItem.h #1005785:1005786
@@ -32,6 +32,8 @@
~WikipediaItem();
QString name() const;
+
+ void setName( const QString& name );
QString itemType() const;
@@ -59,6 +61,10 @@
QUrl thumbnailImageUrl();
void setThumbnailImageUrl( const QUrl& thumbnailImageUrl );
+
+ QString summary();
+
+ void setSummary( const QString& summary );
QAction *action();
@@ -71,10 +77,12 @@
private:
void updateSize();
+ void updateToolTip();
bool showThumbnail();
QUrl m_url;
QUrl m_thumbnailImageUrl;
+ QString m_summary;
QWebView *m_browser;
QAction *m_action;
More information about the Marble-commits
mailing list