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
);
171 startDirLister(viewPropsUrl
);
176 DolphinView::Mode
DolphinView::mode() const
181 void DolphinView::setShowPreview(bool show
)
183 const KUrl viewPropsUrl
= viewPropertiesUrl();
184 ViewProperties
props(viewPropsUrl
);
185 props
.setShowPreview(show
);
187 m_controller
->setShowPreview(show
);
188 emit
showPreviewChanged();
190 startDirLister(viewPropsUrl
, true);
193 bool DolphinView::showPreview() const
195 return m_controller
->showPreview();
198 void DolphinView::setShowHiddenFiles(bool show
)
200 if (m_dirLister
->showingDotFiles() == show
) {
204 const KUrl viewPropsUrl
= viewPropertiesUrl();
205 ViewProperties
props(viewPropsUrl
);
206 props
.setShowHiddenFiles(show
);
208 m_dirLister
->setShowingDotFiles(show
);
209 emit
showHiddenFilesChanged();
211 startDirLister(viewPropsUrl
, true);
214 bool DolphinView::showHiddenFiles() const
216 return m_dirLister
->showingDotFiles();
219 void DolphinView::setCategorizedSorting(bool categorized
)
221 if (categorized
== categorizedSorting()) {
225 if (!categorized
&& !supportsCategorizedSorting())
227 m_proxyModel
->setCategorizedModel(categorized
);
228 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
230 emit
categorizedSortingChanged();
235 Q_ASSERT(m_iconsView
!= 0);
237 ViewProperties
props(viewPropertiesUrl());
238 props
.setCategorizedSorting(categorized
);
241 m_proxyModel
->setCategorizedModel(categorized
);
242 m_proxyModel
->sort(m_proxyModel
->sortColumn(), m_proxyModel
->sortOrder());
244 emit
categorizedSortingChanged();
247 bool DolphinView::categorizedSorting() const
249 return m_proxyModel
->isCategorizedModel();
252 bool DolphinView::supportsCategorizedSorting() const
254 return m_iconsView
!= 0;
257 void DolphinView::selectAll()
259 itemView()->selectAll();
262 void DolphinView::invertSelection()
264 if (isColumnViewActive()) {
265 // QAbstractItemView does not offer a virtual method invertSelection()
266 // as counterpart to QAbstractItemView::selectAll(). This makes it
267 // necessary to delegate the inverting of the selection to the
268 // column view, as only the selection of the active column should get
270 m_columnView
->invertSelection();
272 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
273 const QAbstractItemModel
* itemModel
= selectionModel
->model();
275 const QModelIndex topLeft
= itemModel
->index(0, 0);
276 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
277 itemModel
->columnCount() - 1);
279 const QItemSelection
selection(topLeft
, bottomRight
);
280 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
284 bool DolphinView::hasSelection() const
286 return itemView()->selectionModel()->hasSelection();
289 void DolphinView::clearSelection()
291 itemView()->selectionModel()->clear();
294 QList
<KFileItem
> DolphinView::selectedItems() const
296 const QAbstractItemView
* view
= itemView();
298 // Our view has a selection, we will map them back to the DolphinModel
299 // and then fill the KFileItemList.
300 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
302 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
303 QList
<KFileItem
> itemList
;
305 const QModelIndexList indexList
= selection
.indexes();
306 foreach (QModelIndex index
, indexList
) {
307 KFileItem item
= m_dolphinModel
->itemForIndex(index
);
308 if (!item
.isNull()) {
309 itemList
.append(item
);
316 KUrl::List
DolphinView::selectedUrls() const
319 const QList
<KFileItem
> list
= selectedItems();
320 for ( QList
<KFileItem
>::const_iterator it
= list
.begin(), end
= list
.end();
322 urls
.append((*it
).url());
327 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
329 const QModelIndex dolphinModelIndex
= m_proxyModel
->mapToSource(index
);
330 return m_dolphinModel
->itemForIndex(dolphinModelIndex
);
333 void DolphinView::setContentsPosition(int x
, int y
)
335 QAbstractItemView
* view
= itemView();
337 // the ColumnView takes care itself for the horizontal scrolling
338 if (!isColumnViewActive()) {
339 view
->horizontalScrollBar()->setValue(x
);
341 view
->verticalScrollBar()->setValue(y
);
343 m_loadingDirectory
= false;
346 QPoint
DolphinView::contentsPosition() const
348 const int x
= itemView()->horizontalScrollBar()->value();
349 const int y
= itemView()->verticalScrollBar()->value();
353 void DolphinView::zoomIn()
355 m_controller
->triggerZoomIn();
358 void DolphinView::zoomOut()
360 m_controller
->triggerZoomOut();
363 bool DolphinView::isZoomInPossible() const
365 return m_controller
->isZoomInPossible();
368 bool DolphinView::isZoomOutPossible() const
370 return m_controller
->isZoomOutPossible();
373 void DolphinView::setSorting(Sorting sorting
)
375 if (sorting
!= this->sorting()) {
376 updateSorting(sorting
);
380 DolphinView::Sorting
DolphinView::sorting() const
382 return m_proxyModel
->sorting();
385 void DolphinView::setSortOrder(Qt::SortOrder order
)
387 if (sortOrder() != order
) {
388 updateSortOrder(order
);
392 Qt::SortOrder
DolphinView::sortOrder() const
394 return m_proxyModel
->sortOrder();
397 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
399 const KUrl viewPropsUrl
= viewPropertiesUrl();
400 ViewProperties
props(viewPropsUrl
);
401 props
.setAdditionalInfo(info
);
403 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
404 m_fileItemDelegate
->setAdditionalInformation(info
);
406 emit
additionalInfoChanged(info
);
407 startDirLister(viewPropsUrl
, true);
410 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
412 return m_fileItemDelegate
->additionalInformation();
415 void DolphinView::reload()
418 startDirLister(url(), true);
421 void DolphinView::refresh()
424 applyViewProperties(m_controller
->url());
426 updateViewportColor();
429 void DolphinView::updateView(const KUrl
& url
, const KUrl
& rootUrl
)
431 if (m_controller
->url() == url
) {
435 const bool restoreColumnView
= !rootUrl
.isEmpty()
436 && !rootUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)
437 && rootUrl
.isParentOf(url
);
439 m_controller
->setUrl(url
); // emits urlChanged, which we forward
441 if (restoreColumnView
) {
442 applyViewProperties(rootUrl
);
443 Q_ASSERT(itemView() == m_columnView
);
444 startDirLister(rootUrl
);
445 m_columnView
->showColumn(url
);
447 applyViewProperties(url
);
451 itemView()->setFocus();
453 emit
startedPathLoading(url
);
456 void DolphinView::setUrl(const KUrl
& url
)
458 updateView(url
, KUrl());
461 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
463 QWidget::mouseReleaseEvent(event
);
466 void DolphinView::activate()
471 void DolphinView::triggerItem(const QModelIndex
& index
)
473 Q_ASSERT(index
.isValid());
475 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
476 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
477 // items are selected by the user, hence don't trigger the
478 // item specified by 'index'
482 const KFileItem item
= m_dolphinModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
488 emit
itemTriggered(item
); // caught by DolphinViewContainer or DolphinPart
491 void DolphinView::generatePreviews(const QList
<KFileItem
>& items
)
493 if (m_controller
->showPreview()) {
494 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
495 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
496 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
500 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
502 Q_ASSERT(!item
.isNull());
503 if (item
.url().directory() != m_dirLister
->url().path()) {
504 // the preview job is still working on items of an older URL, hence
505 // the item is not part of the directory model anymore
509 const QModelIndex idx
= m_dolphinModel
->indexForItem(item
);
510 if (idx
.isValid() && (idx
.column() == 0)) {
511 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
512 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
513 KIconEffect iconEffect
;
514 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
515 m_dolphinModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
517 m_dolphinModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
522 void DolphinView::emitSelectionChangedSignal()
524 emit
selectionChanged(DolphinView::selectedItems());
527 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
529 if (!url
.isValid()) {
530 const QString
location(url
.pathOrUrl());
531 if (location
.isEmpty()) {
532 emit
errorMessage(i18nc("@info:status", "The location is empty."));
534 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
539 m_cutItemsCache
.clear();
540 m_loadingDirectory
= true;
544 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
545 m_initializeColumnView
= false;
548 // keeping old directories is only necessary for hierarchical views
549 // like the column view
551 // for the column view it is not enough to reload the directory lister,
552 // so this task is delegated to the column view directly
553 m_columnView
->reload();
554 } else if (m_dirLister
->directories().contains(url
)) {
555 // The dir lister contains the directory already, so
556 // KDirLister::openUrl() may not get invoked twice.
557 m_dirLister
->updateDirectory(url
);
559 const KUrl
& dirListerUrl
= m_dirLister
->url();
560 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
561 // The current URL is not a child of the dir lister
562 // URL. This may happen when e. g. a place has been selected
563 // and hence the view must be reset.
564 m_dirLister
->openUrl(url
, false, false);
568 m_dirLister
->openUrl(url
, false, reload
);
572 KUrl
DolphinView::viewPropertiesUrl() const
574 if (isColumnViewActive()) {
575 return m_dirLister
->url();
581 void DolphinView::applyViewProperties(const KUrl
& url
)
583 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
584 // The column view is active, hence don't apply the view properties
585 // of sub directories (represented by columns) to the view. The
586 // view always represents the properties of the first column.
590 const ViewProperties
props(url
);
592 const Mode mode
= props
.viewMode();
593 if (m_mode
!= mode
) {
598 if (m_mode
== ColumnView
) {
599 // The mode has been changed to the Column View. When starting the dir
600 // lister with DolphinView::startDirLister() it is important to give a
601 // hint that the dir lister may not keep the current directory
602 // although this is the default for showing a hierarchy.
603 m_initializeColumnView
= true;
606 if (itemView() == 0) {
609 Q_ASSERT(itemView() != 0);
610 Q_ASSERT(m_fileItemDelegate
!= 0);
612 const bool showHiddenFiles
= props
.showHiddenFiles();
613 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
614 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
615 emit
showHiddenFilesChanged();
618 const bool categorized
= props
.categorizedSorting();
619 if (categorized
!= categorizedSorting()) {
620 m_proxyModel
->setCategorizedModel(categorized
);
621 emit
categorizedSortingChanged();
624 const DolphinView::Sorting sorting
= props
.sorting();
625 if (sorting
!= m_proxyModel
->sorting()) {
626 m_proxyModel
->setSorting(sorting
);
627 emit
sortingChanged(sorting
);
630 const Qt::SortOrder sortOrder
= props
.sortOrder();
631 if (sortOrder
!= m_proxyModel
->sortOrder()) {
632 m_proxyModel
->setSortOrder(sortOrder
);
633 emit
sortOrderChanged(sortOrder
);
636 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
637 if (info
!= m_fileItemDelegate
->additionalInformation()) {
638 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
639 m_fileItemDelegate
->setAdditionalInformation(info
);
640 emit
additionalInfoChanged(info
);
643 const bool showPreview
= props
.showPreview();
644 if (showPreview
!= m_controller
->showPreview()) {
645 m_controller
->setShowPreview(showPreview
);
646 emit
showPreviewChanged();
650 void DolphinView::changeSelection(const QList
<KFileItem
>& selection
)
653 if (selection
.isEmpty()) {
656 const KUrl
& baseUrl
= url();
658 QItemSelection new_selection
;
659 foreach(const KFileItem
& item
, selection
) {
660 url
= item
.url().upUrl();
661 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
662 QModelIndex index
= m_proxyModel
->mapFromSource(m_dolphinModel
->indexForItem(item
));
663 new_selection
.select(index
, index
);
666 itemView()->selectionModel()->select(new_selection
,
667 QItemSelectionModel::ClearAndSelect
668 | QItemSelectionModel::Current
);
671 void DolphinView::openContextMenu(const QPoint
& pos
)
675 const QModelIndex index
= itemView()->indexAt(pos
);
676 if (isValidNameIndex(index
)) {
677 item
= fileItem(index
);
680 emit
requestContextMenu(item
, url());
683 void DolphinView::dropUrls(const KUrl::List
& urls
,
684 const KUrl
& destPath
,
685 const QModelIndex
& destIndex
,
689 if (isValidNameIndex(destIndex
)) {
690 KFileItem item
= fileItem(destIndex
);
691 Q_ASSERT(!item
.isNull());
693 // the URLs are dropped above a directory
698 if ((directory
.isNull()) && (source
== itemView())) {
699 // The dropping is done into the same viewport where
700 // the dragging has been started. Just ignore this...
704 const KUrl
& destination
= (directory
.isNull()) ?
705 destPath
: directory
.url();
706 dropUrls(urls
, destination
);
709 void DolphinView::dropUrls(const KUrl::List
& urls
,
710 const KUrl
& destination
)
712 emit
urlsDropped(urls
, destination
);
715 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
717 ViewProperties
props(viewPropertiesUrl());
718 props
.setSorting(sorting
);
720 m_proxyModel
->setSorting(sorting
);
722 emit
sortingChanged(sorting
);
725 void DolphinView::updateSortOrder(Qt::SortOrder order
)
727 ViewProperties
props(viewPropertiesUrl());
728 props
.setSortOrder(order
);
730 m_proxyModel
->setSortOrder(order
);
732 emit
sortOrderChanged(order
);
735 void DolphinView::emitContentsMoved()
737 // only emit the contents moved signal if:
738 // - no directory loading is ongoing (this would reset the contents position
740 // - if the Column View is active: the column view does an automatic
741 // positioning during the loading operation, which must be remembered
742 if (!m_loadingDirectory
|| isColumnViewActive()) {
743 const QPoint
pos(contentsPosition());
744 emit
contentsMoved(pos
.x(), pos
.y());
748 void DolphinView::updateCutItems()
750 // restore the icons of all previously selected items to the
752 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
753 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
755 const QModelIndex index
= m_dolphinModel
->indexForUrl((*it
).url
);
756 if (index
.isValid()) {
757 m_dolphinModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
761 m_cutItemsCache
.clear();
763 // ... and apply an item effect to all currently cut items
764 applyCutItemEffect();
767 void DolphinView::showHoverInformation(const QModelIndex
& index
)
769 if (hasSelection()) {
773 const KFileItem item
= fileItem(index
);
774 if (!item
.isNull()) {
775 emit
requestItemInfo(item
);
779 void DolphinView::clearHoverInformation()
781 emit
requestItemInfo(KFileItem());
785 void DolphinView::createView()
787 // delete current view
788 QAbstractItemView
* view
= itemView();
790 m_topLayout
->removeWidget(view
);
797 m_fileItemDelegate
= 0;
800 Q_ASSERT(m_iconsView
== 0);
801 Q_ASSERT(m_detailsView
== 0);
802 Q_ASSERT(m_columnView
== 0);
804 // ... and recreate it representing the current mode
807 m_iconsView
= new DolphinIconsView(this, m_controller
);
813 m_detailsView
= new DolphinDetailsView(this, m_controller
);
814 view
= m_detailsView
;
816 // categorized sorting is not supported yet for the details
817 // view, even if the view properties indicate this
818 setCategorizedSorting(false);
822 m_columnView
= new DolphinColumnView(this, m_controller
);
825 // categorized sorting is not supported yet for the column
826 // view, even if the view properties indicate this
827 setCategorizedSorting(false);
833 m_fileItemDelegate
= new KFileItemDelegate(view
);
834 view
->setItemDelegate(m_fileItemDelegate
);
836 view
->setModel(m_proxyModel
);
837 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
839 new KMimeTypeResolver(view
, m_dolphinModel
);
840 m_topLayout
->insertWidget(1, view
);
842 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
843 this, SLOT(emitSelectionChangedSignal()));
844 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
845 this, SLOT(emitContentsMoved()));
846 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
847 this, SLOT(emitContentsMoved()));
851 QAbstractItemView
* DolphinView::itemView() const
853 if (m_detailsView
!= 0) {
854 return m_detailsView
;
855 } else if (m_columnView
!= 0) {
862 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
864 return index
.isValid() && (index
.column() == DolphinModel::Name
);
867 bool DolphinView::isCutItem(const KFileItem
& item
) const
869 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
870 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
872 const KUrl
& itemUrl
= item
.url();
873 KUrl::List::const_iterator it
= cutUrls
.begin();
874 const KUrl::List::const_iterator end
= cutUrls
.end();
876 if (*it
== itemUrl
) {
885 void DolphinView::applyCutItemEffect()
887 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
888 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
892 KFileItemList
items(m_dirLister
->items());
893 KFileItemList::const_iterator it
= items
.begin();
894 const KFileItemList::const_iterator end
= items
.end();
896 KFileItem
* item
= *it
;
897 if (isCutItem(*item
)) {
898 const QModelIndex index
= m_dolphinModel
->indexForItem(*item
);
899 // Huh? the item is already known
900 //const KFileItem item = m_dolphinModel->itemForIndex(index);
901 const QVariant value
= m_dolphinModel
->data(index
, Qt::DecorationRole
);
902 if (value
.type() == QVariant::Icon
) {
903 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
904 QPixmap pixmap
= icon
.pixmap(128, 128);
906 // remember current pixmap for the item to be able
907 // to restore it when other items get cut
909 cutItem
.url
= item
->url();
910 cutItem
.pixmap
= pixmap
;
911 m_cutItemsCache
.append(cutItem
);
913 // apply icon effect to the cut item
914 KIconEffect iconEffect
;
915 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
916 m_dolphinModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
923 void DolphinView::updateViewportColor()
925 QColor color
= KColorScheme(QPalette::Active
, KColorScheme::View
).background().color();
927 emit
urlChanged(url()); // Hmm, this is a hack; the url hasn't really changed.
928 emit
selectionChanged(selectedItems());
933 QWidget
* viewport
= itemView()->viewport();
935 palette
.setColor(viewport
->backgroundRole(), color
);
936 viewport
->setPalette(palette
);
939 #include "dolphinview.moc"