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 <kdirlister.h>
33 #include <kfileitemdelegate.h>
35 #include <kiconeffect.h>
36 #include <kio/netaccess.h>
37 #include <kio/renamedialog.h>
38 #include <kio/previewjob.h>
39 #include <kmimetyperesolver.h>
40 #include <konqmimedata.h>
41 #include <konq_operations.h>
44 #include "dolphinmodel.h"
45 #include "dolphincolumnview.h"
46 #include "dolphincontroller.h"
47 #include "dolphinsortfilterproxymodel.h"
48 #include "dolphindetailsview.h"
49 #include "dolphiniconsview.h"
50 #include "renamedialog.h"
51 #include "viewproperties.h"
52 #include "dolphinsettings.h"
53 #include "dolphin_generalsettings.h"
55 DolphinView::DolphinView(QWidget
* parent
,
57 KDirLister
* dirLister
,
58 DolphinModel
* dolphinModel
,
59 DolphinSortFilterProxyModel
* proxyModel
) :
62 m_loadingDirectory(false),
63 m_storedCategorizedSorting(false),
64 m_mode(DolphinView::IconsView
),
70 m_fileItemDelegate(0),
71 m_dolphinModel(dolphinModel
),
72 m_dirLister(dirLister
),
73 m_proxyModel(proxyModel
)
75 setFocusPolicy(Qt::StrongFocus
);
76 m_topLayout
= new QVBoxLayout(this);
77 m_topLayout
->setSpacing(0);
78 m_topLayout
->setMargin(0);
80 QClipboard
* clipboard
= QApplication::clipboard();
81 connect(clipboard
, SIGNAL(dataChanged()),
82 this, SLOT(updateCutItems()));
84 connect(m_dirLister
, SIGNAL(completed()),
85 this, SLOT(updateCutItems()));
86 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
87 this, SLOT(generatePreviews(const KFileItemList
&)));
89 m_controller
= new DolphinController(this);
90 m_controller
->setUrl(url
);
92 // Receiver of the DolphinView signal 'urlChanged()' don't need
93 // to care whether the internal controller changed the URL already or whether
94 // the controller just requested an URL change and will be updated later.
95 // In both cases the URL has been changed:
96 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
97 this, SIGNAL(urlChanged(const KUrl
&)));
98 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
99 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
102 this, SLOT(openContextMenu(const QPoint
&)));
103 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)),
104 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)));
105 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
106 this, SLOT(updateSorting(DolphinView::Sorting
)));
107 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
108 this, SLOT(updateSortOrder(Qt::SortOrder
)));
109 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
110 this, SLOT(triggerItem(const KFileItem
&)));
111 connect(m_controller
, SIGNAL(activated()),
112 this, SLOT(activate()));
113 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
114 this, SLOT(showHoverInformation(const KFileItem
&)));
115 connect(m_controller
, SIGNAL(viewportEntered()),
116 this, SLOT(clearHoverInformation()));
118 applyViewProperties(url
);
119 m_topLayout
->addWidget(itemView());
122 DolphinView::~DolphinView()
126 const KUrl
& DolphinView::url() const
128 return m_controller
->url();
131 KUrl
DolphinView::rootUrl() const
133 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
136 void DolphinView::setActive(bool active
)
138 if (active
== m_active
) {
144 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
146 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
147 // bypasses the problem when having a split view and changing the active view to
148 // update the some URL dependent states. A nicer approach should be no big deal...
149 emit
urlChanged(url());
150 emit
selectionChanged(selectedItems());
155 QWidget
* viewport
= itemView()->viewport();
157 palette
.setColor(viewport
->backgroundRole(), color
);
158 viewport
->setPalette(palette
);
166 m_controller
->indicateActivationChange(active
);
169 bool DolphinView::isActive() const
174 void DolphinView::setMode(Mode mode
)
176 if (mode
== m_mode
) {
177 return; // the wished mode is already set
182 if (isColumnViewActive()) {
183 // When changing the mode in the column view, it makes sense
184 // to go back to the root URL of the column view automatically.
185 // Otherwise there it would not be possible to turn off the column view
186 // without focusing the first column.
187 const KUrl root
= rootUrl();
189 m_controller
->setUrl(root
);
192 const KUrl viewPropsUrl
= viewPropertiesUrl();
193 ViewProperties
props(viewPropsUrl
);
194 props
.setViewMode(m_mode
);
198 // Not all view modes support categorized sorting. Adjust the sorting model
199 // if changing the view mode results in a change of the categorized sorting
201 m_storedCategorizedSorting
= props
.categorizedSorting();
202 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
203 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
204 m_proxyModel
->setCategorizedModel(categorized
);
205 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
206 emit
categorizedSortingChanged();
209 loadDirectory(viewPropsUrl
);
214 DolphinView::Mode
DolphinView::mode() const
219 void DolphinView::setShowPreview(bool show
)
221 const KUrl viewPropsUrl
= viewPropertiesUrl();
222 ViewProperties
props(viewPropsUrl
);
223 props
.setShowPreview(show
);
225 m_controller
->setShowPreview(show
);
226 emit
showPreviewChanged();
228 loadDirectory(viewPropsUrl
, true);
231 bool DolphinView::showPreview() const
233 return m_controller
->showPreview();
236 void DolphinView::setShowHiddenFiles(bool show
)
238 if (m_dirLister
->showingDotFiles() == show
) {
242 const KUrl viewPropsUrl
= viewPropertiesUrl();
243 ViewProperties
props(viewPropsUrl
);
244 props
.setShowHiddenFiles(show
);
246 m_dirLister
->setShowingDotFiles(show
);
247 m_controller
->setShowHiddenFiles(show
);
248 emit
showHiddenFilesChanged();
250 loadDirectory(viewPropsUrl
, true);
253 bool DolphinView::showHiddenFiles() const
255 return m_dirLister
->showingDotFiles();
258 void DolphinView::setCategorizedSorting(bool categorized
)
260 if (categorized
== categorizedSorting()) {
264 // setCategorizedSorting(true) may only get invoked
265 // if the view supports categorized sorting
266 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
268 ViewProperties
props(viewPropertiesUrl());
269 props
.setCategorizedSorting(categorized
);
272 m_storedCategorizedSorting
= categorized
;
273 m_proxyModel
->setCategorizedModel(categorized
);
274 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
276 emit
categorizedSortingChanged();
279 bool DolphinView::categorizedSorting() const
281 // If all view modes would support categorized sorting, returning
282 // m_proxyModel->isCategorizedModel() would be the way to go. As
283 // currently only the icons view supports caterized sorting, we remember
284 // the stored view properties state in m_storedCategorizedSorting and
285 // return this state. The application takes care to disable the corresponding
286 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
287 // that this setting is not applied to the current view mode.
288 return m_storedCategorizedSorting
;
291 bool DolphinView::supportsCategorizedSorting() const
293 return m_iconsView
!= 0;
296 void DolphinView::selectAll()
298 itemView()->selectAll();
301 void DolphinView::invertSelection()
303 if (isColumnViewActive()) {
304 // QAbstractItemView does not offer a virtual method invertSelection()
305 // as counterpart to QAbstractItemView::selectAll(). This makes it
306 // necessary to delegate the inverting of the selection to the
307 // column view, as only the selection of the active column should
309 m_columnView
->invertSelection();
311 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
312 const QAbstractItemModel
* itemModel
= selectionModel
->model();
314 const QModelIndex topLeft
= itemModel
->index(0, 0);
315 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
316 itemModel
->columnCount() - 1);
318 const QItemSelection
selection(topLeft
, bottomRight
);
319 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
323 bool DolphinView::hasSelection() const
325 return itemView()->selectionModel()->hasSelection();
328 void DolphinView::clearSelection()
330 itemView()->selectionModel()->clear();
333 KFileItemList
DolphinView::selectedItems() const
335 const QAbstractItemView
* view
= itemView();
337 // Our view has a selection, we will map them back to the DolphinModel
338 // and then fill the KFileItemList.
339 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
341 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
342 KFileItemList itemList
;
344 const QModelIndexList indexList
= selection
.indexes();
345 foreach (QModelIndex index
, indexList
) {
346 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
347 if (!item
.isNull()) {
348 itemList
.append(item
);
355 KUrl::List
DolphinView::selectedUrls() const
358 const KFileItemList list
= selectedItems();
359 foreach (KFileItem item
, list
) {
360 urls
.append(item
.url());
365 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
367 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
368 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
371 void DolphinView::setContentsPosition(int x
, int y
)
373 QAbstractItemView
* view
= itemView();
375 // the ColumnView takes care itself for the horizontal scrolling
376 if (!isColumnViewActive()) {
377 view
->horizontalScrollBar()->setValue(x
);
379 view
->verticalScrollBar()->setValue(y
);
381 m_loadingDirectory
= false;
384 QPoint
DolphinView::contentsPosition() const
386 const int x
= itemView()->horizontalScrollBar()->value();
387 const int y
= itemView()->verticalScrollBar()->value();
391 void DolphinView::zoomIn()
393 m_controller
->triggerZoomIn();
396 void DolphinView::zoomOut()
398 m_controller
->triggerZoomOut();
401 bool DolphinView::isZoomInPossible() const
403 return m_controller
->isZoomInPossible();
406 bool DolphinView::isZoomOutPossible() const
408 return m_controller
->isZoomOutPossible();
411 void DolphinView::setSorting(Sorting sorting
)
413 if (sorting
!= this->sorting()) {
414 updateSorting(sorting
);
418 DolphinView::Sorting
DolphinView::sorting() const
420 return m_proxyModel
->sorting();
423 void DolphinView::setSortOrder(Qt::SortOrder order
)
425 if (sortOrder() != order
) {
426 updateSortOrder(order
);
430 Qt::SortOrder
DolphinView::sortOrder() const
432 return m_proxyModel
->sortOrder();
435 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
437 const KUrl viewPropsUrl
= viewPropertiesUrl();
438 ViewProperties
props(viewPropsUrl
);
439 props
.setAdditionalInfo(info
);
441 m_controller
->setAdditionalInfoCount(info
.count());
442 m_fileItemDelegate
->setShowInformation(info
);
444 emit
additionalInfoChanged(info
);
445 loadDirectory(viewPropsUrl
, true);
448 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
450 return m_fileItemDelegate
->showInformation();
453 void DolphinView::reload()
456 loadDirectory(url(), true);
459 void DolphinView::refresh()
461 const bool oldActivationState
= m_active
;
465 applyViewProperties(m_controller
->url());
468 setActive(oldActivationState
);
471 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
473 if (m_controller
->url() == url
) {
477 m_controller
->setUrl(url
); // emits urlChanged, which we forward
479 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
480 applyViewProperties(rootUrl
);
481 loadDirectory(rootUrl
);
482 if (itemView() == m_columnView
) {
483 m_columnView
->setRootUrl(rootUrl
);
484 m_columnView
->showColumn(url
);
487 applyViewProperties(url
);
491 itemView()->setFocus();
493 emit
startedPathLoading(url
);
496 void DolphinView::setNameFilter(const QString
& nameFilter
)
498 // The name filter of KDirLister does a 'hard' filtering, which
499 // means that only the items are shown where the names match
500 // exactly the filter. This is non-transparent for the user, which
501 // just wants to have a 'soft' filtering: does the name contain
502 // the filter string?
503 QString
adjustedFilter(nameFilter
);
504 adjustedFilter
.insert(0, '*');
505 adjustedFilter
.append('*');
507 m_dirLister
->setNameFilter(adjustedFilter
);
508 m_dirLister
->emitChanges();
510 if (isColumnViewActive()) {
511 // adjusting the directory lister is not enough in the case of the
512 // column view, as each column has its own directory lister internally...
513 m_columnView
->setNameFilter(nameFilter
);
517 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
519 foreach (KFileItem item
, m_dirLister
->items()) {
528 void DolphinView::setUrl(const KUrl
& url
)
530 updateView(url
, KUrl());
533 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
535 QWidget::mouseReleaseEvent(event
);
538 void DolphinView::activate()
543 void DolphinView::triggerItem(const KFileItem
& item
)
545 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
546 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
547 // items are selected by the user, hence don't trigger the
548 // item specified by 'index'
556 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
559 void DolphinView::generatePreviews(const KFileItemList
& items
)
561 if (m_controller
->showPreview()) {
562 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
563 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
564 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
568 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
570 Q_ASSERT(!item
.isNull());
571 if (item
.url().directory() != m_dirLister
->url().path()) {
572 // the preview job is still working on items of an older URL, hence
573 // the item is not part of the directory model anymore
577 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
578 if (idx
.isValid() && (idx
.column() == 0)) {
579 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
580 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
581 KIconEffect iconEffect
;
582 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
583 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
585 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
590 void DolphinView::emitSelectionChangedSignal()
592 emit
selectionChanged(DolphinView::selectedItems());
595 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
597 if (!url
.isValid()) {
598 const QString
location(url
.pathOrUrl());
599 if (location
.isEmpty()) {
600 emit
errorMessage(i18nc("@info:status", "The location is empty."));
602 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
607 m_cutItemsCache
.clear();
608 m_loadingDirectory
= true;
611 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
613 if (isColumnViewActive()) {
614 // adjusting the directory lister is not enough in the case of the
615 // column view, as each column has its own directory lister internally...
617 m_columnView
->reload();
619 m_columnView
->showColumn(url
);
624 KUrl
DolphinView::viewPropertiesUrl() const
626 if (isColumnViewActive()) {
627 return m_dirLister
->url();
633 void DolphinView::applyViewProperties(const KUrl
& url
)
635 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
636 // The column view is active, hence don't apply the view properties
637 // of sub directories (represented by columns) to the view. The
638 // view always represents the properties of the first column.
642 const ViewProperties
props(url
);
644 const Mode mode
= props
.viewMode();
645 if (m_mode
!= mode
) {
650 if (itemView() == 0) {
653 Q_ASSERT(itemView() != 0);
654 Q_ASSERT(m_fileItemDelegate
!= 0);
656 const bool showHiddenFiles
= props
.showHiddenFiles();
657 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
658 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
659 m_controller
->setShowHiddenFiles(showHiddenFiles
);
660 emit
showHiddenFilesChanged();
663 m_storedCategorizedSorting
= props
.categorizedSorting();
664 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
665 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
666 m_proxyModel
->setCategorizedModel(categorized
);
667 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
668 emit
categorizedSortingChanged();
671 const DolphinView::Sorting sorting
= props
.sorting();
672 if (sorting
!= m_proxyModel
->sorting()) {
673 m_proxyModel
->setSorting(sorting
);
674 emit
sortingChanged(sorting
);
677 const Qt::SortOrder sortOrder
= props
.sortOrder();
678 if (sortOrder
!= m_proxyModel
->sortOrder()) {
679 m_proxyModel
->setSortOrder(sortOrder
);
680 emit
sortOrderChanged(sortOrder
);
683 KFileItemDelegate::InformationList info
= props
.additionalInfo();
684 if (info
!= m_fileItemDelegate
->showInformation()) {
685 m_controller
->setAdditionalInfoCount(info
.count());
686 m_fileItemDelegate
->setShowInformation(info
);
687 emit
additionalInfoChanged(info
);
690 const bool showPreview
= props
.showPreview();
691 if (showPreview
!= m_controller
->showPreview()) {
692 m_controller
->setShowPreview(showPreview
);
693 emit
showPreviewChanged();
697 void DolphinView::changeSelection(const KFileItemList
& selection
)
700 if (selection
.isEmpty()) {
703 const KUrl
& baseUrl
= url();
705 QItemSelection new_selection
;
706 foreach(const KFileItem
& item
, selection
) {
707 url
= item
.url().upUrl();
708 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
709 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
710 new_selection
.select(index
, index
);
713 itemView()->selectionModel()->select(new_selection
,
714 QItemSelectionModel::ClearAndSelect
715 | QItemSelectionModel::Current
);
718 void DolphinView::openContextMenu(const QPoint
& pos
)
722 const QModelIndex index
= itemView()->indexAt(pos
);
723 if (isValidNameIndex(index
)) {
724 item
= fileItem(index
);
727 emit
requestContextMenu(item
, url());
730 void DolphinView::dropUrls(const KUrl::List
& urls
,
731 const KUrl
& destPath
,
732 const QModelIndex
& destIndex
,
736 if (isValidNameIndex(destIndex
)) {
737 KFileItem item
= fileItem(destIndex
);
738 Q_ASSERT(!item
.isNull());
740 // the URLs are dropped above a directory
745 if ((directory
.isNull()) && (source
== itemView())) {
746 // The dropping is done into the same viewport where
747 // the dragging has been started. Just ignore this...
751 const KUrl
& destination
= (directory
.isNull()) ?
752 destPath
: directory
.url();
753 dropUrls(urls
, destination
);
756 void DolphinView::dropUrls(const KUrl::List
& urls
,
757 const KUrl
& destination
)
759 emit
urlsDropped(urls
, destination
);
762 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
764 ViewProperties
props(viewPropertiesUrl());
765 props
.setSorting(sorting
);
767 m_proxyModel
->setSorting(sorting
);
769 emit
sortingChanged(sorting
);
772 void DolphinView::updateSortOrder(Qt::SortOrder order
)
774 ViewProperties
props(viewPropertiesUrl());
775 props
.setSortOrder(order
);
777 m_proxyModel
->setSortOrder(order
);
779 emit
sortOrderChanged(order
);
782 void DolphinView::emitContentsMoved()
784 // only emit the contents moved signal if:
785 // - no directory loading is ongoing (this would reset the contents position
787 // - if the Column View is active: the column view does an automatic
788 // positioning during the loading operation, which must be remembered
789 if (!m_loadingDirectory
|| isColumnViewActive()) {
790 const QPoint
pos(contentsPosition());
791 emit
contentsMoved(pos
.x(), pos
.y());
795 void DolphinView::updateCutItems()
797 // restore the icons of all previously selected items to the
799 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
800 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
802 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
803 if (index
.isValid()) {
804 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
808 m_cutItemsCache
.clear();
810 // ... and apply an item effect to all currently cut items
811 applyCutItemEffect();
814 void DolphinView::showHoverInformation(const KFileItem
& item
)
816 if (hasSelection()) {
820 emit
requestItemInfo(item
);
823 void DolphinView::clearHoverInformation()
825 emit
requestItemInfo(KFileItem());
829 void DolphinView::createView()
831 KFileItemDelegate::InformationList infoList
;
832 if (m_fileItemDelegate
!= 0) {
833 infoList
= m_fileItemDelegate
->showInformation();
836 // delete current view
837 QAbstractItemView
* view
= itemView();
839 m_topLayout
->removeWidget(view
);
846 m_fileItemDelegate
= 0;
849 Q_ASSERT(m_iconsView
== 0);
850 Q_ASSERT(m_detailsView
== 0);
851 Q_ASSERT(m_columnView
== 0);
853 // ... and recreate it representing the current mode
856 m_iconsView
= new DolphinIconsView(this, m_controller
);
862 m_detailsView
= new DolphinDetailsView(this, m_controller
);
863 view
= m_detailsView
;
867 m_columnView
= new DolphinColumnView(this, m_controller
);
874 m_fileItemDelegate
= new KFileItemDelegate(view
);
875 m_fileItemDelegate
->setShowInformation(infoList
);
876 view
->setItemDelegate(m_fileItemDelegate
);
878 view
->setModel(m_proxyModel
);
879 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
881 new KMimeTypeResolver(view
, m_dolphinModel
);
882 m_topLayout
->insertWidget(1, view
);
884 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
885 this, SLOT(emitSelectionChangedSignal()));
886 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
887 this, SLOT(emitContentsMoved()));
888 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
889 this, SLOT(emitContentsMoved()));
893 QAbstractItemView
* DolphinView::itemView() const
895 if (m_detailsView
!= 0) {
896 return m_detailsView
;
897 } else if (m_columnView
!= 0) {
904 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
906 return index
.isValid() && (index
.column() == DolphinModel::Name
);
909 bool DolphinView::isCutItem(const KFileItem
& item
) const
911 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
912 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
914 const KUrl
& itemUrl
= item
.url();
915 KUrl::List::const_iterator it
= cutUrls
.begin();
916 const KUrl::List::const_iterator end
= cutUrls
.end();
918 if (*it
== itemUrl
) {
927 void DolphinView::applyCutItemEffect()
929 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
930 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
934 KFileItemList
items(m_dirLister
->items());
935 KFileItemList::const_iterator it
= items
.begin();
936 const KFileItemList::const_iterator end
= items
.end();
938 const KFileItem item
= *it
;
939 if (isCutItem(item
)) {
940 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
941 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
942 if (value
.type() == QVariant::Icon
) {
943 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
944 QPixmap pixmap
= icon
.pixmap(128, 128);
946 // remember current pixmap for the item to be able
947 // to restore it when other items get cut
949 cutItem
.url
= item
.url();
950 cutItem
.pixmap
= pixmap
;
951 m_cutItemsCache
.append(cutItem
);
953 // apply icon effect to the cut item
954 KIconEffect iconEffect
;
955 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
956 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
963 #include "dolphinview.moc"