30 #include <QGridLayout>
31 #include <QGraphicsScene>
32 #include <QGraphicsView>
33 #include <KToggleAction>
34 #include <KColorScheme>
35 #include <KGlobalSettings>
44 QPointer<Karamba> theme;
46 QList<QAction*> actions;
49 Private() : theme(0), appletadaptor(0) {}
50 ~Private() {
delete theme; }
54 : Plasma::AppletScript(parent)
69 Q_ASSERT( package() );
71 if( applet()->isContainment() ) {
72 Plasma::Containment *c =
dynamic_cast<Plasma::Containment *
>(applet());
76 c->setFormFactor(Plasma::Horizontal);
77 c->setLocation(Plasma::TopEdge);
88 applet()->setAspectRatioMode(Plasma::IgnoreAspectRatio);
91 QDir dir(package()->path());
92 QString name = dir.dirName();
93 if( name.toLower().startsWith(
"sk_") )
95 QFileInfo fi(dir, QString(
"%1.theme").arg(name));
97 QFileInfoList files = dir.entryInfoList(QStringList() <<
"*.skz" <<
"*.theme", QDir::Files);
98 if(files.count() < 1) {
99 kWarning() <<
"Failed to locate the themefile in path=" << package()->path();
105 d->themeFile = fi.absoluteFilePath();
106 QTimer::singleShot(50,
this, SLOT(loadKaramba()));
110 void SkAppletScript::loadKaramba()
114 Q_ASSERT( applet() );
115 Q_ASSERT( applet()->scene() );
116 Q_ASSERT( applet()->scene()->views().count() > 0 );
117 QGraphicsScene *scene = applet()->scene();
123 Q_ASSERT( ! d->theme );
124 d->theme =
new Karamba(d->themeFile, view, -1,
false, QPoint(),
false,
false);
125 d->theme->setParentItem(applet());
126 const QRectF geometry = applet()->geometry();
127 d->theme->moveToPos(QPoint(
int(geometry.x()),
int(geometry.y())));
131 if( applet()->isContainment() ) {
132 Plasma::Containment *c =
dynamic_cast<Plasma::Containment *
>(applet());
147 if( KToggleAction* lockedAction = d->theme->findChild<KToggleAction*>(
"lockedAction") ) {
149 if( ! lockedAction->isChecked() )
150 lockedAction->setChecked(
true);
151 lockedAction->setVisible(
false);
154 if( QAction* configAction = d->theme->findChild<QAction*>(
"configureTheme") ) {
155 d->actions << configAction;
158 connect(d->theme, SIGNAL(positionChanged()),
this, SLOT(positionChanged()));
159 connect(d->theme, SIGNAL(sizeChanged()),
this, SLOT(sizeChanged()));
160 connect(d->theme, SIGNAL(error(QString)),
this, SLOT(scriptError(QString)));
165 d->theme->startKaramba();
168 void SkAppletScript::positionChanged()
170 QPointF p = applet()->pos();
193 applet()->moveBy(p.x(),p.y());
202 void SkAppletScript::sizeChanged()
204 QRectF r = d->theme->boundingRect();
207 applet()->setMinimumSize(s);
211 void SkAppletScript::scriptError(
const QString& err)
217 QSizeF SkAppletScript::contentSizeHint()
const
220 return Plasma::AppletScript::contentSizeHint();
221 QRectF r = d->theme->boundingRect();
229 if( d->errors.count() > 0 ) {
230 QColor fontcolor = KColorScheme(QPalette::Active, KColorScheme::View, Plasma::Theme::defaultTheme()->colorScheme()).foreground().color();
231 painter->setPen(QPen(fontcolor));
233 painter->setRenderHint(QPainter::SmoothPixmapTransform);
234 painter->setRenderHint(QPainter::Antialiasing);
236 const QString title = i18n(
"Failed to launch SuperKaramba Theme");
239 titlefont.setBold(
true );
240 painter->setFont(titlefont);
242 QRect titlerect = painter->boundingRect(contentsRect, 0, title);
243 painter->drawText(titlerect, title, QTextOption());
245 QRect textrect = contentsRect;
246 textrect.setY( titlerect.y() + titlerect.height() + 4 );
248 const QString text = d->errors.join( QLatin1String(
"\n" ));
251 textfont.setPointSize( KGlobalSettings::smallestReadableFont().pointSize() );
252 painter->setFont(textfont);
254 QTextOption textopts;
255 textopts.setWrapMode(QTextOption::WrapAnywhere);
256 painter->drawText(textrect, text, textopts);
264 if( d->appletadaptor ) {
265 d->appletadaptor->paintInterface(painter, option, contentsRect);
277 if( constraints & Plasma::FormFactorConstraint ) {
279 if( ! applet()->isContainment() ) {
280 applet()->setDrawStandardBackground(
false);
285 if( constraints & Plasma::SizeConstraint ) {
287 const QRectF r = d->theme->boundingRect();
288 const QSizeF s = applet()->geometry().size();
289 const qreal x = s.width() / r.width();
290 const qreal y = s.height() / r.height();
292 QTransform t = d->theme->transform();
294 d->theme->setTransform(t.scale(x, y));
299 if( constraints & Plasma::ImmutableConstraint ) {
300 Q_ASSERT( applet() );
306 if( applet()->drawStandardBackground() && d->theme ) {
309 applet()->resize( d->theme->boundingRect().size() );
323 if( d->theme && d->theme == group ) {
324 kDebug()<<
">>>>>>>>>>>> SkAppletScript::karambaStarted theme-name="<<d->theme->theme().name();
326 if( applet()->isContainment() ) {
327 Plasma::Containment *c =
dynamic_cast<Plasma::Containment *
>(applet());
329 foreach(Plasma::Applet* a, c->applets()) {
334 applet()->resize(d->theme->boundingRect().size());
335 applet()->updateConstraints(Plasma::SizeConstraint);
341 if( d->theme && d->theme == group ) {
342 kDebug()<<
">>>>>>>>>>>> SkAppletScript::karambaClosed theme-name="<<d->theme->theme().name();
345 Q_ASSERT( applet() );
346 Q_ASSERT( applet()->scene() );
353 bool SkAppletScript::eventFilter(
QObject* watched, QEvent* event)
355 switch( event->type() ) {
356 case QEvent::ContextMenu: {
357 kDebug() <<
"eventFilter type=ContextMenu watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) :
"NULL") ;
360 case QEvent::GraphicsSceneContextMenu:
361 kDebug() <<
"eventFilter type=GraphicsSceneContextMenu watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) :
"NULL") ;
364 case QEvent::KeyPress:
365 kDebug() <<
"eventFilter type=KeyPress watched=" << (watched ? QString(
"%1 [%2]").arg(watched->objectName()).arg(watched->metaObject()->className()) :
"NULL") ;
372 return Plasma::AppletScript::eventFilter(watched, event);
375 #include "skappletscript.moc"
virtual void paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
Called when the applet should be painted.
virtual QList< QAction * > contextualActions()
Returns a list of context-related QAction instances.
The SkContainmentAdaptor class extends the SkAppletAdaptor class to implements an adaptor for Plasma:...
virtual ~SkAppletScript()
Destructor.
virtual void showConfigurationInterface()
Shows the configuration dialog for general SkAppletScript settings.
static KarambaManager * self()
The SkAppletScript class implements a Plasma::AppletScript to implement a Plasma::ScriptEngine for Su...
SkAppletScript(QObject *parent, const QVariantList &args)
Constructor.
virtual void constraintsEvent(Plasma::Constraints constraints)
Called when any of the geometry constraints have been updated.
virtual bool init()
Called when it is safe to initialize the internal state.
The SkAppletAdaptor class implements an adaptor for Plasma::Applet objects.