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 <kdirmodel.h>
32 #include <kdirlister.h>
33 #include <kfileitemdelegate.h>
34 #include <kglobalsettings.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
,
62 bool showHiddenFiles
) :
65 m_blockContentsMovedSignal(false),
66 m_initializeColumnView(false),
73 m_fileItemDelegate(0),
75 m_dirLister(dirLister
),
76 m_proxyModel(proxyModel
)
78 setFocusPolicy(Qt::StrongFocus
);
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setMargin(0);
83 QClipboard
* clipboard
= QApplication::clipboard();
84 connect(clipboard
, SIGNAL(dataChanged()),
85 this, SLOT(updateCutItems()));
87 connect(m_dirLister
, SIGNAL(completed()),
88 this, SLOT(restoreContentsPos()));
89 connect(m_dirLister
, SIGNAL(completed()),
90 this, SLOT(updateCutItems()));
91 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
92 this, SLOT(generatePreviews(const KFileItemList
&)));
94 m_controller
= new DolphinController(this);
95 m_controller
->setUrl(url
);
96 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
97 this, SLOT(openContextMenu(const QPoint
&)));
98 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
99 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
100 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
101 this, SLOT(updateSorting(DolphinView::Sorting
)));
102 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
103 this, SLOT(updateSortOrder(Qt::SortOrder
)));
104 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
105 this, SLOT(triggerItem(const QModelIndex
&)));
106 connect(m_controller
, SIGNAL(activated()),
107 this, SLOT(activate()));
108 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
109 this, SLOT(showHoverInformation(const QModelIndex
&)));
110 connect(m_controller
, SIGNAL(viewportEntered()),
111 this, SLOT(clearHoverInformation()));
114 m_topLayout
->addWidget(itemView());
117 DolphinView::~DolphinView()
121 const KUrl
& DolphinView::url() const
123 return m_controller
->url();
126 KUrl
DolphinView::rootUrl() const
128 return isColumnViewActive() ? m_dirLister
->url() : url();
131 void DolphinView::setActive(bool active
)
133 if (active
== m_active
) {
139 QColor color
= KGlobalSettings::baseColor();
141 emit
urlChanged(url());
142 emit
selectionChanged(selectedItems());
147 QWidget
* viewport
= itemView()->viewport();
149 palette
.setColor(viewport
->backgroundRole(), color
);
150 viewport
->setPalette(palette
);
159 bool DolphinView::isActive() const
164 void DolphinView::setMode(Mode mode
)
166 if (mode
== m_mode
) {
167 return; // the wished mode is already set
172 if (isColumnViewActive()) {
173 // When changing the mode in the column view, it makes sense
174 // to go back to the root URL of the column view automatically.
175 // Otherwise there it would not be possible to turn off the column view
176 // without focusing the first column.
177 // TODO: reactivate again after DolphinView/DolphinViewController split works
178 //setUrl(m_dirLister->url());
179 //m_controller->setUrl(m_dirLister->url());
182 ViewProperties
props(url());
183 props
.setViewMode(m_mode
);
186 startDirLister(url());
191 DolphinView::Mode
DolphinView::mode() const
196 void DolphinView::setShowPreview(bool show
)
198 ViewProperties
props(url());
199 props
.setShowPreview(show
);
201 m_controller
->setShowPreview(show
);
202 emit
showPreviewChanged();
204 startDirLister(url(), true);
207 bool DolphinView::showPreview() const
209 return m_controller
->showPreview();
212 void DolphinView::setShowHiddenFiles(bool show
)
214 if (m_dirLister
->showingDotFiles() == show
) {
218 ViewProperties
props(url());
219 props
.setShowHiddenFiles(show
);
221 m_dirLister
->setShowingDotFiles(show
);
222 emit
showHiddenFilesChanged();
224 startDirLister(url(), true);
227 bool DolphinView::showHiddenFiles() const
229 return m_dirLister
->showingDotFiles();
232 void DolphinView::setCategorizedSorting(bool categorized
)
234 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
238 Q_ASSERT(m_iconsView
!= 0);
240 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
241 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
243 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
244 m_iconsView
->setItemCategorizer(0);
248 ViewProperties
props(url());
249 props
.setCategorizedSorting(categorized
);
252 emit
categorizedSortingChanged();
255 bool DolphinView::categorizedSorting() const
257 if (!supportsCategorizedSorting()) {
261 Q_ASSERT(m_iconsView
!= 0);
262 return m_iconsView
->itemCategorizer() != 0;
265 bool DolphinView::supportsCategorizedSorting() const
267 return m_iconsView
!= 0;
270 void DolphinView::selectAll()
272 selectAll(QItemSelectionModel::Select
);
275 void DolphinView::invertSelection()
277 selectAll(QItemSelectionModel::Toggle
);
280 int DolphinView::contentsX() const
282 return itemView()->horizontalScrollBar()->value();
285 int DolphinView::contentsY() const
287 return itemView()->verticalScrollBar()->value();
290 void DolphinView::zoomIn()
292 m_controller
->triggerZoomIn();
295 void DolphinView::zoomOut()
297 m_controller
->triggerZoomOut();
300 bool DolphinView::isZoomInPossible() const
302 return m_controller
->isZoomInPossible();
305 bool DolphinView::isZoomOutPossible() const
307 return m_controller
->isZoomOutPossible();
310 void DolphinView::setSorting(Sorting sorting
)
312 if (sorting
!= this->sorting()) {
313 updateSorting(sorting
);
317 DolphinView::Sorting
DolphinView::sorting() const
319 return m_proxyModel
->sorting();
322 void DolphinView::setSortOrder(Qt::SortOrder order
)
324 if (sortOrder() != order
) {
325 updateSortOrder(order
);
329 Qt::SortOrder
DolphinView::sortOrder() const
331 return m_proxyModel
->sortOrder();
334 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
336 ViewProperties
props(url());
337 props
.setAdditionalInfo(info
);
339 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
340 m_fileItemDelegate
->setAdditionalInformation(info
);
342 emit
additionalInfoChanged(info
);
343 startDirLister(url(), true);
346 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
348 return m_fileItemDelegate
->additionalInformation();
351 bool DolphinView::hasSelection() const
353 return itemView()->selectionModel()->hasSelection();
356 void DolphinView::clearSelection()
358 itemView()->selectionModel()->clear();
361 KFileItemList
DolphinView::selectedItems() const
363 const QAbstractItemView
* view
= itemView();
365 // Our view has a selection, we will map them back to the DirModel
366 // and then fill the KFileItemList.
367 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
369 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
370 KFileItemList itemList
;
372 const QModelIndexList indexList
= selection
.indexes();
373 QModelIndexList::const_iterator end
= indexList
.end();
374 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
375 Q_ASSERT((*it
).isValid());
377 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
379 itemList
.append(item
);
386 KUrl::List
DolphinView::selectedUrls() const
390 const KFileItemList list
= selectedItems();
391 KFileItemList::const_iterator it
= list
.begin();
392 const KFileItemList::const_iterator end
= list
.end();
394 KFileItem
* item
= *it
;
395 urls
.append(item
->url());
402 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
404 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
405 return m_dirModel
->itemForIndex(dirModelIndex
);
408 void DolphinView::reload()
411 startDirLister(url(), true);
414 void DolphinView::refresh()
420 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
422 QWidget::mouseReleaseEvent(event
);
425 void DolphinView::activate()
430 void DolphinView::triggerItem(const QModelIndex
& index
)
432 if (!isValidNameIndex(index
)) {
434 showHoverInformation(index
);
438 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
439 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
440 // items are selected by the user, hence don't trigger the
441 // item specified by 'index'
445 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
450 // Prefer the local path over the URL. This assures that the
451 // volume space information is correct. Assuming that the URL is media:/sda1,
452 // and the local path is /windows/C: For the URL the space info is related
453 // to the root partition (and hence wrong) and for the local path the space
454 // info is related to the windows partition (-> correct).
455 const QString
localPath(item
->localPath());
457 if (localPath
.isEmpty()) {
465 } else if (item
->isFile()) {
466 // allow to browse through ZIP and tar files
467 KMimeType::Ptr mime
= item
->mimeTypePtr();
468 if (mime
->is("application/zip")) {
469 url
.setProtocol("zip");
471 } else if (mime
->is("application/x-tar") ||
472 mime
->is("application/x-tarz") ||
473 mime
->is("application/x-bzip-compressed-tar") ||
474 mime
->is("application/x-compressed-tar") ||
475 mime
->is("application/x-tzo")) {
476 url
.setProtocol("tar");
486 void DolphinView::generatePreviews(const KFileItemList
& items
)
488 if (m_controller
->showPreview()) {
490 // Must turn QList<KFileItem *> to QList<KFileItem>...
491 QList
<KFileItem
> itemsToPreview
;
492 foreach( KFileItem
* it
, items
)
493 itemsToPreview
.append( *it
);
495 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
496 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
497 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
501 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
503 Q_ASSERT(!item
.isNull());
504 if (item
.url().directory() != m_dirLister
->url().path()) {
505 // the preview job is still working on items of an older URL, hence
506 // the item is not part of the directory model anymore
510 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
511 if (idx
.isValid() && (idx
.column() == 0)) {
512 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
513 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
514 KIconEffect iconEffect
;
515 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
516 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
518 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
523 void DolphinView::restoreContentsPos()
525 m_blockContentsMovedSignal
= false;
526 if (!url().isEmpty()) {
527 QAbstractItemView
* view
= itemView();
528 // TODO #1: view->setCurrentItem(m_urlNavigator->currentFileName());
529 // TODO #2: temporary deactivated due to DolphinView/DolphinViewController split
530 //QPoint pos = m_urlNavigator->savedPosition();
532 view
->horizontalScrollBar()->setValue(pos
.x());
533 view
->verticalScrollBar()->setValue(pos
.y());
537 void DolphinView::emitSelectionChangedSignal()
539 emit
selectionChanged(DolphinView::selectedItems());
542 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
544 if (!url
.isValid()) {
545 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
547 //const QString location(url.pathOrUrl());
548 //if (location.isEmpty()) {
549 // m_statusBar->setMessage(i18n("The location is empty."), DolphinStatusBar::Error);
551 // m_statusBar->setMessage(i18n("The location '%1' is invalid.", location),
552 // DolphinStatusBar::Error);
557 m_cutItemsCache
.clear();
558 m_blockContentsMovedSignal
= 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::setUrl(const KUrl
& url
)
601 if (m_controller
->url() == url
) {
605 m_controller
->setUrl(url
);
607 const ViewProperties
props(url
);
609 const Mode mode
= props
.viewMode();
610 bool changeMode
= (m_mode
!= mode
);
611 if (changeMode
&& isColumnViewActive()) {
612 // The column view is active. Only change the
613 // mode if the current URL is no child of the column view.
614 if (m_dirLister
->url().isParentOf(url
)) {
624 if (m_mode
== ColumnView
) {
625 // The mode has been changed to the Column View. When starting the dir
626 // lister with DolphinView::startDirLister() it is important to give a
627 // hint that the dir lister may not keep the current directory
628 // although this is the default for showing a hierarchy.
629 m_initializeColumnView
= true;
633 const bool showHiddenFiles
= props
.showHiddenFiles();
634 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
635 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
636 emit
showHiddenFilesChanged();
639 const bool categorized
= props
.categorizedSorting();
640 if (categorized
!= categorizedSorting()) {
641 if (supportsCategorizedSorting()) {
642 Q_ASSERT(m_iconsView
!= 0);
644 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
645 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
647 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
648 m_iconsView
->setItemCategorizer(0);
652 emit
categorizedSortingChanged();
655 const DolphinView::Sorting sorting
= props
.sorting();
656 if (sorting
!= m_proxyModel
->sorting()) {
657 m_proxyModel
->setSorting(sorting
);
658 emit
sortingChanged(sorting
);
661 const Qt::SortOrder sortOrder
= props
.sortOrder();
662 if (sortOrder
!= m_proxyModel
->sortOrder()) {
663 m_proxyModel
->setSortOrder(sortOrder
);
664 emit
sortOrderChanged(sortOrder
);
667 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
668 if (info
!= m_fileItemDelegate
->additionalInformation()) {
669 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
670 m_fileItemDelegate
->setAdditionalInformation(info
);
671 emit
additionalInfoChanged(info
);
674 const bool showPreview
= props
.showPreview();
675 if (showPreview
!= m_controller
->showPreview()) {
676 m_controller
->setShowPreview(showPreview
);
677 emit
showPreviewChanged();
681 emit
urlChanged(url
);
683 // TODO: temporary deactivated due to DolphinView/DolphinViewController split
684 //m_statusBar->clear();
687 void DolphinView::changeSelection(const KFileItemList
& selection
)
690 if (selection
.isEmpty()) {
693 const KUrl
& baseUrl
= url();
695 QItemSelection new_selection
;
696 foreach(KFileItem
* item
, selection
) {
697 url
= item
->url().upUrl();
698 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
699 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
700 new_selection
.select(index
, index
);
703 itemView()->selectionModel()->select(new_selection
,
704 QItemSelectionModel::ClearAndSelect
705 | QItemSelectionModel::Current
);
708 void DolphinView::openContextMenu(const QPoint
& pos
)
712 const QModelIndex index
= itemView()->indexAt(pos
);
713 if (isValidNameIndex(index
)) {
714 item
= fileItem(index
);
717 emit
requestContextMenu(item
, url());
720 void DolphinView::dropUrls(const KUrl::List
& urls
,
721 const QModelIndex
& index
,
724 KFileItem
* directory
= 0;
725 if (isValidNameIndex(index
)) {
726 KFileItem
* item
= fileItem(index
);
729 // the URLs are dropped above a directory
734 if ((directory
== 0) && (source
== itemView())) {
735 // The dropping is done into the same viewport where
736 // the dragging has been started. Just ignore this...
740 const KUrl
& destination
= (directory
== 0) ?
741 url() : directory
->url();
742 dropUrls(urls
, destination
);
745 void DolphinView::dropUrls(const KUrl::List
& urls
,
746 const KUrl
& destination
)
748 emit
urlsDropped(urls
, destination
);
751 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
753 ViewProperties
props(url());
754 props
.setSorting(sorting
);
756 m_proxyModel
->setSorting(sorting
);
758 emit
sortingChanged(sorting
);
761 void DolphinView::updateSortOrder(Qt::SortOrder order
)
763 ViewProperties
props(url());
764 props
.setSortOrder(order
);
766 m_proxyModel
->setSortOrder(order
);
768 emit
sortOrderChanged(order
);
771 void DolphinView::emitContentsMoved()
773 if (!m_blockContentsMovedSignal
) {
774 emit
contentsMoved(contentsX(), contentsY());
778 void DolphinView::updateCutItems()
780 // restore the icons of all previously selected items to the
782 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
783 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
785 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
786 if (index
.isValid()) {
787 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
791 m_cutItemsCache
.clear();
793 // ... and apply an item effect to all currently cut items
794 applyCutItemEffect();
797 void DolphinView::showHoverInformation(const QModelIndex
& index
)
799 if (hasSelection()) {
803 const KFileItem
* item
= fileItem(index
);
805 emit
requestItemInfo(item
->url());
809 void DolphinView::clearHoverInformation()
811 emit
requestItemInfo(KUrl());
815 void DolphinView::createView()
817 // delete current view
818 QAbstractItemView
* view
= itemView();
820 m_topLayout
->removeWidget(view
);
822 if (view
== m_iconsView
) {
823 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
824 m_iconsView
->setItemCategorizer(0);
832 m_fileItemDelegate
= 0;
835 Q_ASSERT(m_iconsView
== 0);
836 Q_ASSERT(m_detailsView
== 0);
837 Q_ASSERT(m_columnView
== 0);
839 // ... and recreate it representing the current mode
842 m_iconsView
= new DolphinIconsView(this, m_controller
);
847 m_detailsView
= new DolphinDetailsView(this, m_controller
);
848 view
= m_detailsView
;
852 m_columnView
= new DolphinColumnView(this, m_controller
);
859 m_fileItemDelegate
= new KFileItemDelegate(view
);
860 view
->setItemDelegate(m_fileItemDelegate
);
862 view
->setModel(m_proxyModel
);
863 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
865 new KMimeTypeResolver(view
, m_dirModel
);
866 m_topLayout
->insertWidget(1, view
);
868 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
869 this, SLOT(emitSelectionChangedSignal()));
870 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
871 this, SLOT(emitContentsMoved()));
872 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
873 this, SLOT(emitContentsMoved()));
876 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
878 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
879 const QAbstractItemModel
* itemModel
= selectionModel
->model();
881 const QModelIndex topLeft
= itemModel
->index(0, 0);
882 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
883 itemModel
->columnCount() - 1);
885 QItemSelection
selection(topLeft
, bottomRight
);
886 selectionModel
->select(selection
, flags
);
889 QAbstractItemView
* DolphinView::itemView() const
891 if (m_detailsView
!= 0) {
892 return m_detailsView
;
893 } else if (m_columnView
!= 0) {
900 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
902 return index
.isValid() && (index
.column() == KDirModel::Name
);
905 bool DolphinView::isCutItem(const KFileItem
& item
) const
907 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
908 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
910 const KUrl
& itemUrl
= item
.url();
911 KUrl::List::const_iterator it
= cutUrls
.begin();
912 const KUrl::List::const_iterator end
= cutUrls
.end();
914 if (*it
== itemUrl
) {
923 void DolphinView::applyCutItemEffect()
925 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
926 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
930 KFileItemList
items(m_dirLister
->items());
931 KFileItemList::const_iterator it
= items
.begin();
932 const KFileItemList::const_iterator end
= items
.end();
934 KFileItem
* item
= *it
;
935 if (isCutItem(*item
)) {
936 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
937 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
938 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
939 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
940 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
941 QPixmap pixmap
= icon
.pixmap(128, 128);
943 // remember current pixmap for the item to be able
944 // to restore it when other items get cut
946 cutItem
.url
= item
->url();
947 cutItem
.pixmap
= pixmap
;
948 m_cutItemsCache
.append(cutItem
);
950 // apply icon effect to the cut item
951 KIconEffect iconEffect
;
952 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
953 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
960 #include "dolphinview.moc"