1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Gregor Kališnik <gregor@podnapisi.net> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
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 *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #include "dolphinview.h"
23 #include <QApplication>
26 #include <QItemSelection>
31 #include <kcolorscheme.h>
32 #include <kdirmodel.h>
33 #include <kdirlister.h>
34 #include <kfileitemdelegate.h>
36 #include <kiconeffect.h>
37 #include <kio/netaccess.h>
38 #include <kio/renamedialog.h>
39 #include <kio/previewjob.h>
40 #include <kmimetyperesolver.h>
41 #include <konqmimedata.h>
42 #include <konq_operations.h>
45 #include "dolphincolumnview.h"
46 #include "dolphincontroller.h"
47 #include "dolphinsortfilterproxymodel.h"
48 #include "dolphindetailsview.h"
49 #include "dolphiniconsview.h"
50 #include "dolphinitemcategorizer.h"
51 #include "renamedialog.h"
52 #include "viewproperties.h"
53 #include "dolphinsettings.h"
54 #include "dolphin_generalsettings.h"
56 DolphinView::DolphinView(QWidget
* parent
,
58 KDirLister
* dirLister
,
60 DolphinSortFilterProxyModel
* proxyModel
) :
63 m_loadingDirectory(false),
64 m_initializeColumnView(false),
65 m_mode(DolphinView::IconsView
),
71 m_fileItemDelegate(0),
73 m_dirLister(dirLister
),
74 m_proxyModel(proxyModel
)
76 setFocusPolicy(Qt::StrongFocus
);
77 m_topLayout
= new QVBoxLayout(this);
78 m_topLayout
->setSpacing(0);
79 m_topLayout
->setMargin(0);
81 QClipboard
* clipboard
= QApplication::clipboard();
82 connect(clipboard
, SIGNAL(dataChanged()),
83 this, SLOT(updateCutItems()));
85 connect(m_dirLister
, SIGNAL(completed()),
86 this, SLOT(updateCutItems()));
87 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
88 this, SLOT(generatePreviews(const KFileItemList
&)));
90 m_controller
= new DolphinController(this);
91 m_controller
->setUrl(url
);
92 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
93 this, SLOT(openContextMenu(const QPoint
&)));
94 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
95 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
96 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
97 this, SLOT(updateSorting(DolphinView::Sorting
)));
98 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
99 this, SLOT(updateSortOrder(Qt::SortOrder
)));
100 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
101 this, SLOT(triggerItem(const QModelIndex
&)));
102 connect(m_controller
, SIGNAL(activated()),
103 this, SLOT(activate()));
104 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
105 this, SLOT(showHoverInformation(const QModelIndex
&)));
106 connect(m_controller
, SIGNAL(viewportEntered()),
107 this, SLOT(clearHoverInformation()));
109 applyViewProperties(url
);
110 m_topLayout
->addWidget(itemView());
113 DolphinView::~DolphinView()
117 const KUrl
& DolphinView::url() const
119 return m_controller
->url();
122 KUrl
DolphinView::rootUrl() const
124 return isColumnViewActive() ? m_dirLister
->url() : url();
127 void DolphinView::setActive(bool active
)
129 if (active
== m_active
) {
135 QColor color
= KColorScheme(KColorScheme::View
).background();
137 emit
urlChanged(url());
138 emit
selectionChanged(selectedItems());
143 QWidget
* viewport
= itemView()->viewport();
145 palette
.setColor(viewport
->backgroundRole(), color
);
146 viewport
->setPalette(palette
);
155 bool DolphinView::isActive() const
160 void DolphinView::setMode(Mode mode
)
162 if (mode
== m_mode
) {
163 return; // the wished mode is already set
168 if (isColumnViewActive()) {
169 // When changing the mode in the column view, it makes sense
170 // to go back to the root URL of the column view automatically.
171 // Otherwise there it would not be possible to turn off the column view
172 // without focusing the first column.
173 setUrl(m_dirLister
->url());
174 m_controller
->setUrl(m_dirLister
->url());
177 ViewProperties
props(url());
178 props
.setViewMode(m_mode
);
181 startDirLister(url());
186 DolphinView::Mode
DolphinView::mode() const
191 void DolphinView::setShowPreview(bool show
)
193 ViewProperties
props(url());
194 props
.setShowPreview(show
);
196 m_controller
->setShowPreview(show
);
197 emit
showPreviewChanged();
199 startDirLister(url(), true);
202 bool DolphinView::showPreview() const
204 return m_controller
->showPreview();
207 void DolphinView::setShowHiddenFiles(bool show
)
209 if (m_dirLister
->showingDotFiles() == show
) {
213 ViewProperties
props(url());
214 props
.setShowHiddenFiles(show
);
216 m_dirLister
->setShowingDotFiles(show
);
217 emit
showHiddenFilesChanged();
219 startDirLister(url(), true);
222 bool DolphinView::showHiddenFiles() const
224 return m_dirLister
->showingDotFiles();
227 void DolphinView::setCategorizedSorting(bool categorized
)
229 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
233 Q_ASSERT(m_iconsView
!= 0);
235 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
236 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
238 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
239 m_iconsView
->setItemCategorizer(0);
243 ViewProperties
props(url());
244 props
.setCategorizedSorting(categorized
);
247 emit
categorizedSortingChanged();
250 bool DolphinView::categorizedSorting() const
252 if (!supportsCategorizedSorting()) {
256 Q_ASSERT(m_iconsView
!= 0);
257 return m_iconsView
->itemCategorizer() != 0;
260 bool DolphinView::supportsCategorizedSorting() const
262 return m_iconsView
!= 0;
265 void DolphinView::selectAll()
267 selectAll(QItemSelectionModel::Select
);
270 void DolphinView::invertSelection()
272 selectAll(QItemSelectionModel::Toggle
);
275 bool DolphinView::hasSelection() const
277 return itemView()->selectionModel()->hasSelection();
280 void DolphinView::clearSelection()
282 itemView()->selectionModel()->clear();
285 KFileItemList
DolphinView::selectedItems() const
287 const QAbstractItemView
* view
= itemView();
289 // Our view has a selection, we will map them back to the DirModel
290 // and then fill the KFileItemList.
291 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
293 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
294 KFileItemList itemList
;
296 const QModelIndexList indexList
= selection
.indexes();
297 QModelIndexList::const_iterator end
= indexList
.end();
298 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
299 Q_ASSERT((*it
).isValid());
301 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
303 itemList
.append(item
);
310 KUrl::List
DolphinView::selectedUrls() const
314 const KFileItemList list
= selectedItems();
315 KFileItemList::const_iterator it
= list
.begin();
316 const KFileItemList::const_iterator end
= list
.end();
318 KFileItem
* item
= *it
;
319 urls
.append(item
->url());
326 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
328 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
329 return m_dirModel
->itemForIndex(dirModelIndex
);
332 void DolphinView::setContentsPosition(int x
, int y
)
334 QAbstractItemView
* view
= itemView();
335 view
->horizontalScrollBar()->setValue(x
);
336 view
->verticalScrollBar()->setValue(y
);
338 m_loadingDirectory
= false;
341 QPoint
DolphinView::contentsPosition() const
343 const int x
= itemView()->horizontalScrollBar()->value();
344 const int y
= itemView()->verticalScrollBar()->value();
348 void DolphinView::zoomIn()
350 m_controller
->triggerZoomIn();
353 void DolphinView::zoomOut()
355 m_controller
->triggerZoomOut();
358 bool DolphinView::isZoomInPossible() const
360 return m_controller
->isZoomInPossible();
363 bool DolphinView::isZoomOutPossible() const
365 return m_controller
->isZoomOutPossible();
368 void DolphinView::setSorting(Sorting sorting
)
370 if (sorting
!= this->sorting()) {
371 updateSorting(sorting
);
375 DolphinView::Sorting
DolphinView::sorting() const
377 return m_proxyModel
->sorting();
380 void DolphinView::setSortOrder(Qt::SortOrder order
)
382 if (sortOrder() != order
) {
383 updateSortOrder(order
);
387 Qt::SortOrder
DolphinView::sortOrder() const
389 return m_proxyModel
->sortOrder();
392 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
394 ViewProperties
props(url());
395 props
.setAdditionalInfo(info
);
397 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
398 m_fileItemDelegate
->setAdditionalInformation(info
);
400 emit
additionalInfoChanged(info
);
401 startDirLister(url(), true);
404 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
406 return m_fileItemDelegate
->additionalInformation();
409 void DolphinView::reload()
412 startDirLister(url(), true);
415 void DolphinView::refresh()
418 applyViewProperties(m_controller
->url());
422 void DolphinView::setUrl(const KUrl
& url
)
424 if (m_controller
->url() == url
) {
428 m_controller
->setUrl(url
);
430 applyViewProperties(url
);
433 emit
urlChanged(url
);
436 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
438 QWidget::mouseReleaseEvent(event
);
441 void DolphinView::activate()
446 void DolphinView::triggerItem(const QModelIndex
& index
)
448 if (!isValidNameIndex(index
)) {
450 showHoverInformation(index
);
454 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
455 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
456 // items are selected by the user, hence don't trigger the
457 // item specified by 'index'
461 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
466 // Prefer the local path over the URL. This assures that the
467 // volume space information is correct. Assuming that the URL is media:/sda1,
468 // and the local path is /windows/C: For the URL the space info is related
469 // to the root partition (and hence wrong) and for the local path the space
470 // info is related to the windows partition (-> correct).
471 const QString
localPath(item
->localPath());
473 if (localPath
.isEmpty()) {
481 } else if (item
->isFile()) {
482 // allow to browse through ZIP and tar files
483 KMimeType::Ptr mime
= item
->mimeTypePtr();
484 if (mime
->is("application/zip")) {
485 url
.setProtocol("zip");
487 } else if (mime
->is("application/x-tar") ||
488 mime
->is("application/x-tarz") ||
489 mime
->is("application/x-bzip-compressed-tar") ||
490 mime
->is("application/x-compressed-tar") ||
491 mime
->is("application/x-tzo")) {
492 url
.setProtocol("tar");
502 void DolphinView::generatePreviews(const KFileItemList
& items
)
504 if (m_controller
->showPreview()) {
506 // Must turn QList<KFileItem *> to QList<KFileItem>...
507 QList
<KFileItem
> itemsToPreview
;
508 foreach( KFileItem
* it
, items
)
509 itemsToPreview
.append( *it
);
511 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
512 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
513 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
517 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
519 Q_ASSERT(!item
.isNull());
520 if (item
.url().directory() != m_dirLister
->url().path()) {
521 // the preview job is still working on items of an older URL, hence
522 // the item is not part of the directory model anymore
526 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
527 if (idx
.isValid() && (idx
.column() == 0)) {
528 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
529 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
530 KIconEffect iconEffect
;
531 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
532 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
534 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
539 void DolphinView::emitSelectionChangedSignal()
541 emit
selectionChanged(DolphinView::selectedItems());
544 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
546 if (!url
.isValid()) {
547 const QString
location(url
.pathOrUrl());
548 if (location
.isEmpty()) {
549 emit
errorMessage(i18n("The location is empty."));
551 emit
errorMessage(i18n("The location '%1' is invalid.", location
));
556 m_cutItemsCache
.clear();
557 m_loadingDirectory
= true;
562 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
563 m_initializeColumnView
= false;
569 const KUrl
& dirListerUrl
= m_dirLister
->url();
570 if (dirListerUrl
.isValid()) {
571 const KUrl::List dirs
= m_dirLister
->directories();
574 m_dirLister
->updateDirectory(url
);
578 } else if (m_dirLister
->directories().contains(url
)) {
579 // The dir lister contains the directory already, so
580 // KDirLister::openUrl() may not been invoked twice.
581 m_dirLister
->updateDirectory(url
);
584 const KUrl
& dirListerUrl
= m_dirLister
->url();
585 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
586 // The current URL is not a child of the dir lister
587 // URL. This may happen when e. g. a bookmark has been selected
588 // and hence the view must be reset.
595 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
599 void DolphinView::applyViewProperties(const KUrl
& url
)
601 const ViewProperties
props(url
);
603 const Mode mode
= props
.viewMode();
604 bool changeMode
= (m_mode
!= mode
);
605 if (changeMode
&& isColumnViewActive()) {
606 // The column view is active. Only change the
607 // mode if the current URL is no child of the column view.
608 if (m_dirLister
->url().isParentOf(url
)) {
618 if (m_mode
== ColumnView
) {
619 // The mode has been changed to the Column View. When starting the dir
620 // lister with DolphinView::startDirLister() it is important to give a
621 // hint that the dir lister may not keep the current directory
622 // although this is the default for showing a hierarchy.
623 m_initializeColumnView
= true;
626 if (itemView() == 0) {
629 Q_ASSERT(itemView() != 0);
630 Q_ASSERT(m_fileItemDelegate
!= 0);
632 const bool showHiddenFiles
= props
.showHiddenFiles();
633 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
634 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
635 emit
showHiddenFilesChanged();
638 const bool categorized
= props
.categorizedSorting();
639 if (categorized
!= categorizedSorting()) {
640 if (supportsCategorizedSorting()) {
641 Q_ASSERT(m_iconsView
!= 0);
643 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
644 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
646 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
647 m_iconsView
->setItemCategorizer(0);
651 emit
categorizedSortingChanged();
654 const DolphinView::Sorting sorting
= props
.sorting();
655 if (sorting
!= m_proxyModel
->sorting()) {
656 m_proxyModel
->setSorting(sorting
);
657 emit
sortingChanged(sorting
);
660 const Qt::SortOrder sortOrder
= props
.sortOrder();
661 if (sortOrder
!= m_proxyModel
->sortOrder()) {
662 m_proxyModel
->setSortOrder(sortOrder
);
663 emit
sortOrderChanged(sortOrder
);
666 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
667 if (info
!= m_fileItemDelegate
->additionalInformation()) {
668 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
669 m_fileItemDelegate
->setAdditionalInformation(info
);
670 emit
additionalInfoChanged(info
);
673 const bool showPreview
= props
.showPreview();
674 if (showPreview
!= m_controller
->showPreview()) {
675 m_controller
->setShowPreview(showPreview
);
676 emit
showPreviewChanged();
680 void DolphinView::changeSelection(const KFileItemList
& selection
)
683 if (selection
.isEmpty()) {
686 const KUrl
& baseUrl
= url();
688 QItemSelection new_selection
;
689 foreach(KFileItem
* item
, selection
) {
690 url
= item
->url().upUrl();
691 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
692 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
693 new_selection
.select(index
, index
);
696 itemView()->selectionModel()->select(new_selection
,
697 QItemSelectionModel::ClearAndSelect
698 | QItemSelectionModel::Current
);
701 void DolphinView::openContextMenu(const QPoint
& pos
)
705 const QModelIndex index
= itemView()->indexAt(pos
);
706 if (isValidNameIndex(index
)) {
707 item
= fileItem(index
);
710 emit
requestContextMenu(item
, url());
713 void DolphinView::dropUrls(const KUrl::List
& urls
,
714 const QModelIndex
& index
,
717 KFileItem
* directory
= 0;
718 if (isValidNameIndex(index
)) {
719 KFileItem
* item
= fileItem(index
);
722 // the URLs are dropped above a directory
727 if ((directory
== 0) && (source
== itemView())) {
728 // The dropping is done into the same viewport where
729 // the dragging has been started. Just ignore this...
733 const KUrl
& destination
= (directory
== 0) ?
734 url() : directory
->url();
735 dropUrls(urls
, destination
);
738 void DolphinView::dropUrls(const KUrl::List
& urls
,
739 const KUrl
& destination
)
741 emit
urlsDropped(urls
, destination
);
744 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
746 ViewProperties
props(url());
747 props
.setSorting(sorting
);
749 m_proxyModel
->setSorting(sorting
);
751 emit
sortingChanged(sorting
);
754 void DolphinView::updateSortOrder(Qt::SortOrder order
)
756 ViewProperties
props(url());
757 props
.setSortOrder(order
);
759 m_proxyModel
->setSortOrder(order
);
761 emit
sortOrderChanged(order
);
764 void DolphinView::emitContentsMoved()
766 // only emit the contents moved signal if:
767 // - no directory loading is ongoing (this would reset the contents position
769 // - if the Column View is active: the column view does an automatic
770 // positioning during the loading operation, which must be remembered
771 if (!m_loadingDirectory
|| isColumnViewActive()) {
772 const QPoint
pos(contentsPosition());
773 emit
contentsMoved(pos
.x(), pos
.y());
777 void DolphinView::updateCutItems()
779 // restore the icons of all previously selected items to the
781 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
782 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
784 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
785 if (index
.isValid()) {
786 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
790 m_cutItemsCache
.clear();
792 // ... and apply an item effect to all currently cut items
793 applyCutItemEffect();
796 void DolphinView::showHoverInformation(const QModelIndex
& index
)
798 if (hasSelection()) {
802 const KFileItem
* item
= fileItem(index
);
804 emit
requestItemInfo(item
->url());
808 void DolphinView::clearHoverInformation()
810 emit
requestItemInfo(KUrl());
814 void DolphinView::createView()
816 // delete current view
817 QAbstractItemView
* view
= itemView();
819 m_topLayout
->removeWidget(view
);
821 if (view
== m_iconsView
) {
822 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
823 m_iconsView
->setItemCategorizer(0);
831 m_fileItemDelegate
= 0;
834 Q_ASSERT(m_iconsView
== 0);
835 Q_ASSERT(m_detailsView
== 0);
836 Q_ASSERT(m_columnView
== 0);
838 // ... and recreate it representing the current mode
841 m_iconsView
= new DolphinIconsView(this, m_controller
);
846 m_detailsView
= new DolphinDetailsView(this, m_controller
);
847 view
= m_detailsView
;
851 m_columnView
= new DolphinColumnView(this, m_controller
);
858 m_fileItemDelegate
= new KFileItemDelegate(view
);
859 view
->setItemDelegate(m_fileItemDelegate
);
861 view
->setModel(m_proxyModel
);
862 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
864 new KMimeTypeResolver(view
, m_dirModel
);
865 m_topLayout
->insertWidget(1, view
);
867 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
868 this, SLOT(emitSelectionChangedSignal()));
869 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
870 this, SLOT(emitContentsMoved()));
871 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
872 this, SLOT(emitContentsMoved()));
875 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
877 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
878 const QAbstractItemModel
* itemModel
= selectionModel
->model();
880 const QModelIndex topLeft
= itemModel
->index(0, 0);
881 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
882 itemModel
->columnCount() - 1);
884 QItemSelection
selection(topLeft
, bottomRight
);
885 selectionModel
->select(selection
, flags
);
888 QAbstractItemView
* DolphinView::itemView() const
890 if (m_detailsView
!= 0) {
891 return m_detailsView
;
892 } else if (m_columnView
!= 0) {
899 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
901 return index
.isValid() && (index
.column() == KDirModel::Name
);
904 bool DolphinView::isCutItem(const KFileItem
& item
) const
906 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
907 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
909 const KUrl
& itemUrl
= item
.url();
910 KUrl::List::const_iterator it
= cutUrls
.begin();
911 const KUrl::List::const_iterator end
= cutUrls
.end();
913 if (*it
== itemUrl
) {
922 void DolphinView::applyCutItemEffect()
924 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
925 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
929 KFileItemList
items(m_dirLister
->items());
930 KFileItemList::const_iterator it
= items
.begin();
931 const KFileItemList::const_iterator end
= items
.end();
933 KFileItem
* item
= *it
;
934 if (isCutItem(*item
)) {
935 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
936 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
937 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
938 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
939 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
940 QPixmap pixmap
= icon
.pixmap(128, 128);
942 // remember current pixmap for the item to be able
943 // to restore it when other items get cut
945 cutItem
.url
= item
->url();
946 cutItem
.pixmap
= pixmap
;
947 m_cutItemsCache
.append(cutItem
);
949 // apply icon effect to the cut item
950 KIconEffect iconEffect
;
951 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
952 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
959 #include "dolphinview.moc"