12 #include <tqcombobox.h>
13 #include <tqcheckbox.h>
14 #include <tqwhatsthis.h>
17 #include <tdeapplication.h>
18 #include <tdeconfig.h>
19 #include <tdeglobal.h>
20 #include <kiconloader.h>
21 #include <kpushbutton.h>
22 #include <kstandarddirs.h>
24 #include <tdelocale.h>
25 #include <tdefiledialog.h>
26 #include <tdefileitem.h>
27 #include <tdeio/previewjob.h>
29 #include "kimagefilepreview.h"
30 #include "config-tdefile.h"
34 KImageFilePreview::KImageFilePreview( TQWidget *parent )
38 TDEConfig *config = TDEGlobal::config();
39 TDEConfigGroupSaver cs( config, ConfigGroup );
40 autoMode = config->readBoolEntry(
"Automatic Preview",
true );
42 TQVBoxLayout *vb =
new TQVBoxLayout(
this, 0, KDialog::spacingHint() );
44 imageLabel =
new TQLabel(
this );
45 imageLabel->setFrameStyle( TQFrame::NoFrame );
46 imageLabel->setAlignment( TQt::AlignHCenter | TQt::AlignVCenter );
47 imageLabel->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding) );
48 vb->addWidget( imageLabel );
50 TQHBoxLayout *hb =
new TQHBoxLayout( 0 );
53 autoPreview =
new TQCheckBox( i18n(
"&Automatic preview"),
this );
54 autoPreview->setChecked( autoMode );
55 hb->addWidget( autoPreview );
56 connect( autoPreview, TQ_SIGNAL(toggled(
bool)), TQ_SLOT(toggleAuto(
bool)) );
58 previewButton =
new KPushButton( SmallIconSet(
"thumbnail"), i18n(
"&Preview"),
this );
59 hb->addWidget( previewButton );
60 connect( previewButton, TQ_SIGNAL(clicked()), TQ_SLOT(showPreview()) );
62 timer =
new TQTimer(
this );
63 connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(showPreview()) );
65 setSupportedMimeTypes( TDEIO::PreviewJob::supportedMimeTypes() );
68 KImageFilePreview::~KImageFilePreview()
73 TDEConfig *config = TDEGlobal::config();
74 TDEConfigGroupSaver cs( config, ConfigGroup );
75 config->writeEntry(
"Automatic Preview", autoPreview->isChecked() );
78 void KImageFilePreview::showPreview()
81 KURL url = currentURL;
82 showPreview( url,
true );
86 void KImageFilePreview::showPreview(
const KURL& url )
88 showPreview( url,
false );
91 void KImageFilePreview::showPreview(
const KURL &url,
bool force )
93 if ( !url.isValid() ) {
98 if ( url != currentURL || force )
103 if ( autoMode || force )
105 int w = imageLabel->contentsRect().width() - 4;
106 int h = imageLabel->contentsRect().height() - 4;
108 m_job = createJob( url, w, h );
110 m_job->setIgnoreMaximumSize(
true );
112 connect( m_job, TQ_SIGNAL( result( TDEIO::Job * )),
113 this, TQ_SLOT( slotResult( TDEIO::Job * )));
114 connect( m_job, TQ_SIGNAL( gotPreview(
const KFileItem*,
116 TQ_SLOT( gotPreview(
const KFileItem*,
const TQPixmap& ) ));
118 connect( m_job, TQ_SIGNAL( failed(
const KFileItem* )),
119 this, TQ_SLOT( slotFailed(
const KFileItem* ) ));
124 void KImageFilePreview::toggleAuto(
bool a )
130 KURL url = currentURL;
131 showPreview( url,
true );
135 void KImageFilePreview::resizeEvent( TQResizeEvent * )
137 timer->start( 100,
true );
140 TQSize KImageFilePreview::sizeHint()
const
142 return TQSize( 20, 200 );
145 TDEIO::PreviewJob * KImageFilePreview::createJob(
const KURL& url,
int w,
int h )
149 return TDEIO::filePreview( urls, w, h, 0, 0,
true,
false );
152 void KImageFilePreview::gotPreview(
const KFileItem* item,
const TQPixmap& pm )
154 if ( item->url() == currentURL )
155 imageLabel->setPixmap( pm );
158 void KImageFilePreview::slotFailed(
const KFileItem* item )
162 else if ( item->url() == currentURL )
163 imageLabel->setPixmap( SmallIcon(
"file_broken", TDEIcon::SizeLarge,
164 TDEIcon::DisabledState ));
167 void KImageFilePreview::slotResult( TDEIO::Job *job )
173 void KImageFilePreview::clearPreview()
184 void KImageFilePreview::virtual_hook(
int id,
void* data )
185 { KPreviewWidgetBase::virtual_hook(
id, data ); }
187 #include "kimagefilepreview.moc"