00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "karambainterface.h"
00022 #include "karambainterface.moc"
00023
00024 #include "karamba.h"
00025 #include "karambaapp.h"
00026 #include "lineparser.h"
00027 #include "showdesktop.h"
00028 #include "karambamanager.h"
00029
00030 #include <QGraphicsScene>
00031 #include <QNetworkInterface>
00032 #include <QTimer>
00033 #include <QDomDocument>
00034 #include <QFileInfo>
00035 #include <QDesktopWidget>
00036
00037 #include <KMenu>
00038 #include <KDebug>
00039 #include <KConfigGroup>
00040 #include <KService>
00041 #include <KServiceGroup>
00042 #include <KLocale>
00043 #include <KMessageBox>
00044 #include <KCmdLineArgs>
00045 #include <KAboutData>
00046 #include <KIconLoader>
00047
00049 class KarambaInterface::Private
00050 {
00051 public:
00058 Karamba *karamba;
00059
00064 Kross::Action *action;
00065
00066 Private(Karamba *k) : karamba(k), action(0) {}
00067 };
00068
00069 KarambaInterface::KarambaInterface(Karamba *k)
00070 : QObject()
00071 , d(new Private(k))
00072 {
00073 setObjectName("karamba");
00074 }
00075
00076 KarambaInterface::~KarambaInterface()
00077 {
00078 delete d;
00079 }
00080
00081 void KarambaInterface::startInterpreter()
00082 {
00083 d->action->trigger();
00084 }
00085
00086 bool KarambaInterface::initInterpreter()
00087 {
00088 const ThemeFile &theme = d->karamba->theme();
00089
00090
00091 QDir scriptDir;
00092 if (theme.isZipTheme()) {
00093 scriptDir = theme.extractArchive();
00094 } else {
00095 scriptDir = theme.path();
00096 }
00097
00098 QString interpreter = Kross::Manager::self().interpreternameForFile(theme.scriptModule());
00099 if (interpreter.isEmpty()) {
00100 KMessageBox::sorry(0, i18n(
00101 "SuperKaramba cannot continue to run this theme."
00102 "One or more of the required components of the Kross scripting architecture is not installed. "
00103 "Please consult this theme's documentation and install the necessary Kross components."),
00104 i18n("Please install additional Kross components"));
00105 return false;
00106 }
00107
00108
00109 QFileInfo fi(scriptDir, theme.scriptModule());
00110 if (fi.exists() && !interpreter.isEmpty()) {
00111 QString scriptFile = fi.absoluteFilePath();
00112
00113
00114 d->action = new Kross::Action(this, scriptFile, fi.dir());
00115
00116
00117
00118 d->action->setInterpreter(interpreter);
00119
00120
00121
00122
00123 d->action->addObject(this, "karamba", Kross::ChildrenInterface::AutoConnectSignals);
00124
00125
00126
00127
00128 if( QObject* appletadaptor = d->karamba->findChild<QObject*>("PlasmaApplet") ) {
00129 d->action->addObject(appletadaptor);
00130 }
00131
00132
00133
00134
00135
00136
00137 if (interpreter == "python") {
00138 d->action->setCode(QString(
00139 "import karamba, sys\n"
00140 "sys.path.insert(0, karamba.getThemePath())\n"
00141 "sys.path.insert(0, '')\n"
00142 "execfile(\"%1\", globals(), locals())\n"
00143 ).arg(scriptFile).toLatin1());
00144 } else {
00145 d->action->setFile(scriptFile);
00146 }
00147
00148 kDebug() << "Using " << interpreter << " script: " << scriptFile ;
00149
00150 return true;
00151 }
00152
00153 return false;
00154 }
00155
00156
00157
00158 bool KarambaInterface::checkKaramba(const Karamba *k) const
00159 {
00160 if (!k) {
00161 kWarning() << "Widget pointer was 0" ;
00162 return false;
00163 }
00164
00165 if (!KarambaManager::self()->checkKaramba(k)) {
00166 kWarning() << "Widget " << (long)k << " invalid" ;
00167 return false;
00168 }
00169
00170 return true;
00171 }
00172
00173 bool KarambaInterface::checkMeter(const Karamba *k, const Meter *m, const QString &type) const
00174 {
00175 if (!m) {
00176 kWarning() << "Meter pointer was 0";
00177 return false;
00178 }
00179
00180 if (!k->hasMeter(m)) {
00181 kWarning() << "Widget does not have meter" << (long)m;
00182 return false;
00183 }
00184
00185 if (!m->inherits(type.toAscii().data())) {
00186 kWarning() << "Meter is not of type" << type;
00187 return false;
00188 }
00189
00190 return true;
00191 }
00192
00193 bool KarambaInterface::checkKarambaAndMeter(const Karamba *k, const Meter *m, const QString &type)
00194 const
00195 {
00196 return checkKaramba(k) && checkMeter(k, m, type);
00197 }
00198
00199 QVariantList KarambaInterface::getMeterMinMax(const Karamba *k, const Meter *m, const QString &type)
00200 const
00201 {
00202 if (!checkKarambaAndMeter(k, m, type)) {
00203 return QVariantList();
00204 }
00205
00206 QVariantList ret;
00207 ret << m->getMax();
00208 ret << m->getMin();
00209 return ret;
00210 }
00211
00212 QVariantList KarambaInterface::getMeterSize(const Karamba *k, const Meter *m, const QString &type)
00213 const
00214 {
00215 if (!checkKarambaAndMeter(k, m, type)) {
00216 return QVariantList();
00217 }
00218
00219 QVariantList list;
00220 list << QVariant::fromValue(m->getWidth());
00221 list << QVariant::fromValue(m->getHeight());
00222 return list;
00223 }
00224
00225 QVariantList KarambaInterface::getMeterPos(const Karamba *k, const Meter *m, const QString &type)
00226 const
00227 {
00228 if (!checkKarambaAndMeter(k, m, type)) {
00229 return QVariantList();
00230 }
00231
00232 QVariantList ret;
00233 ret << QVariant::fromValue(m->getX());
00234 ret << QVariant::fromValue(m->getY());
00235 return ret;
00236 }
00237
00238 QString KarambaInterface::getMeterSensor(const Karamba *k, const Meter *m, const QString &type)
00239 const
00240 {
00241 if (!checkKarambaAndMeter(k, m, type)) {
00242 return QString();
00243 }
00244
00245 return k->getSensor(m);
00246
00247 }
00248
00249 int KarambaInterface::getMeterValue(const Karamba *k, const Meter *m, const QString &type) const
00250 {
00251 if (!checkKarambaAndMeter(k, m, type)) {
00252 return 0;
00253 }
00254
00255 return m->getValue();
00256 }
00257
00258 QObject* KarambaInterface::getThemeMeter(const Karamba *k, const QString &meter, const QString
00259 &type) const
00260 {
00261 if (!checkKaramba(k)) {
00262 return 0;
00263 }
00264
00265 QGraphicsItem *item;
00266 QList<QGraphicsItem*> list = ((QGraphicsItemGroup*)k)->children();
00267 foreach(item, list) {
00268 Meter *m = (Meter*)item;
00269 if (m->objectName() == meter) {
00270 if (checkMeter(k, m, type)) {
00271 return m;
00272 }
00273 }
00274 }
00275
00276 return 0;
00277 }
00278
00279 bool KarambaInterface::hideMeter(const Karamba *k, Meter *m, const QString &type) const
00280 {
00281 if (!checkKarambaAndMeter(k, m, type)) {
00282 return false;
00283 }
00284
00285 m->hide();
00286
00287 return true;
00288 }
00289
00290 bool KarambaInterface::moveMeter(const Karamba *k, Meter *m, const QString &type, int x, int y)
00291 const
00292 {
00293 if (!checkKarambaAndMeter(k, m, type)) {
00294 return false;
00295 }
00296
00297 k->moveMeter(m, x, y);
00298
00299 return true;
00300 }
00301
00302 bool KarambaInterface::resizeMeter(const Karamba *k, Meter *m, const QString &type, int width, int
00303 height) const
00304 {
00305 if (!checkKarambaAndMeter(k, m, type)) {
00306 return false;
00307 }
00308
00309 m->setSize(m->getX(), m->getY(), width, height);
00310
00311 return true;
00312 }
00313
00314 bool KarambaInterface::setMeterMinMax(const Karamba *k, Meter *m, const QString &type, int min, int max)
00315 const
00316 {
00317 if (!checkKarambaAndMeter(k, m, type)) {
00318 return false;
00319 }
00320
00321 m->setMin(min);
00322 m->setMax(max);
00323
00324 return true;
00325 }
00326
00327 bool KarambaInterface::setMeterSensor(Karamba *k, Meter *m, const QString &type,
00328 const QString &sensor) const
00329 {
00330 if (!checkKarambaAndMeter(k, m, type)) {
00331 return false;
00332 }
00333
00334 k->setSensor(LineParser(sensor), m);
00335
00336 return true;
00337 }
00338
00339 QObject* KarambaInterface::setMeterValue(const Karamba *k, Meter *m, const QString &type, int value)
00340 const
00341 {
00342 if (!checkKarambaAndMeter(k, m, type)) {
00343 return 0;
00344 }
00345
00346 m->setValue(value);
00347
00348 return m;
00349 }
00350
00351 bool KarambaInterface::showMeter(const Karamba *k, Meter *m, const QString &type) const
00352 {
00353 if (!checkKarambaAndMeter(k, m, type)) {
00354 return false;
00355 }
00356
00357 m->show();
00358
00359 return true;
00360 }
00361
00362 bool KarambaInterface::setMeterColor(const Karamba *k, Meter *m, const QString &type, int red, int
00363 green, int blue, int alpha) const
00364 {
00365 if (!checkKarambaAndMeter(k, m, type)) {
00366 return false;
00367 }
00368
00369 m->setColor(QColor(red, green, blue, alpha));
00370
00371 return true;
00372 }
00373
00374 QVariantList KarambaInterface::getMeterColor(const Karamba *k, const Meter *m, const QString &type)
00375 const
00376 {
00377 if (!checkKarambaAndMeter(k, m, type)) {
00378 return QVariantList();
00379 }
00380
00381 QColor color = m->getColor();
00382
00383 QVariantList ret;
00384 ret << color.red();
00385 ret << color.green();
00386 ret << color.blue();
00387 ret << color.alpha();
00388
00389 return ret;
00390 }
00391
00392 QString KarambaInterface::getMeterStringValue(const Karamba *k, const Meter *m, const QString &type)
00393 const
00394 {
00395 if (!checkKarambaAndMeter(k, m, type)) {
00396 return QString();
00397 }
00398
00399 return m->getStringValue();
00400 }
00401
00402 QObject* KarambaInterface::setMeterStringValue(const Karamba *k, Meter *m, const QString &type,
00403 const QString &value) const
00404 {
00405 if (!checkKarambaAndMeter(k, m, type)) {
00406 return 0;
00407 }
00408
00409 m->setValue(value);
00410
00411 return m;
00412 }
00413
00414
00415
00416 void KarambaInterface::callInitWidget(Karamba *k)
00417 {
00418 emit initWidget(k);
00419 }
00420
00421 void KarambaInterface::callWidgetUpdated(Karamba *k)
00422 {
00423 emit widgetUpdated(k);
00424 }
00425
00426 void KarambaInterface::callWidgetClosed(Karamba *k)
00427 {
00428 emit widgetClosed(k);
00429 }
00430
00431 void KarambaInterface::callMenuOptionChanged(Karamba *k, const QString &key, bool value)
00432 {
00433 emit menuOptionChanged(k, key, value);
00434 }
00435
00436 void KarambaInterface::callMenuItemClicked(Karamba* k, KMenu* menu, QAction *id)
00437 {
00438 emit menuItemClicked(k, menu, id);
00439 }
00440
00441 void KarambaInterface::callActiveTaskChanged(Karamba *k, Task* t)
00442 {
00443 emit activeTaskChanged(k, t);
00444 }
00445
00446 void KarambaInterface::callTaskAdded(Karamba *k, Task *t)
00447 {
00448 emit taskAdded(k, t);
00449 }
00450
00451 void KarambaInterface::callTaskRemoved(Karamba *k, Task *t)
00452 {
00453 emit taskRemoved(k, t);
00454 }
00455
00456 void KarambaInterface::callStartupAdded(Karamba *k, Startup *t)
00457 {
00458 emit startupAdded(k, t);
00459 }
00460
00461 void KarambaInterface::callStartupRemoved(Karamba *k, Startup *t)
00462 {
00463 emit startupRemoved(k, t);
00464 }
00465
00466 void KarambaInterface::callCommandFinished(Karamba *k, int pid)
00467 {
00468 emit commandFinished(k, pid);
00469 }
00470
00471 void KarambaInterface::callCommandOutput(Karamba *k, int pid, char* buffer)
00472 {
00473 emit commandOutput(k, pid, QString(buffer));
00474 }
00475
00476 void KarambaInterface::callItemDropped(Karamba *k, const QString &text, int x, int y)
00477 {
00478 emit itemDropped(k, text, x, y);
00479 }
00480
00481 void KarambaInterface::callMeterClicked(Karamba *k, Meter *m, int button)
00482 {
00483 emit meterClicked(k, m, button);
00484 }
00485
00486 void KarambaInterface::callMeterClicked(Karamba *k, const QString &str, int button)
00487 {
00488 emit meterClicked(k, str, button);
00489 }
00490
00491 void KarambaInterface::callWidgetClicked(Karamba *k, int x, int y, int button)
00492 {
00493 emit widgetClicked(k, x, y, button);
00494 }
00495
00496 void KarambaInterface::callDesktopChanged(Karamba *k, int desktop)
00497 {
00498 emit desktopChanged(k, desktop);
00499 }
00500
00501 void KarambaInterface::callWidgetMouseMoved(Karamba *k, int x, int y, int button)
00502 {
00503 emit widgetMouseMoved(k, x, y, button);
00504 }
00505
00506 void KarambaInterface::callKeyPressed(Karamba *k, Meter *meter, const QString &key)
00507 {
00508 emit keyPressed(k, meter, key);
00509 }
00510
00511 void KarambaInterface::callThemeNotify(Karamba *k, const QString &sender, const QString &data)
00512 {
00513 emit themeNotify(k, sender, data);
00514 }
00515
00516 void KarambaInterface::callWallpaperChanged(Karamba *k, int desktop)
00517 {
00518 emit wallpaperChanged(k, desktop);
00519 }
00520
00521
00522
00523
00540 QObject* KarambaInterface::createBar(Karamba* k, int x, int y, int w, int h, const QString &path)
00541 const
00542 {
00543 if (!checkKaramba(k)) {
00544 return NULL;
00545 }
00546
00547 Bar *tmp = new Bar(k, x, y, w, h);
00548 tmp->setImage(path);
00549 tmp->setValue(50);
00550 k->addToGroup(tmp);
00551
00552 return tmp;
00553 }
00554
00567 bool KarambaInterface::deleteBar(Karamba *k, Bar *bar) const
00568 {
00569 if (!checkKarambaAndMeter(k, bar, "Bar")) {
00570 return false;
00571 }
00572
00573 return k->removeMeter(bar);
00574 }
00575
00590 bool KarambaInterface::setBarMinMax(const Karamba *k, Bar *bar, int min, int max) const
00591 {
00592 return setMeterMinMax(k, bar, "Bar", min, max);
00593 }
00594
00607 QVariantList KarambaInterface::getBarMinMax(const Karamba *k, const Bar *bar) const
00608 {
00609 return getMeterMinMax(k, bar, "Bar");
00610 }
00611
00626 bool KarambaInterface::moveBar(const Karamba *k, Bar *bar, int x, int y) const
00627 {
00628 return moveMeter(k, bar, "Bar", x, y);
00629 }
00630
00644 QVariantList KarambaInterface::getBarPos(const Karamba *k, const Bar *bar) const
00645 {
00646 return getMeterPos(k, bar, "Bar");
00647 }
00648
00662 bool KarambaInterface::setBarSensor(Karamba *k, Bar *bar, const QString &sensor) const
00663 {
00664 return setMeterSensor(k, bar, "Bar", sensor);
00665 }
00666
00679 QString KarambaInterface::getBarSensor(const Karamba *k, const Bar *bar) const
00680 {
00681 return getMeterSensor(k, bar, "Bar");
00682 }
00683
00698 bool KarambaInterface::resizeBar(const Karamba *k, Bar *bar, int width, int height) const
00699 {
00700 return resizeMeter(k, bar, "Bar", width, height);
00701 }
00702
00716 QVariantList KarambaInterface::getBarSize(const Karamba *k, const Bar *bar) const
00717 {
00718 return getMeterSize(k, bar, "Bar");
00719 }
00720
00734 QObject* KarambaInterface::setBarValue(const Karamba *k, Bar *bar, int value) const
00735 {
00736 return setMeterValue(k, bar, "Bar", value);
00737 }
00738
00751 int KarambaInterface::getBarValue(const Karamba *k, const Bar *bar) const
00752 {
00753 return getMeterValue(k, bar, "Bar");
00754 }
00755
00774 QObject* KarambaInterface::getThemeBar(const Karamba *k, const QString &meter) const
00775 {
00776 return getThemeMeter(k, meter, "Bar");
00777 }
00778
00792 bool KarambaInterface::hideBar(const Karamba *k, Bar *bar) const
00793 {
00794 return hideMeter(k, bar, "Bar");
00795 }
00796
00810 bool KarambaInterface::showBar(const Karamba *k, Bar *bar) const
00811 {
00812 return showMeter(k, bar, "Bar");
00813 }
00814
00828 bool KarambaInterface::setBarVertical(const Karamba *k, Bar *bar, bool vert) const
00829 {
00830 if (!checkKarambaAndMeter(k, bar, "Bar")) {
00831 return false;
00832 }
00833
00834 bar->setVertical(vert);
00835 return true;
00836 }
00837
00850 bool KarambaInterface::getBarVertical(const Karamba *k, const Bar *bar) const
00851 {
00852 if (!checkKarambaAndMeter(k, bar, "Bar")) {
00853 return false;
00854 }
00855
00856 return bar->getVertical();
00857 }
00858
00872 bool KarambaInterface::setBarImage(const Karamba *k, Bar *bar, const QString &image) const
00873 {
00874 if (!checkKarambaAndMeter(k, bar, "Bar")) {
00875 return false;
00876 }
00877
00878 return bar->setImage(image);
00879 }
00880
00893 QString KarambaInterface::getBarImage(const Karamba *k, const Bar *bar) const
00894 {
00895 if (!checkKarambaAndMeter(k, bar, "Bar")) {
00896 return QString();
00897 }
00898
00899 return bar->getImage();
00900 }
00901
00902
00903
00904
00921 QObject* KarambaInterface::createGraph(Karamba* k, int x, int y, int w, int h, int points) const
00922 {
00923 if (!checkKaramba(k)) {
00924 return NULL;
00925 }
00926
00927 Graph *tmp = new Graph(k, x, y, w, h, points);
00928 k->addToGroup(tmp);
00929
00930 return tmp;
00931 }
00932
00945 bool KarambaInterface::deleteGraph(Karamba *k, Graph *graph) const
00946 {
00947 if (!checkKarambaAndMeter(k, graph, "Graph")) {
00948 return false;
00949 }
00950
00951 return k->removeMeter(graph);
00952 }
00953
00968 bool KarambaInterface::setGraphMinMax(const Karamba *k, Graph *graph, int min, int max) const
00969 {
00970 return setMeterMinMax(k, graph, "Graph", min, max);
00971 }
00972
00985 QVariantList KarambaInterface::getGraphMinMax(const Karamba *k, const Graph *graph) const
00986 {
00987 return getMeterMinMax(k, graph, "Graph");
00988 }
00989
01004 bool KarambaInterface::moveGraph(const Karamba *k, Graph *graph, int x, int y) const
01005 {
01006 return moveMeter(k, graph, "Graph", x, y);
01007 }
01008
01022 QVariantList KarambaInterface::getGraphPos(const Karamba *k, const Graph *graph) const
01023 {
01024 return getMeterPos(k, graph, "Graph");
01025 }
01026
01040 bool KarambaInterface::setGraphSensor(Karamba *k, Graph *graph, const QString &sensor) const
01041 {
01042 return setMeterSensor(k, graph, "Graph", sensor);
01043 }
01044
01057 QString KarambaInterface::getGraphSensor(const Karamba *k, const Graph *graph) const
01058 {
01059 return getMeterSensor(k, graph, "Graph");
01060 }
01061
01076 bool KarambaInterface::resizeGraph(const Karamba *k, Graph *graph, int width, int height) const
01077 {
01078 return resizeMeter(k, graph, "Graph", width, height);
01079 }
01080
01094 QVariantList KarambaInterface::getGraphSize(const Karamba *k, const Graph *graph) const
01095 {
01096 return getMeterSize(k, graph, "Graph");
01097 }
01098
01112 QObject* KarambaInterface::setGraphValue(const Karamba *k, Graph *graph, int value) const
01113 {
01114 return setMeterValue(k, graph, "Graph", value);
01115 }
01116
01129 int KarambaInterface::getGraphValue(const Karamba *k, const Graph *graph) const
01130 {
01131 return getMeterValue(k, graph, "Graph");
01132 }
01133
01152 QObject* KarambaInterface::getThemeGraph(const Karamba *k, const QString &meter) const
01153 {
01154 return getThemeMeter(k, meter, "Graph");
01155 }
01156
01170 bool KarambaInterface::hideGraph(const Karamba *k, Graph *graph) const
01171 {
01172 return hideMeter(k, graph, "Graph");
01173 }
01174
01188 bool KarambaInterface::showGraph(const Karamba *k, Graph *graph) const
01189 {
01190 return showMeter(k, graph, "Graph");
01191 }
01192
01209 bool KarambaInterface::setGraphColor(const Karamba *k, Graph *graph, int red, int green, int blue, int alpha)
01210 const
01211 {
01212 return setMeterColor(k, graph, "Graph", red, green, blue, alpha);
01213 }
01214
01227 QVariantList KarambaInterface::getGraphColor(const Karamba *k, const Graph *graph) const
01228 {
01229 return getMeterColor(k, graph, "Graph");
01230 }
01231
01232
01233
01234
01235
01254 QObject* KarambaInterface::createImage(Karamba* k, int x, int y, const QString &image) const
01255 {
01256 if (!checkKaramba(k)) {
01257 return NULL;
01258 }
01259
01260 ImageLabel *tmp = new ImageLabel(k, x, y, 0, 0);
01261 tmp->setValue(image);
01262
01263 k->setSensor(LineParser(image), tmp);
01264
01265 k->addToGroup(tmp);
01266
01267 return tmp;
01268 }
01269
01287 QObject* KarambaInterface::createEmptyImage(Karamba* k, int x, int y, int w, int h) const
01288 {
01289 if (!checkKaramba(k)) {
01290 return NULL;
01291 }
01292
01293 ImageLabel *tmp = new ImageLabel(k, x, y, w, h);
01294
01295 k->addToGroup(tmp);
01296
01297 return tmp;
01298 }
01299
01314 bool KarambaInterface::deleteImage(Karamba *k, ImageLabel *image) const
01315 {
01316 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01317 return false;
01318 }
01319
01320 return k->removeMeter(image);
01321 }
01322
01340 bool KarambaInterface::moveImage(Karamba *k, ImageLabel *image, int x, int y) const
01341 {
01342 return moveMeter(k, image, "ImageLabel", x, y);
01343 }
01344
01358 QVariantList KarambaInterface::getImagePos(const Karamba *k, const ImageLabel *image) const
01359 {
01360 return getMeterPos(k, image, "ImageLabel");
01361 }
01362
01376 bool KarambaInterface::setImageSensor(Karamba *k, ImageLabel *image,
01377 const QString &sensor) const
01378 {
01379 return setMeterSensor(k, image, "ImageLabel", sensor);
01380 }
01381
01394 QString KarambaInterface::getImageSensor(const Karamba *k, const ImageLabel *image) const
01395 {
01396 return getMeterSensor(k, image, "ImageLabel");
01397 }
01398
01415 bool KarambaInterface::resizeImage(const Karamba *k, ImageLabel *image, int width, int height) const
01416 {
01417 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01418 return false;
01419 }
01420
01421 k->scaleImageLabel(image, width, height);
01422
01423 return true;
01424 }
01425
01439 QVariantList KarambaInterface::getImageSize(const Karamba *k, const ImageLabel *image) const
01440 {
01441 return getMeterSize(k, image, "ImageLabel");
01442 }
01443
01459 QObject* KarambaInterface::setImagePath(const Karamba *k, ImageLabel *image, const QString &path)
01460 const
01461 {
01462 return setMeterStringValue(k, image, "ImageLabel", path);
01463 }
01464
01477 QString KarambaInterface::getImagePath(const Karamba *k, const ImageLabel *image) const
01478 {
01479 return getMeterStringValue(k, image, "ImageLabel");
01480 }
01481
01500 QObject* KarambaInterface::getThemeImage(const Karamba *k, const QString &meter) const
01501 {
01502 return getThemeMeter(k, meter, "ImageLabel");
01503 }
01504
01518 bool KarambaInterface::hideImage(const Karamba *k, ImageLabel *image) const
01519 {
01520 return hideMeter(k, image, "ImageLabel");
01521 }
01522
01536 bool KarambaInterface::showImage(const Karamba *k, ImageLabel *image) const
01537 {
01538 return showMeter(k, image, "ImageLabel");
01539 }
01540
01559 bool KarambaInterface::addImageTooltip(const Karamba *k, ImageLabel *image, const QString &text)
01560 const
01561 {
01562 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01563 return false;
01564 }
01565
01566 image->setTooltip(text);
01567
01568 return true;
01569 }
01570
01587 bool KarambaInterface::changeImageChannelIntensity(const Karamba *k, ImageLabel *image, double
01588 ratio, const QString &channel, int ms) const
01589 {
01590 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01591 return false;
01592 }
01593
01594 image->channelIntensity(ratio, channel, ms);
01595
01596 return true;
01597 }
01598
01619 bool KarambaInterface::changeImageIntensity(const Karamba *k, ImageLabel *image, double ratio, int
01620 ms) const
01621 {
01622 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01623 return false;
01624 }
01625
01626 image->intensity(ratio, ms);
01627
01628 return true;
01629 }
01630
01647 bool KarambaInterface::changeImageToGray(const Karamba *k, ImageLabel *image, int ms) const
01648 {
01649 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01650 return false;
01651 }
01652
01653 image->toGray(ms);
01654
01655 return true;
01656 }
01657
01683 bool KarambaInterface::changeImageAlpha(const Karamba *k, ImageLabel *image, int a, int r, int g, int b, int ms) const
01684 {
01685 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01686 return false;
01687 }
01688
01689 image->toAlpha(QColor(r, g, b), a, ms);
01690
01691 return true;
01692 }
01693
01712 QObject* KarambaInterface::createBackgroundImage(Karamba *k, int x, int y, const QString &imagePath)
01713 const
01714 {
01715 if (!checkKaramba(k)) {
01716 return 0;
01717 }
01718
01719 ImageLabel *tmp = new ImageLabel(k, x, y, 0, 0);
01720 tmp->setValue(imagePath);
01721 tmp->setBackground(true);
01722 tmp->setZValue(-1);
01723
01724 k->setSensor(LineParser(imagePath), tmp);
01725
01726 k->addToGroup(tmp);
01727
01728 return tmp;
01729 }
01730
01745 QObject* KarambaInterface::createTaskIcon(Karamba *k, int x, int y, int ctask) const
01746 {
01747 if (!checkKaramba(k)) {
01748 return NULL;
01749 }
01750
01751 QList<Task::TaskPtr> tasks = TaskManager::self()->tasks().values();
01752 Task::TaskPtr task;
01753 Task::TaskPtr currTask;
01754 foreach(task, tasks) {
01755 if ((long)task.data() == (long)ctask) {
01756
01757 currTask = task;
01758 break;
01759 }
01760 }
01761
01762 if (currTask.isNull()) {
01763 return 0;
01764 }
01765
01766
01767 QPixmap iconPixmap = KWindowSystem::icon(currTask->window());
01768
01769 ImageLabel *tmp = new ImageLabel(k, x, y, 0, 0);
01770 tmp->setValue(iconPixmap);
01771
01772 k->addToGroup(tmp);
01773
01774 return tmp;
01775 }
01776
01790 int KarambaInterface::getImageHeight(const Karamba *k, const ImageLabel *image) const
01791 {
01792 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01793 return -1;
01794 }
01795
01796 return image->getHeight();
01797 }
01798
01812 int KarambaInterface::getImageWidth(const Karamba *k, const ImageLabel *image) const
01813 {
01814 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01815 return -1;
01816 }
01817
01818 return image->getWidth();
01819 }
01820
01835 bool KarambaInterface::removeImageEffects(const Karamba *k, ImageLabel *image) const
01836 {
01837 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01838 return false;
01839 }
01840
01841 image->removeEffects();
01842
01843 return true;
01844 }
01845
01859 bool KarambaInterface::removeImageTransformations(const Karamba *k, ImageLabel *image) const
01860 {
01861 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01862 return false;
01863 }
01864
01865 image->removeImageTransformations();
01866
01867 return true;
01868 }
01869
01889 bool KarambaInterface::resizeImageSmooth(Karamba *k, ImageLabel *image, int width, int height)
01890 const
01891 {
01892 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01893 return false;
01894 }
01895
01896 k->scaleImageLabel(image, width, height);
01897
01898 return true;
01899 }
01900
01916 bool KarambaInterface::rotateImage(const Karamba *k, ImageLabel *image, int deg) const
01917 {
01918 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01919 return false;
01920 }
01921
01922 image->rotate(deg);
01923
01924 return true;
01925 }
01926
01948 bool KarambaInterface::setPixel(Karamba *k, ImageLabel *image, int x, int y, int r, int g, int b, int a)
01949 {
01950 if (!checkKarambaAndMeter(k, image, "ImageLabel")) {
01951 return false;
01952 }
01953
01954 image->setPixel(QPoint(x, y), QColor(r,g,b,a));
01955
01956 return true;
01957 }
01958