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_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 QList
<KFileItem
>&)),
87 this, SLOT(generatePreviews(const QList
<KFileItem
>&)));
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 QModelIndex
&)),
102 this, SLOT(triggerItem(const QModelIndex
&)));
103 connect(m_controller
, SIGNAL(activated()),
104 this, SLOT(activate()));
105 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
106 this, SLOT(showHoverInformation(const QModelIndex
&)));
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_dirLister
->url() : 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 const bool categorized
= props
.categorizedSorting() && supportsCategorizedSorting();
176 if (categorized
!= categorizedSorting()) {
177 m_proxyModel
->setCategorizedModel(categorized
);
178 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
179 emit
categorizedSortingChanged();
182 startDirLister(viewPropsUrl
);
187 DolphinView::Mode
DolphinView::mode() const
192 void DolphinView::setShowPreview(bool show
)
194 const KUrl viewPropsUrl
= viewPropertiesUrl();
195 ViewProperties
props(viewPropsUrl
);
196 props
.setShowPreview(show
);
198 m_controller
->setShowPreview(show
);
199 emit
showPreviewChanged();
201 startDirLister(viewPropsUrl
, true);
204 bool DolphinView::showPreview() const
206 return m_controller
->showPreview();
209 void DolphinView::setShowHiddenFiles(bool show
)
211 if (m_dirLister
->showingDotFiles() == show
) {
215 const KUrl viewPropsUrl
= viewPropertiesUrl();
216 ViewProperties
props(viewPropsUrl
);
217 props
.setShowHiddenFiles(show
);
219 m_dirLister
->setShowingDotFiles(show
);
220 emit
showHiddenFilesChanged();
222 startDirLister(viewPropsUrl
, true);
225 bool DolphinView::showHiddenFiles() const
227 return m_dirLister
->showingDotFiles();
230 void DolphinView::setCategorizedSorting(bool categorized
)
232 if (categorized
== categorizedSorting()) {
236 // setCategorizedSorting(true) may only get invoked
237 // if the view supports categorized sorting
238 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
240 ViewProperties
props(viewPropertiesUrl());
241 props
.setCategorizedSorting(categorized
);
244 m_proxyModel
->setCategorizedModel(categorized
);
245 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
247 emit
categorizedSortingChanged();
250 bool DolphinView::categorizedSorting() const
252 return m_proxyModel
->isCategorizedModel();
255 bool DolphinView::supportsCategorizedSorting() const
257 return m_iconsView
!= 0;
260 void DolphinView::selectAll()
262 itemView()->selectAll();
265 void DolphinView::invertSelection()
267 if (isColumnViewActive()) {
268 // QAbstractItemView does not offer a virtual method invertSelection()
269 // as counterpart to QAbstractItemView::selectAll(). This makes it
270 // necessary to delegate the inverting of the selection to the
271 // column view, as only the selection of the active column should get
273 m_columnView
->invertSelection();
275 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
276 const QAbstractItemModel
* itemModel
= selectionModel
->model();
278 const QModelIndex topLeft
= itemModel
->index(0, 0);
279 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
280 itemModel
->columnCount() - 1);
282 const QItemSelection
selection(topLeft
, bottomRight
);
283 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
287 bool DolphinView::hasSelection() const
289 return itemView()->selectionModel()->hasSelection();
292 void DolphinView::clearSelection()
294 itemView()->selectionModel()->clear();
297 QList
<KFileItem
> DolphinView::selectedItems() const
299 const QAbstractItemView
* view
= itemView();
301 // Our view has a selection, we will map them back to the DolphinModel
302 // and then fill the KFileItemList.
303 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
305 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
306 QList
<KFileItem
> itemList
;
308 const QModelIndexList indexList
= selection
.indexes();
309 foreach (QModelIndex index
, indexList
) {
310 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
311 if (!item
.isNull()) {
312 itemList
.append(item
);
319 KUrl::List
DolphinView::selectedUrls() const
322 const QList
<KFileItem
> list
= selectedItems();
323 for ( QList
<KFileItem
>::const_iterator it
= list
.begin(), end
= list
.end();
325 urls
.append((*it
).url());
330 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
332 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
333 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
336 void DolphinView::setContentsPosition(int x
, int y
)
338 QAbstractItemView
* view
= itemView();
340 // the ColumnView takes care itself for the horizontal scrolling
341 if (!isColumnViewActive()) {
342 view
->horizontalScrollBar()->setValue(x
);
344 view
->verticalScrollBar()->setValue(y
);
346 m_loadingDirectory
= false;
349 QPoint
DolphinView::contentsPosition() const
351 const int x
= itemView()->horizontalScrollBar()->value();
352 const int y
= itemView()->verticalScrollBar()->value();
356 void DolphinView::zoomIn()
358 m_controller
->triggerZoomIn();
361 void DolphinView::zoomOut()
363 m_controller
->triggerZoomOut();
366 bool DolphinView::isZoomInPossible() const
368 return m_controller
->isZoomInPossible();
371 bool DolphinView::isZoomOutPossible() const
373 return m_controller
->isZoomOutPossible();
376 void DolphinView::setSorting(Sorting sorting
)
378 if (sorting
!= this->sorting()) {
379 updateSorting(sorting
);
383 DolphinView::Sorting
DolphinView::sorting() const
385 return m_proxyModel
->sorting();
388 void DolphinView::setSortOrder(Qt::SortOrder order
)
390 if (sortOrder() != order
) {
391 updateSortOrder(order
);
395 Qt::SortOrder
DolphinView::sortOrder() const
397 return m_proxyModel
->sortOrder();
400 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
402 const KUrl viewPropsUrl
= viewPropertiesUrl();
403 ViewProperties
props(viewPropsUrl
);
404 props
.setAdditionalInfo(info
);
406 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
407 m_fileItemDelegate
->setAdditionalInformation(info
);
409 emit
additionalInfoChanged(info
);
410 startDirLister(viewPropsUrl
, true);
413 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
415 return m_fileItemDelegate
->additionalInformation();
418 void DolphinView::reload()
421 startDirLister(url(), true);
424 void DolphinView::refresh()
427 applyViewProperties(m_controller
->url());
429 updateViewportColor();
432 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
434 if (m_controller
->url() == url
) {
438 const bool restoreColumnView
= !rootUrl
.isEmpty()
439 && !rootUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)
440 && rootUrl
.isParentOf(url
);
442 m_controller
->setUrl(url
); // emits urlChanged, which we forward
444 if (restoreColumnView
) {
445 applyViewProperties(rootUrl
);
446 Q_ASSERT(itemView() == m_columnView
);
447 startDirLister(rootUrl
);
448 m_columnView
->showColumn(url
);
450 applyViewProperties(url
);
454 itemView()->setFocus();
456 emit
startedPathLoading(url
);
459 void DolphinView::setUrl(const KUrl
& url
)
461 updateView(url
, KUrl());
464 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
466 QWidget::mouseReleaseEvent(event
);
469 void DolphinView::activate()
474 void DolphinView::triggerItem(const QModelIndex
& index
)
476 Q_ASSERT(index
.isValid());
478 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
479 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
480 // items are selected by the user, hence don't trigger the
481 // item specified by 'index'
485 const KFileItem item
= m_dolphinModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
491 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
494 void DolphinView::generatePreviews(const QList
<KFileItem
>& items
)
496 if (m_controller
->showPreview()) {
497 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
498 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
499 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
503 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
505 Q_ASSERT(!item
.isNull());
506 if (item
.url().directory() != m_dirLister
->url().path()) {
507 // the preview job is still working on items of an older URL, hence
508 // the item is not part of the directory model anymore
512 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
513 if (idx
.isValid() && (idx
.column() == 0)) {
514 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
515 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
516 KIconEffect iconEffect
;
517 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
518 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
520 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
525 void DolphinView::emitSelectionChangedSignal()
527 emit
selectionChanged(DolphinView::selectedItems());
530 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
532 if (!url
.isValid()) {
533 const QString
location(url
.pathOrUrl());
534 if (location
.isEmpty()) {
535 emit
errorMessage(i18nc("@info:status", "The location is empty."));
537 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
542 m_cutItemsCache
.clear();
543 m_loadingDirectory
= true;
547 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
548 m_initializeColumnView
= false;
551 // keeping old directories is only necessary for hierarchical views
552 // like the column view
554 // for the column view it is not enough to reload the directory lister,
555 // so this task is delegated to the column view directly
556 m_columnView
->reload();
557 } else if (m_dirLister
->directories().contains(url
)) {
558 // The dir lister contains the directory already, so
559 // KDirLister::openUrl() may not get invoked twice.
560 m_dirLister
->updateDirectory(url
);
562 const KUrl
& dirListerUrl
= m_dirLister
->url();
563 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
564 // The current URL is not a child of the dir lister
565 // URL. This may happen when e. g. a place has been selected
566 // and hence the view must be reset.
567 m_dirLister
->openUrl(url
, false, false);
571 m_dirLister
->openUrl(url
, false, reload
);
575 KUrl
DolphinView::viewPropertiesUrl() const
577 if (isColumnViewActive()) {
578 return m_dirLister
->url();
584 void DolphinView::applyViewProperties(const KUrl
& url
)
586 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
587 // The column view is active, hence don't apply the view properties
588 // of sub directories (represented by columns) to the view. The
589 // view always represents the properties of the first column.
593 const ViewProperties
props(url
);
595 const Mode mode
= props
.viewMode();
596 if (m_mode
!= mode
) {
601 if (m_mode
== ColumnView
) {
602 // The mode has been changed to the Column View. When starting the dir
603 // lister with DolphinView::startDirLister() it is important to give a
604 // hint that the dir lister may not keep the current directory
605 // although this is the default for showing a hierarchy.
606 m_initializeColumnView
= true;
609 if (itemView() == 0) {
612 Q_ASSERT(itemView() != 0);
613 Q_ASSERT(m_fileItemDelegate
!= 0);
615 const bool showHiddenFiles
= props
.showHiddenFiles();
616 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
617 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
618 emit
showHiddenFilesChanged();
621 const bool categorized
= props
.categorizedSorting() && supportsCategorizedSorting();
622 if (categorized
!= categorizedSorting()) {
623 m_proxyModel
->setCategorizedModel(categorized
);
624 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
625 emit
categorizedSortingChanged();
628 const DolphinView::Sorting sorting
= props
.sorting();
629 if (sorting
!= m_proxyModel
->sorting()) {
630 m_proxyModel
->setSorting(sorting
);
631 emit
sortingChanged(sorting
);
634 const Qt::SortOrder sortOrder
= props
.sortOrder();
635 if (sortOrder
!= m_proxyModel
->sortOrder()) {
636 m_proxyModel
->setSortOrder(sortOrder
);
637 emit
sortOrderChanged(sortOrder
);
640 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
641 if (info
!= m_fileItemDelegate
->additionalInformation()) {
642 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
643 m_fileItemDelegate
->setAdditionalInformation(info
);
644 emit
additionalInfoChanged(info
);
647 const bool showPreview
= props
.showPreview();
648 if (showPreview
!= m_controller
->showPreview()) {
649 m_controller
->setShowPreview(showPreview
);
650 emit
showPreviewChanged();
654 void DolphinView::changeSelection(const QList
<KFileItem
>& selection
)
657 if (selection
.isEmpty()) {
660 const KUrl
& baseUrl
= url();
662 QItemSelection new_selection
;
663 foreach(const KFileItem
& item
, selection
) {
664 url
= item
.url().upUrl();
665 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
666 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
667 new_selection
.select(index
, index
);
670 itemView()->selectionModel()->select(new_selection
,
671 QItemSelectionModel::ClearAndSelect
672 | QItemSelectionModel::Current
);
675 void DolphinView::openContextMenu(const QPoint
& pos
)
679 const QModelIndex index
= itemView()->indexAt(pos
);
680 if (isValidNameIndex(index
)) {
681 item
= fileItem(index
);
684 emit
requestContextMenu(item
, url());
687 void DolphinView::dropUrls(const KUrl::List
& urls
,
688 const KUrl
& destPath
,
689 const QModelIndex
& destIndex
,
693 if (isValidNameIndex(destIndex
)) {
694 KFileItem item
= fileItem(destIndex
);
695 Q_ASSERT(!item
.isNull());
697 // the URLs are dropped above a directory
702 if ((directory
.isNull()) && (source
== itemView())) {
703 // The dropping is done into the same viewport where
704 // the dragging has been started. Just ignore this...
708 const KUrl
& destination
= (directory
.isNull()) ?
709 destPath
: directory
.url();
710 dropUrls(urls
, destination
);
713 void DolphinView::dropUrls(const KUrl::List
& urls
,
714 const KUrl
& destination
)
716 emit
urlsDropped(urls
, destination
);
719 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
721 ViewProperties
props(viewPropertiesUrl());
722 props
.setSorting(sorting
);
724 m_proxyModel
->setSorting(sorting
);
726 emit
sortingChanged(sorting
);
729 void DolphinView::updateSortOrder(Qt::SortOrder order
)
731 ViewProperties
props(viewPropertiesUrl());
732 props
.setSortOrder(order
);
734 m_proxyModel
->setSortOrder(order
);
736 emit
sortOrderChanged(order
);
739 void DolphinView::emitContentsMoved()
741 // only emit the contents moved signal if:
742 // - no directory loading is ongoing (this would reset the contents position
744 // - if the Column View is active: the column view does an automatic
745 // positioning during the loading operation, which must be remembered
746 if (!m_loadingDirectory
|| isColumnViewActive()) {
747 const QPoint
pos(contentsPosition());
748 emit
contentsMoved(pos
.x(), pos
.y());
752 void DolphinView::updateCutItems()
754 // restore the icons of all previously selected items to the
756 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
757 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
759 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
760 if (index
.isValid()) {
761 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
765 m_cutItemsCache
.clear();
767 // ... and apply an item effect to all currently cut items
768 applyCutItemEffect();
771 void DolphinView::showHoverInformation(const QModelIndex
& index
)
773 if (hasSelection()) {
777 const KFileItem item
= fileItem(index
);
778 if (!item
.isNull()) {
779 emit
requestItemInfo(item
);
783 void DolphinView::clearHoverInformation()
785 emit
requestItemInfo(KFileItem());
789 void DolphinView::createView()
791 // delete current view
792 QAbstractItemView
* view
= itemView();
794 m_topLayout
->removeWidget(view
);
801 m_fileItemDelegate
= 0;
804 Q_ASSERT(m_iconsView
== 0);
805 Q_ASSERT(m_detailsView
== 0);
806 Q_ASSERT(m_columnView
== 0);
808 // ... and recreate it representing the current mode
811 m_iconsView
= new DolphinIconsView(this, m_controller
);
817 m_detailsView
= new DolphinDetailsView(this, m_controller
);
818 view
= m_detailsView
;
822 m_columnView
= new DolphinColumnView(this, m_controller
);
829 m_fileItemDelegate
= new KFileItemDelegate(view
);
830 view
->setItemDelegate(m_fileItemDelegate
);
832 view
->setModel(m_proxyModel
);
833 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
835 new KMimeTypeResolver(view
, m_dolphinModel
);
836 m_topLayout
->insertWidget(1, view
);
838 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
839 this, SLOT(emitSelectionChangedSignal()));
840 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
841 this, SLOT(emitContentsMoved()));
842 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
843 this, SLOT(emitContentsMoved()));
847 QAbstractItemView
* DolphinView::itemView() const
849 if (m_detailsView
!= 0) {
850 return m_detailsView
;
851 } else if (m_columnView
!= 0) {
858 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
860 return index
.isValid() && (index
.column() == DolphinModel::Name
);
863 bool DolphinView::isCutItem(const KFileItem
& item
) const
865 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
866 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
868 const KUrl
& itemUrl
= item
.url();
869 KUrl::List::const_iterator it
= cutUrls
.begin();
870 const KUrl::List::const_iterator end
= cutUrls
.end();
872 if (*it
== itemUrl
) {
881 void DolphinView::applyCutItemEffect()
883 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
884 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
888 KFileItemList
items(m_dirLister
->items());
889 KFileItemList::const_iterator it
= items
.begin();
890 const KFileItemList::const_iterator end
= items
.end();
892 KFileItem
* item
= *it
;
893 if (isCutItem(*item
)) {
894 const QModelIndex index
= m_dolphinModel
->indexForItem(*item
);
895 // Huh? the item is already known
896 //const KFileItem item = m_dolphinModel->itemForIndex(index);
897 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
898 if (value
.type() == QVariant::Icon
) {
899 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
900 QPixmap pixmap
= icon
.pixmap(128, 128);
902 // remember current pixmap for the item to be able
903 // to restore it when other items get cut
905 cutItem
.url
= item
->url();
906 cutItem
.pixmap
= pixmap
;
907 m_cutItemsCache
.append(cutItem
);
909 // apply icon effect to the cut item
910 KIconEffect iconEffect
;
911 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
912 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
919 void DolphinView::updateViewportColor()
921 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
923 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
924 emit
selectionChanged(selectedItems());
929 QWidget
* viewport
= itemView()->viewport();
931 palette
.setColor(viewport
->backgroundRole(), color
);
932 viewport
->setPalette(palette
);
935 #include "dolphinview.moc"