20 #include <KConfigGroup>
21 #include <KConfigDialog>
22 #include <KFontDialog>
23 #include <KColorDialog>
27 : Plasma::Applet(parent, args),
32 KGlobal::locale()->insertCatalog(
"parley");
34 setHasConfigurationInterface(
true);
35 setAcceptDrops(
false);
36 setAcceptsHoverEvents(
true);
37 setAspectRatioMode(Plasma::KeepAspectRatio);
38 setBackgroundHints(NoBackground);
40 m_theme =
new Plasma::Svg(
this);
41 m_theme->setImagePath(
"widgets/parley_plasma_card");
42 m_theme->setContainsMultipleImages(
false);
43 m_theme->resize(size());
44 setAssociatedApplication(
"parley");
49 m_theme->size().height();
54 m_engine = dataEngine(
"parley");
58 m_label1->
setPos(m_theme->elementRect(
"translation1").topLeft());
59 m_label2->
setPos(m_theme->elementRect(
"translation2").topLeft());
63 m_engine->connectSource(m_sourceFile.url(),
this, m_updateInterval);
68 KConfigGroup cg = config();
69 m_updateInterval = cg.readEntry(
"updateInterval", 10000);
70 m_solutionType = cg.readEntry(
"Solution", 0);
72 m_lang1 = cg.readEntry(
"Top Language", 0);
73 m_lang2 = cg.readEntry(
"Bottom Language", 1);
74 m_font = cg.readEntry(
"font",
QFont());
76 m_sourceFile = cg.readEntry(
"File Name", KUrl());
77 if (m_sourceFile.isEmpty()) {
78 kDebug() <<
"open file from parleyrc";
79 KConfig parleyConfig(
"parleyrc");
80 kDebug() << parleyConfig.groupList();
81 KConfigGroup recentFilesGroup(&parleyConfig,
"Recent Files");
83 m_sourceFile = recentFilesGroup.readEntry(recentFilesGroup.keyList().value(recentFilesGroup.keyList().count() / 2 - 1), KUrl());
84 kDebug() <<
"open file: " << m_sourceFile;
90 if (constraints & Plasma::FormFactorConstraint) {
91 setBackgroundHints(NoBackground);
94 if (constraints & Plasma::SizeConstraint) {
95 double aspect = 256.0 / 160.0;
96 if (formFactor() == Plasma::Horizontal) {
98 setMinimumWidth(contentsRect().height() * aspect);
99 }
else if (formFactor() == Plasma::Vertical) {
101 setMinimumHeight((
int)contentsRect().width() / aspect);
104 m_label1->
setPos(m_theme->elementRect(
"translation1").topLeft());
106 double scale = qMin(m_theme->elementRect(
"translation1").width() / m_label1->
boundingRect().
width(), m_theme->elementRect(
"translation1").height() / m_label1->
boundingRect().
height());
109 m_label2->
setPos(m_theme->elementRect(
"translation2").topLeft());
111 scale = qMin(m_theme->elementRect(
"translation2").width() / m_label2->
boundingRect().
width(), m_theme->elementRect(
"translation2").height() / m_label2->
boundingRect().
height());
122 kDebug() <<
"data updated" << source << data;
124 m_languages = data.keys();
128 double scale = qMin(m_theme->elementRect(
"translation1").width() / m_label1->
boundingRect().
width(), m_theme->elementRect(
"translation1").height() / m_label1->
boundingRect().
height());
130 m_label1->
setPos(m_theme->elementRect(
"translation1").topLeft()
132 (m_theme->elementRect(
"translation1").width() - m_label1->
boundingRect().
width()*scale) / 2.0,
133 (m_theme->elementRect(
"translation1").height() - m_label1->
boundingRect().
height()*scale) / 2.0));
135 if (m_languages.
size() > 1) {
137 scale = qMin(m_theme->elementRect(
"translation2").width() / m_label2->
boundingRect().
width(), m_theme->elementRect(
"translation2").height() / m_label2->
boundingRect().
height());
139 if (m_solutionType == Hover) {
142 m_label2->
setPos(m_theme->elementRect(
"translation2").topLeft()
144 (m_theme->elementRect(
"translation2").width() - m_label2->
boundingRect().
width()*scale) / 2.0,
145 (m_theme->elementRect(
"translation2").height() - m_label2->
boundingRect().
height()*scale) / 2.0));
162 const QRect &contentsRect)
166 QSizeF boundSize = geometry().size();
167 m_theme->resize(boundSize);
168 m_theme->paint(p, contentsRect,
"Card");
175 parent->addPage(widget, parent->windowTitle(), icon());
176 parent->setButtons(KDialog::Ok | KDialog::Cancel | KDialog::Apply);
177 connect(parent, SIGNAL(applyClicked()),
this, SLOT(
configAccepted()));
178 connect(parent, SIGNAL(okClicked()),
this, SLOT(
configAccepted()));
180 connect(ui.fontSelectButton, SIGNAL(clicked()),
this, SLOT(
showFontSelectDlg()));
182 ui.updateIntervalSpinBox->setValue(m_updateInterval / 1000);
183 ui.updateIntervalSpinBox->setSuffix(ki18np(
" second",
" seconds"));
184 KConfigGroup cg = config();
186 ui.filechooser->setUrl(m_sourceFile);
187 ui.filechooser->setFilter(i18n(
"*.kvtml|Vocabulary Collections"));
189 ui.language1->addItems(m_languages);
190 ui.language2->addItems(m_languages);
191 ui.language1->setCurrentIndex(m_lang1);
192 ui.language2->setCurrentIndex(m_lang2);
194 switch (m_solutionType) {
196 ui.solutionOnHover->setChecked(
true);
199 ui.solutionAlways->setChecked(
true);
203 connect(ui.fontSelectButton, SIGNAL(clicked()), parent, SLOT(settingsModified()));
204 connect(ui.solutionOnHover, SIGNAL(toggled(
bool)), parent, SLOT(settingsModified()));
205 connect(ui.solutionAlways, SIGNAL(toggled(
bool)), parent, SLOT(settingsModified()));
206 connect(ui.filechooser, SIGNAL(
urlSelected(
const KUrl &)), parent, SLOT(settingsModified()));
207 connect(ui.updateIntervalSpinBox, SIGNAL(valueChanged(
int)), parent, SLOT(settingsModified()));
213 m_engine->disconnectSource(m_sourceFile.url(),
this);
215 m_sourceFile = ui.filechooser->url();
216 m_engine->connectSource(m_sourceFile.url(),
this, m_updateInterval);
218 Plasma::DataEngine::Data data = m_engine->query(m_sourceFile.url());
219 m_languages = data.keys();
221 ui.language1->clear();
222 ui.language2->clear();
223 ui.language1->addItems(m_languages);
224 ui.language2->addItems(m_languages);
226 ui.language1->setCurrentIndex(0);
227 ui.language2->setCurrentIndex(1);
232 KFontDialog::getFont(m_font);
237 prepareGeometryChange();
239 KConfigGroup cg = config();
240 cg.writeEntry(
"font", m_font);
243 m_updateInterval = ui.updateIntervalSpinBox->value() * 1000;
244 cg.writeEntry(
"updateInterval", m_updateInterval);
246 m_engine->disconnectSource(m_sourceFile.url(),
this);
247 m_sourceFile = ui.filechooser->url();
248 cg.writeEntry(
"File Name", m_sourceFile);
250 m_solutionType = Hover;
251 if (ui.solutionAlways->isChecked()) {
252 m_solutionType = Always;
255 cg.writeEntry(
"Solution", m_solutionType);
257 m_lang1 = ui.language1->currentIndex();
258 m_lang2 = ui.language2->currentIndex();
260 cg.writeEntry(
"Top Language", m_lang1);
261 cg.writeEntry(
"Bottom Language", m_lang2);
264 m_engine->connectSource(m_sourceFile.url(),
this, m_updateInterval);
266 kDebug() <<
"open:" << m_sourceFile;
268 emit configNeedsSaving();
273 Plasma::Applet::hoverEnterEvent(event);
279 Plasma::Applet::hoverLeaveEvent(event);
282 #include "parley_plasma.moc"
void setFont(const QFont &font)
void constraintsEvent(Plasma::Constraints constraints)
virtual QRectF boundingRect() const
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
ParleyPlasma(QObject *parent, const QVariantList &args)
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
QSizeF contentSizeHint() const
void urlSelected(const KUrl &file)
void setPos(const QPointF &pos)
void setContentSize(const QSizeF &size)
void setPlainText(const QString &text)
void dataUpdated(const QString &name, const Plasma::DataEngine::Data &data)
void createConfigurationInterface(KConfigDialog *parent)