kio
kfilepreview.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kaction.h>
00023 #include <kfilepreview.h>
00024 #include <kfilepreview.moc>
00025 #include <klocale.h>
00026
00027 #include <qlabel.h>
00028
00029 #include "config-kfile.h"
00030
00031 KFilePreview::KFilePreview(KFileView *view, QWidget *parent, const char *name)
00032 : QSplitter(parent, name), KFileView()
00033 {
00034 if ( view )
00035 init( view );
00036 else
00037 init( new KFileIconView( (QSplitter*) this, "left" ));
00038 }
00039
00040
00041 KFilePreview::KFilePreview(QWidget *parent, const char *name) :
00042 QSplitter(parent, name), KFileView()
00043 {
00044 init( new KFileIconView((QSplitter*)this, "left") );
00045 }
00046
00047 KFilePreview::~KFilePreview()
00048 {
00049
00051
00052
00053
00054
00055
00056 if ( preview && preview->parentWidget() == this ) {
00057 preview->reparent(0L, 0, QPoint(0, 0), false);
00058 }
00059 }
00060
00061 void KFilePreview::init( KFileView *view )
00062 {
00063 setViewName( i18n("Preview") );
00064
00065 left = 0L;
00066 setFileView( view );
00067
00068 preview = new QWidget((QSplitter*)this, "preview");
00069 QString tmp = i18n("No preview available.");
00070 QLabel *l = new QLabel(tmp, preview);
00071 l->setMinimumSize(l->sizeHint());
00072 l->move(10, 5);
00073 preview->setMinimumWidth(l->sizeHint().width()+20);
00074 setResizeMode(preview, QSplitter::KeepSize);
00075
00076
00077
00078
00079 }
00080
00081 void KFilePreview::setFileView( KFileView *view )
00082 {
00083 Q_ASSERT( view );
00084
00085
00086
00087
00088
00089
00090
00091 delete left;
00092 view->widget()->reparent( this, QPoint(0,0) );
00093 view->KFileView::setViewMode(All);
00094 view->setParentView(this);
00095 view->setSorting( sorting() );
00096 left = view;
00097
00098 connect( left->signaler(), SIGNAL( fileHighlighted(const KFileItem*) ),
00099 SLOT( slotHighlighted( const KFileItem * )));
00100
00101
00102
00103
00104 }
00105
00106
00107
00108 void KFilePreview::setPreviewWidget(const QWidget *w, const KURL &)
00109 {
00110 left->setOnlyDoubleClickSelectsFiles( onlyDoubleClickSelectsFiles() );
00111
00112 if (w) {
00113 connect(this, SIGNAL( showPreview(const KURL &) ),
00114 w, SLOT( showPreview(const KURL &) ));
00115 connect( this, SIGNAL( clearPreview() ),
00116 w, SLOT( clearPreview() ));
00117 }
00118 else {
00119 preview->hide();
00120 return;
00121 }
00122
00123 delete preview;
00124 preview = const_cast<QWidget*>(w);
00125 preview->reparent((QSplitter*)this, 0, QPoint(0, 0), true);
00126 preview->resize(preview->sizeHint());
00127 preview->show();
00128 }
00129
00130 void KFilePreview::insertItem(KFileItem *item)
00131 {
00132 KFileView::insertItem( item );
00133 left->insertItem(item);
00134 }
00135
00136 void KFilePreview::setSorting( QDir::SortSpec sort )
00137 {
00138 left->setSorting( sort );
00139 KFileView::setSorting( left->sorting() );
00140 }
00141
00142 void KFilePreview::clearView()
00143 {
00144 left->clearView();
00145 emit clearPreview();
00146 }
00147
00148 void KFilePreview::updateView(bool b)
00149 {
00150 left->updateView(b);
00151 if(preview)
00152 preview->repaint(b);
00153 }
00154
00155 void KFilePreview::updateView(const KFileItem *i)
00156 {
00157 left->updateView(i);
00158 }
00159
00160 void KFilePreview::removeItem(const KFileItem *i)
00161 {
00162 if ( left->isSelected( i ) )
00163 emit clearPreview();
00164
00165 left->removeItem(i);
00166 KFileView::removeItem( i );
00167 }
00168
00169 void KFilePreview::listingCompleted()
00170 {
00171 left->listingCompleted();
00172 }
00173
00174 void KFilePreview::clear()
00175 {
00176 KFileView::clear();
00177 left->KFileView::clear();
00178 }
00179
00180 void KFilePreview::clearSelection()
00181 {
00182 left->clearSelection();
00183 emit clearPreview();
00184 }
00185
00186 void KFilePreview::selectAll()
00187 {
00188 left->selectAll();
00189 }
00190
00191 void KFilePreview::invertSelection()
00192 {
00193 left->invertSelection();
00194 }
00195
00196 bool KFilePreview::isSelected( const KFileItem *i ) const
00197 {
00198 return left->isSelected( i );
00199 }
00200
00201 void KFilePreview::setSelectionMode(KFile::SelectionMode sm) {
00202 left->setSelectionMode( sm );
00203 }
00204
00205 void KFilePreview::setSelected(const KFileItem *item, bool enable) {
00206 left->setSelected( item, enable );
00207 }
00208
00209 void KFilePreview::setCurrentItem( const KFileItem *item )
00210 {
00211 left->setCurrentItem( item );
00212 }
00213
00214 KFileItem * KFilePreview::currentFileItem() const
00215 {
00216 return left->currentFileItem();
00217 }
00218
00219 void KFilePreview::slotHighlighted(const KFileItem* item)
00220 {
00221 if ( item )
00222 emit showPreview( item->url() );
00223
00224 else {
00225 const KFileItemList *items = selectedItems();
00226 if ( items->count() == 1 )
00227 emit showPreview( items->getFirst()->url() );
00228 else
00229 emit clearPreview();
00230 }
00231
00232
00233
00234 left->ensureItemVisible(item);
00235 }
00236
00237 void KFilePreview::ensureItemVisible(const KFileItem *item)
00238 {
00239 left->ensureItemVisible(item);
00240 }
00241
00242 KFileItem * KFilePreview::firstFileItem() const
00243 {
00244 return left->firstFileItem();
00245 }
00246
00247 KFileItem * KFilePreview::nextItem( const KFileItem *item ) const
00248 {
00249 return left->nextItem( item );
00250 }
00251
00252 KFileItem * KFilePreview::prevItem( const KFileItem *item ) const
00253 {
00254 return left->prevItem( item );
00255 }
00256
00257 KActionCollection * KFilePreview::actionCollection() const
00258 {
00259 if ( left )
00260 return left->actionCollection();
00261 else {
00262 kdWarning() << "KFilePreview::actionCollection(): called before setFileView()." << endl;
00263 return KFileView::actionCollection();
00264 }
00265 }
00266
00267 void KFilePreview::readConfig( KConfig *config, const QString& group )
00268 {
00269 left->readConfig( config, group );
00270 }
00271
00272 void KFilePreview::writeConfig( KConfig *config, const QString& group )
00273 {
00274 left->writeConfig( config, group );
00275 }
00276
00277 void KFilePreview::virtual_hook( int id, void* data )
00278 { KFileView::virtual_hook( id, data ); }
00279