• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/tdefile
 

tdeio/tdefile

  • tdeio
  • tdefile
kimagefilepreview.cpp
1/*
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>
5 *
6 * You can Freely distribute this program under the GNU Library General Public
7 * License. See the file "COPYING" for the exact licensing terms.
8 */
9
10#include <tqlayout.h>
11#include <tqlabel.h>
12#include <tqcombobox.h>
13#include <tqcheckbox.h>
14#include <tqwhatsthis.h>
15#include <tqtimer.h>
16
17#include <tdeapplication.h>
18#include <tdeconfig.h>
19#include <tdeglobal.h>
20#include <kiconloader.h>
21#include <kpushbutton.h>
22#include <tdestandarddirs.h>
23#include <kdebug.h>
24#include <tdelocale.h>
25#include <tdefiledialog.h>
26#include <tdefileitem.h>
27#include <tdeio/previewjob.h>
28
29#include "kimagefilepreview.h"
30#include "config-tdefile.h"
31
32/**** KImageFilePreview ****/
33
34KImageFilePreview::KImageFilePreview( TQWidget *parent )
35 : KPreviewWidgetBase( parent ),
36 m_job( 0L )
37{
38 TDEConfig *config = TDEGlobal::config();
39 TDEConfigGroupSaver cs( config, ConfigGroup );
40 autoMode = config->readBoolEntry( "Automatic Preview", true );
41
42 TQVBoxLayout *vb = new TQVBoxLayout( this, 0, KDialog::spacingHint() );
43
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 );
49
50 TQHBoxLayout *hb = new TQHBoxLayout( 0 );
51 vb->addLayout( hb );
52
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)) );
57
58 previewButton = new KPushButton( SmallIconSet("thumbnail"), i18n("&Preview"), this );
59 hb->addWidget( previewButton );
60 connect( previewButton, TQ_SIGNAL(clicked()), TQ_SLOT(showPreview()) );
61
62 timer = new TQTimer( this );
63 connect( timer, TQ_SIGNAL(timeout()), TQ_SLOT(showPreview()) );
64
65 setSupportedMimeTypes( TDEIO::PreviewJob::supportedMimeTypes() );
66}
67
68KImageFilePreview::~KImageFilePreview()
69{
70 if ( m_job )
71 m_job->kill();
72
73 TDEConfig *config = TDEGlobal::config();
74 TDEConfigGroupSaver cs( config, ConfigGroup );
75 config->writeEntry( "Automatic Preview", autoPreview->isChecked() );
76}
77
78void KImageFilePreview::showPreview()
79{
80 // Pass a copy since clearPreview() will clear currentURL
81 KURL url = currentURL;
82 showPreview( url, true );
83}
84
85// called via KPreviewWidgetBase interface
86void KImageFilePreview::showPreview( const KURL& url )
87{
88 showPreview( url, false );
89}
90
91void KImageFilePreview::showPreview( const KURL &url, bool force )
92{
93 if ( !url.isValid() ) {
94 clearPreview();
95 return;
96 }
97
98 if ( url != currentURL || force )
99 {
100 clearPreview();
101 currentURL = url;
102
103 if ( autoMode || force )
104 {
105 int w = imageLabel->contentsRect().width() - 4;
106 int h = imageLabel->contentsRect().height() - 4;
107
108 m_job = createJob( url, w, h );
109 if ( force ) // explicitly requested previews shall always be generated!
110 m_job->setIgnoreMaximumSize( true );
111
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*,
115 const TQPixmap& )),
116 TQ_SLOT( gotPreview( const KFileItem*, const TQPixmap& ) ));
117
118 connect( m_job, TQ_SIGNAL( failed( const KFileItem* )),
119 this, TQ_SLOT( slotFailed( const KFileItem* ) ));
120 }
121 }
122}
123
124void KImageFilePreview::toggleAuto( bool a )
125{
126 autoMode = a;
127 if ( autoMode )
128 {
129 // Pass a copy since clearPreview() will clear currentURL
130 KURL url = currentURL;
131 showPreview( url, true );
132 }
133}
134
135void KImageFilePreview::resizeEvent( TQResizeEvent * )
136{
137 timer->start( 100, true ); // forces a new preview
138}
139
140TQSize KImageFilePreview::sizeHint() const
141{
142 return TQSize( 20, 200 ); // otherwise it ends up huge???
143}
144
145TDEIO::PreviewJob * KImageFilePreview::createJob( const KURL& url, int w, int h )
146{
147 KURL::List urls;
148 urls.append( url );
149 return TDEIO::filePreview( urls, w, h, 0, 0, true, false );
150}
151
152void KImageFilePreview::gotPreview( const KFileItem* item, const TQPixmap& pm )
153{
154 if ( item->url() == currentURL ) // should always be the case
155 imageLabel->setPixmap( pm );
156}
157
158void KImageFilePreview::slotFailed( const KFileItem* item )
159{
160 if ( item->isDir() )
161 imageLabel->clear();
162 else if ( item->url() == currentURL ) // should always be the case
163 imageLabel->setPixmap( SmallIcon( "file_broken", TDEIcon::SizeLarge,
164 TDEIcon::DisabledState ));
165}
166
167void KImageFilePreview::slotResult( TDEIO::Job *job )
168{
169 if ( job == m_job )
170 m_job = 0L;
171}
172
173void KImageFilePreview::clearPreview()
174{
175 if ( m_job ) {
176 m_job->kill();
177 m_job = 0L;
178 }
179
180 imageLabel->clear();
181 currentURL = KURL();
182}
183
184void KImageFilePreview::virtual_hook( int id, void* data )
185{ KPreviewWidgetBase::virtual_hook( id, data ); }
186
187#include "kimagefilepreview.moc"
KPreviewWidgetBase
Abstract baseclass for all preview widgets which shall be used via KFileDialog::setPreviewWidget(cons...
Definition: kpreviewwidgetbase.h:45

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/tdefile

Skip menu "tdeio/tdefile"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/tdefile by doxygen 1.9.4
This website is maintained by Timothy Pearson.