/* ** Originally based on the KWorldClock program ** written by Matthias Hölzer-Klüpfel ** Copyright (C) 1998-2001 by Matthias Hölzer-Klüpfel ** ** Copyright (C) 2008 by Henry de Valence ** */ /* ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 3 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program in a file called COPYING; if not, write to ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, ** MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include "plasmamap.h" WorldClock::WorldClock(QObject *parent, const QVariantList &args) : Plasma::Applet(parent, args) { setDrawStandardBackground(true); resize(QSize(400, 200)); m_proxy = new QGraphicsProxyWidget( ); m_map = new MarbleWidget( ); m_proxy->setWidget( m_map ); m_map->setProjection( Equirectangular ); m_map->setGeometry( 0, 0, 400, 200 ); m_map->show(); m_proxy->show(); m_layout = new QGraphicsLinearLayout(); m_layout->addItem( m_proxy ); m_widget = new QGraphicsWidget(this); m_widget->setLayout( m_layout ); m_widget->show(); } WorldClock::~WorldClock() { delete m_proxy; } void WorldClock::connectToEngine() { Plasma::DataEngine* timeEngine = dataEngine("time"); timeEngine->connectSource("Local", this, 6000, Plasma::AlignToMinute); } void WorldClock::init() { } /* void WorldClock::setHovered( bool state ) { m_isHovered = state; update(); } void WorldClock::hoverMoveEvent( QGraphicsSceneHoverEvent * event ) { if(m_lastRender.isNull()) { Applet::hoverMoveEvent( event ); return; } m_isHovered = true; kDebug() << "hoverMoveEvent"; m_hoverPoint = event->pos().toPoint(); m_cityLocation = QPoint(0,0); QString previous = m_currentCity->name(); m_currentCity = m_cityList->getNearestCity(m_contentsRect.width(), m_contentsRect.height(), m_lastGmtPosition, m_hoverPoint.x(), m_hoverPoint.y(), m_cityLocation); Applet::hoverMoveEvent( event ); if( previous != m_currentCity->name() ) update(); //QTimer::singleShot( 3000, this, SLOT( setHovered( false ) ) ); } void WorldClock::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { if(m_lastRender.isNull()) { Applet::hoverEnterEvent(event); return; } m_isHovered = true; kDebug() << "hoverenterevent"; m_hoverPoint = event->pos().toPoint(); m_cityLocation = QPoint(0,0); QString previous = m_currentCity->name(); m_currentCity = m_cityList->getNearestCity(m_contentsRect.width(), m_contentsRect.height(), m_lastGmtPosition, m_hoverPoint.x(), m_hoverPoint.y(), m_cityLocation); Applet::hoverEnterEvent(event); if( previous != m_currentCity->name() ) update(); //QTimer::singleShot( 3000, this, SLOT( setHovered( false ) ) ); } void WorldClock::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { if(m_lastRender.isNull()) { Applet::hoverLeaveEvent(event); return; } m_isHovered = false; kDebug() << "hoverleaveevent"; m_hoverPoint = QPoint(0,0); Applet::hoverLeaveEvent(event); update(); } */ void WorldClock::dataUpdated(const QString &name, const Plasma::DataEngine::Data &data) { /* m_time = data["Time"].toTime(); if ( m_nextRenderTime <= m_time ) { m_nextRenderTime = m_time.addSecs( 10 * 60 ); calculatePixmap(); } */ update(); } /* //much of this is based on the mapwidget code void WorldClock::calculatePixmap() { time_t local = time(NULL); struct tm *curtime = gmtime(&local); int sec = curtime->tm_hour*60*60 + curtime->tm_min*60 + curtime->tm_sec; int gmt_position = m_contentsRect.width() * sec / 86400; m_lastGmtPosition = gmt_position; kDebug() << "loading theme 'daynight' width=" << m_contentsRect.width() << " height=" << m_contentsRect.height(); MapLoader::load(static_cast(m_contentsRect.width()), "daynight", static_cast(m_contentsRect.height())); QPixmap map = darkMap(); QPixmap clean = lightMap(); kDebug() << "m_contentsRect = " << m_contentsRect.size(); kDebug() << "QPixmap map = " << map.size(); kDebug() << "QPixmap clean = " << clean.size(); QPainter mp(&map); clean.setAlphaChannel(darkMask(map.width(), map.height())); mp.drawPixmap(0,0, clean); if (m_lastRender.isNull() ) { m_lastRender = QPixmap( m_contentsRect.size() ); } QPainter p(&m_lastRender); int greenwich = map.width()/2; if (gmt_position >= greenwich) { p.drawPixmap(gmt_position-greenwich, 0, map); p.drawPixmap(0, 0, map, map.width()-gmt_position+greenwich, 0, gmt_position-greenwich, -1); } else { p.drawPixmap(0,0, map, greenwich-gmt_position, 0, map.width()+gmt_position-greenwich, -1); p.drawPixmap(map.width()+gmt_position-greenwich, 0, map, 0, 0, greenwich-gmt_position, -1); } kDebug() << "made new rendering at " << QTime::currentTime() ; return; } */ void WorldClock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect) { /* //Something like this to keep a constant shape ?? if( ( contentsRect.width() / contentsRect.height() ) != 0.5 ) { if( ( contentsRect.width() / contentsRect.height() ) > 0.5 ) { contentsRect.setHeight( ( contentsRect.width() / 2 ) ); } else { contentsRect.setWidth( ( contentsRect.height() / 2 ) ); } } */ /* kDebug() << "updating.."; p->setRenderHint(QPainter::SmoothPixmapTransform); p->setRenderHint(QPainter::Antialiasing); if ( m_map->size() != contentsRect.size() ) { m_map->setGeometry( 0, 0, contentsRect.width(), contentsRect.height() ); } */ /* QTime time = QTime::currentTime(); p->setPen(Qt::white); p->drawText( 0,0, "last painted at " + time.toString("hh:mm:ss.zzz") ); */ } //originally MapWidget::cityTime(const QString &city) /* This needs to be replaced with something else, * because I think that it's not platform-independent * at all. I don't know what the best way to fix the * problem is though. */ /* QString WorldClock::cityTime(const QString &city) { QString result = i18n(city.toLatin1()); // Time zone translation int pos = result.indexOf('/'); if (pos >= 0) result = result.mid(pos+1); result.replace(QRegExp("_"), " "); result.append(": "); char *initial_TZ = getenv("TZ"); setenv("TZ", city.toLatin1(), 1); tzset(); time_t t = time(NULL); QDateTime dt; dt.setTime_t(t); result.append(QString("%1, %2").arg( KGlobal::locale()->formatTime(dt.time(), true) ).arg( KGlobal::locale()->formatDate(dt.date(), KLocale::ShortDate)) ); if (initial_TZ != 0) setenv("TZ", initial_TZ, 1); else unsetenv("TZ"); tzset(); return result; } */ #include "plasmamap.moc"