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_initializeColumnView(false),
64 m_storedCategorizedSorting(false),
65 m_mode(DolphinView::IconsView
),
71 m_fileItemDelegate(0),
72 m_dolphinModel(dolphinModel
),
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 KUrl
&, const QModelIndex
&, QWidget
*)),
97 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)));
98 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
99 this, SLOT(updateSorting(DolphinView::Sorting
)));
100 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
101 this, SLOT(updateSortOrder(Qt::SortOrder
)));
102 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
103 this, SLOT(triggerItem(const QModelIndex
&)));
104 connect(m_controller
, SIGNAL(activated()),
105 this, SLOT(activate()));
106 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
107 this, SLOT(showHoverInformation(const QModelIndex
&)));
108 connect(m_controller
, SIGNAL(viewportEntered()),
109 this, SLOT(clearHoverInformation()));
111 applyViewProperties(url
);
112 m_topLayout
->addWidget(itemView());
115 DolphinView::~DolphinView()
119 const KUrl
& DolphinView::url() const
121 return m_controller
->url();
124 KUrl
DolphinView::rootUrl() const
126 return isColumnViewActive() ? m_dirLister
->url() : url();
129 void DolphinView::setActive(bool active
)
131 if (active
== m_active
) {
137 updateViewportColor();
145 bool DolphinView::isActive() const
150 void DolphinView::setMode(Mode mode
)
152 if (mode
== m_mode
) {
153 return; // the wished mode is already set
158 if (isColumnViewActive()) {
159 // When changing the mode in the column view, it makes sense
160 // to go back to the root URL of the column view automatically.
161 // Otherwise there it would not be possible to turn off the column view
162 // without focusing the first column.
163 setUrl(m_dirLister
->url());
164 m_controller
->setUrl(m_dirLister
->url());
167 const KUrl viewPropsUrl
= viewPropertiesUrl();
168 ViewProperties
props(viewPropsUrl
);
169 props
.setViewMode(m_mode
);
173 // Not all view modes support categorized sorting. Adjust the sorting model
174 // if changing the view mode results in a change of the categorized sorting
176 m_storedCategorizedSorting
= props
.categorizedSorting();
177 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
178 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
179 m_proxyModel
->setCategorizedModel(categorized
);
180 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
181 emit
categorizedSortingChanged();
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 (categorized
== categorizedSorting()) {
238 // setCategorizedSorting(true) may only get invoked
239 // if the view supports categorized sorting
240 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
242 ViewProperties
props(viewPropertiesUrl());
243 props
.setCategorizedSorting(categorized
);
246 m_storedCategorizedSorting
= categorized
;
247 m_proxyModel
->setCategorizedModel(categorized
);
248 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
250 emit
categorizedSortingChanged();
253 bool DolphinView::categorizedSorting() const
255 // If all view modes would support categorized sorting, returning
256 // m_proxyModel->isCategorizedModel() would be the way to go. As
257 // currently only the icons view supports caterized sorting, we remember
258 // the stored view properties state in m_storedCategorizedSorting and
259 // return this state. The application takes care to disable the corresponding
260 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
261 // that this setting is not applied to the current view mode.
262 return m_storedCategorizedSorting
;
265 bool DolphinView::supportsCategorizedSorting() const
267 return m_iconsView
!= 0;
270 void DolphinView::selectAll()
272 itemView()->selectAll();
275 void DolphinView::invertSelection()
277 if (isColumnViewActive()) {
278 // QAbstractItemView does not offer a virtual method invertSelection()
279 // as counterpart to QAbstractItemView::selectAll(). This makes it
280 // necessary to delegate the inverting of the selection to the
281 // column view, as only the selection of the active column should get
283 m_columnView
->invertSelection();
285 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
286 const QAbstractItemModel
* itemModel
= selectionModel
->model();
288 const QModelIndex topLeft
= itemModel
->index(0, 0);
289 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
290 itemModel
->columnCount() - 1);
292 const QItemSelection
selection(topLeft
, bottomRight
);
293 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
297 bool DolphinView::hasSelection() const
299 return itemView()->selectionModel()->hasSelection();
302 void DolphinView::clearSelection()
304 itemView()->selectionModel()->clear();
307 KFileItemList
DolphinView::selectedItems() const
309 const QAbstractItemView
* view
= itemView();
311 // Our view has a selection, we will map them back to the DolphinModel
312 // and then fill the KFileItemList.
313 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
315 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
316 KFileItemList itemList
;
318 const QModelIndexList indexList
= selection
.indexes();
319 foreach (QModelIndex index
, indexList
) {
320 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
321 if (!item
.isNull()) {
322 itemList
.append(item
);
329 KUrl::List
DolphinView::selectedUrls() const
332 const KFileItemList list
= selectedItems();
333 foreach (KFileItem item
, list
) {
334 urls
.append(item
.url());
339 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
341 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
342 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
345 void DolphinView::setContentsPosition(int x
, int y
)
347 QAbstractItemView
* view
= itemView();
349 // the ColumnView takes care itself for the horizontal scrolling
350 if (!isColumnViewActive()) {
351 view
->horizontalScrollBar()->setValue(x
);
353 view
->verticalScrollBar()->setValue(y
);
355 m_loadingDirectory
= false;
358 QPoint
DolphinView::contentsPosition() const
360 const int x
= itemView()->horizontalScrollBar()->value();
361 const int y
= itemView()->verticalScrollBar()->value();
365 void DolphinView::zoomIn()
367 m_controller
->triggerZoomIn();
370 void DolphinView::zoomOut()
372 m_controller
->triggerZoomOut();
375 bool DolphinView::isZoomInPossible() const
377 return m_controller
->isZoomInPossible();
380 bool DolphinView::isZoomOutPossible() const
382 return m_controller
->isZoomOutPossible();
385 void DolphinView::setSorting(Sorting sorting
)
387 if (sorting
!= this->sorting()) {
388 updateSorting(sorting
);
392 DolphinView::Sorting
DolphinView::sorting() const
394 return m_proxyModel
->sorting();
397 void DolphinView::setSortOrder(Qt::SortOrder order
)
399 if (sortOrder() != order
) {
400 updateSortOrder(order
);
404 Qt::SortOrder
DolphinView::sortOrder() const
406 return m_proxyModel
->sortOrder();
409 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
411 const KUrl viewPropsUrl
= viewPropertiesUrl();
412 ViewProperties
props(viewPropsUrl
);
413 props
.setAdditionalInfo(info
);
415 m_controller
->setAdditionalInfoCount(info
.count());
416 m_fileItemDelegate
->setShowInformation(info
);
418 emit
additionalInfoChanged(info
);
419 startDirLister(viewPropsUrl
, true);
422 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
424 return m_fileItemDelegate
->showInformation();
427 void DolphinView::reload()
430 startDirLister(url(), true);
433 void DolphinView::refresh()
436 applyViewProperties(m_controller
->url());
438 updateViewportColor();
441 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
443 if (m_controller
->url() == url
) {
447 const bool restoreColumnView
= !rootUrl
.isEmpty()
448 && !rootUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)
449 && rootUrl
.isParentOf(url
);
451 m_controller
->setUrl(url
); // emits urlChanged, which we forward
453 if (restoreColumnView
) {
454 applyViewProperties(rootUrl
);
455 startDirLister(rootUrl
);
456 // Restoring the column view relies on the URL-history. It might be possible
457 // that the view properties have been changed or deleted in the meantime, so
458 // it cannot be asserted that really a column view has been created:
459 if (itemView() == m_columnView
) {
460 m_columnView
->showColumn(url
);
463 applyViewProperties(url
);
467 itemView()->setFocus();
469 emit
startedPathLoading(url
);
472 void DolphinView::setUrl(const KUrl
& url
)
474 updateView(url
, KUrl());
477 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
479 QWidget::mouseReleaseEvent(event
);
482 void DolphinView::activate()
487 void DolphinView::triggerItem(const QModelIndex
& index
)
489 Q_ASSERT(index
.isValid());
491 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
492 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
493 // items are selected by the user, hence don't trigger the
494 // item specified by 'index'
498 const KFileItem item
= m_dolphinModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
504 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
507 void DolphinView::generatePreviews(const KFileItemList
& items
)
509 if (m_controller
->showPreview()) {
510 KIO::PreviewJob
* job
= KIO::filePreview(items
, 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_dolphinModel
->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
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
531 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
533 m_dolphinModel
->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;
560 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
561 m_initializeColumnView
= false;
564 // keeping old directories is only necessary for hierarchical views
565 // like the column view
567 // for the column view it is not enough to reload the directory lister,
568 // so this task is delegated to the column view directly
569 m_columnView
->reload();
570 } else if (m_dirLister
->directories().contains(url
)) {
571 // The dir lister contains the directory already, so
572 // KDirLister::openUrl() may not get invoked twice.
573 m_dirLister
->updateDirectory(url
);
575 const KUrl
& dirListerUrl
= m_dirLister
->url();
576 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
577 // The current URL is not a child of the dir lister
578 // URL. This may happen when e. g. a place has been selected
579 // and hence the view must be reset.
580 m_dirLister
->openUrl(url
, KDirLister::NoFlags
);
584 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
588 KUrl
DolphinView::viewPropertiesUrl() const
590 if (isColumnViewActive()) {
591 return m_dirLister
->url();
597 void DolphinView::applyViewProperties(const KUrl
& url
)
599 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
600 // The column view is active, hence don't apply the view properties
601 // of sub directories (represented by columns) to the view. The
602 // view always represents the properties of the first column.
606 const ViewProperties
props(url
);
608 const Mode mode
= props
.viewMode();
609 if (m_mode
!= mode
) {
614 if (m_mode
== ColumnView
) {
615 // The mode has been changed to the Column View. When starting the dir
616 // lister with DolphinView::startDirLister() it is important to give a
617 // hint that the dir lister may not keep the current directory
618 // although this is the default for showing a hierarchy.
619 m_initializeColumnView
= true;
622 if (itemView() == 0) {
625 Q_ASSERT(itemView() != 0);
626 Q_ASSERT(m_fileItemDelegate
!= 0);
628 const bool showHiddenFiles
= props
.showHiddenFiles();
629 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
630 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
631 emit
showHiddenFilesChanged();
634 m_storedCategorizedSorting
= props
.categorizedSorting();
635 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
636 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
637 m_proxyModel
->setCategorizedModel(categorized
);
638 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
639 emit
categorizedSortingChanged();
642 const DolphinView::Sorting sorting
= props
.sorting();
643 if (sorting
!= m_proxyModel
->sorting()) {
644 m_proxyModel
->setSorting(sorting
);
645 emit
sortingChanged(sorting
);
648 const Qt::SortOrder sortOrder
= props
.sortOrder();
649 if (sortOrder
!= m_proxyModel
->sortOrder()) {
650 m_proxyModel
->setSortOrder(sortOrder
);
651 emit
sortOrderChanged(sortOrder
);
654 KFileItemDelegate::InformationList info
= props
.additionalInfo();
655 if (info
!= m_fileItemDelegate
->showInformation()) {
656 m_controller
->setAdditionalInfoCount(info
.count());
657 m_fileItemDelegate
->setShowInformation(info
);
658 emit
additionalInfoChanged(info
);
661 const bool showPreview
= props
.showPreview();
662 if (showPreview
!= m_controller
->showPreview()) {
663 m_controller
->setShowPreview(showPreview
);
664 emit
showPreviewChanged();
668 void DolphinView::changeSelection(const KFileItemList
& selection
)
671 if (selection
.isEmpty()) {
674 const KUrl
& baseUrl
= url();
676 QItemSelection new_selection
;
677 foreach(const KFileItem
& item
, selection
) {
678 url
= item
.url().upUrl();
679 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
680 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
681 new_selection
.select(index
, index
);
684 itemView()->selectionModel()->select(new_selection
,
685 QItemSelectionModel::ClearAndSelect
686 | QItemSelectionModel::Current
);
689 void DolphinView::openContextMenu(const QPoint
& pos
)
693 const QModelIndex index
= itemView()->indexAt(pos
);
694 if (isValidNameIndex(index
)) {
695 item
= fileItem(index
);
698 emit
requestContextMenu(item
, url());
701 void DolphinView::dropUrls(const KUrl::List
& urls
,
702 const KUrl
& destPath
,
703 const QModelIndex
& destIndex
,
707 if (isValidNameIndex(destIndex
)) {
708 KFileItem item
= fileItem(destIndex
);
709 Q_ASSERT(!item
.isNull());
711 // the URLs are dropped above a directory
716 if ((directory
.isNull()) && (source
== itemView())) {
717 // The dropping is done into the same viewport where
718 // the dragging has been started. Just ignore this...
722 const KUrl
& destination
= (directory
.isNull()) ?
723 destPath
: directory
.url();
724 dropUrls(urls
, destination
);
727 void DolphinView::dropUrls(const KUrl::List
& urls
,
728 const KUrl
& destination
)
730 emit
urlsDropped(urls
, destination
);
733 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
735 ViewProperties
props(viewPropertiesUrl());
736 props
.setSorting(sorting
);
738 m_proxyModel
->setSorting(sorting
);
740 emit
sortingChanged(sorting
);
743 void DolphinView::updateSortOrder(Qt::SortOrder order
)
745 ViewProperties
props(viewPropertiesUrl());
746 props
.setSortOrder(order
);
748 m_proxyModel
->setSortOrder(order
);
750 emit
sortOrderChanged(order
);
753 void DolphinView::emitContentsMoved()
755 // only emit the contents moved signal if:
756 // - no directory loading is ongoing (this would reset the contents position
758 // - if the Column View is active: the column view does an automatic
759 // positioning during the loading operation, which must be remembered
760 if (!m_loadingDirectory
|| isColumnViewActive()) {
761 const QPoint
pos(contentsPosition());
762 emit
contentsMoved(pos
.x(), pos
.y());
766 void DolphinView::updateCutItems()
768 // restore the icons of all previously selected items to the
770 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
771 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
773 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
774 if (index
.isValid()) {
775 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
779 m_cutItemsCache
.clear();
781 // ... and apply an item effect to all currently cut items
782 applyCutItemEffect();
785 void DolphinView::showHoverInformation(const QModelIndex
& index
)
787 if (hasSelection()) {
791 const KFileItem item
= fileItem(index
);
792 if (!item
.isNull()) {
793 emit
requestItemInfo(item
);
797 void DolphinView::clearHoverInformation()
799 emit
requestItemInfo(KFileItem());
803 void DolphinView::createView()
805 KFileItemDelegate::InformationList infoList
;
806 if (m_fileItemDelegate
!= 0) {
807 infoList
= m_fileItemDelegate
->showInformation();
810 // delete current view
811 QAbstractItemView
* view
= itemView();
813 m_topLayout
->removeWidget(view
);
820 m_fileItemDelegate
= 0;
823 Q_ASSERT(m_iconsView
== 0);
824 Q_ASSERT(m_detailsView
== 0);
825 Q_ASSERT(m_columnView
== 0);
827 // ... and recreate it representing the current mode
830 m_iconsView
= new DolphinIconsView(this, m_controller
);
836 m_detailsView
= new DolphinDetailsView(this, m_controller
);
837 view
= m_detailsView
;
841 m_columnView
= new DolphinColumnView(this, m_controller
);
848 m_fileItemDelegate
= new KFileItemDelegate(view
);
849 m_fileItemDelegate
->setShowInformation(infoList
);
850 view
->setItemDelegate(m_fileItemDelegate
);
852 view
->setModel(m_proxyModel
);
853 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
855 new KMimeTypeResolver(view
, m_dolphinModel
);
856 m_topLayout
->insertWidget(1, view
);
858 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
859 this, SLOT(emitSelectionChangedSignal()));
860 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
861 this, SLOT(emitContentsMoved()));
862 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
863 this, SLOT(emitContentsMoved()));
867 QAbstractItemView
* DolphinView::itemView() const
869 if (m_detailsView
!= 0) {
870 return m_detailsView
;
871 } else if (m_columnView
!= 0) {
878 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
880 return index
.isValid() && (index
.column() == DolphinModel::Name
);
883 bool DolphinView::isCutItem(const KFileItem
& item
) const
885 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
886 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
888 const KUrl
& itemUrl
= item
.url();
889 KUrl::List::const_iterator it
= cutUrls
.begin();
890 const KUrl::List::const_iterator end
= cutUrls
.end();
892 if (*it
== itemUrl
) {
901 void DolphinView::applyCutItemEffect()
903 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
904 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
908 KFileItemList
items(m_dirLister
->items());
909 KFileItemList::const_iterator it
= items
.begin();
910 const KFileItemList::const_iterator end
= items
.end();
912 const KFileItem item
= *it
;
913 if (isCutItem(item
)) {
914 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
915 // Huh? the item is already known
916 //const KFileItem item = m_dolphinModel->itemForIndex(index);
917 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
918 if (value
.type() == QVariant::Icon
) {
919 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
920 QPixmap pixmap
= icon
.pixmap(128, 128);
922 // remember current pixmap for the item to be able
923 // to restore it when other items get cut
925 cutItem
.url
= item
.url();
926 cutItem
.pixmap
= pixmap
;
927 m_cutItemsCache
.append(cutItem
);
929 // apply icon effect to the cut item
930 KIconEffect iconEffect
;
931 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
932 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
939 void DolphinView::updateViewportColor()
941 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
943 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
944 emit
selectionChanged(selectedItems());
949 QWidget
* viewport
= itemView()->viewport();
951 palette
.setColor(viewport
->backgroundRole(), color
);
952 viewport
->setPalette(palette
);
955 #include "dolphinview.moc"