kalzium
didyouknow.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "didyouknow.h"
00014
00015 #include <QDebug>
00016 #include <QPainter>
00017 #include <QPen>
00018
00019 KalziumDidyouknow::KalziumDidyouknow(QObject *parent, const QVariantList &args)
00020 : Plasma::Applet(parent, args)
00021 {
00022 m_theme.setImagePath("widgets/chalkboard");
00023
00024 m_random = new KRandomSequence( QDateTime::currentDateTime().toTime_t() );
00025
00026 m_engine = dataEngine("kalzium");
00027 m_label1 = 0;
00028 setHasConfigurationInterface(false);
00029 setAcceptDrops(false);
00030 setAcceptsHoverEvents(true);
00031
00032
00033 resize(512,256);
00034 }
00035
00036 void KalziumDidyouknow::init()
00037 {
00038 qDebug() << "initializing DidYouKnow-Applet";
00039
00040 m_engine->connectSource( "Fact" , this, 1000);
00041
00042 m_theme.setContainsMultipleImages(false);
00043
00044 m_label1 = new QGraphicsTextItem(this);
00045 m_label1->setPos( m_theme.elementRect( "canvas" ).topLeft() );
00046 m_label1->setDefaultTextColor( Qt::white );
00047 }
00048
00049 void KalziumDidyouknow::constraintsUpdated(Plasma::Constraints constraints)
00050 {
00051
00052 prepareGeometryChange();
00053 if (constraints & Plasma::SizeConstraint) {
00054 m_theme.resize(size());
00055 }
00056
00057 m_label1->setPos( m_theme.elementRect( "canvas" ).topLeft() );
00058 }
00059
00060 KalziumDidyouknow::~KalziumDidyouknow()
00061 {
00062 delete m_random;
00063 }
00064
00065 void KalziumDidyouknow::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data)
00066 {
00067 qDebug() << "entering dataUpdated()";
00068 Q_UNUSED(source);
00069
00070 if (m_label1) {
00071
00072 m_label1->setPlainText( data["fact"].toString() );
00073 }
00074 }
00075
00076
00077 void KalziumDidyouknow::paintInterface(QPainter *p,
00078 const QStyleOptionGraphicsItem *option,
00079 const QRect &contentsRect)
00080 {
00081 Q_UNUSED(option);
00082
00083 p->setRenderHint(QPainter::SmoothPixmapTransform);
00084 p->setRenderHint(QPainter::Antialiasing);
00085
00086
00087 m_theme.resize(size());
00088 m_theme.paint(p, 0, 0 );
00089 }
00090
00091 #include "didyouknow.moc"