22 #include <QRadialGradient>
24 #include <QGraphicsSceneHoverEvent>
35 #include <KConfigDialog>
36 #include <KConfigGroup>
38 #include <KTimeZoneWidget>
39 #include <KSystemTimeZone>
42 #include <Plasma/Applet>
43 #include <Plasma/DataEngine>
59 : Plasma::Applet(parent, args),
66 KGlobal::locale()->insertCatalog(
"marble");
67 KGlobal::locale()->insertCatalog(
"marble_qt");
68 KGlobal::locale()->insertCatalog(
"timezones4");
69 setHasConfigurationInterface(
true);
70 setAcceptHoverEvents(
true);
78 KConfigGroup cg = config();
82 m_map->
centerOn( cg.readEntry(
"rotation", -20), 0 );
109 m_customTz = cg.readEntry(
"customtz",
false );
110 m_locationkey = KSystemTimeZones::local().name();
114 foreach(
const QString& tzname, tzlist ) {
115 m_locations.
insert(tzname, KSystemTimeZones::zone(tzname));
117 if(!m_locations.
contains(m_locationkey))
118 m_locationkey = m_locations.
keys().first();
120 m_locations = KSystemTimeZones::zones();
122 for (
int i = 0; i < zones.
size(); ++i ) {
123 KTimeZone curzone = m_locations.
value( zones.
at( i ) );
124 if ( curzone.latitude() == KTimeZone::UNKNOWN ||
125 curzone.longitude() == KTimeZone::UNKNOWN ) {
132 m_timeFont =
QFont(
"Helvetica", 12, QFont::Bold);
133 m_locationFont =
QFont(
"Helvetica", 12, QFont::Bold);
135 m_lastRect =
QRect(0,0,0,0);
136 m_showDate = cg.readEntry(
"showdate",
false);
140 Plasma::DataEngine *m_timeEngine = dataEngine(
"time");
141 m_timeEngine->connectSource(
"Local",
this, 6000, Plasma::AlignToMinute);
143 connect(m_map, SIGNAL(repaintNeeded(
QRegion)),
this, SLOT(slotRepaint()));
151 void WorldClock::resizeMap(
bool changeAspect)
156 double ratio =
static_cast<double>(m_lastRect.
width()) /
157 static_cast<double>(m_lastRect.
height());
159 kDebug() <<
"equirectangular with rect" << m_lastRect;
160 kDebug() <<
"w/h ratio:" << ratio;
162 height = m_lastRect.
height();
164 radius =
static_cast<int>(height/2);
166 width = m_lastRect.
width();
167 height =
static_cast<int>(width/2);
168 radius =
static_cast<int>(width/4);
171 kDebug() <<
"mercator with rect" << m_lastRect;
172 kDebug() <<
"w/h ratio:" << ratio;
174 height = m_lastRect.
height();
176 radius =
static_cast<int>(width/4);
178 width = m_lastRect.
width();
180 radius =
static_cast<int>(width/4);
183 kDebug() <<
"width, height, radius:" << width << height <<
radius;
189 QRectF curGeo = geometry();
190 setGeometry( curGeo.
x(), curGeo.
y(),
static_cast<double>(width),
191 static_cast<double>(height) );
195 void WorldClock::slotRepaint()
201 const Plasma::DataEngine::Data &data)
206 m_time = KSystemTimeZones::local().convert(m_locations.
value(m_locationkey),
215 Applet::hoverLeaveEvent(event);
221 m_hover =
event->pos() - m_t;
222 Applet::hoverEnterEvent(event);
228 m_hover =
event->pos() - m_t;
229 Applet::hoverMoveEvent(event);
238 bool ok = !m_hover.
isNull() &&
242 return KSystemTimeZones::local().name();
247 qreal mindist = 99999999999999999.9;
249 for (
int i = 0; i < zones.
size(); ++i ) {
250 KTimeZone cz = m_locations.
value( zones.
at( i ) );
251 qreal dist = sqrt( pow(lat-cz.latitude(), 2) + pow(lon-cz.longitude(), 2) );
252 if ( dist < mindist ) {
254 closest = zones.
at( i );
257 return m_locations.
value( closest ).name();
260 void WorldClock::setTz(
QString newtz )
262 if ( newtz == m_locationkey ) {
return; }
263 m_locationkey = newtz;
264 m_time = KSystemTimeZones::local().convert(m_locations.
value(m_locationkey),
269 void WorldClock::recalculatePoints()
271 int x = m_map->
width();
273 m_points.
insert(
"topright",
QPoint( ( x*0.666 ), ( y*0.25 ) ) );
274 m_points.
insert(
"topleft",
QPoint( ( x*0.333 ), ( y*0.25 ) ) );
275 m_points.
insert(
"middleright",
QPoint( ( x*0.666 ), ( y*0.58333 ) ) );
276 m_points.
insert(
"middleleft",
QPoint( ( x*0.333 ), ( y*0.58333 ) ) );
277 m_points.
insert(
"bottomright",
QPoint( ( x*0.666 ), ( y*0.75 ) ) );
278 m_points.
insert(
"bottomleft",
QPoint( ( x*0.333 ), ( y*0.75 ) ) );
283 void WorldClock::recalculateFonts( )
287 timestr = KGlobal::locale()->formatDateTime( m_time );
289 timestr = KGlobal::locale()->formatTime( m_time.
time() );
293 QRect timeRect( m_points.
value(
"topleft" ), m_points.
value(
"middleright" ) );
294 QRect locationRect( m_points.
value(
"middleleft" ), m_points.
value(
"bottomright" ) );
296 m_locationFont = calculateFont(locstr, locationRect);
297 m_timeFont = calculateFont(timestr, timeRect);
302 QFont resultFont(
"Helvetica", 3, QFont::Bold);
308 for (
int curSize = resultFont.pointSize()+1; unscaled<100; ++curSize ) {
309 resultFont.setPointSize(curSize);
311 QRect rect = metrics.boundingRect( text );
328 resultFont.setPointSize(resultFont.pointSize()-1);
332 void WorldClock::recalculateTranslation()
334 m_t =
QPoint(static_cast<int>( (m_lastRect.
width()/2) - (m_map->
width()/2) ),
335 static_cast<int>( (m_lastRect.
height()/2) - (m_map->
height()/2) ));
341 const QRect &contentsRect)
344 if ( contentsRect != m_lastRect ) {
345 m_lastRect = contentsRect;
347 recalculateTranslation();
357 pixmap.
fill( Qt::transparent );
361 m_map->
paint(gp, mapRect );
364 if ( !m_isHovered ) {
365 setTz( KSystemTimeZones::local().name() );
371 qreal lon = m_locations.
value(m_locationkey).longitude() *
DEG2RAD;
372 qreal lat = m_locations.
value(m_locationkey).latitude() *
DEG2RAD;
377 int radius = m_lastRect.
width() / 40;
394 timestr = KGlobal::locale()->formatDateTime( m_time );
396 timestr = KGlobal::locale()->formatTime( m_time.
time() );
400 m_points.
value(
"middleright" ) + m_t ),
401 Qt::AlignCenter, timestr );
405 m_points.
value(
"bottomright" ) + m_t ),
406 Qt::AlignCenter, locstr );
413 parent->setButtons(KDialog::Ok | KDialog::Apply | KDialog::Cancel);
415 KConfigGroup cg = config();
417 ui.longitudeEdit->setValue(cg.readEntry(
"rotation", -20));
420 ui.projection->setCurrentIndex(1);
422 ui.projection->setCurrentIndex(0);
424 if(cg.readEntry(
"daylight",
false ))
425 ui.daylightButton->setChecked(
true);
427 if(cg.readEntry(
"showdate",
false ))
428 ui.showdate->setChecked(
true);
430 if(cg.readEntry(
"customtz",
false ))
431 ui.customTz->setChecked(
true);
433 ui.tzWidget->setSelectionMode( QTreeView::MultiSelection );
434 foreach(
const QString& tz, cg.readEntry(
"tzlist")) {
435 ui.tzWidget->setSelected(tz,
true);
438 connect(parent, SIGNAL(okClicked()),
this, SLOT(
configAccepted()));
439 connect(parent, SIGNAL(applyClicked()),
this, SLOT(
configAccepted()));
440 parent->addPage(widget, parent->
windowTitle(), icon());
445 KConfigGroup cg = config();
447 if( ui.daylightButton->isChecked() )
450 m_map->
centerOn(ui.longitudeEdit->value(), 0);
454 m_showDate = ui.showdate->isChecked();
455 m_customTz = ui.customTz->isChecked();
459 kDebug() <<
"\tSetting TZLIST";
462 selectedZones.
insert(KSystemTimeZones::local().name(),
463 KSystemTimeZones::local());
464 foreach(
const QString& tzname, tzlist ) {
465 selectedZones.
insert(tzname, KSystemTimeZones::zone(tzname));
467 cg.writeEntry(
"tzlist",tzlist);
468 m_locations = selectedZones;
469 if(!m_locations.
contains(m_locationkey))
470 m_locationkey = m_locations.
keys().first();
474 if((ui.projection->currentIndex() + 1) != cg.readEntry(
"projection",
477 switch ( ui.projection->currentIndex() ) {
483 cg.writeEntry(
"projection", static_cast<int>(
Mercator));
496 cg.writeEntry(
"rotation", ui.longitudeEdit->value());
497 cg.writeEntry(
"centersun", ui.daylightButton->isChecked());
498 cg.writeEntry(
"showdate", ui.showdate->isChecked());
499 cg.writeEntry(
"customtz", ui.customTz->isChecked());
501 emit configNeedsSaving();
506 #include "worldclock.moc"
WorldClock(QObject *parent, const QVariantList &args)
QPixmap resize(const QPixmap &pixmap)
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
void setLockToSubSolarPoint(bool visible)
Set the globe locked to the sub solar point.
void setRenderHint(RenderHint hint, bool on)
void fill(const QColor &color)
bool geoCoordinates(const int x, const int y, qreal &lon, qreal &lat, GeoDataCoordinates::Unit unit=GeoDataCoordinates::Degree) const
Get the earth coordinates corresponding to a pixel in the map.
A painter that allows to draw geometric primitives on the map.
void setColorAt(qreal position, const QColor &color)
This file contains the headers for MarbleModel.
const T & at(int i) const
void setSubSolarPointIconVisible(bool visible)
Set whether the sun icon is shown in the sub solar point.
QString & remove(int position, int n)
ViewportParams * viewport()
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
MarbleModel * model() const
Return the model that this view shows.
void setMapThemeId(const QString &maptheme)
Set a new map theme.
QList< Key > keys() const
Flat projection ("plate carree")
void setFont(const QFont &font)
This file contains the headers for MarbleMap.
void setSize(int width, int height)
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void setShowCompass(bool visible)
Set whether the compass overlay is visible.
void setShowPlaces(bool visible)
Set whether the place mark overlay is visible.
void setPen(const QColor &color)
void drawEllipse(const QRectF &rectangle)
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
static qreal radius(qreal zoom)
void setRadius(int radius)
Set the radius of the globe in pixels.
void setBrush(const QBrush &brush)
void drawText(const QPointF &position, const QString &text)
bool screenCoordinates(const qreal lon, const qreal lat, qreal &x, qreal &y) const
Get the screen coordinates corresponding to geographical coordinates in the map.
void setVisible(bool visible)
settting visible
void paint(GeoPainter &painter, const QRect &dirtyRect)
Paint the map using a give painter.
void setClockDateTime(const QDateTime &datetime)
void setShowSunShading(bool visible)
Set whether the night shadow is visible.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QList< RenderPlugin * > renderPlugins() const
Returns a list of all RenderPlugins in the model, this includes float items.
A class that can paint a view of the earth.
void setProjection(Projection projection)
Set the Projection used for the map.
const T value(const Key &key) const
void setShowTerrain(bool visible)
Set whether the terrain place mark overlay is visible.
void createConfigurationInterface(KConfigDialog *parent)
This file contains the headers for ViewportParams.
void setShowClouds(bool visible)
Set whether the cloud cover is visible.
void setShowGrid(bool visible)
Set whether the coordinate grid overlay is visible.
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
void setShowOtherPlaces(bool visible)
Set whether the other places overlay is visible.
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
Projection projection() const
Get the Projection used for the map.
iterator insert(const Key &key, const T &value)
void centerOn(const qreal lon, const qreal lat)
Center the view on a geographical point.
void setShowCityLights(bool visible)
Set whether city lights instead of night shadow are visible.
The abstract class that creates a renderable item.
QDateTime currentDateTimeUtc()
void setShowCities(bool visible)
Set whether the city place mark overlay is visible.
const T value(const Key &key) const
int remove(const Key &key)
void setShowScaleBar(bool visible)
Set whether the scale bar overlay is visible.
QByteArray toUtf8() const