20#include "tdefileivi.h"
21#include "kivdirectoryoverlay.h"
22#include "kivfreespaceoverlay.h"
23#include "konq_iconviewwidget.h"
24#include "konq_operations.h"
25#include "konq_settings.h"
28#include <tqtextedit.h>
31#include <kiconeffect.h>
32#include <tdefileitem.h>
37#include <tdestandarddirs.h>
44struct KFileIVI::Private
49 TQString m_animatedIcon;
51 KIVDirectoryOverlay* m_directoryOverlay;
52 KIVFreeSpaceOverlay* m_freeSpaceOverlay;
54 TQString m_overlayName;
59 : TDEIconViewItem( iconview, fileitem->text() ),
60 m_size( size ), m_state( TDEIcon::DefaultState ),
61 m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem ),
64 d =
new KFileIVI::Private;
67 setPixmap( m_fileitem->pixmap( m_size, m_state ) );
68 setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
71 d->icons.reset( *pixmap(), TQIconSet::Large );
72 d->m_animated =
false;
75 if ( fileitem->isMimeTypeKnown() )
77 TQString icon = fileitem->iconName();
78 if ( !icon.isEmpty() )
84 d->m_directoryOverlay = 0;
85 d->m_freeSpaceOverlay = 0;
91 delete d->m_directoryOverlay;
92 delete d->m_freeSpaceOverlay;
101 case TDEIcon::DisabledState:
102 mode = TQIconSet::Disabled;
104 case TDEIcon::ActiveState:
105 mode = TQIconSet::Active;
107 case TDEIcon::DefaultState:
109 mode = TQIconSet::Normal;
112 d->icons = TQIconSet();
113 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
114 apply( d->thumb, TDEIcon::Desktop,
state ),
115 TQIconSet::Large, mode );
118 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
125 m_bThumbnail =
false;
127 m_state = TDEIcon::DisabledState;
131 if ( d->m_overlayName.isNull() )
132 d->m_overlay = TQPixmap();
136 halfSize = IconSize(TDEIcon::Desktop) / 2;
138 halfSize = m_size / 2;
140 d->m_overlay = DesktopIcon(d->m_overlayName, halfSize);
143 setPixmapDirect(m_fileitem->pixmap( m_size, m_state ) , recalc, redraw );
148 d->m_overlayName = iconName;
155 d->m_progress = progress;
162 if ( !m_fileitem->isDir() || m_fileitem->iconName() !=
"folder" )
166 if (!d->m_directoryOverlay)
167 d->m_directoryOverlay =
new KIVDirectoryOverlay(
this);
168 return d->m_directoryOverlay;
170 delete d->m_directoryOverlay;
171 d->m_directoryOverlay = 0;
177bool KFileIVI::showDirectoryOverlay( )
179 return (
bool)d->m_directoryOverlay;
184 if ( !m_fileitem->mimetype().startsWith(
"media/") ) {
189 if (!d->m_freeSpaceOverlay)
190 d->m_freeSpaceOverlay =
new KIVFreeSpaceOverlay(
this);
191 return d->m_freeSpaceOverlay;
193 delete d->m_freeSpaceOverlay;
194 d->m_freeSpaceOverlay = 0;
200bool KFileIVI::showFreeSpaceOverlay( )
202 return (
bool)d->m_freeSpaceOverlay;
207 TQIconSet::Mode mode;
210 case TDEIcon::DisabledState:
211 mode = TQIconSet::Disabled;
213 case TDEIcon::ActiveState:
214 mode = TQIconSet::Active;
216 case TDEIcon::DefaultState:
218 mode = TQIconSet::Normal;
225 d->icons = TQIconSet();
226 d->icons.setPixmap( pixmap, TQIconSet::Large, mode );
229 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
235 if ( m_bDisabled != disabled )
237 m_bDisabled = disabled;
238 bool active = ( m_state == TDEIcon::ActiveState );
239 setEffect( m_bDisabled ? TDEIcon::DisabledState :
240 ( active ? TDEIcon::ActiveState : TDEIcon::DefaultState ) );
250 d->icons = TQIconSet();
251 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
252 apply( pixmap, TDEIcon::Desktop, TDEIcon::DefaultState ),
253 TQIconSet::Large, TQIconSet::Normal );
255 m_state = TDEIcon::DefaultState;
259 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large,
260 TQIconSet::Normal ),
true );
268 setEffect( m_bDisabled ? TDEIcon::DisabledState : TDEIcon::DefaultState );
273 TQIconSet::Mode mode;
276 case TDEIcon::DisabledState:
277 mode = TQIconSet::Disabled;
279 case TDEIcon::ActiveState:
280 mode = TQIconSet::Active;
282 case TDEIcon::DefaultState:
284 mode = TQIconSet::Normal;
289 TDEIconEffect *effect = TDEGlobal::iconLoader()->iconEffect();
291 bool haveEffect = effect->hasEffect( TDEIcon::Desktop, m_state ) !=
292 effect->hasEffect( TDEIcon::Desktop,
state );
302 effect->fingerprint( TDEIcon::Desktop, m_state ) !=
303 effect->fingerprint( TDEIcon::Desktop,
state ) )
309 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
310 d->icons.setPixmap( effect->apply( d->thumb, TDEIcon::Desktop,
state ),
311 TQIconSet::Large, mode );
315 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
316 d->icons.setPixmap( m_fileitem->pixmap( m_size,
state ),
317 TQIconSet::Large, mode );
319 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ) );
327 setIcon( m_size, m_state,
true, redraw );
333 d->thumb = TQPixmap();
336bool KFileIVI::isThumbnailInvalid()
const
338 return d->thumb.isNull();
343 if ( mime->provides(
"text/uri-list" ) )
345 if ( m_fileitem->acceptsDrops() )
353 KURL::List::Iterator it = uris.begin();
354 for ( ; it != uris.end() ; it++ )
356 if ( m_fileitem->url().equals( *it,
true ) )
360 return TQIconViewItem::acceptDrop( mime );
363void KFileIVI::setKey(
const TQString &key )
365 TQString theKey = key;
367 TQVariant sortDirProp = iconView()->property(
"sortDirectoriesFirst" );
369 bool isdir = ( S_ISDIR( m_fileitem->mode() ) && ( !sortDirProp.isValid() || ( sortDirProp.type() == TQVariant::Bool && sortDirProp.toBool() ) ) );
372 int sortChar = isdir ? 1 : 3;
373 if ( m_fileitem->text()[0] ==
'.' )
376 if ( !iconView()->sortDirection() )
377 sortChar = 3 - sortChar;
379 theKey.prepend( TQChar( sortChar +
'0' ) );
381 TQIconViewItem::setKey( theKey );
384void KFileIVI::dropped( TQDropEvent *e,
const TQValueList<TQIconDragItem> & )
392 KURL url = m_fileitem->url();
393 if (url.protocol() ==
"media") {
394 TQString mimetype = m_fileitem->mimetype();
395 TQString lockingAction = TQString::null;
396 if (mimetype.contains(
"encrypted_locked")) {
397 lockingAction =
"konqueror/servicemenus/media_unlock.desktop";
399 else if (mimetype.contains(
"encrypted_unlocked")) {
400 lockingAction =
"konqueror/servicemenus/media_lock.desktop";
402 if (!lockingAction.isEmpty()) {
403 TQString lockingService = TDEGlobal::dirs()->findResource(
"data", lockingAction);
404 if (!lockingService.isEmpty()) {
405 TQValueList<KDEDesktopMimeType::Service> serviceList = KDEDesktopMimeType::userDefinedServices(lockingService, m_fileitem->isLocalFile());
406 if (serviceList.count() == 1) {
407 KURL::List m_lstURLs;
408 m_lstURLs.append(m_fileitem->url());
409 KDEDesktopMimeType::executeService(m_lstURLs, serviceList[0]);
414 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
420 if ( m_fileitem->isLink() && url.isLocalFile() ) {
421 url = KURL( url, m_fileitem->linkDest() );
424 (void)
new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
447 TDEIconViewItem::paintItem( p, cg );
455 if ( !d->m_overlay.isNull() ) {
456 TQRect rect = pixmapRect(
true);
457 p->drawPixmap(x() + rect.x() , y() + pixmapRect().height() - d->m_overlay.height(), d->m_overlay);
463 if (d->m_progress != -1) {
494 TQRect rect = pixmapRect(
true);
495 int horizontalOffset = 0;
496 int usedBarHeight = (((100-d->m_progress)*pixmapRect().height())/100);
497 int endPosition = y() + rect.y() + usedBarHeight;
501 p->setPen(TQPen::NoPen);
502 p->setBrush(TQt::green);
503 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), y() + rect.y(), 1, usedBarHeight));
504 p->setBrush(TQt::red);
505 p->drawRect(TQRect(x() + rect.x() + (pixmapRect().width() - horizontalOffset), endPosition, 1, pixmapRect().height() - usedBarHeight));
513 if ( m_fileitem->isLink() )
515 TQFont f( p->font() );
523 TQColorGroup cg( c );
524 cg.setColor( TQColorGroup::Text,
static_cast<KonqIconViewWidget*
>(iconView())->itemColor() );
528bool KFileIVI::move(
int x,
int y )
533 if ( x > iconView()->viewport()->width() - ( width() + 5 ) )
534 x = iconView()->viewport()->width() - ( width() + 5 );
537 if ( y > iconView()->viewport()->height() - ( height() + 5 ) )
538 y = iconView()->viewport()->height() - ( height() + 5 );
540 return TQIconViewItem::move( x, y );
545 return !d->m_animatedIcon.isEmpty() && !m_bThumbnail;
550 if ( !movieFileName.isEmpty() )
553 d->m_animatedIcon = movieFileName;
557TQString KFileIVI::mouseOverAnimation()
const
559 return d->m_animatedIcon;
564 return d->m_animated;
567void KFileIVI::setAnimated(
bool a )
572int KFileIVI::compare( TQIconViewItem *i )
const
575 if ( view->caseInsensitiveSort() )
576 return key().localeAwareCompare( i->key() );
578 return view->m_pSettings->caseSensitiveCompare( key(), i->key() );
581void KFileIVI::updatePixmapSize()
583 int size = m_size ? m_size :
584 TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
588 bool mimeDetermined =
false;
589 if ( m_fileitem->isMimeTypeKnown() ) {
590 mimeDetermined =
true;
593 if (mimeDetermined) {
594 bool changed =
false;
595 if ( view && view->canPreview(
item() ) ) {
596 int previewSize = view->previewIconSize( size );
597 if (previewSize != size) {
598 setPixmapSize( TQSize( previewSize, previewSize ) );
603 TQSize pixSize = TQSize( size, size );
604 if ( pixSize != pixmapSize() ) {
605 setPixmapSize( pixSize );
614 TQSize pixSize = TQSize( size, size );
615 if ( pixSize != pixmapSize() ) {
616 setPixmapSize( pixSize );
621void KFileIVI::mimeTypeAndIconDetermined()
627class KFileIVILineEdit :
public TQTextEdit
632 KFileIVILineEdit(
const TQString &text, TQWidget *parent,
KFileIVI *theItem,
const char* name = 0);
635 void keyPressEvent(TQKeyEvent *e);
636 void focusOutEvent(TQFocusEvent *e);
643 KFileIVILineEdit(
const KFileIVILineEdit &);
644 KFileIVILineEdit &operator=(
const KFileIVILineEdit &);
647KFileIVILineEdit::KFileIVILineEdit(
const TQString &text, TQWidget *parent,
648 KFileIVI *theItem,
const char *name)
649 : TQTextEdit(parent, name),
item(theItem), startText(text)
651 setFrameStyle(TQFrame::Plain | TQFrame::Box);
654 setHScrollBarMode(AlwaysOff);
655 setVScrollBarMode(AlwaysOff);
658 setTextFormat(PlainText);
660 setAlignment(TQt::AlignCenter);
661 setWordWrap(WidgetWidth);
662 setWrapPolicy(AtWordOrDocumentBoundary);
663 setWrapColumnOrWidth(
item->iconView()->maxItemWidth() -
664 (
item->iconView()->itemTextPos() == TQIconView::Bottom ?
665 0 :
item->pixmapRect().width()));
667 resize(wrapColumnOrWidth() + 2, heightForWidth(wrapColumnOrWidth()) + 2);
670void KFileIVILineEdit::keyPressEvent(TQKeyEvent *e)
672 if (e->key() == Key_Escape)
674 item->TQIconViewItem::setText(startText);
675 item->cancelRenameItem();
677 else if (e->key() == Key_Enter || e->key() == Key_Return)
681 else if ((e->key() == Key_Tab || e->key() == Key_Backtab) &&
682 !(e->state() & ControlButton || e->state() & AltButton))
686 if (e->key() == Key_Tab && !(e->state() & ShiftButton))
691 it =
static_cast<KFileIVI*
>(
item->iconView()->firstItem());
699 it =
static_cast<KFileIVI*
>(
item->iconView()->lastItem());
702 if (it) it->rename();
706 TQTextEdit::keyPressEvent(e);
708 resize(width(), heightForWidth(width()) + 2);
712void KFileIVILineEdit::focusOutEvent(TQFocusEvent *e)
714 if ( e->reason() != TQFocusEvent::Popup )
715 item->cancelRenameItem();
718void KFileIVI::rename()
729 const TQString fileName = text();
730 m_renameBox =
new KFileIVILineEdit(fileName, view->viewport(),
this,
"kfileivi_renamebox");
731 view->ensureItemVisible(
this);
732 TQRect txtr(textRect(
false));
733 view->addChild(m_renameBox, txtr.x() + (txtr.width() / 2 - m_renameBox->width() / 2),
735 int sel = fileName.find(
".");
736 sel = sel > -1 ? sel : fileName.length();
737 m_renameBox->setSelection(0, 0, 0, sel);
738 view->viewport()->setFocusProxy(m_renameBox);
739 m_renameBox->setFocus();
741 Q_ASSERT(view->renamingItem() ==
nullptr);
742 view->setRenamingItem(
this);
748 if (!m_renameBox || !view)
return;
750 if (!view->wordWrapIconText())
755 setText(m_renameBox->text());
756 view->repaintContents(oldRect.x() - 1, oldRect.y() - 1, oldRect.width() + 2, oldRect.height() + 2,
false);
757 view->repaintContents(r.x() - 1, r.y() - 1, r.width() + 2, r.height() + 2,
false);
759 view->emitRenamed(
this);
762void KFileIVI::cancelRenameItem()
769 view->repaintContents(oldRect.x() - 1, oldRect.y() - 1, oldRect.width() + 2, oldRect.height() + 2,
false);
770 view->repaintContents(r.x() - 1, r.y() - 1, r.width() + 2, r.height() + 2,
false);
772 if (!m_renameBox)
return;
777void KFileIVI::removeRenameBox()
780 if (!m_renameBox || !view)
return;
782 bool resetFocus = view->viewport()->focusProxy() == m_renameBox;
784 m_renameBox->deleteLater();
785 m_renameBox =
nullptr;
788 view->viewport()->setFocusProxy(view);
791 Q_ASSERT(view->renamingItem() ==
this);
792 view->setRenamingItem(
nullptr);
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem,...
virtual void returnPressed()
Handler for return (or single/double click) on ONE icon.
virtual void setIcon(int size, int state=TDEIcon::DefaultState, bool recalc=false, bool redraw=false)
Changes the icon for this item.
void setEffect(int state)
Set the icon to use the specified TDEIconEffect See the docs for TDEIconEffect for details.
void invalidateThumb(int state, bool redraw=false)
Notifies that all icon effects on thumbs should be invalidated, e.g.
KIVDirectoryOverlay * setShowDirectoryOverlay(bool)
Sets showing of directory overlays.
KFileIVI(KonqIconViewWidget *iconview, KFileItem *fileitem, int size)
Create an icon, within a qlistview, representing a file.
void paintFontUpdate(TQPainter *p) const
Contains the logic and code for painting links.
void setOverlayProgressBar(const int progress)
Sets a progress bar to be shown on the right side of the icon.
TQColorGroup updateColors(const TQColorGroup &c) const
Updates the colorgroup.
void invalidateThumbnail()
Our current thumbnail is not longer "current".
int state() const
Return the current state of the icon (TDEIcon::DefaultState, TDEIcon::ActiveState etc....
void setOverlay(const TQString &iconName)
Sets an icon to be shown over the bottom left corner of the icon.
void setActive(bool active)
Called when the mouse is over the icon.
virtual bool acceptDrop(const TQMimeSource *mime) const
virtual void refreshIcon(bool redraw)
Redetermines the icon (useful if KFileItem might return another icon).
void setThumbnailPixmap(const TQPixmap &pixmap)
Set this when the thumbnail was loaded.
bool isAnimated() const
Return true if we are currently animating this icon.
void setMouseOverAnimation(const TQString &movieFileName)
Enable an animation on mouseover, if there is an available mng.
void setDisabled(bool disabled)
Set to true when this icon is 'cut'.
bool hasAnimation() const
Return true if the icon might have an animation available.
KIVFreeSpaceOverlay * setShowFreeSpaceOverlay(bool)
Sets showing of free space overlays.
void renameItem()
Reimplementation of TQt inline rename.
void setPixmapDirect(const TQPixmap &pixmap, bool recalc=false, bool redraw=false)
Bypass setIcon.
void paintOverlayProgressBar(TQPainter *p) const
Contains the logic and code for painting the overlay progress bar.
virtual void paintItem(TQPainter *p, const TQColorGroup &cg)
Paints this item.
void paintOverlay(TQPainter *p) const
Contains the logic and code for painting the overlay pixmap.
static void doDrop(const KFileItem *destItem, const KURL &destURL, TQDropEvent *ev, TQWidget *parent)
Drop.