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"
54 #include "dolphincategorydrawer.h"
56 DolphinView::DolphinView(QWidget
* parent
,
58 KDirLister
* dirLister
,
59 DolphinModel
* dolphinModel
,
60 DolphinSortFilterProxyModel
* proxyModel
) :
63 m_loadingDirectory(false),
64 m_initializeColumnView(false),
65 m_mode(DolphinView::IconsView
),
71 m_fileItemDelegate(0),
72 m_dolphinModel(dolphinModel
),
73 m_dirLister(dirLister
),
74 m_proxyModel(proxyModel
),
77 setFocusPolicy(Qt::StrongFocus
);
78 m_topLayout
= new QVBoxLayout(this);
79 m_topLayout
->setSpacing(0);
80 m_topLayout
->setMargin(0);
82 QClipboard
* clipboard
= QApplication::clipboard();
83 connect(clipboard
, SIGNAL(dataChanged()),
84 this, SLOT(updateCutItems()));
86 connect(m_dirLister
, SIGNAL(completed()),
87 this, SLOT(updateCutItems()));
88 connect(m_dirLister
, SIGNAL(newItems(const QList
<KFileItem
>&)),
89 this, SLOT(generatePreviews(const QList
<KFileItem
>&)));
91 m_controller
= new DolphinController(this);
92 m_controller
->setUrl(url
);
93 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
94 this, SIGNAL(urlChanged(const KUrl
&)));
95 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
96 this, SLOT(openContextMenu(const QPoint
&)));
97 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)),
98 this, SLOT(dropUrls(const KUrl::List
&, const KUrl
&, const QModelIndex
&, QWidget
*)));
99 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
100 this, SLOT(updateSorting(DolphinView::Sorting
)));
101 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
102 this, SLOT(updateSortOrder(Qt::SortOrder
)));
103 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
104 this, SLOT(triggerItem(const QModelIndex
&)));
105 connect(m_controller
, SIGNAL(activated()),
106 this, SLOT(activate()));
107 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
108 this, SLOT(showHoverInformation(const QModelIndex
&)));
109 connect(m_controller
, SIGNAL(viewportEntered()),
110 this, SLOT(clearHoverInformation()));
112 applyViewProperties(url
);
113 m_topLayout
->addWidget(itemView());
116 DolphinView::~DolphinView()
120 const KUrl
& DolphinView::url() const
122 return m_controller
->url();
125 void DolphinView::setRootUrl(const KUrl
& url
)
130 KUrl
DolphinView::rootUrl() const
132 return isColumnViewActive() ? m_dirLister
->url() : url();
135 void DolphinView::setActive(bool active
)
137 if (active
== m_active
) {
143 updateViewportColor();
151 bool DolphinView::isActive() const
156 void DolphinView::setMode(Mode mode
)
158 if (mode
== m_mode
) {
159 return; // the wished mode is already set
164 if (isColumnViewActive()) {
165 // When changing the mode in the column view, it makes sense
166 // to go back to the root URL of the column view automatically.
167 // Otherwise there it would not be possible to turn off the column view
168 // without focusing the first column.
169 setUrl(m_dirLister
->url());
170 m_controller
->setUrl(m_dirLister
->url());
173 const KUrl viewPropsUrl
= viewPropertiesUrl();
174 ViewProperties
props(viewPropsUrl
);
175 props
.setViewMode(m_mode
);
178 startDirLister(viewPropsUrl
);
183 DolphinView::Mode
DolphinView::mode() const
188 void DolphinView::setShowPreview(bool show
)
190 const KUrl viewPropsUrl
= viewPropertiesUrl();
191 ViewProperties
props(viewPropsUrl
);
192 props
.setShowPreview(show
);
194 m_controller
->setShowPreview(show
);
195 emit
showPreviewChanged();
197 startDirLister(viewPropsUrl
, true);
200 bool DolphinView::showPreview() const
202 return m_controller
->showPreview();
205 void DolphinView::setShowHiddenFiles(bool show
)
207 if (m_dirLister
->showingDotFiles() == show
) {
211 const KUrl viewPropsUrl
= viewPropertiesUrl();
212 ViewProperties
props(viewPropsUrl
);
213 props
.setShowHiddenFiles(show
);
215 m_dirLister
->setShowingDotFiles(show
);
216 emit
showHiddenFilesChanged();
218 startDirLister(viewPropsUrl
, true);
221 bool DolphinView::showHiddenFiles() const
223 return m_dirLister
->showingDotFiles();
226 void DolphinView::setCategorizedSorting(bool categorized
)
228 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
232 Q_ASSERT(m_iconsView
!= 0);
234 ViewProperties
props(viewPropertiesUrl());
235 props
.setCategorizedSorting(categorized
);
238 m_proxyModel
->setCategorizedModel(categorized
);
239 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
241 emit
categorizedSortingChanged();
244 bool DolphinView::categorizedSorting() const
246 return m_proxyModel
->isCategorizedModel();
249 bool DolphinView::supportsCategorizedSorting() const
251 return m_iconsView
!= 0;
254 void DolphinView::selectAll()
256 itemView()->selectAll();
259 void DolphinView::invertSelection()
261 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
262 const QAbstractItemModel
* itemModel
= selectionModel
->model();
264 const QModelIndex topLeft
= itemModel
->index(0, 0);
265 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
266 itemModel
->columnCount() - 1);
268 QItemSelection
selection(topLeft
, bottomRight
);
269 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
272 bool DolphinView::hasSelection() const
274 return itemView()->selectionModel()->hasSelection();
277 void DolphinView::clearSelection()
279 itemView()->selectionModel()->clear();
282 QList
<KFileItem
> DolphinView::selectedItems() const
284 const QAbstractItemView
* view
= itemView();
286 // Our view has a selection, we will map them back to the DolphinModel
287 // and then fill the KFileItemList.
288 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
290 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
291 QList
<KFileItem
> itemList
;
293 const QModelIndexList indexList
= selection
.indexes();
294 foreach (QModelIndex index
, indexList
) {
295 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
296 if (!item
.isNull()) {
297 itemList
.append(item
);
304 KUrl::List
DolphinView::selectedUrls() const
307 const QList
<KFileItem
> list
= selectedItems();
308 for ( QList
<KFileItem
>::const_iterator it
= list
.begin(), end
= list
.end();
310 urls
.append((*it
).url());
315 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
317 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
318 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
321 void DolphinView::setContentsPosition(int x
, int y
)
323 QAbstractItemView
* view
= itemView();
325 // the ColumnView takes care itself for the horizontal scrolling
326 if (!isColumnViewActive()) {
327 view
->horizontalScrollBar()->setValue(x
);
329 view
->verticalScrollBar()->setValue(y
);
331 m_loadingDirectory
= false;
334 QPoint
DolphinView::contentsPosition() const
336 const int x
= itemView()->horizontalScrollBar()->value();
337 const int y
= itemView()->verticalScrollBar()->value();
341 void DolphinView::zoomIn()
343 m_controller
->triggerZoomIn();
346 void DolphinView::zoomOut()
348 m_controller
->triggerZoomOut();
351 bool DolphinView::isZoomInPossible() const
353 return m_controller
->isZoomInPossible();
356 bool DolphinView::isZoomOutPossible() const
358 return m_controller
->isZoomOutPossible();
361 void DolphinView::setSorting(Sorting sorting
)
363 if (sorting
!= this->sorting()) {
364 updateSorting(sorting
);
368 DolphinView::Sorting
DolphinView::sorting() const
370 return m_proxyModel
->sorting();
373 void DolphinView::setSortOrder(Qt::SortOrder order
)
375 if (sortOrder() != order
) {
376 updateSortOrder(order
);
380 Qt::SortOrder
DolphinView::sortOrder() const
382 return m_proxyModel
->sortOrder();
385 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
387 const KUrl viewPropsUrl
= viewPropertiesUrl();
388 ViewProperties
props(viewPropsUrl
);
389 props
.setAdditionalInfo(info
);
391 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
392 m_fileItemDelegate
->setAdditionalInformation(info
);
394 emit
additionalInfoChanged(info
);
395 startDirLister(viewPropsUrl
, true);
398 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
400 return m_fileItemDelegate
->additionalInformation();
403 void DolphinView::reload()
406 startDirLister(url(), true);
409 void DolphinView::refresh()
412 applyViewProperties(m_controller
->url());
414 updateViewportColor();
417 void DolphinView::setUrl(const KUrl
& url
)
419 if (m_controller
->url() == url
) {
423 const bool restoreColumnView
= !isColumnViewActive()
424 && !m_rootUrl
.isEmpty()
425 && m_rootUrl
.isParentOf(url
)
426 && (m_rootUrl
!= url
);
428 const KUrl oldRootUrl
= rootUrl();
429 m_controller
->setUrl(url
); // emits urlChanged, which we forward
431 if (restoreColumnView
) {
432 applyViewProperties(m_rootUrl
);
433 Q_ASSERT(itemView() == m_columnView
);
434 startDirLister(m_rootUrl
);
435 m_columnView
->showColumn(url
);
437 applyViewProperties(url
);
441 itemView()->setFocus();
443 const KUrl newRootUrl
= rootUrl();
444 if (newRootUrl
!= oldRootUrl
) {
445 emit
rootUrlChanged(newRootUrl
);
449 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
451 QWidget::mouseReleaseEvent(event
);
454 void DolphinView::activate()
459 void DolphinView::triggerItem(const QModelIndex
& index
)
461 Q_ASSERT(index
.isValid());
463 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
464 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
465 // items are selected by the user, hence don't trigger the
466 // item specified by 'index'
470 const KFileItem item
= m_dolphinModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
476 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
479 void DolphinView::generatePreviews(const QList
<KFileItem
>& items
)
481 if (m_controller
->showPreview()) {
482 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
483 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
484 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
488 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
490 Q_ASSERT(!item
.isNull());
491 if (item
.url().directory() != m_dirLister
->url().path()) {
492 // the preview job is still working on items of an older URL, hence
493 // the item is not part of the directory model anymore
497 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
498 if (idx
.isValid() && (idx
.column() == 0)) {
499 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
500 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
501 KIconEffect iconEffect
;
502 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
503 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
505 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
510 void DolphinView::emitSelectionChangedSignal()
512 emit
selectionChanged(DolphinView::selectedItems());
515 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
517 if (!url
.isValid()) {
518 const QString
location(url
.pathOrUrl());
519 if (location
.isEmpty()) {
520 emit
errorMessage(i18nc("@info:status", "The location is empty."));
522 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
527 m_cutItemsCache
.clear();
528 m_loadingDirectory
= true;
532 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
533 m_initializeColumnView
= false;
536 // keeping old directories is only necessary for hierarchical views
537 // like the column view
539 // for the column view it is not enough to reload the directory lister,
540 // so this task is delegated to the column view directly
541 m_columnView
->reload();
542 } else if (m_dirLister
->directories().contains(url
)) {
543 // The dir lister contains the directory already, so
544 // KDirLister::openUrl() may not get invoked twice.
545 m_dirLister
->updateDirectory(url
);
547 const KUrl
& dirListerUrl
= m_dirLister
->url();
548 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
549 // The current URL is not a child of the dir lister
550 // URL. This may happen when e. g. a place has been selected
551 // and hence the view must be reset.
552 m_dirLister
->openUrl(url
, false, false);
556 m_dirLister
->openUrl(url
, false, reload
);
560 KUrl
DolphinView::viewPropertiesUrl() const
562 if (isColumnViewActive()) {
563 return m_dirLister
->url();
569 void DolphinView::applyViewProperties(const KUrl
& url
)
571 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
572 // The column view is active, hence don't apply the view properties
573 // of sub directories (represented by columns) to the view. The
574 // view always represents the properties of the first column.
578 const ViewProperties
props(url
);
580 const Mode mode
= props
.viewMode();
581 if (m_mode
!= mode
) {
586 if (m_mode
== ColumnView
) {
587 // The mode has been changed to the Column View. When starting the dir
588 // lister with DolphinView::startDirLister() it is important to give a
589 // hint that the dir lister may not keep the current directory
590 // although this is the default for showing a hierarchy.
591 m_initializeColumnView
= true;
594 if (itemView() == 0) {
597 Q_ASSERT(itemView() != 0);
598 Q_ASSERT(m_fileItemDelegate
!= 0);
600 const bool showHiddenFiles
= props
.showHiddenFiles();
601 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
602 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
603 emit
showHiddenFilesChanged();
606 const bool categorized
= props
.categorizedSorting();
607 if (categorized
!= categorizedSorting()) {
608 m_proxyModel
->setCategorizedModel(categorized
);
609 emit
categorizedSortingChanged();
612 const DolphinView::Sorting sorting
= props
.sorting();
613 if (sorting
!= m_proxyModel
->sorting()) {
614 m_proxyModel
->setSorting(sorting
);
615 emit
sortingChanged(sorting
);
618 const Qt::SortOrder sortOrder
= props
.sortOrder();
619 if (sortOrder
!= m_proxyModel
->sortOrder()) {
620 m_proxyModel
->setSortOrder(sortOrder
);
621 emit
sortOrderChanged(sortOrder
);
624 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
625 if (info
!= m_fileItemDelegate
->additionalInformation()) {
626 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
627 m_fileItemDelegate
->setAdditionalInformation(info
);
628 emit
additionalInfoChanged(info
);
631 const bool showPreview
= props
.showPreview();
632 if (showPreview
!= m_controller
->showPreview()) {
633 m_controller
->setShowPreview(showPreview
);
634 emit
showPreviewChanged();
638 void DolphinView::changeSelection(const QList
<KFileItem
>& selection
)
641 if (selection
.isEmpty()) {
644 const KUrl
& baseUrl
= url();
646 QItemSelection new_selection
;
647 foreach(const KFileItem
& item
, selection
) {
648 url
= item
.url().upUrl();
649 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
650 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
651 new_selection
.select(index
, index
);
654 itemView()->selectionModel()->select(new_selection
,
655 QItemSelectionModel::ClearAndSelect
656 | QItemSelectionModel::Current
);
659 void DolphinView::openContextMenu(const QPoint
& pos
)
663 const QModelIndex index
= itemView()->indexAt(pos
);
664 if (isValidNameIndex(index
)) {
665 item
= fileItem(index
);
668 emit
requestContextMenu(item
, url());
671 void DolphinView::dropUrls(const KUrl::List
& urls
,
672 const KUrl
& destPath
,
673 const QModelIndex
& destIndex
,
677 if (isValidNameIndex(destIndex
)) {
678 KFileItem item
= fileItem(destIndex
);
679 Q_ASSERT(!item
.isNull());
681 // the URLs are dropped above a directory
686 if ((directory
.isNull()) && (source
== itemView())) {
687 // The dropping is done into the same viewport where
688 // the dragging has been started. Just ignore this...
692 const KUrl
& destination
= (directory
.isNull()) ?
693 destPath
: directory
.url();
694 dropUrls(urls
, destination
);
697 void DolphinView::dropUrls(const KUrl::List
& urls
,
698 const KUrl
& destination
)
700 emit
urlsDropped(urls
, destination
);
703 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
705 ViewProperties
props(viewPropertiesUrl());
706 props
.setSorting(sorting
);
708 m_proxyModel
->setSorting(sorting
);
710 emit
sortingChanged(sorting
);
713 void DolphinView::updateSortOrder(Qt::SortOrder order
)
715 ViewProperties
props(viewPropertiesUrl());
716 props
.setSortOrder(order
);
718 m_proxyModel
->setSortOrder(order
);
720 emit
sortOrderChanged(order
);
723 void DolphinView::emitContentsMoved()
725 // only emit the contents moved signal if:
726 // - no directory loading is ongoing (this would reset the contents position
728 // - if the Column View is active: the column view does an automatic
729 // positioning during the loading operation, which must be remembered
730 if (!m_loadingDirectory
|| isColumnViewActive()) {
731 const QPoint
pos(contentsPosition());
732 emit
contentsMoved(pos
.x(), pos
.y());
736 void DolphinView::updateCutItems()
738 // restore the icons of all previously selected items to the
740 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
741 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
743 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
744 if (index
.isValid()) {
745 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
749 m_cutItemsCache
.clear();
751 // ... and apply an item effect to all currently cut items
752 applyCutItemEffect();
755 void DolphinView::showHoverInformation(const QModelIndex
& index
)
757 if (hasSelection()) {
761 const KFileItem item
= fileItem(index
);
762 if (!item
.isNull()) {
763 emit
requestItemInfo(item
);
767 void DolphinView::clearHoverInformation()
769 emit
requestItemInfo(KFileItem());
773 void DolphinView::createView()
775 // delete current view
776 QAbstractItemView
* view
= itemView();
778 m_topLayout
->removeWidget(view
);
785 m_fileItemDelegate
= 0;
788 Q_ASSERT(m_iconsView
== 0);
789 Q_ASSERT(m_detailsView
== 0);
790 Q_ASSERT(m_columnView
== 0);
792 // ... and recreate it representing the current mode
795 m_iconsView
= new DolphinIconsView(this, m_controller
);
796 m_iconsView
->setCategoryDrawer(new DolphinCategoryDrawer());
801 m_detailsView
= new DolphinDetailsView(this, m_controller
);
802 view
= m_detailsView
;
806 m_columnView
= new DolphinColumnView(this, m_controller
);
813 m_fileItemDelegate
= new KFileItemDelegate(view
);
814 view
->setItemDelegate(m_fileItemDelegate
);
816 view
->setModel(m_proxyModel
);
817 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
819 new KMimeTypeResolver(view
, m_dolphinModel
);
820 m_topLayout
->insertWidget(1, view
);
822 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
823 this, SLOT(emitSelectionChangedSignal()));
824 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
825 this, SLOT(emitContentsMoved()));
826 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
827 this, SLOT(emitContentsMoved()));
831 QAbstractItemView
* DolphinView::itemView() const
833 if (m_detailsView
!= 0) {
834 return m_detailsView
;
835 } else if (m_columnView
!= 0) {
842 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
844 return index
.isValid() && (index
.column() == DolphinModel::Name
);
847 bool DolphinView::isCutItem(const KFileItem
& item
) const
849 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
850 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
852 const KUrl
& itemUrl
= item
.url();
853 KUrl::List::const_iterator it
= cutUrls
.begin();
854 const KUrl::List::const_iterator end
= cutUrls
.end();
856 if (*it
== itemUrl
) {
865 void DolphinView::applyCutItemEffect()
867 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
868 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
872 KFileItemList
items(m_dirLister
->items());
873 KFileItemList::const_iterator it
= items
.begin();
874 const KFileItemList::const_iterator end
= items
.end();
876 KFileItem
* item
= *it
;
877 if (isCutItem(*item
)) {
878 const QModelIndex index
= m_dolphinModel
->indexForItem(*item
);
879 // Huh? the item is already known
880 //const KFileItem item = m_dolphinModel->itemForIndex(index);
881 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
882 if (value
.type() == QVariant::Icon
) {
883 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
884 QPixmap pixmap
= icon
.pixmap(128, 128);
886 // remember current pixmap for the item to be able
887 // to restore it when other items get cut
889 cutItem
.url
= item
->url();
890 cutItem
.pixmap
= pixmap
;
891 m_cutItemsCache
.append(cutItem
);
893 // apply icon effect to the cut item
894 KIconEffect iconEffect
;
895 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
896 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
903 void DolphinView::updateViewportColor()
905 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
907 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
908 emit
selectionChanged(selectedItems());
913 QWidget
* viewport
= itemView()->viewport();
915 palette
.setColor(viewport
->backgroundRole(), color
);
916 viewport
->setPalette(palette
);
919 #include "dolphinview.moc"