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

# kfileiconview.cpp

    00001 // -*- c++ -*-
    00002 /* This file is part of the KDE libraries
    00003    Copyright (C) 1997 Stephan Kulow <coolo@kde.org>
    00004                  2000,2001,2002 Carsten Pfeiffer <pfeiffer@kde.org>
    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 <qfontmetrics.h>
    00023 #include <qkeycode.h>
    00024 #include <qlabel.h>
    00025 #include <qpainter.h>
    00026 #include <qpixmap.h>
    00027 #include <qregexp.h>
    00028 #include <qtimer.h>
    00029 #include <qtooltip.h>
    00030
    00031 #include <kaction.h>
    00032 #include <kapplication.h>
    00033 #include <klocale.h>
    00034 #include <kfileitem.h>
    00035 #include <kglobalsettings.h>
    00036 #include <kio/previewjob.h>
    00037
    00038 #include "kfileiconview.h"
    00039 #include "config-kfile.h"
    00040
    00041
    00042 KFileIconViewItem::~KFileIconViewItem()
    00043 {
    00044     fileInfo()->removeExtraData( iconView() );
    00045 }
    00046
    00047 class KFileIconView::KFileIconViewPrivate
    00048 {
    00049 public:
    00050     KFileIconViewPrivate( KFileIconView *parent ) {
    00051         previewIconSize = 60;
    00052         job = 0L;
    00053
    00054         noArrangement = false;
    00055         smallColumns = new KRadioAction( i18n("Small Icons"), 0, parent,
    00056                                          SLOT( slotSmallColumns() ),
    00057                                          parent->actionCollection(),
    00058                                          "small columns" );
    00059
    00060         largeRows = new KRadioAction( i18n("Large Icons"), 0, parent,
    00061                                       SLOT( slotLargeRows() ),
    00062                                       parent->actionCollection(),
    00063                                       "large rows" );
    00064
    00065         smallColumns->setExclusiveGroup(QString::fromLatin1("IconView mode"));
    00066         largeRows->setExclusiveGroup(QString::fromLatin1("IconView mode"));
    00067
    00068         previews = new KToggleAction( i18n("Thumbnail Previews"), 0,
    00069                                       parent->actionCollection(),
    00070                                       "show previews" );
    00071         connect( previews, SIGNAL( toggled( bool )),
    00072                  parent, SLOT( slotPreviewsToggled( bool )));
    00073
    00074         previewTimer = new QTimer;
    00075         connect( previewTimer, SIGNAL( timeout() ),
    00076                  parent, SLOT( showPreviews() ));
    00077     }
    00078
    00079     ~KFileIconViewPrivate() {
    00080         delete previewTimer;
    00081         if ( job )
    00082             job->kill();
    00083     }
    00084
    00085     KRadioAction *smallColumns, *largeRows;
    00086     KToggleAction *previews;
    00087     KIO::PreviewJob *job;
    00088     QTimer *previewTimer;
    00089     QStringList previewMimeTypes;
    00090     int previewIconSize;
    00091     bool noArrangement :1;
    00092 };
    00093
    00094 KFileIconView::KFileIconView(QWidget *parent, const char *name)
    00095     : KIconView(parent, name), KFileView()
    00096 {
    00097     d = new KFileIconViewPrivate( this );
    00098
    00099     setViewName( i18n("Icon View") );
    00100
    00101     toolTip = 0;
    00102     setResizeMode( Adjust );
    00103     setMaxItemWidth( 300 );
    00104     setWordWrapIconText( false );
    00105     setArrangement( TopToBottom );
    00106     setAutoArrange( true );
    00107     setItemsMovable( false );
    00108     setMode( KIconView::Select );
    00109     KIconView::setSorting( true );
    00110     // as long as QIconView only shows tooltips when the cursor is over the
    00111     // icon (and not the text), we have to create our own tooltips
    00112     setShowToolTips( false );
    00113     slotSmallColumns();
    00114     d->smallColumns->setChecked( true );
    00115
    00116     connect( this, SIGNAL( returnPressed(QIconViewItem *) ),
    00117              SLOT( slotActivate( QIconViewItem *) ) );
    00118
    00119     // we want single click _and_ double click (as convenience)
    00120     connect( this, SIGNAL( clicked(QIconViewItem *, const QPoint&) ),
    00121              SLOT( selected( QIconViewItem *) ) );
    00122     connect( this, SIGNAL( doubleClicked(QIconViewItem *, const QPoint&) ),
    00123              SLOT( slotActivate( QIconViewItem *) ) );
    00124
    00125     connect( this, SIGNAL( onItem( QIconViewItem * ) ),
    00126              SLOT( showToolTip( QIconViewItem * ) ) );
    00127     connect( this, SIGNAL( onViewport() ),
    00128              SLOT( removeToolTip() ) );
    00129     connect( this, SIGNAL( contextMenuRequested(QIconViewItem*,const QPoint&)),
    00130              SLOT( slotActivateMenu( QIconViewItem*, const QPoint& ) ) );
    00131
    00132     KFile::SelectionMode sm = KFileView::selectionMode();
    00133     switch ( sm ) {
    00134     case KFile::Multi:
    00135         QIconView::setSelectionMode( QIconView::Multi );
    00136         break;
    00137     case KFile::Extended:
    00138         QIconView::setSelectionMode( QIconView::Extended );
    00139         break;
    00140     case KFile::NoSelection:
    00141         QIconView::setSelectionMode( QIconView::NoSelection );
    00142         break;
    00143     default: // fall through
    00144     case KFile::Single:
    00145         QIconView::setSelectionMode( QIconView::Single );
    00146         break;
    00147     }
    00148
    00149     if ( sm == KFile::Multi || sm == KFile::Extended )
    00150         connect( this, SIGNAL( selectionChanged() ),
    00151                  SLOT( slotSelectionChanged() ));
    00152     else
    00153         connect( this, SIGNAL( selectionChanged( QIconViewItem * )),
    00154                  SLOT( highlighted( QIconViewItem * )));
    00155
    00156     viewport()->installEventFilter( this );
    00157
    00158     // for mimetype resolving
    00159     m_resolver = new KMimeTypeResolver<KFileIconViewItem,KFileIconView>(this);
    00160 }
    00161
    00162 KFileIconView::~KFileIconView()
    00163 {
    00164     delete m_resolver;
    00165     removeToolTip();
    00166     delete d;
    00167 }
    00168
    00169 void KFileIconView::readConfig( KConfig *kc, const QString& group )
    00170 {
    00171     QString gr = group.isEmpty() ? QString("KFileIconView") : group;
    00172     KConfigGroupSaver cs( kc, gr );
    00173     QString small = QString::fromLatin1("SmallColumns");
    00174     d->previewIconSize = kc->readNumEntry( "Preview Size", 60 );
    00175     d->previews->setChecked( kc->readBoolEntry( "ShowPreviews", false ) );
    00176
    00177     if ( kc->readEntry("ViewMode", small ) == small ) {
    00178         d->smallColumns->setChecked( true );
    00179         slotSmallColumns();
    00180     }
    00181     else {
    00182         d->largeRows->setChecked( true );
    00183         slotLargeRows();
    00184     }
    00185
    00186     if ( d->previews->isChecked() )
    00187         showPreviews();
    00188 }
    00189
    00190 void KFileIconView::writeConfig( KConfig *kc, const QString& group )
    00191 {
    00192     QString gr = group.isEmpty() ? QString("KFileIconView") : group;
    00193     KConfigGroupSaver cs( kc, gr );
    00194     kc->writeEntry( "ViewMode", d->smallColumns->isChecked() ?
    00195                     QString::fromLatin1("SmallColumns") :
    00196                     QString::fromLatin1("LargeRows") );
    00197     kc->writeEntry( "Preview Size", d->previewIconSize );
    00198     kc->writeEntry( "ShowPreviews", d->previews->isChecked() );
    00199 }
    00200
    00201 void KFileIconView::removeToolTip()
    00202 {
    00203     delete toolTip;
    00204     toolTip = 0;
    00205 }
    00206
    00207 void KFileIconView::showToolTip( QIconViewItem *item )
    00208 {
    00209     delete toolTip;
    00210     toolTip = 0;
    00211
    00212     if ( !item )
    00213         return;
    00214
    00215     int w = maxItemWidth() - ( itemTextPos() == QIconView::Bottom ? 0 :
    00216                                item->pixmapRect().width() ) - 4;
    00217     if ( fontMetrics().width( item->text() ) >= w ) {
    00218         toolTip = new QLabel( QString::fromLatin1(" %1 ").arg(item->text()), 0,
    00219                               "myToolTip",
    00220                               WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
    00221         toolTip->setFrameStyle( QFrame::Plain | QFrame::Box );
    00222         toolTip->setLineWidth( 1 );
    00223         toolTip->setAlignment( AlignLeft | AlignTop );
    00224         toolTip->move( QCursor::pos() + QPoint( 14, 14 ) );
    00225         toolTip->adjustSize();
    00226         QRect screen = QApplication::desktop()->screenGeometry(
    00227                         QApplication::desktop()->screenNumber(QCursor::pos()));
    00228         if (toolTip->x()+toolTip->width() > screen.right()) {
    00229                 toolTip->move(toolTip->x()+screen.right()-toolTip->x()-toolTip->width(), toolTip->y());
    00230         }
    00231         if (toolTip->y()+toolTip->height() > screen.bottom()) {
    00232                 toolTip->move(toolTip->x(), screen.bottom()-toolTip->y()-toolTip->height()+toolTip->y());
    00233         }
    00234         toolTip->setFont( QToolTip::font() );
    00235         toolTip->setPalette( QToolTip::palette(), TRUE );
    00236         toolTip->show();
    00237     }
    00238 }
    00239
    00240 void KFileIconView::slotActivateMenu( QIconViewItem* item, const QPoint& pos )
    00241 {
    00242     if ( !item ) {
    00243         sig->activateMenu( 0, pos );
    00244         return;
    00245     }
    00246     KFileIconViewItem *i = (KFileIconViewItem*) item;
    00247     sig->activateMenu( i->fileInfo(), pos );
    00248 }
    00249
    00250 void KFileIconView::hideEvent( QHideEvent *e )
    00251 {
    00252     removeToolTip();
    00253     KIconView::hideEvent( e );
    00254 }
    00255
    00256 void KFileIconView::keyPressEvent( QKeyEvent *e )
    00257 {
    00258     KIconView::keyPressEvent( e );
    00259
    00260     // ignore Ctrl-Return so that the dialog can catch it.
    00261     if ( (e->state() & ControlButton) &&
    00262          (e->key() == Key_Return || e->key() == Key_Enter) )
    00263         e->ignore();
    00264 }
    00265
    00266 void KFileIconView::setSelected( const KFileItem *info, bool enable )
    00267 {
    00268     KFileIconViewItem *item = viewItem( info );
    00269     if ( item )
    00270         KIconView::setSelected( item, enable, true );
    00271 }
    00272
    00273 void KFileIconView::selectAll()
    00274 {
    00275     if (KFileView::selectionMode() == KFile::NoSelection ||
    00276         KFileView::selectionMode() == KFile::Single)
    00277         return;
    00278
    00279     KIconView::selectAll( true );
    00280 }
    00281
    00282 void KFileIconView::clearSelection()
    00283 {
    00284     KIconView::clearSelection();
    00285 }
    00286
    00287 void KFileIconView::invertSelection()
    00288 {
    00289     KIconView::invertSelection();
    00290 }
    00291
    00292 void KFileIconView::clearView()
    00293 {
    00294     m_resolver->m_lstPendingMimeIconItems.clear();
    00295
    00296     KIconView::clear();
    00297     stopPreview();
    00298 }
    00299
    00300 void KFileIconView::insertItem( KFileItem *i )
    00301 {
    00302     KFileView::insertItem( i );
    00303
    00304     KFileIconViewItem *item =
    00305         new KFileIconViewItem( (QIconView*)this, i->text(),
    00306                                i->pixmap( iconSizeFor( i ) ), i);
    00307     initItem( item, i, false );
    00308
    00309     if ( !i->isMimeTypeKnown() )
    00310         m_resolver->m_lstPendingMimeIconItems.append( item );
    00311
    00312     i->setExtraData( this, item );
    00313 }
    00314
    00315 void KFileIconView::slotActivate( QIconViewItem *item )
    00316 {
    00317     if ( !item )
    00318         return;
    00319     const KFileItem *fi = ( (KFileIconViewItem*)item )->fileInfo();
    00320     if ( fi )
    00321         sig->activate( fi );
    00322 }
    00323
    00324 void KFileIconView::selected( QIconViewItem *item )
    00325 {
    00326     if ( !item || (KApplication::keyboardModifiers() & (KApplication::ShiftModifier | KApplication::ControlModifier)) != 0 )
    00327         return;
    00328
    00329     if ( KGlobalSettings::singleClick() ) {
    00330         const KFileItem *fi = ( (KFileIconViewItem*)item )->fileInfo();
    00331         if ( fi && (fi->isDir() || !onlyDoubleClickSelectsFiles()) )
    00332             sig->activate( fi );
    00333     }
    00334 }
    00335
    00336 void KFileIconView::setCurrentItem( const KFileItem *item )
    00337 {
    00338     KFileIconViewItem *it = viewItem( item );
    00339     if ( it )
    00340         KIconView::setCurrentItem( it );
    00341 }
    00342
    00343 KFileItem * KFileIconView::currentFileItem() const
    00344 {
    00345     KFileIconViewItem *current = static_cast<KFileIconViewItem*>( currentItem() );
    00346     if ( current )
    00347         return current->fileInfo();
    00348
    00349     return 0L;
    00350 }
    00351
    00352 void KFileIconView::highlighted( QIconViewItem *item )
    00353 {
    00354     if ( !item )
    00355         return;
    00356     const KFileItem *fi = ( (KFileIconViewItem*)item )->fileInfo();
    00357     if ( fi )
    00358         sig->highlightFile( fi );
    00359 }
    00360
    00361 void KFileIconView::setSelectionMode( KFile::SelectionMode sm )
    00362 {
    00363     disconnect( SIGNAL( selectionChanged() ), this );
    00364     disconnect( SIGNAL( selectionChanged( QIconViewItem * )), this );
    00365
    00366     KFileView::setSelectionMode( sm );
    00367     switch ( KFileView::selectionMode() ) {
    00368     case KFile::Multi:
    00369         QIconView::setSelectionMode( QIconView::Multi );
    00370         break;
    00371     case KFile::Extended:
    00372         QIconView::setSelectionMode( QIconView::Extended );
    00373         break;
    00374     case KFile::NoSelection:
    00375         QIconView::setSelectionMode( QIconView::NoSelection );
    00376         break;
    00377     default: // fall through
    00378     case KFile::Single:
    00379         QIconView::setSelectionMode( QIconView::Single );
    00380         break;
    00381     }
    00382
    00383     if ( sm == KFile::Multi || sm == KFile::Extended )
    00384         connect( this, SIGNAL( selectionChanged() ),
    00385                  SLOT( slotSelectionChanged() ));
    00386     else
    00387         connect( this, SIGNAL( selectionChanged( QIconViewItem * )),
    00388                  SLOT( highlighted( QIconViewItem * )));
    00389 }
    00390
    00391 bool KFileIconView::isSelected( const KFileItem *i ) const
    00392 {
    00393     KFileIconViewItem *item = viewItem( i );
    00394     return (item && item->isSelected());
    00395 }
    00396
    00397 void KFileIconView::updateView( bool b )
    00398 {
    00399     if ( !b )
    00400         return; // eh?
    00401
    00402     KFileIconViewItem *item = static_cast<KFileIconViewItem*>(QIconView::firstItem());
    00403     if ( item ) {
    00404         if ( d->previews->isChecked() ) {
    00405             do {
    00406                 int size = canPreview( item->fileInfo() ) ?
    00407                            d->previewIconSize : myIconSize;
    00408                 item ->setPixmap( (item->fileInfo())->pixmap( size ) );
    00409                 item = static_cast<KFileIconViewItem *>(item->nextItem());
    00410             } while ( item != 0L );
    00411         }
    00412
    00413         else {
    00414             do {
    00415                 item ->setPixmap( (item->fileInfo())->pixmap( myIconSize));
    00416                 item = static_cast<KFileIconViewItem *>(item->nextItem());
    00417             } while ( item != 0L );
    00418         }
    00419     }
    00420 }
    00421
    00422 void KFileIconView::updateView( const KFileItem *i )
    00423 {
    00424     KFileIconViewItem *item = viewItem( i );
    00425     if ( item )
    00426         initItem( item, i, true );
    00427 }
    00428
    00429 void KFileIconView::removeItem( const KFileItem *i )
    00430 {
    00431     if ( !i )
    00432         return;
    00433
    00434     KFileIconViewItem *item = viewItem( i );
    00435     m_resolver->m_lstPendingMimeIconItems.remove( item );
    00436     delete item;
    00437
    00438     KFileView::removeItem( i );
    00439 }
    00440
    00441 void KFileIconView::setIconSize( int size )
    00442 {
    00443     myIconSize = size;
    00444     updateIcons();
    00445 }
    00446
    00447 void KFileIconView::setPreviewSize( int size )
    00448 {
    00449     d->previewIconSize = size;
    00450     if ( d->previews->isChecked() )
    00451         updateIcons();
    00452 }
    00453
    00454 void KFileIconView::updateIcons()
    00455 {
    00456     updateView( true );
    00457     arrangeItemsInGrid();
    00458 }
    00459
    00460 void KFileIconView::ensureItemVisible( const KFileItem *i )
    00461 {
    00462     KFileIconViewItem *item = viewItem( i );
    00463     if ( item )
    00464         KIconView::ensureItemVisible( item );
    00465 }
    00466
    00467 void KFileIconView::slotSelectionChanged()
    00468 {
    00469     sig->highlightFile( 0L );
    00470 }
    00471
    00472 void KFileIconView::slotSmallColumns()
    00473 {
    00474     // setItemTextPos(), setArrangement(), setWordWrapIconText() and
    00475     // setIconSize() all call arrangeItemsInGrid() :( Prevent this.
    00476     d->noArrangement = true; // stop arrangeItemsInGrid()!
    00477
    00478     // Make sure to uncheck previews if selected
    00479     if ( d->previews->isChecked() )
    00480     {
    00481         stopPreview();
    00482         d->previews->setChecked( false );
    00483     }
    00484     setGridX( -1 );
    00485     setMaxItemWidth( 300 );
    00486     setItemTextPos( Right );
    00487     setArrangement( TopToBottom );
    00488     setWordWrapIconText( false );
    00489     setSpacing( 0 );
    00490
    00491     d->noArrangement = false; // now we can arrange
    00492     setIconSize( KIcon::SizeSmall );
    00493 }
    00494
    00495 void KFileIconView::slotLargeRows()
    00496 {
    00497     // setItemTextPos(), setArrangement(), setWordWrapIconText() and
    00498     // setIconSize() all call arrangeItemsInGrid() :( Prevent this.
    00499     d->noArrangement = true; // stop arrangeItemsInGrid()!
    00500
    00501     setGridX( KGlobal::iconLoader()->currentSize( KIcon::Desktop ) + 50 );
    00502     setItemTextPos( Bottom );
    00503     setArrangement( LeftToRight );
    00504     setWordWrapIconText( true );
    00505     setSpacing( 5 ); // default in QIconView
    00506
    00507     d->noArrangement = false; // now we can arrange
    00508     setIconSize( KIcon::SizeMedium );
    00509 }
    00510
    00511 void KFileIconView::stopPreview()
    00512 {
    00513     if ( d->job ) {
    00514         d->job->kill();
    00515         d->job = 0L;
    00516     }
    00517 }
    00518
    00519 void KFileIconView::slotPreviewsToggled( bool on )
    00520 {
    00521     if ( on )
    00522         showPreviews();
    00523     else {
    00524         stopPreview();
    00525         slotLargeRows();
    00526     }
    00527 }
    00528
    00529 void KFileIconView::showPreviews()
    00530 {
    00531     if ( d->previewMimeTypes.isEmpty() )
    00532         d->previewMimeTypes = KIO::PreviewJob::supportedMimeTypes();
    00533
    00534     stopPreview();
    00535     d->previews->setChecked( true );
    00536
    00537     if ( !d->largeRows->isChecked() ) {
    00538         d->largeRows->setChecked( true );
    00539         slotLargeRows(); // also sets the icon size and updates the grid
    00540     }
    00541     else {
    00542         updateIcons();
    00543     }
    00544
    00545     d->job = KIO::filePreview(*items(), d->previewIconSize,d->previewIconSize);
    00546
    00547     connect( d->job, SIGNAL( result( KIO::Job * )),
    00548              this, SLOT( slotPreviewResult( KIO::Job * )));
    00549     connect( d->job, SIGNAL( gotPreview( const KFileItem*, const QPixmap& )),
    00550              SLOT( gotPreview( const KFileItem*, const QPixmap& ) ));
    00551 //     connect( d->job, SIGNAL( failed( const KFileItem* )),
    00552 //              this, SLOT( slotFailed( const KFileItem* ) ));
    00553 }
    00554
    00555 void KFileIconView::slotPreviewResult( KIO::Job *job )
    00556 {
    00557     if ( job == d->job )
    00558         d->job = 0L;
    00559 }
    00560
    00561 void KFileIconView::gotPreview( const KFileItem *item, const QPixmap& pix )
    00562 {
    00563     KFileIconViewItem *it = viewItem( item );
    00564     if ( it )
    00565         it->setPixmap( pix );
    00566 }
    00567
    00568 bool KFileIconView::canPreview( const KFileItem *item ) const
    00569 {
    00570     QStringList::Iterator it = d->previewMimeTypes.begin();
    00571     QRegExp r;
    00572     r.setWildcard( true );
    00573
    00574     for ( ; it != d->previewMimeTypes.end(); ++it ) {
    00575         QString type = *it;
    00576         // the "mimetype" can be "image/*"
    00577         if ( type.at( type.length() - 1 ) == '*' ) {
    00578             r.setPattern( type );
    00579             if ( r.search( item->mimetype() ) != -1 )
    00580                 return true;
    00581         }
    00582         else
    00583             if ( item->mimetype() == type )
    00584                 return true;
    00585     }
    00586
    00587     return false;
    00588 }
    00589
    00590 KFileItem * KFileIconView::firstFileItem() const
    00591 {
    00592     KFileIconViewItem *item = static_cast<KFileIconViewItem*>( firstItem() );
    00593     if ( item )
    00594         return item->fileInfo();
    00595     return 0L;
    00596 }
    00597
    00598 KFileItem * KFileIconView::nextItem( const KFileItem *fileItem ) const
    00599 {
    00600     if ( fileItem ) {
    00601         KFileIconViewItem *item = viewItem( fileItem );
    00602         if ( item && item->nextItem() )
    00603             return ((KFileIconViewItem*) item->nextItem())->fileInfo();
    00604     }
    00605     return 0L;
    00606 }
    00607
    00608 KFileItem * KFileIconView::prevItem( const KFileItem *fileItem ) const
    00609 {
    00610     if ( fileItem ) {
    00611         KFileIconViewItem *item = viewItem( fileItem );
    00612         if ( item && item->prevItem() )
    00613             return ((KFileIconViewItem*) item->prevItem())->fileInfo();
    00614     }
    00615     return 0L;
    00616 }
    00617
    00618 void KFileIconView::setSorting( QDir::SortSpec spec )
    00619 {
    00620     KFileView::setSorting( spec );
    00621     KFileItemListIterator it( *items() );
    00622
    00623     KFileItem *item;
    00624
    00625     if ( spec & QDir::Time ) {
    00626         for ( ; (item = it.current()); ++it )
    00627             viewItem(item)->setKey( sortingKey( item->time( KIO::UDS_MODIFICATION_TIME ), item->isDir(), spec ));
    00628     }
    00629
    00630     else if ( spec & QDir::Size ) {
    00631         for ( ; (item = it.current()); ++it )
    00632             viewItem(item)->setKey( sortingKey( item->size(), item->isDir(),
    00633                                                 spec ));
    00634     }
    00635     else { // Name or Unsorted
    00636         for ( ; (item = it.current()); ++it )
    00637             viewItem(item)->setKey( sortingKey( item->text(), item->isDir(),
    00638                                                 spec ));
    00639     }
    00640
    00641     KIconView::setSorting( true, !isReversed() );
    00642     sort( !isReversed() );
    00643 }
    00644
    00645 //
    00646 // mimetype determination on demand
    00647 //
    00648 void KFileIconView::mimeTypeDeterminationFinished()
    00649 {
    00650     // anything to do?
    00651 }
    00652
    00653 void KFileIconView::determineIcon( KFileIconViewItem *item )
    00654 {
    00655     (void) item->fileInfo()->determineMimeType();
    00656     updateView( item->fileInfo() );
    00657 }
    00658
    00659 void KFileIconView::listingCompleted()
    00660 {
    00661     // QIconView doesn't set the current item automatically, so we have to do
    00662     // that. We don't want to emit selectionChanged() tho.
    00663     if ( !currentItem() ) {
    00664         bool block = signalsBlocked();
    00665         blockSignals( true );
    00666         QIconViewItem *item = viewItem( firstFileItem() );
    00667         KIconView::setCurrentItem( item );
    00668         KIconView::setSelected( item, false );
    00669         blockSignals( block );
    00670     }
    00671
    00672     arrangeItemsInGrid();
    00673     m_resolver->start( d->previews->isChecked() ? 0 : 10 );
    00674 }
    00675
    00676 // need to remove our tooltip, eventually
    00677 bool KFileIconView::eventFilter( QObject *o, QEvent *e )
    00678 {
    00679     if ( o == viewport() || o == this ) {
    00680         int type = e->type();
    00681         if ( type == QEvent::Leave ||
    00682              type == QEvent::FocusOut )
    00683             removeToolTip();
    00684     }
    00685
    00686     return KIconView::eventFilter( o, e );
    00687 }
    00688
    00690
    00691 // ### workaround for Qt3 Bug
    00692 void KFileIconView::showEvent( QShowEvent *e )
    00693 {
    00694     KIconView::showEvent( e );
    00695 #if QT_VERSION <= 302
    00696     sort( !isReversed() );
    00697 #endif
    00698 }
    00699
    00700
    00701 void KFileIconView::initItem( KFileIconViewItem *item, const KFileItem *i,
    00702                               bool updateTextAndPixmap )
    00703 {
    00704     if ( updateTextAndPixmap )
    00705     {
    00706         // this causes a repaint of the item, which we want to avoid during
    00707         // directory listing, when all items are created. We want to paint all
    00708         // items at once, not every single item in that case.
    00709     item->setText( i->text() , false, false );
    00710         item->setPixmap( i->pixmap( iconSizeFor( i ) ) );
    00711     }
    00712
    00713     // see also setSorting()
    00714     QDir::SortSpec spec = KFileView::sorting();
    00715
    00716     if ( spec & QDir::Time )
    00717         item->setKey( sortingKey( i->time( KIO::UDS_MODIFICATION_TIME ),
    00718                                   i->isDir(), spec ));
    00719     else if ( spec & QDir::Size )
    00720         item->setKey( sortingKey( i->size(), i->isDir(), spec ));
    00721
    00722     else // Name or Unsorted
    00723         item->setKey( sortingKey( i->text(), i->isDir(), spec ));
    00724
    00725     //qDebug("** key for: %s: %s", i->text().latin1(), item->key().latin1());
    00726
    00727     if ( d->previews->isChecked() )
    00728         d->previewTimer->start( 10, true );
    00729 }
    00730
    00731 void KFileIconView::arrangeItemsInGrid( bool update )
    00732 {
    00733     if ( d->noArrangement )
    00734         return;
    00735
    00736     KIconView::arrangeItemsInGrid( update );
    00737 }
    00738
    00739 int KFileIconView::iconSizeFor( const KFileItem *item ) const
    00740 {
    00741     if ( d->previews->isChecked() && canPreview( item ) )
    00742         return d->previewIconSize;
    00743     return myIconSize;
    00744 }
    00745
    00746 void KFileIconView::virtual_hook( int id, void* data )
    00747 { KIconView::virtual_hook( id, data );
    00748   KFileView::virtual_hook( id, data ); }
    00749
    00750 #include "kfileiconview.moc"

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:29 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001