• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeutils API Reference
  • KDE Home
  • Contact Us
 

superkaramba

  • sources
  • kde-4.12
  • kdeutils
  • superkaramba
  • plasma
skapplet.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007 Sebastian Sauer <mail@dipe.org>
3  *
4  * This file is part of SuperKaramba.
5  *
6  * SuperKaramba is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * SuperKaramba is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SuperKaramba; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "skapplet.h"
22 #include "skappletadaptor.h"
23 
24 #include <QGraphicsScene>
25 #include <QPainter>
26 #include <QTimer>
27 #include <QPointer>
28 #include <QStyleOptionGraphicsItem>
29 #include <QGraphicsItemGroup>
30 #include <QGraphicsView>
31 #include <KDebug>
32 #include <KLocale>
33 #include <KDialog>
34 #include <KMenu>
35 #include <KFileDialog>
36 #include <KToggleAction>
37 
38 #include "../src/karamba.h"
39 #include "../src/karambamanager.h"
40 
41 K_EXPORT_PLASMA_APPLET(skapplet, SuperKarambaApplet)
42 
43 class SuperKarambaApplet::Private : public QObject
45 {
46  public:
47  SuperKarambaApplet* applet;
48  QPointer<Skip::AppletAdaptor> appletadaptor;
49  QPointer<Karamba> themeItem;
50  KUrl themePath;
51  QList<QAction*> contextActions;
52  QVariantList args;
53 
54  explicit Private(SuperKarambaApplet* a) : applet(a), appletadaptor(0), themeItem(0) {}
55  ~Private() { delete appletadaptor; delete themeItem; }
56 
57  void initTheme()
58  {
59  Q_ASSERT(applet);
60  Q_ASSERT(themeItem);
61  contextActions.clear();
62 
63  QPointF origPos = themeItem->pos();
64  themeItem->setParentItem(applet);
65  themeItem->moveToPos( origPos.toPoint() );
66 
67  //testcases
68  applet->scene()->installEventFilter(this);
69  QGraphicsView* view = applet->scene()->views()[0];
70  view->installEventFilter(this);
71  view->viewport()->installEventFilter(this);
72 
73  if( KToggleAction* lockedAction = themeItem->findChild<KToggleAction*>("lockedAction") ) {
74  // disable locked action since Plasma will handle it for us.
75  if( ! lockedAction->isChecked() )
76  lockedAction->setChecked(true);
77  lockedAction->setVisible(false);
78  }
79 
80  if( QAction* configAction = themeItem->findChild<QAction*>("configureTheme") ) {
81  contextActions.append(configAction);
82  }
83 
84  //if( KAction* reloadAction = themeItem->findChild<KAction*>("reloadAction") )
85  // contextActions.append(reloadAction);
86 
87  delete appletadaptor;
88  appletadaptor = new Skip::AppletAdaptor(themeItem, applet);
89  }
90 
91  private:
92  bool eventFilter(QObject* watched, QEvent* event)
93  {
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") ;
97  //static_cast<QContextMenuEvent*>(event);
98  //return true;
99  break;
100  case QEvent::GraphicsSceneContextMenu:
101  kDebug() << "eventFilter type=GraphicsSceneContextMenu watched=" << (watched ? QString("%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) : "NULL") ;
102  break;
103  case QEvent::KeyPress:
104  kDebug() << "eventFilter type=KeyPress watched=" << (watched ? QString("%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) : "NULL") ;
105  //QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
106  //qDebug() << "Ate key press" << keyEvent->key();
107  break;
108  default:
109  break;
110  }
111  return false;
112  }
113 };
114 
115 SuperKarambaApplet::SuperKarambaApplet(QObject *parent, const QVariantList &args)
116  : Plasma::Applet(parent, args)
117  , d(new Private(this))
118 {
119  //watchForFocus(d,true);
120 
121  kDebug() << "========================> SuperKarambaApplet Ctor" << args ;
122  setHasConfigurationInterface(true);
123 
124  d->args = args;
125 }
126 
127 void SuperKarambaApplet::init()
128 {
129  if (d->args.count() < 3) {
130  KConfigGroup cg = config();
131  d->themePath = cg.readEntry("theme", KUrl());
132  } else {
133  d->themePath = d->args[2].toString();
134  }
135 
136  setDrawStandardBackground(false);
137 
138  if( !d->themePath.isValid() ) {
139  KFileDialog* filedialog = new KFileDialog(
140  KUrl("kfiledialog:///SuperKarambaPlasmaApplet"), // startdir
141  i18n("*.skz *.theme|Theme Files\n*|All Files"), // filter
142  0, // custom widget
143  0 // parent
144  );
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();
150  delete filedialog;
151  }
152 
153  if( d->themePath.isValid() ) {
154  QTimer::singleShot(100, this, SLOT(loadKaramba()));
155  } else {
156  // Wait till the Phase Animator finished
157  QTimer::singleShot(1000, this, SLOT(loadFailed()));
158  }
159 }
160 
161 SuperKarambaApplet::~SuperKarambaApplet()
162 {
163  kDebug() << "========================> SuperKarambaApplet Dtor" ;
164  //watchForFocus(d, false);
165  KConfigGroup cg = config();
166  cg.writeEntry("theme", d->themePath);
167 
168  delete d;
169 }
170 
171 Karamba* SuperKarambaApplet::karamba() const
172 {
173  return d->themeItem;
174 }
175 
176 void SuperKarambaApplet::loadKaramba()
177 {
178  kDebug() << "SuperKarambaApplet::loadKaramba() Theme: " << d->themePath ;
179 
180  QGraphicsScene *gfxScene = scene();
181  Q_ASSERT( gfxScene );
182  Q_ASSERT( gfxScene->views().count() > 0 );
183 
184  d->themeItem = new Karamba(d->themePath, gfxScene->views()[0]);
185  d->initTheme();
186 
187  connect(KarambaManager::self(), SIGNAL(karambaStarted(QGraphicsItemGroup*)), this, SLOT(karambaStarted(QGraphicsItemGroup*)));
188  connect(KarambaManager::self(), SIGNAL(karambaClosed(QGraphicsItemGroup*)), this, SLOT(karambaClosed(QGraphicsItemGroup*)));
189 }
190 
191 void SuperKarambaApplet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &rect)
192 {
193  if( d->appletadaptor )
194  d->appletadaptor->paintInterface(painter, option, rect);
195 }
196 
197 void SuperKarambaApplet::showConfigurationInterface()
198 {
199  if( d->themeItem )
200  d->themeItem->popupGlobalMenu();
201 }
202 
203 void SuperKarambaApplet::configAccepted()
204 {
205  kDebug() << "SuperKarambaApplet::configAccepted" ;
206  KConfigGroup cg = config();
207  cg.writeEntry("theme", d->themePath);
208  QGraphicsItem::update();
209  constraintsUpdated(Plasma::AllConstraints);
210  cg.config()->sync();
211 }
212 
213 void SuperKarambaApplet::constraintsUpdated(Plasma::Constraints constraints)
214 {
215  Q_UNUSED(constraints)
216 
217  setDrawStandardBackground(false);
218 }
219 
220 QRectF SuperKarambaApplet::boundingRect() const
221 {
222  return d->themeItem ? d->themeItem->boundingRect() : Applet::boundingRect();
223 }
224 
225 void SuperKarambaApplet::karambaStarted(QGraphicsItemGroup* group)
226 {
227  if( ! d->themeItem ) {
228  kDebug()<<">>>>>>>>>>>> SuperKarambaApplet::karambaStarted";
229  d->themeItem = dynamic_cast< Karamba* >( group );
230  Q_ASSERT(d->themeItem);
231  d->initTheme();
232  QGraphicsItem::update();
233  constraintsUpdated(Plasma::AllConstraints);
234  }
235 }
236 
237 void SuperKarambaApplet::karambaClosed(QGraphicsItemGroup* group)
238 {
239  if( d->themeItem == group ) {
240  kDebug()<<">>>>>>>>>>>> SuperKarambaApplet::karambaClosed";
241  d->themeItem = 0;
242  d->themePath = KUrl();
243  scene()->removeItem(this);
244  deleteLater();
245  }
246 }
247 
248 void SuperKarambaApplet::loadFailed()
249 {
250  kDebug()<<">>>>>>>>>>>> SuperKarambaApplet::loadFailed";
251  d->themePath = KUrl();
252  scene()->removeItem(this);
253  deleteLater();
254 }
255 
256 QList<QAction*> SuperKarambaApplet::contextActions()
257 {
258  return d->contextActions;
259 }
260 
261 extern "C" {
262  KDE_EXPORT QList<QMap<QString, QVariant> > installedThemes()
263  {
264  KSharedConfigPtr config = KSharedConfig::openConfig("superkarambarc");
265  KConfigGroup cg(config, "themes");
266 
267  QStringList themes = cg.readPathEntry("UserAddedThemes", QStringList());
268 
269  QList<QMap<QString, QVariant> > result;
270 
271  foreach (const QString &theme, themes) {
272  ThemeFile themeFile(theme);
273 
274  QMap<QString, QVariant> metadata;
275  QVariantList arguments;
276  arguments << theme;
277  metadata["arguments"] = arguments;
278  metadata["name"] = themeFile.name();
279  metadata["description"] = themeFile.description();
280  QPixmap icon = themeFile.icon();
281  if (icon.isNull()) {
282  metadata["icon"] = KIcon( QLatin1String( "application-x-plasma" ));
283  } else {
284  metadata["icon"] = KIcon(themeFile.icon());
285  }
286 
287  result << metadata;
288  }
289 
290  return result;
291  }
292 }
293 
294 #include "skapplet.moc"
SuperKarambaApplet::karamba
Karamba * karamba() const
Definition: skapplet.cpp:171
ThemeFile
Definition: themefile.h:41
SuperKarambaApplet::~SuperKarambaApplet
virtual ~SuperKarambaApplet()
Definition: skapplet.cpp:161
QObject
SuperKarambaApplet::paintInterface
void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &rect)
Definition: skapplet.cpp:191
SuperKarambaApplet
Definition: skapplet.h:35
Karamba
Definition: karamba.h:52
skapplet.h
skappletadaptor.h
ThemeFile::name
const QString & name() const
Definition: themefile.cpp:536
SuperKarambaApplet::showConfigurationInterface
virtual void showConfigurationInterface()
Definition: skapplet.cpp:197
SuperKarambaApplet::constraintsUpdated
virtual void constraintsUpdated(Plasma::Constraints constraints)
Definition: skapplet.cpp:213
installedThemes
KDE_EXPORT QList< QMap< QString, QVariant > > installedThemes()
Definition: skapplet.cpp:262
SuperKarambaApplet::init
void init()
Definition: skapplet.cpp:127
KarambaManager::self
static KarambaManager * self()
Definition: karambamanager.cpp:47
ThemeFile::description
const QString & description() const
Definition: themefile.cpp:576
QGraphicsItemGroup
SuperKarambaApplet::SuperKarambaApplet
SuperKarambaApplet(QObject *parent, const QVariantList &args)
Definition: skapplet.cpp:115
QGraphicsView
SuperKarambaApplet::boundingRect
QRectF boundingRect() const
Definition: skapplet.cpp:220
ThemeFile::icon
QPixmap icon() const
Definition: themefile.cpp:263
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

superkaramba

Skip menu "superkaramba"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal