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 <kdirmodel.h>
33 #include <kdirlister.h>
34 #include <kfileitemdelegate.h>
36 #include <kiconeffect.h>
37 #include <kio/netaccess.h>
38 #include <kio/renamedialog.h>
39 #include <kio/previewjob.h>
40 #include <kmimetyperesolver.h>
41 #include <konqmimedata.h>
42 #include <konq_operations.h>
45 #include "dolphincolumnview.h"
46 #include "dolphincontroller.h"
47 #include "dolphinsortfilterproxymodel.h"
48 #include "dolphindetailsview.h"
49 #include "dolphiniconsview.h"
50 #include "dolphinitemcategorizer.h"
51 #include "renamedialog.h"
52 #include "viewproperties.h"
53 #include "dolphinsettings.h"
54 #include "dolphin_generalsettings.h"
56 DolphinView::DolphinView(QWidget
* parent
,
58 KDirLister
* dirLister
,
60 DolphinSortFilterProxyModel
* proxyModel
) :
63 m_loadingDirectory(false),
64 m_initializeColumnView(false),
65 m_mode(DolphinView::IconsView
),
71 m_fileItemDelegate(0),
73 m_dirLister(dirLister
),
74 m_proxyModel(proxyModel
)
76 setFocusPolicy(Qt::StrongFocus
);
77 m_topLayout
= new QVBoxLayout(this);
78 m_topLayout
->setSpacing(0);
79 m_topLayout
->setMargin(0);
81 QClipboard
* clipboard
= QApplication::clipboard();
82 connect(clipboard
, SIGNAL(dataChanged()),
83 this, SLOT(updateCutItems()));
85 connect(m_dirLister
, SIGNAL(completed()),
86 this, SLOT(updateCutItems()));
87 connect(m_dirLister
, SIGNAL(newItems(const QList
<KFileItem
>&)),
88 this, SLOT(generatePreviews(const QList
<KFileItem
>&)));
90 m_controller
= new DolphinController(this);
91 m_controller
->setUrl(url
);
92 connect(m_controller
, SIGNAL(urlChanged(const KUrl
&)),
93 this, SIGNAL(urlChanged(const KUrl
&)));
94 connect(m_controller
, SIGNAL(requestContextMenu(const QPoint
&)),
95 this, SLOT(openContextMenu(const QPoint
&)));
96 connect(m_controller
, SIGNAL(urlsDropped(const KUrl::List
&, const QModelIndex
&, QWidget
*)),
97 this, SLOT(dropUrls(const KUrl::List
&, const QModelIndex
&, QWidget
*)));
98 connect(m_controller
, SIGNAL(sortingChanged(DolphinView::Sorting
)),
99 this, SLOT(updateSorting(DolphinView::Sorting
)));
100 connect(m_controller
, SIGNAL(sortOrderChanged(Qt::SortOrder
)),
101 this, SLOT(updateSortOrder(Qt::SortOrder
)));
102 connect(m_controller
, SIGNAL(itemTriggered(const QModelIndex
&)),
103 this, SLOT(triggerItem(const QModelIndex
&)));
104 connect(m_controller
, SIGNAL(activated()),
105 this, SLOT(activate()));
106 connect(m_controller
, SIGNAL(itemEntered(const QModelIndex
&)),
107 this, SLOT(showHoverInformation(const QModelIndex
&)));
108 connect(m_controller
, SIGNAL(viewportEntered()),
109 this, SLOT(clearHoverInformation()));
111 applyViewProperties(url
);
112 m_topLayout
->addWidget(itemView());
115 DolphinView::~DolphinView()
119 const KUrl
& DolphinView::url() const
121 return m_controller
->url();
124 KUrl
DolphinView::rootUrl() const
126 return isColumnViewActive() ? m_dirLister
->url() : url();
129 void DolphinView::setActive(bool active
)
131 if (active
== m_active
) {
137 updateViewportColor();
145 bool DolphinView::isActive() const
150 void DolphinView::setMode(Mode mode
)
152 if (mode
== m_mode
) {
153 return; // the wished mode is already set
158 if (isColumnViewActive()) {
159 // When changing the mode in the column view, it makes sense
160 // to go back to the root URL of the column view automatically.
161 // Otherwise there it would not be possible to turn off the column view
162 // without focusing the first column.
163 setUrl(m_dirLister
->url());
164 m_controller
->setUrl(m_dirLister
->url());
167 const KUrl viewPropsUrl
= viewPropertiesUrl();
168 ViewProperties
props(viewPropsUrl
);
169 props
.setViewMode(m_mode
);
172 startDirLister(viewPropsUrl
);
177 DolphinView::Mode
DolphinView::mode() const
182 void DolphinView::setShowPreview(bool show
)
184 const KUrl viewPropsUrl
= viewPropertiesUrl();
185 ViewProperties
props(viewPropsUrl
);
186 props
.setShowPreview(show
);
188 m_controller
->setShowPreview(show
);
189 emit
showPreviewChanged();
191 startDirLister(viewPropsUrl
, true);
194 bool DolphinView::showPreview() const
196 return m_controller
->showPreview();
199 void DolphinView::setShowHiddenFiles(bool show
)
201 if (m_dirLister
->showingDotFiles() == show
) {
205 const KUrl viewPropsUrl
= viewPropertiesUrl();
206 ViewProperties
props(viewPropsUrl
);
207 props
.setShowHiddenFiles(show
);
209 m_dirLister
->setShowingDotFiles(show
);
210 emit
showHiddenFilesChanged();
212 startDirLister(viewPropsUrl
, true);
215 bool DolphinView::showHiddenFiles() const
217 return m_dirLister
->showingDotFiles();
220 void DolphinView::setCategorizedSorting(bool categorized
)
222 if (!supportsCategorizedSorting() || (categorized
== categorizedSorting())) {
226 Q_ASSERT(m_iconsView
!= 0);
228 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
229 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
231 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
232 m_iconsView
->setItemCategorizer(0);
236 ViewProperties
props(viewPropertiesUrl());
237 props
.setCategorizedSorting(categorized
);
240 emit
categorizedSortingChanged();
243 bool DolphinView::categorizedSorting() const
245 if (!supportsCategorizedSorting()) {
249 Q_ASSERT(m_iconsView
!= 0);
250 return m_iconsView
->itemCategorizer() != 0;
253 bool DolphinView::supportsCategorizedSorting() const
255 return m_iconsView
!= 0;
258 void DolphinView::selectAll()
260 itemView()->selectAll();
263 void DolphinView::invertSelection()
265 if (isColumnViewActive()) {
266 // In opposite to QAbstractItemView::selectAll() there is no virtual method
267 // for adjusting the invertion of a selection. As the generic approach by using
268 // the selection model does not work for the column view, we delegate this task:
269 m_columnView
->invertSelection();
271 QItemSelectionModel
* selectionModel
= itemView()->selectionModel();
272 const QAbstractItemModel
* itemModel
= selectionModel
->model();
274 const QModelIndex topLeft
= itemModel
->index(0, 0);
275 const QModelIndex bottomRight
= itemModel
->index(itemModel
->rowCount() - 1,
276 itemModel
->columnCount() - 1);
278 QItemSelection
selection(topLeft
, bottomRight
);
279 selectionModel
->select(selection
, QItemSelectionModel::Toggle
);
283 bool DolphinView::hasSelection() const
285 return itemView()->selectionModel()->hasSelection();
288 void DolphinView::clearSelection()
290 itemView()->selectionModel()->clear();
293 QList
<KFileItem
> DolphinView::selectedItems() const
295 const QAbstractItemView
* view
= itemView();
297 // Our view has a selection, we will map them back to the DirModel
298 // and then fill the KFileItemList.
299 Q_ASSERT((view
!= 0) && (view
->selectionModel() != 0));
301 const QItemSelection selection
= m_proxyModel
->mapSelectionToSource(view
->selectionModel()->selection());
302 QList
<KFileItem
> itemList
;
304 const QModelIndexList indexList
= selection
.indexes();
305 QModelIndexList::const_iterator end
= indexList
.end();
306 for (QModelIndexList::const_iterator it
= indexList
.begin(); it
!= end
; ++it
) {
307 Q_ASSERT((*it
).isValid());
309 KFileItem item
= m_dirModel
->itemForIndex(*it
);
310 if (!item
.isNull()) {
311 itemList
.append(item
);
318 KUrl::List
DolphinView::selectedUrls() const
321 const QList
<KFileItem
> list
= selectedItems();
322 for ( QList
<KFileItem
>::const_iterator it
= list
.begin(), end
= list
.end();
324 urls
.append((*it
).url());
329 KFileItem
DolphinView::fileItem(const QModelIndex
& index
) const
331 const QModelIndex dirModelIndex
= m_proxyModel
->mapToSource(index
);
332 return m_dirModel
->itemForIndex(dirModelIndex
);
335 void DolphinView::setContentsPosition(int x
, int y
)
337 QAbstractItemView
* view
= itemView();
338 view
->horizontalScrollBar()->setValue(x
);
339 view
->verticalScrollBar()->setValue(y
);
341 m_loadingDirectory
= false;
344 QPoint
DolphinView::contentsPosition() const
346 const int x
= itemView()->horizontalScrollBar()->value();
347 const int y
= itemView()->verticalScrollBar()->value();
351 void DolphinView::zoomIn()
353 m_controller
->triggerZoomIn();
356 void DolphinView::zoomOut()
358 m_controller
->triggerZoomOut();
361 bool DolphinView::isZoomInPossible() const
363 return m_controller
->isZoomInPossible();
366 bool DolphinView::isZoomOutPossible() const
368 return m_controller
->isZoomOutPossible();
371 void DolphinView::setSorting(Sorting sorting
)
373 if (sorting
!= this->sorting()) {
374 updateSorting(sorting
);
378 DolphinView::Sorting
DolphinView::sorting() const
380 return m_proxyModel
->sorting();
383 void DolphinView::setSortOrder(Qt::SortOrder order
)
385 if (sortOrder() != order
) {
386 updateSortOrder(order
);
390 Qt::SortOrder
DolphinView::sortOrder() const
392 return m_proxyModel
->sortOrder();
395 void DolphinView::setAdditionalInfo(KFileItemDelegate::AdditionalInformation info
)
397 const KUrl viewPropsUrl
= viewPropertiesUrl();
398 ViewProperties
props(viewPropsUrl
);
399 props
.setAdditionalInfo(info
);
401 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
402 m_fileItemDelegate
->setAdditionalInformation(info
);
404 emit
additionalInfoChanged(info
);
405 startDirLister(viewPropsUrl
, true);
408 KFileItemDelegate::AdditionalInformation
DolphinView::additionalInfo() const
410 return m_fileItemDelegate
->additionalInformation();
413 void DolphinView::reload()
416 startDirLister(url(), true);
419 void DolphinView::refresh()
422 applyViewProperties(m_controller
->url());
424 updateViewportColor();
427 void DolphinView::setUrl(const KUrl
& url
)
429 if (m_controller
->url() == url
) {
433 m_controller
->setUrl(url
);
435 applyViewProperties(url
);
438 emit
urlChanged(url
);
441 void DolphinView::mouseReleaseEvent(QMouseEvent
* event
)
443 QWidget::mouseReleaseEvent(event
);
446 void DolphinView::activate()
451 void DolphinView::triggerItem(const QModelIndex
& index
)
453 if (!isValidNameIndex(index
)) {
455 showHoverInformation(index
);
459 const Qt::KeyboardModifiers modifier
= QApplication::keyboardModifiers();
460 if ((modifier
& Qt::ShiftModifier
) || (modifier
& Qt::ControlModifier
)) {
461 // items are selected by the user, hence don't trigger the
462 // item specified by 'index'
466 KFileItem item
= m_dirModel
->itemForIndex(m_proxyModel
->mapToSource(index
));
471 // The stuff below should be moved to ViewContainer and be just a signal?
473 // Prefer the local path over the URL.
475 KUrl url
= item
.mostLocalUrl(isLocal
);
479 } else if (item
.isFile()) {
480 // allow to browse through ZIP and tar files
481 KMimeType::Ptr mime
= item
.mimeTypePtr();
482 if (mime
->is("application/zip")) {
483 url
.setProtocol("zip");
485 } else if (mime
->is("application/x-tar") ||
486 mime
->is("application/x-tarz") ||
487 mime
->is("application/x-bzip-compressed-tar") ||
488 mime
->is("application/x-compressed-tar") ||
489 mime
->is("application/x-tzo")) {
490 url
.setProtocol("tar");
500 void DolphinView::generatePreviews(const QList
<KFileItem
>& items
)
502 if (m_controller
->showPreview()) {
503 KIO::PreviewJob
* job
= KIO::filePreview(items
, 128);
504 connect(job
, SIGNAL(gotPreview(const KFileItem
&, const QPixmap
&)),
505 this, SLOT(showPreview(const KFileItem
&, const QPixmap
&)));
509 void DolphinView::showPreview(const KFileItem
& item
, const QPixmap
& pixmap
)
511 Q_ASSERT(!item
.isNull());
512 if (item
.url().directory() != m_dirLister
->url().path()) {
513 // the preview job is still working on items of an older URL, hence
514 // the item is not part of the directory model anymore
518 const QModelIndex idx
= m_dirModel
->indexForItem(item
);
519 if (idx
.isValid() && (idx
.column() == 0)) {
520 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
521 if (KonqMimeData::decodeIsCutSelection(mimeData
) && isCutItem(item
)) {
522 KIconEffect iconEffect
;
523 const QPixmap cutPixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
524 m_dirModel
->setData(idx
, QIcon(cutPixmap
), Qt::DecorationRole
);
526 m_dirModel
->setData(idx
, QIcon(pixmap
), Qt::DecorationRole
);
531 void DolphinView::emitSelectionChangedSignal()
533 emit
selectionChanged(DolphinView::selectedItems());
536 void DolphinView::startDirLister(const KUrl
& url
, bool reload
)
538 if (!url
.isValid()) {
539 const QString
location(url
.pathOrUrl());
540 if (location
.isEmpty()) {
541 emit
errorMessage(i18nc("@info:status", "The location is empty."));
543 emit
errorMessage(i18nc("@info:status", "The location '%1' is invalid.", location
));
548 m_cutItemsCache
.clear();
549 m_loadingDirectory
= true;
554 bool keepOldDirs
= isColumnViewActive() && !m_initializeColumnView
;
555 m_initializeColumnView
= false;
561 const KUrl
& dirListerUrl
= m_dirLister
->url();
562 if (dirListerUrl
.isValid()) {
563 const KUrl::List dirs
= m_dirLister
->directories();
566 m_dirLister
->updateDirectory(url
);
570 } else if (m_dirLister
->directories().contains(url
)) {
571 // The dir lister contains the directory already, so
572 // KDirLister::openUrl() may not been invoked twice.
573 m_dirLister
->updateDirectory(url
);
576 const KUrl
& dirListerUrl
= m_dirLister
->url();
577 if ((dirListerUrl
== url
) || !m_dirLister
->url().isParentOf(url
)) {
578 // The current URL is not a child of the dir lister
579 // URL. This may happen when e. g. a place has been selected
580 // and hence the view must be reset.
587 m_dirLister
->openUrl(url
, keepOldDirs
, reload
);
591 KUrl
DolphinView::viewPropertiesUrl() const
593 if (isColumnViewActive()) {
594 return m_dirLister
->url();
600 void DolphinView::applyViewProperties(const KUrl
& url
)
602 if (isColumnViewActive() && m_dirLister
->url().isParentOf(url
)) {
603 // The column view is active, hence don't apply the view properties
604 // of sub directories (represented by columns) to the view. The
605 // view always represents the properties of the first column.
609 const ViewProperties
props(url
);
611 const Mode mode
= props
.viewMode();
612 if (m_mode
!= mode
) {
617 if (m_mode
== ColumnView
) {
618 // The mode has been changed to the Column View. When starting the dir
619 // lister with DolphinView::startDirLister() it is important to give a
620 // hint that the dir lister may not keep the current directory
621 // although this is the default for showing a hierarchy.
622 m_initializeColumnView
= true;
625 if (itemView() == 0) {
628 Q_ASSERT(itemView() != 0);
629 Q_ASSERT(m_fileItemDelegate
!= 0);
631 const bool showHiddenFiles
= props
.showHiddenFiles();
632 if (showHiddenFiles
!= m_dirLister
->showingDotFiles()) {
633 m_dirLister
->setShowingDotFiles(showHiddenFiles
);
634 emit
showHiddenFilesChanged();
637 const bool categorized
= props
.categorizedSorting();
638 if (categorized
!= categorizedSorting()) {
639 if (supportsCategorizedSorting()) {
640 Q_ASSERT(m_iconsView
!= 0);
642 Q_ASSERT(m_iconsView
->itemCategorizer() == 0);
643 m_iconsView
->setItemCategorizer(new DolphinItemCategorizer());
645 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
646 m_iconsView
->setItemCategorizer(0);
650 emit
categorizedSortingChanged();
653 const DolphinView::Sorting sorting
= props
.sorting();
654 if (sorting
!= m_proxyModel
->sorting()) {
655 m_proxyModel
->setSorting(sorting
);
656 emit
sortingChanged(sorting
);
659 const Qt::SortOrder sortOrder
= props
.sortOrder();
660 if (sortOrder
!= m_proxyModel
->sortOrder()) {
661 m_proxyModel
->setSortOrder(sortOrder
);
662 emit
sortOrderChanged(sortOrder
);
665 KFileItemDelegate::AdditionalInformation info
= props
.additionalInfo();
666 if (info
!= m_fileItemDelegate
->additionalInformation()) {
667 m_controller
->setShowAdditionalInfo(info
!= KFileItemDelegate::NoInformation
);
668 m_fileItemDelegate
->setAdditionalInformation(info
);
669 emit
additionalInfoChanged(info
);
672 const bool showPreview
= props
.showPreview();
673 if (showPreview
!= m_controller
->showPreview()) {
674 m_controller
->setShowPreview(showPreview
);
675 emit
showPreviewChanged();
679 void DolphinView::changeSelection(const QList
<KFileItem
>& selection
)
682 if (selection
.isEmpty()) {
685 const KUrl
& baseUrl
= url();
687 QItemSelection new_selection
;
688 foreach(const KFileItem
& item
, selection
) {
689 url
= item
.url().upUrl();
690 if (baseUrl
.equals(url
, KUrl::CompareWithoutTrailingSlash
)) {
691 QModelIndex index
= m_proxyModel
->mapFromSource(m_dirModel
->indexForItem(item
));
692 new_selection
.select(index
, index
);
695 itemView()->selectionModel()->select(new_selection
,
696 QItemSelectionModel::ClearAndSelect
697 | QItemSelectionModel::Current
);
700 void DolphinView::openContextMenu(const QPoint
& pos
)
704 const QModelIndex index
= itemView()->indexAt(pos
);
705 if (isValidNameIndex(index
)) {
706 item
= fileItem(index
);
709 emit
requestContextMenu(item
, url());
712 void DolphinView::dropUrls(const KUrl::List
& urls
,
713 const QModelIndex
& index
,
717 if (isValidNameIndex(index
)) {
718 KFileItem item
= fileItem(index
);
719 Q_ASSERT(!item
.isNull());
721 // the URLs are dropped above a directory
726 if ((directory
.isNull()) && (source
== itemView())) {
727 // The dropping is done into the same viewport where
728 // the dragging has been started. Just ignore this...
732 const KUrl
& destination
= (directory
.isNull()) ?
733 url() : directory
.url();
734 dropUrls(urls
, destination
);
737 void DolphinView::dropUrls(const KUrl::List
& urls
,
738 const KUrl
& destination
)
740 emit
urlsDropped(urls
, destination
);
743 void DolphinView::updateSorting(DolphinView::Sorting sorting
)
745 ViewProperties
props(viewPropertiesUrl());
746 props
.setSorting(sorting
);
748 m_proxyModel
->setSorting(sorting
);
750 emit
sortingChanged(sorting
);
753 void DolphinView::updateSortOrder(Qt::SortOrder order
)
755 ViewProperties
props(viewPropertiesUrl());
756 props
.setSortOrder(order
);
758 m_proxyModel
->setSortOrder(order
);
760 emit
sortOrderChanged(order
);
763 void DolphinView::emitContentsMoved()
765 // only emit the contents moved signal if:
766 // - no directory loading is ongoing (this would reset the contents position
768 // - if the Column View is active: the column view does an automatic
769 // positioning during the loading operation, which must be remembered
770 if (!m_loadingDirectory
|| isColumnViewActive()) {
771 const QPoint
pos(contentsPosition());
772 emit
contentsMoved(pos
.x(), pos
.y());
776 void DolphinView::updateCutItems()
778 // restore the icons of all previously selected items to the
780 QList
<CutItem
>::const_iterator it
= m_cutItemsCache
.begin();
781 QList
<CutItem
>::const_iterator end
= m_cutItemsCache
.end();
783 const QModelIndex index
= m_dirModel
->indexForUrl((*it
).url
);
784 if (index
.isValid()) {
785 m_dirModel
->setData(index
, QIcon((*it
).pixmap
), Qt::DecorationRole
);
789 m_cutItemsCache
.clear();
791 // ... and apply an item effect to all currently cut items
792 applyCutItemEffect();
795 void DolphinView::showHoverInformation(const QModelIndex
& index
)
797 if (hasSelection()) {
801 const KFileItem item
= fileItem(index
);
802 if (!item
.isNull()) {
803 emit
requestItemInfo(item
);
807 void DolphinView::clearHoverInformation()
809 emit
requestItemInfo(KFileItem());
813 void DolphinView::createView()
815 // delete current view
816 QAbstractItemView
* view
= itemView();
818 m_topLayout
->removeWidget(view
);
820 if (view
== m_iconsView
) {
821 KItemCategorizer
* categorizer
= m_iconsView
->itemCategorizer();
822 m_iconsView
->setItemCategorizer(0);
830 m_fileItemDelegate
= 0;
833 Q_ASSERT(m_iconsView
== 0);
834 Q_ASSERT(m_detailsView
== 0);
835 Q_ASSERT(m_columnView
== 0);
837 // ... and recreate it representing the current mode
840 m_iconsView
= new DolphinIconsView(this, m_controller
);
845 m_detailsView
= new DolphinDetailsView(this, m_controller
);
846 view
= m_detailsView
;
850 m_columnView
= new DolphinColumnView(this, m_controller
);
857 m_fileItemDelegate
= new KFileItemDelegate(view
);
858 view
->setItemDelegate(m_fileItemDelegate
);
860 view
->setModel(m_proxyModel
);
861 view
->setSelectionMode(QAbstractItemView::ExtendedSelection
);
863 new KMimeTypeResolver(view
, m_dirModel
);
864 m_topLayout
->insertWidget(1, view
);
866 connect(view
->selectionModel(), SIGNAL(selectionChanged(const QItemSelection
&, const QItemSelection
&)),
867 this, SLOT(emitSelectionChangedSignal()));
868 connect(view
->verticalScrollBar(), SIGNAL(valueChanged(int)),
869 this, SLOT(emitContentsMoved()));
870 connect(view
->horizontalScrollBar(), SIGNAL(valueChanged(int)),
871 this, SLOT(emitContentsMoved()));
874 QAbstractItemView
* DolphinView::itemView() const
876 if (m_detailsView
!= 0) {
877 return m_detailsView
;
878 } else if (m_columnView
!= 0) {
885 bool DolphinView::isValidNameIndex(const QModelIndex
& index
) const
887 return index
.isValid() && (index
.column() == KDirModel::Name
);
890 bool DolphinView::isCutItem(const KFileItem
& item
) const
892 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
893 const KUrl::List cutUrls
= KUrl::List::fromMimeData(mimeData
);
895 const KUrl
& itemUrl
= item
.url();
896 KUrl::List::const_iterator it
= cutUrls
.begin();
897 const KUrl::List::const_iterator end
= cutUrls
.end();
899 if (*it
== itemUrl
) {
908 void DolphinView::applyCutItemEffect()
910 const QMimeData
* mimeData
= QApplication::clipboard()->mimeData();
911 if (!KonqMimeData::decodeIsCutSelection(mimeData
)) {
915 KFileItemList
items(m_dirLister
->items());
916 KFileItemList::const_iterator it
= items
.begin();
917 const KFileItemList::const_iterator end
= items
.end();
919 KFileItem
* item
= *it
;
920 if (isCutItem(*item
)) {
921 const QModelIndex index
= m_dirModel
->indexForItem(*item
);
922 // Huh? the item is already known
923 //const KFileItem item = m_dirModel->itemForIndex(index);
924 const QVariant value
= m_dirModel
->data(index
, Qt::DecorationRole
);
925 if (value
.type() == QVariant::Icon
) {
926 const QIcon
icon(qvariant_cast
<QIcon
>(value
));
927 QPixmap pixmap
= icon
.pixmap(128, 128);
929 // remember current pixmap for the item to be able
930 // to restore it when other items get cut
932 cutItem
.url
= item
->url();
933 cutItem
.pixmap
= pixmap
;
934 m_cutItemsCache
.append(cutItem
);
936 // apply icon effect to the cut item
937 KIconEffect iconEffect
;
938 pixmap
= iconEffect
.apply(pixmap
, K3Icon::Desktop
, K3Icon::DisabledState
);
939 m_dirModel
->setData(index
, QIcon(pixmap
), Qt::DecorationRole
);
946 void DolphinView::updateViewportColor()
948 QColor color
= KColorScheme(KColorScheme::View
).background();
950 emit
urlChanged(url());
951 emit
selectionChanged(selectedItems());
956 QWidget
* viewport
= itemView()->viewport();
958 palette
.setColor(viewport
->backgroundRole(), color
);
959 viewport
->setPalette(palette
);
962 #include "dolphinview.moc"