[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/base/plasma/applets/worldclock
From:       Henry de Valence <hdevalence () gmail ! com>
Date:       2008-01-29 2:03:48
Message-ID: 1201572228.368812.11333.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 767922 by hdevalence:

More work; trying to get it not to update so often

 M  +25 -6     plasmamap.cpp  
 M  +1 -1      plasmamap.h  


--- trunk/playground/base/plasma/applets/worldclock/plasmamap.cpp #767921:767922
@@ -74,14 +74,25 @@
 }
 
 //much of this is based on the mapwidget code
-QPixmap WorldClock::calculatePixmap(const QRect& contentsRect, QPixmap& final)
+void WorldClock::calculatePixmap(const QRect& contentsRect, QPixmap& final)
 {
 	time_t local = time(NULL);
 	struct tm *curtime = gmtime(&local);
-	m_lastTime = curtime->tm_hour*60*60 + curtime->tm_min*60;
 	int sec = curtime->tm_hour*60*60 + curtime->tm_min*60 + curtime->tm_sec;
 	int gmt_position = contentsRect.width() * sec / 86400;
-	int mins = sec - 60;
+
+	if( ( m_lastTime + 600 ) > sec ) {
+		qDebug() << "less than 10 mins since last calculatePixmap()";
+		if( m_lastContentsRect.size() == contentsRect.size() ) {
+			qDebug() << "same size, returning last result";
+			final = m_lastRender;
+			return;
+		} else {
+			qDebug() << "scaling old image to new size";
+			final = final.scaled(contentsRect.size());
+		}
+	}
+
 	qDebug() << "loading theme 'daynight' width=" << contentsRect.width()
 	         << " height=" << contentsRect.height();
 	load( static_cast<unsigned int>(contentsRect.width()),
@@ -109,7 +120,14 @@
 		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);
 	}
-	return final;
+
+	QTime time = QTime::currentTime();
+	p.setPen(Qt::black);
+	p.drawText( 0, (final.height() - 10 ), "last rendered at " + time.toString("hh:mm:ss.zzz") );
+
+	m_lastRender = final;
+	m_lastTime = sec;
+	return;
 }
 
 void WorldClock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option,
@@ -120,11 +138,12 @@
 	p->setRenderHint(QPainter::Antialiasing);
 
 	QPixmap world(contentsRect.size());
-	p->drawPixmap(0,0,calculatePixmap(contentsRect, world) );
+	calculatePixmap(contentsRect, world);
+	p->drawPixmap(0,0, world );
 	m_lastRender = world;
 	QTime time = QTime::currentTime();
 	p->setPen(Qt::white);
-	p->drawText( 0,0, "last updated at " + time.toString("hh:mm:ss.zzz") );
+	p->drawText( 0,0, "last painted at " + time.toString("hh:mm:ss.zzz") );
 }
 
  
--- trunk/playground/base/plasma/applets/worldclock/plasmamap.h #767921:767922
@@ -43,7 +43,7 @@
 		void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data);
  
 	private:
-		QPixmap calculatePixmap(const QRect& contentsRect, QPixmap& final);
+		void calculatePixmap(const QRect& contentsRect, QPixmap& final);
 		void connectToEngine();
 		QTime m_time;
 		int m_lastTime;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic