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

libkonq

  • libkonq
tdefileivi.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1999, 2000, 2001, 2002 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
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"
26
27#include <tqpainter.h>
28#include <tqtextedit.h>
29
30#include <kurldrag.h>
31#include <kiconeffect.h>
32#include <tdefileitem.h>
33#include <kdebug.h>
34#include <krun.h>
35#include <kservice.h>
36#include <kmimetype.h> // for KDEDesktopMimeType
37#include <tdestandarddirs.h>
38
39#undef Bool
40
44struct KFileIVI::Private
45{
46 TQIconSet icons; // Icon states (cached to prevent re-applying icon effects
47 // every time)
48 TQPixmap thumb; // Raw unprocessed thumbnail
49 TQString m_animatedIcon; // Name of animation
50 bool m_animated; // Animation currently running ?
51 KIVDirectoryOverlay* m_directoryOverlay;
52 KIVFreeSpaceOverlay* m_freeSpaceOverlay;
53 TQPixmap m_overlay;
54 TQString m_overlayName;
55 int m_progress;
56};
57
58KFileIVI::KFileIVI( KonqIconViewWidget *iconview, KFileItem* fileitem, int size )
59 : TDEIconViewItem( iconview, fileitem->text() ),
60 m_size( size ), m_state( TDEIcon::DefaultState ),
61 m_bDisabled( false ), m_bThumbnail( false ), m_fileitem( fileitem ),
62 m_renameBox(nullptr)
63{
64 d = new KFileIVI::Private;
65
66 updatePixmapSize();
67 setPixmap( m_fileitem->pixmap( m_size, m_state ) );
68 setDropEnabled( S_ISDIR( m_fileitem->mode() ) );
69
70 // Cache entry for the icon effects
71 d->icons.reset( *pixmap(), TQIconSet::Large );
72 d->m_animated = false;
73
74 // iconName() requires the mimetype to be known
75 if ( fileitem->isMimeTypeKnown() )
76 {
77 TQString icon = fileitem->iconName();
78 if ( !icon.isEmpty() )
79 setMouseOverAnimation( icon );
80 else
81 setMouseOverAnimation( "unknown" );
82 }
83 d->m_progress = -1;
84 d->m_directoryOverlay = 0;
85 d->m_freeSpaceOverlay = 0;
86}
87
88KFileIVI::~KFileIVI()
89{
90 removeRenameBox();
91 delete d->m_directoryOverlay;
92 delete d->m_freeSpaceOverlay;
93 delete d;
94}
95
96void KFileIVI::invalidateThumb( int state, bool redraw )
97{
98 TQIconSet::Mode mode;
99 switch( state )
100 {
101 case TDEIcon::DisabledState:
102 mode = TQIconSet::Disabled;
103 break;
104 case TDEIcon::ActiveState:
105 mode = TQIconSet::Active;
106 break;
107 case TDEIcon::DefaultState:
108 default:
109 mode = TQIconSet::Normal;
110 break;
111 }
112 d->icons = TQIconSet();
113 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
114 apply( d->thumb, TDEIcon::Desktop, state ),
115 TQIconSet::Large, mode );
116 m_state = state;
117
118 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
119 false, redraw );
120}
121
122void KFileIVI::setIcon( int size, int state, bool recalc, bool redraw )
123{
124 m_size = size;
125 m_bThumbnail = false;
126 if ( m_bDisabled )
127 m_state = TDEIcon::DisabledState;
128 else
129 m_state = state;
130
131 if ( d->m_overlayName.isNull() )
132 d->m_overlay = TQPixmap();
133 else {
134 int halfSize;
135 if (m_size == 0) {
136 halfSize = IconSize(TDEIcon::Desktop) / 2;
137 } else {
138 halfSize = m_size / 2;
139 }
140 d->m_overlay = DesktopIcon(d->m_overlayName, halfSize);
141 }
142
143 setPixmapDirect(m_fileitem->pixmap( m_size, m_state ) , recalc, redraw );
144}
145
146void KFileIVI::setOverlay( const TQString& iconName )
147{
148 d->m_overlayName = iconName;
149
150 refreshIcon(true);
151}
152
153void KFileIVI::setOverlayProgressBar( const int progress )
154{
155 d->m_progress = progress;
156
157 refreshIcon(true);
158}
159
160KIVDirectoryOverlay* KFileIVI::setShowDirectoryOverlay( bool show )
161{
162 if ( !m_fileitem->isDir() || m_fileitem->iconName() != "folder" )
163 return 0;
164
165 if (show) {
166 if (!d->m_directoryOverlay)
167 d->m_directoryOverlay = new KIVDirectoryOverlay(this);
168 return d->m_directoryOverlay;
169 } else {
170 delete d->m_directoryOverlay;
171 d->m_directoryOverlay = 0;
172 setOverlay(TQString());
173 return 0;
174 }
175}
176
177bool KFileIVI::showDirectoryOverlay( )
178{
179 return (bool)d->m_directoryOverlay;
180}
181
182KIVFreeSpaceOverlay* KFileIVI::setShowFreeSpaceOverlay( bool show )
183{
184 if ( !m_fileitem->mimetype().startsWith("media/") ) {
185 return 0;
186 }
187
188 if (show) {
189 if (!d->m_freeSpaceOverlay)
190 d->m_freeSpaceOverlay = new KIVFreeSpaceOverlay(this);
191 return d->m_freeSpaceOverlay;
192 } else {
193 delete d->m_freeSpaceOverlay;
194 d->m_freeSpaceOverlay = 0;
195 setOverlayProgressBar(-1);
196 return 0;
197 }
198}
199
200bool KFileIVI::showFreeSpaceOverlay( )
201{
202 return (bool)d->m_freeSpaceOverlay;
203}
204
205void KFileIVI::setPixmapDirect( const TQPixmap& pixmap, bool recalc, bool redraw )
206{
207 TQIconSet::Mode mode;
208 switch( m_state )
209 {
210 case TDEIcon::DisabledState:
211 mode = TQIconSet::Disabled;
212 break;
213 case TDEIcon::ActiveState:
214 mode = TQIconSet::Active;
215 break;
216 case TDEIcon::DefaultState:
217 default:
218 mode = TQIconSet::Normal;
219 break;
220 }
221
222 // We cannot just reset() the iconset here, because setIcon can be
223 // called with any state and not just normal state. So we just
224 // create a dummy empty iconset as base object.
225 d->icons = TQIconSet();
226 d->icons.setPixmap( pixmap, TQIconSet::Large, mode );
227
228 updatePixmapSize();
229 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ),
230 recalc, redraw );
231}
232
233void KFileIVI::setDisabled( bool disabled )
234{
235 if ( m_bDisabled != disabled )
236 {
237 m_bDisabled = disabled;
238 bool active = ( m_state == TDEIcon::ActiveState );
239 setEffect( m_bDisabled ? TDEIcon::DisabledState :
240 ( active ? TDEIcon::ActiveState : TDEIcon::DefaultState ) );
241 }
242}
243
244void KFileIVI::setThumbnailPixmap( const TQPixmap & pixmap )
245{
246 m_bThumbnail = true;
247 d->thumb = pixmap;
248 // TQIconSet::reset() doesn't seem to clear the other generated pixmaps,
249 // so we just create a blank TQIconSet here
250 d->icons = TQIconSet();
251 d->icons.setPixmap( TDEGlobal::iconLoader()->iconEffect()->
252 apply( pixmap, TDEIcon::Desktop, TDEIcon::DefaultState ),
253 TQIconSet::Large, TQIconSet::Normal );
254
255 m_state = TDEIcon::DefaultState;
256
257 // Recalc when setting this pixmap!
258 updatePixmapSize();
259 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large,
260 TQIconSet::Normal ), true );
261}
262
263void KFileIVI::setActive( bool active )
264{
265 if ( active )
266 setEffect( TDEIcon::ActiveState );
267 else
268 setEffect( m_bDisabled ? TDEIcon::DisabledState : TDEIcon::DefaultState );
269}
270
271void KFileIVI::setEffect( int state )
272{
273 TQIconSet::Mode mode;
274 switch( state )
275 {
276 case TDEIcon::DisabledState:
277 mode = TQIconSet::Disabled;
278 break;
279 case TDEIcon::ActiveState:
280 mode = TQIconSet::Active;
281 break;
282 case TDEIcon::DefaultState:
283 default:
284 mode = TQIconSet::Normal;
285 break;
286 }
287 // Do not update if the fingerprint is identical (prevents flicker)!
288
289 TDEIconEffect *effect = TDEGlobal::iconLoader()->iconEffect();
290
291 bool haveEffect = effect->hasEffect( TDEIcon::Desktop, m_state ) !=
292 effect->hasEffect( TDEIcon::Desktop, state );
293
294 //kdDebug(1203) << "desktop;defaultstate=" <<
295 // effect->fingerprint(TDEIcon::Desktop, TDEIcon::DefaultState) <<
296 // endl;
297 //kdDebug(1203) << "desktop;activestate=" <<
298 // effect->fingerprint(TDEIcon::Desktop, TDEIcon::ActiveState) <<
299 // endl;
300
301 if( haveEffect &&
302 effect->fingerprint( TDEIcon::Desktop, m_state ) !=
303 effect->fingerprint( TDEIcon::Desktop, state ) )
304 {
305 // Effects on are not applied until they are first accessed to
306 // save memory. Do this now when needed
307 if( m_bThumbnail )
308 {
309 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
310 d->icons.setPixmap( effect->apply( d->thumb, TDEIcon::Desktop, state ),
311 TQIconSet::Large, mode );
312 }
313 else
314 {
315 if( d->icons.isGenerated( TQIconSet::Large, mode ) )
316 d->icons.setPixmap( m_fileitem->pixmap( m_size, state ),
317 TQIconSet::Large, mode );
318 }
319 TQIconViewItem::setPixmap( d->icons.pixmap( TQIconSet::Large, mode ) );
320 }
321 m_state = state;
322}
323
324void KFileIVI::refreshIcon( bool redraw )
325{
326 if (!isThumbnail()) {
327 setIcon( m_size, m_state, true, redraw );
328 }
329}
330
331void KFileIVI::invalidateThumbnail()
332{
333 d->thumb = TQPixmap();
334}
335
336bool KFileIVI::isThumbnailInvalid() const
337{
338 return d->thumb.isNull();
339}
340
341bool KFileIVI::acceptDrop( const TQMimeSource *mime ) const
342{
343 if ( mime->provides( "text/uri-list" ) ) // We're dragging URLs
344 {
345 if ( m_fileitem->acceptsDrops() ) // Directory, executables, ...
346 return true;
347
348 // Use cache
349 KURL::List uris = ( static_cast<KonqIconViewWidget*>(iconView()) )->dragURLs();
350
351 // Check if we want to drop something on itself
352 // (Nothing will happen, but it's a convenient way to move icons)
353 KURL::List::Iterator it = uris.begin();
354 for ( ; it != uris.end() ; it++ )
355 {
356 if ( m_fileitem->url().equals( *it, true /*ignore trailing slashes*/ ) )
357 return true;
358 }
359 }
360 return TQIconViewItem::acceptDrop( mime );
361}
362
363void KFileIVI::setKey( const TQString &key )
364{
365 TQString theKey = key;
366
367 TQVariant sortDirProp = iconView()->property( "sortDirectoriesFirst" );
368
369 bool isdir = ( S_ISDIR( m_fileitem->mode() ) && ( !sortDirProp.isValid() || ( sortDirProp.type() == TQVariant::Bool && sortDirProp.toBool() ) ) );
370
371 // The order is: .dir (0), dir (1), .file (2), file (3)
372 int sortChar = isdir ? 1 : 3;
373 if ( m_fileitem->text()[0] == '.' )
374 --sortChar;
375
376 if ( !iconView()->sortDirection() ) // reverse sorting
377 sortChar = 3 - sortChar;
378
379 theKey.prepend( TQChar( sortChar + '0' ) );
380
381 TQIconViewItem::setKey( theKey );
382}
383
384void KFileIVI::dropped( TQDropEvent *e, const TQValueList<TQIconDragItem> & )
385{
386 KonqOperations::doDrop( item(), item()->url(), e, iconView() );
387}
388
389void KFileIVI::returnPressed()
390{
391 if ( static_cast<KonqIconViewWidget*>(iconView())->isDesktop() ) {
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";
398 }
399 else if (mimetype.contains("encrypted_unlocked")) {
400 lockingAction = "konqueror/servicemenus/media_lock.desktop";
401 }
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]);
410 }
411 }
412 }
413 else {
414 (void) new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
415 }
416 }
417 else {
418 // When clicking on a link to e.g. $HOME from the desktop, we want to open $HOME
419 // Symlink resolution must only happen on the desktop though (#63014)
420 if ( m_fileitem->isLink() && url.isLocalFile() ) {
421 url = KURL( url, m_fileitem->linkDest() );
422 }
423
424 (void) new KRun( url, m_fileitem->mode(), m_fileitem->isLocalFile() );
425 }
426 }
427 else {
428 m_fileitem->run();
429 }
430}
431
432
433void KFileIVI::paintItem( TQPainter *p, const TQColorGroup &c )
434{
435 TQColorGroup cg = updateColors(c);
436 paintFontUpdate( p );
437
438 //*** TEMPORARY CODE - MUST BE MADE CONFIGURABLE FIRST - Martijn
439 // SET UNDERLINE ON HOVER ONLY
440 /*if ( ( ( KonqIconViewWidget* ) iconView() )->m_pActiveItem == this )
441 {
442 TQFont f( p->font() );
443 f.setUnderline( true );
444 p->setFont( f );
445 }*/
446
447 TDEIconViewItem::paintItem( p, cg );
448 paintOverlay(p);
449 paintOverlayProgressBar(p);
450
451}
452
453void KFileIVI::paintOverlay( TQPainter *p ) const
454{
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);
458 }
459}
460
461void KFileIVI::paintOverlayProgressBar( TQPainter *p ) const
462{
463 if (d->m_progress != -1) {
464// // Pie chart
465// TQRect rect = pixmapRect(true);
466// rect.setX(x() + rect.x());
467// rect.setY(y() + rect.y() + ((pixmapRect().height()*3)/4));
468// rect.setWidth(pixmapRect().width()/4);
469// rect.setHeight(pixmapRect().height()/4);
470//
471// p->save();
472//
473// p->setPen(TQPen::NoPen);
474// p->setBrush(TQt::red);
475// p->drawEllipse(rect);
476// p->setBrush(TQt::green);
477// p->drawPie(rect, 1440, (((100-d->m_progress)*5760)/100));
478
479// // Horizontal progress bar
480// TQRect rect = pixmapRect(true);
481// int verticalOffset = 0;
482// int usedBarWidth = ((d->m_progress*pixmapRect().width())/100);
483// int endPosition = x() + rect.x() + usedBarWidth;
484//
485// p->save();
486//
487// p->setPen(TQPen::NoPen);
488// p->setBrush(TQt::red);
489// p->drawRect(TQRect(x() + rect.x(), y() + rect.y() + (pixmapRect().height() - verticalOffset), usedBarWidth, 1));
490// p->setBrush(TQt::green);
491// p->drawRect(TQRect(endPosition, y() + rect.y() + (pixmapRect().height() - verticalOffset), pixmapRect().width() - usedBarWidth, 1));
492
493 // Vertical progress bar
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;
498
499 p->save();
500
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));
506
507 p->restore();
508 }
509}
510
511void KFileIVI::paintFontUpdate( TQPainter *p ) const
512{
513 if ( m_fileitem->isLink() )
514 {
515 TQFont f( p->font() );
516 f.setItalic( true );
517 p->setFont( f );
518 }
519}
520
521TQColorGroup KFileIVI::updateColors( const TQColorGroup &c ) const
522{
523 TQColorGroup cg( c );
524 cg.setColor( TQColorGroup::Text, static_cast<KonqIconViewWidget*>(iconView())->itemColor() );
525 return cg;
526}
527
528bool KFileIVI::move( int x, int y )
529{
530 if ( static_cast<KonqIconViewWidget*>(iconView())->isDesktop() ) {
531 if ( x < 5 )
532 x = 5;
533 if ( x > iconView()->viewport()->width() - ( width() + 5 ) )
534 x = iconView()->viewport()->width() - ( width() + 5 );
535 if ( y < 5 )
536 y = 5;
537 if ( y > iconView()->viewport()->height() - ( height() + 5 ) )
538 y = iconView()->viewport()->height() - ( height() + 5 );
539 }
540 return TQIconViewItem::move( x, y );
541}
542
543bool KFileIVI::hasAnimation() const
544{
545 return !d->m_animatedIcon.isEmpty() && !m_bThumbnail;
546}
547
548void KFileIVI::setMouseOverAnimation( const TQString& movieFileName )
549{
550 if ( !movieFileName.isEmpty() )
551 {
552 //kdDebug(1203) << "TDEIconViewItem::setMouseOverAnimation " << movieFileName << endl;
553 d->m_animatedIcon = movieFileName;
554 }
555}
556
557TQString KFileIVI::mouseOverAnimation() const
558{
559 return d->m_animatedIcon;
560}
561
562bool KFileIVI::isAnimated() const
563{
564 return d->m_animated;
565}
566
567void KFileIVI::setAnimated( bool a )
568{
569 d->m_animated = a;
570}
571
572int KFileIVI::compare( TQIconViewItem *i ) const
573{
574 KonqIconViewWidget* view = static_cast<KonqIconViewWidget*>(iconView());
575 if ( view->caseInsensitiveSort() )
576 return key().localeAwareCompare( i->key() );
577 else
578 return view->m_pSettings->caseSensitiveCompare( key(), i->key() );
579}
580
581void KFileIVI::updatePixmapSize()
582{
583 int size = m_size ? m_size :
584 TDEGlobal::iconLoader()->currentSize( TDEIcon::Desktop );
585
586 KonqIconViewWidget* view = static_cast<KonqIconViewWidget*>( iconView() );
587
588 bool mimeDetermined = false;
589 if ( m_fileitem->isMimeTypeKnown() ) {
590 mimeDetermined = true;
591 }
592
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 ) );
599 changed = true;
600 }
601 }
602 else {
603 TQSize pixSize = TQSize( size, size );
604 if ( pixSize != pixmapSize() ) {
605 setPixmapSize( pixSize );
606 changed = true;
607 }
608 }
609 if (changed) {
610 view->adjustItems();
611 }
612 }
613 else {
614 TQSize pixSize = TQSize( size, size );
615 if ( pixSize != pixmapSize() ) {
616 setPixmapSize( pixSize );
617 }
618 }
619}
620
621void KFileIVI::mimeTypeAndIconDetermined()
622{
623 updatePixmapSize();
624}
625
626// Reimplemented from tqiconview.cpp
627class KFileIVILineEdit : public TQTextEdit
628{
629 friend class KFileIVI;
630
631 public:
632 KFileIVILineEdit(const TQString &text, TQWidget *parent, KFileIVI *theItem, const char* name = 0);
633
634 protected:
635 void keyPressEvent(TQKeyEvent *e);
636 void focusOutEvent(TQFocusEvent *e);
637
638 protected:
639 KFileIVI *item;
640 TQString startText;
641
642 private:
643 KFileIVILineEdit(const KFileIVILineEdit &);
644 KFileIVILineEdit &operator=(const KFileIVILineEdit &);
645};
646
647KFileIVILineEdit::KFileIVILineEdit(const TQString &text, TQWidget *parent,
648 KFileIVI *theItem, const char *name)
649 : TQTextEdit(parent, name), item(theItem), startText(text)
650{
651 setFrameStyle(TQFrame::Plain | TQFrame::Box);
652 setLineWidth(1);
653
654 setHScrollBarMode(AlwaysOff);
655 setVScrollBarMode(AlwaysOff);
656
657 resize( 200, 200 ); // ### some size, there should be a forceReformat()
658 setTextFormat(PlainText);
659 setText(text);
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()));
666
667 resize(wrapColumnOrWidth() + 2, heightForWidth(wrapColumnOrWidth()) + 2);
668}
669
670void KFileIVILineEdit::keyPressEvent(TQKeyEvent *e)
671{
672 if (e->key() == Key_Escape)
673 {
674 item->TQIconViewItem::setText(startText);
675 item->cancelRenameItem();
676 }
677 else if (e->key() == Key_Enter || e->key() == Key_Return)
678 {
679 item->renameItem();
680 }
681 else if ((e->key() == Key_Tab || e->key() == Key_Backtab) &&
682 !(e->state() & ControlButton || e->state() & AltButton))
683 {
684 item->renameItem();
685 KFileIVI *it;
686 if (e->key() == Key_Tab && !(e->state() & ShiftButton))
687 {
688 it = static_cast<KFileIVI*>(item->nextItem());
689 if (!it) // wrap around to start
690 {
691 it = static_cast<KFileIVI*>(item->iconView()->firstItem());
692 }
693 }
694 else
695 {
696 it = static_cast<KFileIVI*>(item->prevItem());
697 if (!it) // wrap around to end
698 {
699 it = static_cast<KFileIVI*>(item->iconView()->lastItem());
700 }
701 }
702 if (it) it->rename();
703 }
704 else
705 {
706 TQTextEdit::keyPressEvent(e);
707 sync();
708 resize(width(), heightForWidth(width()) + 2);
709 }
710}
711
712void KFileIVILineEdit::focusOutEvent(TQFocusEvent *e)
713{
714 if ( e->reason() != TQFocusEvent::Popup )
715 item->cancelRenameItem();
716}
717
718void KFileIVI::rename()
719{
720 KonqIconViewWidget *view = static_cast<KonqIconViewWidget *>(iconView());
721 if (!view) return;
722
723 if (m_renameBox)
724 {
725 removeRenameBox();
726 }
727
728 oldRect = rect();
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),
734 txtr.y() - 3);
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();
740 m_renameBox->show();
741 Q_ASSERT(view->renamingItem() == nullptr);
742 view->setRenamingItem(this);
743}
744
745void KFileIVI::renameItem()
746{
747 KonqIconViewWidget *view = static_cast<KonqIconViewWidget *>(iconView());
748 if (!m_renameBox || !view) return;
749
750 if (!view->wordWrapIconText())
751 {
752 calcRect();
753 }
754 TQRect r = rect();
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);
758 removeRenameBox();
759 view->emitRenamed(this);
760}
761
762void KFileIVI::cancelRenameItem()
763{
764 KonqIconViewWidget *view = static_cast<KonqIconViewWidget *>(iconView());
765 if (!view) return;
766
767 TQRect r = rect();
768 calcRect();
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);
771
772 if (!m_renameBox) return;
773
774 removeRenameBox();
775}
776
777void KFileIVI::removeRenameBox()
778{
779 KonqIconViewWidget *view = static_cast<KonqIconViewWidget *>(iconView());
780 if (!m_renameBox || !view) return;
781
782 bool resetFocus = view->viewport()->focusProxy() == m_renameBox;
783 m_renameBox->hide();
784 m_renameBox->deleteLater();
785 m_renameBox = nullptr;
786 if (resetFocus)
787 {
788 view->viewport()->setFocusProxy(view);
789 view->setFocus();
790 }
791 Q_ASSERT(view->renamingItem() == this);
792 view->setRenamingItem(nullptr);
793}
KFileIVI
KFileIVI (short form of "Konq - File - IconViewItem") is, as expected, an improved TDEIconViewItem,...
Definition: tdefileivi.h:41
KFileIVI::returnPressed
virtual void returnPressed()
Handler for return (or single/double click) on ONE icon.
Definition: tdefileivi.cpp:389
KFileIVI::setIcon
virtual void setIcon(int size, int state=TDEIcon::DefaultState, bool recalc=false, bool redraw=false)
Changes the icon for this item.
Definition: tdefileivi.cpp:122
KFileIVI::setEffect
void setEffect(int state)
Set the icon to use the specified TDEIconEffect See the docs for TDEIconEffect for details.
Definition: tdefileivi.cpp:271
KFileIVI::invalidateThumb
void invalidateThumb(int state, bool redraw=false)
Notifies that all icon effects on thumbs should be invalidated, e.g.
Definition: tdefileivi.cpp:96
KFileIVI::setShowDirectoryOverlay
KIVDirectoryOverlay * setShowDirectoryOverlay(bool)
Sets showing of directory overlays.
Definition: tdefileivi.cpp:160
KFileIVI::item
KFileItem * item() const
Definition: tdefileivi.h:63
KFileIVI::KFileIVI
KFileIVI(KonqIconViewWidget *iconview, KFileItem *fileitem, int size)
Create an icon, within a qlistview, representing a file.
Definition: tdefileivi.cpp:58
KFileIVI::paintFontUpdate
void paintFontUpdate(TQPainter *p) const
Contains the logic and code for painting links.
Definition: tdefileivi.cpp:511
KFileIVI::setOverlayProgressBar
void setOverlayProgressBar(const int progress)
Sets a progress bar to be shown on the right side of the icon.
Definition: tdefileivi.cpp:153
KFileIVI::updateColors
TQColorGroup updateColors(const TQColorGroup &c) const
Updates the colorgroup.
Definition: tdefileivi.cpp:521
KFileIVI::invalidateThumbnail
void invalidateThumbnail()
Our current thumbnail is not longer "current".
Definition: tdefileivi.cpp:331
KFileIVI::state
int state() const
Return the current state of the icon (TDEIcon::DefaultState, TDEIcon::ActiveState etc....
Definition: tdefileivi.h:117
KFileIVI::setOverlay
void setOverlay(const TQString &iconName)
Sets an icon to be shown over the bottom left corner of the icon.
Definition: tdefileivi.cpp:146
KFileIVI::setActive
void setActive(bool active)
Called when the mouse is over the icon.
Definition: tdefileivi.cpp:263
KFileIVI::acceptDrop
virtual bool acceptDrop(const TQMimeSource *mime) const
Definition: tdefileivi.cpp:341
KFileIVI::refreshIcon
virtual void refreshIcon(bool redraw)
Redetermines the icon (useful if KFileItem might return another icon).
Definition: tdefileivi.cpp:324
KFileIVI::setThumbnailPixmap
void setThumbnailPixmap(const TQPixmap &pixmap)
Set this when the thumbnail was loaded.
Definition: tdefileivi.cpp:244
KFileIVI::isAnimated
bool isAnimated() const
Return true if we are currently animating this icon.
Definition: tdefileivi.cpp:562
KFileIVI::setMouseOverAnimation
void setMouseOverAnimation(const TQString &movieFileName)
Enable an animation on mouseover, if there is an available mng.
Definition: tdefileivi.cpp:548
KFileIVI::setDisabled
void setDisabled(bool disabled)
Set to true when this icon is 'cut'.
Definition: tdefileivi.cpp:233
KFileIVI::isThumbnail
bool isThumbnail() const
Definition: tdefileivi.h:143
KFileIVI::hasAnimation
bool hasAnimation() const
Return true if the icon might have an animation available.
Definition: tdefileivi.cpp:543
KFileIVI::setShowFreeSpaceOverlay
KIVFreeSpaceOverlay * setShowFreeSpaceOverlay(bool)
Sets showing of free space overlays.
Definition: tdefileivi.cpp:182
KFileIVI::renameItem
void renameItem()
Reimplementation of TQt inline rename.
Definition: tdefileivi.cpp:745
KFileIVI::setPixmapDirect
void setPixmapDirect(const TQPixmap &pixmap, bool recalc=false, bool redraw=false)
Bypass setIcon.
Definition: tdefileivi.cpp:205
KFileIVI::paintOverlayProgressBar
void paintOverlayProgressBar(TQPainter *p) const
Contains the logic and code for painting the overlay progress bar.
Definition: tdefileivi.cpp:461
KFileIVI::paintItem
virtual void paintItem(TQPainter *p, const TQColorGroup &cg)
Paints this item.
Definition: tdefileivi.cpp:433
KFileIVI::paintOverlay
void paintOverlay(TQPainter *p) const
Contains the logic and code for painting the overlay pixmap.
Definition: tdefileivi.cpp:453
KonqIconViewWidget
A file-aware icon view, implementing drag'n'drop, KDE icon sizes, user settings, animated icons....
Definition: konq_iconviewwidget.h:43
KonqOperations::doDrop
static void doDrop(const KFileItem *destItem, const KURL &destURL, TQDropEvent *ev, TQWidget *parent)
Drop.
Definition: konq_operations.cpp:315

libkonq

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

libkonq

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