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

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.9.1
This website is maintained by Timothy Pearson.