• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkonq
 

libkonq

  • libkonq
konq_iconviewwidget.cpp
1 /* This file is part of the KDE projects
2  Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3  Copyright (C) 2000 - 2005 David Faure <faure@kde.org>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
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"
25 
26 #include <tqclipboard.h>
27 #include <tqlayout.h>
28 #include <tqtimer.h>
29 #include <tqpainter.h>
30 #include <tqtooltip.h>
31 #include <tqlabel.h>
32 #include <tqmovie.h>
33 #include <tqregexp.h>
34 #include <tqcursor.h>
35 
36 #include <tdeapplication.h>
37 #include <kdebug.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>
44 #include <kipc.h>
45 #include <kicontheme.h>
46 #include <kiconeffect.h>
47 #include <kurldrag.h>
48 #include <tdestandarddirs.h>
49 #include <kprotocolinfo.h>
50 #include <ktrader.h>
51 
52 #include <assert.h>
53 #include <unistd.h>
54 #include <tdelocale.h>
55 
56 
57 struct KonqIconViewWidgetPrivate
58 {
59  KonqIconViewWidgetPrivate() {
60  pActiveItem = 0;
61  bSoundPreviews = false;
62  pSoundItem = 0;
63  bSoundItemClicked = false;
64  pSoundPlayer = 0;
65  pSoundTimer = 0;
66  pPreviewJob = 0;
67  bAllowSetWallpaper = false;
68 
69  doAnimations = true;
70  m_movie = 0L;
71  m_movieBlocked = 0;
72  pFileTip = 0;
73  pActivateDoubleClick = 0L;
74  bCaseInsensitive = true;
75  pPreviewMimeTypes = 0L;
76  bProgramsURLdrag = false;
77  }
78  ~KonqIconViewWidgetPrivate() {
79  delete pSoundPlayer;
80  delete pSoundTimer;
81  delete m_movie;
82  delete pFileTip;
83  delete pActivateDoubleClick;
84  delete pPreviewMimeTypes;
85  //delete pPreviewJob; done by stopImagePreview
86  }
87  KFileIVI *pActiveItem;
88  // Sound preview
89  KFileIVI *pSoundItem;
90  KonqSoundPlayer *pSoundPlayer;
91  TQTimer *pSoundTimer;
92  bool bSoundPreviews;
93  bool bSoundItemClicked;
94  bool bAllowSetWallpaper;
95  bool bCaseInsensitive;
96  bool bBoostPreview;
97 
98  // Animated icons support
99  bool doAnimations;
100  TQMovie* m_movie;
101  int m_movieBlocked;
102  TQString movieFileName;
103 
104  TDEIO::PreviewJob *pPreviewJob;
105  KonqFileTip* pFileTip;
106  TQStringList previewSettings;
107  bool renameItem;
108  bool firstClick;
109  bool releaseMouseEvent;
110  TQPoint mousePos;
111  int mouseState;
112  TQTimer *pActivateDoubleClick;
113  TQStringList* pPreviewMimeTypes;
114  bool bProgramsURLdrag;
115 };
116 
117 KonqIconViewWidget::KonqIconViewWidget( TQWidget * parent, const char * name, WFlags f, bool kdesktop )
118  : TDEIconView( parent, name, f ),
119  m_rootItem( 0L ), m_size( 0 ) /* default is DesktopIcon size */,
120  m_bDesktop( kdesktop ),
121  m_bSetGridX( !kdesktop ) /* No line breaking on the desktop */
122 {
123  d = new KonqIconViewWidgetPrivate;
124  connect( this, TQ_SIGNAL( dropped( TQDropEvent *, const TQValueList<TQIconDragItem> & ) ),
125  this, TQ_SLOT( slotDropped( TQDropEvent*, const TQValueList<TQIconDragItem> & ) ) );
126 
127  connect( this, TQ_SIGNAL( selectionChanged() ),
128  this, TQ_SLOT( slotSelectionChanged() ) );
129 
130  tdeApp->addKipcEventMask( KIPC::IconChanged );
131  connect( tdeApp, 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 &)) );
135 
136  m_pSettings = KonqFMSettings::settings(); // already needed in setItemTextPos(), calculateGridX()
137  d->bBoostPreview = boostPreview();
138 
139  // hardcoded settings
140  setSelectionMode( TQIconView::Extended );
141  setItemTextPos( TQIconView::Bottom );
142  d->releaseMouseEvent = false;
143  d->pFileTip = new KonqFileTip(this);
144  d->firstClick = false;
145  calculateGridX();
146  setAutoArrange( true );
147  setSorting( true, sortDirection() );
148  readAnimatedIconsConfig();
149  m_bSortDirsFirst = true;
150  m_bMousePressed = false;
151  m_LineupMode = LineupBoth;
152  // emit our signals
153  slotSelectionChanged();
154  m_iconPositionGroupPrefix = TQString::fromLatin1( "IconPosition::" );
155  KonqUndoManager::incRef();
156 }
157 
158 KonqIconViewWidget::~KonqIconViewWidget()
159 {
160  stopImagePreview();
161  KonqUndoManager::decRef();
162  delete d;
163 }
164 
165 bool KonqIconViewWidget::maySetWallpaper()
166 {
167  return d->bAllowSetWallpaper;
168 }
169 
170 void KonqIconViewWidget::setMaySetWallpaper(bool b)
171 {
172  d->bAllowSetWallpaper = b;
173 }
174 
175 void KonqIconViewWidget::focusOutEvent( TQFocusEvent * ev )
176 {
177  // We can't possibly have the mouse pressed and still lose focus.
178  // Well, we can, but when we regain focus we should assume the mouse is
179  // not down anymore or the slotOnItem code will break with highlighting!
180  m_bMousePressed = false;
181 
182  // This will ensure that tooltips don't pop up and the mouseover icon
183  // effect will go away if the mouse goes out of the view without
184  // first moving into an empty portion of the view
185  // Fixes part of #86968, and #85204
186  // Matt Newell 2004-09-24
187  slotOnViewport();
188 
189  TDEIconView::focusOutEvent( ev );
190 }
191 
192 void KonqIconViewWidget::slotItemRenamed(TQIconViewItem *item, const TQString &name)
193 {
194  kdDebug(1203) << "KonqIconViewWidget::slotItemRenamed" << endl;
195  KFileIVI *viewItem = static_cast<KFileIVI *>(item);
196  KFileItem *fileItem = viewItem->item();
197 
198  // The correct behavior is to show the old name until the rename has successfully
199  // completed. Unfortunately, TDEIconView forces us to allow the text to be changed
200  // before we try the rename, so set it back to the pre-rename state.
201  viewItem->setText( fileItem->text() );
202  kdDebug(1203)<<" fileItem->text() ;"<<fileItem->text()<<endl;
203  // Don't do anything if the user renamed to a blank name.
204  if( !name.isEmpty() )
205  {
206  // Actually attempt the rename. If it succeeds, KDirLister will update the name.
207  KURL oldurl( fileItem->url() );
208  KURL newurl( oldurl );
209  newurl.setPath( newurl.directory(false) + TDEIO::encodeFileName( name ) );
210  kdDebug(1203)<<" newurl :"<<newurl<<endl;
211  // We use url()+name so that it also works if the name is a relative path (#51176)
212  KonqOperations::rename( this, oldurl, newurl );
213  }
214 }
215 
216 void KonqIconViewWidget::slotIconChanged( int group )
217 {
218  if (group != TDEIcon::Desktop)
219  return;
220 
221  int size = m_size;
222  if ( m_size == 0 )
223  m_size = -1; // little trick to force grid change in setIcons
224  setIcons( size ); // force re-determining all icons
225  readAnimatedIconsConfig();
226 }
227 
228 void KonqIconViewWidget::readAnimatedIconsConfig()
229 {
230  TDEConfigGroup cfgGroup( TDEGlobal::config(), "DesktopIcons" );
231  d->doAnimations = cfgGroup.readBoolEntry( "Animated", true /*default*/ );
232 }
233 
234 void KonqIconViewWidget::slotOnItem( TQIconViewItem *_item )
235 {
236  KFileIVI* item = static_cast<KFileIVI *>( _item );
237  // Reset icon of previous item
238  if( d->pActiveItem != 0L && d->pActiveItem != item )
239  {
240  if ( d->m_movie && d->pActiveItem->isAnimated() )
241  {
242  d->m_movie->pause(); // we'll see below what we do with it
243  d->pActiveItem->setAnimated( false );
244  d->pActiveItem->refreshIcon( true );
245  }
246  else {
247  d->pActiveItem->setActive( false );
248  }
249  d->pActiveItem = 0L;
250  d->pFileTip->setItem( 0L );
251  }
252 
253  // Stop sound
254  if (d->pSoundPlayer != 0 && item != d->pSoundItem)
255  {
256  d->pSoundPlayer->stop();
257 
258  d->pSoundItem = 0;
259  if (d->pSoundTimer && d->pSoundTimer->isActive())
260  d->pSoundTimer->stop();
261  }
262 
263  if ( !m_bMousePressed )
264  {
265  if( item != d->pActiveItem )
266  {
267  d->pActiveItem = item;
268  d->pFileTip->setItem( d->pActiveItem->item(),
269  item->rect(),
270  item->pixmap() );
271 
272  if ( d->doAnimations && d->pActiveItem && d->pActiveItem->hasAnimation() )
273  {
274  //kdDebug(1203) << "Playing animation for: " << d->pActiveItem->mouseOverAnimation() << endl;
275  // Check if cached movie can be used
276 #if 0 // Qt-mng bug, reusing the movie doesn't work currently.
277  if ( d->m_movie && d->movieFileName == d->pActiveItem->mouseOverAnimation() )
278  {
279  d->pActiveItem->setAnimated( true );
280  if (d->m_movieBlocked) {
281  kdDebug(1203) << "onitem, but blocked" << endl;
282  d->m_movie->pause();
283  }
284  else {
285  kdDebug(1203) << "we go ahead.." << endl;
286  d->m_movieBlocked++;
287  TQTimer::singleShot(300, this, TQ_SLOT(slotReenableAnimation()));
288  d->m_movie->restart();
289  d->m_movie->unpause();
290  }
291  }
292  else
293 #endif
294  {
295  TQMovie movie = TDEGlobal::iconLoader()->loadMovie( d->pActiveItem->mouseOverAnimation(), TDEIcon::Desktop, d->pActiveItem->iconSize() );
296  if ( !movie.isNull() )
297  {
298  delete d->m_movie;
299  d->m_movie = new TQMovie( movie ); // shallow copy, don't worry
300  // Fix alpha-channel - currently only if no background pixmap,
301  // the bg pixmap case requires to uncomment the code at qmovie.cpp:404
302  const TQPixmap* pm = backgroundPixmap();
303  bool hasPixmap = pm && !pm->isNull();
304  if ( !hasPixmap ) {
305  pm = viewport()->backgroundPixmap();
306  hasPixmap = pm && !pm->isNull();
307  }
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 );
314  }
315  else
316  {
317  d->pActiveItem->setAnimated( false );
318  if (d->m_movie)
319  d->m_movie->pause();
320  // No movie available, remember it
321  d->pActiveItem->setMouseOverAnimation( TQString::null );
322  }
323  }
324  } // animations
325  // Only do the normal "mouseover" effect if no animation is in use
326  if (d->pActiveItem && !d->pActiveItem->isAnimated())
327  {
328  d->pActiveItem->setActive( true );
329  }
330  }
331  else // No change in current item
332  {
333  // No effect. If we want to underline on hover, we should
334  // force the IVI to repaint here, though!
335  d->pActiveItem = 0L;
336  d->pFileTip->setItem( 0L );
337  }
338  } // bMousePressed
339  else
340  {
341  // All features disabled during mouse clicking, e.g. rectangular
342  // selection
343  d->pActiveItem = 0L;
344  d->pFileTip->setItem( 0L );
345  }
346 
347  // ## shouldn't this be disabled during rectangular selection too ?
348  if (d->bSoundPreviews && d->pSoundPlayer &&
349  d->pSoundPlayer->mimeTypes().contains(
350  item->item()->mimetype())
351  && TDEGlobalSettings::showFilePreview(item->item()->url())
352  && topLevelWidget() == tdeApp->activeWindow())
353  {
354  d->pSoundItem = item;
355  d->bSoundItemClicked = false;
356  if (!d->pSoundTimer)
357  {
358  d->pSoundTimer = new TQTimer(this);
359  connect(d->pSoundTimer, TQ_SIGNAL(timeout()), TQ_SLOT(slotStartSoundPreview()));
360  }
361  if (d->pSoundTimer->isActive())
362  d->pSoundTimer->stop();
363  d->pSoundTimer->start(500, true);
364  }
365  else
366  {
367  if (d->pSoundPlayer)
368  d->pSoundPlayer->stop();
369  d->pSoundItem = 0;
370  if (d->pSoundTimer && d->pSoundTimer->isActive())
371  d->pSoundTimer->stop();
372  }
373 }
374 
375 void KonqIconViewWidget::slotOnViewport()
376 {
377  d->pFileTip->setItem( 0L );
378 
379  if (d->pSoundPlayer)
380  d->pSoundPlayer->stop();
381  d->pSoundItem = 0;
382  if (d->pSoundTimer && d->pSoundTimer->isActive())
383  d->pSoundTimer->stop();
384 
385  if (d->pActiveItem == 0L)
386  return;
387 
388  if ( d->doAnimations && d->m_movie && d->pActiveItem->isAnimated() )
389  {
390  d->pActiveItem->setAnimated( false );
391 #if 0
392  // Aborting before the end of the animation ?
393  if (d->m_movie->running()) {
394  d->m_movie->pause();
395  d->m_movieBlocked++;
396  kdDebug(1203) << "on viewport, blocking" << endl;
397  TQTimer::singleShot(300, this, TQ_SLOT(slotReenableAnimation()));
398  }
399 #endif
400  d->pActiveItem->refreshIcon( true );
401  Q_ASSERT( d->pActiveItem->state() == TDEIcon::DefaultState );
402  //delete d->m_movie;
403  //d->m_movie = 0L;
404  // TODO a timer to delete the movie after some time if unused?
405  }
406  else
407  {
408  d->pActiveItem->setActive( false );
409  }
410  d->pActiveItem = 0L;
411 }
412 
413 void KonqIconViewWidget::slotStartSoundPreview()
414 {
415  if (!d->pSoundItem || d->bSoundItemClicked)
416  return;
417 
418  d->pSoundPlayer->play(d->pSoundItem->item()->url().url());
419 }
420 
421 
422 void KonqIconViewWidget::slotPreview(const KFileItem *item, const TQPixmap &pix)
423 {
424  // ### slow. Idea: move KonqKfmIconView's m_itemDict into this class
425  for (TQIconViewItem *it = firstItem(); it; it = it->nextItem())
426  {
427  KFileIVI* current = static_cast<KFileIVI *>(it);
428  if (current->item() == item)
429  {
430  if (item->overlays() & TDEIcon::HiddenOverlay) {
431  TQPixmap p(pix);
432 
433  TDEIconEffect::semiTransparent(p);
434  current->setThumbnailPixmap(p);
435  } else {
436  current->setThumbnailPixmap(pix);
437  }
438  break;
439  }
440  }
441 }
442 
443 void KonqIconViewWidget::slotPreviewResult()
444 {
445  d->pPreviewJob = 0;
446  emit imagePreviewFinished();
447 }
448 
449 void KonqIconViewWidget::slotToolTipPreview(const KFileItem* , const TQPixmap &)
450 {
451 // unused - remove for KDE4
452 }
453 
454 void KonqIconViewWidget::slotToolTipPreviewResult()
455 {
456 // unused - remove for KDE4
457 }
458 
459 void KonqIconViewWidget::slotMovieUpdate( const TQRect& rect )
460 {
461  //kdDebug(1203) << "KonqIconViewWidget::slotMovieUpdate " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl;
462  Q_ASSERT( d );
463  Q_ASSERT( d->m_movie );
464  // seems stopAnimation triggers one last update
465  if ( d->pActiveItem && d->m_movie && d->pActiveItem->isAnimated() ) {
466  const TQPixmap &frame = d->m_movie->framePixmap();
467  // This can happen if the icon was scaled to the desired size, so TDEIconLoader
468  // will happily return a movie with different dimensions than the icon
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 );
473  d->m_movie->pause();
474  // No movie available, remember it
475  d->pActiveItem->setMouseOverAnimation( TQString::null );
476  d->pActiveItem->setActive( true );
477  return;
478  }
479  d->pActiveItem->setPixmapDirect( frame, false, false /*no redraw*/ );
480  TQRect pixRect = d->pActiveItem->pixmapRect(false);
481  repaintContents( pixRect.x() + rect.x(), pixRect.y() + rect.y(), rect.width(), rect.height(), false );
482  }
483 }
484 
485 void KonqIconViewWidget::slotMovieStatus( int status )
486 {
487  if ( status < 0 ) {
488  // Error playing the MNG -> forget about it and do normal iconeffect
489  if ( d->pActiveItem && d->pActiveItem->isAnimated() ) {
490  d->pActiveItem->setAnimated( false );
491  d->pActiveItem->setMouseOverAnimation( TQString::null );
492  d->pActiveItem->setActive( true );
493  }
494  }
495 }
496 
497 void KonqIconViewWidget::slotReenableAnimation()
498 {
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();
504  }
505  }
506 }
507 
508 void KonqIconViewWidget::clear()
509 {
510  d->pFileTip->setItem( 0L );
511  stopImagePreview(); // Just in case
512  TDEIconView::clear();
513  d->pActiveItem = 0L;
514 }
515 
516 void KonqIconViewWidget::takeItem( TQIconViewItem *item )
517 {
518  if ( d->pActiveItem == static_cast<KFileIVI *>(item) )
519  {
520  d->pFileTip->setItem( 0L );
521  d->pActiveItem = 0L;
522  }
523 
524  if ( d->pPreviewJob )
525  d->pPreviewJob->removeItem( static_cast<KFileIVI *>(item)->item() );
526 
527  TDEIconView::takeItem( item );
528 }
529 
530 // Currently unused - remove in KDE 4.0
531 void KonqIconViewWidget::setThumbnailPixmap( KFileIVI * item, const TQPixmap & pixmap )
532 {
533  if ( item )
534  {
535  if ( d->pActiveItem == item )
536  {
537  d->pFileTip->setItem( 0L );
538  d->pActiveItem = 0L;
539  }
540  item->setThumbnailPixmap( pixmap );
541  if ( m_bSetGridX && item->width() > gridX() )
542  {
543  setGridX( item->width() );
544  if (autoArrange())
545  arrangeItemsInGrid();
546  }
547  }
548 }
549 
550 bool KonqIconViewWidget::initConfig( bool bInit )
551 {
552  bool fontChanged = false;
553 
554  // Color settings
555  TQColor normalTextColor = m_pSettings->normalTextColor();
556  setItemColor( normalTextColor );
557 
558  if (m_bDesktop)
559  {
560  TQColor itemTextBg = m_pSettings->itemTextBackground();
561  if ( itemTextBg.isValid() )
562  setItemTextBackground( itemTextBg );
563  else
564  setItemTextBackground( TQt::NoBrush );
565  }
566 
567  bool on = m_pSettings->showFileTips() && TQToolTip::isGloballyEnabled();
568  d->pFileTip->setOptions(on,
569  m_pSettings->showPreviewsInFileTips(),
570  m_pSettings->numFileTips());
571 
572  // if the user wants our own tooltip, don't show the one from Qts ListView
573  setShowToolTips(!on);
574 
575  // Font settings
576  TQFont font( m_pSettings->standardFont() );
577  if (!m_bDesktop)
578  font.setUnderline( m_pSettings->underlineLink() );
579 
580  if ( font != KonqIconViewWidget::font() )
581  {
582  setFont( font );
583  if (!bInit)
584  {
585  // TQIconView doesn't do it by default... but if the font is made much
586  // bigger, we really need to give more space between the icons
587  fontChanged = true;
588  }
589  }
590 
591  setIconTextHeight( m_pSettings->iconTextHeight() );
592 
593  if ( (itemTextPos() == TQIconView::Right) && (maxItemWidth() != gridXValue()) )
594  {
595  int size = m_size;
596  m_size = -1; // little trick to force grid change in setIcons
597  setIcons( size ); // force re-determining all icons
598  }
599  else if ( d->bBoostPreview != boostPreview() ) // Update icons if settings for preview icon size have changed
600  setIcons(m_size);
601  else if (!bInit)
602  updateContents();
603  return fontChanged;
604 }
605 
606 bool KonqIconViewWidget::boostPreview() const
607 {
608  if ( m_bDesktop ) return false;
609 
610  TDEConfigGroup group( TDEGlobal::config(), "PreviewSettings" );
611  return group.readBoolEntry( "BoostSize", false );
612 }
613 
614 void KonqIconViewWidget::disableSoundPreviews()
615 {
616  d->bSoundPreviews = false;
617 
618  if (d->pSoundPlayer)
619  d->pSoundPlayer->stop();
620  d->pSoundItem = 0;
621  if (d->pSoundTimer && d->pSoundTimer->isActive())
622  d->pSoundTimer->stop();
623 }
624 
625 void KonqIconViewWidget::setIcons( int size, const TQStringList& stopImagePreviewFor )
626 {
627  // size has changed?
628  bool sizeChanged = (m_size != size);
629  int oldGridX = gridX();
630  m_size = size;
631 
632  // boost preview option has changed?
633  bool boost = boostPreview();
634  bool previewSizeChanged = ( d->bBoostPreview != boost );
635  d->bBoostPreview = boost;
636 
637  if ( sizeChanged || previewSizeChanged )
638  {
639  int realSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
640  // choose spacing depending on font, but min 5 (due to KFileIVI move limit)
641  setSpacing( ( m_bDesktop || ( realSize > TDEIcon::SizeSmall ) ) ?
642  TQMAX( spacing(), TQFontMetrics(font()).width('n') ) : 0 );
643  }
644 
645  if ( sizeChanged || previewSizeChanged || !stopImagePreviewFor.isEmpty() )
646  {
647  calculateGridX();
648  }
649  bool stopAll = !stopImagePreviewFor.isEmpty() && stopImagePreviewFor.first() == "*";
650 
651  // Disable repaints that can be triggered by ivi->setIcon(). Since icons are
652  // resized in-place, if the icon size is increasing it can happens that the right
653  // or bottom icons exceed the size of the viewport.. here we prevent the repaint
654  // event that will be triggered in that case.
655  bool prevUpdatesState = viewport()->isUpdatesEnabled();
656  viewport()->setUpdatesEnabled( false );
657 
658  // Do this even if size didn't change, since this is used by refreshMimeTypes...
659  for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
660  KFileIVI * ivi = static_cast<KFileIVI *>( it );
661  // Set a normal icon for files that are not thumbnails, and for files
662  // that are thumbnails but for which it should be stopped
663  if ( !ivi->isThumbnail() ||
664  sizeChanged ||
665  previewSizeChanged ||
666  stopAll ||
667  mimeTypeMatch( ivi->item()->mimetype(), stopImagePreviewFor ) )
668  {
669  ivi->setIcon( size, ivi->state(), true, false );
670  }
671  else
672  ivi->invalidateThumb( ivi->state(), true );
673  }
674 
675  // Restore viewport update to previous state
676  viewport()->setUpdatesEnabled( prevUpdatesState );
677 
678  if ( ( sizeChanged || previewSizeChanged || oldGridX != gridX() ||
679  !stopImagePreviewFor.isEmpty() ) && autoArrange() )
680  arrangeItemsInGrid( true ); // take new grid into account and repaint
681  else
682  viewport()->update(); //Repaint later..
683 }
684 
685 bool KonqIconViewWidget::mimeTypeMatch( const TQString& mimeType, const TQStringList& mimeList ) const
686 {
687  // Code duplication from TDEIO::PreviewJob
688  KMimeType::Ptr mime = KMimeType::mimeType( mimeType );
689  for (TQStringList::ConstIterator mt = mimeList.begin(); mt != mimeList.end(); ++mt)
690  {
691  if ( mime->is( *mt ) )
692  return true;
693  // Support for *mt == "image/*"
694  TQString tmp( mimeType );
695  if ( (*mt).endsWith("*") && tmp.replace(TQRegExp("/.*"), "/*") == (*mt) )
696  return true;
697  if ( (*mt) == "text/plain" )
698  {
699  TQVariant textProperty = mime->property( "X-TDE-text" );
700  if ( textProperty.type() == TQVariant::Bool && textProperty.toBool() )
701  return true;
702  }
703  }
704  return false;
705 }
706 
707 void KonqIconViewWidget::setItemTextPos( ItemTextPos pos )
708 {
709  // can't call gridXValue() because this already would need the new itemTextPos()
710  int sz = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
711 
712  if ( m_bSetGridX ) {
713  if ( pos == TQIconView::Bottom ) {
714  setGridX( TQMAX( sz + 50, previewIconSize( sz ) + 13 ) );
715  }
716  else
717  {
718  setMaxItemWidth( TQMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth() );
719  setGridX( -1 );
720  }
721  }
722 
723  TDEIconView::setItemTextPos( pos );
724 }
725 
726 void KonqIconViewWidget::gridValues( int* x, int* y, int* dx, int* dy,
727  int* nx, int* ny )
728 {
729  int previewSize = previewIconSize( m_size );
730  int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
731 
732  // Grid size
733  // as KFileIVI limits to move an icon to x >= 5, y >= 5, we define a grid cell as:
734  // spacing() must be >= 5 (currently set to 5 in setIcons())
735  // horizontal: left spacing() + <width>
736  // vertical : top spacing(), <height>, bottom spacing()
737  // The doubled space in y-direction gives a better visual separation and makes it clearer
738  // to which item the text belongs
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();
742 
743  // Icon Area
744  int w, h;
745  if ( m_IconRect.isValid() ) { // w and h must be != 0, otherwise we would get a div by zero
746  *x = m_IconRect.left(); w = m_IconRect.width();
747  *y = m_IconRect.top(); h = m_IconRect.height();
748  }
749  else {
750  *x = 0; w = viewport()->width();
751  *y = 0; h = viewport()->height();
752  }
753 
754  // bug:110775 avoid div by zero (happens e.g. when iconTextHeight or iconTextWidth are very large)
755  if ( *dx > w )
756  *dx = w;
757 
758  if ( *dy > h )
759  *dy = h;
760 
761  *nx = w / *dx;
762  *ny = h / *dy;
763  // TODO: Check that items->count() <= nx * ny
764 
765  // Let have exactly nx columns and ny rows
766  if(*nx && *ny) {
767  *dx = w / *nx;
768  *dy = h / *ny;
769  }
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;
774 }
775 
776 void KonqIconViewWidget::calculateGridX()
777 {
778  if ( m_bSetGridX ) {
779  if ( itemTextPos() == TQIconView::Bottom ) {
780  setGridX( gridXValue() );
781  }
782  else
783  {
784  setMaxItemWidth( gridXValue() );
785  setGridX( -1 );
786  }
787  }
788 }
789 
790 int KonqIconViewWidget::gridXValue() const
791 {
792  // this method is only used in konqi as filemanager (not desktop)
793  int sz = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
794  int newGridX;
795 
796  if ( itemTextPos() == TQIconView::Bottom )
797  newGridX = TQMAX( sz + 50, previewIconSize( sz ) + 13 );
798  else
799  newGridX = TQMAX( sz, previewIconSize( sz ) ) + m_pSettings->iconTextWidth();
800 
801  //kdDebug(1203) << "gridXValue: " << newGridX << " sz=" << sz << endl;
802  return newGridX;
803 }
804 
805 void KonqIconViewWidget::refreshMimeTypes()
806 {
807  updatePreviewMimeTypes();
808  for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
809  (static_cast<KFileIVI *>( it ))->item()->refreshMimeType();
810  setIcons( m_size );
811 }
812 
813 void KonqIconViewWidget::setURL( const KURL &kurl )
814 {
815  stopImagePreview();
816  m_url = kurl;
817 
818  d->pFileTip->setPreview( TDEGlobalSettings::showFilePreview(m_url) );
819 
820  if ( m_url.isLocalFile() )
821  m_dotDirectoryPath = m_url.path(1).append( ".directory" );
822  else
823  m_dotDirectoryPath = TQString::null;
824 }
825 
826 void KonqIconViewWidget::startImagePreview( const TQStringList &, bool force )
827 {
828  stopImagePreview(); // just in case
829 
830  // Check config
831  if ( !TDEGlobalSettings::showFilePreview( url() ) ) {
832  kdDebug(1203) << "Previews disabled for protocol " << url().protocol() << endl;
833  emit imagePreviewFinished();
834  return;
835  }
836 
837  if ((d->bSoundPreviews = d->previewSettings.contains( "audio/" )) &&
838  !d->pSoundPlayer)
839  {
840  KLibFactory *factory = KLibLoader::self()->factory("konq_sound");
841  if (factory)
842  d->pSoundPlayer = static_cast<KonqSoundPlayer *>(
843  factory->create(this, 0, "KonqSoundPlayer"));
844  d->bSoundPreviews = (d->pSoundPlayer != 0L);
845  }
846 
847  KFileItemList items;
848  for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
849  if ( force || !static_cast<KFileIVI *>( it )->hasValidThumbnail() )
850  items.append( static_cast<KFileIVI *>( it )->item() );
851 
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;
856  else
857  onlyAudio = false;
858  }
859 
860  if ( items.isEmpty() || onlyAudio ) {
861  emit imagePreviewFinished();
862  return; // don't start the preview job if not really necessary
863  }
864 
865  int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
866  int size;
867 
868  d->bBoostPreview = boostPreview();
869  size = previewIconSize( iconSize );
870 
871  if ( !d->bBoostPreview )
872  iconSize /= 2;
873 
874  d->pPreviewJob = TDEIO::filePreview( items, size, size, iconSize,
875  m_pSettings->textPreviewIconTransparency(), true /* scale */,
876  true /* save */, &(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() ) );
881 }
882 
883 void KonqIconViewWidget::stopImagePreview()
884 {
885  if (d->pPreviewJob)
886  {
887  d->pPreviewJob->kill();
888  d->pPreviewJob = 0;
889  // Now that previews are updated in-place, calling
890  // arrangeItemsInGrid() here is not needed anymore
891  }
892 }
893 
894 bool KonqIconViewWidget::isPreviewRunning() const
895 {
896  return d->pPreviewJob;
897 }
898 
899 KFileItemList KonqIconViewWidget::selectedFileItems()
900 {
901  KFileItemList lstItems;
902 
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 );
908  }
909  return lstItems;
910 }
911 
912 void KonqIconViewWidget::slotDropped( TQDropEvent *ev, const TQValueList<TQIconDragItem> & )
913 {
914  // Drop on background
915  KURL dirURL = url();
916  if ( m_rootItem ) {
917  bool dummy;
918  dirURL = m_rootItem->mostLocalURL(dummy);
919  }
920  KonqOperations::doDrop( m_rootItem /* may be 0L */, dirURL, ev, this );
921 }
922 
923 void KonqIconViewWidget::slotAboutToCreate(const TQPoint &, const TQValueList<TDEIO::CopyInfo> &)
924 {
925  // Do nothing :-)
926 }
927 
928 void KonqIconViewWidget::drawBackground( TQPainter *p, const TQRect &r )
929 {
930  drawBackground(p, r, r.topLeft());
931 }
932 
933 void KonqIconViewWidget::drawBackground( TQPainter *p, const TQRect &r , const TQPoint &pt)
934 {
935  const TQPixmap *pm = backgroundPixmap();
936  bool hasPixmap = pm && !pm->isNull();
937  if ( !hasPixmap ) {
938  pm = viewport()->backgroundPixmap();
939  hasPixmap = pm && !pm->isNull();
940  }
941 
942  TQRect rtgt(r);
943  rtgt.moveTopLeft(pt);
944  if (!hasPixmap && backgroundMode() != NoBackground) {
945  p->fillRect(rtgt, viewport()->backgroundColor());
946  return;
947  }
948 
949  if (hasPixmap) {
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));
953  }
954 }
955 
956 TQDragObject * KonqIconViewWidget::dragObject()
957 {
958  if ( !currentItem() )
959  return 0;
960 
961  return konqDragObject( viewport() );
962 }
963 
964 KonqIconDrag * KonqIconViewWidget::konqDragObject( TQWidget * dragSource )
965 {
966  //kdDebug(1203) << "KonqIconViewWidget::konqDragObject" << endl;
967 
968  KonqIconDrag2 * drag = new KonqIconDrag2( dragSource );
969  TQIconViewItem *primaryItem = currentItem();
970  // Append all items to the drag object
971  for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() ) {
972  if ( it->isVisible() && it->isSelected() ) {
973  if (!primaryItem)
974  primaryItem = it;
975  KFileItem* fileItem = (static_cast<KFileIVI *>(it))->item();
976  KURL url = fileItem->url();
977  bool dummy;
978  KURL mostLocalURL = fileItem->mostLocalURL(dummy);
979  TQString itemURL = KURLDrag::urlToString(url);
980  kdDebug(1203) << "itemURL=" << itemURL << endl;
981  TQIconDragItem id;
982  id.setData( TQCString(itemURL.latin1()) );
983  drag->append( id,
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 );
989  }
990  }
991 
992  if (primaryItem)
993  drag->setPixmap( *primaryItem->pixmap(), m_mousePos - primaryItem->pixmapRect(false).topLeft() );
994 
995  return drag;
996 }
997 
998 void KonqIconViewWidget::contentsDragEnterEvent( TQDragEnterEvent *e )
999 {
1000  if ( e->provides( "text/uri-list" ) )
1001  {
1002  TQByteArray payload = e->encodedData( "text/uri-list" );
1003  if ( !payload.size() )
1004  kdError() << "Empty data !" << endl;
1005  // Cache the URLs, since we need them every time we move over a file
1006  // (see KFileIVI)
1007  bool ok = KURLDrag::decode( e, m_lstDragURLs );
1008  if( !ok )
1009  kdError() << "Couldn't decode urls dragged !" << endl;
1010  }
1011 
1012  KURL::List uriList;
1013  if ( KURLDrag::decode(e, uriList) )
1014  {
1015  if ( uriList.first().protocol() == "programs" )
1016  {
1017  e->ignore();
1018  emit dragEntered( false );
1019  d->bProgramsURLdrag = true;
1020  return;
1021  }
1022  }
1023 
1024  TDEIconView::contentsDragEnterEvent( e );
1025  emit dragEntered( true /*accepted*/ );
1026 }
1027 
1028 void KonqIconViewWidget::contentsDragMoveEvent( TQDragMoveEvent *e )
1029 {
1030  if ( d->bProgramsURLdrag ) {
1031  emit dragMove( false );
1032  e->ignore();
1033  cancelPendingHeldSignal();
1034  return;
1035  }
1036 
1037  TQIconViewItem *item = findItem( e->pos() );
1038  if ( e->source() != viewport() &&
1039  !item && m_rootItem && !m_rootItem->isWritable() ) {
1040  emit dragMove( false );
1041  e->ignore();
1042  cancelPendingHeldSignal();
1043  return;
1044  }
1045  emit dragMove( true );
1046  TDEIconView::contentsDragMoveEvent( e );
1047 }
1048 
1049 void KonqIconViewWidget::contentsDragLeaveEvent( TQDragLeaveEvent *e )
1050 {
1051  d->bProgramsURLdrag = false;
1052  TDEIconView::contentsDragLeaveEvent(e);
1053  emit dragLeft();
1054 }
1055 
1056 
1057 void KonqIconViewWidget::setItemColor( const TQColor &c )
1058 {
1059  iColor = c;
1060 }
1061 
1062 TQColor KonqIconViewWidget::itemColor() const
1063 {
1064  return iColor;
1065 }
1066 
1067 void KonqIconViewWidget::disableIcons( const KURL::List & lst )
1068 {
1069  for ( TQIconViewItem *kit = firstItem(); kit; kit = kit->nextItem() )
1070  {
1071  bool bFound = false;
1072  // Wow. This is ugly. Matching two lists together....
1073  // Some sorting to optimise this would be a good idea ?
1074  for (KURL::List::ConstIterator it = lst.begin(); !bFound && it != lst.end(); ++it)
1075  {
1076  if ( static_cast<KFileIVI *>( kit )->item()->url() == *it )
1077  {
1078  bFound = true;
1079  // maybe remove "it" from lst here ?
1080  }
1081  }
1082  static_cast<KFileIVI *>( kit )->setDisabled( bFound );
1083  }
1084 }
1085 
1086 void KonqIconViewWidget::slotSelectionChanged()
1087 {
1088  // This code is very related to ListViewBrowserExtension::updateActions
1089  int canCopy = 0;
1090  int canDel = 0;
1091  int canTrash = 0;
1092  bool bInTrash = false;
1093  int iCount = 0;
1094 
1095  for ( TQIconViewItem *it = firstItem(); it; it = it->nextItem() )
1096  {
1097  if ( it->isVisible() && it->isSelected() )
1098  {
1099  iCount++;
1100  canCopy++;
1101 
1102  KFileItem *item = ( static_cast<KFileIVI *>( it ) )->item();
1103  KURL url = item->url();
1104  TQString local_path = item->localPath();
1105 
1106  if ( url.directory(false) == TDEGlobalSettings::trashPath() ) {
1107  bInTrash = true;
1108  }
1109  if ( KProtocolInfo::supportsDeleting( url ) ) {
1110  canDel++;
1111  }
1112  if ( !local_path.isEmpty() ) {
1113  canTrash++;
1114  }
1115  }
1116  }
1117 
1118  emit enableAction( "cut", canDel > 0 );
1119  emit enableAction( "copy", canCopy > 0 );
1120  emit enableAction( "trash", canDel > 0 && !bInTrash && canTrash==canDel );
1121  emit enableAction( "del", canDel > 0 );
1122  emit enableAction( "properties", iCount > 0 && KPropertiesDialog::canDisplay( selectedFileItems() ) );
1123  emit enableAction( "editMimeType", ( iCount == 1 ) );
1124  emit enableAction( "rename", ( iCount == 1) && !bInTrash );
1125 }
1126 
1127 void KonqIconViewWidget::renameCurrentItem()
1128 {
1129  if ( currentItem() )
1130  currentItem()->rename();
1131 }
1132 
1133 void KonqIconViewWidget::renameSelectedItem()
1134 {
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 )
1140  {
1141  item = it;
1142  break;
1143  }
1144  if (!item)
1145  {
1146  Q_ASSERT(item);
1147  return;
1148  }
1149  item->rename();
1150 }
1151 
1152 void KonqIconViewWidget::cutSelection()
1153 {
1154  kdDebug(1203) << " -- KonqIconViewWidget::cutSelection() -- " << endl;
1155  KonqIconDrag * obj = konqDragObject( /* no parent ! */ );
1156  obj->setMoveSelection( true );
1157  TQApplication::clipboard()->setData( obj );
1158 }
1159 
1160 void KonqIconViewWidget::copySelection()
1161 {
1162  kdDebug(1203) << " -- KonqIconViewWidget::copySelection() -- " << endl;
1163  KonqIconDrag * obj = konqDragObject( /* no parent ! */ );
1164  TQApplication::clipboard()->setData( obj );
1165 }
1166 
1167 void KonqIconViewWidget::pasteSelection()
1168 {
1169  paste( url() );
1170 }
1171 
1172 void KonqIconViewWidget::paste( const KURL &url )
1173 {
1174  KonqOperations::doPaste( this, url );
1175 }
1176 
1177 KURL::List KonqIconViewWidget::selectedUrls()
1178 {
1179  return selectedUrls( UserVisibleUrls );
1180 }
1181 
1182 KURL::List KonqIconViewWidget::selectedUrls( UrlFlags flags ) const
1183 {
1184  KURL::List lstURLs;
1185  bool dummy;
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() );
1190  }
1191  return lstURLs;
1192 }
1193 
1194 TQRect KonqIconViewWidget::iconArea() const
1195 {
1196  return m_IconRect;
1197 }
1198 
1199 void KonqIconViewWidget::setIconArea(const TQRect &rect)
1200 {
1201  m_IconRect = rect;
1202 }
1203 
1204 int KonqIconViewWidget::lineupMode() const
1205 {
1206  return m_LineupMode;
1207 }
1208 
1209 void KonqIconViewWidget::setLineupMode(int mode)
1210 {
1211  m_LineupMode = mode;
1212 }
1213 
1214 bool KonqIconViewWidget::sortDirectoriesFirst() const
1215 {
1216  return m_bSortDirsFirst;
1217 }
1218 
1219 void KonqIconViewWidget::setSortDirectoriesFirst( bool b )
1220 {
1221  m_bSortDirsFirst = b;
1222 }
1223 
1224 void KonqIconViewWidget::contentsMouseMoveEvent( TQMouseEvent *e )
1225 {
1226  if ( (d->pSoundPlayer && d->pSoundPlayer->isPlaying()) || (d->pSoundTimer && d->pSoundTimer->isActive()))
1227  {
1228  // The following call is SO expensive (the ::widgetAt call eats up to 80%
1229  // of the mouse move cpucycles!), so it's mandatory to place that function
1230  // under strict checks, such as d->pSoundPlayer->isPlaying()
1231  if ( TQApplication::widgetAt( TQCursor::pos() ) != topLevelWidget() )
1232  {
1233  if (d->pSoundPlayer)
1234  d->pSoundPlayer->stop();
1235  d->pSoundItem = 0;
1236  if (d->pSoundTimer && d->pSoundTimer->isActive())
1237  d->pSoundTimer->stop();
1238  }
1239  }
1240  d->renameItem= false;
1241  TDEIconView::contentsMouseMoveEvent( e );
1242 }
1243 
1244 void KonqIconViewWidget::contentsDropEvent( TQDropEvent * ev )
1245 {
1246  TQIconViewItem *i = findItem( ev->pos() );
1247  KURL::List uriList;
1248 
1249  if ( ev->source() != viewport() &&
1250  !i && m_rootItem && !m_rootItem->isWritable() ) {
1251  ev->accept( false );
1252  return;
1253  }
1254 
1255  // Short-circuit TQIconView if Ctrl is pressed, so that it's possible
1256  // to drop a file into its own parent widget to copy it.
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))
1261  {
1262  // First we need to call TQIconView though, to clear the drag shape
1263  bool bMovable = itemsMovable();
1264  setItemsMovable(false); // hack ? call it what you want :-)
1265  TDEIconView::contentsDropEvent( ev );
1266  setItemsMovable(bMovable);
1267 
1268  TQValueList<TQIconDragItem> lst;
1269  slotDropped(ev, lst);
1270  }
1271  else
1272  {
1273  TDEIconView::contentsDropEvent( ev );
1274  emit dropped(); // What is this for ? (David) KDE4: remove
1275  }
1276  // Don't do this here, it's too early !
1277  // slotSaveIconPositions();
1278  // If we want to save after the new file gets listed, though,
1279  // we could reimplement contentsDropEvent in KDIconView and set m_bNeedSave. Bah.
1280 
1281  // This signal is sent last because we need to ensure it is
1282  // taken in account when all the slots triggered by the dropped() signal
1283  // are executed. This way we know that the Drag and Drop is truely finished
1284  emit dragFinished();
1285 }
1286 
1287 void KonqIconViewWidget::doubleClickTimeout()
1288 {
1289  d->renameItem= true;
1290  mousePressChangeValue();
1291  if ( d->releaseMouseEvent )
1292  {
1293  TQMouseEvent e( TQEvent::MouseButtonPress,d->mousePos , 1, d->mouseState);
1294  TQIconViewItem* item = findItem( e.pos() );
1295  KURL url;
1296  if ( item )
1297  {
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;
1302 
1303  if ( url.isLocalFile() && !brenameTrash && d->renameItem && m_pSettings->renameIconDirectly() && e.button() == TQt::LeftButton && item->textRect( false ).contains(e.pos()))
1304  {
1305  if( d->pActivateDoubleClick->isActive () )
1306  d->pActivateDoubleClick->stop();
1307  item->rename();
1308  m_bMousePressed = false;
1309  }
1310  }
1311  }
1312  else
1313  {
1314  TQMouseEvent e( TQEvent::MouseMove,d->mousePos , 1, d->mouseState);
1315  TDEIconView::contentsMousePressEvent( &e );
1316  }
1317  if( d->pActivateDoubleClick->isActive() )
1318  d->pActivateDoubleClick->stop();
1319 
1320  d->releaseMouseEvent = false;
1321  d->renameItem= false;
1322 }
1323 
1324 void KonqIconViewWidget::wheelEvent(TQWheelEvent* e)
1325 {
1326  // when scrolling with mousewheel, stop possible pending filetip
1327  d->pFileTip->setItem( 0 );
1328 
1329  if (e->state() == ControlButton)
1330  {
1331  if (e->delta() >= 0)
1332  {
1333  emit incIconSize();
1334  }
1335  else
1336  {
1337  emit decIconSize();
1338  }
1339  e->accept();
1340  return;
1341  }
1342 
1343  TDEIconView::wheelEvent(e);
1344 }
1345 
1346 void KonqIconViewWidget::leaveEvent( TQEvent *e )
1347 {
1348  // when leaving the widget, stop possible pending filetip and icon effect
1349  slotOnViewport();
1350 
1351  TDEIconView::leaveEvent(e);
1352 }
1353 
1354 void KonqIconViewWidget::mousePressChangeValue()
1355 {
1356  //kdDebug(1203) << "KonqIconViewWidget::contentsMousePressEvent" << endl;
1357  m_bMousePressed = true;
1358  if (d->pSoundPlayer)
1359  d->pSoundPlayer->stop();
1360  d->bSoundItemClicked = true;
1361  d->firstClick = false;
1362 
1363  // Once we click on the item, we don't want a tooltip
1364  // Fixes part of #86968
1365  d->pFileTip->setItem( 0 );
1366 }
1367 
1368 void KonqIconViewWidget::contentsMousePressEvent( TQMouseEvent *e )
1369 {
1370  if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
1371  d->pActivateDoubleClick->stop();
1372  TQIconViewItem* item = findItem( e->pos() );
1373  m_mousePos = e->pos();
1374  KURL url;
1375  if ( item )
1376  {
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))
1382  {
1383  d->firstClick = true;
1384  d->mousePos = e->pos();
1385  d->mouseState = e->state();
1386  if (!d->pActivateDoubleClick)
1387  {
1388  d->pActivateDoubleClick = new TQTimer(this);
1389  connect(d->pActivateDoubleClick, TQ_SIGNAL(timeout()), this, TQ_SLOT(doubleClickTimeout()));
1390  }
1391  if( d->pActivateDoubleClick->isActive () )
1392  d->pActivateDoubleClick->stop();
1393  else
1394  d->pActivateDoubleClick->start(TQApplication::doubleClickInterval());
1395  d->releaseMouseEvent = false;
1396  return;
1397  }
1398  else
1399  d->renameItem= false;
1400  }
1401  else
1402  d->renameItem= false;
1403  mousePressChangeValue();
1404  if(d->pActivateDoubleClick && d->pActivateDoubleClick->isActive())
1405  d->pActivateDoubleClick->stop();
1406  TDEIconView::contentsMousePressEvent( e );
1407 
1408 }
1409 
1410 void KonqIconViewWidget::contentsMouseReleaseEvent( TQMouseEvent *e )
1411 {
1412  TDEIconView::contentsMouseReleaseEvent( e );
1413  if(d->releaseMouseEvent && d->pActivateDoubleClick && d->pActivateDoubleClick->isActive ())
1414  d->pActivateDoubleClick->stop();
1415  slotSelectionChanged();
1416  d->releaseMouseEvent = true;
1417  m_bMousePressed = false;
1418 }
1419 
1420 void KonqIconViewWidget::slotSaveIconPositions()
1421 {
1422  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1423  // This code is currently not used but left in for compatibility reasons.
1424  // It can be removed in KDE 4.0
1425  // Saving of desktop icon positions is now done in KDIconView::saveIconPositions()
1426  // in tdebase/kdesktop/kdiconview.cpp
1427  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1428 
1429  printf("WARNING: Strongly deprecated method KonqIconViewWidget::slotSaveIconPositions() called!\n"); fflush(stdout);
1430 
1431  if ( m_dotDirectoryPath.isEmpty() )
1432  return;
1433  if ( !m_bDesktop )
1434  return; // Currently not available in Konqueror
1435  kdDebug(1214) << "KonqIconViewWidget::slotSaveIconPositions" << endl;
1436  KSimpleConfig dotDirectory( m_dotDirectoryPath );
1437  TQIconViewItem *it = firstItem();
1438  if ( !it )
1439  return; // No more icons. Maybe we're closing and they've been removed already
1440  while ( it )
1441  {
1442  KFileIVI *ivi = static_cast<KFileIVI *>( it );
1443  KFileItem *item = ivi->item();
1444 
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 );
1450 
1451  it = it->nextItem();
1452  }
1453 
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 )
1459  {
1460  dotDirectory.setGroup( *gIt );
1461  if ( dotDirectory.hasKey( "Exists" ) )
1462  dotDirectory.deleteEntry( "Exists", false );
1463  else
1464  {
1465  kdDebug(1214) << "KonqIconViewWidget::slotSaveIconPositions deleting group " << *gIt << endl;
1466  dotDirectory.deleteGroup( *gIt );
1467  }
1468  }
1469 
1470  dotDirectory.sync();
1471 
1472  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1473  // This code is currently not used but left in for compatibility reasons.
1474  // It can be removed in KDE 4.0
1475  // Saving of desktop icon positions is now done in KDIconView::saveIconPositions()
1476  // in tdebase/kdesktop/kdiconview.cpp
1477  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1478 }
1479 
1480 // Adapted version of TQIconView::insertInGrid, that works relative to
1481 // m_IconRect, instead of the entire viewport.
1482 
1483 void KonqIconViewWidget::insertInGrid(TQIconViewItem *item)
1484 {
1485  if (0L == item)
1486  return;
1487 
1488  if (!m_IconRect.isValid())
1489  {
1490  TDEIconView::insertInGrid(item);
1491  return;
1492  }
1493 
1494  TQRegion r(m_IconRect);
1495  TQIconViewItem *i = firstItem();
1496  int y = -1;
1497  for (; i; i = i->nextItem() )
1498  {
1499  r = r.subtract(i->rect());
1500  y = TQMAX(y, i->y() + i->height());
1501  }
1502 
1503  TQMemArray<TQRect> rects = r.rects();
1504  TQMemArray<TQRect>::Iterator it = rects.begin();
1505  bool foundPlace = false;
1506  for (; it != rects.end(); ++it)
1507  {
1508  TQRect rect = *it;
1509  if (rect.width() >= item->width() && rect.height() >= item->height())
1510  {
1511  int sx = 0, sy = 0;
1512  if (rect.width() >= item->width() + spacing())
1513  sx = spacing();
1514  if (rect.height() >= item->height() + spacing())
1515  sy = spacing();
1516  item->move(rect.x() + sx, rect.y() + sy);
1517  foundPlace = true;
1518  break;
1519  }
1520  }
1521 
1522  if (!foundPlace)
1523  item->move(m_IconRect.topLeft());
1524 
1525  //item->dirty = false;
1526  return;
1527 }
1528 
1529 
1530 /*
1531  * The algorithm used for lineing up the icons could be called
1532  * "beating flat the icon field". Imagine the icon field to be some height
1533  * field on a regular grid, with the height being the number of icons in
1534  * each grid element. Now imagine slamming on the field with a shovel or
1535  * some other flat surface. The high peaks will be flattened and spread out
1536  * over their adjacent areas. This is basically what the algorithm tries to
1537  * simulate.
1538  *
1539  * First, the icons are binned to a grid of the desired size. If all bins
1540  * are containing at most one icon, we're done, of course. We just have to
1541  * move all icons to the center of each grid element.
1542  * For each bin which has more than one icon in it, we calculate 4
1543  * "friction coefficients", one for each cardinal direction. The friction
1544  * coefficient of a direction is the number of icons adjacent in that
1545  * direction. The idea is that this number is somewhat a measure in which
1546  * direction the icons should flow: icons flow in the direction of lowest
1547  * friction coefficient. We move a maximum of one icon per bin and loop over
1548  * all bins. This procedure is repeated some maximum number of times or until
1549  * no icons are moved anymore.
1550  *
1551  * I don't know if this algorithm is good or bad, I don't even know if it will
1552  * work all the time. It seems a correct thing to do, however, and it seems to
1553  * work particularly well. In any case, the number of runs is limited so there
1554  * can be no races.
1555  */
1556 
1557 void KonqIconViewWidget::lineupIcons()
1558 {
1559  // even if there are no items yet, calculate the maxItemWidth to have the correct
1560  // item rect when we insert new items
1561 
1562  // Create a grid of (ny x nx) bins.
1563  int x0, y0, dx, dy, nx, ny;
1564  gridValues( &x0, &y0, &dx, &dy, &nx, &ny );
1565 
1566  int itemWidth = dx - spacing();
1567  bool newItemWidth = false;
1568  if ( maxItemWidth() != itemWidth ) {
1569  newItemWidth = true;
1570  setMaxItemWidth( itemWidth );
1571  setFont( font() ); // Force calcRect()
1572  }
1573 
1574  if ( !firstItem() ) {
1575  kdDebug(1203) << "No icons at all ?\n";
1576  return;
1577  }
1578 
1579  int iconSize = m_size ? m_size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1580 
1581  typedef TQValueList<TQIconViewItem*> Bin;
1582  Bin*** bins = new Bin**[nx];
1583  int i;
1584  int j;
1585  for ( i = 0; i < nx ; i++ ) {
1586  bins[i] = new Bin*[ny];
1587  for ( j = 0; j < ny; j++ )
1588  bins[i][j] = 0L;
1589  }
1590 
1591  // Insert items into grid
1592  int textHeight = iconTextHeight() * fontMetrics().height();
1593 
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 ) );
1600 
1601  if ( !bins[posX][posY] )
1602  bins[posX][posY] = new Bin;
1603  bins[posX][posY]->prepend( item );
1604  }
1605 
1606  // The shuffle code
1607  int n, k;
1608  const int infinity = 10000;
1609  int nmoves = 1;
1610  for ( n = 0; n < 30 && nmoves > 0; n++ ) {
1611  nmoves = 0;
1612  for ( i = 0; i < nx; i++ ) {
1613  for ( j = 0; j < ny; j++ ) {
1614  if ( !bins[i][j] || ( bins[i][j]->count() <= 1 ) )
1615  continue;
1616 
1617  // Calculate the 4 "friction coefficients".
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();
1621  if ( k == -1 )
1622  tf += infinity;
1623 
1624  for ( k = j+1; k < ny && bins[i][k] && bins[i][k]->count(); k++ )
1625  bf += bins[i][k]->count();
1626  if ( k == ny )
1627  bf += infinity;
1628 
1629  for ( k = i-1; k >= 0 && bins[k][j] && bins[k][j]->count(); k-- )
1630  lf += bins[k][j]->count();
1631  if ( k == -1 )
1632  lf += infinity;
1633 
1634  for ( k = i+1; k < nx && bins[k][j] && bins[k][j]->count(); k++ )
1635  rf += bins[k][j]->count();
1636  if ( k == nx )
1637  rf += infinity;
1638 
1639  // If we are stuck between walls, continue
1640  if ( tf >= infinity && bf >= infinity &&
1641  lf >= infinity && rf >= infinity )
1642  continue;
1643 
1644  // Is there a preferred lineup direction?
1645  if ( m_LineupMode == LineupHorizontal ) {
1646  tf += infinity;
1647  bf += infinity;
1648  }
1649  else if ( m_LineupMode == LineupVertical ) {
1650  lf += infinity;
1651  rf += infinity;
1652  }
1653 
1654  // Move one item in the direction of the least friction
1655  TQIconViewItem* movedItem;
1656  Bin* items = bins[i][j];
1657 
1658  int mini = TQMIN( TQMIN( tf, bf ), TQMIN( lf, rf ) );
1659  if ( tf == mini ) {
1660  // move top item in (i,j) to (i,j-1)
1661  Bin::iterator it = items->begin();
1662  movedItem = *it;
1663  for ( ++it; it != items->end(); ++it ) {
1664  if ( (*it)->y() < movedItem->y() )
1665  movedItem = *it;
1666  }
1667  items->remove( movedItem );
1668  if ( !bins[i][j-1] )
1669  bins[i][j-1] = new Bin;
1670  bins[i][j-1]->prepend( movedItem );
1671  }
1672  else if ( bf ==mini ) {
1673  // move bottom item in (i,j) to (i,j+1)
1674  Bin::iterator it = items->begin();
1675  movedItem = *it;
1676  for ( ++it; it != items->end(); ++it ) {
1677  if ( (*it)->y() > movedItem->y() )
1678  movedItem = *it;
1679  }
1680  items->remove( movedItem );
1681  if ( !bins[i][j+1] )
1682  bins[i][j+1] = new Bin;
1683  bins[i][j+1]->prepend( movedItem );
1684  }
1685  else if ( lf == mini )
1686  {
1687  // move left item in (i,j) to (i-1,j)
1688  Bin::iterator it = items->begin();
1689  movedItem = *it;
1690  for ( ++it; it != items->end(); ++it ) {
1691  if ( (*it)->x() < movedItem->x() )
1692  movedItem = *it;
1693  }
1694  items->remove( movedItem );
1695  if ( !bins[i-1][j] )
1696  bins[i-1][j] = new Bin;
1697  bins[i-1][j]->prepend( movedItem );
1698  }
1699  else {
1700  // move right item in (i,j) to (i+1,j)
1701  Bin::iterator it = items->begin();
1702  movedItem = *it;
1703  for ( ++it; it != items->end(); ++it ) {
1704  if ( (*it)->x() > movedItem->x() )
1705  movedItem = *it;
1706  }
1707  items->remove( movedItem );
1708  if ( !bins[i+1][j] )
1709  bins[i+1][j] = new Bin;
1710  bins[i+1][j]->prepend( movedItem );
1711  }
1712  nmoves++;
1713  }
1714  }
1715  }
1716 
1717  // Perform the actual moving
1718  TQRegion repaintRegion;
1719  TQValueList<TQIconViewItem*> movedItems;
1720 
1721  for ( i = 0; i < nx; i++ ) {
1722  for ( j = 0; j < ny; j++ ) {
1723  Bin* bin = bins[i][j];
1724  if ( !bin )
1725  continue;
1726  if ( !bin->isEmpty() ) {
1727  TQIconViewItem* item = bin->first();
1728  int newX = x0 + i*dx + spacing() +
1729  TQMAX(0, ( (dx-spacing()) - item->width() ) / 2); // pixmap can be larger as iconsize
1730  // align all icons vertically to their text
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 );
1738  }
1739  }
1740  delete bin;
1741  bins[i][j] = 0L;
1742  }
1743  }
1744 
1745  // repaint
1746  if ( newItemWidth )
1747  updateContents();
1748  else {
1749  // Repaint only repaintRegion...
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 );
1755  }
1756  // Repaint icons that were moved
1757  while ( !movedItems.isEmpty() ) {
1758  repaintItem( movedItems.first() );
1759  movedItems.remove( movedItems.first() );
1760  }
1761  }
1762 
1763  for ( i = 0; i < nx ; i++ ) {
1764  delete [] bins[i];
1765  }
1766  delete [] bins;
1767 }
1768 
1769 void KonqIconViewWidget::lineupIcons( TQIconView::Arrangement arrangement )
1770 {
1771  int x0, y0, dx, dy, nxmax, nymax;
1772  gridValues( &x0, &y0, &dx, &dy, &nxmax, &nymax );
1773  int textHeight = iconTextHeight() * fontMetrics().height();
1774 
1775  TQRegion repaintRegion;
1776  TQValueList<TQIconViewItem*> movedItems;
1777  int nx = 0, ny = 0;
1778 
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); // icon can be larger as defined
1783  // align all icons vertically to their text
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 );
1791  }
1792  if ( arrangement == TQIconView::LeftToRight ) {
1793  nx++;
1794  if ( nx >= nxmax ) {
1795  ny++;
1796  nx = 0;
1797  }
1798  }
1799  else {
1800  ny++;
1801  if ( ny >= nymax ) {
1802  nx++;
1803  ny = 0;
1804  }
1805  }
1806  }
1807 
1808  // Repaint only repaintRegion...
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 );
1814  }
1815  // Repaint icons that were moved
1816  while ( !movedItems.isEmpty() ) {
1817  repaintItem( movedItems.first() );
1818  movedItems.remove( movedItems.first() );
1819  }
1820 }
1821 
1822 int KonqIconViewWidget::largestPreviewIconSize( int size ) const
1823 {
1824  int iconSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1825 
1826  if (iconSize < 28)
1827  return 48;
1828  if (iconSize < 40)
1829  return 64;
1830  if (iconSize < 60)
1831  return 96;
1832  if (iconSize < 120)
1833  return 128;
1834 
1835  return 192;
1836 }
1837 
1838 int KonqIconViewWidget::previewIconSize( int size ) const
1839 {
1840  int iconSize = size ? size : TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
1841 
1842  if (!d->bBoostPreview)
1843  return iconSize;
1844 
1845  return largestPreviewIconSize( iconSize );
1846 }
1847 
1848 void KonqIconViewWidget::visualActivate(TQIconViewItem * item)
1849 {
1850  // Rect of the TQIconViewItem.
1851  TQRect irect = item->rect();
1852 
1853  // Rect of the QIconViewItem's pixmap area.
1854  TQRect rect = item->pixmapRect();
1855 
1856  // Adjust to correct position. If this isn't done, the fact that the
1857  // text may be wider than the pixmap puts us off-centre.
1858  rect.moveBy(irect.x(), irect.y());
1859 
1860  // Adjust for scrolling (David)
1861  rect.moveBy( -contentsX(), -contentsY() );
1862 
1863  if (TDEGlobalSettings::showKonqIconActivationEffect() == true) {
1864  TDEIconEffect::visualActivate(viewport(), rect, item->pixmap());
1865  }
1866 }
1867 
1868 void KonqIconViewWidget::backgroundPixmapChange( const TQPixmap & )
1869 {
1870  viewport()->update();
1871 }
1872 
1873 void KonqIconViewWidget::setPreviewSettings( const TQStringList& settings )
1874 {
1875  d->previewSettings = settings;
1876  updatePreviewMimeTypes();
1877 
1878  int size = m_size;
1879  m_size = -1; // little trick to force grid change in setIcons
1880  setIcons( size ); // force re-determining all icons
1881 }
1882 
1883 const TQStringList& KonqIconViewWidget::previewSettings()
1884 {
1885  return d->previewSettings;
1886 }
1887 
1888 void KonqIconViewWidget::setNewURL( const TQString& url )
1889 {
1890  KURL u;
1891  if ( url.startsWith( "/" ) )
1892  u.setPath( url );
1893  else
1894  u = url;
1895  setURL( u );
1896 }
1897 
1898 void KonqIconViewWidget::setCaseInsensitiveSort( bool b )
1899 {
1900  d->bCaseInsensitive = b;
1901 }
1902 
1903 bool KonqIconViewWidget::caseInsensitiveSort() const
1904 {
1905  return d->bCaseInsensitive;
1906 }
1907 
1908 bool KonqIconViewWidget::canPreview( KFileItem* item )
1909 {
1910  if ( !TDEGlobalSettings::showFilePreview( url() ) )
1911  return false;
1912 
1913  if ( d->pPreviewMimeTypes == 0L )
1914  updatePreviewMimeTypes();
1915 
1916  return mimeTypeMatch( item->mimetype(), *( d->pPreviewMimeTypes ) );
1917 }
1918 
1919 void KonqIconViewWidget::updatePreviewMimeTypes()
1920 {
1921  if ( d->pPreviewMimeTypes == 0L )
1922  d->pPreviewMimeTypes = new TQStringList;
1923  else
1924  d->pPreviewMimeTypes->clear();
1925 
1926  // Load the list of plugins to determine which mimetypes are supported
1927  TDETrader::OfferList plugins = TDETrader::self()->query("ThumbCreator");
1928  TDETrader::OfferList::ConstIterator it;
1929 
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);
1935  }
1936  }
1937 }
1938 
1939 #include "konq_iconviewwidget.moc"
KFileIVI
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem...
Definition: tdefileivi.h:39
KonqIconViewWidget::enableAction
void enableAction(const char *name, bool enabled)
For cut/copy/paste/move/delete (see tdeparts/browserextension.h)
KonqIconViewWidget::insertInGrid
virtual void insertInGrid(TQIconViewItem *item)
Reimplemented from TQIconView to take into account iconArea.
Definition: konq_iconviewwidget.cpp:1483
KonqIconViewWidget::refreshMimeTypes
void refreshMimeTypes()
Called on databaseChanged.
Definition: konq_iconviewwidget.cpp:805
KonqIconViewWidget::slotSelectionChanged
virtual void slotSelectionChanged()
Checks the new selection and emits enableAction() signals.
Definition: konq_iconviewwidget.cpp:1086
KonqIconViewWidget::KonqIconViewWidget
KonqIconViewWidget(TQWidget *parent=0L, const char *name=0L, WFlags f=0, bool kdesktop=false)
Constructor.
Definition: konq_iconviewwidget.cpp:117
KonqIconViewWidget::dragFinished
void dragFinished()
Emited after the dropped() event.
KonqIconViewWidget::iconArea
TQRect iconArea() const
Returns the icon area.
Definition: konq_iconviewwidget.cpp:1194
KonqIconViewWidget::gridValues
void gridValues(int *x, int *y, int *dx, int *dy, int *nx, int *ny)
Calculate the geometry of the fixed grid that is used to line up the icons, for example when using th...
Definition: konq_iconviewwidget.cpp:726
KonqIconViewWidget::lineupIcons
void lineupIcons()
Line up the icons to a regular grid.
Definition: konq_iconviewwidget.cpp:1557
KonqIconViewWidget::clear
virtual void clear()
Reimplemented from QIconView.
Definition: konq_iconviewwidget.cpp:508
KonqIconViewWidget::takeItem
virtual void takeItem(TQIconViewItem *item)
Reimplemented from QIconView.
Definition: konq_iconviewwidget.cpp:516
KonqIconViewWidget::selectedFileItems
KFileItemList selectedFileItems()
Get list of selected KFileItems.
Definition: konq_iconviewwidget.cpp:899
KonqIconViewWidget::setItemTextPos
virtual void setItemTextPos(ItemTextPos pos)
Reimplemented from TQIconView to update the gridX.
Definition: konq_iconviewwidget.cpp:707
KonqIconDrag2
Clipboard/dnd data for: Icons + URLs + MostLocal URLs + isCut KDE4: merge with KonqIconDrag.
Definition: konq_drag.h:66
KonqOperations::rename
static void rename(TQWidget *parent, const KURL &oldurl, const TQString &name)
Do a renaming.
Definition: konq_operations.cpp:725
KFileIVI::invalidateThumb
void invalidateThumb(int state, bool redraw=false)
Notifies that all icon effects on thumbs should be invalidated, e.g.
Definition: tdefileivi.cpp:93
KFileIVI::setThumbnailPixmap
void setThumbnailPixmap(const TQPixmap &pixmap)
Set this when the thumbnail was loaded.
Definition: tdefileivi.cpp:241
KonqFMSettings::settings
static KonqFMSettings * settings()
The static instance of KonqFMSettings.
Definition: konq_settings.cpp:47
KonqIconViewWidget::setIcons
void setIcons(int size, const TQStringList &stopImagePreviewFor=TQStringList())
Sets the icons of all items, and stores the size This doesn&#39;t touch thumbnails, except if stopImagePr...
Definition: konq_iconviewwidget.cpp:625
KonqOperations::doDrop
static void doDrop(const KFileItem *destItem, const KURL &destURL, TQDropEvent *ev, TQWidget *parent)
Drop.
Definition: konq_operations.cpp:315
KFileIVI::state
int state() const
Return the current state of the icon (TDEIcon::DefaultState, TDEIcon::ActiveState etc...
Definition: tdefileivi.h:114
KonqIconViewWidget::lineupMode
int lineupMode() const
Returns the lineup mode.
Definition: konq_iconviewwidget.cpp:1204
KonqIconViewWidget::visualActivate
virtual void visualActivate(TQIconViewItem *)
Give feedback when item is activated.
Definition: konq_iconviewwidget.cpp:1848
KonqIconViewWidget::setLineupMode
void setLineupMode(int mode)
Set the lineup mode.
Definition: konq_iconviewwidget.cpp:1209
KonqIconViewWidget::setIconArea
void setIconArea(const TQRect &rect)
Set the area that will be occupied by icons.
Definition: konq_iconviewwidget.cpp:1199
KFileIVI::setIcon
virtual void setIcon(int size, int state=TDEIcon::DefaultState, bool recalc=false, bool redraw=false)
Changes the icon for this item.
Definition: tdefileivi.cpp:119
KonqIconViewWidget::initConfig
bool initConfig(bool bInit)
Read the configuration and apply it.
Definition: konq_iconviewwidget.cpp:550
KonqIconViewWidget::dragEntered
void dragEntered(bool accepted)
We need to track drag in icon views for the spring loading folders.
KonqIconViewWidget::gridXValue
int gridXValue() const
The horizontal distance between two icons (whether or not a grid has been given to TQIconView) ...
Definition: konq_iconviewwidget.cpp:790
KFileIVI::isThumbnail
bool isThumbnail() const
Definition: tdefileivi.h:140
KFileIVI::item
KFileItem * item() const
Definition: tdefileivi.h:60
KonqOperations::doPaste
static void doPaste(TQWidget *parent, const KURL &destURL, const TQPoint &pos)
Paste the clipboard contents.
Definition: konq_operations.cpp:123
KonqIconViewWidget::startImagePreview
void startImagePreview(const TQStringList &ignored, bool force)
Start generating the previews.
Definition: konq_iconviewwidget.cpp:826
KonqIconViewWidget::focusOutEvent
virtual void focusOutEvent(TQFocusEvent *)
Reimplemented to make the slotOnItem highlighting work.
Definition: konq_iconviewwidget.cpp:175

libkonq

Skip menu "libkonq"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkonq

Skip menu "libkonq"
  • kate
  • libkonq
  • twin
  •   lib
Generated for libkonq by doxygen 1.8.13
This website is maintained by Timothy Pearson.