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

libkonq

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

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.