• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Plasma

qedje_applet.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2008 by Artur Duque de Souza <morpheuz@gmail.com>       *
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program; if not, write to the                         *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
00018  ***************************************************************************/
00019 
00020 #include <qedje_applet.h>
00021 
00022 #include <QtGui/QGraphicsProxyWidget>
00023 
00024 #include <Plasma/Package>
00025 #include <Plasma/Applet>
00026 
00027 using namespace Plasma;
00028 
00029 K_EXPORT_PLASMA_APPLETSCRIPTENGINE(qedjescripts, QEdjeAppletScript)
00030 
00031 QEdjeAppletScript::QEdjeAppletScript(QObject *parent, const QVariantList &args)
00032 : Plasma::AppletScript(parent), dialog(0), config_widget(0),
00033     m_edje_file(""), m_edje_group(""), currentIndex(0)
00034 {
00035     Q_UNUSED(args);
00036 }
00037 
00038 QEdjeAppletScript::~QEdjeAppletScript()
00039 {
00040     // the proxy gets the ownership of the applet
00041     // so we need to free the applet in order to avoid segfaults later
00042     proxy->setWidget(0);
00043 
00044     // deleting setting's dialog stuff
00045     if (dialog) {
00046         delete previewWorld;
00047         delete previewCanvas;
00048         delete dialog;
00049     }
00050 
00051     delete world;
00052     delete canvas;
00053 }
00054 
00055 void QEdjeAppletScript::resizeAll(QSize size)
00056 {
00057     // minimum required size
00058     if (size == QSize(0, 0))
00059         size = QSize(100, 100);
00060 
00061     // resize the applet and qzion's canvas
00062     QSizeF new_size = applet()->size() - applet()->contentsRect().size() + size;
00063     applet()->resize(new_size.toSize());
00064     canvas->resize(size);
00065 }
00066 
00067 void QEdjeAppletScript::setup_canvas()
00068 {
00069     // we need a proxy so we can put qzion inside the applet
00070     proxy = new QGraphicsProxyWidget(applet());
00071     canvas = new QZionCanvas();
00072 
00073     // create the canvasd (qzion) needed by qedje
00074     proxy->setWidget(canvas->widget());
00075     canvas->show();
00076 
00077     // minimum size
00078     canvas->resize(100, 100);
00079 }
00080 
00081 bool QEdjeAppletScript::init()
00082 {
00083     setup_canvas();
00084 
00085     // set plasma options
00086     applet()->setBackgroundHints(Applet::TranslucentBackground);
00087     setHasConfigurationInterface(true);
00088 
00089     // get config info
00090     KConfigGroup cg = applet()->config();
00091     m_edje_group = cg.readEntry("EdjeGroup", "");
00092 
00093     // setup edje file
00094     m_edje_file = package()->filePath("edje_file");
00095 
00096     // check groups
00097     m_groups_list = groupNamesFromFile(m_edje_file);
00098 
00099     if (m_groups_list.count() <= 0)
00100         return false;
00101 
00102     if (m_edje_group.isEmpty()) {
00103         m_edje_group = m_groups_list.first();
00104         currentIndex = 0;
00105     } else
00106         currentIndex = m_groups_list.indexOf(m_edje_group);
00107 
00108     // create qedje object
00109     world = new QEdje(canvas, m_edje_file, m_edje_group);
00110 
00111     // show qedje object and resize applet and plasmoid based on
00112     // the object's min size
00113     world->show();
00114     resizeAll(world->propMin());
00115     return true;
00116 }
00117 
00118 void QEdjeAppletScript::showConfigurationInterface()
00119 {
00120     if (!dialog) {
00121         dialog = new KDialog();
00122         config_widget = new QWidget(dialog);
00123         previewCanvas = new QZionCanvas(config_widget);
00124 
00125         dialog->setCaption(i18n("QEdje Applet Config"));
00126         dialog->setButtons(KDialog::Ok | KDialog::Cancel);
00127 
00128         ui.setupUi(config_widget);
00129         ui.edje_groups->addItems(m_groups_list);
00130         ui.edje_groups->setCurrentIndex(ui.edje_groups->findText(m_edje_group));
00131         previewCanvas->widget()->setGeometry(ui.preview->frameGeometry());
00132 
00133         // connect the signals
00134         connect(dialog, SIGNAL(okClicked()), this, SLOT(configChanged()));
00135         connect(ui.edje_groups, SIGNAL(activated(int)), this, SLOT(groupSelected(int)));
00136 
00137         // show the config dialog
00138         dialog->setMainWidget(config_widget);
00139 
00140         previewWorld = new QEdje(previewCanvas, m_edje_file, m_edje_group);
00141     }
00142 
00143     dialog->show();
00144     previewWorld->show();
00145 }
00146 
00147 void QEdjeAppletScript::groupSelected(int index)
00148 {
00149     if (index == currentIndex)
00150         return;
00151 
00152     m_edje_group = m_groups_list[index];
00153     currentIndex = index;
00154 
00155     previewWorld->hide();
00156     delete previewWorld;
00157 
00158     previewWorld = new QEdje(previewCanvas, m_edje_file, m_edje_group);
00159     previewWorld->show();
00160 }
00161 
00162 void QEdjeAppletScript::configChanged()
00163 {
00164     KConfigGroup cg = applet()->config();
00165     cg.writeEntry("EdjeGroup", m_edje_group);
00166 
00167     world->hide();
00168     delete world;
00169 
00170     world = new QEdje(canvas, m_edje_file, m_edje_group);
00171     world->show();
00172     resizeAll(world->propMin());
00173 }
00174 
00175 void QEdjeAppletScript::paintInterface(QPainter *,
00176                                        const QStyleOptionGraphicsItem *,
00177                                        const QRect &contentsRect)
00178 {
00179     // make sure qzion have the correct geometry
00180     canvas->widget()->setGeometry(contentsRect);
00181 }
00182 
00183 #include "qedje_applet.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal