2
* This file is part of the KDE project
3
* Copyright (C) 2001 Martin R. Jones <mjones@kde.org>
4
* 2001 Carsten Pfeiffer <pfeiffer@kde.org>
6
* You can Freely distribute this program under the GNU Library General Public
7
* License. See the file "COPYING" for the exact licensing terms.
12
#include <qcombobox.h>
13
#include <qcheckbox.h>
14
#include <qwhatsthis.h>
17
#include <kapplication.h>
19
#include <kiconloader.h>
20
#include <kpushbutton.h>
21
#include <kstandarddirs.h>
24
#include <kfiledialog.h>
25
#include <kfileitem.h>
26
#include <kio/previewjob.h>
28
#include "kimagefilepreview.h"
30
/**** KImageFilePreview ****/
32
KImageFilePreview::KImageFilePreview( QWidget *parent )
33
: KPreviewWidgetBase( parent ),
35
QVBoxLayout *vb = new QVBoxLayout( this, KDialog::marginHint() );
37
imageLabel = new QLabel( this );
38
imageLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken );
39
imageLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
40
imageLabel->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ) );
41
vb->addWidget( imageLabel, 1 );
43
timer = new QTimer( this );
44
connect( timer, SIGNAL( timeout() ), SLOT( showPreview() ) );
46
setSupportedMimeTypes( KIO::PreviewJob::supportedMimeTypes() );
49
KImageFilePreview::~KImageFilePreview() {
54
void KImageFilePreview::showPreview() {
55
// Pass a copy since clearPreview() will clear currentURL
56
KURL url = currentURL;
57
showPreview( url, true );
60
// called via KPreviewWidgetBase interface
61
void KImageFilePreview::showPreview( const KURL& url ) {
62
showPreview( url, false );
65
void KImageFilePreview::showPreview( const KURL &url, bool force ) {
66
if ( !url.isValid() ) {
71
if ( url != currentURL || force ) {
75
int w = imageLabel->contentsRect().width() - 4;
76
int h = imageLabel->contentsRect().height() - 4;
78
m_job = createJob( url, w, h );
79
connect( m_job, SIGNAL( result( KIO::Job * ) ),
80
this, SLOT( slotResult( KIO::Job * ) ) );
81
connect( m_job, SIGNAL( gotPreview( const KFileItem*,
83
SLOT( gotPreview( const KFileItem*, const QPixmap& ) ) );
85
connect( m_job, SIGNAL( failed( const KFileItem* ) ),
86
this, SLOT( slotFailed( const KFileItem* ) ) );
90
void KImageFilePreview::resizeEvent( QResizeEvent * ) {
91
timer->start( 100, true ); // forces a new preview
94
QSize KImageFilePreview::sizeHint() const {
95
return QSize( 20, 200 ); // otherwise it ends up huge???
98
KIO::PreviewJob * KImageFilePreview::createJob( const KURL& url, int w, int h ) {
101
return KIO::filePreview( urls, w, h, 0, 0, true, false );
104
void KImageFilePreview::gotPreview( const KFileItem* item, const QPixmap& pm ) {
105
if ( item->url() == currentURL ) // should always be the case
106
imageLabel->setPixmap( pm );
109
void KImageFilePreview::slotFailed( const KFileItem* item ) {
112
else if ( item->url() == currentURL ) // should always be the case
113
imageLabel->setPixmap( SmallIcon( "file_broken", KIcon::SizeLarge,
114
KIcon::DisabledState ) );
117
void KImageFilePreview::slotResult( KIO::Job *job ) {
122
void KImageFilePreview::clearPreview() {
132
void KImageFilePreview::virtual_hook( int id, void* data ) {
133
KPreviewWidgetBase::virtual_hook( id, data );
136
#include "kimagefilepreview.moc"