1
/***************************************************************************
2
copyright : (C) 2008 by Carsten Niehaus
3
email : cniehaus@kde.org
4
Copyright 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
5
***************************************************************************/
6
/***************************************************************************
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
***************************************************************************/
14
#include "kalzium_plasma.h"
17
#include <KConfigGroup>
18
#include <KFontDialog>
26
KalziumPlasma::KalziumPlasma(QObject *parent, const QVariantList &args)
27
: Plasma::Applet(parent, args),
31
m_theme.setImagePath("widgets/testtube"),
32
m_engine = dataEngine("kalzium");
36
m_lineedit = new Plasma::LineEdit( this );
37
m_lineedit->setDefaultText( i18n("Enter the atomic number.") );
38
connect( m_lineedit, SIGNAL(editingFinished() ),
39
this, SLOT(textChanged() ) );
41
setHasConfigurationInterface(true);
42
setAcceptDrops(false);
43
setAcceptsHoverEvents(true);
44
// setDrawStandardBackground(false);
49
void KalziumPlasma::init()
51
qDebug() << "initializing Kalzium";
55
m_currentSource = "BlueObelisk:RandomElement";
56
// connect to random source and update ever 5 seconds
57
m_engine->connectSource( m_currentSource, this, 5000);
59
m_theme.setContainsMultipleImages(false);
61
m_label1 = new QGraphicsTextItem(this);
62
m_label1->setPos( m_theme.elementRect( "name" ).topLeft() );
63
m_label1->setFont(m_font);
64
m_label1->setDefaultTextColor(Qt::white);
67
void KalziumPlasma::configChanged()
69
KConfigGroup cg = config();
70
m_font = cg.readEntry("font",QFont());
73
void KalziumPlasma::constraintsUpdated(Plasma::Constraints constraints)
75
// setDrawStandardBackground(false);
76
prepareGeometryChange();
77
if (constraints & Plasma::SizeConstraint) {
78
//m_theme.resize(contentSize().toSize());
79
m_theme.resize(size());
82
m_label1->setPos( m_theme.elementRect( "canvas" ).topLeft() );
85
KalziumPlasma::~KalziumPlasma()
90
void KalziumPlasma::dataUpdated(const QString& source, const Plasma::DataEngine::Data &data)
92
qDebug() << "dataUpdated" << source;
93
if (source != m_currentSource) {
97
QString bp = data["bp"].toString();
98
QString mp = data["mp"].toString();
99
QString mass = data["mass"].toString();
100
QString symbol = data["symbol"].toString();
101
QString name = data["name"].toString();
103
text = QString(i18n( "\nName: %1", name ));
104
text.append(QString(i18n( "\nSymbol: %1", symbol)));
105
text.append(QString(i18n( "\nBoiling point: %1", bp)));
106
text.append(QString(i18n( "\nMelting point: %1", mp)));
107
text.append(QString(i18n( "\nMass: %1", mass)));
109
// m_label1->setAlignment(Qt::AlignLeft);
110
m_label1->setPlainText(text);
114
void KalziumPlasma::paintInterface(QPainter *p,
115
const QStyleOptionGraphicsItem *option,
116
const QRect &contentsRect)
120
p->setRenderHint(QPainter::SmoothPixmapTransform);
121
p->setRenderHint(QPainter::Antialiasing);
123
// Now we draw the applet, starting with our svg
124
//m_theme.resize((int)contentsRect.width(), (int)contentsRect.height());
125
m_theme.resize(size());
126
//m_theme.paint(p, (int)contentsRect.left(), (int)contentsRect.top());
127
m_theme.paint(p, 0,0 );
129
m_lineedit->setPos( 0,150 );
132
void KalziumPlasma::showConfigurationInterface()
135
m_dialog = new KDialog;
136
m_dialog->setWindowIcon(KIcon("kalzium"));
137
m_dialog->setCaption( i18n("KalziumPlasma Configuration") );
138
ui.setupUi(m_dialog->mainWidget());
139
m_dialog->mainWidget()->layout()->setMargin(0);
140
m_dialog->setButtons( KDialog::Ok | KDialog::Cancel | KDialog::Apply );
141
connect( m_dialog, SIGNAL(applyClicked()),
142
this, SLOT(configAccepted()) );
143
connect( m_dialog, SIGNAL(okClicked()),
144
this, SLOT(configAccepted()) );
145
connect( ui.fontSelectButton, SIGNAL(clicked()),
146
this, SLOT(showFontSelectDlg()) );
152
void KalziumPlasma::showFontSelectDlg()
154
KFontDialog::getFont(m_font);
157
void KalziumPlasma::configAccepted()
159
prepareGeometryChange();
161
KConfigGroup cg = config();
162
cg.writeEntry("font", m_font);
163
m_label1->setFont(m_font);
165
emit configNeedsSaving();
168
void KalziumPlasma::textChanged()
170
m_engine->disconnectSource(m_currentSource, this);
172
QString currentText = m_lineedit->toPlainText();
173
if (!currentText.isEmpty()) {
174
// simply assume the user entered the atomic number of the element
175
m_currentSource = QString("BlueObelisk:Element:") + currentText;
177
m_currentSource = QString("BlueObelisk:RandomElement");
179
m_engine->connectSource( m_currentSource, this, 5000);
182
#include "kalzium_plasma.moc"