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"
22 #include <ktoggleaction.h>
23 #include <kactioncollection.h>
25 #include <QApplication>
28 #include <QItemSelection>
33 #include <kcolorscheme.h>
34 #include <kdirlister.h>
35 #include <kfileitemdelegate.h>
37 #include <kiconeffect.h>
38 #include <kio/netaccess.h>
39 #include <kio/renamedialog.h>
40 #include <kio/previewjob.h>
41 #include <kmimetyperesolver.h>
42 #include <konqmimedata.h>
43 #include <konq_operations.h>
46 #include "dolphinmodel.h"
47 #include "dolphincolumnview.h"
48 #include "dolphincontroller.h"
49 #include "dolphinsortfilterproxymodel.h"
50 #include "dolphindetailsview.h"
51 #include "dolphiniconsview.h"
52 #include "renamedialog.h"
53 #include "viewproperties.h"
54 #include "dolphinsettings.h"
55 #include "dolphin_generalsettings.h"
57 DolphinView::DolphinView(QWidget
* parent
,
59 KDirLister
* dirLister
,
60 DolphinModel
* dolphinModel
,
61 DolphinSortFilterProxyModel
* proxyModel
) :
64 m_loadingDirectory(false),
65 m_storedCategorizedSorting(false),
66 m_mode(DolphinView::IconsView
),
72 m_fileItemDelegate(0),
73 m_dolphinModel(dolphinModel
),
74 m_dirLister(dirLister
),
75 m_proxyModel(proxyModel
)
77 setFocusPolicy(Qt::StrongFocus
);
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setMargin(0);
82 QClipboard
* clipboard
= QApplication::clipboard();
83 connect(clipboard
, SIGNAL(dataChanged()),
84 this, SLOT(updateCutItems()));
86 connect(m_dirLister
, SIGNAL(completed()),
87 this, SLOT(updateCutItems()));
88 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
89 this, SLOT(generatePreviews(const KFileItemList
&)));
91 m_controller
= new DolphinController(this);
92 m_controller
->setUrl(url
);
94 // Receiver of the DolphinView signal 'urlChanged()' don't need
95 // to care whether the internal controller changed the URL already or whether
96 // the controller just requested an URL change and will be updated later.
97 // In both cases the URL has been changed:
98 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
99 this, SIGNAL(urlChanged(const KUrl
&)));
100 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
101 this, SIGNAL(urlChanged(const KUrl
&)));
103 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
104 this, SLOT(openContextMenu(const QPoint
&)));
105 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&, QWidget
*)),
106 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&, QWidget
*)));
107 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
108 this, SLOT(updateSorting(DolphinView::Sorting
)));
109 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
110 this, SLOT(updateSortOrder(Qt::SortOrder
)));
111 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
112 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
113 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
114 this, SLOT(triggerItem(const KFileItem
&)));
115 connect(m_controller
, SIGNAL(activated()),
116 this, SLOT(activate()));
117 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
118 this, SLOT(showHoverInformation(const KFileItem
&)));
119 connect(m_controller
, SIGNAL(viewportEntered()),
120 this, SLOT(clearHoverInformation()));
122 applyViewProperties(url
);
123 m_topLayout
->addWidget(itemView());
126 DolphinView::~DolphinView()
130 const KUrl
& DolphinView::url() const
132 return m_controller
->url();
135 KUrl
DolphinView::rootUrl() const
137 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
140 void DolphinView::setActive(bool active
)
142 if (active
== m_active
) {
148 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
150 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
151 // bypasses the problem when having a split view and changing the active view to
152 // update the some URL dependent states. A nicer approach should be no big deal...
153 emit
urlChanged(url());
154 emit
selectionChanged(selectedItems());
159 QWidget
* viewport
= itemView()->viewport();
161 palette
.setColor(viewport
->backgroundRole(), color
);
162 viewport
->setPalette(palette
);
170 m_controller
->indicateActivationChange(active
);
173 bool DolphinView::isActive() const
178 void DolphinView::setMode(Mode mode
)
180 if (mode
== m_mode
) {
181 return; // the wished mode is already set
186 if (isColumnViewActive()) {
187 // When changing the mode in the column view, it makes sense
188 // to go back to the root URL of the column view automatically.
189 // Otherwise there it would not be possible to turn off the column view
190 // without focusing the first column.
191 const KUrl root
= rootUrl();
193 m_controller
->setUrl(root
);
196 const KUrl viewPropsUrl
= viewPropertiesUrl();
197 ViewProperties
props(viewPropsUrl
);
198 props
.setViewMode(m_mode
);
202 // the file item delegate has been recreated, apply the current
203 // additional information manually
204 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
205 m_fileItemDelegate
->setShowInformation(infoList
);
206 emit
additionalInfoChanged(infoList
);
208 // Not all view modes support categorized sorting. Adjust the sorting model
209 // if changing the view mode results in a change of the categorized sorting
211 m_storedCategorizedSorting
= props
.categorizedSorting();
212 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
213 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
214 m_proxyModel
->setCategorizedModel(categorized
);
215 emit
categorizedSortingChanged();
218 loadDirectory(viewPropsUrl
);
223 DolphinView::Mode
DolphinView::mode() const
228 void DolphinView::setShowPreview(bool show
)
230 const KUrl viewPropsUrl
= viewPropertiesUrl();
231 ViewProperties
props(viewPropsUrl
);
232 props
.setShowPreview(show
);
234 m_controller
->setShowPreview(show
);
235 emit
showPreviewChanged();
237 loadDirectory(viewPropsUrl
, true);
240 bool DolphinView::showPreview() const
242 return m_controller
->showPreview();
245 void DolphinView::setShowHiddenFiles(bool show
)
247 if (m_dirLister
->showingDotFiles() == show
) {
251 const KUrl viewPropsUrl
= viewPropertiesUrl();
252 ViewProperties
props(viewPropsUrl
);
253 props
.setShowHiddenFiles(show
);
255 m_dirLister
->setShowingDotFiles(show
);
256 m_controller
->setShowHiddenFiles(show
);
257 emit
showHiddenFilesChanged();
259 loadDirectory(viewPropsUrl
, true);
262 bool DolphinView::showHiddenFiles() const
264 return m_dirLister
->showingDotFiles();
267 void DolphinView::setCategorizedSorting(bool categorized
)
269 if (categorized
== categorizedSorting()) {
273 // setCategorizedSorting(true) may only get invoked
274 // if the view supports categorized sorting
275 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
277 ViewProperties
props(viewPropertiesUrl());
278 props
.setCategorizedSorting(categorized
);
281 m_storedCategorizedSorting
= categorized
;
282 m_proxyModel
->setCategorizedModel(categorized
);
284 emit
categorizedSortingChanged();
287 bool DolphinView::categorizedSorting() const
289 // If all view modes would support categorized sorting, returning
290 // m_proxyModel->isCategorizedModel() would be the way to go. As
291 // currently only the icons view supports caterized sorting, we remember
292 // the stored view properties state in m_storedCategorizedSorting and
293 // return this state. The application takes care to disable the corresponding
294 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
295 // that this setting is not applied to the current view mode.
296 return m_storedCategorizedSorting
;
299 bool DolphinView::supportsCategorizedSorting() const
301 return m_iconsView
!= 0;
304 void DolphinView::selectAll()
306 itemView()->selectAll();
309 void DolphinView::invertSelection()
311 if (isColumnViewActive()) {
312 // QAbstractItemView does not offer a virtual method invertSelection()
313 // as counterpart to QAbstractItemView::selectAll(). This makes it
314 // necessary to delegate the inverting of the selection to the
315 // column view, as only the selection of the active column should
317 m_columnView
->invertSelection();
319 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
320 const QAbstractItemModel
* itemModel
= selectionModel
->model();
322 const QModelIndex topLeft
= itemModel
->index(0, 0);
323 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
324 itemModel
->columnCount() - 1);
326 const QItemSelection
selection(topLeft
, bottomRight
);
327 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
331 bool DolphinView::hasSelection() const
333 return itemView()->selectionModel()->hasSelection();
336 void DolphinView::clearSelection()
338 itemView()->selectionModel()->clear();
341 KFileItemList
DolphinView::selectedItems() const
343 const QAbstractItemView
* view
= itemView();
345 // Our view has a selection, we will map them back to the DolphinModel
346 // and then fill the KFileItemList.
347 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
349 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
350 KFileItemList itemList
;
352 const QModelIndexList indexList
= selection
.indexes();
353 foreach (QModelIndex index
, indexList
) {
354 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
355 if (!item
.isNull()) {
356 itemList
.append(item
);
363 KUrl::List
DolphinView::selectedUrls() const
366 const KFileItemList list
= selectedItems();
367 foreach (KFileItem item
, list
) {
368 urls
.append(item
.url());
373 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
375 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
376 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
379 void DolphinView::setContentsPosition(int x
, int y
)
381 QAbstractItemView
* view
= itemView();
383 // the ColumnView takes care itself for the horizontal scrolling
384 if (!isColumnViewActive()) {
385 view
->horizontalScrollBar()->setValue(x
);
387 view
->verticalScrollBar()->setValue(y
);
389 m_loadingDirectory
= false;
392 QPoint
DolphinView::contentsPosition() const
394 const int x
= itemView()->horizontalScrollBar()->value();
395 const int y
= itemView()->verticalScrollBar()->value();
399 void DolphinView::zoomIn()
401 m_controller
->triggerZoomIn();
404 void DolphinView::zoomOut()
406 m_controller
->triggerZoomOut();
409 bool DolphinView::isZoomInPossible() const
411 return m_controller
->isZoomInPossible();
414 bool DolphinView::isZoomOutPossible() const
416 return m_controller
->isZoomOutPossible();
419 void DolphinView::setSorting(Sorting sorting
)
421 if (sorting
!= this->sorting()) {
422 updateSorting(sorting
);
426 DolphinView::Sorting
DolphinView::sorting() const
428 return m_proxyModel
->sorting();
431 void DolphinView::setSortOrder(Qt::SortOrder order
)
433 if (sortOrder() != order
) {
434 updateSortOrder(order
);
438 Qt::SortOrder
DolphinView::sortOrder() const
440 return m_proxyModel
->sortOrder();
443 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
445 const KUrl viewPropsUrl
= viewPropertiesUrl();
446 ViewProperties
props(viewPropsUrl
);
447 props
.setAdditionalInfo(info
);
448 m_fileItemDelegate
->setShowInformation(info
);
450 emit
additionalInfoChanged(info
);
452 if (itemView() != m_detailsView
) {
453 // the details view requires no reloading of the directory, as it maps
454 // the file item delegate info to its columns internally
455 loadDirectory(viewPropsUrl
, true);
459 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
461 return m_fileItemDelegate
->showInformation();
464 void DolphinView::reload()
467 loadDirectory(url(), true);
470 void DolphinView::refresh()
472 const bool oldActivationState
= m_active
;
476 applyViewProperties(m_controller
->url());
479 setActive(oldActivationState
);
482 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
484 if (m_controller
->url() == url
) {
488 m_controller
->setUrl(url
); // emits urlChanged, which we forward
490 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
491 applyViewProperties(rootUrl
);
492 loadDirectory(rootUrl
);
493 if (itemView() == m_columnView
) {
494 m_columnView
->setRootUrl(rootUrl
);
495 m_columnView
->showColumn(url
);
498 applyViewProperties(url
);
502 emit
startedPathLoading(url
);
505 void DolphinView::setNameFilter(const QString
& nameFilter
)
507 m_proxyModel
->setFilterRegExp(nameFilter
);
509 if (isColumnViewActive()) {
510 // adjusting the directory lister is not enough in the case of the
511 // column view, as each column has its own directory lister internally...
512 m_columnView
->setNameFilter(nameFilter
);
516 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
518 foreach (KFileItem item
, m_dirLister
->items()) {
527 void DolphinView::setUrl(const KUrl
& url
)
529 updateView(url
, KUrl());
532 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
534 QWidget::mouseReleaseEvent(event
);
537 void DolphinView::activate()
542 void DolphinView::triggerItem(const KFileItem
& item
)
544 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
545 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
546 // items are selected by the user, hence don't trigger the
547 // item specified by 'index'
555 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
558 void DolphinView::generatePreviews(const KFileItemList
& items
)
560 if (m_controller
->showPreview()) {
561 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
562 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
563 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
567 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
569 Q_ASSERT(!item
.isNull());
570 if (item
.url().directory() != m_dirLister
->url().path()) {
571 // the preview job is still working on items of an older URL, hence
572 // the item is not part of the directory model anymore
576 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
577 if (idx
.isValid() && (idx
.column() == 0)) {
578 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
579 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
580 KIconEffect iconEffect
;
581 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
582 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
584 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
589 void DolphinView::emitSelectionChangedSignal()
591 emit
selectionChanged(DolphinView::selectedItems());
594 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
596 if (!url
.isValid()) {
597 const QString
location(url
.pathOrUrl());
598 if (location
.isEmpty()) {
599 emit
errorMessage(i18nc("@info:status", "The location is empty."));
601 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
606 m_cutItemsCache
.clear();
607 m_loadingDirectory
= true;
610 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
612 if (isColumnViewActive()) {
613 // adjusting the directory lister is not enough in the case of the
614 // column view, as each column has its own directory lister internally...
616 m_columnView
->reload();
618 m_columnView
->showColumn(url
);
623 KUrl
DolphinView::viewPropertiesUrl() const
625 if (isColumnViewActive()) {
626 return m_dirLister
->url();
632 void DolphinView::applyViewProperties(const KUrl
& url
)
634 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
635 // The column view is active, hence don't apply the view properties
636 // of sub directories (represented by columns) to the view. The
637 // view always represents the properties of the first column.
641 const ViewProperties
props(url
);
643 const Mode mode
= props
.viewMode();
644 if (m_mode
!= mode
) {
649 if (itemView() == 0) {
652 Q_ASSERT(itemView() != 0);
653 Q_ASSERT(m_fileItemDelegate
!= 0);
655 const bool showHiddenFiles
= props
.showHiddenFiles();
656 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
657 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
658 m_controller
->setShowHiddenFiles(showHiddenFiles
);
659 emit
showHiddenFilesChanged();
662 m_storedCategorizedSorting
= props
.categorizedSorting();
663 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
664 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
665 m_proxyModel
->setCategorizedModel(categorized
);
666 emit
categorizedSortingChanged();
669 const DolphinView::Sorting sorting
= props
.sorting();
670 if (sorting
!= m_proxyModel
->sorting()) {
671 m_proxyModel
->setSorting(sorting
);
672 emit
sortingChanged(sorting
);
675 const Qt::SortOrder sortOrder
= props
.sortOrder();
676 if (sortOrder
!= m_proxyModel
->sortOrder()) {
677 m_proxyModel
->setSortOrder(sortOrder
);
678 emit
sortOrderChanged(sortOrder
);
681 KFileItemDelegate::InformationList info
= props
.additionalInfo();
682 if (info
!= m_fileItemDelegate
->showInformation()) {
683 m_fileItemDelegate
->setShowInformation(info
);
684 emit
additionalInfoChanged(info
);
687 const bool showPreview
= props
.showPreview();
688 if (showPreview
!= m_controller
->showPreview()) {
689 m_controller
->setShowPreview(showPreview
);
690 emit
showPreviewChanged();
694 void DolphinView::changeSelection(const KFileItemList
& selection
)
697 if (selection
.isEmpty()) {
700 const KUrl
& baseUrl
= url();
702 QItemSelection new_selection
;
703 foreach(const KFileItem
& item
, selection
) {
704 url
= item
.url().upUrl();
705 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
706 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
707 new_selection
.select(index
, index
);
710 itemView()->selectionModel()->select(new_selection
,
711 QItemSelectionModel::ClearAndSelect
712 | QItemSelectionModel::Current
);
715 void DolphinView::openContextMenu(const QPoint
& pos
)
719 const QModelIndex index
= itemView()->indexAt(pos
);
720 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
721 item
= fileItem(index
);
724 emit
requestContextMenu(item
, url());
727 void DolphinView::dropUrls(const KUrl::List
& urls
,
728 const KUrl
& destPath
,
729 const KFileItem
& destItem
,
732 bool dropAboveDir
= false;
733 if (!destItem
.isNull()) {
734 dropAboveDir
= destItem
.isDir();
736 // the dropping is done above a file
739 } else if (source
== itemView()) {
740 // the dropping is done into the same viewport where the dragging
745 const KUrl
& destination
= dropAboveDir
? destItem
.url() : destPath
;
746 dropUrls(urls
, destination
);
749 void DolphinView::dropUrls(const KUrl::List
& urls
,
750 const KUrl
& destination
)
752 emit
urlsDropped(urls
, destination
);
755 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
757 ViewProperties
props(viewPropertiesUrl());
758 props
.setSorting(sorting
);
760 m_proxyModel
->setSorting(sorting
);
762 emit
sortingChanged(sorting
);
765 void DolphinView::updateSortOrder(Qt::SortOrder order
)
767 ViewProperties
props(viewPropertiesUrl());
768 props
.setSortOrder(order
);
770 m_proxyModel
->setSortOrder(order
);
772 emit
sortOrderChanged(order
);
775 void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
777 ViewProperties
props(viewPropertiesUrl());
778 props
.setAdditionalInfo(info
);
780 m_fileItemDelegate
->setShowInformation(info
);
782 emit
additionalInfoChanged(info
);
786 void DolphinView::emitContentsMoved()
788 // only emit the contents moved signal if:
789 // - no directory loading is ongoing (this would reset the contents position
791 // - if the Column View is active: the column view does an automatic
792 // positioning during the loading operation, which must be remembered
793 if (!m_loadingDirectory
|| isColumnViewActive()) {
794 const QPoint
pos(contentsPosition());
795 emit
contentsMoved(pos
.x(), pos
.y());
799 void DolphinView::updateCutItems()
801 // restore the icons of all previously selected items to the
803 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
804 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
806 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
807 if (index
.isValid()) {
808 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
812 m_cutItemsCache
.clear();
814 // ... and apply an item effect to all currently cut items
815 applyCutItemEffect();
818 void DolphinView::showHoverInformation(const KFileItem
& item
)
820 if (hasSelection()) {
824 emit
requestItemInfo(item
);
827 void DolphinView::clearHoverInformation()
829 emit
requestItemInfo(KFileItem());
833 void DolphinView::createView()
835 // delete current view
836 QAbstractItemView
* view
= itemView();
838 m_topLayout
->removeWidget(view
);
845 m_fileItemDelegate
= 0;
848 Q_ASSERT(m_iconsView
== 0);
849 Q_ASSERT(m_detailsView
== 0);
850 Q_ASSERT(m_columnView
== 0);
852 // ... and recreate it representing the current mode
855 m_iconsView
= new DolphinIconsView(this, m_controller
);
861 m_detailsView
= new DolphinDetailsView(this, m_controller
);
862 view
= m_detailsView
;
866 m_columnView
= new DolphinColumnView(this, m_controller
);
873 m_fileItemDelegate
= new KFileItemDelegate(view
);
874 view
->setItemDelegate(m_fileItemDelegate
);
876 view
->setModel(m_proxyModel
);
877 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
879 new KMimeTypeResolver(view
, m_dolphinModel
);
880 m_topLayout
->insertWidget(1, view
);
882 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
883 this, SLOT(emitSelectionChangedSignal()));
884 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
885 this, SLOT(emitContentsMoved()));
886 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
887 this, SLOT(emitContentsMoved()));
890 QAbstractItemView
* DolphinView::itemView() const
892 if (m_detailsView
!= 0) {
893 return m_detailsView
;
894 } else if (m_columnView
!= 0) {
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 const KFileItem item
= *it
;
931 if (isCutItem(item
)) {
932 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
933 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
934 if (value
.type() == QVariant::Icon
) {
935 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
936 QPixmap pixmap
= icon
.pixmap(128, 128);
938 // remember current pixmap for the item to be able
939 // to restore it when other items get cut
941 cutItem
.url
= item
.url();
942 cutItem
.pixmap
= pixmap
;
943 m_cutItemsCache
.append(cutItem
);
945 // apply icon effect to the cut item
946 KIconEffect iconEffect
;
947 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
948 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
955 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
957 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
958 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
959 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
960 iconsView
->setIcon(KIcon("fileview-icon"));
961 iconsView
->setData(QVariant::fromValue(IconsView
));
965 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
967 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
968 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
969 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
970 detailsView
->setIcon(KIcon("fileview-detailed"));
971 detailsView
->setData(QVariant::fromValue(DetailsView
));
975 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
977 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
978 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
979 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
980 columnView
->setIcon(KIcon("fileview-column"));
981 columnView
->setData(QVariant::fromValue(ColumnView
));
985 QString
DolphinView::currentViewModeActionName() const
988 case DolphinView::IconsView
:
990 case DolphinView::DetailsView
:
992 case DolphinView::ColumnView
:
995 return QString(); // can't happen
998 #include "dolphinview.moc"