27#include <kpixmapeffect.h>
29#include <kimageeffect.h>
30#include <tdetempfile.h>
32#include "karambaapp.h"
33#include "imagelabel.h"
36Effect::Effect(ImageLabel* img,
int msec) :
56void Effect::startTimer()
60 TQTimer::singleShot (millisec, myImage, TQ_SLOT(slotEffectExpired()));
66Intensity::Intensity(ImageLabel* img,
float r,
int millisec) :
70 ratio = (ratio > 1) ? 1 : ratio;
71 ratio = (ratio < -1) ? -1 : ratio;
74KPixmap Intensity::apply(KPixmap pixmap)
76 return KPixmapEffect::intensity(pixmap, ratio);
80ChannelIntensity::ChannelIntensity(ImageLabel* img,
float r, TQString c,
85 ratio = (ratio > 1) ? 1 : ratio;
86 ratio = (ratio < -1) ? -1 : ratio;
89 if (c.find(
"red", 0 ,
false))
93 else if (c.find(
"green", 0,
false))
97 else if (c.find(
"blue", 0,
false))
103KPixmap ChannelIntensity::apply(KPixmap pixmap)
105 return KPixmapEffect::channelIntensity(pixmap, ratio,
106 (KPixmapEffect::RGBComponent)channel);
110ToGray::ToGray(ImageLabel* img,
int millisec) : Effect(img, millisec)
114KPixmap ToGray::apply(KPixmap pixmap)
116 return KPixmapEffect::toGray(pixmap);
121ImageLabel::ImageLabel(karamba* k,
int ix,
int iy,
int iw,
int ih) :
122 Meter(k, ix,iy,iw,ih), zoomed(false), rollover(false)
138ImageLabel::ImageLabel(karamba* k) :
139 Meter(k), zoomed(false), rollover(false)
145ImageLabel::~ImageLabel()
147 if (imageEffect != 0)
152 if(!old_tip_rect.isNull())
154 TQToolTip::remove(m_karamba, old_tip_rect);
158void ImageLabel::setValue(
long v)
160 setValue( TQString::number( v ) );
163void ImageLabel::show()
169void ImageLabel::hide()
175void ImageLabel::rotate(
int deg)
177 doRotate = !(deg == 0);
181 applyTransformations();
184void ImageLabel::scale(
int w,
int h)
186 doScale = !(w == realpixmap.width() && h == realpixmap.height());
191 applyTransformations();
194void ImageLabel::smoothScale(
int w,
int h)
196 doScale = !(w == realpixmap.width() && h == realpixmap.height());
201 applyTransformations(
true);
213void ImageLabel::removeImageTransformations()
224void ImageLabel::applyTransformations(
bool useSmoothScale)
231 rotMat.rotate(rot_angle);
232 pixmap = pixmap.xForm(rotMat);
236 if (m_karamba -> useSmoothTransforms() || useSmoothScale)
238 pixmap.convertFromImage(
239 pixmap.convertToImage().smoothScale(scale_w, scale_h));
243 double widthFactor = ((double)scale_w) / ((double)pixmap.width());
244 double heightFactor = ((double)scale_h) / ((double)pixmap.height());
246 scaleMat.scale(widthFactor, heightFactor);
247 pixmap = pixmap.xForm(scaleMat);
250 if (imageEffect != 0)
252 pixmap = imageEffect -> apply(pixmap);
254 setWidth(pixmap.width());
255 setHeight(pixmap.height());
258void ImageLabel::slotCopyResult(TDEIO::Job* job)
260 TQString tempFile = ((TDEIO::FileCopyJob*)job)->destURL().path();
261 if(job->error() == 0)
264 imagePath = ((TDEIO::FileCopyJob*)job)->srcURL().path();
269 tqWarning(
"Error downloading (%s): %s", job->errorText().ascii(),
272 TDEIO::NetAccess::removeTempFile(tempFile);
275void ImageLabel::setValue(TQString fn)
278 TQStringList sList = TQStringList::split(
"\n", fn );
279 TQString fileName = *sList.begin();
281 TQRegExp rx(
"^[a-zA-Z]{1,5}:/",
false);
282 bool protocol = (rx.search(fileName)!=-1)?
true:
false;
285 if(protocol && url.isLocalFile() ==
false)
288 TDEIO::FileCopyJob* copy = TDEIO::file_copy(fileName, tmpFile.name(), 0600,
290 connect(copy, TQ_SIGNAL(result(TDEIO::Job*)),
291 this, TQ_SLOT(slotCopyResult(TDEIO::Job*)));
296 if(m_karamba->theme().isThemeFile(fileName))
298 TQByteArray ba = m_karamba->theme().readThemeFile(fileName);
305 imagePath = fileName;
314void ImageLabel::setValue(TQPixmap& pix)
316 realpixmap = KPixmap(pix);
318 setWidth(pixmap.width());
319 setHeight(pixmap.height());
321 pixmapWidth = pixmap.width();
322 pixmapHeight = pixmap.height();
323 rect_off = TQRect(getX(),getY(),pixmapWidth,pixmapHeight);
326void ImageLabel::mUpdate(TQPainter* p,
int backgroundUpdate)
328 if (backgroundUpdate == 1)
335 p->drawPixmap(getX(),getY(),pixmap);
340 TQImage image = pixmap.convertToImage();
342 TQImage result = KImageEffect::blend(TQColor(255,0,0), image, 0.5f);
343 p->drawImage(getX(),getY(),result);
349 if (imageEffect != 0)
351 imageEffect -> startTimer();
356void ImageLabel::mUpdate(TQPainter* p)
359 if (hidden == 0 && background == 0)
364 p->drawPixmap(getX(),getY(),pixmap);
370 TQImage image = pixmap.convertToImage();
372 TQImage result = KImageEffect::blend(TQColor(255,0,0), image, 0.5f);
373 p->drawImage(getX(),getY(),result);
379 if (imageEffect != 0)
381 imageEffect -> startTimer();
385bool ImageLabel::click(TQMouseEvent* e)
387 if (getBoundingBox().contains(e -> x(), e -> y()) && isEnabled())
390 if (e -> button() == TQt::LeftButton)
392 program = leftButtonAction;
394 else if (e -> button() == TQt::MidButton)
396 program = middleButtonAction;
398 else if (e -> button() == TQt::RightButton)
400 program = rightButtonAction;
403 if( !program.isEmpty() )
405 KRun::runCommand(program);
415void ImageLabel::parseImages(TQString fn, TQString fn_roll,
int _xoff,
416 int _yoff,
int _xon,
int _yon)
427 TQStringList sList = TQStringList::split(
"\n", fn );
428 TQString fileName = *sList.begin();
429 TQFileInfo fileInfo( fileName );
432 TQRegExp rx(
"^http://",
false);
433 bool fileOnNet = (rx.search(fileName)!=-1)?
true:
false;
436 if( fileInfo.isRelative() && !fileOnNet )
438 path = m_karamba->theme().path() +
"/" + fileName;
449 if(TDEIO::NetAccess::download(KURL(path), tmpFile, karambaApp->parentWindow()))
451 if(TDEIO::NetAccess::download(KURL(path), tmpFile))
454 pixmap_off = KPixmap(tmpFile);
455 TDEIO::NetAccess::removeTempFile(tmpFile);
456 tqDebug(
"Downloaded: %s to %s", path.ascii(), tmpFile.ascii() );
460 tqDebug(
"Error Downloading: %s", path.ascii());
465 pixmap_off = KPixmap( path );
468 pixmapOffWidth = pixmap.width();
469 pixmapOffHeight = pixmap.height();
471 rect_off = TQRect(xoff,yoff,pixmapWidth,pixmapHeight);
473 if (fn_roll.isEmpty())
477 sList = TQStringList::split(
"\n", fn_roll );
478 fileName = *sList.begin();
479 fileInfo = TQFileInfo( fileName );
481 fileOnNet = (rx.search(fileName)!=-1)?
true:
false;
484 if( fileInfo.isRelative() && !fileOnNet )
486 path = m_karamba->theme().path() +
"/" + fileName;
497 if(TDEIO::NetAccess::download(KURL(path), tmpFile, karambaApp->parentWindow()))
499 if(TDEIO::NetAccess::download(KURL(path), tmpFile))
502 pixmap_on = KPixmap(tmpFile);
503 TDEIO::NetAccess::removeTempFile(tmpFile);
504 tqDebug(
"Downloaded: %s to %s", path.ascii(), tmpFile.ascii());
508 tqDebug(
"Error Downloading: %s", path.ascii());
513 pixmap_on = KPixmap( path );
515 pixmapOnWidth = pixmap_on.width();
516 pixmapOnHeight = pixmap_on.height();
518 rect_on = TQRect(xon,yon,pixmapOnWidth,pixmapOnHeight);
521void ImageLabel::setBackground(
int b)
526void ImageLabel::rolloverImage(TQMouseEvent *e)
533 if (!rect_off.contains(e->pos()))
540 pixmapWidth = pixmapOffWidth;
541 pixmapHeight = pixmapOffHeight;
548 if (rect_off.contains(e->pos()))
555 pixmapWidth = pixmapOnWidth;
556 pixmapHeight = pixmapOnHeight;
563void ImageLabel::setTooltip(TQString txt)
565 TQRect rect(getX(),getY(),pixmapWidth,pixmapHeight);
566 TQToolTip::add(m_karamba, rect, txt);
567 old_tip_rect = TQRect(rect.topLeft(), rect.bottomRight());
571void ImageLabel::removeEffects()
573 if (imageEffect != 0)
578 applyTransformations();
581void ImageLabel::intensity(
float ratio,
int millisec)
583 if (imageEffect != 0)
589 imageEffect =
new Intensity(
this, ratio, millisec);
590 applyTransformations();
593void ImageLabel::channelIntensity(
float ratio, TQString channel,
int millisec)
595 if (imageEffect != 0)
601 imageEffect =
new ChannelIntensity(
this, ratio, channel, millisec);
602 applyTransformations();
605void ImageLabel::toGray(
int millisec)
607 if (imageEffect != 0)
613 imageEffect =
new ToGray(
this, millisec);
614 applyTransformations();
617void ImageLabel::slotEffectExpired()
620 m_karamba -> externalStep();
623void ImageLabel::attachClickArea(TQString leftMouseButton,
624 TQString middleMouseButton,
625 TQString rightMouseButton)
627 leftButtonAction = leftMouseButton;
628 middleButtonAction = middleMouseButton;
629 rightButtonAction = rightMouseButton;
632#include "imagelabel.moc"