You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
188 lines
5.2 KiB
188 lines
5.2 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE project
|
||
|
* Copyright (C) 2001 Martin R. Jones <mjones@kde.org>
|
||
|
* 2001 Carsten Pfeiffer <pfeiffer@kde.org>
|
||
|
*
|
||
|
* You can Freely distribute this program under the GNU Library General Public
|
||
|
* License. See the file "COPYING" for the exact licensing terms.
|
||
|
*/
|
||
|
|
||
13 years ago
|
#include <tqlayout.h>
|
||
14 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqcombobox.h>
|
||
|
#include <tqcheckbox.h>
|
||
|
#include <tqwhatsthis.h>
|
||
|
#include <tqtimer.h>
|
||
15 years ago
|
|
||
|
#include <kapplication.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kglobal.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <kpushbutton.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <klocale.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
|
#include <tdefileitem.h>
|
||
|
#include <tdeio/previewjob.h>
|
||
15 years ago
|
|
||
|
#include "kimagefilepreview.h"
|
||
12 years ago
|
#include "config-tdefile.h"
|
||
15 years ago
|
|
||
|
/**** KImageFilePreview ****/
|
||
|
|
||
14 years ago
|
KImageFilePreview::KImageFilePreview( TQWidget *parent )
|
||
15 years ago
|
: KPreviewWidgetBase( parent ),
|
||
|
m_job( 0L )
|
||
|
{
|
||
12 years ago
|
TDEConfig *config = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cs( config, ConfigGroup );
|
||
15 years ago
|
autoMode = config->readBoolEntry( "Automatic Preview", true );
|
||
|
|
||
14 years ago
|
TQVBoxLayout *vb = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
|
||
15 years ago
|
|
||
14 years ago
|
imageLabel = new TQLabel( this );
|
||
|
imageLabel->setFrameStyle( TQFrame::NoFrame );
|
||
13 years ago
|
imageLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
|
||
13 years ago
|
imageLabel->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding) );
|
||
15 years ago
|
vb->addWidget( imageLabel );
|
||
|
|
||
14 years ago
|
TQHBoxLayout *hb = new TQHBoxLayout( 0 );
|
||
15 years ago
|
vb->addLayout( hb );
|
||
|
|
||
14 years ago
|
autoPreview = new TQCheckBox( i18n("&Automatic preview"), this );
|
||
15 years ago
|
autoPreview->setChecked( autoMode );
|
||
|
hb->addWidget( autoPreview );
|
||
14 years ago
|
connect( autoPreview, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggleAuto(bool)) );
|
||
15 years ago
|
|
||
|
previewButton = new KPushButton( SmallIconSet("thumbnail"), i18n("&Preview"), this );
|
||
|
hb->addWidget( previewButton );
|
||
14 years ago
|
connect( previewButton, TQT_SIGNAL(clicked()), TQT_SLOT(showPreview()) );
|
||
15 years ago
|
|
||
14 years ago
|
timer = new TQTimer( this );
|
||
|
connect( timer, TQT_SIGNAL(timeout()), TQT_SLOT(showPreview()) );
|
||
15 years ago
|
|
||
12 years ago
|
setSupportedMimeTypes( TDEIO::PreviewJob::supportedMimeTypes() );
|
||
15 years ago
|
}
|
||
|
|
||
|
KImageFilePreview::~KImageFilePreview()
|
||
|
{
|
||
|
if ( m_job )
|
||
|
m_job->kill();
|
||
|
|
||
12 years ago
|
TDEConfig *config = TDEGlobal::config();
|
||
|
TDEConfigGroupSaver cs( config, ConfigGroup );
|
||
15 years ago
|
config->writeEntry( "Automatic Preview", autoPreview->isChecked() );
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::showPreview()
|
||
|
{
|
||
|
// Pass a copy since clearPreview() will clear currentURL
|
||
|
KURL url = currentURL;
|
||
|
showPreview( url, true );
|
||
|
}
|
||
|
|
||
|
// called via KPreviewWidgetBase interface
|
||
|
void KImageFilePreview::showPreview( const KURL& url )
|
||
|
{
|
||
|
showPreview( url, false );
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::showPreview( const KURL &url, bool force )
|
||
|
{
|
||
|
if ( !url.isValid() ) {
|
||
|
clearPreview();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ( url != currentURL || force )
|
||
|
{
|
||
|
clearPreview();
|
||
|
currentURL = url;
|
||
|
|
||
|
if ( autoMode || force )
|
||
|
{
|
||
|
int w = imageLabel->contentsRect().width() - 4;
|
||
|
int h = imageLabel->contentsRect().height() - 4;
|
||
|
|
||
|
m_job = createJob( url, w, h );
|
||
|
if ( force ) // explicitly requested previews shall always be generated!
|
||
|
m_job->setIgnoreMaximumSize( true );
|
||
|
|
||
12 years ago
|
connect( m_job, TQT_SIGNAL( result( TDEIO::Job * )),
|
||
|
this, TQT_SLOT( slotResult( TDEIO::Job * )));
|
||
14 years ago
|
connect( m_job, TQT_SIGNAL( gotPreview( const KFileItem*,
|
||
|
const TQPixmap& )),
|
||
|
TQT_SLOT( gotPreview( const KFileItem*, const TQPixmap& ) ));
|
||
|
|
||
|
connect( m_job, TQT_SIGNAL( failed( const KFileItem* )),
|
||
|
this, TQT_SLOT( slotFailed( const KFileItem* ) ));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::toggleAuto( bool a )
|
||
|
{
|
||
|
autoMode = a;
|
||
|
if ( autoMode )
|
||
|
{
|
||
|
// Pass a copy since clearPreview() will clear currentURL
|
||
|
KURL url = currentURL;
|
||
|
showPreview( url, true );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void KImageFilePreview::resizeEvent( TQResizeEvent * )
|
||
15 years ago
|
{
|
||
|
timer->start( 100, true ); // forces a new preview
|
||
|
}
|
||
|
|
||
13 years ago
|
TQSize KImageFilePreview::sizeHint() const
|
||
15 years ago
|
{
|
||
14 years ago
|
return TQSize( 20, 200 ); // otherwise it ends up huge???
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEIO::PreviewJob * KImageFilePreview::createJob( const KURL& url, int w, int h )
|
||
15 years ago
|
{
|
||
|
KURL::List urls;
|
||
|
urls.append( url );
|
||
12 years ago
|
return TDEIO::filePreview( urls, w, h, 0, 0, true, false );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KImageFilePreview::gotPreview( const KFileItem* item, const TQPixmap& pm )
|
||
15 years ago
|
{
|
||
|
if ( item->url() == currentURL ) // should always be the case
|
||
|
imageLabel->setPixmap( pm );
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::slotFailed( const KFileItem* item )
|
||
|
{
|
||
|
if ( item->isDir() )
|
||
|
imageLabel->clear();
|
||
|
else if ( item->url() == currentURL ) // should always be the case
|
||
|
imageLabel->setPixmap( SmallIcon( "file_broken", KIcon::SizeLarge,
|
||
|
KIcon::DisabledState ));
|
||
|
}
|
||
|
|
||
12 years ago
|
void KImageFilePreview::slotResult( TDEIO::Job *job )
|
||
15 years ago
|
{
|
||
|
if ( job == m_job )
|
||
|
m_job = 0L;
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::clearPreview()
|
||
|
{
|
||
|
if ( m_job ) {
|
||
|
m_job->kill();
|
||
|
m_job = 0L;
|
||
|
}
|
||
|
|
||
|
imageLabel->clear();
|
||
|
currentURL = KURL();
|
||
|
}
|
||
|
|
||
|
void KImageFilePreview::virtual_hook( int id, void* data )
|
||
|
{ KPreviewWidgetBase::virtual_hook( id, data ); }
|
||
|
|
||
|
#include "kimagefilepreview.moc"
|