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 updateViewportColor();
145 bool DolphinView::isActive() const
150 void DolphinView::setMode(Mode mode
)
152 if (mode
== m_mode
) {
153 return; // the wished mode is already set
158 if (isColumnViewActive()) {
159 // When changing the mode in the column view, it makes sense
160 // to go back to the root URL of the column view automatically.
161 // Otherwise there it would not be possible to turn off the column view
162 // without focusing the first column.
163 setUrl(m_dirLister
->url());
164 m_controller
->setUrl(m_dirLister
->url());
167 const KUrl viewPropsUrl
= viewPropertiesUrl();
168 ViewProperties
props(viewPropsUrl
);
169 props
.setViewMode(m_mode
);
172 startDirLister(viewPropsUrl
);
177 DolphinView::Mode
DolphinView::mode() const
182 void DolphinView::setShowPreview(bool show
)
184 const KUrl viewPropsUrl
= viewPropertiesUrl();
185 ViewProperties
props(viewPropsUrl
);
186 props
.setShowPreview(show
);
188 m_controller
->setShowPreview(show
);
189 emit
showPreviewChanged();
191 startDirLister(viewPropsUrl
, true);
194 bool DolphinView::showPreview() const
196 return m_controller
->showPreview();
199 void DolphinView::setShowHiddenFiles(bool show
)
201 if (m_dirLister
->showingDotFiles() == show
) {
205 const KUrl viewPropsUrl
= viewPropertiesUrl();
206 ViewProperties
props(viewPropsUrl
);
207 props
.setShowHiddenFiles(show
);
209 m_dirLister
->setShowingDotFiles(show
);
210 emit
showHiddenFilesChanged();
212 startDirLister(viewPropsUrl
, true);
215 bool DolphinView::showHiddenFiles() const
217 return m_dirLister
->showingDotFiles();
220 void DolphinView::setCategorizedSorting(bool categorized
)
222 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
226 Q_ASSERT(m_iconsView
!= 0);
228 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
229 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
231 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
232 m_iconsView
->setItemCategorizer(0);
236 ViewProperties
props(viewPropertiesUrl());
237 props
.setCategorizedSorting(categorized
);
240 emit
categorizedSortingChanged();
243 bool DolphinView::categorizedSorting() const
245 if (!supportsCategorizedSorting()) {
249 Q_ASSERT(m_iconsView
!= 0);
250 return m_iconsView
->itemCategorizer() != 0;
253 bool DolphinView::supportsCategorizedSorting() const
255 return m_iconsView
!= 0;
258 void DolphinView::selectAll()
260 itemView()->selectAll();
263 void DolphinView::invertSelection()
265 if (isColumnViewActive()) {
266 // In opposite to QAbstractItemView::selectAll() there is no virtual method
267 // for adjusting the invertion of a selection. As the generic approach by using
268 // the selection model does not work for the column view, we delegate this task:
269 m_columnView
->invertSelection();
271 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
272 const QAbstractItemModel
* itemModel
= selectionModel
->model();
274 const QModelIndex topLeft
= itemModel
->index(0, 0);
275 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
276 itemModel
->columnCount() - 1);
278 QItemSelection
selection(topLeft
, bottomRight
);
279 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
283 bool DolphinView::hasSelection() const
285 return itemView()->selectionModel()->hasSelection();
288 void DolphinView::clearSelection()
290 itemView()->selectionModel()->clear();
293 KFileItemList
DolphinView::selectedItems() const
295 const QAbstractItemView
* view
= itemView();
297 // Our view has a selection, we will map them back to the DirModel
298 // and then fill the KFileItemList.
299 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
301 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
302 KFileItemList itemList
;
304 const QModelIndexList indexList
= selection
.indexes();
305 QModelIndexList::const_iterator end
= indexList
.end();
306 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
307 Q_ASSERT((*it
).isValid());
309 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
311 itemList
.append(item
);
318 KUrl::List
DolphinView::selectedUrls() const
322 const KFileItemList list
= selectedItems();
323 KFileItemList::const_iterator it
= list
.begin();
324 const KFileItemList::const_iterator end
= list
.end();
326 KFileItem
* item
= *it
;
327 urls
.append(item
->url());
334 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
336 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
337 return m_dirModel
->itemForIndex(dirModelIndex
);
340 void DolphinView::setContentsPosition(int x
, int y
)
342 QAbstractItemView
* view
= itemView();
343 view
->horizontalScrollBar()->setValue(x
);
344 view
->verticalScrollBar()->setValue(y
);
346 m_loadingDirectory
= false;
349 QPoint
DolphinView::contentsPosition() const
351 const int x
= itemView()->horizontalScrollBar()->value();
352 const int y
= itemView()->verticalScrollBar()->value();
356 void DolphinView::zoomIn()
358 m_controller
->triggerZoomIn();
361 void DolphinView::zoomOut()
363 m_controller
->triggerZoomOut();
366 bool DolphinView::isZoomInPossible() const
368 return m_controller
->isZoomInPossible();
371 bool DolphinView::isZoomOutPossible() const
373 return m_controller
->isZoomOutPossible();
376 void DolphinView::setSorting(Sorting sorting
)
378 if (sorting
!= this->sorting()) {
379 updateSorting(sorting
);
383 DolphinView::Sorting
DolphinView::sorting() const
385 return m_proxyModel
->sorting();
388 void DolphinView::setSortOrder(Qt::SortOrder order
)
390 if (sortOrder() != order
) {
391 updateSortOrder(order
);
395 Qt::SortOrder
DolphinView::sortOrder() const
397 return m_proxyModel
->sortOrder();
400 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
402 const KUrl viewPropsUrl
= viewPropertiesUrl();
403 ViewProperties
props(viewPropsUrl
);
404 props
.setAdditionalInfo(info
);
406 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
407 m_fileItemDelegate
->setAdditionalInformation(info
);
409 emit
additionalInfoChanged(info
);
410 startDirLister(viewPropsUrl
, true);
413 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
415 return m_fileItemDelegate
->additionalInformation();
418 void DolphinView::reload()
421 startDirLister(url(), true);
424 void DolphinView::refresh()
427 applyViewProperties(m_controller
->url());
429 updateViewportColor();
432 void DolphinView::setUrl(const KUrl
& url
)
434 if (m_controller
->url() == url
) {
438 m_controller
->setUrl(url
);
440 applyViewProperties(url
);
443 emit
urlChanged(url
);
446 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
448 QWidget::mouseReleaseEvent(event
);
451 void DolphinView::activate()
456 void DolphinView::triggerItem(const QModelIndex
& index
)
458 if (!isValidNameIndex(index
)) {
460 showHoverInformation(index
);
464 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
465 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
466 // items are selected by the user, hence don't trigger the
467 // item specified by 'index'
471 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
476 // The stuff below should be moved to ViewContainer and be just a signal?
478 // Prefer the local path over the URL.
480 KUrl url
= item
->mostLocalUrl(isLocal
);
484 } else if (item
->isFile()) {
485 // allow to browse through ZIP and tar files
486 KMimeType::Ptr mime
= item
->mimeTypePtr();
487 if (mime
->is("application/zip")) {
488 url
.setProtocol("zip");
490 } else if (mime
->is("application/x-tar") ||
491 mime
->is("application/x-tarz") ||
492 mime
->is("application/x-bzip-compressed-tar") ||
493 mime
->is("application/x-compressed-tar") ||
494 mime
->is("application/x-tzo")) {
495 url
.setProtocol("tar");
505 void DolphinView::generatePreviews(const KFileItemList
& items
)
507 if (m_controller
->showPreview()) {
509 // Must turn QList<KFileItem *> to QList<KFileItem>...
510 QList
<KFileItem
> itemsToPreview
;
511 foreach( KFileItem
* it
, items
)
512 itemsToPreview
.append( *it
);
514 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
515 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
516 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
520 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
522 Q_ASSERT(!item
.isNull());
523 if (item
.url().directory() != m_dirLister
->url().path()) {
524 // the preview job is still working on items of an older URL, hence
525 // the item is not part of the directory model anymore
529 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
530 if (idx
.isValid() && (idx
.column() == 0)) {
531 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
532 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
533 KIconEffect iconEffect
;
534 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
535 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
537 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
542 void DolphinView::emitSelectionChangedSignal()
544 emit
selectionChanged(DolphinView::selectedItems());
547 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
549 if (!url
.isValid()) {
550 const QString
location(url
.pathOrUrl());
551 if (location
.isEmpty()) {
552 emit
errorMessage(i18nc("@info:status", "The location is empty."));
554 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
559 m_cutItemsCache
.clear();
560 m_loadingDirectory
= true;
565 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
566 m_initializeColumnView
= false;
572 const KUrl
& dirListerUrl
= m_dirLister
->url();
573 if (dirListerUrl
.isValid()) {
574 const KUrl::List dirs
= m_dirLister
->directories();
577 m_dirLister
->updateDirectory(url
);
581 } else if (m_dirLister
->directories().contains(url
)) {
582 // The dir lister contains the directory already, so
583 // KDirLister::openUrl() may not been invoked twice.
584 m_dirLister
->updateDirectory(url
);
587 const KUrl
& dirListerUrl
= m_dirLister
->url();
588 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
589 // The current URL is not a child of the dir lister
590 // URL. This may happen when e. g. a bookmark has been selected
591 // and hence the view must be reset.
598 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
602 KUrl
DolphinView::viewPropertiesUrl() const
604 if (isColumnViewActive()) {
605 return m_dirLister
->url();
611 void DolphinView::applyViewProperties(const KUrl
& url
)
613 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
614 // The column view is active, hence don't apply the view properties
615 // of sub directories (represented by columns) to the view. The
616 // view always represents the properties of the first column.
620 const ViewProperties
props(url
);
622 const Mode mode
= props
.viewMode();
623 if (m_mode
!= mode
) {
628 if (m_mode
== ColumnView
) {
629 // The mode has been changed to the Column View. When starting the dir
630 // lister with DolphinView::startDirLister() it is important to give a
631 // hint that the dir lister may not keep the current directory
632 // although this is the default for showing a hierarchy.
633 m_initializeColumnView
= true;
636 if (itemView() == 0) {
639 Q_ASSERT(itemView() != 0);
640 Q_ASSERT(m_fileItemDelegate
!= 0);
642 const bool showHiddenFiles
= props
.showHiddenFiles();
643 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
644 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
645 emit
showHiddenFilesChanged();
648 const bool categorized
= props
.categorizedSorting();
649 if (categorized
!= categorizedSorting()) {
650 if (supportsCategorizedSorting()) {
651 Q_ASSERT(m_iconsView
!= 0);
653 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
654 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
656 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
657 m_iconsView
->setItemCategorizer(0);
661 emit
categorizedSortingChanged();
664 const DolphinView::Sorting sorting
= props
.sorting();
665 if (sorting
!= m_proxyModel
->sorting()) {
666 m_proxyModel
->setSorting(sorting
);
667 emit
sortingChanged(sorting
);
670 const Qt::SortOrder sortOrder
= props
.sortOrder();
671 if (sortOrder
!= m_proxyModel
->sortOrder()) {
672 m_proxyModel
->setSortOrder(sortOrder
);
673 emit
sortOrderChanged(sortOrder
);
676 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
677 if (info
!= m_fileItemDelegate
->additionalInformation()) {
678 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
679 m_fileItemDelegate
->setAdditionalInformation(info
);
680 emit
additionalInfoChanged(info
);
683 const bool showPreview
= props
.showPreview();
684 if (showPreview
!= m_controller
->showPreview()) {
685 m_controller
->setShowPreview(showPreview
);
686 emit
showPreviewChanged();
690 void DolphinView::changeSelection(const KFileItemList
& selection
)
693 if (selection
.isEmpty()) {
696 const KUrl
& baseUrl
= url();
698 QItemSelection new_selection
;
699 foreach(KFileItem
* item
, selection
) {
700 url
= item
->url().upUrl();
701 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
702 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
703 new_selection
.select(index
, index
);
706 itemView()->selectionModel()->select(new_selection
,
707 QItemSelectionModel::ClearAndSelect
708 | QItemSelectionModel::Current
);
711 void DolphinView::openContextMenu(const QPoint
& pos
)
715 const QModelIndex index
= itemView()->indexAt(pos
);
716 if (isValidNameIndex(index
)) {
717 item
= fileItem(index
);
720 emit
requestContextMenu(item
, url());
723 void DolphinView::dropUrls(const KUrl::List
& urls
,
724 const QModelIndex
& index
,
727 KFileItem
* directory
= 0;
728 if (isValidNameIndex(index
)) {
729 KFileItem
* item
= fileItem(index
);
732 // the URLs are dropped above a directory
737 if ((directory
== 0) && (source
== itemView())) {
738 // The dropping is done into the same viewport where
739 // the dragging has been started. Just ignore this...
743 const KUrl
& destination
= (directory
== 0) ?
744 url() : directory
->url();
745 dropUrls(urls
, destination
);
748 void DolphinView::dropUrls(const KUrl::List
& urls
,
749 const KUrl
& destination
)
751 emit
urlsDropped(urls
, destination
);
754 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
756 ViewProperties
props(viewPropertiesUrl());
757 props
.setSorting(sorting
);
759 m_proxyModel
->setSorting(sorting
);
761 emit
sortingChanged(sorting
);
764 void DolphinView::updateSortOrder(Qt::SortOrder order
)
766 ViewProperties
props(viewPropertiesUrl());
767 props
.setSortOrder(order
);
769 m_proxyModel
->setSortOrder(order
);
771 emit
sortOrderChanged(order
);
774 void DolphinView::emitContentsMoved()
776 // only emit the contents moved signal if:
777 // - no directory loading is ongoing (this would reset the contents position
779 // - if the Column View is active: the column view does an automatic
780 // positioning during the loading operation, which must be remembered
781 if (!m_loadingDirectory
|| isColumnViewActive()) {
782 const QPoint
pos(contentsPosition());
783 emit
contentsMoved(pos
.x(), pos
.y());
787 void DolphinView::updateCutItems()
789 // restore the icons of all previously selected items to the
791 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
792 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
794 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
795 if (index
.isValid()) {
796 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
800 m_cutItemsCache
.clear();
802 // ... and apply an item effect to all currently cut items
803 applyCutItemEffect();
806 void DolphinView::showHoverInformation(const QModelIndex
& index
)
808 if (hasSelection()) {
812 const KFileItem
* item
= fileItem(index
);
814 emit
requestItemInfo(*item
);
818 void DolphinView::clearHoverInformation()
820 emit
requestItemInfo(KFileItem());
824 void DolphinView::createView()
826 // delete current view
827 QAbstractItemView
* view
= itemView();
829 m_topLayout
->removeWidget(view
);
831 if (view
== m_iconsView
) {
832 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
833 m_iconsView
->setItemCategorizer(0);
841 m_fileItemDelegate
= 0;
844 Q_ASSERT(m_iconsView
== 0);
845 Q_ASSERT(m_detailsView
== 0);
846 Q_ASSERT(m_columnView
== 0);
848 // ... and recreate it representing the current mode
851 m_iconsView
= new DolphinIconsView(this, m_controller
);
856 m_detailsView
= new DolphinDetailsView(this, m_controller
);
857 view
= m_detailsView
;
861 m_columnView
= new DolphinColumnView(this, m_controller
);
868 m_fileItemDelegate
= new KFileItemDelegate(view
);
869 view
->setItemDelegate(m_fileItemDelegate
);
871 view
->setModel(m_proxyModel
);
872 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
874 new KMimeTypeResolver(view
, m_dirModel
);
875 m_topLayout
->insertWidget(1, view
);
877 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
878 this, SLOT(emitSelectionChangedSignal()));
879 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
880 this, SLOT(emitContentsMoved()));
881 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
882 this, SLOT(emitContentsMoved()));
885 QAbstractItemView
* DolphinView::itemView() const
887 if (m_detailsView
!= 0) {
888 return m_detailsView
;
889 } else if (m_columnView
!= 0) {
896 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
898 return index
.isValid() && (index
.column() == KDirModel::Name
);
901 bool DolphinView::isCutItem(const KFileItem
& item
) const
903 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
904 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
906 const KUrl
& itemUrl
= item
.url();
907 KUrl::List::const_iterator it
= cutUrls
.begin();
908 const KUrl::List::const_iterator end
= cutUrls
.end();
910 if (*it
== itemUrl
) {
919 void DolphinView::applyCutItemEffect()
921 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
922 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
926 KFileItemList
items(m_dirLister
->items());
927 KFileItemList::const_iterator it
= items
.begin();
928 const KFileItemList::const_iterator end
= items
.end();
930 KFileItem
* item
= *it
;
931 if (isCutItem(*item
)) {
932 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
933 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
934 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
935 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
936 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
937 QPixmap pixmap
= icon
.pixmap(128, 128);
939 // remember current pixmap for the item to be able
940 // to restore it when other items get cut
942 cutItem
.url
= item
->url();
943 cutItem
.pixmap
= pixmap
;
944 m_cutItemsCache
.append(cutItem
);
946 // apply icon effect to the cut item
947 KIconEffect iconEffect
;
948 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
949 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
956 void DolphinView::updateViewportColor()
958 QColor color
= KColorScheme(KColorScheme::View
).background();
960 emit
urlChanged(url());
961 emit
selectionChanged(selectedItems());
966 QWidget
* viewport
= itemView()->viewport();
968 palette
.setColor(viewport
->backgroundRole(), color
);
969 viewport
->setPalette(palette
);
972 #include "dolphinview.moc"