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 selectAll(QItemSelectionModel::Select
);
275 void DolphinView::invertSelection()
277 selectAll(QItemSelectionModel::Toggle
);
280 bool DolphinView::hasSelection() const
282 return itemView()->selectionModel()->hasSelection();
285 void DolphinView::clearSelection()
287 itemView()->selectionModel()->clear();
290 KFileItemList
DolphinView::selectedItems() const
292 const QAbstractItemView
* view
= itemView();
294 // Our view has a selection, we will map them back to the DirModel
295 // and then fill the KFileItemList.
296 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
298 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
299 KFileItemList itemList
;
301 const QModelIndexList indexList
= selection
.indexes();
302 QModelIndexList::const_iterator end
= indexList
.end();
303 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
304 Q_ASSERT((*it
).isValid());
306 KFileItem
* item
= m_dirModel
->itemForIndex(*it
);
308 itemList
.append(item
);
315 KUrl::List
DolphinView::selectedUrls() const
319 const KFileItemList list
= selectedItems();
320 KFileItemList::const_iterator it
= list
.begin();
321 const KFileItemList::const_iterator end
= list
.end();
323 KFileItem
* item
= *it
;
324 urls
.append(item
->url());
331 KFileItem
* DolphinView::fileItem(const QModelIndex index
) const
333 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
334 return m_dirModel
->itemForIndex(dirModelIndex
);
337 void DolphinView::setContentsPosition(int x
, int y
)
339 QAbstractItemView
* view
= itemView();
340 view
->horizontalScrollBar()->setValue(x
);
341 view
->verticalScrollBar()->setValue(y
);
343 m_loadingDirectory
= false;
346 QPoint
DolphinView::contentsPosition() const
348 const int x
= itemView()->horizontalScrollBar()->value();
349 const int y
= itemView()->verticalScrollBar()->value();
353 void DolphinView::zoomIn()
355 m_controller
->triggerZoomIn();
358 void DolphinView::zoomOut()
360 m_controller
->triggerZoomOut();
363 bool DolphinView::isZoomInPossible() const
365 return m_controller
->isZoomInPossible();
368 bool DolphinView::isZoomOutPossible() const
370 return m_controller
->isZoomOutPossible();
373 void DolphinView::setSorting(Sorting sorting
)
375 if (sorting
!= this->sorting()) {
376 updateSorting(sorting
);
380 DolphinView::Sorting
DolphinView::sorting() const
382 return m_proxyModel
->sorting();
385 void DolphinView::setSortOrder(Qt::SortOrder order
)
387 if (sortOrder() != order
) {
388 updateSortOrder(order
);
392 Qt::SortOrder
DolphinView::sortOrder() const
394 return m_proxyModel
->sortOrder();
397 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
399 const KUrl viewPropsUrl
= viewPropertiesUrl();
400 ViewProperties
props(viewPropsUrl
);
401 props
.setAdditionalInfo(info
);
403 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
404 m_fileItemDelegate
->setAdditionalInformation(info
);
406 emit
additionalInfoChanged(info
);
407 startDirLister(viewPropsUrl
, true);
410 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
412 return m_fileItemDelegate
->additionalInformation();
415 void DolphinView::reload()
418 startDirLister(url(), true);
421 void DolphinView::refresh()
424 applyViewProperties(m_controller
->url());
428 void DolphinView::setUrl(const KUrl
& url
)
430 if (m_controller
->url() == url
) {
434 m_controller
->setUrl(url
);
436 applyViewProperties(url
);
439 emit
urlChanged(url
);
442 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
444 QWidget::mouseReleaseEvent(event
);
447 void DolphinView::activate()
452 void DolphinView::triggerItem(const QModelIndex
& index
)
454 if (!isValidNameIndex(index
)) {
456 showHoverInformation(index
);
460 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
461 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
462 // items are selected by the user, hence don't trigger the
463 // item specified by 'index'
467 KFileItem
* item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
472 // The stuff below should be moved to ViewContainer and be just a signal?
474 // Prefer the local path over the URL.
476 KUrl url
= item
->mostLocalUrl(isLocal
);
480 } else if (item
->isFile()) {
481 // allow to browse through ZIP and tar files
482 KMimeType::Ptr mime
= item
->mimeTypePtr();
483 if (mime
->is("application/zip")) {
484 url
.setProtocol("zip");
486 } else if (mime
->is("application/x-tar") ||
487 mime
->is("application/x-tarz") ||
488 mime
->is("application/x-bzip-compressed-tar") ||
489 mime
->is("application/x-compressed-tar") ||
490 mime
->is("application/x-tzo")) {
491 url
.setProtocol("tar");
501 void DolphinView::generatePreviews(const KFileItemList
& items
)
503 if (m_controller
->showPreview()) {
505 // Must turn QList<KFileItem *> to QList<KFileItem>...
506 QList
<KFileItem
> itemsToPreview
;
507 foreach( KFileItem
* it
, items
)
508 itemsToPreview
.append( *it
);
510 KIO::PreviewJob
* job
= KIO::filePreview(itemsToPreview
, 128);
511 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
512 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
516 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
518 Q_ASSERT(!item
.isNull());
519 if (item
.url().directory() != m_dirLister
->url().path()) {
520 // the preview job is still working on items of an older URL, hence
521 // the item is not part of the directory model anymore
525 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
526 if (idx
.isValid() && (idx
.column() == 0)) {
527 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
528 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
529 KIconEffect iconEffect
;
530 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
531 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
533 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
538 void DolphinView::emitSelectionChangedSignal()
540 emit
selectionChanged(DolphinView::selectedItems());
543 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
545 if (!url
.isValid()) {
546 const QString
location(url
.pathOrUrl());
547 if (location
.isEmpty()) {
548 emit
errorMessage(i18nc("@info:status", "The location is empty."));
550 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
555 m_cutItemsCache
.clear();
556 m_loadingDirectory
= true;
561 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
562 m_initializeColumnView
= false;
568 const KUrl
& dirListerUrl
= m_dirLister
->url();
569 if (dirListerUrl
.isValid()) {
570 const KUrl::List dirs
= m_dirLister
->directories();
573 m_dirLister
->updateDirectory(url
);
577 } else if (m_dirLister
->directories().contains(url
)) {
578 // The dir lister contains the directory already, so
579 // KDirLister::openUrl() may not been invoked twice.
580 m_dirLister
->updateDirectory(url
);
583 const KUrl
& dirListerUrl
= m_dirLister
->url();
584 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
585 // The current URL is not a child of the dir lister
586 // URL. This may happen when e. g. a bookmark has been selected
587 // and hence the view must be reset.
594 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
598 KUrl
DolphinView::viewPropertiesUrl() const
600 if (isColumnViewActive()) {
601 return m_dirLister
->url();
607 void DolphinView::applyViewProperties(const KUrl
& url
)
609 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
610 // The column view is active, hence don't apply the view properties
611 // of sub directories (represented by columns) to the view. The
612 // view always represents the properties of the first column.
616 const ViewProperties
props(url
);
618 const Mode mode
= props
.viewMode();
619 if (m_mode
!= mode
) {
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;
632 if (itemView() == 0) {
635 Q_ASSERT(itemView() != 0);
636 Q_ASSERT(m_fileItemDelegate
!= 0);
638 const bool showHiddenFiles
= props
.showHiddenFiles();
639 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
640 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
641 emit
showHiddenFilesChanged();
644 const bool categorized
= props
.categorizedSorting();
645 if (categorized
!= categorizedSorting()) {
646 if (supportsCategorizedSorting()) {
647 Q_ASSERT(m_iconsView
!= 0);
649 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
650 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
652 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
653 m_iconsView
->setItemCategorizer(0);
657 emit
categorizedSortingChanged();
660 const DolphinView::Sorting sorting
= props
.sorting();
661 if (sorting
!= m_proxyModel
->sorting()) {
662 m_proxyModel
->setSorting(sorting
);
663 emit
sortingChanged(sorting
);
666 const Qt::SortOrder sortOrder
= props
.sortOrder();
667 if (sortOrder
!= m_proxyModel
->sortOrder()) {
668 m_proxyModel
->setSortOrder(sortOrder
);
669 emit
sortOrderChanged(sortOrder
);
672 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
673 if (info
!= m_fileItemDelegate
->additionalInformation()) {
674 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
675 m_fileItemDelegate
->setAdditionalInformation(info
);
676 emit
additionalInfoChanged(info
);
679 const bool showPreview
= props
.showPreview();
680 if (showPreview
!= m_controller
->showPreview()) {
681 m_controller
->setShowPreview(showPreview
);
682 emit
showPreviewChanged();
686 void DolphinView::changeSelection(const KFileItemList
& selection
)
689 if (selection
.isEmpty()) {
692 const KUrl
& baseUrl
= url();
694 QItemSelection new_selection
;
695 foreach(KFileItem
* item
, selection
) {
696 url
= item
->url().upUrl();
697 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
698 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(*item
));
699 new_selection
.select(index
, index
);
702 itemView()->selectionModel()->select(new_selection
,
703 QItemSelectionModel::ClearAndSelect
704 | QItemSelectionModel::Current
);
707 void DolphinView::openContextMenu(const QPoint
& pos
)
711 const QModelIndex index
= itemView()->indexAt(pos
);
712 if (isValidNameIndex(index
)) {
713 item
= fileItem(index
);
716 emit
requestContextMenu(item
, url());
719 void DolphinView::dropUrls(const KUrl::List
& urls
,
720 const QModelIndex
& index
,
723 KFileItem
* directory
= 0;
724 if (isValidNameIndex(index
)) {
725 KFileItem
* item
= fileItem(index
);
728 // the URLs are dropped above a directory
733 if ((directory
== 0) && (source
== itemView())) {
734 // The dropping is done into the same viewport where
735 // the dragging has been started. Just ignore this...
739 const KUrl
& destination
= (directory
== 0) ?
740 url() : directory
->url();
741 dropUrls(urls
, destination
);
744 void DolphinView::dropUrls(const KUrl::List
& urls
,
745 const KUrl
& destination
)
747 emit
urlsDropped(urls
, destination
);
750 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
752 ViewProperties
props(viewPropertiesUrl());
753 props
.setSorting(sorting
);
755 m_proxyModel
->setSorting(sorting
);
757 emit
sortingChanged(sorting
);
760 void DolphinView::updateSortOrder(Qt::SortOrder order
)
762 ViewProperties
props(viewPropertiesUrl());
763 props
.setSortOrder(order
);
765 m_proxyModel
->setSortOrder(order
);
767 emit
sortOrderChanged(order
);
770 void DolphinView::emitContentsMoved()
772 // only emit the contents moved signal if:
773 // - no directory loading is ongoing (this would reset the contents position
775 // - if the Column View is active: the column view does an automatic
776 // positioning during the loading operation, which must be remembered
777 if (!m_loadingDirectory
|| isColumnViewActive()) {
778 const QPoint
pos(contentsPosition());
779 emit
contentsMoved(pos
.x(), pos
.y());
783 void DolphinView::updateCutItems()
785 // restore the icons of all previously selected items to the
787 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
788 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
790 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
791 if (index
.isValid()) {
792 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
796 m_cutItemsCache
.clear();
798 // ... and apply an item effect to all currently cut items
799 applyCutItemEffect();
802 void DolphinView::showHoverInformation(const QModelIndex
& index
)
804 if (hasSelection()) {
808 const KFileItem
* item
= fileItem(index
);
810 emit
requestItemInfo(*item
);
814 void DolphinView::clearHoverInformation()
816 emit
requestItemInfo(KFileItem());
820 void DolphinView::createView()
822 // delete current view
823 QAbstractItemView
* view
= itemView();
825 m_topLayout
->removeWidget(view
);
827 if (view
== m_iconsView
) {
828 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
829 m_iconsView
->setItemCategorizer(0);
837 m_fileItemDelegate
= 0;
840 Q_ASSERT(m_iconsView
== 0);
841 Q_ASSERT(m_detailsView
== 0);
842 Q_ASSERT(m_columnView
== 0);
844 // ... and recreate it representing the current mode
847 m_iconsView
= new DolphinIconsView(this, m_controller
);
852 m_detailsView
= new DolphinDetailsView(this, m_controller
);
853 view
= m_detailsView
;
857 m_columnView
= new DolphinColumnView(this, m_controller
);
864 m_fileItemDelegate
= new KFileItemDelegate(view
);
865 view
->setItemDelegate(m_fileItemDelegate
);
867 view
->setModel(m_proxyModel
);
868 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
870 new KMimeTypeResolver(view
, m_dirModel
);
871 m_topLayout
->insertWidget(1, view
);
873 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
874 this, SLOT(emitSelectionChangedSignal()));
875 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
876 this, SLOT(emitContentsMoved()));
877 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
878 this, SLOT(emitContentsMoved()));
881 void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags
)
883 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
884 const QAbstractItemModel
* itemModel
= selectionModel
->model();
886 const QModelIndex topLeft
= itemModel
->index(0, 0);
887 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
888 itemModel
->columnCount() - 1);
890 QItemSelection
selection(topLeft
, bottomRight
);
891 selectionModel
->select(selection
, flags
);
894 QAbstractItemView
* DolphinView::itemView() const
896 if (m_detailsView
!= 0) {
897 return m_detailsView
;
898 } else if (m_columnView
!= 0) {
905 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
907 return index
.isValid() && (index
.column() == KDirModel::Name
);
910 bool DolphinView::isCutItem(const KFileItem
& item
) const
912 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
913 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
915 const KUrl
& itemUrl
= item
.url();
916 KUrl::List::const_iterator it
= cutUrls
.begin();
917 const KUrl::List::const_iterator end
= cutUrls
.end();
919 if (*it
== itemUrl
) {
928 void DolphinView::applyCutItemEffect()
930 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
931 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
935 KFileItemList
items(m_dirLister
->items());
936 KFileItemList::const_iterator it
= items
.begin();
937 const KFileItemList::const_iterator end
= items
.end();
939 KFileItem
* item
= *it
;
940 if (isCutItem(*item
)) {
941 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
942 const KFileItem
* item
= m_dirModel
->itemForIndex(index
);
943 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
944 if ((value
.type() == QVariant::Icon
) && (item
!= 0)) {
945 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
946 QPixmap pixmap
= icon
.pixmap(128, 128);
948 // remember current pixmap for the item to be able
949 // to restore it when other items get cut
951 cutItem
.url
= item
->url();
952 cutItem
.pixmap
= pixmap
;
953 m_cutItemsCache
.append(cutItem
);
955 // apply icon effect to the cut item
956 KIconEffect iconEffect
;
957 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
958 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
965 #include "dolphinview.moc"