24 #include <QGraphicsScene> 
   28 #include <QStyleOptionGraphicsItem> 
   29 #include <QGraphicsItemGroup> 
   30 #include <QGraphicsView> 
   35 #include <KFileDialog> 
   36 #include <KToggleAction> 
   38 #include "../src/karamba.h" 
   39 #include "../src/karambamanager.h" 
   48         QPointer<Skip::AppletAdaptor> appletadaptor;
 
   49         QPointer<Karamba> themeItem;
 
   51         QList<QAction*> contextActions;
 
   55         ~Private() { 
delete appletadaptor; 
delete themeItem; }
 
   61             contextActions.clear();
 
   63             QPointF origPos = themeItem->pos();
 
   64             themeItem->setParentItem(applet);
 
   65             themeItem->moveToPos( origPos.toPoint() );
 
   68             applet->scene()->installEventFilter(
this);
 
   70             view->installEventFilter(
this);
 
   71             view->viewport()->installEventFilter(
this);
 
   73             if( KToggleAction* lockedAction = themeItem->findChild<KToggleAction*>(
"lockedAction") ) {
 
   75                 if( ! lockedAction->isChecked() )
 
   76                     lockedAction->setChecked(
true);
 
   77                 lockedAction->setVisible(
false);
 
   80             if( QAction* configAction = themeItem->findChild<QAction*>(
"configureTheme") ) {
 
   81                 contextActions.append(configAction);
 
   88             appletadaptor = 
new Skip::AppletAdaptor(themeItem, applet);
 
   92         bool eventFilter(QObject* watched, QEvent* event)
 
   94             switch( event->type() ) {
 
   95                 case QEvent::ContextMenu:
 
   96                     kDebug() << 
"eventFilter type=ContextMenu watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) : 
"NULL") ;
 
  100                 case QEvent::GraphicsSceneContextMenu:
 
  101                     kDebug() << 
"eventFilter type=GraphicsSceneContextMenu watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) : 
"NULL") ;
 
  103                 case QEvent::KeyPress:
 
  104                     kDebug() << 
"eventFilter type=KeyPress watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) : 
"NULL") ;
 
  116     : Plasma::Applet(parent, args)
 
  117     , d(new Private(this))
 
  121     kDebug() << 
"========================> SuperKarambaApplet Ctor" << args ;
 
  122     setHasConfigurationInterface(
true);
 
  129     if (d->args.count() < 3) {
 
  130         KConfigGroup cg = config();
 
  131         d->themePath = cg.readEntry(
"theme", KUrl());
 
  133         d->themePath = d->args[2].toString();
 
  136     setDrawStandardBackground(
false);
 
  138     if( !d->themePath.isValid() ) {
 
  139         KFileDialog* filedialog = 
new KFileDialog(
 
  140             KUrl(
"kfiledialog:///SuperKarambaPlasmaApplet"), 
 
  141             i18n(
"*.skz *.theme|Theme Files\n*|All Files"), 
 
  145         filedialog->setCaption( i18n(
"SuperKaramba Theme") );
 
  146         filedialog->setOperationMode( KFileDialog::Opening );
 
  147         filedialog->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
 
  148         if( filedialog->exec() )
 
  149             d->themePath = filedialog->selectedUrl();
 
  153     if( d->themePath.isValid() ) {
 
  154         QTimer::singleShot(100, 
this, SLOT(loadKaramba()));
 
  157         QTimer::singleShot(1000, 
this, SLOT(loadFailed()));
 
  163     kDebug() << 
"========================> SuperKarambaApplet Dtor" ;
 
  165     KConfigGroup cg = config();
 
  166     cg.writeEntry(
"theme", d->themePath);
 
  176 void SuperKarambaApplet::loadKaramba()
 
  178     kDebug() << 
"SuperKarambaApplet::loadKaramba() Theme: " << d->themePath ;
 
  180     QGraphicsScene *gfxScene = scene();
 
  181     Q_ASSERT( gfxScene );
 
  182     Q_ASSERT( gfxScene->views().count() > 0 );
 
  184     d->themeItem = 
new Karamba(d->themePath, gfxScene->views()[0]);
 
  193     if( d->appletadaptor )
 
  194         d->appletadaptor->paintInterface(painter, option, rect);
 
  200         d->themeItem->popupGlobalMenu();
 
  203 void SuperKarambaApplet::configAccepted()
 
  205     kDebug() << 
"SuperKarambaApplet::configAccepted" ;
 
  206     KConfigGroup cg = config();
 
  207     cg.writeEntry(
"theme", d->themePath);
 
  208     QGraphicsItem::update();
 
  215     Q_UNUSED(constraints)
 
  217     setDrawStandardBackground(
false);
 
  222     return d->themeItem ? d->themeItem->boundingRect() : Applet::boundingRect();
 
  227     if( ! d->themeItem ) {
 
  228         kDebug()<<
">>>>>>>>>>>> SuperKarambaApplet::karambaStarted";
 
  229         d->themeItem = 
dynamic_cast< Karamba* 
>( group );
 
  230         Q_ASSERT(d->themeItem);
 
  232         QGraphicsItem::update();
 
  239     if( d->themeItem == group ) {
 
  240         kDebug()<<
">>>>>>>>>>>> SuperKarambaApplet::karambaClosed";
 
  242         d->themePath = KUrl();
 
  243         scene()->removeItem(
this);
 
  248 void SuperKarambaApplet::loadFailed()
 
  250     kDebug()<<
">>>>>>>>>>>> SuperKarambaApplet::loadFailed";
 
  251     d->themePath = KUrl();
 
  252     scene()->removeItem(
this);
 
  256 QList<QAction*> SuperKarambaApplet::contextActions()
 
  258     return d->contextActions;
 
  264         KSharedConfigPtr config = KSharedConfig::openConfig(
"superkarambarc");
 
  265         KConfigGroup cg(config, 
"themes");
 
  267         QStringList themes = cg.readPathEntry(
"UserAddedThemes", QStringList());
 
  269         QList<QMap<QString, QVariant> > result;
 
  271         foreach (
const QString &theme, themes) {
 
  274             QMap<QString, QVariant> metadata;
 
  275             QVariantList arguments;
 
  277             metadata[
"arguments"] = arguments;
 
  278             metadata[
"name"] = themeFile.
name();
 
  280             QPixmap icon = themeFile.
icon();
 
  282                 metadata[
"icon"] = KIcon( QLatin1String( 
"application-x-plasma" ));
 
  284                 metadata[
"icon"] = KIcon(themeFile.
icon());
 
  294 #include "skapplet.moc" 
Karamba * karamba() const 
virtual ~SuperKarambaApplet()
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &rect)
const QString & name() const 
virtual void showConfigurationInterface()
virtual void constraintsUpdated(Plasma::Constraints constraints)
KDE_EXPORT QList< QMap< QString, QVariant > > installedThemes()
static KarambaManager * self()
const QString & description() const 
SuperKarambaApplet(QObject *parent, const QVariantList &args)
QRectF boundingRect() const