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 ) )
355 return TQIconViewItem::acceptDrop( mime );
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") {
391 KService::Ptr service = KService::serviceByDesktopName(
"konqueror");
396 KRun::runCommand(
"konqueror " + url.url(),
"konqueror", service->icon());
399 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
405 if ( m_fileitem->isLink() && url.isLocalFile() ) {
406 url = KURL( url, m_fileitem->linkDest() );
409 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
432 TDEIconViewItem::paintItem( p, cg );
440 if ( !d->m_overlay.isNull() ) {
441 TQRect rect = pixmapRect(
true);
442 p->drawPixmap(x() + rect.x() , y() + pixmapRect().height() - d->m_overlay.height(), d->m_overlay);
448 if (d->m_progress != -1) {
479 TQRect rect = pixmapRect(
true);
480 int horizontalOffset = 0;
481 int usedBarHeight = (((100-d->m_progress)*pixmapRect().height())/100);
482 int endPosition = y() + rect.y() + usedBarHeight;
486 p->setPen(TQPen::NoPen);
487 p->setBrush(TQt::green);
488 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), y() + rect.y(), 1, usedBarHeight));
489 p->setBrush(TQt::red);
490 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), endPosition, 1, pixmapRect().height() - usedBarHeight));
498 if ( m_fileitem->isLink() )
500 TQFont f( p->font() );
508 TQColorGroup cg( c );
509 cg.setColor( TQColorGroup::Text, static_cast<KonqIconViewWidget*>(iconView())->itemColor() );
513 bool KFileIVI::move(
int x,
int y )
515 if ( static_cast<KonqIconViewWidget*>(iconView())->isDesktop() ) {
518 if ( x > iconView()->viewport()->width() - ( width() + 5 ) )
519 x = iconView()->viewport()->width() - ( width() + 5 );
522 if ( y > iconView()->viewport()->height() - ( height() + 5 ) )
523 y = iconView()->viewport()->height() - ( height() + 5 );
525 return TQIconViewItem::move( x, y );
530 return !d->m_animatedIcon.isEmpty() && !m_bThumbnail;
535 if ( !movieFileName.isEmpty() )
538 d->m_animatedIcon = movieFileName;
542 TQString KFileIVI::mouseOverAnimation()
const 544 return d->m_animatedIcon;
549 return d->m_animated;
552 void KFileIVI::setAnimated(
bool a )
557 int KFileIVI::compare( TQIconViewItem *i )
const 560 if ( view->caseInsensitiveSort() )
561 return key().localeAwareCompare( i->key() );
563 return view->m_pSettings->caseSensitiveCompare( key(), i->key() );
566 void KFileIVI::updatePixmapSize()
568 int size = m_size ? m_size :
569 TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
573 bool mimeDetermined =
false;
574 if ( m_fileitem->isMimeTypeKnown() ) {
575 mimeDetermined =
true;
578 if (mimeDetermined) {
579 bool changed =
false;
580 if ( view && view->canPreview(
item() ) ) {
581 int previewSize = view->previewIconSize( size );
582 if (previewSize != size) {
583 setPixmapSize( TQSize( previewSize, previewSize ) );
588 TQSize pixSize = TQSize( size, size );
589 if ( pixSize != pixmapSize() ) {
590 setPixmapSize( pixSize );
599 TQSize pixSize = TQSize( size, size );
600 if ( pixSize != pixmapSize() ) {
601 setPixmapSize( pixSize );
606 void KFileIVI::mimeTypeAndIconDetermined()
void setMouseOverAnimation(const TQString &movieFileName)
Enable an animation on mouseover, if there is an available mng.
KFileIVI(KonqIconViewWidget *iconview, KFileItem *fileitem, int size)
Create an icon, within a qlistview, representing a file.
void setOverlay(const TQString &iconName)
Sets an icon to be shown over the bottom left corner of the icon.
void paintFontUpdate(TQPainter *p) const
Contains the logic and code for painting links.
void invalidateThumbnail()
Our current thumbnail is not longer "current".
virtual void returnPressed()
Handler for return (or single/double click) on ONE icon.
void setOverlayProgressBar(const int progress)
Sets a progress bar to be shown on the right side of the icon.
virtual void refreshIcon(bool redraw)
Redetermines the icon (useful if KFileItem might return another icon).
void setActive(bool active)
Called when the mouse is over the icon.
void setEffect(int state)
Set the icon to use the specified TDEIconEffect See the docs for TDEIconEffect for details...
void invalidateThumb(int state, bool redraw=false)
Notifies that all icon effects on thumbs should be invalidated, e.g.
void setThumbnailPixmap(const TQPixmap &pixmap)
Set this when the thumbnail was loaded.
void setPixmapDirect(const TQPixmap &pixmap, bool recalc=false, bool redraw=false)
Bypass setIcon.
virtual void paintItem(TQPainter *p, const TQColorGroup &cg)
Paints this item.
void paintOverlayProgressBar(TQPainter *p) const
Contains the logic and code for painting the overlay progress bar.
static void doDrop(const KFileItem *destItem, const KURL &destURL, TQDropEvent *ev, TQWidget *parent)
Drop.
bool hasAnimation() const
Return true if the icon might have an animation available.
int state() const
Return the current state of the icon (TDEIcon::DefaultState, TDEIcon::ActiveState etc...
bool isAnimated() const
Return true if we are currently animating this icon.
void paintOverlay(TQPainter *p) const
Contains the logic and code for painting the overlay pixmap.
KIVFreeSpaceOverlay * setShowFreeSpaceOverlay(bool)
Sets showing of free space overlays.
TQColorGroup updateColors(const TQColorGroup &c) const
Updates the colorgroup.
virtual void setIcon(int size, int state=TDEIcon::DefaultState, bool recalc=false, bool redraw=false)
Changes the icon for this item.
void setDisabled(bool disabled)
Set to true when this icon is 'cut'.
virtual bool acceptDrop(const TQMimeSource *mime) const
KIVDirectoryOverlay * setShowDirectoryOverlay(bool)
Sets showing of directory overlays.