20 #include "tdefileivi.h"
21 #include "kivdirectoryoverlay.h"
22 #include "kivfreespaceoverlay.h"
23 #include "konq_iconviewwidget.h"
24 #include "konq_operations.h"
25 #include "konq_settings.h"
27 #include <tqpainter.h>
30 #include <kiconeffect.h>
31 #include <tdefileitem.h>
41 struct KFileIVI::Private
46 TQString m_animatedIcon;
48 KIVDirectoryOverlay* m_directoryOverlay;
49 KIVFreeSpaceOverlay* m_freeSpaceOverlay;
51 TQString m_overlayName;
56 : TDEIconViewItem( iconview, fileitem->text() ),
57 m_size( size ), m_state( TDEIcon::DefaultState ),
58 m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem )
60 d =
new KFileIVI::Private;
63 setPixmap( m_fileitem->pixmap( m_size, m_state ) );
64 setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
67 d->icons.reset( *pixmap(), TQIconSet::Large );
68 d->m_animated =
false;
71 if ( fileitem->isMimeTypeKnown() )
73 TQString icon = fileitem->iconName();
74 if ( !icon.isEmpty() )
80 d->m_directoryOverlay = 0;
81 d->m_freeSpaceOverlay = 0;
86 delete d->m_directoryOverlay;
87 delete d->m_freeSpaceOverlay;
96 case TDEIcon::DisabledState:
97 mode = TQIconSet::Disabled;
99 case TDEIcon::ActiveState:
100 mode = TQIconSet::Active;
102 case TDEIcon::DefaultState:
104 mode = TQIconSet::Normal;
107 d->icons = TQIconSet();
108 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
109 apply( d->thumb, TDEIcon::Desktop, state ),
110 TQIconSet::Large, mode );
113 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
120 m_bThumbnail =
false;
122 m_state = TDEIcon::DisabledState;
126 if ( d->m_overlayName.isNull() )
127 d->m_overlay = TQPixmap();
131 halfSize = IconSize(TDEIcon::Desktop) / 2;
133 halfSize = m_size / 2;
135 d->m_overlay = DesktopIcon(d->m_overlayName, halfSize);
138 setPixmapDirect(m_fileitem->pixmap( m_size, m_state ) , recalc, redraw );
143 d->m_overlayName = iconName;
150 d->m_progress = progress;
157 if ( !m_fileitem->isDir() || m_fileitem->iconName() !=
"folder" )
161 if (!d->m_directoryOverlay)
162 d->m_directoryOverlay =
new KIVDirectoryOverlay(
this);
163 return d->m_directoryOverlay;
165 delete d->m_directoryOverlay;
166 d->m_directoryOverlay = 0;
172 bool KFileIVI::showDirectoryOverlay( )
174 return (
bool)d->m_directoryOverlay;
179 if ( !m_fileitem->mimetype().startsWith(
"media/") ) {
184 if (!d->m_freeSpaceOverlay)
185 d->m_freeSpaceOverlay =
new KIVFreeSpaceOverlay(
this);
186 return d->m_freeSpaceOverlay;
188 delete d->m_freeSpaceOverlay;
189 d->m_freeSpaceOverlay = 0;
195 bool KFileIVI::showFreeSpaceOverlay( )
197 return (
bool)d->m_freeSpaceOverlay;
202 TQIconSet::Mode mode;
205 case TDEIcon::DisabledState:
206 mode = TQIconSet::Disabled;
208 case TDEIcon::ActiveState:
209 mode = TQIconSet::Active;
211 case TDEIcon::DefaultState:
213 mode = TQIconSet::Normal;
220 d->icons = TQIconSet();
221 d->icons.setPixmap( pixmap, TQIconSet::Large, mode );
224 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
230 if ( m_bDisabled != disabled )
232 m_bDisabled = disabled;
233 bool active = ( m_state == TDEIcon::ActiveState );
234 setEffect( m_bDisabled ? TDEIcon::DisabledState :
235 ( active ? TDEIcon::ActiveState : TDEIcon::DefaultState ) );
245 d->icons = TQIconSet();
246 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
247 apply( pixmap, TDEIcon::Desktop, TDEIcon::DefaultState ),
248 TQIconSet::Large, TQIconSet::Normal );
250 m_state = TDEIcon::DefaultState;
254 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large,
255 TQIconSet::Normal ), true );
263 setEffect( m_bDisabled ? TDEIcon::DisabledState : TDEIcon::DefaultState );
268 TQIconSet::Mode mode;
271 case TDEIcon::DisabledState:
272 mode = TQIconSet::Disabled;
274 case TDEIcon::ActiveState:
275 mode = TQIconSet::Active;
277 case TDEIcon::DefaultState:
279 mode = TQIconSet::Normal;
284 TDEIconEffect *effect = TDEGlobal::iconLoader()->iconEffect();
286 bool haveEffect = effect->hasEffect( TDEIcon::Desktop, m_state ) !=
287 effect->hasEffect( TDEIcon::Desktop, state );
297 effect->fingerprint( TDEIcon::Desktop, m_state ) !=
298 effect->fingerprint( TDEIcon::Desktop, state ) )
304 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
305 d->icons.setPixmap( effect->apply( d->thumb, TDEIcon::Desktop, state ),
306 TQIconSet::Large, mode );
310 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
311 d->icons.setPixmap( m_fileitem->pixmap( m_size, state ),
312 TQIconSet::Large, mode );
314 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ) );
322 setIcon( m_size, m_state,
true, redraw );
328 d->thumb = TQPixmap();
331 bool KFileIVI::isThumbnailInvalid()
const
333 return d->thumb.isNull();
338 if ( mime->provides(
"text/uri-list" ) )
340 if ( m_fileitem->acceptsDrops() )
348 KURL::List::Iterator it = uris.begin();
349 for ( ; it != uris.end() ; it++ )
351 if ( m_fileitem->url().equals( *it,
true ) )
358 void KFileIVI::setKey(
const TQString &key )
360 TQString theKey = key;
362 TQVariant sortDirProp = iconView()->property(
"sortDirectoriesFirst" );
364 bool isdir = ( S_ISDIR( m_fileitem->mode() ) && ( !sortDirProp.isValid() || ( sortDirProp.type() == TQVariant::Bool && sortDirProp.toBool() ) ) );
367 int sortChar = isdir ? 1 : 3;
368 if ( m_fileitem->text()[0] ==
'.' )
371 if ( !iconView()->sortDirection() )
372 sortChar = 3 - sortChar;
374 theKey.prepend( TQChar( sortChar +
'0' ) );
376 TQIconViewItem::setKey( theKey );
379 void KFileIVI::dropped( TQDropEvent *e,
const TQValueList<TQIconDragItem> & )
386 if ( static_cast<KonqIconViewWidget*>(iconView())->isDesktop() ) {
387 KURL url = m_fileitem->url();
388 if (url.protocol() ==
"media") {
389 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
394 if ( m_fileitem->isLink() && url.isLocalFile() ) {
395 url = KURL( url, m_fileitem->linkDest() );
398 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
429 if ( !d->m_overlay.isNull() ) {
430 TQRect rect = pixmapRect(
true);
431 p->drawPixmap(x() + rect.x() , y() + pixmapRect().height() - d->m_overlay.height(), d->m_overlay);
437 if (d->m_progress != -1) {
468 TQRect rect = pixmapRect(
true);
469 int horizontalOffset = 0;
470 int usedBarHeight = (((100-d->m_progress)*pixmapRect().height())/100);
471 int endPosition = y() + rect.y() + usedBarHeight;
475 p->setPen(TQPen::NoPen);
476 p->setBrush(TQt::green);
477 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), y() + rect.y(), 1, usedBarHeight));
478 p->setBrush(TQt::red);
479 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), endPosition, 1, pixmapRect().height() - usedBarHeight));
487 if ( m_fileitem->isLink() )
489 TQFont f( p->font() );
497 TQColorGroup cg( c );
498 cg.setColor( TQColorGroup::Text, static_cast<KonqIconViewWidget*>(iconView())->itemColor() );
502 bool KFileIVI::move(
int x,
int y )
504 if ( static_cast<KonqIconViewWidget*>(iconView())->isDesktop() ) {
507 if ( x > iconView()->viewport()->width() - ( width() + 5 ) )
508 x = iconView()->viewport()->width() - ( width() + 5 );
511 if ( y > iconView()->viewport()->height() - ( height() + 5 ) )
512 y = iconView()->viewport()->height() - ( height() + 5 );
514 return TQIconViewItem::move( x, y );
519 return !d->m_animatedIcon.isEmpty() && !m_bThumbnail;
524 if ( !movieFileName.isEmpty() )
527 d->m_animatedIcon = movieFileName;
531 TQString KFileIVI::mouseOverAnimation()
const
533 return d->m_animatedIcon;
538 return d->m_animated;
541 void KFileIVI::setAnimated(
bool a )
546 int KFileIVI::compare( TQIconViewItem *i )
const
549 if ( view->caseInsensitiveSort() )
550 return key().localeAwareCompare( i->key() );
552 return view->m_pSettings->caseSensitiveCompare( key(), i->key() );
555 void KFileIVI::updatePixmapSize()
557 int size = m_size ? m_size :
558 TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
562 bool mimeDetermined =
false;
563 if ( m_fileitem->isMimeTypeKnown() ) {
564 mimeDetermined =
true;
567 if (mimeDetermined) {
568 bool changed =
false;
569 if ( view && view->canPreview(
item() ) ) {
570 int previewSize = view->previewIconSize( size );
571 if (previewSize != size) {
572 setPixmapSize( TQSize( previewSize, previewSize ) );
577 TQSize pixSize = TQSize( size, size );
578 if ( pixSize != pixmapSize() ) {
579 setPixmapSize( pixSize );
588 TQSize pixSize = TQSize( size, size );
589 if ( pixSize != pixmapSize() ) {
590 setPixmapSize( pixSize );
595 void KFileIVI::mimeTypeAndIconDetermined()