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
);
91 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
92 this, SIGNAL(urlChanged(const KUrl
&)));
93 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
94 this, SLOT(openContextMenu(const QPoint
&)));
95 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)),
96 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)));
97 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
98 this, SLOT(updateSorting(DolphinView::Sorting
)));
99 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
100 this, SLOT(updateSortOrder(Qt::SortOrder
)));
101 connect(m_controller
, SIGNAL(itemTriggered(const KFileItem
&)),
102 this, SLOT(triggerItem(const KFileItem
&)));
103 connect(m_controller
, SIGNAL(activated()),
104 this, SLOT(activate()));
105 connect(m_controller
, SIGNAL(itemEntered(const KFileItem
&)),
106 this, SLOT(showHoverInformation(const KFileItem
&)));
107 connect(m_controller
, SIGNAL(viewportEntered()),
108 this, SLOT(clearHoverInformation()));
110 applyViewProperties(url
);
111 m_topLayout
->addWidget(itemView());
114 DolphinView::~DolphinView()
118 const KUrl
& DolphinView::url() const
120 return m_controller
->url();
123 KUrl
DolphinView::rootUrl() const
125 return isColumnViewActive() ? m_columnView
->rootUrl() : url();
128 void DolphinView::setActive(bool active
)
130 if (active
== m_active
) {
136 updateViewportColor();
144 bool DolphinView::isActive() const
149 void DolphinView::setMode(Mode mode
)
151 if (mode
== m_mode
) {
152 return; // the wished mode is already set
157 if (isColumnViewActive()) {
158 // When changing the mode in the column view, it makes sense
159 // to go back to the root URL of the column view automatically.
160 // Otherwise there it would not be possible to turn off the column view
161 // without focusing the first column.
162 setUrl(m_dirLister
->url());
163 m_controller
->setUrl(m_dirLister
->url());
166 const KUrl viewPropsUrl
= viewPropertiesUrl();
167 ViewProperties
props(viewPropsUrl
);
168 props
.setViewMode(m_mode
);
172 // Not all view modes support categorized sorting. Adjust the sorting model
173 // if changing the view mode results in a change of the categorized sorting
175 m_storedCategorizedSorting
= props
.categorizedSorting();
176 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
177 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
178 m_proxyModel
->setCategorizedModel(categorized
);
179 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
180 emit
categorizedSortingChanged();
183 loadDirectory(viewPropsUrl
);
188 DolphinView::Mode
DolphinView::mode() const
193 void DolphinView::setShowPreview(bool show
)
195 const KUrl viewPropsUrl
= viewPropertiesUrl();
196 ViewProperties
props(viewPropsUrl
);
197 props
.setShowPreview(show
);
199 m_controller
->setShowPreview(show
);
200 emit
showPreviewChanged();
202 loadDirectory(viewPropsUrl
, true);
205 bool DolphinView::showPreview() const
207 return m_controller
->showPreview();
210 void DolphinView::setShowHiddenFiles(bool show
)
212 if (m_dirLister
->showingDotFiles() == show
) {
216 const KUrl viewPropsUrl
= viewPropertiesUrl();
217 ViewProperties
props(viewPropsUrl
);
218 props
.setShowHiddenFiles(show
);
220 m_dirLister
->setShowingDotFiles(show
);
221 m_controller
->setShowHiddenFiles(show
);
222 emit
showHiddenFilesChanged();
224 loadDirectory(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
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 loadDirectory(viewPropsUrl
, true);
422 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
424 return m_fileItemDelegate
->showInformation();
427 void DolphinView::reload()
430 loadDirectory(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 loadDirectory(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
->setRootUrl(rootUrl
);
461 m_columnView
->showColumn(url
);
464 applyViewProperties(url
);
468 itemView()->setFocus();
470 emit
startedPathLoading(url
);
473 void DolphinView::setUrl(const KUrl
& url
)
475 updateView(url
, KUrl());
478 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
480 QWidget::mouseReleaseEvent(event
);
483 void DolphinView::activate()
488 void DolphinView::triggerItem(const KFileItem
& item
)
490 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
491 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
492 // items are selected by the user, hence don't trigger the
493 // item specified by 'index'
501 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
504 void DolphinView::generatePreviews(const KFileItemList
& items
)
506 if (m_controller
->showPreview()) {
507 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
508 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
509 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
513 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
515 Q_ASSERT(!item
.isNull());
516 if (item
.url().directory() != m_dirLister
->url().path()) {
517 // the preview job is still working on items of an older URL, hence
518 // the item is not part of the directory model anymore
522 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
523 if (idx
.isValid() && (idx
.column() == 0)) {
524 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
525 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
526 KIconEffect iconEffect
;
527 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
528 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
530 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
535 void DolphinView::emitSelectionChangedSignal()
537 emit
selectionChanged(DolphinView::selectedItems());
540 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
542 if (!url
.isValid()) {
543 const QString
location(url
.pathOrUrl());
544 if (location
.isEmpty()) {
545 emit
errorMessage(i18nc("@info:status", "The location is empty."));
547 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
552 m_cutItemsCache
.clear();
553 m_loadingDirectory
= true;
556 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
558 if (isColumnViewActive()) {
559 // adjusting the directory lister is not enough in the case of the
560 // column view, as each column has its own directory lister internally...
562 m_columnView
->reload();
564 m_columnView
->showColumn(url
);
569 KUrl
DolphinView::viewPropertiesUrl() const
571 if (isColumnViewActive()) {
572 return m_dirLister
->url();
578 void DolphinView::applyViewProperties(const KUrl
& url
)
580 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
581 // The column view is active, hence don't apply the view properties
582 // of sub directories (represented by columns) to the view. The
583 // view always represents the properties of the first column.
587 const ViewProperties
props(url
);
589 const Mode mode
= props
.viewMode();
590 if (m_mode
!= mode
) {
595 if (itemView() == 0) {
598 Q_ASSERT(itemView() != 0);
599 Q_ASSERT(m_fileItemDelegate
!= 0);
601 const bool showHiddenFiles
= props
.showHiddenFiles();
602 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
603 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
604 m_controller
->setShowHiddenFiles(showHiddenFiles
);
605 emit
showHiddenFilesChanged();
608 m_storedCategorizedSorting
= props
.categorizedSorting();
609 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
610 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
611 m_proxyModel
->setCategorizedModel(categorized
);
612 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
613 emit
categorizedSortingChanged();
616 const DolphinView::Sorting sorting
= props
.sorting();
617 if (sorting
!= m_proxyModel
->sorting()) {
618 m_proxyModel
->setSorting(sorting
);
619 emit
sortingChanged(sorting
);
622 const Qt::SortOrder sortOrder
= props
.sortOrder();
623 if (sortOrder
!= m_proxyModel
->sortOrder()) {
624 m_proxyModel
->setSortOrder(sortOrder
);
625 emit
sortOrderChanged(sortOrder
);
628 KFileItemDelegate::InformationList info
= props
.additionalInfo();
629 if (info
!= m_fileItemDelegate
->showInformation()) {
630 m_controller
->setAdditionalInfoCount(info
.count());
631 m_fileItemDelegate
->setShowInformation(info
);
632 emit
additionalInfoChanged(info
);
635 const bool showPreview
= props
.showPreview();
636 if (showPreview
!= m_controller
->showPreview()) {
637 m_controller
->setShowPreview(showPreview
);
638 emit
showPreviewChanged();
642 void DolphinView::changeSelection(const KFileItemList
& selection
)
645 if (selection
.isEmpty()) {
648 const KUrl
& baseUrl
= url();
650 QItemSelection new_selection
;
651 foreach(const KFileItem
& item
, selection
) {
652 url
= item
.url().upUrl();
653 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
654 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
655 new_selection
.select(index
, index
);
658 itemView()->selectionModel()->select(new_selection
,
659 QItemSelectionModel::ClearAndSelect
660 | QItemSelectionModel::Current
);
663 void DolphinView::openContextMenu(const QPoint
& pos
)
667 const QModelIndex index
= itemView()->indexAt(pos
);
668 if (isValidNameIndex(index
)) {
669 item
= fileItem(index
);
672 emit
requestContextMenu(item
, url());
675 void DolphinView::dropUrls(const KUrl::List
& urls
,
676 const KUrl
& destPath
,
677 const QModelIndex
& destIndex
,
681 if (isValidNameIndex(destIndex
)) {
682 KFileItem item
= fileItem(destIndex
);
683 Q_ASSERT(!item
.isNull());
685 // the URLs are dropped above a directory
690 if ((directory
.isNull()) && (source
== itemView())) {
691 // The dropping is done into the same viewport where
692 // the dragging has been started. Just ignore this...
696 const KUrl
& destination
= (directory
.isNull()) ?
697 destPath
: directory
.url();
698 dropUrls(urls
, destination
);
701 void DolphinView::dropUrls(const KUrl::List
& urls
,
702 const KUrl
& destination
)
704 emit
urlsDropped(urls
, destination
);
707 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
709 ViewProperties
props(viewPropertiesUrl());
710 props
.setSorting(sorting
);
712 m_proxyModel
->setSorting(sorting
);
714 emit
sortingChanged(sorting
);
717 void DolphinView::updateSortOrder(Qt::SortOrder order
)
719 ViewProperties
props(viewPropertiesUrl());
720 props
.setSortOrder(order
);
722 m_proxyModel
->setSortOrder(order
);
724 emit
sortOrderChanged(order
);
727 void DolphinView::emitContentsMoved()
729 // only emit the contents moved signal if:
730 // - no directory loading is ongoing (this would reset the contents position
732 // - if the Column View is active: the column view does an automatic
733 // positioning during the loading operation, which must be remembered
734 if (!m_loadingDirectory
|| isColumnViewActive()) {
735 const QPoint
pos(contentsPosition());
736 emit
contentsMoved(pos
.x(), pos
.y());
740 void DolphinView::updateCutItems()
742 // restore the icons of all previously selected items to the
744 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
745 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
747 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
748 if (index
.isValid()) {
749 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
753 m_cutItemsCache
.clear();
755 // ... and apply an item effect to all currently cut items
756 applyCutItemEffect();
759 void DolphinView::showHoverInformation(const KFileItem
& item
)
761 if (hasSelection()) {
765 emit
requestItemInfo(item
);
768 void DolphinView::clearHoverInformation()
770 emit
requestItemInfo(KFileItem());
774 void DolphinView::createView()
776 KFileItemDelegate::InformationList infoList
;
777 if (m_fileItemDelegate
!= 0) {
778 infoList
= m_fileItemDelegate
->showInformation();
781 // delete current view
782 QAbstractItemView
* view
= itemView();
784 m_topLayout
->removeWidget(view
);
791 m_fileItemDelegate
= 0;
794 Q_ASSERT(m_iconsView
== 0);
795 Q_ASSERT(m_detailsView
== 0);
796 Q_ASSERT(m_columnView
== 0);
798 // ... and recreate it representing the current mode
801 m_iconsView
= new DolphinIconsView(this, m_controller
);
807 m_detailsView
= new DolphinDetailsView(this, m_controller
);
808 view
= m_detailsView
;
812 m_columnView
= new DolphinColumnView(this, m_controller
);
819 m_fileItemDelegate
= new KFileItemDelegate(view
);
820 m_fileItemDelegate
->setShowInformation(infoList
);
821 view
->setItemDelegate(m_fileItemDelegate
);
823 view
->setModel(m_proxyModel
);
824 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
826 new KMimeTypeResolver(view
, m_dolphinModel
);
827 m_topLayout
->insertWidget(1, view
);
829 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
830 this, SLOT(emitSelectionChangedSignal()));
831 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
832 this, SLOT(emitContentsMoved()));
833 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
834 this, SLOT(emitContentsMoved()));
838 QAbstractItemView
* DolphinView::itemView() const
840 if (m_detailsView
!= 0) {
841 return m_detailsView
;
842 } else if (m_columnView
!= 0) {
849 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
851 return index
.isValid() && (index
.column() == DolphinModel::Name
);
854 bool DolphinView::isCutItem(const KFileItem
& item
) const
856 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
857 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
859 const KUrl
& itemUrl
= item
.url();
860 KUrl::List::const_iterator it
= cutUrls
.begin();
861 const KUrl::List::const_iterator end
= cutUrls
.end();
863 if (*it
== itemUrl
) {
872 void DolphinView::applyCutItemEffect()
874 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
875 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
879 KFileItemList
items(m_dirLister
->items());
880 KFileItemList::const_iterator it
= items
.begin();
881 const KFileItemList::const_iterator end
= items
.end();
883 const KFileItem item
= *it
;
884 if (isCutItem(item
)) {
885 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
886 // Huh? the item is already known
887 //const KFileItem item = m_dolphinModel->itemForIndex(index);
888 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
889 if (value
.type() == QVariant::Icon
) {
890 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
891 QPixmap pixmap
= icon
.pixmap(128, 128);
893 // remember current pixmap for the item to be able
894 // to restore it when other items get cut
896 cutItem
.url
= item
.url();
897 cutItem
.pixmap
= pixmap
;
898 m_cutItemsCache
.append(cutItem
);
900 // apply icon effect to the cut item
901 KIconEffect iconEffect
;
902 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
903 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
910 void DolphinView::updateViewportColor()
912 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
914 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
915 emit
selectionChanged(selectedItems());
920 QWidget
* viewport
= itemView()->viewport();
922 palette
.setColor(viewport
->backgroundRole(), color
);
923 viewport
->setPalette(palette
);
926 #include "dolphinview.moc"