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
) :
65 m_loadingDirectory(false),
66 m_storedCategorizedSorting(false),
67 m_mode(DolphinView::IconsView
),
73 m_fileItemDelegate(0),
74 m_dolphinModel(dolphinModel
),
75 m_dirLister(dirLister
),
76 m_proxyModel(proxyModel
)
78 setFocusPolicy(Qt::StrongFocus
);
79 m_topLayout
= new QVBoxLayout(this);
80 m_topLayout
->setSpacing(0);
81 m_topLayout
->setMargin(0);
83 QClipboard
* clipboard
= QApplication::clipboard();
84 connect(clipboard
, SIGNAL(dataChanged()),
85 this, SLOT(updateCutItems()));
87 connect(m_dirLister
, SIGNAL(completed()),
88 this, SLOT(updateCutItems()));
89 connect(m_dirLister
, SIGNAL(newItems(const KFileItemList
&)),
90 this, SLOT(generatePreviews(const KFileItemList
&)));
92 m_controller
= new DolphinController(this);
93 m_controller
->setUrl(url
);
95 // Receiver of the DolphinView signal 'urlChanged()' don't need
96 // to care whether the internal controller changed the URL already or whether
97 // the controller just requested an URL change and will be updated later.
98 // In both cases the URL has been changed:
99 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
100 this, SIGNAL(urlChanged(const KUrl
&)));
101 connect(m_controller
, SIGNAL(requestUrlChange(const KUrl
&)),
102 this, SIGNAL(urlChanged(const KUrl
&)));
104 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
105 this, SLOT(openContextMenu(const QPoint
&)));
106 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const KFileItem
&)),
107 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const KFileItem
&)));
108 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
109 this, SLOT(updateSorting(DolphinView::Sorting
)));
110 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
111 this, SLOT(updateSortOrder(Qt::SortOrder
)));
112 connect(m_controller
, SIGNAL(additionalInfoChanged(const KFileItemDelegate::InformationList
&)),
113 this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList
&)));
114 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
115 this, SLOT(triggerItem(const KFileItem
&)));
116 connect(m_controller
, SIGNAL(activated()),
117 this, SLOT(activate()));
118 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
119 this, SLOT(showHoverInformation(const KFileItem
&)));
120 connect(m_controller
, SIGNAL(viewportEntered()),
121 this, SLOT(clearHoverInformation()));
123 applyViewProperties(url
);
124 m_topLayout
->addWidget(itemView());
127 DolphinView::~DolphinView()
131 const KUrl
& DolphinView::url() const
133 return m_controller
->url();
136 KUrl
DolphinView::rootUrl() const
138 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
141 void DolphinView::setActive(bool active
)
143 if (active
== m_active
) {
149 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
151 // TODO: emitting urlChanged() is a hack, as the URL hasn't really changed. It
152 // bypasses the problem when having a split view and changing the active view to
153 // update the some URL dependent states. A nicer approach should be no big deal...
154 emit
urlChanged(url());
155 emit
selectionChanged(selectedItems());
160 QWidget
* viewport
= itemView()->viewport();
162 palette
.setColor(viewport
->backgroundRole(), color
);
163 viewport
->setPalette(palette
);
171 m_controller
->indicateActivationChange(active
);
174 bool DolphinView::isActive() const
179 void DolphinView::setMode(Mode mode
)
181 if (mode
== m_mode
) {
182 return; // the wished mode is already set
187 if (isColumnViewActive()) {
188 // When changing the mode in the column view, it makes sense
189 // to go back to the root URL of the column view automatically.
190 // Otherwise there it would not be possible to turn off the column view
191 // without focusing the first column.
192 const KUrl root
= rootUrl();
194 m_controller
->setUrl(root
);
199 // It is important to read the view properties _after_ deleting the view,
200 // as e. g. the detail view might adjust the additional information properties
201 // after getting closed:
202 const KUrl viewPropsUrl
= viewPropertiesUrl();
203 ViewProperties
props(viewPropsUrl
);
204 props
.setViewMode(m_mode
);
208 // the file item delegate has been recreated, apply the current
209 // additional information manually
210 const KFileItemDelegate::InformationList infoList
= props
.additionalInfo();
211 m_fileItemDelegate
->setShowInformation(infoList
);
212 emit
additionalInfoChanged(infoList
);
214 // Not all view modes support categorized sorting. Adjust the sorting model
215 // if changing the view mode results in a change of the categorized sorting
217 m_storedCategorizedSorting
= props
.categorizedSorting();
218 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
219 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
220 m_proxyModel
->setCategorizedModel(categorized
);
221 emit
categorizedSortingChanged();
224 loadDirectory(viewPropsUrl
);
229 DolphinView::Mode
DolphinView::mode() const
234 void DolphinView::setShowPreview(bool show
)
236 if (m_showPreview
== show
) {
240 const KUrl viewPropsUrl
= viewPropertiesUrl();
241 ViewProperties
props(viewPropsUrl
);
242 props
.setShowPreview(show
);
244 m_showPreview
= show
;
246 emit
showPreviewChanged();
248 loadDirectory(viewPropsUrl
, true);
251 bool DolphinView::showPreview() const
253 return m_showPreview
;
256 void DolphinView::setShowHiddenFiles(bool show
)
258 if (m_dirLister
->showingDotFiles() == show
) {
262 const KUrl viewPropsUrl
= viewPropertiesUrl();
263 ViewProperties
props(viewPropsUrl
);
264 props
.setShowHiddenFiles(show
);
266 m_dirLister
->setShowingDotFiles(show
);
267 emit
showHiddenFilesChanged();
269 loadDirectory(viewPropsUrl
, true);
272 bool DolphinView::showHiddenFiles() const
274 return m_dirLister
->showingDotFiles();
277 void DolphinView::setCategorizedSorting(bool categorized
)
279 if (categorized
== categorizedSorting()) {
283 // setCategorizedSorting(true) may only get invoked
284 // if the view supports categorized sorting
285 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
287 ViewProperties
props(viewPropertiesUrl());
288 props
.setCategorizedSorting(categorized
);
291 m_storedCategorizedSorting
= categorized
;
292 m_proxyModel
->setCategorizedModel(categorized
);
294 emit
categorizedSortingChanged();
297 bool DolphinView::categorizedSorting() const
299 // If all view modes would support categorized sorting, returning
300 // m_proxyModel->isCategorizedModel() would be the way to go. As
301 // currently only the icons view supports caterized sorting, we remember
302 // the stored view properties state in m_storedCategorizedSorting and
303 // return this state. The application takes care to disable the corresponding
304 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
305 // that this setting is not applied to the current view mode.
306 return m_storedCategorizedSorting
;
309 bool DolphinView::supportsCategorizedSorting() const
311 return m_iconsView
!= 0;
314 void DolphinView::selectAll()
316 itemView()->selectAll();
319 void DolphinView::invertSelection()
321 if (isColumnViewActive()) {
322 // QAbstractItemView does not offer a virtual method invertSelection()
323 // as counterpart to QAbstractItemView::selectAll(). This makes it
324 // necessary to delegate the inverting of the selection to the
325 // column view, as only the selection of the active column should
327 m_columnView
->invertSelection();
329 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
330 const QAbstractItemModel
* itemModel
= selectionModel
->model();
332 const QModelIndex topLeft
= itemModel
->index(0, 0);
333 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
334 itemModel
->columnCount() - 1);
336 const QItemSelection
selection(topLeft
, bottomRight
);
337 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
341 bool DolphinView::hasSelection() const
343 return itemView()->selectionModel()->hasSelection();
346 void DolphinView::clearSelection()
348 itemView()->selectionModel()->clear();
351 KFileItemList
DolphinView::selectedItems() const
353 const QAbstractItemView
* view
= itemView();
355 // Our view has a selection, we will map them back to the DolphinModel
356 // and then fill the KFileItemList.
357 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
359 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
360 KFileItemList itemList
;
362 const QModelIndexList indexList
= selection
.indexes();
363 foreach (QModelIndex index
, indexList
) {
364 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
365 if (!item
.isNull()) {
366 itemList
.append(item
);
373 KUrl::List
DolphinView::selectedUrls() const
376 const KFileItemList list
= selectedItems();
377 foreach (KFileItem item
, list
) {
378 urls
.append(item
.url());
383 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
385 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
386 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
389 void DolphinView::setContentsPosition(int x
, int y
)
391 QAbstractItemView
* view
= itemView();
393 // the ColumnView takes care itself for the horizontal scrolling
394 if (!isColumnViewActive()) {
395 view
->horizontalScrollBar()->setValue(x
);
397 view
->verticalScrollBar()->setValue(y
);
399 m_loadingDirectory
= false;
402 QPoint
DolphinView::contentsPosition() const
404 const int x
= itemView()->horizontalScrollBar()->value();
405 const int y
= itemView()->verticalScrollBar()->value();
409 void DolphinView::zoomIn()
411 m_controller
->triggerZoomIn();
414 void DolphinView::zoomOut()
416 m_controller
->triggerZoomOut();
419 bool DolphinView::isZoomInPossible() const
421 return m_controller
->isZoomInPossible();
424 bool DolphinView::isZoomOutPossible() const
426 return m_controller
->isZoomOutPossible();
429 void DolphinView::setSorting(Sorting sorting
)
431 if (sorting
!= this->sorting()) {
432 updateSorting(sorting
);
436 DolphinView::Sorting
DolphinView::sorting() const
438 return m_proxyModel
->sorting();
441 void DolphinView::setSortOrder(Qt::SortOrder order
)
443 if (sortOrder() != order
) {
444 updateSortOrder(order
);
448 Qt::SortOrder
DolphinView::sortOrder() const
450 return m_proxyModel
->sortOrder();
453 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
455 const KUrl viewPropsUrl
= viewPropertiesUrl();
456 ViewProperties
props(viewPropsUrl
);
457 props
.setAdditionalInfo(info
);
458 m_fileItemDelegate
->setShowInformation(info
);
460 emit
additionalInfoChanged(info
);
462 if (itemView() != m_detailsView
) {
463 // the details view requires no reloading of the directory, as it maps
464 // the file item delegate info to its columns internally
465 loadDirectory(viewPropsUrl
, true);
469 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
471 return m_fileItemDelegate
->showInformation();
474 void DolphinView::reload()
477 loadDirectory(url(), true);
480 void DolphinView::refresh()
482 const bool oldActivationState
= m_active
;
486 applyViewProperties(m_controller
->url());
489 setActive(oldActivationState
);
492 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
494 if (m_controller
->url() == url
) {
498 m_controller
->setUrl(url
); // emits urlChanged, which we forward
500 if (!rootUrl
.isEmpty() && rootUrl
.isParentOf(url
)) {
501 applyViewProperties(rootUrl
);
502 loadDirectory(rootUrl
);
503 if (itemView() == m_columnView
) {
504 m_columnView
->setRootUrl(rootUrl
);
505 m_columnView
->showColumn(url
);
508 applyViewProperties(url
);
512 emit
startedPathLoading(url
);
515 void DolphinView::setNameFilter(const QString
& nameFilter
)
517 m_proxyModel
->setFilterRegExp(nameFilter
);
519 if (isColumnViewActive()) {
520 // adjusting the directory lister is not enough in the case of the
521 // column view, as each column has its own directory lister internally...
522 m_columnView
->setNameFilter(nameFilter
);
526 void DolphinView::calculateItemCount(int& fileCount
, int& folderCount
)
528 foreach (KFileItem item
, m_dirLister
->items()) {
537 void DolphinView::setUrl(const KUrl
& url
)
539 updateView(url
, KUrl());
542 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
544 QWidget::mouseReleaseEvent(event
);
547 void DolphinView::activate()
552 void DolphinView::triggerItem(const KFileItem
& item
)
554 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
555 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
556 // items are selected by the user, hence don't trigger the
557 // item specified by 'index'
565 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
568 void DolphinView::generatePreviews(const KFileItemList
& items
)
570 if (m_controller
->dolphinView()->showPreview()) {
571 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
572 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
573 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
577 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
579 Q_ASSERT(!item
.isNull());
580 if (item
.url().directory() != m_dirLister
->url().path()) {
581 // the preview job is still working on items of an older URL, hence
582 // the item is not part of the directory model anymore
586 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
587 if (idx
.isValid() && (idx
.column() == 0)) {
588 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
589 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
590 KIconEffect iconEffect
;
591 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
592 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
594 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
599 void DolphinView::emitSelectionChangedSignal()
601 emit
selectionChanged(DolphinView::selectedItems());
604 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
606 if (!url
.isValid()) {
607 const QString
location(url
.pathOrUrl());
608 if (location
.isEmpty()) {
609 emit
errorMessage(i18nc("@info:status", "The location is empty."));
611 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
616 m_cutItemsCache
.clear();
617 m_loadingDirectory
= true;
620 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
622 if (isColumnViewActive()) {
623 // adjusting the directory lister is not enough in the case of the
624 // column view, as each column has its own directory lister internally...
626 m_columnView
->reload();
628 m_columnView
->showColumn(url
);
633 KUrl
DolphinView::viewPropertiesUrl() const
635 if (isColumnViewActive()) {
636 return m_dirLister
->url();
642 void DolphinView::applyViewProperties(const KUrl
& url
)
644 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
645 // The column view is active, hence don't apply the view properties
646 // of sub directories (represented by columns) to the view. The
647 // view always represents the properties of the first column.
651 const ViewProperties
props(url
);
653 const Mode mode
= props
.viewMode();
654 if (m_mode
!= mode
) {
659 if (itemView() == 0) {
662 Q_ASSERT(itemView() != 0);
663 Q_ASSERT(m_fileItemDelegate
!= 0);
665 const bool showHiddenFiles
= props
.showHiddenFiles();
666 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
667 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
668 emit
showHiddenFilesChanged();
671 m_storedCategorizedSorting
= props
.categorizedSorting();
672 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
673 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
674 m_proxyModel
->setCategorizedModel(categorized
);
675 emit
categorizedSortingChanged();
678 const DolphinView::Sorting sorting
= props
.sorting();
679 if (sorting
!= m_proxyModel
->sorting()) {
680 m_proxyModel
->setSorting(sorting
);
681 emit
sortingChanged(sorting
);
684 const Qt::SortOrder sortOrder
= props
.sortOrder();
685 if (sortOrder
!= m_proxyModel
->sortOrder()) {
686 m_proxyModel
->setSortOrder(sortOrder
);
687 emit
sortOrderChanged(sortOrder
);
690 KFileItemDelegate::InformationList info
= props
.additionalInfo();
691 if (info
!= m_fileItemDelegate
->showInformation()) {
692 m_fileItemDelegate
->setShowInformation(info
);
693 emit
additionalInfoChanged(info
);
696 const bool showPreview
= props
.showPreview();
697 if (showPreview
!= m_showPreview
) {
698 m_showPreview
= showPreview
;
699 emit
showPreviewChanged();
703 void DolphinView::changeSelection(const KFileItemList
& selection
)
706 if (selection
.isEmpty()) {
709 const KUrl
& baseUrl
= url();
711 QItemSelection new_selection
;
712 foreach(const KFileItem
& item
, selection
) {
713 url
= item
.url().upUrl();
714 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
715 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
716 new_selection
.select(index
, index
);
719 itemView()->selectionModel()->select(new_selection
,
720 QItemSelectionModel::ClearAndSelect
721 | QItemSelectionModel::Current
);
724 void DolphinView::openContextMenu(const QPoint
& pos
)
728 const QModelIndex index
= itemView()->indexAt(pos
);
729 if (index
.isValid() && (index
.column() == DolphinModel::Name
)) {
730 item
= fileItem(index
);
733 emit
requestContextMenu(item
, url());
736 void DolphinView::dropUrls(const KUrl::List
& urls
,
737 const KUrl
& destPath
,
738 const KFileItem
& destItem
)
740 const KUrl
& destination
= !destItem
.isNull() && destItem
.isDir() ?
741 destItem
.url() : destPath
;
742 const KUrl sourceDir
= KUrl(urls
.first().directory());
743 if (sourceDir
!= destination
) {
744 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::updateAdditionalInfo(const KFileItemDelegate::InformationList
& info
)
776 ViewProperties
props(viewPropertiesUrl());
777 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()
836 Q_ASSERT(m_iconsView
== 0);
837 Q_ASSERT(m_detailsView
== 0);
838 Q_ASSERT(m_columnView
== 0);
840 QAbstractItemView
* view
= 0;
843 m_iconsView
= new DolphinIconsView(this, m_controller
);
849 m_detailsView
= new DolphinDetailsView(this, m_controller
);
850 view
= m_detailsView
;
854 m_columnView
= new DolphinColumnView(this, m_controller
);
861 m_fileItemDelegate
= new KFileItemDelegate(view
);
862 view
->setItemDelegate(m_fileItemDelegate
);
864 view
->setModel(m_proxyModel
);
865 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
867 new KMimeTypeResolver(view
, m_dolphinModel
);
868 m_topLayout
->insertWidget(1, view
);
870 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
871 this, SLOT(emitSelectionChangedSignal()));
872 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
873 this, SLOT(emitContentsMoved()));
874 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
875 this, SLOT(emitContentsMoved()));
878 void DolphinView::deleteView()
880 QAbstractItemView
* view
= itemView();
882 m_topLayout
->removeWidget(view
);
889 m_fileItemDelegate
= 0;
893 QAbstractItemView
* DolphinView::itemView() const
895 if (m_detailsView
!= 0) {
896 return m_detailsView
;
897 } else if (m_columnView
!= 0) {
904 bool DolphinView::isCutItem(const KFileItem
& item
) const
906 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
907 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
909 const KUrl
& itemUrl
= item
.url();
910 KUrl::List::const_iterator it
= cutUrls
.begin();
911 const KUrl::List::const_iterator end
= cutUrls
.end();
913 if (*it
== itemUrl
) {
922 void DolphinView::applyCutItemEffect()
924 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
925 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
929 KFileItemList
items(m_dirLister
->items());
930 KFileItemList::const_iterator it
= items
.begin();
931 const KFileItemList::const_iterator end
= items
.end();
933 const KFileItem item
= *it
;
934 if (isCutItem(item
)) {
935 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
936 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
937 if (value
.type() == QVariant::Icon
) {
938 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
939 QPixmap pixmap
= icon
.pixmap(128, 128);
941 // remember current pixmap for the item to be able
942 // to restore it when other items get cut
944 cutItem
.url
= item
.url();
945 cutItem
.pixmap
= pixmap
;
946 m_cutItemsCache
.append(cutItem
);
948 // apply icon effect to the cut item
949 KIconEffect iconEffect
;
950 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
951 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
958 KToggleAction
* DolphinView::iconsModeAction(KActionCollection
* actionCollection
)
960 KToggleAction
* iconsView
= actionCollection
->add
<KToggleAction
>("icons");
961 iconsView
->setText(i18nc("@action:inmenu View Mode", "Icons"));
962 iconsView
->setShortcut(Qt::CTRL
| Qt::Key_1
);
963 iconsView
->setIcon(KIcon("fileview-icon"));
964 iconsView
->setData(QVariant::fromValue(IconsView
));
968 KToggleAction
* DolphinView::detailsModeAction(KActionCollection
* actionCollection
)
970 KToggleAction
* detailsView
= actionCollection
->add
<KToggleAction
>("details");
971 detailsView
->setText(i18nc("@action:inmenu View Mode", "Details"));
972 detailsView
->setShortcut(Qt::CTRL
| Qt::Key_2
);
973 detailsView
->setIcon(KIcon("fileview-detailed"));
974 detailsView
->setData(QVariant::fromValue(DetailsView
));
978 KToggleAction
* DolphinView::columnsModeAction(KActionCollection
* actionCollection
)
980 KToggleAction
* columnView
= actionCollection
->add
<KToggleAction
>("columns");
981 columnView
->setText(i18nc("@action:inmenu View Mode", "Columns"));
982 columnView
->setShortcut(Qt::CTRL
| Qt::Key_3
);
983 columnView
->setIcon(KIcon("fileview-column"));
984 columnView
->setData(QVariant::fromValue(ColumnView
));
988 QString
DolphinView::currentViewModeActionName() const
991 case DolphinView::IconsView
:
993 case DolphinView::DetailsView
:
995 case DolphinView::ColumnView
:
998 return QString(); // can't happen
1001 #include "dolphinview.moc"