1 /* This file is part of the KDE project
2 Copyright (C) 2002 Holger Freyther <freyther@kde.org>
3 2003 Carsten Pfeiffer <pfeiffer@kde.org>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public
7 License as published by the Free Software Foundation; version 2
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
23 #include <kurllabel.h>
29 #include <kio/netaccess.h>
32 #include "imagevisualizer.h"
34 ImageVisualizer::ImageVisualizer( QWidget
*parent
, const KUrl
&url
)
40 if( url
.isValid() && url
.isLocalFile() ) {
41 pic
= new QLabel(this );
42 description
= new QLabel( this );
43 loadImage( url
.path() );
44 } else if( !url
.isLocalFile() ) {
45 KUrlLabel
*label
= new KUrlLabel( this );
46 label
->setText(i18n("This picture is not stored\non the local host.\nClick on this label to load it.\n" ) );
47 label
->setUrl( url
.prettyUrl() );
48 connect(label
, SIGNAL(leftClickedUrl(const QString
&)), SLOT(downloadImage(const QString
&)));
50 description
= new QLabel(this);
51 description
->adjustSize( );
53 description
= new QLabel(this );
54 description
->setText(i18n("Unable to load image") );
58 void ImageVisualizer::loadImage( const QString
& path
)
61 QPixmap
pixmap(pix
.scaled(180, 200, Qt::KeepAspectRatio
, Qt::SmoothTransformation
) );
62 pic
->setText( QString() );
63 pic
->setPixmap(pixmap
);
67 desc
.append(i18nc("The color depth of an image", "Depth: %1\n", pix
.depth() ));
68 desc
.append(i18nc("The dimensions of an image", "Dimensions: %1x%2", pix
.width(), pix
.height() ));
69 description
->setText(desc
);
70 description
->adjustSize();
73 void ImageVisualizer::downloadImage(const QString
& url
)
76 if( KIO::NetAccess::download( KUrl( url
), tmpFile
, window()) )
79 KIO::NetAccess::removeTempFile( tmpFile
);
83 #include "imagevisualizer.moc"