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 const KUrl root
= rootUrl();
164 m_controller
->setUrl(root
);
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 loadDirectory(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 loadDirectory(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 m_controller
->setShowHiddenFiles(show
);
223 emit
showHiddenFilesChanged();
225 loadDirectory(viewPropsUrl
, true);
228 bool DolphinView::showHiddenFiles() const
230 return m_dirLister
->showingDotFiles();
233 void DolphinView::setCategorizedSorting(bool categorized
)
235 if (categorized
== categorizedSorting()) {
239 // setCategorizedSorting(true) may only get invoked
240 // if the view supports categorized sorting
241 Q_ASSERT(!categorized
|| supportsCategorizedSorting());
243 ViewProperties
props(viewPropertiesUrl());
244 props
.setCategorizedSorting(categorized
);
247 m_storedCategorizedSorting
= categorized
;
248 m_proxyModel
->setCategorizedModel(categorized
);
249 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
251 emit
categorizedSortingChanged();
254 bool DolphinView::categorizedSorting() const
256 // If all view modes would support categorized sorting, returning
257 // m_proxyModel->isCategorizedModel() would be the way to go. As
258 // currently only the icons view supports caterized sorting, we remember
259 // the stored view properties state in m_storedCategorizedSorting and
260 // return this state. The application takes care to disable the corresponding
261 // checkbox by checking DolphinView::supportsCategorizedSorting() to indicate
262 // that this setting is not applied to the current view mode.
263 return m_storedCategorizedSorting
;
266 bool DolphinView::supportsCategorizedSorting() const
268 return m_iconsView
!= 0;
271 void DolphinView::selectAll()
273 itemView()->selectAll();
276 void DolphinView::invertSelection()
278 if (isColumnViewActive()) {
279 // QAbstractItemView does not offer a virtual method invertSelection()
280 // as counterpart to QAbstractItemView::selectAll(). This makes it
281 // necessary to delegate the inverting of the selection to the
282 // column view, as only the selection of the active column should
284 m_columnView
->invertSelection();
286 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
287 const QAbstractItemModel
* itemModel
= selectionModel
->model();
289 const QModelIndex topLeft
= itemModel
->index(0, 0);
290 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
291 itemModel
->columnCount() - 1);
293 const QItemSelection
selection(topLeft
, bottomRight
);
294 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
298 bool DolphinView::hasSelection() const
300 return itemView()->selectionModel()->hasSelection();
303 void DolphinView::clearSelection()
305 itemView()->selectionModel()->clear();
308 KFileItemList
DolphinView::selectedItems() const
310 const QAbstractItemView
* view
= itemView();
312 // Our view has a selection, we will map them back to the DolphinModel
313 // and then fill the KFileItemList.
314 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
316 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
317 KFileItemList itemList
;
319 const QModelIndexList indexList
= selection
.indexes();
320 foreach (QModelIndex index
, indexList
) {
321 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
322 if (!item
.isNull()) {
323 itemList
.append(item
);
330 KUrl::List
DolphinView::selectedUrls() const
333 const KFileItemList list
= selectedItems();
334 foreach (KFileItem item
, list
) {
335 urls
.append(item
.url());
340 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
342 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
343 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
346 void DolphinView::setContentsPosition(int x
, int y
)
348 QAbstractItemView
* view
= itemView();
350 // the ColumnView takes care itself for the horizontal scrolling
351 if (!isColumnViewActive()) {
352 view
->horizontalScrollBar()->setValue(x
);
354 view
->verticalScrollBar()->setValue(y
);
356 m_loadingDirectory
= false;
359 QPoint
DolphinView::contentsPosition() const
361 const int x
= itemView()->horizontalScrollBar()->value();
362 const int y
= itemView()->verticalScrollBar()->value();
366 void DolphinView::zoomIn()
368 m_controller
->triggerZoomIn();
371 void DolphinView::zoomOut()
373 m_controller
->triggerZoomOut();
376 bool DolphinView::isZoomInPossible() const
378 return m_controller
->isZoomInPossible();
381 bool DolphinView::isZoomOutPossible() const
383 return m_controller
->isZoomOutPossible();
386 void DolphinView::setSorting(Sorting sorting
)
388 if (sorting
!= this->sorting()) {
389 updateSorting(sorting
);
393 DolphinView::Sorting
DolphinView::sorting() const
395 return m_proxyModel
->sorting();
398 void DolphinView::setSortOrder(Qt::SortOrder order
)
400 if (sortOrder() != order
) {
401 updateSortOrder(order
);
405 Qt::SortOrder
DolphinView::sortOrder() const
407 return m_proxyModel
->sortOrder();
410 void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info
)
412 const KUrl viewPropsUrl
= viewPropertiesUrl();
413 ViewProperties
props(viewPropsUrl
);
414 props
.setAdditionalInfo(info
);
416 m_controller
->setAdditionalInfoCount(info
.count());
417 m_fileItemDelegate
->setShowInformation(info
);
419 emit
additionalInfoChanged(info
);
420 loadDirectory(viewPropsUrl
, true);
423 KFileItemDelegate::InformationList
DolphinView::additionalInfo() const
425 return m_fileItemDelegate
->showInformation();
428 void DolphinView::reload()
431 loadDirectory(url(), true);
434 void DolphinView::refresh()
437 applyViewProperties(m_controller
->url());
439 updateViewportColor();
442 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
444 if (m_controller
->url() == url
) {
448 const bool restoreColumnView
= !rootUrl
.isEmpty()
449 && !rootUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)
450 && rootUrl
.isParentOf(url
);
452 m_controller
->setUrl(url
); // emits urlChanged, which we forward
454 if (restoreColumnView
) {
455 applyViewProperties(rootUrl
);
456 loadDirectory(rootUrl
);
457 // Restoring the column view relies on the URL-history. It might be possible
458 // that the view properties have been changed or deleted in the meantime, so
459 // it cannot be asserted that really a column view has been created:
460 if (itemView() == m_columnView
) {
461 m_columnView
->setRootUrl(rootUrl
);
462 m_columnView
->showColumn(url
);
465 applyViewProperties(url
);
469 itemView()->setFocus();
471 emit
startedPathLoading(url
);
474 void DolphinView::setUrl(const KUrl
& url
)
476 updateView(url
, KUrl());
479 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
481 QWidget::mouseReleaseEvent(event
);
484 void DolphinView::activate()
489 void DolphinView::triggerItem(const KFileItem
& item
)
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'
502 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
505 void DolphinView::generatePreviews(const KFileItemList
& items
)
507 if (m_controller
->showPreview()) {
508 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
509 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
510 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
514 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
516 Q_ASSERT(!item
.isNull());
517 if (item
.url().directory() != m_dirLister
->url().path()) {
518 // the preview job is still working on items of an older URL, hence
519 // the item is not part of the directory model anymore
523 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
524 if (idx
.isValid() && (idx
.column() == 0)) {
525 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
526 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
527 KIconEffect iconEffect
;
528 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
529 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
531 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
536 void DolphinView::emitSelectionChangedSignal()
538 emit
selectionChanged(DolphinView::selectedItems());
541 void DolphinView::loadDirectory(const KUrl
& url
, bool reload
)
543 if (!url
.isValid()) {
544 const QString
location(url
.pathOrUrl());
545 if (location
.isEmpty()) {
546 emit
errorMessage(i18nc("@info:status", "The location is empty."));
548 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
553 m_cutItemsCache
.clear();
554 m_loadingDirectory
= true;
557 m_dirLister
->openUrl(url
, reload
? KDirLister::Reload
: KDirLister::NoFlags
);
559 if (isColumnViewActive()) {
560 // adjusting the directory lister is not enough in the case of the
561 // column view, as each column has its own directory lister internally...
563 m_columnView
->reload();
565 m_columnView
->showColumn(url
);
570 KUrl
DolphinView::viewPropertiesUrl() const
572 if (isColumnViewActive()) {
573 return m_dirLister
->url();
579 void DolphinView::applyViewProperties(const KUrl
& url
)
581 if (isColumnViewActive() && rootUrl().isParentOf(url
)) {
582 // The column view is active, hence don't apply the view properties
583 // of sub directories (represented by columns) to the view. The
584 // view always represents the properties of the first column.
588 const ViewProperties
props(url
);
590 const Mode mode
= props
.viewMode();
591 if (m_mode
!= mode
) {
596 if (itemView() == 0) {
599 Q_ASSERT(itemView() != 0);
600 Q_ASSERT(m_fileItemDelegate
!= 0);
602 const bool showHiddenFiles
= props
.showHiddenFiles();
603 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
604 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
605 m_controller
->setShowHiddenFiles(showHiddenFiles
);
606 emit
showHiddenFilesChanged();
609 m_storedCategorizedSorting
= props
.categorizedSorting();
610 const bool categorized
= m_storedCategorizedSorting
&& supportsCategorizedSorting();
611 if (categorized
!= m_proxyModel
->isCategorizedModel()) {
612 m_proxyModel
->setCategorizedModel(categorized
);
613 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
614 emit
categorizedSortingChanged();
617 const DolphinView::Sorting sorting
= props
.sorting();
618 if (sorting
!= m_proxyModel
->sorting()) {
619 m_proxyModel
->setSorting(sorting
);
620 emit
sortingChanged(sorting
);
623 const Qt::SortOrder sortOrder
= props
.sortOrder();
624 if (sortOrder
!= m_proxyModel
->sortOrder()) {
625 m_proxyModel
->setSortOrder(sortOrder
);
626 emit
sortOrderChanged(sortOrder
);
629 KFileItemDelegate::InformationList info
= props
.additionalInfo();
630 if (info
!= m_fileItemDelegate
->showInformation()) {
631 m_controller
->setAdditionalInfoCount(info
.count());
632 m_fileItemDelegate
->setShowInformation(info
);
633 emit
additionalInfoChanged(info
);
636 const bool showPreview
= props
.showPreview();
637 if (showPreview
!= m_controller
->showPreview()) {
638 m_controller
->setShowPreview(showPreview
);
639 emit
showPreviewChanged();
643 void DolphinView::changeSelection(const KFileItemList
& selection
)
646 if (selection
.isEmpty()) {
649 const KUrl
& baseUrl
= url();
651 QItemSelection new_selection
;
652 foreach(const KFileItem
& item
, selection
) {
653 url
= item
.url().upUrl();
654 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
655 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
656 new_selection
.select(index
, index
);
659 itemView()->selectionModel()->select(new_selection
,
660 QItemSelectionModel::ClearAndSelect
661 | QItemSelectionModel::Current
);
664 void DolphinView::openContextMenu(const QPoint
& pos
)
668 const QModelIndex index
= itemView()->indexAt(pos
);
669 if (isValidNameIndex(index
)) {
670 item
= fileItem(index
);
673 emit
requestContextMenu(item
, url());
676 void DolphinView::dropUrls(const KUrl::List
& urls
,
677 const KUrl
& destPath
,
678 const QModelIndex
& destIndex
,
682 if (isValidNameIndex(destIndex
)) {
683 KFileItem item
= fileItem(destIndex
);
684 Q_ASSERT(!item
.isNull());
686 // the URLs are dropped above a directory
691 if ((directory
.isNull()) && (source
== itemView())) {
692 // The dropping is done into the same viewport where
693 // the dragging has been started. Just ignore this...
697 const KUrl
& destination
= (directory
.isNull()) ?
698 destPath
: directory
.url();
699 dropUrls(urls
, destination
);
702 void DolphinView::dropUrls(const KUrl::List
& urls
,
703 const KUrl
& destination
)
705 emit
urlsDropped(urls
, destination
);
708 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
710 ViewProperties
props(viewPropertiesUrl());
711 props
.setSorting(sorting
);
713 m_proxyModel
->setSorting(sorting
);
715 emit
sortingChanged(sorting
);
718 void DolphinView::updateSortOrder(Qt::SortOrder order
)
720 ViewProperties
props(viewPropertiesUrl());
721 props
.setSortOrder(order
);
723 m_proxyModel
->setSortOrder(order
);
725 emit
sortOrderChanged(order
);
728 void DolphinView::emitContentsMoved()
730 // only emit the contents moved signal if:
731 // - no directory loading is ongoing (this would reset the contents position
733 // - if the Column View is active: the column view does an automatic
734 // positioning during the loading operation, which must be remembered
735 if (!m_loadingDirectory
|| isColumnViewActive()) {
736 const QPoint
pos(contentsPosition());
737 emit
contentsMoved(pos
.x(), pos
.y());
741 void DolphinView::updateCutItems()
743 // restore the icons of all previously selected items to the
745 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
746 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
748 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
749 if (index
.isValid()) {
750 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
754 m_cutItemsCache
.clear();
756 // ... and apply an item effect to all currently cut items
757 applyCutItemEffect();
760 void DolphinView::showHoverInformation(const KFileItem
& item
)
762 if (hasSelection()) {
766 emit
requestItemInfo(item
);
769 void DolphinView::clearHoverInformation()
771 emit
requestItemInfo(KFileItem());
775 void DolphinView::createView()
777 KFileItemDelegate::InformationList infoList
;
778 if (m_fileItemDelegate
!= 0) {
779 infoList
= m_fileItemDelegate
->showInformation();
782 // delete current view
783 QAbstractItemView
* view
= itemView();
785 m_topLayout
->removeWidget(view
);
792 m_fileItemDelegate
= 0;
795 Q_ASSERT(m_iconsView
== 0);
796 Q_ASSERT(m_detailsView
== 0);
797 Q_ASSERT(m_columnView
== 0);
799 // ... and recreate it representing the current mode
802 m_iconsView
= new DolphinIconsView(this, m_controller
);
808 m_detailsView
= new DolphinDetailsView(this, m_controller
);
809 view
= m_detailsView
;
813 m_columnView
= new DolphinColumnView(this, m_controller
);
820 m_fileItemDelegate
= new KFileItemDelegate(view
);
821 m_fileItemDelegate
->setShowInformation(infoList
);
822 view
->setItemDelegate(m_fileItemDelegate
);
824 view
->setModel(m_proxyModel
);
825 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
827 new KMimeTypeResolver(view
, m_dolphinModel
);
828 m_topLayout
->insertWidget(1, view
);
830 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
831 this, SLOT(emitSelectionChangedSignal()));
832 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
833 this, SLOT(emitContentsMoved()));
834 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
835 this, SLOT(emitContentsMoved()));
839 QAbstractItemView
* DolphinView::itemView() const
841 if (m_detailsView
!= 0) {
842 return m_detailsView
;
843 } else if (m_columnView
!= 0) {
850 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
852 return index
.isValid() && (index
.column() == DolphinModel::Name
);
855 bool DolphinView::isCutItem(const KFileItem
& item
) const
857 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
858 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
860 const KUrl
& itemUrl
= item
.url();
861 KUrl::List::const_iterator it
= cutUrls
.begin();
862 const KUrl::List::const_iterator end
= cutUrls
.end();
864 if (*it
== itemUrl
) {
873 void DolphinView::applyCutItemEffect()
875 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
876 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
880 KFileItemList
items(m_dirLister
->items());
881 KFileItemList::const_iterator it
= items
.begin();
882 const KFileItemList::const_iterator end
= items
.end();
884 const KFileItem item
= *it
;
885 if (isCutItem(item
)) {
886 const QModelIndex index
= m_dolphinModel
->indexForItem(item
);
887 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
888 if (value
.type() == QVariant::Icon
) {
889 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
890 QPixmap pixmap
= icon
.pixmap(128, 128);
892 // remember current pixmap for the item to be able
893 // to restore it when other items get cut
895 cutItem
.url
= item
.url();
896 cutItem
.pixmap
= pixmap
;
897 m_cutItemsCache
.append(cutItem
);
899 // apply icon effect to the cut item
900 KIconEffect iconEffect
;
901 pixmap
= iconEffect
.apply(pixmap
, KIconLoader::Desktop
, KIconLoader::DisabledState
);
902 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
909 void DolphinView::updateViewportColor()
911 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
913 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
914 emit
selectionChanged(selectedItems());
919 QWidget
* viewport
= itemView()->viewport();
921 palette
.setColor(viewport
->backgroundRole(), color
);
922 viewport
->setPalette(palette
);
925 #include "dolphinview.moc"