| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kfilepreview.cpp

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 1998 Stephan Kulow <coolo@kde.org>
    00003                   1998 Daniel Grana <grana@ie.iwi.unibe.ch>
    00004                   2000 Werner Trobin <wtrobin@carinthia.com>
    00005
    00006     This library is free software; you can redistribute it and/or
    00007     modify it under the terms of the GNU Library General Public
    00008     License as published by the Free Software Foundation; either
    00009     version 2 of the License, or (at your option) any later version.
    00010
    00011     This library is distributed in the hope that it will be useful,
    00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014     Library General Public License for more details.
    00015
    00016     You should have received a copy of the GNU Library General Public License
    00017     along with this library; see the file COPYING.LIB.  If not, write to
    00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019     Boston, MA 02111-1307, USA.
    00020 */
    00021
    00022 #include <kaction.h>
    00023 #include <kfilepreview.h>
    00024 #include <kfilepreview.moc>
    00025
    00026 #include "config-kfile.h"
    00027
    00028 KFilePreview::KFilePreview(KFileView *view, QWidget *parent, const char *name)
    00029     : QSplitter(parent, name), KFileView()
    00030 {
    00031     if ( view )
    00032         init( view );
    00033     else
    00034         init( new KFileIconView( (QSplitter*) this, "left" ));
    00035 }
    00036
    00037
    00038 KFilePreview::KFilePreview(QWidget *parent, const char *name) :
    00039                            QSplitter(parent, name), KFileView()
    00040 {
    00041     init( new KFileIconView((QSplitter*)this, "left") );
    00042 }
    00043
    00044 KFilePreview::~KFilePreview()
    00045 {
    00046     // Why copy the actions in the first place? --ellis, 13 Jan 02.
    00048     //for ( uint i = 0; i < left->actionCollection()->count(); i++ )
    00049     //    actionCollection()->take( left->actionCollection()->action( i ));
    00050
    00051     // don't delete the preview, we can reuse it
    00052     // (it will get deleted by ~KDirOperator)
    00053     if ( preview && preview->parentWidget() == this ) {
    00054         preview->reparent(0L, 0, QPoint(0, 0), false);
    00055     }
    00056 }
    00057
    00058 void KFilePreview::init( KFileView *view )
    00059 {
    00060     setViewName( i18n("Preview") );
    00061
    00062     left = 0L;
    00063     setFileView( view );
    00064
    00065     preview = new QWidget((QSplitter*)this, "preview");
    00066     QString tmp = i18n("No preview available.");
    00067     QLabel *l = new QLabel(tmp, preview);
    00068     l->setMinimumSize(l->sizeHint());
    00069     l->move(10, 5);
    00070     preview->setMinimumWidth(l->sizeHint().width()+20);
    00071     setResizeMode(preview, QSplitter::KeepSize);
    00072
    00073     // Why copy the actions? --ellis, 13 Jan 02.
    00074     //for ( uint i = 0; i < view->actionCollection()->count(); i++ )
    00075     //    actionCollection()->insert( view->actionCollection()->action( i ));
    00076 }
    00077
    00078 void KFilePreview::setFileView( KFileView *view )
    00079 {
    00080     Q_ASSERT( view );
    00081
    00082     // Why copy the actions? --ellis, 13 Jan 02.
    00083     //if ( left ) { // remove any previous actions
    00084     //    for ( uint i = 0; i < left->actionCollection()->count(); i++ )
    00085     //        actionCollection()->take( left->actionCollection()->action( i ));
    00086     //}
    00087
    00088     delete left;
    00089     view->widget()->reparent( this, QPoint(0,0) );
    00090     view->KFileView::setViewMode(All);
    00091     view->setParentView(this);
    00092     view->setSorting( sorting() );
    00093     left = view;
    00094
    00095     connect( left->signaler(), SIGNAL( fileHighlighted(const KFileItem*) ),
    00096              SLOT( slotHighlighted( const KFileItem * )));
    00097
    00098     // Why copy the actions? --ellis, 13 Jan 02.
    00099     //for ( uint i = 0; i < view->actionCollection()->count(); i++ )
    00100     //    actionCollection()->insert( view->actionCollection()->action( i ));
    00101 }
    00102
    00103 // this url parameter is useless... it's the url of the current directory.
    00104 // what for?
    00105 void KFilePreview::setPreviewWidget(const QWidget *w, const KURL &)
    00106 {
    00107     left->setOnlyDoubleClickSelectsFiles( onlyDoubleClickSelectsFiles() );
    00108
    00109     if (w) {
    00110         connect(this, SIGNAL( showPreview(const KURL &) ),
    00111                 w, SLOT( showPreview(const KURL &) ));
    00112         connect( this, SIGNAL( clearPreview() ),
    00113                 w, SLOT( clearPreview() ));
    00114     }
    00115     else {
    00116         preview->hide();
    00117         return;
    00118     }
    00119
    00120     delete preview;
    00121     preview = const_cast<QWidget*>(w);
    00122     preview->reparent((QSplitter*)this, 0, QPoint(0, 0), true);
    00123     preview->resize(preview->sizeHint());
    00124     preview->show();
    00125 }
    00126
    00127 void KFilePreview::insertItem(KFileItem *item)
    00128 {
    00129     KFileView::insertItem( item );
    00130     left->insertItem(item);
    00131 }
    00132
    00133 void KFilePreview::setSorting( QDir::SortSpec sort )
    00134 {
    00135     left->setSorting( sort );
    00136     KFileView::setSorting( left->sorting() );
    00137 }
    00138
    00139 void KFilePreview::clearView()
    00140 {
    00141     left->clearView();
    00142     emit clearPreview();
    00143 }
    00144
    00145 void KFilePreview::updateView(bool b)
    00146 {
    00147     left->updateView(b);
    00148     if(preview)
    00149         preview->repaint(b);
    00150 }
    00151
    00152 void KFilePreview::updateView(const KFileItem *i)
    00153 {
    00154     left->updateView(i);
    00155 }
    00156
    00157 void KFilePreview::removeItem(const KFileItem *i)
    00158 {
    00159     if ( left->isSelected( i ) )
    00160         emit clearPreview();
    00161
    00162     left->removeItem(i);
    00163     KFileView::removeItem( i );
    00164 }
    00165
    00166 void KFilePreview::listingCompleted()
    00167 {
    00168     left->listingCompleted();
    00169 }
    00170
    00171 void KFilePreview::clear()
    00172 {
    00173     KFileView::clear();
    00174     left->KFileView::clear();
    00175 }
    00176
    00177 void KFilePreview::clearSelection()
    00178 {
    00179     left->clearSelection();
    00180     emit clearPreview();
    00181 }
    00182
    00183 void KFilePreview::selectAll()
    00184 {
    00185     left->selectAll();
    00186 }
    00187
    00188 void KFilePreview::invertSelection()
    00189 {
    00190     left->invertSelection();
    00191 }
    00192
    00193 bool KFilePreview::isSelected( const KFileItem *i ) const
    00194 {
    00195     return left->isSelected( i );
    00196 }
    00197
    00198 void KFilePreview::setSelectionMode(KFile::SelectionMode sm) {
    00199     left->setSelectionMode( sm );
    00200 }
    00201
    00202 void KFilePreview::setSelected(const KFileItem *item, bool enable) {
    00203     left->setSelected( item, enable );
    00204 }
    00205
    00206 void KFilePreview::setCurrentItem( const KFileItem *item )
    00207 {
    00208     left->setCurrentItem( item );
    00209 }
    00210
    00211 KFileItem * KFilePreview::currentFileItem() const
    00212 {
    00213     return left->currentFileItem();
    00214 }
    00215
    00216 void KFilePreview::slotHighlighted(const KFileItem* item)
    00217 {
    00218     if ( item )
    00219         emit showPreview( item->url() );
    00220
    00221     else { // item = 0 -> multiselection mode
    00222         const KFileItemList *items = selectedItems();
    00223         if ( items->count() == 1 )
    00224             emit showPreview( items->getFirst()->url() );
    00225         else
    00226             emit clearPreview();
    00227     }
    00228
    00229     // the preview widget appears and takes some space of the left view,
    00230     // so we may have to scroll to make the current item visible
    00231     left->ensureItemVisible(item);
    00232  }
    00233
    00234 void KFilePreview::ensureItemVisible(const KFileItem *item)
    00235 {
    00236     left->ensureItemVisible(item);
    00237 }
    00238
    00239 KFileItem * KFilePreview::firstFileItem() const
    00240 {
    00241     return left->firstFileItem();
    00242 }
    00243
    00244 KFileItem * KFilePreview::nextItem( const KFileItem *item ) const
    00245 {
    00246     return left->nextItem( item );
    00247 }
    00248
    00249 KFileItem * KFilePreview::prevItem( const KFileItem *item ) const
    00250 {
    00251     return left->prevItem( item );
    00252 }
    00253
    00254 KActionCollection * KFilePreview::actionCollection() const
    00255 {
    00256     if ( left )
    00257         return left->actionCollection();
    00258     else {
    00259         kdWarning() << "KFilePreview::actionCollection(): called before setFileView()." << endl; //ellis
    00260         return KFileView::actionCollection();
    00261     }
    00262 }
    00263
    00264 void KFilePreview::readConfig( KConfig *config, const QString& group )
    00265 {
    00266     left->readConfig( config, group );
    00267 }
    00268
    00269 void KFilePreview::writeConfig( KConfig *config, const QString& group )
    00270 {
    00271     left->writeConfig( config, group );
    00272 }
    00273
    00274 void KFilePreview::virtual_hook( int id, void* data )
    00275 { KFileView::virtual_hook( id, data ); }
    00276

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:33 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001