22#include <tqfontmetrics.h>
32#include <tdeapplication.h>
34#include <tdefileitem.h>
35#include <kiconeffect.h>
36#include <tdeglobalsettings.h>
38#include <tdeio/previewjob.h>
40#include "tdefileiconview.h"
41#include "config-tdefile.h"
43#define DEFAULT_PREVIEW_SIZE 60
44#define DEFAULT_SHOW_PREVIEWS false
45#define DEFAULT_VIEW_MODE "SmallColumns"
47KFileIconViewItem::~KFileIconViewItem()
49 fileInfo()->removeExtraData( iconView() );
52class KFileIconView::KFileIconViewPrivate
60 noArrangement =
false;
61 ignoreMaximumSize =
false;
62 smallColumns =
new TDERadioAction( i18n(
"Small Icons"), 0, parent,
63 TQ_SLOT( slotSmallColumns() ),
67 largeRows =
new TDERadioAction( i18n(
"Large Icons"), 0, parent,
68 TQ_SLOT( slotLargeRows() ),
72 smallColumns->setExclusiveGroup(TQString::fromLatin1(
"IconView mode"));
73 largeRows->setExclusiveGroup(TQString::fromLatin1(
"IconView mode"));
75 previews =
new TDEToggleAction( i18n(
"Thumbnail Previews"), 0,
78 zoomIn = KStdAction::zoomIn( parent, TQ_SLOT( zoomIn() ),
80 zoomOut = KStdAction::zoomOut( parent, TQ_SLOT( zoomOut() ),
83 previews->setGroup(
"previews");
84 zoomIn->setGroup(
"previews");
85 zoomOut->setGroup(
"previews");
87 connect( previews, TQ_SIGNAL( toggled(
bool )),
88 parent, TQ_SLOT( slotPreviewsToggled(
bool )));
90 connect( &previewTimer, TQ_SIGNAL( timeout() ),
92 connect( &autoOpenTimer, TQ_SIGNAL( timeout() ),
93 parent, TQ_SLOT( slotAutoOpen() ));
96 ~KFileIconViewPrivate() {
101 TDERadioAction *smallColumns, *largeRows;
102 TDEAction *zoomIn, *zoomOut;
103 TDEToggleAction *previews;
104 TDEIO::PreviewJob *job;
106 TQTimer previewTimer;
107 TQTimer autoOpenTimer;
108 TQStringList previewMimeTypes;
110 bool noArrangement :1;
111 bool ignoreMaximumSize :1;
114KFileIconView::KFileIconView(TQWidget *parent,
const char *name)
117 d =
new KFileIconViewPrivate(
this );
119 setViewName( i18n(
"Icon View") );
122 setResizeMode( Adjust );
123 setMaxItemWidth( 300 );
124 setWordWrapIconText(
false );
125 setArrangement( TopToBottom );
126 setAutoArrange(
true );
127 setItemsMovable(
false );
128 setMode( TDEIconView::Select );
129 TDEIconView::setSorting(
true );
132 setShowToolTips(
false );
134 d->smallColumns->setChecked(
true );
136 connect(
this, TQ_SIGNAL( returnPressed(TQIconViewItem *) ),
137 TQ_SLOT( slotActivate( TQIconViewItem *) ) );
140 connect(
this, TQ_SIGNAL( clicked(TQIconViewItem *,
const TQPoint&) ),
141 TQ_SLOT( selected( TQIconViewItem *) ) );
142 connect(
this, TQ_SIGNAL( doubleClicked(TQIconViewItem *,
const TQPoint&) ),
143 TQ_SLOT( slotActivate( TQIconViewItem *) ) );
145 connect(
this, TQ_SIGNAL( onItem( TQIconViewItem * ) ),
146 TQ_SLOT( showToolTip( TQIconViewItem * ) ) );
147 connect(
this, TQ_SIGNAL( onViewport() ),
148 TQ_SLOT( removeToolTip() ) );
149 connect(
this, TQ_SIGNAL( contextMenuRequested(TQIconViewItem*,
const TQPoint&)),
150 TQ_SLOT( slotActivateMenu( TQIconViewItem*,
const TQPoint& ) ) );
152 KFile::SelectionMode sm = KFileView::selectionMode();
155 TQIconView::setSelectionMode( TQIconView::Multi );
157 case KFile::Extended:
158 TQIconView::setSelectionMode( TQIconView::Extended );
160 case KFile::NoSelection:
161 TQIconView::setSelectionMode( TQIconView::NoSelection );
165 TQIconView::setSelectionMode( TQIconView::Single );
169 if ( sm == KFile::Multi || sm == KFile::Extended )
170 connect(
this, TQ_SIGNAL( selectionChanged() ),
171 TQ_SLOT( slotSelectionChanged() ));
173 connect(
this, TQ_SIGNAL( selectionChanged( TQIconViewItem * )),
174 TQ_SLOT( highlighted( TQIconViewItem * )));
176 viewport()->installEventFilter(
this );
179 m_resolver =
new KMimeTypeResolver<KFileIconViewItem,KFileIconView>(
this);
182KFileIconView::~KFileIconView()
189void KFileIconView::readConfig( TDEConfig *kc,
const TQString& group )
191 TQString gr = group.isEmpty() ? TQString(
"KFileIconView") : group;
192 TDEConfigGroupSaver cs( kc, gr );
193 TQString small = TQString::fromLatin1(
"SmallColumns");
194 d->previewIconSize = kc->readNumEntry(
"Preview Size", DEFAULT_PREVIEW_SIZE );
195 d->previews->setChecked( kc->readBoolEntry(
"ShowPreviews", DEFAULT_SHOW_PREVIEWS ) );
197 if ( kc->readEntry(
"ViewMode", DEFAULT_VIEW_MODE ) == small ) {
198 d->smallColumns->setChecked(
true );
202 d->largeRows->setChecked(
true );
206 if ( d->previews->isChecked() )
210void KFileIconView::writeConfig( TDEConfig *kc,
const TQString& group )
212 TQString gr = group.isEmpty() ? TQString(
"KFileIconView") : group;
213 TDEConfigGroupSaver cs( kc, gr );
215 TQString viewMode = d->smallColumns->isChecked() ?
216 TQString::fromLatin1(
"SmallColumns") :
217 TQString::fromLatin1(
"LargeRows");
218 if(!kc->hasDefault(
"ViewMode" ) && viewMode == DEFAULT_VIEW_MODE )
219 kc->revertToDefault(
"ViewMode" );
221 kc->writeEntry(
"ViewMode", viewMode );
223 int previewsIconSize = d->previewIconSize;
224 if(!kc->hasDefault(
"Preview Size" ) && previewsIconSize == DEFAULT_PREVIEW_SIZE )
225 kc->revertToDefault(
"Preview Size" );
227 kc->writeEntry(
"Preview Size", previewsIconSize );
230 if(!kc->hasDefault(
"ShowPreviews" ) &&
showPreviews == DEFAULT_SHOW_PREVIEWS )
231 kc->revertToDefault(
"ShowPreviews" );
236void KFileIconView::removeToolTip()
242void KFileIconView::showToolTip( TQIconViewItem *item )
250 int w = maxItemWidth() - ( itemTextPos() == TQIconView::Bottom ? 0 :
251 item->pixmapRect().width() ) - 4;
252 if ( fontMetrics().width( item->text() ) >= w ) {
253 toolTip =
new TQLabel( TQString::fromLatin1(
" %1 ").arg(item->text()), 0,
255 (WFlags)(WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM) );
256 toolTip->setFrameStyle( TQFrame::Plain | TQFrame::Box );
257 toolTip->setLineWidth( 1 );
258 toolTip->setAlignment( AlignLeft | AlignTop );
259 toolTip->move( TQCursor::pos() + TQPoint( 14, 14 ) );
260 toolTip->adjustSize();
261 TQRect screen = TQApplication::desktop()->screenGeometry(
262 TQApplication::desktop()->screenNumber(TQCursor::pos()));
263 if (toolTip->x()+toolTip->width() > screen.right()) {
264 toolTip->move(toolTip->x()+screen.right()-toolTip->x()-toolTip->width(), toolTip->y());
266 if (toolTip->y()+toolTip->height() > screen.bottom()) {
267 toolTip->move(toolTip->x(), screen.bottom()-toolTip->y()-toolTip->height()+toolTip->y());
269 toolTip->setFont( TQToolTip::font() );
270 toolTip->setPalette( TQToolTip::palette(),
true );
275void KFileIconView::slotActivateMenu( TQIconViewItem* item,
const TQPoint& pos )
278 sig->activateMenu( 0, pos );
282 sig->activateMenu( i->
fileInfo(), pos );
288 TDEIconView::hideEvent( e );
293 TDEIconView::keyPressEvent( e );
296 if ( (e->state() & ControlButton) &&
297 (e->key() == Key_Return || e->key() == Key_Enter) )
305 TDEIconView::setSelected( item, enable,
true );
310 if (KFileView::selectionMode() == KFile::NoSelection ||
311 KFileView::selectionMode() == KFile::Single)
314 TDEIconView::selectAll(
true );
319 TDEIconView::clearSelection();
324 TDEIconView::invertSelection();
329 m_resolver->m_lstPendingMimeIconItems.clear();
331 TDEIconView::clear();
339 TQIconView* qview =
static_cast<TQIconView*
>( this );
342 qview->setUpdatesEnabled(
false );
344 initItem( item, i,
true );
345 qview->setUpdatesEnabled(
true );
347 if ( !i->isMimeTypeKnown() )
348 m_resolver->m_lstPendingMimeIconItems.append( item );
350 i->setExtraData(
this, item );
353void KFileIconView::slotActivate( TQIconViewItem *item )
362void KFileIconView::selected( TQIconViewItem *item )
364 if ( !item || (TDEApplication::keyboardMouseState() & (ShiftButton | ControlButton)) != 0 )
367 if ( TDEGlobalSettings::singleClick() ) {
378 TDEIconView::setCurrentItem( it );
390void KFileIconView::highlighted( TQIconViewItem *item )
399void KFileIconView::setSelectionMode( KFile::SelectionMode sm )
401 disconnect( TQ_SIGNAL( selectionChanged() ),
this );
402 disconnect( TQ_SIGNAL( selectionChanged( TQIconViewItem * )),
this );
404 KFileView::setSelectionMode( sm );
405 switch ( KFileView::selectionMode() ) {
407 TQIconView::setSelectionMode( TQIconView::Multi );
409 case KFile::Extended:
410 TQIconView::setSelectionMode( TQIconView::Extended );
412 case KFile::NoSelection:
413 TQIconView::setSelectionMode( TQIconView::NoSelection );
417 TQIconView::setSelectionMode( TQIconView::Single );
421 if ( sm == KFile::Multi || sm == KFile::Extended )
422 connect(
this, TQ_SIGNAL( selectionChanged() ),
423 TQ_SLOT( slotSelectionChanged() ));
425 connect(
this, TQ_SIGNAL( selectionChanged( TQIconViewItem * )),
426 TQ_SLOT( highlighted( TQIconViewItem * )));
432 return (item && item->isSelected());
443 if ( d->previews->isChecked() ) {
444 if ( canPreview( item->
fileInfo() ) )
445 item->setPixmapSize( TQSize( d->previewIconSize, d->previewIconSize ) );
449 if ( !item->pixmapSize().isNull() )
450 item->setPixmapSize( TQSize( 0, 0 ) );
453 item->setPixmap( (item->
fileInfo())->pixmap( myIconSize ),
true, false );
455 }
while ( item != 0L );
463 initItem( item, i,
true );
472 d->job->removeItem( i );
475 m_resolver->m_lstPendingMimeIconItems.remove( item );
492 d->previewIconSize = size;
493 if ( d->previews->isChecked() )
499 d->ignoreMaximumSize = ignoreSize;
502void KFileIconView::updateIcons()
512 TDEIconView::ensureItemVisible( item );
515void KFileIconView::slotSelectionChanged()
520void KFileIconView::slotSmallColumns()
524 d->noArrangement =
true;
527 if ( d->previews->isChecked() )
530 d->previews->setChecked(
false );
533 setMaxItemWidth( 300 );
534 setItemTextPos( Right );
535 setArrangement( TopToBottom );
536 setWordWrapIconText(
false );
539 d->noArrangement =
false;
543void KFileIconView::slotLargeRows()
547 d->noArrangement =
true;
549 setGridX( TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop ) + 50 );
550 setItemTextPos( Bottom );
551 setArrangement( LeftToRight );
552 setWordWrapIconText(
true );
555 d->noArrangement =
false;
559void KFileIconView::stopPreview()
567void KFileIconView::slotPreviewsToggled(
bool on )
579 if ( d->previewMimeTypes.isEmpty() )
580 d->previewMimeTypes = TDEIO::PreviewJob::supportedMimeTypes();
583 d->previews->setChecked(
true );
585 if ( !d->largeRows->isChecked() ) {
586 d->largeRows->setChecked(
true );
593 d->job = TDEIO::filePreview(*
items(), d->previewIconSize,d->previewIconSize);
594 d->job->setIgnoreMaximumSize(d->ignoreMaximumSize);
596 connect( d->job, TQ_SIGNAL( result( TDEIO::Job * )),
597 this, TQ_SLOT( slotPreviewResult( TDEIO::Job * )));
598 connect( d->job, TQ_SIGNAL( gotPreview(
const KFileItem*,
const TQPixmap& )),
599 TQ_SLOT( gotPreview(
const KFileItem*,
const TQPixmap& ) ));
604void KFileIconView::slotPreviewResult( TDEIO::Job *job )
610void KFileIconView::gotPreview(
const KFileItem *item,
const TQPixmap& pix )
614 if( item->overlays() & TDEIcon::HiddenOverlay )
618 TDEIconEffect::semiTransparent( p );
622 it->setPixmap( pix );
627bool KFileIconView::canPreview(
const KFileItem *item )
const
629 TQStringList::Iterator it = d->previewMimeTypes.begin();
631 r.setWildcard(
true );
633 for ( ; it != d->previewMimeTypes.end(); ++it ) {
636 if ( type.at( type.length() - 1 ) ==
'*' ) {
637 r.setPattern( type );
638 if ( r.search( item->mimetype() ) != -1 )
642 if ( item->mimetype() == type )
649KFileItem * KFileIconView::firstFileItem()
const
657KFileItem * KFileIconView::nextItem(
const KFileItem *fileItem )
const
661 if ( item && item->nextItem() )
667KFileItem * KFileIconView::prevItem(
const KFileItem *fileItem )
const
671 if ( item && item->prevItem() )
680 KFileItemListIterator it( *
items() );
684 if ( spec & TQDir::Time ) {
685 for ( ; (item = it.current()); ++it )
687 viewItem(item)->setKey(
sortingKey( (
unsigned long)item->time( TDEIO::UDS_MODIFICATION_TIME ), item->isDir(), spec ));
690 else if ( spec & TQDir::Size ) {
691 for ( ; (item = it.current()); ++it )
692 viewItem(item)->setKey(
sortingKey( item->size(), item->isDir(),
696 for ( ; (item = it.current()); ++it )
697 viewItem(item)->setKey(
sortingKey( item->text(), item->isDir(),
701 TDEIconView::setSorting(
true, !
isReversed() );
708void KFileIconView::mimeTypeDeterminationFinished()
715 (void) item->
fileInfo()->determineMimeType();
725 if ( !currentItem() ) {
726 bool block = signalsBlocked();
727 blockSignals(
true );
728 TQIconViewItem *item = viewItem( firstFileItem() );
729 TDEIconView::setCurrentItem( item );
730 TDEIconView::setSelected( item,
false );
731 blockSignals( block );
734 m_resolver->start( d->previews->isChecked() ? 0 : 10 );
738bool KFileIconView::eventFilter( TQObject *o, TQEvent *e )
740 if ( o == viewport() || o ==
this ) {
741 int type = e->type();
742 if ( type == TQEvent::Leave ||
743 type == TQEvent::FocusOut )
747 return TDEIconView::eventFilter( o, e );
753void KFileIconView::showEvent( TQShowEvent *e )
755 TDEIconView::showEvent( e );
760 bool updateTextAndPixmap )
762 if ( d->previews->isChecked() && canPreview( i ) )
763 item->setPixmapSize( TQSize( d->previewIconSize, d->previewIconSize ) );
765 if ( updateTextAndPixmap )
770 item->setText( i->text() ,
false,
false );
771 item->setPixmap( i->pixmap( myIconSize ) );
777 if ( spec & TQDir::Time )
779 item->setKey(
sortingKey( (
unsigned long) i->time( TDEIO::UDS_MODIFICATION_TIME ),
781 else if ( spec & TQDir::Size )
782 item->setKey(
sortingKey( i->size(), i->isDir(), spec ));
785 item->setKey(
sortingKey( i->text(), i->isDir(), spec ));
789 if ( d->previews->isChecked() )
790 d->previewTimer.start( 10,
true );
795 if ( d->noArrangement )
798 TDEIconView::arrangeItemsInGrid( update );
801void KFileIconView::zoomIn()
806void KFileIconView::zoomOut()
811TQDragObject *KFileIconView::dragObject()
816 for ( ; it.current(); ++it ){
817 urls.append( (*it)->url() );
820 if( urls.count() > 1 )
821 pixmap = DesktopIcon(
"application-vnd.tde.tdemultiple",
iconSize() );
822 if( pixmap.isNull() )
826 hotspot.setX( pixmap.width() / 2 );
827 hotspot.setY( pixmap.height() / 2 );
828 TQDragObject* myDragObject =
new KURLDrag( urls,
widget() );
829 myDragObject->setPixmap( pixmap, hotspot );
833void KFileIconView::slotAutoOpen()
835 d->autoOpenTimer.stop();
839 KFileItem *fileItem = d->dropItem->fileInfo();
843 if( fileItem->isFile() )
846 if ( fileItem->isDir() || fileItem->isLink())
850bool KFileIconView::acceptDrag(TQDropEvent* e)
const
852 return KURLDrag::canDecode( e ) &&
854 ( e->action() == TQDropEvent::Copy
855 || e->action() == TQDropEvent::Move
856 || e->action() == TQDropEvent::Link );
859void KFileIconView::contentsDragEnterEvent( TQDragEnterEvent *e )
861 if ( ! acceptDrag( e ) ) {
873 d->autoOpenTimer.start( autoOpenDelay() );
878 d->autoOpenTimer.stop();
882void KFileIconView::contentsDragMoveEvent( TQDragMoveEvent *e )
884 if ( ! acceptDrag( e ) ) {
895 if (d->dropItem != item)
898 d->autoOpenTimer.start( autoOpenDelay() );
904 d->autoOpenTimer.stop();
908void KFileIconView::contentsDragLeaveEvent( TQDragLeaveEvent * )
911 d->autoOpenTimer.stop();
914void KFileIconView::contentsDropEvent( TQDropEvent *e )
917 d->autoOpenTimer.stop();
919 if ( ! acceptDrag( e ) ) {
926 KFileItem * fileItem = 0;
933 if (KURLDrag::decode( e, urls ) && !urls.isEmpty())
935 emit
dropped(e, urls, fileItem ? fileItem->url() : KURL());
936 sig->dropURLs(fileItem, e, urls);
940void KFileIconView::virtual_hook(
int id,
void* data )
941{ TDEIconView::virtual_hook(
id, data );
942 KFileView::virtual_hook(
id, data ); }
944#include "tdefileiconview.moc"
An item for the iconview, that has a reference to its corresponding KFileItem.
KFileItem * fileInfo() const
An icon-view capable of showing KFileItem's.
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
void dropped(TQDropEvent *event, KFileItem *fileItem)
The user dropped something.
void setIconSize(int size)
Sets the size of the icons to show.
void ensureItemVisible(const KFileItem *)
pure virtual function, that should be implemented to make item i visible, i.e.
virtual void hideEvent(TQHideEvent *)
Reimplemented to remove an eventual tooltip.
virtual void keyPressEvent(TQKeyEvent *)
Reimplemented to not let TQIconView eat return-key events.
void showPreviews()
Starts loading previews for all files shown and shows them.
virtual bool isSelected(const KFileItem *i) const
virtual void setCurrentItem(const KFileItem *)
Reimplement this to set item the current item in the view, e.g.
void setIgnoreMaximumSize(bool ignoreSize=true)
Disables the "Maximum file size" configuration option for previews.
void setPreviewSize(int size)
Sets the size of the previews.
virtual void clearView()
pure virtual function, that should be implemented to clear the view.
virtual void listingCompleted()
This hook is called when all items of the currently listed directory are listed and inserted into the...
virtual void removeItem(const KFileItem *)
Removes an item from the list; has to be implemented by the view.
virtual void clearSelection()
Clears any selection, unhighlights everything.
virtual void setSorting(TQDir::SortSpec sort)
Sets the sorting order of the view.
virtual void updateView(bool)
does a repaint of the view.
virtual KFileItem * currentFileItem() const
virtual void selectAll()
Selects all items.
virtual void setSelected(const KFileItem *, bool)
Tells the view that it should highlight the item.
virtual void arrangeItemsInGrid(bool updated=true)
Reimplemented for performance reasons.
virtual TQWidget * widget()
a pure virtual function to get a TQWidget, that can be added to other widgets.
virtual void invertSelection()
Inverts the current selection, i.e.
void activate(const KFileItem *item)
Call this method when an item is selected (depends on single click / double click configuration).
void highlightFile(const KFileItem *i)
emits the highlighted signal for item.
This class defines an interface to all file views.
bool onlyDoubleClickSelectsFiles() const
virtual void insertItem(KFileItem *i)
The derived view must implement this function to add the file in the widget.
const KFileItemList * items() const
bool isReversed() const
Tells whether the current items are in reversed order (shortcut to sorting() & TQDir::Reversed).
const KFileItemList * selectedItems() const
TQDir::SortSpec sorting() const
Returns the sorting order of the internal list.
int dropOptions()
Returns the DND options in effect.
virtual void removeItem(const KFileItem *item)
Removes an item from the list; has to be implemented by the view.
virtual void setSorting(TQDir::SortSpec sort)
Sets the sorting order of the view.
virtual TDEActionCollection * actionCollection() const
static TQString sortingKey(const TQString &value, bool isDir, int sortSpec)
This method calculates a TQString from the given parameters, that is suitable for sorting with e....