[PATCH] Add image thumbnail when drag-and-dropping images.
Michael Pyne
pynm0001 at comcast.net
Fri Dec 31 21:47:32 GMT 2004
Hi all,
I'm including a patch to set a thumbnail image when dragging an image (that
doesn't link to something) from KHTML. You can see a screenshot of the
effect at
http://grammarian.homelinux.net/~kde-cvs/khtml-drag-drop-screenie.png (51.7
KB). I've tried to KolourPaint in about where the mouse cursor is since
ksnapshot wasn't able to get it.
The patch uses the standard "image" mimetype icon if the image isn't finished
loading yet, or if the image is too small. The image scales the image below
300x200 using SmoothScale if necessary, and then applies a fade filter to
enhance the iCandy-ness. ;)
It may be a good idea to leave out the filter, as it makes khtml depend on
kdefx (not a horrible problem), and obviously increases the time it takes to
set the icon (could be problematic). I think the thing that takes the
longest is actually the smoothScale(), however, so perhaps it would be best
to use a faster, but less accurate scaling function?
Also, the thumbnail setting code is skipped if DISPLAY doesn't appear to be a
local machine.
Please let me know what you guys think of the code. There's no need to CC:
me, as I'm newly subscribed.
Regards,
- Michael Pyne
The patch follows:
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/khtml/Makefile.am,v
retrieving revision 1.163
diff -u -3 -p -r1.163 Makefile.am
--- Makefile.am 21 Dec 2004 19:17:24 -0000 1.163
+++ Makefile.am 31 Dec 2004 21:24:08 -0000
@@ -54,6 +54,7 @@ libkhtml_la_LIBADD = ./xml/libkhtmlxml.l
./rendering/libkhtmlrender.la ./css/libkhtmlcss.la \
./misc/libkhtmlmisc.la ecma/libkjs_html.la ./dom/libkhtmldom.la $(LIBKJAVA)
\
$(LIB_KPARTS) \
+ $(LIB_KDEFX) \
$(LIBTHAI) \
$(top_builddir)/kdeprint/libkdeprint.la \
$(top_builddir)/kutils/libkutils.la \
Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.1069
diff -u -3 -p -r1.1069 khtml_part.cpp
--- khtml_part.cpp 25 Dec 2004 16:36:36 -0000 1.1069
+++ khtml_part.cpp 31 Dec 2004 21:24:10 -0000
@@ -60,11 +60,14 @@ using namespace DOM;
#include <kjs/function.h>
#include <kjs/interpreter.h>
+#include <kimageeffect.h>
+
#include "htmlpageinfo.h"
#include <sys/types.h>
#include <assert.h>
#include <unistd.h>
+#include <stdlib.h>
#include <config.h>
@@ -6026,7 +6029,28 @@ void KHTMLPart::khtmlMouseMoveEvent( kht
{
img = static_cast<HTMLImageElementImpl *>(innerNode.handle());
u =
KURL( completeURL( khtml::parseURL(img->getAttribute(ATTR_SRC)).string() ) );
- pix = KMimeType::mimeType("image/png")->pixmap(KIcon::Desktop);
+ char *displayName = getenv ( "DISPLAY" );
+
+ // Check if the X Server is running locally. I wish I knew a better
way
+ // to do this. Also make sure the image has actually downloaded.
+ if ( displayName && displayName[0] == ':' && img->complete() )
+ {
+ QImage image = img->currentImage();
+ if ( image.width() > 300 || image.height() > 200 )
+ image = image.smoothScale ( 300, 200, QImage::ScaleMin );
+
+ // Only use the thumbnail if the image is "large enough", as there's
+ // no reason to thumbnail e.g. a 1x1 invisible gif.
+ if ( image.width() > 6 && image.height() > 6 )
+ {
+ KImageEffect::fade ( image, 0.37, gray );
+ pix = QPixmap ( image );
+ }
+ else
+ pix = KMimeType::mimeType("image/png")->pixmap(KIcon::Desktop);
+ }
+ else
+ pix = KMimeType::mimeType("image/png")->pixmap(KIcon::Desktop);
}
else
{
More information about the kfm-devel
mailing list