#include <kactioncollection.h>
#include <kcolorscheme.h>
#include <kdirlister.h>
-#include <kfileitemdelegate.h>
+#include <kfilepreviewgenerator.h>
#include <kiconeffect.h>
+#include <kfileitem.h>
#include <klocale.h>
#include <kio/deletejob.h>
#include <kio/netaccess.h>
#include <kmenu.h>
#include <kmessagebox.h>
#include <kmimetyperesolver.h>
+#include <konq_fileitemcapabilities.h>
#include <konq_operations.h>
#include <konqmimedata.h>
+#include <kstringhandler.h>
#include <ktoggleaction.h>
#include <kurl.h>
-#include "dolphindropcontroller.h"
#include "dolphinmodel.h"
#include "dolphincolumnview.h"
#include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
#include "dolphinsortfilterproxymodel.h"
#include "dolphindetailsview.h"
+#include "dolphin_detailsmodesettings.h"
#include "dolphiniconsview.h"
-#include "dolphinsettings.h"
+#include "settings/dolphinsettings.h"
#include "dolphin_generalsettings.h"
-#include "iconmanager.h"
+#include "draganddrophelper.h"
+#include "folderexpander.h"
#include "renamedialog.h"
+#include "tooltips/tooltipmanager.h"
#include "viewproperties.h"
+#include "zoomlevelinfo.h"
+
+/**
+ * Helper function for sorting items with qSort() in
+ * DolphinView::renameSelectedItems().
+ */
+bool lessThan(const KFileItem& item1, const KFileItem& item2)
+{
+ return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0;
+}
DolphinView::DolphinView(QWidget* parent,
const KUrl& url,
m_showPreview(false),
m_loadingDirectory(false),
m_storedCategorizedSorting(false),
+ m_tabsForFiles(false),
+ m_isContextMenuOpen(false),
+ m_ignoreViewProperties(false),
m_mode(DolphinView::IconsView),
m_topLayout(0),
m_controller(0),
m_dolphinModel(dolphinModel),
m_dirLister(dirLister),
m_proxyModel(proxyModel),
- m_iconManager(0)
+ m_previewGenerator(0),
+ m_toolTipManager(0),
+ m_rootUrl(),
+ m_currentItemUrl(),
+ m_expandedDragSource(0)
{
- setFocusPolicy(Qt::StrongFocus);
m_topLayout = new QVBoxLayout(this);
m_topLayout->setSpacing(0);
m_topLayout->setMargin(0);
m_controller = new DolphinController(this);
m_controller->setUrl(url);
- // Receiver of the DolphinView signal 'urlChanged()' don't need
- // to care whether the internal controller changed the URL already or whether
- // the controller just requested an URL change and will be updated later.
- // In both cases the URL has been changed:
connect(m_controller, SIGNAL(urlChanged(const KUrl&)),
this, SIGNAL(urlChanged(const KUrl&)));
connect(m_controller, SIGNAL(requestUrlChange(const KUrl&)),
- this, SIGNAL(urlChanged(const KUrl&)));
+ this, SLOT(slotRequestUrlChange(const KUrl&)));
- connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
- this, SLOT(openContextMenu(const QPoint&)));
- connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const KUrl&, const KFileItem&)),
- this, SLOT(dropUrls(const KUrl::List&, const KUrl&, const KFileItem&)));
+ connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QList<QAction*>&)),
+ this, SLOT(openContextMenu(const QPoint&, const QList<QAction*>&)));
+ connect(m_controller, SIGNAL(urlsDropped(const KFileItem&, const KUrl&, QDropEvent*)),
+ this, SLOT(dropUrls(const KFileItem&, const KUrl&, QDropEvent*)));
connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
this, SLOT(updateSorting(DolphinView::Sorting)));
connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
this, SLOT(updateAdditionalInfo(const KFileItemDelegate::InformationList&)));
connect(m_controller, SIGNAL(itemTriggered(const KFileItem&)),
this, SLOT(triggerItem(const KFileItem&)));
+ connect(m_controller, SIGNAL(tabRequested(const KUrl&)),
+ this, SIGNAL(tabRequested(const KUrl&)));
connect(m_controller, SIGNAL(activated()),
this, SLOT(activate()));
connect(m_controller, SIGNAL(itemEntered(const KFileItem&)),
connect(m_controller, SIGNAL(viewportEntered()),
this, SLOT(clearHoverInformation()));
+ connect(m_dirLister, SIGNAL(redirection(KUrl, KUrl)),
+ this, SIGNAL(redirection(KUrl, KUrl)));
+ connect(m_dirLister, SIGNAL(completed()),
+ this, SLOT(restoreCurrentItem()));
+
applyViewProperties(url);
m_topLayout->addWidget(itemView());
}
DolphinView::~DolphinView()
{
+ kDebug() << "Deleted view " << m_expandedDragSource;
+ delete m_expandedDragSource;
+ m_expandedDragSource = 0;
}
const KUrl& DolphinView::url() const
}
m_active = active;
- m_selectionModel->clearSelection();
QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
if (active) {
update();
if (active) {
+ itemView()->setFocus();
emit activated();
}
return; // the wished mode is already set
}
+ const int oldZoomLevel = m_controller->zoomLevel();
m_mode = mode;
deleteView();
}
emit modeChanged();
+
+ updateZoomLevel(oldZoomLevel);
+ if (m_showPreview) {
+ loadDirectory(viewPropsUrl);
+ }
}
DolphinView::Mode DolphinView::mode() const
KFileItemList DolphinView::selectedItems() const
{
+ if (isColumnViewActive()) {
+ return m_columnView->selectedItems();
+ }
+
const QAbstractItemView* view = itemView();
// Our view has a selection, we will map them back to the DolphinModel
KFileItemList itemList;
const QModelIndexList indexList = selection.indexes();
- foreach (QModelIndex index, indexList) {
+ foreach (const QModelIndex &index, indexList) {
KFileItem item = m_dolphinModel->itemForIndex(index);
if (!item.isNull()) {
itemList.append(item);
{
KUrl::List urls;
const KFileItemList list = selectedItems();
- foreach (KFileItem item, list) {
+ foreach (const KFileItem &item, list) {
urls.append(item.url());
}
return urls;
}
-KFileItem DolphinView::fileItem(const QModelIndex& index) const
+int DolphinView::selectedItemsCount() const
{
- const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
- return m_dolphinModel->itemForIndex(dolphinModelIndex);
+ if (isColumnViewActive()) {
+ // TODO: get rid of this special case by adjusting the dir lister
+ // to the current column
+ return m_columnView->selectedItems().count();
+ }
+
+ return itemView()->selectionModel()->selection().count();
}
void DolphinView::setContentsPosition(int x, int y)
return QPoint(x, y);
}
-void DolphinView::zoomIn()
+void DolphinView::setZoomLevel(int level)
{
- m_controller->triggerZoomIn();
- m_iconManager->updatePreviews();
-}
-
-void DolphinView::zoomOut()
-{
- m_controller->triggerZoomOut();
- m_iconManager->updatePreviews();
-}
+ if (level < ZoomLevelInfo::minimumLevel()) {
+ level = ZoomLevelInfo::minimumLevel();
+ } else if (level > ZoomLevelInfo::maximumLevel()) {
+ level = ZoomLevelInfo::maximumLevel();
+ }
-bool DolphinView::isZoomInPossible() const
-{
- return m_controller->isZoomInPossible();
+ if (level != zoomLevel()) {
+ m_controller->setZoomLevel(level);
+ m_previewGenerator->updatePreviews();
+ emit zoomLevelChanged(level);
+ }
}
-bool DolphinView::isZoomOutPossible() const
+int DolphinView::zoomLevel() const
{
- return m_controller->isZoomOutPossible();
+ return m_controller->zoomLevel();
}
void DolphinView::setSorting(Sorting sorting)
void DolphinView::refresh()
{
+ m_ignoreViewProperties = false;
+
const bool oldActivationState = m_active;
+ const int oldZoomLevel = m_controller->zoomLevel();
m_active = true;
createView();
reload();
setActive(oldActivationState);
+ updateZoomLevel(oldZoomLevel);
}
void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
return;
}
+ m_previewGenerator->cancelPreviews();
m_controller->setUrl(url); // emits urlChanged, which we forward
if (!rootUrl.isEmpty() && rootUrl.isParentOf(url)) {
}
}
-void DolphinView::calculateItemCount(int& fileCount, int& folderCount)
+void DolphinView::calculateItemCount(int& fileCount,
+ int& folderCount,
+ KIO::filesize_t& totalFileSize) const
{
- foreach (KFileItem item, m_dirLister->items()) {
+ foreach (const KFileItem& item, m_dirLister->items()) {
if (item.isDir()) {
++folderCount;
} else {
++fileCount;
+ totalFileSize += item.size();
}
}
}
+QString DolphinView::statusBarText() const
+{
+ QString text;
+ int folderCount = 0;
+ int fileCount = 0;
+ KIO::filesize_t totalFileSize = 0;
+
+ if (hasSelection()) {
+ // give a summary of the status of the selected files
+ const KFileItemList list = selectedItems();
+ if (list.isEmpty()) {
+ // when an item is triggered, it is temporary selected but selectedItems()
+ // will return an empty list
+ return text;
+ }
+
+ KFileItemList::const_iterator it = list.begin();
+ const KFileItemList::const_iterator end = list.end();
+ while (it != end) {
+ const KFileItem& item = *it;
+ if (item.isDir()) {
+ ++folderCount;
+ } else {
+ ++fileCount;
+ totalFileSize += item.size();
+ }
+ ++it;
+ }
+
+ if (folderCount + fileCount == 1) {
+ // if only one item is selected, show the filename
+ const QString name = list.first().name();
+ text = (folderCount == 1) ? i18nc("@info:status", "<filename>%1</filename> selected", name) :
+ i18nc("@info:status", "<filename>%1</filename> selected (%2)",
+ name, KIO::convertSize(totalFileSize));
+ } else {
+ // at least 2 items are selected
+ const QString foldersText = i18ncp("@info:status", "1 Folder selected", "%1 Folders selected", folderCount);
+ const QString filesText = i18ncp("@info:status", "1 File selected", "%1 Files selected", fileCount);
+ if ((folderCount > 0) && (fileCount > 0)) {
+ text = i18nc("@info:status folders, files (size)", "%1, %2 (%3)",
+ foldersText, filesText, KIO::convertSize(totalFileSize));
+ } else if (fileCount > 0) {
+ text = i18nc("@info:status files (size)", "%1 (%2)", filesText, KIO::convertSize(totalFileSize));
+ } else {
+ Q_ASSERT(folderCount > 0);
+ text = foldersText;
+ }
+ }
+ } else {
+ calculateItemCount(fileCount, folderCount, totalFileSize);
+ text = KIO::itemsSummaryString(fileCount + folderCount,
+ fileCount, folderCount,
+ totalFileSize, true);
+ }
+
+ return text;
+}
+
void DolphinView::setUrl(const KUrl& url)
{
+ // remember current item candidate (see restoreCurrentItem())
+ m_currentItemUrl = url;
updateView(url, KUrl());
}
void DolphinView::renameSelectedItems()
{
- const KFileItemList items = selectedItems();
- if (items.count() > 1) {
+ KFileItemList items = selectedItems();
+ const int itemCount = items.count();
+ if (itemCount < 1) {
+ return;
+ }
+
+ if (itemCount > 1) {
// More than one item has been selected for renaming. Open
// a rename dialog and rename all items afterwards.
RenameDialog dialog(this, items);
if (newName.isEmpty()) {
emit errorMessage(dialog.errorString());
} else {
- // TODO: check how this can be integrated into KonqFileUndoManager/KonqOperations
+ // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
// as one operation instead of n rename operations like it is done now...
Q_ASSERT(newName.contains('#'));
+ // currently the items are sorted by the selection order, resort
+ // them by the file name
+ qSort(items.begin(), items.end(), lessThan);
+
// iterate through all selected items and rename them...
int index = 1;
- foreach (KFileItem item, items) {
+ foreach (const KFileItem& item, items) {
const KUrl& oldUrl = item.url();
QString number;
number.setNum(index++);
KUrl newUrl = oldUrl;
newUrl.setFileName(name);
KonqOperations::rename(this, oldUrl, newUrl);
- emit doingOperation(KonqFileUndoManager::RENAME);
}
}
}
} else if (DolphinSettings::instance().generalSettings()->renameInline()) {
- Q_ASSERT(items.count() == 1);
+ Q_ASSERT(itemCount == 1);
if (isColumnViewActive()) {
m_columnView->editItem(items.first());
itemView()->edit(proxyIndex);
}
} else {
- Q_ASSERT(items.count() == 1);
+ Q_ASSERT(itemCount == 1);
RenameDialog dialog(this, items);
if (dialog.exec() == QDialog::Rejected) {
KUrl newUrl = oldUrl;
newUrl.setFileName(newName);
KonqOperations::rename(this, oldUrl, newUrl);
- emit doingOperation(KonqFileUndoManager::RENAME);
}
}
}
void DolphinView::trashSelectedItems()
{
- emit doingOperation(KonqFileUndoManager::TRASH);
- KonqOperations::del(this, KonqOperations::TRASH, selectedUrls());
+ const KUrl::List list = simplifiedSelectedUrls();
+ KonqOperations::del(this, KonqOperations::TRASH, list);
}
void DolphinView::deleteSelectedItems()
{
- const KUrl::List list = selectedUrls();
+ const KUrl::List list = simplifiedSelectedUrls();
const bool del = KonqOperations::askDeleteConfirmation(list,
KonqOperations::DEL,
KonqOperations::DEFAULT_CONFIRMATION,
void DolphinView::cutSelectedItems()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = selectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, true);
+ QMimeData* mimeData = selectionMimeData();
+ KonqMimeData::addIsCutSelection(mimeData, true);
QApplication::clipboard()->setMimeData(mimeData);
}
void DolphinView::copySelectedItems()
{
- QMimeData* mimeData = new QMimeData();
- const KUrl::List kdeUrls = selectedUrls();
- const KUrl::List mostLocalUrls;
- KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, false);
+ QMimeData* mimeData = selectionMimeData();
QApplication::clipboard()->setMimeData(mimeData);
}
void DolphinView::paste()
{
- QClipboard* clipboard = QApplication::clipboard();
- const QMimeData* mimeData = clipboard->mimeData();
+ pasteToUrl(url());
+}
- const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
- if (KonqMimeData::decodeIsCutSelection(mimeData)) {
- KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url());
- emit doingOperation(KonqFileUndoManager::MOVE);
- clipboard->clear();
- } else {
- KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url());
- emit doingOperation(KonqFileUndoManager::COPY);
+void DolphinView::pasteIntoFolder()
+{
+ const KFileItemList items = selectedItems();
+ if ((items.count() == 1) && items.first().isDir()) {
+ pasteToUrl(items.first().url());
}
}
props.setShowPreview(show);
m_showPreview = show;
- m_iconManager->setShowPreview(show);
+ m_previewGenerator->setPreviewShown(show);
+
+ const int oldZoomLevel = m_controller->zoomLevel();
emit showPreviewChanged();
+ // Enabling or disabling the preview might change the icon size of the view.
+ // As the view does not emit a signal when the icon size has been changed,
+ // the used zoom level of the controller must be adjusted manually:
+ updateZoomLevel(oldZoomLevel);
+
loadDirectory(viewPropsUrl);
}
}
}
-
void DolphinView::mouseReleaseEvent(QMouseEvent* event)
{
QWidget::mouseReleaseEvent(event);
{
if (event->modifiers() & Qt::ControlModifier) {
const int delta = event->delta();
- if ((delta > 0) && isZoomInPossible()) {
- zoomIn();
- } else if ((delta < 0) && isZoomOutPossible()) {
- zoomOut();
+ const int level = zoomLevel();
+ if (delta > 0) {
+ setZoomLevel(level + 1);
+ } else if (delta < 0) {
+ setZoomLevel(level - 1);
}
event->accept();
}
bool DolphinView::eventFilter(QObject* watched, QEvent* event)
{
- if ((watched == itemView()) && (event->type() == QEvent::FocusIn)) {
- m_controller->requestActivation();
+ switch (event->type()) {
+ case QEvent::FocusIn:
+ if (watched == itemView()) {
+ m_controller->requestActivation();
+ }
+ break;
+
+ case QEvent::MouseButtonPress:
+ kDebug() << "m_expandedDragSource = " << m_expandedDragSource;
+ if ((watched == itemView()->viewport()) && (m_expandedDragSource != 0)) {
+ // Listening to a mousebutton press event to delete expanded views is a
+ // workaround, as it seems impossible for the FolderExpander to know when
+ // a dragging outside a view has been finished. However it works quite well:
+ // A mousebutton press event indicates that a drag operation must be
+ // finished already.
+ kDebug() << "Deleted view " << m_expandedDragSource;
+ m_expandedDragSource->deleteLater();
+ m_expandedDragSource = 0;
+ }
+ break;
+
+ case QEvent::DragEnter:
+ if (watched == itemView()->viewport()) {
+ setActive(true);
+ }
+ break;
+
+ case QEvent::KeyPress:
+ if ((watched == itemView()) && (m_toolTipManager != 0)) {
+ m_toolTipManager->hideTip();
+ }
+ break;
+
+ default:
+ break;
}
return QWidget::eventFilter(watched, event);
return;
}
- if (item.isNull()) {
+ // TODO: the m_isContextMenuOpen check is a workaround for Qt-issue 207192
+ if (item.isNull() || m_isContextMenuOpen) {
return;
}
+ if (m_toolTipManager != 0) {
+ m_toolTipManager->hideTip();
+ }
emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
}
emit selectionChanged(DolphinView::selectedItems());
}
-void DolphinView::openContextMenu(const QPoint& pos)
+void DolphinView::openContextMenu(const QPoint& pos,
+ const QList<QAction*>& customActions)
{
KFileItem item;
+ if (isColumnViewActive()) {
+ item = m_columnView->itemAt(pos);
+ } else {
+ const QModelIndex index = itemView()->indexAt(pos);
+ if (index.isValid() && (index.column() == DolphinModel::Name)) {
+ const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index);
+ item = m_dolphinModel->itemForIndex(dolphinModelIndex);
+ }
+ }
- const QModelIndex index = itemView()->indexAt(pos);
- if (index.isValid() && (index.column() == DolphinModel::Name)) {
- item = fileItem(index);
+ if (m_toolTipManager != 0) {
+ m_toolTipManager->hideTip();
}
- emit requestContextMenu(item, url());
+ m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192
+ emit requestContextMenu(item, url(), customActions);
+ m_isContextMenuOpen = false;
}
-void DolphinView::dropUrls(const KUrl::List& urls,
+void DolphinView::dropUrls(const KFileItem& destItem,
const KUrl& destPath,
- const KFileItem& destItem)
-{
- Q_ASSERT(!urls.isEmpty());
- const KUrl& destination = !destItem.isNull() && destItem.isDir() ?
- destItem.url() : destPath;
- const KUrl sourceDir = KUrl(urls.first().directory());
- if (sourceDir != destination) {
- dropUrls(urls, destination);
- }
-}
-
-void DolphinView::dropUrls(const KUrl::List& urls,
- const KUrl& destination)
+ QDropEvent* event)
{
- DolphinDropController dropController(this);
- // forward doingOperation signal up to the mainwindow
- connect(&dropController, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)),
- this, SIGNAL(doingOperation(KonqFileUndoManager::CommandType)));
- dropController.dropUrls(urls, destination);
+ DragAndDropHelper::instance().dropUrls(destItem, destPath, event, this);
}
void DolphinView::updateSorting(DolphinView::Sorting sorting)
KUrl::List urls = KUrl::List::fromMimeData(mimeData);
if (!urls.isEmpty()) {
- ret.first = true;
+ // disable the paste action if no writing is supported
+ KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url());
+ ret.first = KonqFileItemCapabilities(KFileItemList() << item).supportsWriting();
+
if (urls.count() == 1) {
const KFileItem item(KFileItem::Unknown, KFileItem::Unknown, urls.first(), true);
ret.second = item.isDir() ? i18nc("@action:inmenu", "Paste One Folder") :
return ret;
}
+void DolphinView::setTabsForFilesEnabled(bool tabsForFiles)
+{
+ m_tabsForFiles = tabsForFiles;
+}
+
+bool DolphinView::isTabsForFilesEnabled() const
+{
+ return m_tabsForFiles;
+}
+
+bool DolphinView::itemsExpandable() const
+{
+ return (m_detailsView != 0) && m_detailsView->itemsExpandable();
+}
+
+void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
+{
+ if (view == 0)
+ return;
+
+ if (DragAndDropHelper::instance().isDragSource(view)) {
+ kDebug() << "Is current drag source";
+ // We must store for later deletion.
+ if (m_expandedDragSource != 0) {
+ // The old stored view is obviously not the drag source anymore.
+ kDebug() << "Deleted old view " << m_expandedDragSource;
+ m_expandedDragSource->deleteLater();
+ m_expandedDragSource = 0;
+ }
+ view->hide();
+ m_expandedDragSource = view;
+ }
+ else {
+ kDebug() << "Deleted new view " << view;
+ view->deleteLater();
+ }
+}
+
void DolphinView::emitContentsMoved()
{
// only emit the contents moved signal if:
{
if (job->error() == 0) {
emit operationCompletedMessage(i18nc("@info:status", "Delete operation completed."));
- } else {
+ } else if (job->error() != KIO::ERR_USER_CANCELED) {
emit errorMessage(job->errorString());
}
}
+void DolphinView::slotRequestUrlChange(const KUrl& url)
+{
+ emit requestUrlChange(url);
+ m_controller->setUrl(url);
+}
+
+void DolphinView::restoreCurrentItem()
+{
+ const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
+ if (dirIndex.isValid()) {
+ const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+ QAbstractItemView* view = itemView();
+ const bool clearSelection = !hasSelection();
+ view->setCurrentIndex(proxyIndex);
+ if (clearSelection) {
+ view->clearSelection();
+ }
+ }
+}
+
void DolphinView::loadDirectory(const KUrl& url, bool reload)
{
if (!url.isValid()) {
void DolphinView::applyViewProperties(const KUrl& url)
{
+ if (m_ignoreViewProperties) {
+ return;
+ }
+
if (isColumnViewActive() && rootUrl().isParentOf(url)) {
// The column view is active, hence don't apply the view properties
// of sub directories (represented by columns) to the view. The
const Mode mode = props.viewMode();
if (m_mode != mode) {
+ const int oldZoomLevel = m_controller->zoomLevel();
+
m_mode = mode;
createView();
emit modeChanged();
+
+ updateZoomLevel(oldZoomLevel);
}
if (itemView() == 0) {
createView();
const bool showPreview = props.showPreview();
if (showPreview != m_showPreview) {
m_showPreview = showPreview;
- m_iconManager->setShowPreview(showPreview);
+ m_previewGenerator->setPreviewShown(showPreview);
+
+ const int oldZoomLevel = m_controller->zoomLevel();
emit showPreviewChanged();
+
+ // Enabling or disabling the preview might change the icon size of the view.
+ // As the view does not emit a signal when the icon size has been changed,
+ // the used zoom level of the controller must be adjusted manually:
+ updateZoomLevel(oldZoomLevel);
+ }
+
+ if (DolphinSettings::instance().generalSettings()->globalViewProps()) {
+ // During the lifetime of a DolphinView instance the global view properties
+ // should not be changed. This allows e. g. to split a view and use different
+ // view properties for each view.
+ m_ignoreViewProperties = true;
}
}
Q_ASSERT(view != 0);
view->installEventFilter(this);
+ view->viewport()->installEventFilter(this);
+ setFocusProxy(view);
+
+ if (m_mode != ColumnView) {
+ // Give the view the ability to auto-expand its directories on hovering
+ // (the column view takes care about this itself). If the details view
+ // uses expandable folders, the auto-expanding should be used always.
+ DolphinSettings& settings = DolphinSettings::instance();
+ const bool enabled = settings.generalSettings()->autoExpandFolders() ||
+ ((m_detailsView != 0) && settings.detailsModeSettings()->expandableFolders());
+
+ FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel);
+ folderExpander->setEnabled(enabled);
+ connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
+ m_controller, SLOT(triggerItem(const QModelIndex&)));
+ }
+ else {
+ // Listen out for requests to delete the current column.
+ connect(m_columnView, SIGNAL(requestColumnDeletion(QAbstractItemView*)),
+ this, SLOT(deleteWhenNotDragSource(QAbstractItemView*)));
+ }
m_controller->setItemView(view);
- m_fileItemDelegate = new KFileItemDelegate(view);
+ m_fileItemDelegate = new DolphinFileItemDelegate(view);
+ m_fileItemDelegate->setShowToolTipWhenElided(false);
+ m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
view->setItemDelegate(m_fileItemDelegate);
view->setModel(m_proxyModel);
view->setSelectionMode(QAbstractItemView::ExtendedSelection);
- new KMimeTypeResolver(view, m_dolphinModel);
- m_iconManager = new IconManager(view, m_proxyModel);
- m_iconManager->setShowPreview(m_showPreview);
+ m_previewGenerator = new KFilePreviewGenerator(view);
+ m_previewGenerator->setPreviewShown(m_showPreview);
+
+ if (DolphinSettings::instance().generalSettings()->showToolTips()) {
+ m_toolTipManager = new ToolTipManager(view, m_proxyModel);
+ connect(m_controller, SIGNAL(hideToolTip()),
+ m_toolTipManager, SLOT(hideTip()));
+ }
m_topLayout->insertWidget(1, view);
{
QAbstractItemView* view = itemView();
if (view != 0) {
+ // It's important to set the keyboard focus to the parent
+ // before deleting the view: Otherwise when having a split
+ // view the other view will get the focus and will request
+ // an activation (see DolphinView::eventFilter()).
+ setFocusProxy(0);
+ setFocus();
+
m_topLayout->removeWidget(view);
view->close();
- view->deleteLater();
+
+ // m_previewGenerator's parent is not always destroyed, and we
+ // don't want two active at once - manually delete.
+ delete m_previewGenerator;
+ m_previewGenerator = 0;
+
+ disconnect(view);
+ m_controller->disconnect(view);
+ view->disconnect();
+
+ deleteWhenNotDragSource(view);
view = 0;
+
m_iconsView = 0;
m_detailsView = 0;
m_columnView = 0;
m_fileItemDelegate = 0;
- m_iconManager = 0;
+ m_toolTipManager = 0;
}
}
return false;
}
+void DolphinView::pasteToUrl(const KUrl& url)
+{
+ QClipboard* clipboard = QApplication::clipboard();
+ const QMimeData* mimeData = clipboard->mimeData();
+
+ const KUrl::List sourceUrls = KUrl::List::fromMimeData(mimeData);
+ if (KonqMimeData::decodeIsCutSelection(mimeData)) {
+ KonqOperations::copy(this, KonqOperations::MOVE, sourceUrls, url);
+ clipboard->clear();
+ } else {
+ KonqOperations::copy(this, KonqOperations::COPY, sourceUrls, url);
+ }
+}
+
+void DolphinView::updateZoomLevel(int oldZoomLevel)
+{
+ const int newZoomLevel = ZoomLevelInfo::zoomLevelForIconSize(itemView()->iconSize());
+ if (oldZoomLevel != newZoomLevel) {
+ m_controller->setZoomLevel(newZoomLevel);
+ emit zoomLevelChanged(newZoomLevel);
+ }
+}
+
+KUrl::List DolphinView::simplifiedSelectedUrls() const
+{
+ KUrl::List list = selectedUrls();
+ if (itemsExpandable() ) {
+ list = KDirModel::simplifiedUrlList(list);
+ }
+ return list;
+}
+
+QMimeData* DolphinView::selectionMimeData() const
+{
+ if (isColumnViewActive()) {
+ return m_columnView->selectionMimeData();
+ }
+
+ const QAbstractItemView* view = itemView();
+ Q_ASSERT((view != 0) && (view->selectionModel() != 0));
+ const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
+ return m_dolphinModel->mimeData(selection.indexes());
+}
+
#include "dolphinview.moc"