1 /***************************************************************************
2 * Copyright (C) 2008 by Artur Duque de Souza <morpheuz@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
20 #include <qedje_applet.h>
22 #include <QtGui/QGraphicsProxyWidget>
24 #include <Plasma/Package>
25 #include <Plasma/Applet>
27 using namespace Plasma
;
29 K_EXPORT_PLASMA_APPLETSCRIPTENGINE(qedjescripts
, QEdjeAppletScript
)
31 QEdjeAppletScript::QEdjeAppletScript(QObject
*parent
, const QVariantList
&args
)
32 : Plasma::AppletScript(parent
), dialog(0), config_widget(0),
33 m_edje_file(""), m_edje_group(""), currentIndex(0)
38 QEdjeAppletScript::~QEdjeAppletScript()
40 // the proxy gets the ownership of the applet
41 // so we need to free the applet in order to avoid segfaults later
44 // deleting setting's dialog stuff
55 void QEdjeAppletScript::resizeAll(QSize size
)
57 // minimum required size
58 if (size
== QSize(0, 0))
59 size
= QSize(100, 100);
61 // resize the applet and qzion's canvas
62 QSizeF new_size
= applet()->size() - applet()->contentsRect().size() + size
;
63 applet()->resize(new_size
.toSize());
67 void QEdjeAppletScript::setup_canvas()
69 // we need a proxy so we can put qzion inside the applet
70 proxy
= new QGraphicsProxyWidget(applet());
71 canvas
= new QZionCanvas();
73 // create the canvasd (qzion) needed by qedje
74 proxy
->setWidget(canvas
->widget());
78 canvas
->resize(100, 100);
81 bool QEdjeAppletScript::init()
86 applet()->setBackgroundHints(Applet::TranslucentBackground
);
87 setHasConfigurationInterface(true);
90 KConfigGroup cg
= applet()->config();
91 m_edje_group
= cg
.readEntry("EdjeGroup", "");
94 m_edje_file
= package()->filePath("edje_file");
97 m_groups_list
= groupNamesFromFile(m_edje_file
);
99 if (m_groups_list
.count() <= 0)
102 if (m_edje_group
.isEmpty()) {
103 m_edje_group
= m_groups_list
.first();
106 currentIndex
= m_groups_list
.indexOf(m_edje_group
);
108 // create qedje object
109 world
= new QEdje(canvas
, m_edje_file
, m_edje_group
);
111 // show qedje object and resize applet and plasmoid based on
112 // the object's min size
114 resizeAll(world
->propMin());
118 void QEdjeAppletScript::showConfigurationInterface()
121 dialog
= new KDialog();
122 config_widget
= new QWidget(dialog
);
123 previewCanvas
= new QZionCanvas(config_widget
);
125 dialog
->setCaption(i18n("QEdje Applet Config"));
126 dialog
->setButtons(KDialog::Ok
| KDialog::Cancel
);
128 ui
.setupUi(config_widget
);
129 ui
.edje_groups
->addItems(m_groups_list
);
130 ui
.edje_groups
->setCurrentIndex(ui
.edje_groups
->findText(m_edje_group
));
131 previewCanvas
->widget()->setGeometry(ui
.preview
->frameGeometry());
133 // connect the signals
134 connect(dialog
, SIGNAL(okClicked()), this, SLOT(configChanged()));
135 connect(ui
.edje_groups
, SIGNAL(activated(int)), this, SLOT(groupSelected(int)));
137 // show the config dialog
138 dialog
->setMainWidget(config_widget
);
140 previewWorld
= new QEdje(previewCanvas
, m_edje_file
, m_edje_group
);
144 previewWorld
->show();
147 void QEdjeAppletScript::groupSelected(int index
)
149 if (index
== currentIndex
)
152 m_edje_group
= m_groups_list
[index
];
153 currentIndex
= index
;
155 previewWorld
->hide();
158 previewWorld
= new QEdje(previewCanvas
, m_edje_file
, m_edje_group
);
159 previewWorld
->show();
162 void QEdjeAppletScript::configChanged()
164 KConfigGroup cg
= applet()->config();
165 cg
.writeEntry("EdjeGroup", m_edje_group
);
170 world
= new QEdje(canvas
, m_edje_file
, m_edje_group
);
172 resizeAll(world
->propMin());
175 void QEdjeAppletScript::paintInterface(QPainter
*,
176 const QStyleOptionGraphicsItem
*,
177 const QRect
&contentsRect
)
179 // make sure qzion have the correct geometry
180 canvas
->widget()->setGeometry(contentsRect
);
183 #include "qedje_applet.moc"