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 const KUrl viewPropsUrl
= viewPropertiesUrl();
180 ViewProperties
props(viewPropsUrl
);
181 props
.setViewMode(m_mode
);
184 startDirLister(viewPropsUrl
);
189 DolphinView::Mode
DolphinView::mode() const
194 void DolphinView::setShowPreview(bool show
)
196 const KUrl viewPropsUrl
= viewPropertiesUrl();
197 ViewProperties
props(viewPropsUrl
);
198 props
.setShowPreview(show
);
200 m_controller
->setShowPreview(show
);
201 emit
showPreviewChanged();
203 startDirLister(viewPropsUrl
, true);
206 bool DolphinView::showPreview() const
208 return m_controller
->showPreview();
211 void DolphinView::setShowHiddenFiles(bool show
)
213 if (m_dirLister
->showingDotFiles() == show
) {
217 const KUrl viewPropsUrl
= viewPropertiesUrl();
218 ViewProperties
props(viewPropsUrl
);
219 props
.setShowHiddenFiles(show
);
221 m_dirLister
->setShowingDotFiles(show
);
222 emit
showHiddenFilesChanged();
224 startDirLister(viewPropsUrl
, 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(viewPropertiesUrl());
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 itemView()->selectAll();
275 void DolphinView::invertSelection()
277 if (isColumnViewActive()) {
278 // In opposite to QAbstractItemView::selectAll() there is no virtual method
279 // for adjusting the invertion of a selection. As the generic approach by using
280 // the selection model does not work for the column view, we delegate this task:
281 m_columnView
->invertSelection();
283 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
284 const QAbstractItemModel
* itemModel
= selectionModel
->model();
286 const QModelIndex topLeft
= itemModel
->index(0, 0);
287 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
288 itemModel
->columnCount() - 1);
290 QItemSelection
selection(topLeft
, bottomRight
);
291 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
295 bool DolphinView::hasSelection() const
297 return itemView()->selectionModel()->hasSelection();
300 void DolphinView::clearSelection()
302 itemView()->selectionModel()->clear();
305 KFileItemList
DolphinView::selectedItems() const
307 const QAbstractItemView
* view
= itemView();
309 // Our view has a selection, we will map them back to the DirModel
310 // and then fill the KFileItemList.
311 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
313 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
314 KFileItemList itemList
;
316 const QModelIndexList indexList
= selection
.indexes();
317 QModelIndexList::const_iterator end
= indexList
.end();
318 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
319 Q_ASSERT((*it
).isValid());
321 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
323 itemList
.append(item
);
330 KUrl::List
DolphinView::selectedUrls() const
334 const KFileItemList list
= selectedItems();
335 KFileItemList::const_iterator it
= list
.begin();
336 const KFileItemList::const_iterator end
= list
.end();
338 KFileItem
* item
= *it
;
339 urls
.append(item
->url());
346 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
348 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
349 return m_dirModel
->itemForIndex(dirModelIndex
);
352 void DolphinView::setContentsPosition(int x
, int y
)
354 QAbstractItemView
* view
= itemView();
355 view
->horizontalScrollBar()->setValue(x
);
356 view
->verticalScrollBar()->setValue(y
);
358 m_loadingDirectory
= false;
361 QPoint
DolphinView::contentsPosition() const
363 const int x
= itemView()->horizontalScrollBar()->value();
364 const int y
= itemView()->verticalScrollBar()->value();
368 void DolphinView::zoomIn()
370 m_controller
->triggerZoomIn();
373 void DolphinView::zoomOut()
375 m_controller
->triggerZoomOut();
378 bool DolphinView::isZoomInPossible() const
380 return m_controller
->isZoomInPossible();
383 bool DolphinView::isZoomOutPossible() const
385 return m_controller
->isZoomOutPossible();
388 void DolphinView::setSorting(Sorting sorting
)
390 if (sorting
!= this->sorting()) {
391 updateSorting(sorting
);
395 DolphinView::Sorting
DolphinView::sorting() const
397 return m_proxyModel
->sorting();
400 void DolphinView::setSortOrder(Qt::SortOrder order
)
402 if (sortOrder() != order
) {
403 updateSortOrder(order
);
407 Qt::SortOrder
DolphinView::sortOrder() const
409 return m_proxyModel
->sortOrder();
412 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
414 const KUrl viewPropsUrl
= viewPropertiesUrl();
415 ViewProperties
props(viewPropsUrl
);
416 props
.setAdditionalInfo(info
);
418 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
419 m_fileItemDelegate
->setAdditionalInformation(info
);
421 emit
additionalInfoChanged(info
);
422 startDirLister(viewPropsUrl
, true);
425 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
427 return m_fileItemDelegate
->additionalInformation();
430 void DolphinView::reload()
433 startDirLister(url(), true);
436 void DolphinView::refresh()
439 applyViewProperties(m_controller
->url());
443 void DolphinView::setUrl(const KUrl
& url
)
445 if (m_controller
->url() == url
) {
449 m_controller
->setUrl(url
);
451 applyViewProperties(url
);
454 emit
urlChanged(url
);
457 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
459 QWidget::mouseReleaseEvent(event
);
462 void DolphinView::activate()
467 void DolphinView::triggerItem(const QModelIndex
& index
)
469 if (!isValidNameIndex(index
)) {
471 showHoverInformation(index
);
475 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
476 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
477 // items are selected by the user, hence don't trigger the
478 // item specified by 'index'
482 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
487 // The stuff below should be moved to ViewContainer and be just a signal?
489 // Prefer the local path over the URL.
491 KUrl url
= item
->mostLocalUrl(isLocal
);
495 } else if (item
->isFile()) {
496 // allow to browse through ZIP and tar files
497 KMimeType::Ptr mime
= item
->mimeTypePtr();
498 if (mime
->is("application/zip")) {
499 url
.setProtocol("zip");
501 } else if (mime
->is("application/x-tar") ||
502 mime
->is("application/x-tarz") ||
503 mime
->is("application/x-bzip-compressed-tar") ||
504 mime
->is("application/x-compressed-tar") ||
505 mime
->is("application/x-tzo")) {
506 url
.setProtocol("tar");
516 void DolphinView::generatePreviews(const KFileItemList
& items
)
518 if (m_controller
->showPreview()) {
520 // Must turn QList<KFileItem *> to QList<KFileItem>...
521 QList
<KFileItem
> itemsToPreview
;
522 foreach( KFileItem
* it
, items
)
523 itemsToPreview
.append( *it
);
525 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
526 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
527 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
531 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
533 Q_ASSERT(!item
.isNull());
534 if (item
.url().directory() != m_dirLister
->url().path()) {
535 // the preview job is still working on items of an older URL, hence
536 // the item is not part of the directory model anymore
540 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
541 if (idx
.isValid() && (idx
.column() == 0)) {
542 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
543 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
544 KIconEffect iconEffect
;
545 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
546 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
548 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
553 void DolphinView::emitSelectionChangedSignal()
555 emit
selectionChanged(DolphinView::selectedItems());
558 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
560 if (!url
.isValid()) {
561 const QString
location(url
.pathOrUrl());
562 if (location
.isEmpty()) {
563 emit
errorMessage(i18nc("@info:status", "The location is empty."));
565 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
570 m_cutItemsCache
.clear();
571 m_loadingDirectory
= true;
576 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
577 m_initializeColumnView
= false;
583 const KUrl
& dirListerUrl
= m_dirLister
->url();
584 if (dirListerUrl
.isValid()) {
585 const KUrl::List dirs
= m_dirLister
->directories();
588 m_dirLister
->updateDirectory(url
);
592 } else if (m_dirLister
->directories().contains(url
)) {
593 // The dir lister contains the directory already, so
594 // KDirLister::openUrl() may not been invoked twice.
595 m_dirLister
->updateDirectory(url
);
598 const KUrl
& dirListerUrl
= m_dirLister
->url();
599 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
600 // The current URL is not a child of the dir lister
601 // URL. This may happen when e. g. a bookmark has been selected
602 // and hence the view must be reset.
609 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
613 KUrl
DolphinView::viewPropertiesUrl() const
615 if (isColumnViewActive()) {
616 return m_dirLister
->url();
622 void DolphinView::applyViewProperties(const KUrl
& url
)
624 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
625 // The column view is active, hence don't apply the view properties
626 // of sub directories (represented by columns) to the view. The
627 // view always represents the properties of the first column.
631 const ViewProperties
props(url
);
633 const Mode mode
= props
.viewMode();
634 if (m_mode
!= mode
) {
639 if (m_mode
== ColumnView
) {
640 // The mode has been changed to the Column View. When starting the dir
641 // lister with DolphinView::startDirLister() it is important to give a
642 // hint that the dir lister may not keep the current directory
643 // although this is the default for showing a hierarchy.
644 m_initializeColumnView
= true;
647 if (itemView() == 0) {
650 Q_ASSERT(itemView() != 0);
651 Q_ASSERT(m_fileItemDelegate
!= 0);
653 const bool showHiddenFiles
= props
.showHiddenFiles();
654 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
655 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
656 emit
showHiddenFilesChanged();
659 const bool categorized
= props
.categorizedSorting();
660 if (categorized
!= categorizedSorting()) {
661 if (supportsCategorizedSorting()) {
662 Q_ASSERT(m_iconsView
!= 0);
664 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
665 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
667 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
668 m_iconsView
->setItemCategorizer(0);
672 emit
categorizedSortingChanged();
675 const DolphinView::Sorting sorting
= props
.sorting();
676 if (sorting
!= m_proxyModel
->sorting()) {
677 m_proxyModel
->setSorting(sorting
);
678 emit
sortingChanged(sorting
);
681 const Qt::SortOrder sortOrder
= props
.sortOrder();
682 if (sortOrder
!= m_proxyModel
->sortOrder()) {
683 m_proxyModel
->setSortOrder(sortOrder
);
684 emit
sortOrderChanged(sortOrder
);
687 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
688 if (info
!= m_fileItemDelegate
->additionalInformation()) {
689 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
690 m_fileItemDelegate
->setAdditionalInformation(info
);
691 emit
additionalInfoChanged(info
);
694 const bool showPreview
= props
.showPreview();
695 if (showPreview
!= m_controller
->showPreview()) {
696 m_controller
->setShowPreview(showPreview
);
697 emit
showPreviewChanged();
701 void DolphinView::changeSelection(const KFileItemList
& selection
)
704 if (selection
.isEmpty()) {
707 const KUrl
& baseUrl
= url();
709 QItemSelection new_selection
;
710 foreach(KFileItem
* item
, selection
) {
711 url
= item
->url().upUrl();
712 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
713 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
714 new_selection
.select(index
, index
);
717 itemView()->selectionModel()->select(new_selection
,
718 QItemSelectionModel::ClearAndSelect
719 | QItemSelectionModel::Current
);
722 void DolphinView::openContextMenu(const QPoint
& pos
)
726 const QModelIndex index
= itemView()->indexAt(pos
);
727 if (isValidNameIndex(index
)) {
728 item
= fileItem(index
);
731 emit
requestContextMenu(item
, url());
734 void DolphinView::dropUrls(const KUrl::List
& urls
,
735 const QModelIndex
& index
,
738 KFileItem
* directory
= 0;
739 if (isValidNameIndex(index
)) {
740 KFileItem
* item
= fileItem(index
);
743 // the URLs are dropped above a directory
748 if ((directory
== 0) && (source
== itemView())) {
749 // The dropping is done into the same viewport where
750 // the dragging has been started. Just ignore this...
754 const KUrl
& destination
= (directory
== 0) ?
755 url() : directory
->url();
756 dropUrls(urls
, destination
);
759 void DolphinView::dropUrls(const KUrl::List
& urls
,
760 const KUrl
& destination
)
762 emit
urlsDropped(urls
, destination
);
765 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
767 ViewProperties
props(viewPropertiesUrl());
768 props
.setSorting(sorting
);
770 m_proxyModel
->setSorting(sorting
);
772 emit
sortingChanged(sorting
);
775 void DolphinView::updateSortOrder(Qt::SortOrder order
)
777 ViewProperties
props(viewPropertiesUrl());
778 props
.setSortOrder(order
);
780 m_proxyModel
->setSortOrder(order
);
782 emit
sortOrderChanged(order
);
785 void DolphinView::emitContentsMoved()
787 // only emit the contents moved signal if:
788 // - no directory loading is ongoing (this would reset the contents position
790 // - if the Column View is active: the column view does an automatic
791 // positioning during the loading operation, which must be remembered
792 if (!m_loadingDirectory
|| isColumnViewActive()) {
793 const QPoint
pos(contentsPosition());
794 emit
contentsMoved(pos
.x(), pos
.y());
798 void DolphinView::updateCutItems()
800 // restore the icons of all previously selected items to the
802 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
803 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
805 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
806 if (index
.isValid()) {
807 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
811 m_cutItemsCache
.clear();
813 // ... and apply an item effect to all currently cut items
814 applyCutItemEffect();
817 void DolphinView::showHoverInformation(const QModelIndex
& index
)
819 if (hasSelection()) {
823 const KFileItem
* item
= fileItem(index
);
825 emit
requestItemInfo(*item
);
829 void DolphinView::clearHoverInformation()
831 emit
requestItemInfo(KFileItem());
835 void DolphinView::createView()
837 // delete current view
838 QAbstractItemView
* view
= itemView();
840 m_topLayout
->removeWidget(view
);
842 if (view
== m_iconsView
) {
843 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
844 m_iconsView
->setItemCategorizer(0);
852 m_fileItemDelegate
= 0;
855 Q_ASSERT(m_iconsView
== 0);
856 Q_ASSERT(m_detailsView
== 0);
857 Q_ASSERT(m_columnView
== 0);
859 // ... and recreate it representing the current mode
862 m_iconsView
= new DolphinIconsView(this, m_controller
);
867 m_detailsView
= new DolphinDetailsView(this, m_controller
);
868 view
= m_detailsView
;
872 m_columnView
= new DolphinColumnView(this, m_controller
);
879 m_fileItemDelegate
= new KFileItemDelegate(view
);
880 view
->setItemDelegate(m_fileItemDelegate
);
882 view
->setModel(m_proxyModel
);
883 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
885 new KMimeTypeResolver(view
, m_dirModel
);
886 m_topLayout
->insertWidget(1, view
);
888 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
889 this, SLOT(emitSelectionChangedSignal()));
890 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
891 this, SLOT(emitContentsMoved()));
892 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
893 this, SLOT(emitContentsMoved()));
896 QAbstractItemView
* DolphinView::itemView() const
898 if (m_detailsView
!= 0) {
899 return m_detailsView
;
900 } else if (m_columnView
!= 0) {
907 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
909 return index
.isValid() && (index
.column() == KDirModel::Name
);
912 bool DolphinView::isCutItem(const KFileItem
& item
) const
914 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
915 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
917 const KUrl
& itemUrl
= item
.url();
918 KUrl::List::const_iterator it
= cutUrls
.begin();
919 const KUrl::List::const_iterator end
= cutUrls
.end();
921 if (*it
== itemUrl
) {
930 void DolphinView::applyCutItemEffect()
932 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
933 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
937 KFileItemList
items(m_dirLister
->items());
938 KFileItemList::const_iterator it
= items
.begin();
939 const KFileItemList::const_iterator end
= items
.end();
941 KFileItem
* item
= *it
;
942 if (isCutItem(*item
)) {
943 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
944 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
945 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
946 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
947 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
948 QPixmap pixmap
= icon
.pixmap(128, 128);
950 // remember current pixmap for the item to be able
951 // to restore it when other items get cut
953 cutItem
.url
= item
->url();
954 cutItem
.pixmap
= pixmap
;
955 m_cutItemsCache
.append(cutItem
);
957 // apply icon effect to the cut item
958 KIconEffect iconEffect
;
959 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
960 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
967 #include "dolphinview.moc"