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(urlChanged(const KUrl
&)),
93 this, SIGNAL(urlChanged(const KUrl
&)));
94 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
95 this, SLOT(openContextMenu(const QPoint
&)));
96 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
97 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
98 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
99 this, SLOT(updateSorting(DolphinView::Sorting
)));
100 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
101 this, SLOT(updateSortOrder(Qt::SortOrder
)));
102 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
103 this, SLOT(triggerItem(const QModelIndex
&)));
104 connect(m_controller
, SIGNAL(activated()),
105 this, SLOT(activate()));
106 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
107 this, SLOT(showHoverInformation(const QModelIndex
&)));
108 connect(m_controller
, SIGNAL(viewportEntered()),
109 this, SLOT(clearHoverInformation()));
111 applyViewProperties(url
);
112 m_topLayout
->addWidget(itemView());
115 DolphinView::~DolphinView()
119 const KUrl
& DolphinView::url() const
121 return m_controller
->url();
124 KUrl
DolphinView::rootUrl() const
126 return isColumnViewActive() ? m_dirLister
->url() : url();
129 void DolphinView::setActive(bool active
)
131 if (active
== m_active
) {
137 QColor color
= KColorScheme(KColorScheme::View
).background();
139 emit
urlChanged(url());
140 emit
selectionChanged(selectedItems());
145 QWidget
* viewport
= itemView()->viewport();
147 palette
.setColor(viewport
->backgroundRole(), color
);
148 viewport
->setPalette(palette
);
157 bool DolphinView::isActive() const
162 void DolphinView::setMode(Mode mode
)
164 if (mode
== m_mode
) {
165 return; // the wished mode is already set
170 if (isColumnViewActive()) {
171 // When changing the mode in the column view, it makes sense
172 // to go back to the root URL of the column view automatically.
173 // Otherwise there it would not be possible to turn off the column view
174 // without focusing the first column.
175 setUrl(m_dirLister
->url());
176 m_controller
->setUrl(m_dirLister
->url());
179 ViewProperties
props(url());
180 props
.setViewMode(m_mode
);
183 startDirLister(url());
188 DolphinView::Mode
DolphinView::mode() const
193 void DolphinView::setShowPreview(bool show
)
195 ViewProperties
props(url());
196 props
.setShowPreview(show
);
198 m_controller
->setShowPreview(show
);
199 emit
showPreviewChanged();
201 startDirLister(url(), true);
204 bool DolphinView::showPreview() const
206 return m_controller
->showPreview();
209 void DolphinView::setShowHiddenFiles(bool show
)
211 if (m_dirLister
->showingDotFiles() == show
) {
215 ViewProperties
props(url());
216 props
.setShowHiddenFiles(show
);
218 m_dirLister
->setShowingDotFiles(show
);
219 emit
showHiddenFilesChanged();
221 startDirLister(url(), true);
224 bool DolphinView::showHiddenFiles() const
226 return m_dirLister
->showingDotFiles();
229 void DolphinView::setCategorizedSorting(bool categorized
)
231 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
235 Q_ASSERT(m_iconsView
!= 0);
237 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
238 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
240 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
241 m_iconsView
->setItemCategorizer(0);
245 ViewProperties
props(url());
246 props
.setCategorizedSorting(categorized
);
249 emit
categorizedSortingChanged();
252 bool DolphinView::categorizedSorting() const
254 if (!supportsCategorizedSorting()) {
258 Q_ASSERT(m_iconsView
!= 0);
259 return m_iconsView
->itemCategorizer() != 0;
262 bool DolphinView::supportsCategorizedSorting() const
264 return m_iconsView
!= 0;
267 void DolphinView::selectAll()
269 selectAll(QItemSelectionModel::Select
);
272 void DolphinView::invertSelection()
274 selectAll(QItemSelectionModel::Toggle
);
277 bool DolphinView::hasSelection() const
279 return itemView()->selectionModel()->hasSelection();
282 void DolphinView::clearSelection()
284 itemView()->selectionModel()->clear();
287 KFileItemList
DolphinView::selectedItems() const
289 const QAbstractItemView
* view
= itemView();
291 // Our view has a selection, we will map them back to the DirModel
292 // and then fill the KFileItemList.
293 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
295 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
296 KFileItemList itemList
;
298 const QModelIndexList indexList
= selection
.indexes();
299 QModelIndexList::const_iterator end
= indexList
.end();
300 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
301 Q_ASSERT((*it
).isValid());
303 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
305 itemList
.append(item
);
312 KUrl::List
DolphinView::selectedUrls() const
316 const KFileItemList list
= selectedItems();
317 KFileItemList::const_iterator it
= list
.begin();
318 const KFileItemList::const_iterator end
= list
.end();
320 KFileItem
* item
= *it
;
321 urls
.append(item
->url());
328 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
330 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
331 return m_dirModel
->itemForIndex(dirModelIndex
);
334 void DolphinView::setContentsPosition(int x
, int y
)
336 QAbstractItemView
* view
= itemView();
337 view
->horizontalScrollBar()->setValue(x
);
338 view
->verticalScrollBar()->setValue(y
);
340 m_loadingDirectory
= false;
343 QPoint
DolphinView::contentsPosition() const
345 const int x
= itemView()->horizontalScrollBar()->value();
346 const int y
= itemView()->verticalScrollBar()->value();
350 void DolphinView::zoomIn()
352 m_controller
->triggerZoomIn();
355 void DolphinView::zoomOut()
357 m_controller
->triggerZoomOut();
360 bool DolphinView::isZoomInPossible() const
362 return m_controller
->isZoomInPossible();
365 bool DolphinView::isZoomOutPossible() const
367 return m_controller
->isZoomOutPossible();
370 void DolphinView::setSorting(Sorting sorting
)
372 if (sorting
!= this->sorting()) {
373 updateSorting(sorting
);
377 DolphinView::Sorting
DolphinView::sorting() const
379 return m_proxyModel
->sorting();
382 void DolphinView::setSortOrder(Qt::SortOrder order
)
384 if (sortOrder() != order
) {
385 updateSortOrder(order
);
389 Qt::SortOrder
DolphinView::sortOrder() const
391 return m_proxyModel
->sortOrder();
394 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
396 ViewProperties
props(url());
397 props
.setAdditionalInfo(info
);
399 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
400 m_fileItemDelegate
->setAdditionalInformation(info
);
402 emit
additionalInfoChanged(info
);
403 startDirLister(url(), true);
406 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
408 return m_fileItemDelegate
->additionalInformation();
411 void DolphinView::reload()
414 startDirLister(url(), true);
417 void DolphinView::refresh()
420 applyViewProperties(m_controller
->url());
424 void DolphinView::setUrl(const KUrl
& url
)
426 if (m_controller
->url() == url
) {
430 m_controller
->setUrl(url
);
432 applyViewProperties(url
);
435 emit
urlChanged(url
);
438 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
440 QWidget::mouseReleaseEvent(event
);
443 void DolphinView::activate()
448 void DolphinView::triggerItem(const QModelIndex
& index
)
450 if (!isValidNameIndex(index
)) {
452 showHoverInformation(index
);
456 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
457 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
458 // items are selected by the user, hence don't trigger the
459 // item specified by 'index'
463 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
468 // Prefer the local path over the URL. This assures that the
469 // volume space information is correct. Assuming that the URL is media:/sda1,
470 // and the local path is /windows/C: For the URL the space info is related
471 // to the root partition (and hence wrong) and for the local path the space
472 // info is related to the windows partition (-> correct).
473 const QString
localPath(item
->localPath());
475 if (localPath
.isEmpty()) {
483 } else if (item
->isFile()) {
484 // allow to browse through ZIP and tar files
485 KMimeType::Ptr mime
= item
->mimeTypePtr();
486 if (mime
->is("application/zip")) {
487 url
.setProtocol("zip");
489 } else if (mime
->is("application/x-tar") ||
490 mime
->is("application/x-tarz") ||
491 mime
->is("application/x-bzip-compressed-tar") ||
492 mime
->is("application/x-compressed-tar") ||
493 mime
->is("application/x-tzo")) {
494 url
.setProtocol("tar");
504 void DolphinView::generatePreviews(const KFileItemList
& items
)
506 if (m_controller
->showPreview()) {
508 // Must turn QList<KFileItem *> to QList<KFileItem>...
509 QList
<KFileItem
> itemsToPreview
;
510 foreach( KFileItem
* it
, items
)
511 itemsToPreview
.append( *it
);
513 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
514 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
515 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
519 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
521 Q_ASSERT(!item
.isNull());
522 if (item
.url().directory() != m_dirLister
->url().path()) {
523 // the preview job is still working on items of an older URL, hence
524 // the item is not part of the directory model anymore
528 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
529 if (idx
.isValid() && (idx
.column() == 0)) {
530 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
531 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
532 KIconEffect iconEffect
;
533 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
534 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
536 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
541 void DolphinView::emitSelectionChangedSignal()
543 emit
selectionChanged(DolphinView::selectedItems());
546 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
548 if (!url
.isValid()) {
549 const QString
location(url
.pathOrUrl());
550 if (location
.isEmpty()) {
551 emit
errorMessage(i18n("The location is empty."));
553 emit
errorMessage(i18n("The location '%1' is invalid.", location
));
558 m_cutItemsCache
.clear();
559 m_loadingDirectory
= true;
564 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
565 m_initializeColumnView
= false;
571 const KUrl
& dirListerUrl
= m_dirLister
->url();
572 if (dirListerUrl
.isValid()) {
573 const KUrl::List dirs
= m_dirLister
->directories();
576 m_dirLister
->updateDirectory(url
);
580 } else if (m_dirLister
->directories().contains(url
)) {
581 // The dir lister contains the directory already, so
582 // KDirLister::openUrl() may not been invoked twice.
583 m_dirLister
->updateDirectory(url
);
586 const KUrl
& dirListerUrl
= m_dirLister
->url();
587 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
588 // The current URL is not a child of the dir lister
589 // URL. This may happen when e. g. a bookmark has been selected
590 // and hence the view must be reset.
597 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
601 void DolphinView::applyViewProperties(const KUrl
& url
)
603 const ViewProperties
props(url
);
605 const Mode mode
= props
.viewMode();
606 bool changeMode
= (m_mode
!= mode
);
607 if (changeMode
&& isColumnViewActive()) {
608 // The column view is active. Only change the
609 // mode if the current URL is no child of the column view.
610 if (m_dirLister
->url().isParentOf(url
)) {
620 if (m_mode
== ColumnView
) {
621 // The mode has been changed to the Column View. When starting the dir
622 // lister with DolphinView::startDirLister() it is important to give a
623 // hint that the dir lister may not keep the current directory
624 // although this is the default for showing a hierarchy.
625 m_initializeColumnView
= true;
628 if (itemView() == 0) {
631 Q_ASSERT(itemView() != 0);
632 Q_ASSERT(m_fileItemDelegate
!= 0);
634 const bool showHiddenFiles
= props
.showHiddenFiles();
635 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
636 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
637 emit
showHiddenFilesChanged();
640 const bool categorized
= props
.categorizedSorting();
641 if (categorized
!= categorizedSorting()) {
642 if (supportsCategorizedSorting()) {
643 Q_ASSERT(m_iconsView
!= 0);
645 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
646 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
648 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
649 m_iconsView
->setItemCategorizer(0);
653 emit
categorizedSortingChanged();
656 const DolphinView::Sorting sorting
= props
.sorting();
657 if (sorting
!= m_proxyModel
->sorting()) {
658 m_proxyModel
->setSorting(sorting
);
659 emit
sortingChanged(sorting
);
662 const Qt::SortOrder sortOrder
= props
.sortOrder();
663 if (sortOrder
!= m_proxyModel
->sortOrder()) {
664 m_proxyModel
->setSortOrder(sortOrder
);
665 emit
sortOrderChanged(sortOrder
);
668 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
669 if (info
!= m_fileItemDelegate
->additionalInformation()) {
670 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
671 m_fileItemDelegate
->setAdditionalInformation(info
);
672 emit
additionalInfoChanged(info
);
675 const bool showPreview
= props
.showPreview();
676 if (showPreview
!= m_controller
->showPreview()) {
677 m_controller
->setShowPreview(showPreview
);
678 emit
showPreviewChanged();
682 void DolphinView::changeSelection(const KFileItemList
& selection
)
685 if (selection
.isEmpty()) {
688 const KUrl
& baseUrl
= url();
690 QItemSelection new_selection
;
691 foreach(KFileItem
* item
, selection
) {
692 url
= item
->url().upUrl();
693 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
694 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
695 new_selection
.select(index
, index
);
698 itemView()->selectionModel()->select(new_selection
,
699 QItemSelectionModel::ClearAndSelect
700 | QItemSelectionModel::Current
);
703 void DolphinView::openContextMenu(const QPoint
& pos
)
707 const QModelIndex index
= itemView()->indexAt(pos
);
708 if (isValidNameIndex(index
)) {
709 item
= fileItem(index
);
712 emit
requestContextMenu(item
, url());
715 void DolphinView::dropUrls(const KUrl::List
& urls
,
716 const QModelIndex
& index
,
719 KFileItem
* directory
= 0;
720 if (isValidNameIndex(index
)) {
721 KFileItem
* item
= fileItem(index
);
724 // the URLs are dropped above a directory
729 if ((directory
== 0) && (source
== itemView())) {
730 // The dropping is done into the same viewport where
731 // the dragging has been started. Just ignore this...
735 const KUrl
& destination
= (directory
== 0) ?
736 url() : directory
->url();
737 dropUrls(urls
, destination
);
740 void DolphinView::dropUrls(const KUrl::List
& urls
,
741 const KUrl
& destination
)
743 emit
urlsDropped(urls
, destination
);
746 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
748 ViewProperties
props(url());
749 props
.setSorting(sorting
);
751 m_proxyModel
->setSorting(sorting
);
753 emit
sortingChanged(sorting
);
756 void DolphinView::updateSortOrder(Qt::SortOrder order
)
758 ViewProperties
props(url());
759 props
.setSortOrder(order
);
761 m_proxyModel
->setSortOrder(order
);
763 emit
sortOrderChanged(order
);
766 void DolphinView::emitContentsMoved()
768 // only emit the contents moved signal if:
769 // - no directory loading is ongoing (this would reset the contents position
771 // - if the Column View is active: the column view does an automatic
772 // positioning during the loading operation, which must be remembered
773 if (!m_loadingDirectory
|| isColumnViewActive()) {
774 const QPoint
pos(contentsPosition());
775 emit
contentsMoved(pos
.x(), pos
.y());
779 void DolphinView::updateCutItems()
781 // restore the icons of all previously selected items to the
783 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
784 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
786 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
787 if (index
.isValid()) {
788 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
792 m_cutItemsCache
.clear();
794 // ... and apply an item effect to all currently cut items
795 applyCutItemEffect();
798 void DolphinView::showHoverInformation(const QModelIndex
& index
)
800 if (hasSelection()) {
804 const KFileItem
* item
= fileItem(index
);
806 emit
requestItemInfo(*item
);
810 void DolphinView::clearHoverInformation()
812 emit
requestItemInfo(KFileItem());
816 void DolphinView::createView()
818 // delete current view
819 QAbstractItemView
* view
= itemView();
821 m_topLayout
->removeWidget(view
);
823 if (view
== m_iconsView
) {
824 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
825 m_iconsView
->setItemCategorizer(0);
833 m_fileItemDelegate
= 0;
836 Q_ASSERT(m_iconsView
== 0);
837 Q_ASSERT(m_detailsView
== 0);
838 Q_ASSERT(m_columnView
== 0);
840 // ... and recreate it representing the current mode
843 m_iconsView
= new DolphinIconsView(this, m_controller
);
848 m_detailsView
= new DolphinDetailsView(this, m_controller
);
849 view
= m_detailsView
;
853 m_columnView
= new DolphinColumnView(this, m_controller
);
860 m_fileItemDelegate
= new KFileItemDelegate(view
);
861 view
->setItemDelegate(m_fileItemDelegate
);
863 view
->setModel(m_proxyModel
);
864 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
866 new KMimeTypeResolver(view
, m_dirModel
);
867 m_topLayout
->insertWidget(1, view
);
869 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
870 this, SLOT(emitSelectionChangedSignal()));
871 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
872 this, SLOT(emitContentsMoved()));
873 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
874 this, SLOT(emitContentsMoved()));
877 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
879 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
880 const QAbstractItemModel
* itemModel
= selectionModel
->model();
882 const QModelIndex topLeft
= itemModel
->index(0, 0);
883 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
884 itemModel
->columnCount() - 1);
886 QItemSelection
selection(topLeft
, bottomRight
);
887 selectionModel
->select(selection
, flags
);
890 QAbstractItemView
* DolphinView::itemView() const
892 if (m_detailsView
!= 0) {
893 return m_detailsView
;
894 } else if (m_columnView
!= 0) {
901 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
903 return index
.isValid() && (index
.column() == KDirModel::Name
);
906 bool DolphinView::isCutItem(const KFileItem
& item
) const
908 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
909 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
911 const KUrl
& itemUrl
= item
.url();
912 KUrl::List::const_iterator it
= cutUrls
.begin();
913 const KUrl::List::const_iterator end
= cutUrls
.end();
915 if (*it
== itemUrl
) {
924 void DolphinView::applyCutItemEffect()
926 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
927 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
931 KFileItemList
items(m_dirLister
->items());
932 KFileItemList::const_iterator it
= items
.begin();
933 const KFileItemList::const_iterator end
= items
.end();
935 KFileItem
* item
= *it
;
936 if (isCutItem(*item
)) {
937 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
938 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
939 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
940 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
941 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
942 QPixmap pixmap
= icon
.pixmap(128, 128);
944 // remember current pixmap for the item to be able
945 // to restore it when other items get cut
947 cutItem
.url
= item
->url();
948 cutItem
.pixmap
= pixmap
;
949 m_cutItemsCache
.append(cutItem
);
951 // apply icon effect to the cut item
952 KIconEffect iconEffect
;
953 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
954 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
961 #include "dolphinview.moc"