20 #include "konq_iconviewwidget.h"
21 #include "konq_operations.h"
22 #include "konq_undo.h"
23 #include "konq_sound.h"
24 #include "konq_filetip.h"
26 #include <tqclipboard.h>
29 #include <tqpainter.h>
30 #include <tqtooltip.h>
36 #include <tdeapplication.h>
38 #include <tdeio/previewjob.h>
39 #include <tdefileivi.h>
40 #include <konq_settings.h>
41 #include <konq_drag.h>
42 #include <tdeglobalsettings.h>
43 #include <kpropertiesdialog.h>
45 #include <kicontheme.h>
46 #include <kiconeffect.h>
48 #include <kstandarddirs.h>
49 #include <kprotocolinfo.h>
54 #include <tdelocale.h>
57 struct KonqIconViewWidgetPrivate
59 KonqIconViewWidgetPrivate() {
61 bSoundPreviews =
false;
63 bSoundItemClicked =
false;
67 bAllowSetWallpaper =
false;
73 pActivateDoubleClick = 0L;
74 bCaseInsensitive =
true;
75 pPreviewMimeTypes = 0L;
76 bProgramsURLdrag =
false;
78 ~KonqIconViewWidgetPrivate() {
83 delete pActivateDoubleClick;
84 delete pPreviewMimeTypes;
90 KonqSoundPlayer *pSoundPlayer;
93 bool bSoundItemClicked;
94 bool bAllowSetWallpaper;
95 bool bCaseInsensitive;
102 TQString movieFileName;
104 TDEIO::PreviewJob *pPreviewJob;
105 KonqFileTip* pFileTip;
106 TQStringList previewSettings;
109 bool releaseMouseEvent;
112 TQTimer *pActivateDoubleClick;
113 TQStringList* pPreviewMimeTypes;
114 bool bProgramsURLdrag;
118 : TDEIconView( parent, name, f ),
119 m_rootItem( 0L ), m_size( 0 ) ,
120 m_bDesktop( kdesktop ),
121 m_bSetGridX( !kdesktop )
123 d =
new KonqIconViewWidgetPrivate;
124 connect(
this, TQ_SIGNAL( dropped( TQDropEvent *,
const TQValueList<TQIconDragItem> & ) ),
125 this, TQ_SLOT( slotDropped( TQDropEvent*,
const TQValueList<TQIconDragItem> & ) ) );
127 connect(
this, TQ_SIGNAL( selectionChanged() ),
130 kapp->addKipcEventMask( KIPC::IconChanged );
131 connect( kapp, TQ_SIGNAL(iconChanged(
int)), TQ_SLOT(slotIconChanged(
int)) );
132 connect(
this, TQ_SIGNAL(onItem(TQIconViewItem *)), TQ_SLOT(slotOnItem(TQIconViewItem *)) );
133 connect(
this, TQ_SIGNAL(onViewport()), TQ_SLOT(slotOnViewport()) );
134 connect(
this, TQ_SIGNAL(itemRenamed(TQIconViewItem *,
const TQString &)), TQ_SLOT(slotItemRenamed(TQIconViewItem *,
const TQString &)) );
137 d->bBoostPreview = boostPreview();
140 setSelectionMode( TQIconView::Extended );
142 d->releaseMouseEvent =
false;
143 d->pFileTip =
new KonqFileTip(
this);
144 d->firstClick =
false;
146 setAutoArrange(
true );
147 setSorting(
true, sortDirection() );
148 readAnimatedIconsConfig();
149 m_bSortDirsFirst =
true;
150 m_bMousePressed =
false;
151 m_LineupMode = LineupBoth;
154 m_iconPositionGroupPrefix = TQString::fromLatin1(
"IconPosition::" );
155 KonqUndoManager::incRef();
158 KonqIconViewWidget::~KonqIconViewWidget()
161 KonqUndoManager::decRef();
165 bool KonqIconViewWidget::maySetWallpaper()
167 return d->bAllowSetWallpaper;
170 void KonqIconViewWidget::setMaySetWallpaper(
bool b)
172 d->bAllowSetWallpaper = b;
180 m_bMousePressed =
false;
189 TDEIconView::focusOutEvent( ev );
192 void KonqIconViewWidget::slotItemRenamed(TQIconViewItem *item,
const TQString &name)
194 kdDebug(1203) <<
"KonqIconViewWidget::slotItemRenamed" << endl;
196 KFileItem *fileItem = viewItem->
item();
201 viewItem->setText( fileItem->text() );
202 kdDebug(1203)<<
" fileItem->text() ;"<<fileItem->text()<<endl;
204 if( !name.isEmpty() )
207 KURL oldurl( fileItem->url() );
208 KURL newurl( oldurl );
209 newurl.setPath( newurl.directory(
false) + TDEIO::encodeFileName( name ) );
210 kdDebug(1203)<<
" newurl :"<<newurl<<endl;
216 void KonqIconViewWidget::slotIconChanged(
int group )
218 if (group != TDEIcon::Desktop)
225 readAnimatedIconsConfig();
228 void KonqIconViewWidget::readAnimatedIconsConfig()
230 TDEConfigGroup cfgGroup( TDEGlobal::config(),
"DesktopIcons" );
231 d->doAnimations = cfgGroup.readBoolEntry(
"Animated",
true );
234 void KonqIconViewWidget::slotOnItem( TQIconViewItem *_item )
238 if( d->pActiveItem != 0L && d->pActiveItem != item )
240 if ( d->m_movie && d->pActiveItem->isAnimated() )
243 d->pActiveItem->setAnimated(
false );
244 d->pActiveItem->refreshIcon(
true );
247 d->pActiveItem->setActive(
false );
250 d->pFileTip->setItem( 0L );
254 if (d->pSoundPlayer != 0 && item != d->pSoundItem)
256 d->pSoundPlayer->stop();
259 if (d->pSoundTimer && d->pSoundTimer->isActive())
260 d->pSoundTimer->stop();
263 if ( !m_bMousePressed )
265 if( item != d->pActiveItem )
267 d->pActiveItem = item;
268 d->pFileTip->setItem( d->pActiveItem->item(),
272 if ( d->doAnimations && d->pActiveItem && d->pActiveItem->hasAnimation() )
277 if ( d->m_movie && d->movieFileName == d->pActiveItem->mouseOverAnimation() )
279 d->pActiveItem->setAnimated(
true );
280 if (d->m_movieBlocked) {
281 kdDebug(1203) <<
"onitem, but blocked" << endl;
285 kdDebug(1203) <<
"we go ahead.." << endl;
287 TQTimer::singleShot(300,
this, TQ_SLOT(slotReenableAnimation()));
288 d->m_movie->restart();
289 d->m_movie->unpause();
295 TQMovie movie = TDEGlobal::iconLoader()->loadMovie( d->pActiveItem->mouseOverAnimation(), TDEIcon::Desktop, d->pActiveItem->iconSize() );
296 if ( !movie.isNull() )
299 d->m_movie =
new TQMovie( movie );
302 const TQPixmap* pm = backgroundPixmap();
303 bool hasPixmap = pm && !pm->isNull();
305 pm = viewport()->backgroundPixmap();
306 hasPixmap = pm && !pm->isNull();
308 if (!hasPixmap && backgroundMode() != NoBackground)
309 d->m_movie->setBackgroundColor( viewport()->backgroundColor() );
310 d->m_movie->connectUpdate(
this, TQ_SLOT( slotMovieUpdate(
const TQRect &) ) );
311 d->m_movie->connectStatus(
this, TQ_SLOT( slotMovieStatus(
int) ) );
312 d->movieFileName = d->pActiveItem->mouseOverAnimation();
313 d->pActiveItem->setAnimated(
true );
317 d->pActiveItem->setAnimated(
false );
321 d->pActiveItem->setMouseOverAnimation( TQString::null );
326 if (d->pActiveItem && !d->pActiveItem->isAnimated())
328 d->pActiveItem->setActive(
true );
336 d->pFileTip->setItem( 0L );
344 d->pFileTip->setItem( 0L );
348 if (d->bSoundPreviews && d->pSoundPlayer &&
349 d->pSoundPlayer->mimeTypes().contains(
350 item->
item()->mimetype())
351 && TDEGlobalSettings::showFilePreview(item->
item()->url())
352 && topLevelWidget() == kapp->activeWindow())
354 d->pSoundItem = item;
355 d->bSoundItemClicked =
false;
358 d->pSoundTimer =
new TQTimer(
this);
359 connect(d->pSoundTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotStartSoundPreview()));
361 if (d->pSoundTimer->isActive())
362 d->pSoundTimer->stop();
363 d->pSoundTimer->start(500,
true);
368 d->pSoundPlayer->stop();
370 if (d->pSoundTimer && d->pSoundTimer->isActive())
371 d->pSoundTimer->stop();
375 void KonqIconViewWidget::slotOnViewport()
377 d->pFileTip->setItem( 0L );
380 d->pSoundPlayer->stop();
382 if (d->pSoundTimer && d->pSoundTimer->isActive())
383 d->pSoundTimer->stop();
385 if (d->pActiveItem == 0L)
388 if ( d->doAnimations && d->m_movie && d->pActiveItem->isAnimated() )
390 d->pActiveItem->setAnimated(
false );
393 if (d->m_movie->running()) {
396 kdDebug(1203) <<
"on viewport, blocking" << endl;
397 TQTimer::singleShot(300,
this, TQ_SLOT(slotReenableAnimation()));
400 d->pActiveItem->refreshIcon(
true );
401 Q_ASSERT( d->pActiveItem->state() == TDEIcon::DefaultState );
408 d->pActiveItem->setActive(
false );
413 void KonqIconViewWidget::slotStartSoundPreview()
415 if (!d->pSoundItem || d->bSoundItemClicked)
418 d->pSoundPlayer->play(d->pSoundItem->item()->url().url());
422 void KonqIconViewWidget::slotPreview(
const KFileItem *item,
const TQPixmap &pix)
425 for (TQIconViewItem *it = firstItem(); it; it = it->nextItem())
428 if (current->
item() == item)
430 if (item->overlays() & TDEIcon::HiddenOverlay) {
433 TDEIconEffect::semiTransparent(p);
443 void KonqIconViewWidget::slotPreviewResult()
446 emit imagePreviewFinished();
449 void KonqIconViewWidget::slotToolTipPreview(
const KFileItem* ,
const TQPixmap &)
454 void KonqIconViewWidget::slotToolTipPreviewResult()
459 void KonqIconViewWidget::slotMovieUpdate(
const TQRect& rect )
463 Q_ASSERT( d->m_movie );
465 if ( d->pActiveItem && d->m_movie && d->pActiveItem->isAnimated() ) {
466 const TQPixmap &frame = d->m_movie->framePixmap();
469 int iconSize=d->pActiveItem->iconSize();
470 if (iconSize==0) iconSize = TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
471 if ( frame.width() != iconSize || frame.height() != iconSize ) {
472 d->pActiveItem->setAnimated(
false );
475 d->pActiveItem->setMouseOverAnimation( TQString::null );
476 d->pActiveItem->setActive(
true );
479 d->pActiveItem->setPixmapDirect( frame,
false,
false );
480 TQRect pixRect = d->pActiveItem->pixmapRect(
false);
481 repaintContents( pixRect.x() + rect.x(), pixRect.y() + rect.y(), rect.width(), rect.height(),
false );
485 void KonqIconViewWidget::slotMovieStatus(
int status )
489 if ( d->pActiveItem && d->pActiveItem->isAnimated() ) {
490 d->pActiveItem->setAnimated(
false );
491 d->pActiveItem->setMouseOverAnimation( TQString::null );
492 d->pActiveItem->setActive(
true );
497 void KonqIconViewWidget::slotReenableAnimation()
499 if (!--d->m_movieBlocked) {
500 if ( d->pActiveItem && d->m_movie && d->m_movie->paused()) {
501 kdDebug(1203) <<
"reenabled animation" << endl;
502 d->m_movie->restart();
503 d->m_movie->unpause();
510 d->pFileTip->setItem( 0L );
512 TDEIconView::clear();
518 if ( d->pActiveItem ==
static_cast<KFileIVI *
>(item) )
520 d->pFileTip->setItem( 0L );
524 if ( d->pPreviewJob )
525 d->pPreviewJob->removeItem(
static_cast<KFileIVI *
>(item)->item() );
527 TDEIconView::takeItem( item );
531 void KonqIconViewWidget::setThumbnailPixmap(
KFileIVI * item,
const TQPixmap & pixmap )
535 if ( d->pActiveItem == item )
537 d->pFileTip->setItem( 0L );
541 if ( m_bSetGridX && item->width() > gridX() )
543 setGridX( item->width() );
545 arrangeItemsInGrid();
552 bool fontChanged =
false;
555 TQColor normalTextColor = m_pSettings->normalTextColor();
556 setItemColor( normalTextColor );
560 TQColor itemTextBg = m_pSettings->itemTextBackground();
561 if ( itemTextBg.isValid() )
562 setItemTextBackground( itemTextBg );
564 setItemTextBackground( TQt::NoBrush );
567 bool on = m_pSettings->showFileTips() && TQToolTip::isGloballyEnabled();
568 d->pFileTip->setOptions(on,
569 m_pSettings->showPreviewsInFileTips(),
570 m_pSettings->numFileTips());
573 setShowToolTips(!on);
576 TQFont font( m_pSettings->standardFont() );
578 font.setUnderline( m_pSettings->underlineLink() );
580 if ( font != KonqIconViewWidget::font() )
591 setIconTextHeight( m_pSettings->iconTextHeight() );
593 if ( (itemTextPos() == TQIconView::Right) && (maxItemWidth() !=
gridXValue()) )
599 else if ( d->bBoostPreview != boostPreview() )
606 bool KonqIconViewWidget::boostPreview()
const
608 if ( m_bDesktop )
return false;
610 TDEConfigGroup group( TDEGlobal::config(),
"PreviewSettings" );
611 return group.readBoolEntry(
"BoostSize",
false );
614 void KonqIconViewWidget::disableSoundPreviews()
616 d->bSoundPreviews =
false;
619 d->pSoundPlayer->stop();
621 if (d->pSoundTimer && d->pSoundTimer->isActive())
622 d->pSoundTimer->stop();
628 bool sizeChanged = (m_size != size);
629 int oldGridX = gridX();
633 bool boost = boostPreview();
634 bool previewSizeChanged = ( d->bBoostPreview != boost );
635 d->bBoostPreview = boost;
637 if ( sizeChanged || previewSizeChanged )
639 int realSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
641 setSpacing( ( m_bDesktop || ( realSize > TDEIcon::SizeSmall ) ) ?
642 TQMAX( spacing(), TQFontMetrics(font()).width(
'n') ) : 0 );
645 if ( sizeChanged || previewSizeChanged || !stopImagePreviewFor.isEmpty() )
649 bool stopAll = !stopImagePreviewFor.isEmpty() && stopImagePreviewFor.first() ==
"*";
655 bool prevUpdatesState = viewport()->isUpdatesEnabled();
656 viewport()->setUpdatesEnabled(
false );
659 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
665 previewSizeChanged ||
667 mimeTypeMatch( ivi->
item()->mimetype(), stopImagePreviewFor ) )
676 viewport()->setUpdatesEnabled( prevUpdatesState );
678 if ( ( sizeChanged || previewSizeChanged || oldGridX != gridX() ||
679 !stopImagePreviewFor.isEmpty() ) && autoArrange() )
680 arrangeItemsInGrid(
true );
682 viewport()->update();
685 bool KonqIconViewWidget::mimeTypeMatch(
const TQString& mimeType,
const TQStringList& mimeList )
const
688 KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
689 for (TQStringList::ConstIterator mt = mimeList.begin(); mt != mimeList.end(); ++mt)
691 if ( mime->is( *mt ) )
694 TQString tmp( mimeType );
695 if ( (*mt).endsWith(
"*") && tmp.replace(TQRegExp(
"/.*"),
"/*") == (*mt) )
697 if ( (*mt) ==
"text/plain" )
699 TQVariant textProperty = mime->property(
"X-TDE-text" );
700 if ( textProperty.type() == TQVariant::Bool && textProperty.toBool() )
710 int sz = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
713 if ( pos == TQIconView::Bottom ) {
714 setGridX( TQMAX( sz + 50, previewIconSize( sz ) + 13 ) );
718 setMaxItemWidth( TQMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth() );
723 TDEIconView::setItemTextPos( pos );
729 int previewSize = previewIconSize( m_size );
730 int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
739 *dx = spacing() + TQMAX( TQMAX( iconSize, previewSize ), m_pSettings->iconTextWidth() );
740 int textHeight = iconTextHeight() * fontMetrics().height();
741 *dy = spacing() + TQMAX( iconSize, previewSize ) + 2 + textHeight + spacing();
745 if ( m_IconRect.isValid() ) {
746 *x = m_IconRect.left(); w = m_IconRect.width();
747 *y = m_IconRect.top(); h = m_IconRect.height();
750 *x = 0; w = viewport()->width();
751 *y = 0; h = viewport()->height();
770 kdDebug(1203) <<
"x=" << *x <<
" y=" << *y <<
" spacing=" << spacing() <<
" iconSize=" << iconSize
771 <<
" w=" << w <<
" h=" << h
772 <<
" nx=" << *nx <<
" ny=" << *ny
773 <<
" dx=" << *dx <<
" dy=" << *dy << endl;
776 void KonqIconViewWidget::calculateGridX()
779 if ( itemTextPos() == TQIconView::Bottom ) {
793 int sz = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
796 if ( itemTextPos() == TQIconView::Bottom )
797 newGridX = TQMAX( sz + 50, previewIconSize( sz ) + 13 );
799 newGridX = TQMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth();
807 updatePreviewMimeTypes();
808 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
809 (
static_cast<KFileIVI *
>( it ))->item()->refreshMimeType();
813 void KonqIconViewWidget::setURL(
const KURL &kurl )
818 d->pFileTip->setPreview( TDEGlobalSettings::showFilePreview(m_url) );
820 if ( m_url.isLocalFile() )
821 m_dotDirectoryPath = m_url.path(1).append(
".directory" );
823 m_dotDirectoryPath = TQString::null;
831 if ( !TDEGlobalSettings::showFilePreview( url() ) ) {
832 kdDebug(1203) <<
"Previews disabled for protocol " << url().protocol() << endl;
833 emit imagePreviewFinished();
837 if ((d->bSoundPreviews = d->previewSettings.contains(
"audio/" )) &&
840 KLibFactory *factory = KLibLoader::self()->factory(
"konq_sound");
842 d->pSoundPlayer =
static_cast<KonqSoundPlayer *
>(
843 factory->create(
this, 0,
"KonqSoundPlayer"));
844 d->bSoundPreviews = (d->pSoundPlayer != 0L);
848 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
849 if ( force || !
static_cast<KFileIVI *
>( it )->hasValidThumbnail() )
852 bool onlyAudio =
true;
853 for ( TQStringList::ConstIterator it = d->previewSettings.begin(); it != d->previewSettings.end(); ++it ) {
854 if ( (*it).startsWith(
"audio/" ) )
855 d->bSoundPreviews =
true;
860 if ( items.isEmpty() || onlyAudio ) {
861 emit imagePreviewFinished();
865 int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
868 d->bBoostPreview = boostPreview();
869 size = previewIconSize( iconSize );
871 if ( !d->bBoostPreview )
874 d->pPreviewJob = TDEIO::filePreview( items, size, size, iconSize,
875 m_pSettings->textPreviewIconTransparency(),
true ,
876 true , &(d->previewSettings) );
877 connect( d->pPreviewJob, TQ_SIGNAL( gotPreview(
const KFileItem *,
const TQPixmap & ) ),
878 this, TQ_SLOT( slotPreview(
const KFileItem *,
const TQPixmap & ) ) );
879 connect( d->pPreviewJob, TQ_SIGNAL( result( TDEIO::Job * ) ),
880 this, TQ_SLOT( slotPreviewResult() ) );
883 void KonqIconViewWidget::stopImagePreview()
887 d->pPreviewJob->kill();
894 bool KonqIconViewWidget::isPreviewRunning()
const
896 return d->pPreviewJob;
901 KFileItemList lstItems;
903 TQIconViewItem *it = firstItem();
904 for (; it; it = it->nextItem() )
905 if ( it->isVisible() && it->isSelected() ) {
906 KFileItem *fItem = (
static_cast<KFileIVI *
>(it))->item();
907 lstItems.append( fItem );
912 void KonqIconViewWidget::slotDropped( TQDropEvent *ev,
const TQValueList<TQIconDragItem> & )
918 dirURL = m_rootItem->mostLocalURL(dummy);
923 void KonqIconViewWidget::slotAboutToCreate(
const TQPoint &,
const TQValueList<TDEIO::CopyInfo> &)
928 void KonqIconViewWidget::drawBackground( TQPainter *p,
const TQRect &r )
930 drawBackground(p, r, r.topLeft());
933 void KonqIconViewWidget::drawBackground( TQPainter *p,
const TQRect &r ,
const TQPoint &pt)
935 const TQPixmap *pm = backgroundPixmap();
936 bool hasPixmap = pm && !pm->isNull();
938 pm = viewport()->backgroundPixmap();
939 hasPixmap = pm && !pm->isNull();
943 rtgt.moveTopLeft(pt);
944 if (!hasPixmap && backgroundMode() != NoBackground) {
945 p->fillRect(rtgt, viewport()->backgroundColor());
950 int ax = (r.x() + contentsX() + leftMargin()) % pm->width();
951 int ay = (r.y() + contentsY() + topMargin()) % pm->height();
952 p->drawTiledPixmap(rtgt, *pm, TQPoint(ax, ay));
956 TQDragObject * KonqIconViewWidget::dragObject()
958 if ( !currentItem() )
961 return konqDragObject( viewport() );
964 KonqIconDrag * KonqIconViewWidget::konqDragObject( TQWidget * dragSource )
969 TQIconViewItem *primaryItem = currentItem();
971 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
972 if ( it->isVisible() && it->isSelected() ) {
975 KFileItem* fileItem = (
static_cast<KFileIVI *
>(it))->item();
976 KURL url = fileItem->url();
978 KURL mostLocalURL = fileItem->mostLocalURL(dummy);
979 TQString itemURL = KURLDrag::urlToString(url);
980 kdDebug(1203) <<
"itemURL=" << itemURL << endl;
982 id.setData( TQCString(itemURL.latin1()) );
984 TQRect( it->pixmapRect(
false).topLeft() - m_mousePos,
985 it->pixmapRect().size() ),
986 TQRect( it->textRect(
false).topLeft() - m_mousePos,
987 it->textRect().size() ),
988 itemURL, mostLocalURL );
993 drag->setPixmap( *primaryItem->pixmap(), m_mousePos - primaryItem->pixmapRect(
false).topLeft() );
998 void KonqIconViewWidget::contentsDragEnterEvent( TQDragEnterEvent *e )
1000 if ( e->provides(
"text/uri-list" ) )
1002 TQByteArray payload = e->encodedData(
"text/uri-list" );
1003 if ( !payload.size() )
1004 kdError() <<
"Empty data !" << endl;
1007 bool ok = KURLDrag::decode( e, m_lstDragURLs );
1009 kdError() <<
"Couldn't decode urls dragged !" << endl;
1013 if ( KURLDrag::decode(e, uriList) )
1015 if ( uriList.first().protocol() ==
"programs" )
1019 d->bProgramsURLdrag =
true;
1024 TDEIconView::contentsDragEnterEvent( e );
1028 void KonqIconViewWidget::contentsDragMoveEvent( TQDragMoveEvent *e )
1030 if ( d->bProgramsURLdrag ) {
1031 emit dragMove(
false );
1033 cancelPendingHeldSignal();
1037 TQIconViewItem *item = findItem( e->pos() );
1038 if ( e->source() != viewport() &&
1039 !item && m_rootItem && !m_rootItem->isWritable() ) {
1040 emit dragMove(
false );
1042 cancelPendingHeldSignal();
1045 emit dragMove(
true );
1046 TDEIconView::contentsDragMoveEvent( e );
1049 void KonqIconViewWidget::contentsDragLeaveEvent( TQDragLeaveEvent *e )
1051 d->bProgramsURLdrag =
false;
1052 TDEIconView::contentsDragLeaveEvent(e);
1057 void KonqIconViewWidget::setItemColor(
const TQColor &c )
1062 TQColor KonqIconViewWidget::itemColor()
const
1067 void KonqIconViewWidget::disableIcons(
const KURL::List & lst )
1069 for ( TQIconViewItem *kit = firstItem(); kit; kit = kit->nextItem() )
1071 bool bFound =
false;
1074 for (KURL::List::ConstIterator it = lst.begin(); !bFound && it != lst.end(); ++it)
1076 if (
static_cast<KFileIVI *
>( kit )->item()->url() == *it )
1082 static_cast<KFileIVI *
>( kit )->setDisabled( bFound );
1092 bool bInTrash =
false;
1095 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
1097 if ( it->isVisible() && it->isSelected() )
1102 KFileItem *item = (
static_cast<KFileIVI *
>( it ) )->item();
1103 KURL url = item->url();
1104 TQString local_path = item->localPath();
1106 if ( url.directory(
false) == TDEGlobalSettings::trashPath() ) {
1109 if ( KProtocolInfo::supportsDeleting( url ) ) {
1112 if ( !local_path.isEmpty() ) {
1120 emit
enableAction(
"trash", canDel > 0 && !bInTrash && canTrash==canDel );
1124 emit
enableAction(
"rename", ( iCount == 1) && !bInTrash );
1127 void KonqIconViewWidget::renameCurrentItem()
1129 if ( currentItem() )
1130 currentItem()->rename();
1133 void KonqIconViewWidget::renameSelectedItem()
1135 kdDebug(1203) <<
" -- KonqIconViewWidget::renameSelectedItem() -- " << endl;
1136 TQIconViewItem * item = 0L;
1137 TQIconViewItem *it = firstItem();
1138 for (; it; it = it->nextItem() )
1139 if ( it->isVisible() && it->isSelected() && !item )
1152 void KonqIconViewWidget::cutSelection()
1154 kdDebug(1203) <<
" -- KonqIconViewWidget::cutSelection() -- " << endl;
1155 KonqIconDrag * obj = konqDragObject( );
1156 obj->setMoveSelection(
true );
1157 TQApplication::clipboard()->setData( obj );
1160 void KonqIconViewWidget::copySelection()
1162 kdDebug(1203) <<
" -- KonqIconViewWidget::copySelection() -- " << endl;
1163 KonqIconDrag * obj = konqDragObject( );
1164 TQApplication::clipboard()->setData( obj );
1167 void KonqIconViewWidget::pasteSelection()
1172 void KonqIconViewWidget::paste(
const KURL &url )
1177 KURL::List KonqIconViewWidget::selectedUrls()
1179 return selectedUrls( UserVisibleUrls );
1182 KURL::List KonqIconViewWidget::selectedUrls( UrlFlags flags )
const
1186 for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
1187 if ( it->isVisible() && it->isSelected() ) {
1188 KFileItem* item = (
static_cast<KFileIVI *
>( it ))->item();
1189 lstURLs.append( flags == MostLocalUrls ? item->mostLocalURL( dummy ) : item->url() );
1206 return m_LineupMode;
1211 m_LineupMode = mode;
1214 bool KonqIconViewWidget::sortDirectoriesFirst()
const
1216 return m_bSortDirsFirst;
1219 void KonqIconViewWidget::setSortDirectoriesFirst(
bool b )
1221 m_bSortDirsFirst = b;
1224 void KonqIconViewWidget::contentsMouseMoveEvent( TQMouseEvent *e )
1226 if ( (d->pSoundPlayer && d->pSoundPlayer->isPlaying()) || (d->pSoundTimer && d->pSoundTimer->isActive()))
1231 if ( TQApplication::widgetAt( TQCursor::pos() ) != topLevelWidget() )
1233 if (d->pSoundPlayer)
1234 d->pSoundPlayer->stop();
1236 if (d->pSoundTimer && d->pSoundTimer->isActive())
1237 d->pSoundTimer->stop();
1240 d->renameItem=
false;
1241 TDEIconView::contentsMouseMoveEvent( e );
1244 void KonqIconViewWidget::contentsDropEvent( TQDropEvent * ev )
1246 TQIconViewItem *i = findItem( ev->pos() );
1249 if ( ev->source() != viewport() &&
1250 !i && m_rootItem && !m_rootItem->isWritable() ) {
1251 ev->accept(
false );
1257 if ( !i && (ev->action() == TQDropEvent::Copy || ev->action() == TQDropEvent::Link)
1258 && ev->source() && ev->source() == viewport()
1259 && KURLDrag::decode(ev, uriList) && !uriList.isEmpty()
1260 && uriList.first().upURL().url(1) == url().url(1))
1263 bool bMovable = itemsMovable();
1264 setItemsMovable(
false);
1265 TDEIconView::contentsDropEvent( ev );
1266 setItemsMovable(bMovable);
1268 TQValueList<TQIconDragItem> lst;
1269 slotDropped(ev, lst);
1273 TDEIconView::contentsDropEvent( ev );
1287 void KonqIconViewWidget::doubleClickTimeout()
1289 d->renameItem=
true;
1290 mousePressChangeValue();
1291 if ( d->releaseMouseEvent )
1293 TQMouseEvent e( TQEvent::MouseButtonPress,d->mousePos , 1, d->mouseState);
1294 TQIconViewItem* item = findItem( e.pos() );
1298 url= (
static_cast<KFileIVI *
>( item ) )->item()->url();
1299 bool brenameTrash =
false;
1300 if ( url.isLocalFile() && (url.directory(
false) == TDEGlobalSettings::trashPath() || url.path(1).startsWith(TDEGlobalSettings::trashPath())))
1301 brenameTrash =
true;
1303 if ( url.isLocalFile() && !brenameTrash && d->renameItem && m_pSettings->renameIconDirectly() && e.button() == TQt::LeftButton && item->textRect(
false ).contains(e.pos()))
1305 if( d->pActivateDoubleClick->isActive () )
1306 d->pActivateDoubleClick->stop();
1308 m_bMousePressed =
false;
1314 TQMouseEvent e( TQEvent::MouseMove,d->mousePos , 1, d->mouseState);
1315 TDEIconView::contentsMousePressEvent( &e );
1317 if( d->pActivateDoubleClick->isActive() )
1318 d->pActivateDoubleClick->stop();
1320 d->releaseMouseEvent =
false;
1321 d->renameItem=
false;
1324 void KonqIconViewWidget::wheelEvent(TQWheelEvent* e)
1327 d->pFileTip->setItem( 0 );
1329 if (e->state() == ControlButton)
1331 if (e->delta() >= 0)
1343 TDEIconView::wheelEvent(e);
1346 void KonqIconViewWidget::leaveEvent( TQEvent *e )
1351 TDEIconView::leaveEvent(e);
1354 void KonqIconViewWidget::mousePressChangeValue()
1357 m_bMousePressed =
true;
1358 if (d->pSoundPlayer)
1359 d->pSoundPlayer->stop();
1360 d->bSoundItemClicked =
true;
1361 d->firstClick =
false;
1365 d->pFileTip->setItem( 0 );
1368 void KonqIconViewWidget::contentsMousePressEvent( TQMouseEvent *e )
1370 if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
1371 d->pActivateDoubleClick->stop();
1372 TQIconViewItem* item = findItem( e->pos() );
1373 m_mousePos = e->pos();
1377 url = (
static_cast<KFileIVI *
>( item ) )->item()->url();
1378 bool brenameTrash =
false;
1379 if ( url.isLocalFile() && (url.directory(
false) == TDEGlobalSettings::trashPath() || url.path(1).startsWith(TDEGlobalSettings::trashPath())))
1380 brenameTrash =
true;
1381 if ( !brenameTrash && !TDEGlobalSettings::singleClick() && m_pSettings->renameIconDirectly() && e->button() == TQt::LeftButton && item->textRect(
false ).contains(e->pos())&& !d->firstClick && url.isLocalFile() && (!url.protocol().find(
"device", 0,
false)==0))
1383 d->firstClick =
true;
1384 d->mousePos = e->pos();
1385 d->mouseState = e->state();
1386 if (!d->pActivateDoubleClick)
1388 d->pActivateDoubleClick =
new TQTimer(
this);
1389 connect(d->pActivateDoubleClick, TQ_SIGNAL(timeout()),
this, TQ_SLOT(doubleClickTimeout()));
1391 if( d->pActivateDoubleClick->isActive () )
1392 d->pActivateDoubleClick->stop();
1394 d->pActivateDoubleClick->start(TQApplication::doubleClickInterval());
1395 d->releaseMouseEvent =
false;
1399 d->renameItem=
false;
1402 d->renameItem=
false;
1403 mousePressChangeValue();
1404 if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive())
1405 d->pActivateDoubleClick->stop();
1406 TDEIconView::contentsMousePressEvent( e );
1410 void KonqIconViewWidget::contentsMouseReleaseEvent( TQMouseEvent *e )
1412 TDEIconView::contentsMouseReleaseEvent( e );
1413 if(d->releaseMouseEvent && d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
1414 d->pActivateDoubleClick->stop();
1416 d->releaseMouseEvent =
true;
1417 m_bMousePressed =
false;
1420 void KonqIconViewWidget::slotSaveIconPositions()
1429 printf(
"WARNING: Strongly deprecated method KonqIconViewWidget::slotSaveIconPositions() called!\n"); fflush(stdout);
1431 if ( m_dotDirectoryPath.isEmpty() )
1435 kdDebug(1214) <<
"KonqIconViewWidget::slotSaveIconPositions" << endl;
1436 KSimpleConfig dotDirectory( m_dotDirectoryPath );
1437 TQIconViewItem *it = firstItem();
1443 KFileItem *item = ivi->
item();
1445 dotDirectory.setGroup( TQString( m_iconPositionGroupPrefix ).append( item->url().fileName() ) );
1446 kdDebug(1214) <<
"KonqIconViewWidget::slotSaveIconPositions " << item->url().fileName() <<
" " << it->x() <<
" " << it->y() << endl;
1447 dotDirectory.writeEntry( TQString(
"X %1" ).arg( width() ), it->x() );
1448 dotDirectory.writeEntry( TQString(
"Y %1" ).arg( height() ), it->y() );
1449 dotDirectory.writeEntry(
"Exists",
true );
1451 it = it->nextItem();
1454 TQStringList groups = dotDirectory.groupList();
1455 TQStringList::ConstIterator gIt = groups.begin();
1456 TQStringList::ConstIterator gEnd = groups.end();
1457 for (; gIt != gEnd; ++gIt )
1458 if ( (*gIt).left( m_iconPositionGroupPrefix.length() ) == m_iconPositionGroupPrefix )
1460 dotDirectory.setGroup( *gIt );
1461 if ( dotDirectory.hasKey(
"Exists" ) )
1462 dotDirectory.deleteEntry(
"Exists",
false );
1465 kdDebug(1214) <<
"KonqIconViewWidget::slotSaveIconPositions deleting group " << *gIt << endl;
1466 dotDirectory.deleteGroup( *gIt );
1470 dotDirectory.sync();
1488 if (!m_IconRect.isValid())
1490 TDEIconView::insertInGrid(item);
1494 TQRegion r(m_IconRect);
1495 TQIconViewItem *i = firstItem();
1497 for (; i; i = i->nextItem() )
1499 r = r.subtract(i->rect());
1500 y = TQMAX(y, i->y() + i->height());
1503 TQMemArray<TQRect> rects = r.rects();
1504 TQMemArray<TQRect>::Iterator it = rects.begin();
1505 bool foundPlace = FALSE;
1506 for (; it != rects.end(); ++it)
1509 if (rect.width() >= item->width() && rect.height() >= item->height())
1512 if (rect.width() >= item->width() + spacing())
1514 if (rect.height() >= item->height() + spacing())
1516 item->move(rect.x() + sx, rect.y() + sy);
1523 item->move(m_IconRect.topLeft());
1563 int x0, y0, dx, dy, nx, ny;
1566 int itemWidth = dx - spacing();
1567 bool newItemWidth =
false;
1568 if ( maxItemWidth() != itemWidth ) {
1569 newItemWidth =
true;
1570 setMaxItemWidth( itemWidth );
1574 if ( !firstItem() ) {
1575 kdDebug(1203) <<
"No icons at all ?\n";
1579 int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1581 typedef TQValueList<TQIconViewItem*> Bin;
1582 Bin*** bins =
new Bin**[nx];
1585 for ( i = 0; i < nx ; i++ ) {
1586 bins[i] =
new Bin*[ny];
1587 for ( j = 0; j < ny; j++ )
1592 int textHeight = iconTextHeight() * fontMetrics().height();
1594 for ( TQIconViewItem* item = firstItem(); item; item = item->nextItem() ) {
1595 int x = item->x() + item->width() / 2 - x0;
1596 int y = item->pixmapRect(
false ).bottom() - iconSize / 2
1597 - ( dy - ( iconSize + textHeight ) ) / 2 - y0;
1598 int posX = TQMIN( nx-1, TQMAX( 0, x / dx ) );
1599 int posY = TQMIN( ny-1, TQMAX( 0, y / dy ) );
1601 if ( !bins[posX][posY] )
1602 bins[posX][posY] =
new Bin;
1603 bins[posX][posY]->prepend( item );
1608 const int infinity = 10000;
1610 for ( n = 0; n < 30 && nmoves > 0; n++ ) {
1612 for ( i = 0; i < nx; i++ ) {
1613 for ( j = 0; j < ny; j++ ) {
1614 if ( !bins[i][j] || ( bins[i][j]->count() <= 1 ) )
1618 int tf = 0, bf = 0, lf = 0, rf = 0;
1619 for ( k = j-1; k >= 0 && bins[i][k] && bins[i][k]->count(); k-- )
1620 tf += bins[i][k]->count();
1624 for ( k = j+1; k < ny && bins[i][k] && bins[i][k]->count(); k++ )
1625 bf += bins[i][k]->count();
1629 for ( k = i-1; k >= 0 && bins[k][j] && bins[k][j]->count(); k-- )
1630 lf += bins[k][j]->count();
1634 for ( k = i+1; k < nx && bins[k][j] && bins[k][j]->count(); k++ )
1635 rf += bins[k][j]->count();
1640 if ( tf >= infinity && bf >= infinity &&
1641 lf >= infinity && rf >= infinity )
1645 if ( m_LineupMode == LineupHorizontal ) {
1649 else if ( m_LineupMode == LineupVertical ) {
1655 TQIconViewItem* movedItem;
1656 Bin* items = bins[i][j];
1658 int mini = TQMIN( TQMIN( tf, bf ), TQMIN( lf, rf ) );
1661 Bin::iterator it = items->begin();
1663 for ( ++it; it != items->end(); ++it ) {
1664 if ( (*it)->y() < movedItem->y() )
1667 items->remove( movedItem );
1668 if ( !bins[i][j-1] )
1669 bins[i][j-1] =
new Bin;
1670 bins[i][j-1]->prepend( movedItem );
1672 else if ( bf ==mini ) {
1674 Bin::iterator it = items->begin();
1676 for ( ++it; it != items->end(); ++it ) {
1677 if ( (*it)->y() > movedItem->y() )
1680 items->remove( movedItem );
1681 if ( !bins[i][j+1] )
1682 bins[i][j+1] =
new Bin;
1683 bins[i][j+1]->prepend( movedItem );
1685 else if ( lf == mini )
1688 Bin::iterator it = items->begin();
1690 for ( ++it; it != items->end(); ++it ) {
1691 if ( (*it)->x() < movedItem->x() )
1694 items->remove( movedItem );
1695 if ( !bins[i-1][j] )
1696 bins[i-1][j] =
new Bin;
1697 bins[i-1][j]->prepend( movedItem );
1701 Bin::iterator it = items->begin();
1703 for ( ++it; it != items->end(); ++it ) {
1704 if ( (*it)->x() > movedItem->x() )
1707 items->remove( movedItem );
1708 if ( !bins[i+1][j] )
1709 bins[i+1][j] =
new Bin;
1710 bins[i+1][j]->prepend( movedItem );
1718 TQRegion repaintRegion;
1719 TQValueList<TQIconViewItem*> movedItems;
1721 for ( i = 0; i < nx; i++ ) {
1722 for ( j = 0; j < ny; j++ ) {
1723 Bin* bin = bins[i][j];
1726 if ( !bin->isEmpty() ) {
1727 TQIconViewItem* item = bin->first();
1728 int newX = x0 + i*dx + spacing() +
1729 TQMAX(0, ( (dx-spacing()) - item->width() ) / 2);
1731 int newY = y0 + j*dy + dy - spacing() - ( item->pixmapRect().bottom() + 2 + textHeight );
1732 if ( item->x() != newX || item->y() != newY ) {
1733 TQRect oldRect = item->rect();
1734 movedItems.prepend( item );
1735 item->move( newX, newY );
1736 if ( item->rect() != oldRect )
1737 repaintRegion = repaintRegion.unite( oldRect );
1750 TQMemArray<TQRect> rects = repaintRegion.rects();
1751 for ( uint l = 0; l < rects.count(); l++ ) {
1752 kdDebug( 1203 ) <<
"Repainting (" << rects[l].x() <<
","
1753 << rects[l].y() <<
")\n";
1754 repaintContents( rects[l],
false );
1757 while ( !movedItems.isEmpty() ) {
1758 repaintItem( movedItems.first() );
1759 movedItems.remove( movedItems.first() );
1763 for ( i = 0; i < nx ; i++ ) {
1771 int x0, y0, dx, dy, nxmax, nymax;
1772 gridValues( &x0, &y0, &dx, &dy, &nxmax, &nymax );
1773 int textHeight = iconTextHeight() * fontMetrics().height();
1775 TQRegion repaintRegion;
1776 TQValueList<TQIconViewItem*> movedItems;
1779 TQIconViewItem* item;
1780 for ( item = firstItem(); item; item = item->nextItem() ) {
1781 int newX = x0 + nx*dx + spacing() +
1782 TQMAX(0, ( (dx-spacing()) - item->width() ) / 2);
1784 int newY = y0 + ny*dy + dy - spacing() - ( item->pixmapRect().bottom() + 2 + textHeight );
1785 if ( item->x() != newX || item->y() != newY ) {
1786 TQRect oldRect = item->rect();
1787 movedItems.prepend( item );
1788 item->move( newX, newY );
1789 if ( item->rect() != oldRect )
1790 repaintRegion = repaintRegion.unite( oldRect );
1792 if ( arrangement == TQIconView::LeftToRight ) {
1794 if ( nx >= nxmax ) {
1801 if ( ny >= nymax ) {
1809 TQMemArray<TQRect> rects = repaintRegion.rects();
1810 for ( uint l = 0; l < rects.count(); l++ ) {
1811 kdDebug( 1203 ) <<
"Repainting (" << rects[l].x() <<
","
1812 << rects[l].y() <<
")\n";
1813 repaintContents( rects[l],
false );
1816 while ( !movedItems.isEmpty() ) {
1817 repaintItem( movedItems.first() );
1818 movedItems.remove( movedItems.first() );
1822 int KonqIconViewWidget::largestPreviewIconSize(
int size )
const
1824 int iconSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1838 int KonqIconViewWidget::previewIconSize(
int size )
const
1840 int iconSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1842 if (!d->bBoostPreview)
1845 return largestPreviewIconSize( iconSize );
1851 TQRect irect = item->rect();
1854 TQRect rect = item->pixmapRect();
1858 rect.moveBy(irect.x(), irect.y());
1861 rect.moveBy( -contentsX(), -contentsY() );
1863 if (TDEGlobalSettings::showKonqIconActivationEffect() ==
true) {
1864 TDEIconEffect::visualActivate(viewport(), rect, item->pixmap());
1868 void KonqIconViewWidget::backgroundPixmapChange(
const TQPixmap & )
1870 viewport()->update();
1873 void KonqIconViewWidget::setPreviewSettings(
const TQStringList& settings )
1875 d->previewSettings = settings;
1876 updatePreviewMimeTypes();
1883 const TQStringList& KonqIconViewWidget::previewSettings()
1885 return d->previewSettings;
1888 void KonqIconViewWidget::setNewURL(
const TQString& url )
1891 if ( url.startsWith(
"/" ) )
1898 void KonqIconViewWidget::setCaseInsensitiveSort(
bool b )
1900 d->bCaseInsensitive = b;
1903 bool KonqIconViewWidget::caseInsensitiveSort()
const
1905 return d->bCaseInsensitive;
1908 bool KonqIconViewWidget::canPreview( KFileItem* item )
1910 if ( !TDEGlobalSettings::showFilePreview( url() ) )
1913 if ( d->pPreviewMimeTypes == 0L )
1914 updatePreviewMimeTypes();
1916 return mimeTypeMatch( item->mimetype(), *( d->pPreviewMimeTypes ) );
1919 void KonqIconViewWidget::updatePreviewMimeTypes()
1921 if ( d->pPreviewMimeTypes == 0L )
1922 d->pPreviewMimeTypes =
new TQStringList;
1924 d->pPreviewMimeTypes->clear();
1927 TDETrader::OfferList plugins = TDETrader::self()->query(
"ThumbCreator");
1928 TDETrader::OfferList::ConstIterator it;
1930 for ( it = plugins.begin(); it != plugins.end(); ++it ) {
1931 if ( d->previewSettings.contains((*it)->desktopEntryName()) ) {
1932 TQStringList mimeTypes = (*it)->property(
"MimeTypes").toStringList();
1933 for (TQStringList::ConstIterator mt = mimeTypes.begin(); mt != mimeTypes.end(); ++mt)
1934 d->pPreviewMimeTypes->append(*mt);
1939 #include "konq_iconviewwidget.moc"
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem,...
virtual void setIcon(int size, int state=TDEIcon::DefaultState, bool recalc=false, bool redraw=false)
Changes the icon for this item.
void invalidateThumb(int state, bool redraw=false)
Notifies that all icon effects on thumbs should be invalidated, e.g.
int state() const
Return the current state of the icon (TDEIcon::DefaultState, TDEIcon::ActiveState etc....
void setThumbnailPixmap(const TQPixmap &pixmap)
Set this when the thumbnail was loaded.
static KonqFMSettings * settings()
The static instance of KonqFMSettings.
Clipboard/dnd data for: Icons + URLs + MostLocal URLs + isCut KDE4: merge with KonqIconDrag.
static void doPaste(TQWidget *parent, const KURL &destURL, const TQPoint &pos)
Paste the clipboard contents.
static void rename(TQWidget *parent, const KURL &oldurl, const TQString &name)
Do a renaming.
static void doDrop(const KFileItem *destItem, const KURL &destURL, TQDropEvent *ev, TQWidget *parent)
Drop.