add more spacing
[personal-kdebase.git] / runtime / renamedlgplugins / images / imagevisualizer.cpp
blob4a9a5f5b4a61bb04a242a08b62a1de193b7b1d2a
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
8 of the License.
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.
21 #include <klocale.h>
22 #include <kurl.h>
23 #include <kurllabel.h>
25 #include <qlabel.h>
26 #include <qpixmap.h>
27 #include <qimage.h>
29 #include <kio/netaccess.h>
30 #include <kvbox.h>
32 #include "imagevisualizer.h"
34 ImageVisualizer::ImageVisualizer( QWidget *parent, const KUrl &url )
35 : KVBox( parent )
37 pic = 0;
38 description = 0;
39 setSpacing( 0 );
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&)));
49 pic = label;
50 description = new QLabel(this);
51 description->adjustSize( );
52 } else {
53 description = new QLabel(this );
54 description->setText(i18n("Unable to load image") );
58 void ImageVisualizer::loadImage( const QString& path )
60 QPixmap pix(path);
61 QPixmap pixmap(pix.scaled(180, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation) );
62 pic->setText( QString() );
63 pic->setPixmap(pixmap );
64 pic->adjustSize();
66 QString desc;
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)
75 QString tmpFile;
76 if( KIO::NetAccess::download( KUrl( url ), tmpFile, window()) )
78 loadImage( tmpFile );
79 KIO::NetAccess::removeTempFile( tmpFile );
83 #include "imagevisualizer.moc"