• 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
  • opencaching
OpenCachingItem.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 2011 Daniel Marth <danielmarth@gmx.at>
9 //
10 
11 #include "OpenCachingItem.h"
12 #include "GeoPainter.h"
13 #include "ViewportParams.h"
14 
15 #include <QFontMetrics>
16 #include <QPixmap>
17 
18 #include "ui_OpenCachingCacheDialog.h"
19 
20 namespace Marble
21 {
22 
23 // That's the font we will use to paint.
24 QFont OpenCachingItem::s_font = QFont( "Sans Serif", 8 );
25 QPixmap OpenCachingItem::s_icon = QPixmap( "/usr/share/icons/oxygen/32x32/status/folder-open.png" );
26 
27 OpenCachingItem::OpenCachingItem( const OpenCachingCache& cache, QObject *parent )
28  : AbstractDataPluginItem( parent ), m_cache( cache ), m_infoDialog( 0), m_action( new QAction( this ) ), m_logIndex( 0 )
29 {
30  // The size of an item without a text is 0
31  setSize( QSize( m_cache.difficulty() * 10, m_cache.difficulty() * 10 ) );
32  s_font.setBold( true );
33  updateTooltip();
34  setId( QString( "opencache-%1" ).arg( cache.id() ) );
35  setCoordinate( GeoDataCoordinates( cache.longitude(), cache.latitude(), 0.0, GeoDataCoordinates::Degree ) );
36  setTarget( "earth" );
37  connect( m_action, SIGNAL(triggered()),
38  this, SLOT(showInfoDialog()) );
39 }
40 
41 OpenCachingItem::~OpenCachingItem()
42 {
43  // nothing to do
44 }
45 
46 QString OpenCachingItem::itemType() const
47 {
48  // Our itemType:
49  return "OpenCachingItem";
50 }
51 
52 bool OpenCachingItem::initialized()
53 {
54  return m_cache.id() != 0;
55 }
56 
57 void OpenCachingItem::showInfoDialog()
58 {
59  if( !m_infoDialog ) {
60  m_infoDialog = infoDialog();
61  }
62  Q_ASSERT( m_infoDialog );
63  m_infoDialog->show();
64 }
65 
66 QDialog *OpenCachingItem::infoDialog()
67 {
68  if ( !m_infoDialog ) {
69  // Initializing information dialog
70  m_infoDialog = new QDialog();
71  m_ui = new Ui::OpenCachingCacheDialog;
72  m_ui->setupUi( m_infoDialog );
73  m_ui->m_cacheName->setText( m_cache.cacheName() );
74  m_ui->m_country->setText( m_cache.country() );
75  m_ui->m_dateCreated->setText( m_cache.dateCreated().toString( Qt::SystemLocaleShortDate ) );
76  m_ui->m_dateHidden->setText( m_cache.dateHidden().toString( Qt::SystemLocaleShortDate ) );
77  m_ui->m_dateLastModified->setText( m_cache.dateCreated().toString( Qt::SystemLocaleShortDate ) );
78  m_ui->m_difficulty->setText( QString::number( m_cache.difficulty() ) );
79  m_ui->m_latitude->setText( QString::number( m_cache.latitude() ) );
80  m_ui->m_longitude->setText( QString::number( m_cache.longitude() ) );
81  m_ui->m_size->setText( m_cache.sizeString() );
82  m_ui->m_status->setText( m_cache.status() );
83  m_ui->m_terrain->setText( QString::number( m_cache.terrain() ) );
84  m_ui->m_type->setText( m_cache.cacheType() );
85  m_ui->m_userName->setText( m_cache.userName() );
86  QHash<QString, OpenCachingCacheDescription> descriptions = m_cache.description();
87  QStringList languages = descriptions.keys();
88  qSort( languages );
89  m_ui->m_languageBox->addItems( languages );
90  if( descriptions.size() > 0 ) {
91  updateDescriptionLanguage( languages.first() );
92  connect( m_ui->m_languageBox, SIGNAL(currentIndexChanged(QString)),
93  this, SLOT(updateDescriptionLanguage(QString)) );
94  }
95  OpenCachingCacheLog log = m_cache.log();
96  if( log.size() > 0 ) {
97  m_ui->m_logText->setHtml( log[m_logIndex].text() );
98  m_ui->m_logCount->setText( "1 / " + QString::number( log.size() ) );
99  connect( m_ui->m_nextButton, SIGNAL(clicked()),
100  this, SLOT(nextLogEntry()) );
101  connect( m_ui->m_previousButton, SIGNAL(clicked()),
102  this, SLOT(previousLogEntry()) );
103  }
104  if( log.size() > 1 ) {
105  m_ui->m_nextButton->setEnabled( true );
106  }
107  QPushButton *closeButton = m_ui->m_buttonBox->button( QDialogButtonBox::Close );
108  connect( closeButton, SIGNAL(clicked()),
109  m_infoDialog, SLOT(close()) );
110  m_infoDialog->setWindowTitle( m_cache.cacheName() );
111  }
112  return m_infoDialog;
113 }
114 
115 QAction *OpenCachingItem::action()
116 {
117  m_action->setText( m_cache.cacheName() );
118  return m_action;
119 }
120 
121 bool OpenCachingItem::operator<( const AbstractDataPluginItem *other ) const
122 {
123  // FIXME shorter distance to current position?
124  const OpenCachingItem* item = dynamic_cast<const OpenCachingItem*>( other );
125  return item ? m_cache.id() < item->m_cache.id() : false;
126 }
127 
128 void OpenCachingItem::paint( GeoPainter *painter, ViewportParams *viewport,
129  const QString& renderPos, GeoSceneLayer * layer )
130 {
131  Q_UNUSED( viewport )
132  Q_UNUSED( renderPos )
133  Q_UNUSED( layer )
134 
135  // Save the old painter state.
136  painter->save();
137  painter->autoMapQuality();
138 
139  qreal width;
140  qreal height;
141 
142  if( !s_icon.isNull() ) {
143  width = s_icon.width();
144  height = s_icon.height();
145  painter->drawPixmap( 0, 0, s_icon );
146  }
147  else {
148  width = m_cache.difficulty() * 10;
149  height = m_cache.difficulty() * 10;
150  // Draws the circle with circles' center as rectangle's top-left corner.
151  QRect arcRect( 0, 0, width, height );
152  QColor color = Oxygen::brickRed4;
153  if ( m_cache.difficulty() < 2.0 ) {
154  color = Oxygen::sunYellow6;
155  } else if ( m_cache.difficulty() < 4.0 ) {
156  color = Oxygen::hotOrange4;
157  }
158  painter->setPen( QPen( Qt::NoPen ) );
159  QBrush brush( color );
160  brush.setColor( color );
161  painter->setBrush( brush );
162  painter->drawEllipse( arcRect );
163  }
164 
165  // Draws difficulty of the cache
166  QFontMetrics metrics( s_font );
167  QString difficultyText = QString::number( m_cache.difficulty() );
168  QRect difficultyRect = metrics.boundingRect( difficultyText );
169  painter->setBrush( QBrush() );
170  painter->setPen( QPen() );
171  painter->setFont( s_font );
172  painter->drawText( QPoint( (width - difficultyRect.width()) / 2, (height - difficultyRect.height()) / 2 + metrics.ascent() ), difficultyText );
173 
174  // Restore the old painter state.
175  painter->restore();
176 }
177 
178 void OpenCachingItem::updateTooltip()
179 {
180  QString html = "<table cellpadding=\"2\">";
181  if ( m_cache.id() != 0 ) {
182  html += tr( "<tr><td align=\"right\">Cache name</td>" );
183  html += "<td>" + m_cache.cacheName() + "</td></tr>";
184  html += tr( "<tr><td align=\"right\">User name</td><td>" ) + m_cache.userName() + "</td></tr>";
185  if ( !m_cache.cacheName().isEmpty() ) {
186  html += tr( "<tr><td align=\"right\">Date hidden</td><td>" ) + m_cache.dateHidden().toString( Qt::SystemLocaleShortDate ) + "</td></tr>";
187  }
188  html += tr( "<tr><td align=\"right\">Difficulty</td><td>" ) + QString::number( m_cache.difficulty() ) + "</td></tr>";
189  html += tr( "<tr><td align=\"right\">Size</td><td>" ) + m_cache.sizeString() + "</td></tr>";
190  html += "</table>";
191  setToolTip( html );
192  }
193 }
194 
195 void OpenCachingItem::updateDescriptionLanguage( QString language )
196 {
197  QHash<QString, OpenCachingCacheDescription> descriptions = m_cache.description();
198  QString text = descriptions[language].shortDescription() + "\n\n" +
199  descriptions[language].description() + "\n\n" +
200  descriptions[language].hint() + "\n\n";
201  m_ui->m_descriptionText->setHtml( text );
202 }
203 
204 void OpenCachingItem::nextLogEntry()
205 {
206  OpenCachingCacheLog log = m_cache.log();
207  if( m_logIndex + 1 < log.size() ) {
208  m_logIndex++;
209  m_ui->m_logText->setHtml( log[m_logIndex].text() );
210  m_ui->m_logCount->setText( QString::number( m_logIndex + 1 ) + " / " + QString::number( log.size() ) );
211  m_ui->m_previousButton->setEnabled( true );
212  if( m_logIndex == log.size() - 1 ) {
213  m_ui->m_nextButton->setEnabled( false );
214  }
215  }
216 }
217 
218 void OpenCachingItem::previousLogEntry()
219 {
220  OpenCachingCacheLog log = m_cache.log();
221  if( m_logIndex - 1 >= 0 ) {
222  m_logIndex--;
223  m_ui->m_logText->setHtml( log[m_logIndex].text() );
224  m_ui->m_logCount->setText( QString::number( m_logIndex + 1 ) + " / " + QString::number( log.size() ) );
225  m_ui->m_nextButton->setEnabled( true );
226  if( m_logIndex == 0 ) {
227  m_ui->m_previousButton->setEnabled( false );
228  }
229  }
230 }
231 
232 }
233 
234 #include "OpenCachingItem.moc"
QAction::setText
void setText(const QString &text)
QDateTime::toString
QString toString(Qt::DateFormat format) const
Marble::AbstractDataPluginItem::setTarget
void setTarget(const QString &target)
Definition: AbstractDataPluginItem.cpp:66
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
QFontMetrics::ascent
int ascent() const
Marble::OpenCachingItem::initialized
bool initialized()
Definition: OpenCachingItem.cpp:52
Marble::OpenCachingItem::OpenCachingItem
OpenCachingItem(const OpenCachingCache &cache, QObject *parent)
Definition: OpenCachingItem.cpp:27
QPixmap::width
int width() const
Marble::MarbleGraphicsItem::setSize
void setSize(const QSizeF &size)
Set the size of the item.
Definition: MarbleGraphicsItem.cpp:197
Marble::OpenCachingCache
Contains all information about a cache, including logs and descriptions in all available languages...
Definition: OpenCachingCache.h:27
Marble::AbstractDataPluginItem
Definition: AbstractDataPluginItem.h:28
Marble::OpenCachingCache::sizeString
const QString & sizeString() const
Definition: OpenCachingCache.cpp:129
Marble::GeoPainter
A painter that allows to draw geometric primitives on the map.
Definition: GeoPainter.h:98
Marble::OpenCachingCache::status
const QString & status() const
Definition: OpenCachingCache.cpp:109
Marble::OpenCachingItem::paint
void paint(GeoPainter *painter, ViewportParams *viewport, const QString &renderPos, GeoSceneLayer *layer=0)
Definition: OpenCachingItem.cpp:128
QFont
Marble::AbstractDataPluginItem::setId
void setId(const QString &id)
Definition: AbstractDataPluginItem.cpp:86
QHash::size
int size() const
QPainter::save
void save()
Marble::OpenCachingCache::description
const QHash< QString, OpenCachingCacheDescription > & description() const
Definition: OpenCachingCache.cpp:179
Marble::OpenCachingCache::terrain
qreal terrain() const
Definition: OpenCachingCache.cpp:149
Marble::OpenCachingItem::operator<
bool operator<(const AbstractDataPluginItem *other) const
Definition: OpenCachingItem.cpp:121
Marble::OpenCachingCache::country
const QString & country() const
Definition: OpenCachingCache.cpp:119
QBrush
QPoint
QFontMetrics
Marble::GeoPainter::drawEllipse
void drawEllipse(const GeoDataCoordinates &centerPosition, qreal width, qreal height, bool isGeoProjected=false)
Draws an ellipse at the given position. The ellipse is placed with its center located at the given ce...
Definition: GeoPainter.cpp:289
QObject::tr
QString tr(const char *sourceText, const char *disambiguation, int n)
Marble::OpenCachingItem
Item representing a single cache.
Definition: OpenCachingItem.h:33
Marble::GeoDataCoordinates::Degree
Definition: GeoDataCoordinates.h:66
Marble::Oxygen::hotOrange4
QColor const hotOrange4
Definition: MarbleColors.h:86
QFont::setBold
void setBold(bool enable)
QRect
QFontMetrics::boundingRect
QRect boundingRect(QChar ch) const
QPainter::setFont
void setFont(const QFont &font)
QString::number
QString number(int n, int base)
Marble::GeoSceneLayer
Layer of a GeoScene document.
Definition: GeoSceneLayer.h:43
Marble::OpenCachingItem::showInfoDialog
void showInfoDialog()
Definition: OpenCachingItem.cpp:57
Marble::OpenCachingCache::dateHidden
const QDateTime & dateHidden() const
Definition: OpenCachingCache.cpp:49
QHash
Marble::OpenCachingItem::action
QAction * action()
Returns the action of this specific item.
Definition: OpenCachingItem.cpp:115
QObject
QPainter::setPen
void setPen(const QColor &color)
Marble::OpenCachingCache::dateCreated
const QDateTime & dateCreated() const
Definition: OpenCachingCache.cpp:59
QString::isEmpty
bool isEmpty() const
Marble::Oxygen::sunYellow6
QColor const sunYellow6
Definition: MarbleColors.h:78
QPainter::setBrush
void setBrush(const QBrush &brush)
Marble::OpenCachingCache::longitude
qreal longitude() const
Definition: OpenCachingCache.cpp:159
QList::first
T & first()
OpenCachingItem.h
QString
QColor
GeoPainter.h
QStringList
Marble::ViewportParams
A public class that controls what is visible in the viewport of a Marble map.
Definition: ViewportParams.h:44
QHash::keys
QList< Key > keys() const
QPixmap
QPixmap::isNull
bool isNull() const
QSize
QPixmap::height
int height() const
ViewportParams.h
This file contains the headers for ViewportParams.
Marble::OpenCachingCache::log
const OpenCachingCacheLog & log() const
Definition: OpenCachingCache.cpp:189
QPainter::restore
void restore()
Marble::Oxygen::brickRed4
QColor const brickRed4
Definition: MarbleColors.h:32
Marble::GeoPainter::drawText
void drawText(const GeoDataCoordinates &position, const QString &text)
Draws the given text at a given geographic position. The text is drawn starting at the given position...
Definition: GeoPainter.cpp:264
Marble::OpenCachingCache::difficulty
qreal difficulty() const
Definition: OpenCachingCache.cpp:139
Marble::OpenCachingCache::cacheType
const QString & cacheType() const
Definition: OpenCachingCache.cpp:99
QWidget::setWindowTitle
void setWindowTitle(const QString &)
QAction
QPen
QDialog
QPushButton
Marble::OpenCachingCache::cacheName
const QString & cacheName() const
Definition: OpenCachingCache.cpp:89
QWidget::show
void show()
Marble::OpenCachingCache::userName
const QString & userName() const
Definition: OpenCachingCache.cpp:79
Marble::OpenCachingCache::latitude
qreal latitude() const
Definition: OpenCachingCache.cpp:169
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Marble::BillboardGraphicsItem::setCoordinate
void setCoordinate(const GeoDataCoordinates &coordinates)
Definition: BillboardGraphicsItem.cpp:98
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)
Marble::GeoPainter::drawPixmap
void drawPixmap(const GeoDataCoordinates &centerPosition, const QPixmap &pixmap)
Draws a pixmap at the given position. The pixmap is placed with its center located at the given cente...
Definition: GeoPainter.cpp:452
Marble::OpenCachingItem::~OpenCachingItem
~OpenCachingItem()
Definition: OpenCachingItem.cpp:41
Marble::OpenCachingCache::id
unsigned long long id() const
Definition: OpenCachingCache.cpp:39
Marble::OpenCachingItem::itemType
QString itemType() const
Definition: OpenCachingItem.cpp:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 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