27 #include <QtGui/QPixmap>
28 #include <QtGui/QToolTip>
29 #include <QtGui/QCursor>
30 #include <QtGui/QBitmap>
31 #include <QtGui/QImage>
33 #include <qimageblitz.h>
35 #include <KIconEffect>
36 #include <KTemporaryFile>
71 ratio = (ratio > 1) ? 1 : ratio;
72 ratio = (ratio < -1) ? -1 : ratio;
77 QImage img = pixmap.toImage();
78 return QPixmap::fromImage(Blitz::intensity(img, ratio));
87 ratio = (ratio > 1) ? 1 : ratio;
88 ratio = (ratio < -1) ? -1 : ratio;
91 if (c.contains(
"red", Qt::CaseInsensitive)) {
93 }
else if (c.contains(
"green", Qt::CaseInsensitive)) {
95 }
else if (c.contains(
"blue", Qt::CaseInsensitive)) {
102 QImage img = pixmap.toImage();
103 return QPixmap::fromImage(Blitz::channelIntensity(img, ratio,
104 Blitz::RGBChannel(channel+2)));
113 QImage image = pixmap.toImage();
114 KIconEffect::toGray(image, 1.0f);
115 return pixmap = QPixmap::fromImage(image);
124 QPixmap alpha(pixmap.width(), pixmap.height());
125 alpha.fill(QColor(m_alpha, m_alpha, m_alpha));
127 if (m_alphaColor.isValid()) {
128 QBitmap mask = pixmap.createMaskFromColor(m_alphaColor, Qt::MaskOutColor);
129 QPainter painter(&alpha);
130 painter.drawPixmap(0, 0, mask);
133 pixmap.setAlphaChannel(alpha);
140 Meter(k, ix, iy, iw, ih), m_allowClick(false), zoomed(false), rollover(false), m_renderer(0), m_connected(false)
142 pixmap = QPixmap(iw, ih);
143 pixmap.fill(Qt::transparent);
159 Meter(k), zoomed(false), rollover(false), m_renderer(0),
167 if (imageEffect != 0) {
171 if (!old_tip_rect.isNull()) {}
195 doRotate = !(deg == 0);
199 applyTransformations();
204 doScale = !(w == realpixmap.width() && h == realpixmap.height());
209 applyTransformations();
214 doScale = !(w == realpixmap.width() && h == realpixmap.height());
219 applyTransformations(
true);
242 void ImageLabel::applyTransformations(
bool useSmoothScale)
244 prepareGeometryChange();
249 rotMat.rotate(rot_angle);
250 pixmap = pixmap.transformed(rotMat, Qt::SmoothTransformation);
255 QPixmap pm(scale_w, scale_h);
256 pm.fill(Qt::transparent);
257 QPainter painter(&pm);
258 if (m_element.isEmpty()) {
259 m_renderer->render(&painter);
261 m_renderer->render(&painter, m_element);
265 if (useSmoothScale) {
266 pixmap = QPixmap::fromImage(pixmap.toImage().scaled(scale_w, scale_h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
268 double widthFactor = ((double)scale_w) / ((double)pixmap.width());
269 double heightFactor = ((double)scale_h) / ((double)pixmap.height());
271 scaleMat.scale(widthFactor, heightFactor);
272 pixmap = pixmap.transformed(scaleMat);
276 if (imageEffect != 0) {
277 pixmap = imageEffect -> apply(pixmap);
285 void ImageLabel::slotCopyResult(KJob* job)
287 QString tempFile = ((KIO::FileCopyJob*)job)->destUrl().path();
288 if (job->error() == 0) {
290 imagePath = ((KIO::FileCopyJob*)job)->srcUrl().path();
293 qWarning(
"Error downloading (%s): %s", job->errorText().toAscii().constData(),
294 tempFile.toAscii().constData());
296 KIO::NetAccess::removeTempFile(tempFile);
302 QStringList sList = fn.split(
'\n');
303 QString fileName = *sList.begin();
305 QRegExp rx(
"^[a-zA-Z]{1,5}:/", Qt::CaseInsensitive);
306 bool protocol = (rx.indexIn(fileName) != -1) ?
true :
false;
309 if (protocol && url.isLocalFile() ==
false) {
310 KTemporaryFile tmpFile;
311 tmpFile.setAutoRemove(
false);
313 KIO::FileCopyJob* copy = KIO::file_copy(fileName, tmpFile.fileName(), 0600,
315 connect(copy, SIGNAL(result(KJob*)),
316 this, SLOT(slotCopyResult(KJob*)));
321 if (fileName.endsWith(
"svg", Qt::CaseInsensitive) || fileName.endsWith(
"svgz", Qt::CaseInsensitive)) {
322 m_renderer =
new QSvgRenderer(ba);
327 if (fileName.endsWith(
"svg", Qt::CaseInsensitive) || fileName.endsWith(
"svgz", Qt::CaseInsensitive)) {
328 m_renderer =
new QSvgRenderer(fileName);
335 QPixmap tmpPm(m_renderer->defaultSize());
336 tmpPm.fill(Qt::transparent);
337 QPainter painter(&tmpPm);
338 if (m_element.isEmpty()) {
339 m_renderer->render(&painter);
341 m_renderer->render(&painter, m_element);
345 if (m_renderer->animated()) {
346 m_connected = connect(m_renderer, SIGNAL(repaintNeeded()),
this, SLOT(repaintSvg()));
350 imagePath = fileName;
361 prepareGeometryChange();
363 realpixmap = QPixmap(pix);
368 pixmapWidth = pixmap.width();
369 pixmapHeight = pixmap.height();
370 rect_off = QRect(
getX(),
getY(), pixmapWidth, pixmapHeight);
386 painter->drawPixmap(0, 0, pixmap);
390 if (imageEffect != 0)
392 imageEffect -> startTimer();
399 Qt::MouseButtons button;
400 if (QGraphicsSceneMouseEvent *event = dynamic_cast<QGraphicsSceneMouseEvent*>(e)) {
401 button =
event->button();
402 }
else if (QGraphicsSceneWheelEvent *event = dynamic_cast<QGraphicsSceneWheelEvent*>(e)) {
403 button =
event->buttons();
407 if (button == Qt::LeftButton) {
408 program = m_leftMouseButtonAction;
409 }
else if (button == Qt::MidButton) {
410 program = m_middleMouseButtonAction;
411 }
else if (button == Qt::RightButton) {
412 program = m_rightMouseButtonAction;
415 if (!program.isEmpty()) {
416 KRun::runCommand(program,0L);
426 m_allowClick = enable;
435 int _yoff,
int _xon,
int _yon)
446 QStringList sList = fn.split(
'\n');
447 QString fileName = *sList.begin();
448 QFileInfo fileInfo(fileName);
451 QRegExp rx(
"^http://", Qt::CaseInsensitive);
452 bool fileOnNet = (rx.indexIn(fileName) != -1) ?
true :
false;
455 if (fileInfo.isRelative() && !fileOnNet) {
463 if (KIO::NetAccess::download(KUrl(path), tmpFile, 0)) {
464 pixmap_off = QPixmap(tmpFile);
465 KIO::NetAccess::removeTempFile(tmpFile);
466 kDebug() <<
"Downloaded: " << path <<
" to " << tmpFile ;
468 kDebug() <<
"Error Downloading: " << path ;
471 pixmap_off = QPixmap(path);
474 pixmapOffWidth = pixmap.width();
475 pixmapOffHeight = pixmap.height();
477 rect_off = QRect(xoff, yoff, pixmapWidth, pixmapHeight);
479 if (fn_roll.isEmpty())
483 sList = fn_roll.split(
'\n');
484 fileName = *sList.begin();
485 fileInfo = QFileInfo(fileName);
487 fileOnNet = (rx.indexIn(fileName) != -1) ?
true :
false;
490 if (fileInfo.isRelative() && !fileOnNet) {
498 if (KIO::NetAccess::download(KUrl(path), tmpFile, 0)) {
499 pixmap_on = QPixmap(tmpFile);
500 KIO::NetAccess::removeTempFile(tmpFile);
501 qDebug(
"Downloaded: %s to %s", path.toAscii().constData(), tmpFile.toAscii().constData());
503 qDebug(
"Error Downloading: %s", path.toAscii().constData());
506 pixmap_on = QPixmap(path);
508 pixmapOnWidth = pixmap_on.width();
509 pixmapOnHeight = pixmap_on.height();
511 rect_on = QRect(xon, yon, pixmapOnWidth, pixmapOnHeight);
524 prepareGeometryChange();
527 if (!rect_off.contains(e->pos().toPoint())) {
533 pixmapWidth = pixmapOffWidth;
534 pixmapHeight = pixmapOffHeight;
538 if (rect_off.contains(e->pos().toPoint())) {
544 pixmapWidth = pixmapOnWidth;
545 pixmapHeight = pixmapOnHeight;
561 if (imageEffect != 0) {
565 applyTransformations();
570 if (imageEffect != 0) {
575 imageEffect =
new Intensity(
this, ratio, millisec);
576 applyTransformations();
581 if (imageEffect != 0) {
587 applyTransformations();
592 if (imageEffect != 0) {
597 imageEffect =
new ToGray(
this, millisec);
598 applyTransformations();
603 if (imageEffect != 0) {
608 imageEffect =
new ToAlpha(
this, alphaColor, alpha, millisec);
609 applyTransformations();
612 void ImageLabel::slotEffectExpired()
619 QString middleMouseButton,
620 QString rightMouseButton)
622 m_leftMouseButtonAction = leftMouseButton;
623 m_middleMouseButtonAction = middleMouseButton;
624 m_rightMouseButtonAction = rightMouseButton;
626 setAcceptedMouseButtons(Qt::LeftButton | Qt::MidButton | Qt::RightButton);
627 setCursor(QCursor(Qt::PointingHandCursor));
632 QPainter painter(&pixmap);
633 painter.setPen(pixel);
634 painter.drawPoint(point);
637 void ImageLabel::repaintSvg()
639 QPainter painter(&pixmap);
640 pixmap.fill(Qt::transparent);
642 if (m_element.isEmpty()) {
643 m_renderer->render(&painter);
645 m_renderer->render(&painter, m_element);
653 if (!m_renderer || !m_renderer->animated()) {
657 if (enable && !m_connected) {
658 m_connected = connect(m_renderer, SIGNAL(repaintNeeded()),
this, SLOT(repaintSvg()));
659 }
else if (!enable && m_connected) {
660 m_connected = !disconnect(m_renderer, SIGNAL(repaintNeeded()),
this, SLOT(repaintSvg()));
673 if (element.isEmpty()) {
681 if (m_renderer && m_renderer->elementExists(element)) {
697 #include "imagelabel.moc"
ToAlpha(ImageLabel *, const QColor &alphaColor, int alpha, int millisec)
void attachClickArea(QString leftMouseButton, QString middleMouseButton, QString rightMouseButton)
bool animationEnabled() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
bool mouseEvent(QEvent *e)
ImageLabel(Karamba *k, int ix, int iy, int iw, int ih)
QPixmap apply(QPixmap pixmap)
void toAlpha(const QColor &alphaColor, int alpha, int millisec)
QPixmap apply(QPixmap pixmap)
void channelIntensity(float ratio, QString channel, int millisec)
QString elementDrawn() const
void intensity(float ratio, int millisec)
void parseImages(const QString &fn, const QString &fn_roll, int, int, int, int)
virtual void setHeight(int)
ChannelIntensity(ImageLabel *, float r, const QString &c, int millisec)
bool isThemeFile(const QString &filename) const
QPixmap apply(QPixmap pixmap)
const ThemeFile & theme() const
bool enableAnimation(bool enable)
void setPixel(const QPoint &point, const QColor &pixel)
virtual void setWidth(int)
void rolloverImage(QGraphicsSceneHoverEvent *e)
void setTooltip(QString txt)
bool drawElement(const QString &element)
Intensity(ImageLabel *, float r, int millisec)
void setValue(const QString &imagePath)
void setEnabled(bool enable)
Effect(ImageLabel *, int millisec)
void setBackground(int b)
void toGray(int millisec)
ToGray(ImageLabel *, int millisec)
const QString & path() const
void smoothScale(int, int)
QPixmap apply(QPixmap pixmap)
void removeImageTransformations()
QByteArray readThemeFile(const QString &filename) const