From: Peter Penz Date: Sun, 20 Nov 2011 18:32:52 +0000 (+0100) Subject: Initial draft for bringing back the "Folders" panel X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/b27e599429731337af4bb18b986933c968bea279 Initial draft for bringing back the "Folders" panel The folders panel has been adjusted to use the new view-engine. A lot of things don't work yet, but are mostly minor issues that should be fixable during the next 10 days. --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6956a196c..a10f6b448 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,7 +55,6 @@ set(dolphinprivate_LIB_SRCS views/dolphinviewactionhandler.cpp views/dolphinviewautoscroller.cpp views/draganddrophelper.cpp - views/folderexpander.cpp views/renamedialog.cpp views/tooltips/filemetadatatooltip.cpp views/tooltips/tooltipmanager.cpp @@ -123,12 +122,10 @@ set(dolphin_SRCS panels/information/informationpanelcontent.cpp panels/information/pixmapviewer.cpp panels/information/phononwidget.cpp - panels/folders/ktreeview.cpp panels/places/placespanel.cpp panels/panel.cpp panels/folders/treeviewcontextmenu.cpp panels/folders/folderspanel.cpp - panels/folders/paneltreeview.cpp search/dolphinsearchbox.cpp search/dolphinsearchinformation.cpp settings/general/behaviorsettingspage.cpp diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index a7fa27f0d..b0ffd3c20 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -65,6 +65,8 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : m_updateIconSizeTimer->setInterval(ShortInterval); connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize())); + setVisibleRoles(QList() << "name"); + updateMinimumRolesWidths(); } @@ -302,7 +304,8 @@ void KFileItemListView::initializeItemListWidget(KItemListWidget* item) default: Q_ASSERT(false); break; } - fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout); + fileItemListWidget->setAlternatingBackgroundColors(m_itemLayout == DetailsLayout && + visibleRoles().count() > 1); } bool KFileItemListView::itemSizeHintUpdateRequired(const QSet& changedRoles) const @@ -332,6 +335,8 @@ void KFileItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* m_modelRolesUpdater = new KFileItemModelRolesUpdater(static_cast(current), this); const int size = styleOption().iconSize; m_modelRolesUpdater->setIconSize(QSize(size, size)); + + applyRolesToModel(); } void KFileItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous) @@ -360,6 +365,19 @@ void KFileItemListView::onVisibleRolesChanged(const QList& current, Q_UNUSED(current); Q_UNUSED(previous); applyRolesToModel(); + + if (m_itemLayout == DetailsLayout) { + // Only enable the alternating background colors if more than one role + // is visible + const int previousCount = previous.count(); + const int currentCount = current.count(); + if ((previousCount <= 1 && currentCount > 1) || (previousCount > 1 && currentCount <= 1)) { + const bool enabled = (currentCount > 1); + foreach (KItemListWidget* widget, visibleItemListWidgets()) { + widget->setAlternatingBackgroundColors(enabled); + } + } + } } void KFileItemListView::onStyleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) @@ -410,6 +428,9 @@ void KFileItemListView::slotSortRoleChanged(const QByteArray& current, const QBy void KFileItemListView::triggerVisibleIndexRangeUpdate() { + if (!model()) { + return; + } m_modelRolesUpdater->setPaused(true); m_updateVisibleIndexRangeTimer->start(); } @@ -439,6 +460,9 @@ void KFileItemListView::updateVisibleIndexRange() void KFileItemListView::triggerIconSizeUpdate() { + if (!model()) { + return; + } m_modelRolesUpdater->setPaused(true); m_updateIconSizeTimer->start(); } @@ -494,6 +518,10 @@ QSizeF KFileItemListView::visibleRoleSizeHint(int index, const QByteArray& role) void KFileItemListView::updateLayoutOfVisibleItems() { + if (!model()) { + return; + } + foreach (KItemListWidget* widget, visibleItemListWidgets()) { initializeItemListWidget(widget); } @@ -528,6 +556,10 @@ void KFileItemListView::updateMinimumRolesWidths() void KFileItemListView::applyRolesToModel() { + if (!model()) { + return; + } + Q_ASSERT(qobject_cast(model())); KFileItemModel* fileItemModel = static_cast(model()); diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index d46bfc8da..363503b02 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -49,7 +49,7 @@ KFileItemModel::KFileItemModel(KDirLister* dirLister, QObject* parent) : m_groups(), m_rootExpansionLevel(-1), m_expandedUrls(), - m_restoredExpandedUrls() + m_urlsToExpand() { // Apply default roles that should be determined resetRoles(); @@ -431,9 +431,43 @@ QSet KFileItemModel::expandedUrls() const return m_expandedUrls; } -void KFileItemModel::restoreExpandedUrls(const QSet& urls) +void KFileItemModel::setExpanded(const QSet& urls) { - m_restoredExpandedUrls = urls; + + const KDirLister* dirLister = m_dirLister.data(); + if (!dirLister) { + return; + } + + const int pos = dirLister->url().url().length(); + + // Assure that each sub-path of the URLs that should be + // expanded is added to m_urlsToExpand too. KDirLister + // does not care whether the parent-URL has already been + // expanded. + QSetIterator it1(urls); + while (it1.hasNext()) { + const KUrl& url = it1.next(); + + KUrl urlToExpand = dirLister->url(); + const QStringList subDirs = url.url().mid(pos).split(QDir::separator()); + for (int i = 0; i < subDirs.count(); ++i) { + urlToExpand.addPath(subDirs.at(i)); + m_urlsToExpand.insert(urlToExpand); + } + } + + // KDirLister::open() must called at least once to trigger an initial + // loading. The pending URLs that must be restored are handled + // in slotCompleted(). + QSetIterator it2(m_urlsToExpand); + while (it2.hasNext()) { + const int idx = index(it2.next()); + if (idx >= 0 && !isExpanded(idx)) { + setExpanded(idx, true); + break; + } + } } void KFileItemModel::onGroupedSortingChanged(bool current) @@ -520,7 +554,7 @@ void KFileItemModel::resortAllItems() void KFileItemModel::slotCompleted() { - if (m_restoredExpandedUrls.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) { + if (m_urlsToExpand.isEmpty() && m_minimumUpdateIntervalTimer->isActive()) { // dispatchPendingItems() will be called when the timer // has been expired. m_pendingEmitLoadingCompleted = true; @@ -530,25 +564,26 @@ void KFileItemModel::slotCompleted() m_pendingEmitLoadingCompleted = false; dispatchPendingItemsToInsert(); - if (!m_restoredExpandedUrls.isEmpty()) { + if (!m_urlsToExpand.isEmpty()) { // Try to find a URL that can be expanded. // Note that the parent folder must be expanded before any of its subfolders become visible. // Therefore, some URLs in m_restoredExpandedUrls might not be visible yet // -> we expand the first visible URL we find in m_restoredExpandedUrls. - foreach(const KUrl& url, m_restoredExpandedUrls) { + foreach(const KUrl& url, m_urlsToExpand) { const int index = m_items.value(url, -1); if (index >= 0) { - // We have found an expandable URL. Expand it and return - when - // the dir lister has finished, this slot will be called again. - m_restoredExpandedUrls.remove(url); - setExpanded(index, true); - return; + m_urlsToExpand.remove(url); + if (setExpanded(index, true)) { + // The dir lister has been triggered. This slot will be called + // again after the directory has been expanded. + return; + } } } // None of the URLs in m_restoredExpandedUrls could be found in the model. This can happen // if these URLs have been deleted in the meantime. - m_restoredExpandedUrls.clear(); + m_urlsToExpand.clear(); } emit loadingCompleted(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index b28887b2c..a049f6766 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -120,7 +120,11 @@ public: bool isExpanded(int index) const; bool isExpandable(int index) const; QSet expandedUrls() const; - void restoreExpandedUrls(const QSet& urls); + + /** + * Expands all parent-items of each URL given by \a urls. + */ + void setExpanded(const QSet& urls); signals: void loadingCompleted(); @@ -291,8 +295,9 @@ private: // Stores the URLs of the expanded folders. QSet m_expandedUrls; - // Stores the URLs which have to be expanded in order to restore a previous state of the model. - QSet m_restoredExpandedUrls; + // URLs that must be expanded. The expanding is initially triggered in setExpanded() + // and done step after step in slotCompleted(). + QSet m_urlsToExpand; friend class KFileItemModelTest; // For unit testing }; diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp index d006e2c4d..8ca983acd 100644 --- a/src/kitemviews/kitemlistcontainer.cpp +++ b/src/kitemviews/kitemlistcontainer.cpp @@ -314,7 +314,14 @@ void KItemListContainer::updateSmoothScrollers(Qt::Orientation orientation) void KItemListContainer::initialize() { - if (!m_controller) { + if (m_controller) { + if (m_controller->model()) { + slotModelChanged(m_controller->model(), 0); + } + if (m_controller->view()) { + slotViewChanged(m_controller->view(), 0); + } + } else { m_controller = new KItemListController(this); } diff --git a/src/kitemviews/kitemliststyleoption.cpp b/src/kitemviews/kitemliststyleoption.cpp index f26b220bc..83af31202 100644 --- a/src/kitemviews/kitemliststyleoption.cpp +++ b/src/kitemviews/kitemliststyleoption.cpp @@ -19,13 +19,15 @@ #include "kitemliststyleoption.h" +#include + KItemListStyleOption::KItemListStyleOption() : rect(), font(), fontMetrics(QFont()), palette(), margin(0), - iconSize(0) + iconSize(KIconLoader::SizeMedium) { } diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index 4ded4a93e..389069ce3 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -1196,7 +1196,7 @@ void KItemListView::setModel(KItemModelBase* model) } m_model = model; - m_layouter->setModel(model); + m_layouter->setModel(model); m_grouped = model->groupedSorting(); if (m_model) { @@ -1231,7 +1231,7 @@ void KItemListView::doLayout(LayoutAnimationHint hint, int changedIndex, int cha m_layoutTimer->stop(); } - if (m_model->count() < 0 || m_activeTransactions > 0) { + if (!m_model || m_model->count() < 0 || m_activeTransactions > 0) { return; } @@ -1675,6 +1675,10 @@ void KItemListView::updateVisibleRolesSizes(const KItemRangeList& itemRanges) void KItemListView::updateVisibleRolesSizes() { + if (!m_model) { + return; + } + const int itemCount = m_model->count(); if (itemCount > 0) { updateVisibleRolesSizes(KItemRangeList() << KItemRange(0, itemCount)); @@ -1683,7 +1687,7 @@ void KItemListView::updateVisibleRolesSizes() void KItemListView::updateStretchedVisibleRolesSizes() { - if (!m_itemSize.isEmpty() || m_useHeaderWidths) { + if (!m_itemSize.isEmpty() || m_useHeaderWidths || m_visibleRoles.isEmpty()) { return; } @@ -1692,7 +1696,7 @@ void KItemListView::updateStretchedVisibleRolesSizes() // size does not use the available view-size it the size of the // first role will get stretched. m_stretchedVisibleRolesSizes = m_visibleRolesSizes; - const QByteArray role = visibleRoles().first(); + const QByteArray role = m_visibleRoles.first(); QSizeF firstRoleSize = m_stretchedVisibleRolesSizes.value(role); QSizeF dynamicItemSize = m_itemSize; diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index 76a4b4e08..23911f8fc 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -21,34 +21,34 @@ #include "dolphin_folderspanelsettings.h" #include "dolphin_generalsettings.h" -#include "paneltreeview.h" #include "treeviewcontextmenu.h" +#include +#include +#include +#include +#include +#include + #include #include #include #include #include -#include -#include -#include -#include -#include +#include #include -#include -#include #include +#include + FoldersPanel::FoldersPanel(QWidget* parent) : Panel(parent), m_setLeafVisible(false), m_mouseButtons(Qt::NoButton), m_dirLister(0), - //m_dolphinModel(0), - //m_proxyModel(0), - m_treeView(0), + m_controller(0), m_leafDir() { setLayoutDirection(Qt::LeftToRight); @@ -58,10 +58,10 @@ FoldersPanel::~FoldersPanel() { FoldersPanelSettings::self()->writeConfig(); - //delete m_proxyModel; - //m_proxyModel = 0; - //delete m_dolphinModel; - //m_dolphinModel = 0; + KItemListView* view = m_controller->view(); + m_controller->setView(0); + delete view; + delete m_dirLister; m_dirLister = 0; } @@ -70,8 +70,11 @@ void FoldersPanel::setHiddenFilesShown(bool show) { FoldersPanelSettings::setHiddenFilesShown(show); if (m_dirLister) { + KFileItemModel* model = fileItemModel(); + const QSet expandedUrls = model->expandedUrls(); m_dirLister->setShowingDotFiles(show); m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); + model->setExpanded(expandedUrls); } } @@ -82,7 +85,7 @@ bool FoldersPanel::hiddenFilesShown() const void FoldersPanel::setAutoScrolling(bool enable) { - m_treeView->setAutoHorizontalScroll(enable); + //m_treeView->setAutoHorizontalScroll(enable); FoldersPanelSettings::setAutoScrolling(enable); } @@ -141,43 +144,48 @@ void FoldersPanel::showEvent(QShowEvent* event) m_dirLister->setDelayedMimeTypes(true); m_dirLister->setAutoErrorHandlingEnabled(false, this); m_dirLister->setShowingDotFiles(FoldersPanelSettings::hiddenFilesShown()); - connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted())); - - /*Q_ASSERT(!m_dolphinModel); - m_dolphinModel = new DolphinModel(this); - m_dolphinModel->setDirLister(m_dirLister); - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - connect(m_dolphinModel, SIGNAL(expand(QModelIndex)), - this, SLOT(expandToDir(QModelIndex))); - - Q_ASSERT(!m_proxyModel); - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dolphinModel); - - Q_ASSERT(!m_treeView); - m_treeView = new PanelTreeView(this); - m_treeView->setModel(m_proxyModel); - m_proxyModel->setSorting(DolphinView::SortByName); - m_proxyModel->setSortOrder(Qt::AscendingOrder); - m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling()); - - new FolderExpander(m_treeView, m_proxyModel); - - connect(m_treeView, SIGNAL(clicked(QModelIndex)), - this, SLOT(updateActiveView(QModelIndex))); - connect(m_treeView, SIGNAL(urlsDropped(QModelIndex,QDropEvent*)), - this, SLOT(dropUrls(QModelIndex,QDropEvent*))); - connect(m_treeView, SIGNAL(pressed(QModelIndex)), - this, SLOT(updateMouseButtons())); - - connect(m_treeView->horizontalScrollBar(), SIGNAL(sliderMoved(int)), - this, SLOT(slotHorizontalScrollBarMoved(int))); - connect(m_treeView->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(slotVerticalScrollBarMoved(int))); + + KFileItemListView* view = new KFileItemListView(); + view->setWidgetCreator(new KItemListWidgetCreator()); + + KItemListStyleOption styleOption = view->styleOption(); + styleOption.margin = 2; + styleOption.iconSize = KIconLoader::SizeSmall; + view->setStyleOption(styleOption); + + const qreal itemHeight = qMax(int(KIconLoader::SizeSmall), styleOption.fontMetrics.height()); + view->setItemSize(QSizeF(-1, itemHeight + 2 * styleOption.margin)); + view->setItemLayout(KFileItemListView::DetailsLayout); + + KFileItemModel* model = new KFileItemModel(m_dirLister, this); + // Use a QueuedConnection to give the view the possibility to react first on the + // finished loading. + connect(model, SIGNAL(loadingCompleted()), this, SLOT(slotLoadingCompleted()), Qt::QueuedConnection); + + KItemListContainer* container = new KItemListContainer(this); + m_controller = container->controller(); + m_controller->setView(view); + m_controller->setModel(model); + + // TODO: Check whether it makes sense to make an explicit API for KItemListContainer + // to make the background transparent. + container->setFrameShape(QFrame::NoFrame); + QGraphicsView* graphicsView = qobject_cast(container->viewport()); + if (graphicsView) { + // Make the background of the container transparent and apply the window-text color + // to the text color, so that enough contrast is given for all color + // schemes + QPalette p = graphicsView->palette(); + p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); + p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); + p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); + graphicsView->setPalette(p); + graphicsView->viewport()->setAutoFillBackground(false); + } QVBoxLayout* layout = new QVBoxLayout(this); layout->setMargin(0); - layout->addWidget(m_treeView);*/ + layout->addWidget(container); } loadTree(url()); @@ -205,59 +213,23 @@ void FoldersPanel::keyPressEvent(QKeyEvent* event) const int key = event->key(); if ((key == Qt::Key_Enter) || (key == Qt::Key_Return)) { event->accept(); - updateActiveView(m_treeView->currentIndex()); + //updateActiveView(m_treeView->currentIndex()); } else { Panel::keyPressEvent(event); } } -void FoldersPanel::updateActiveView(const QModelIndex& index) -{ - Q_UNUSED(index); - /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - const KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - if (!item.isNull()) { - emit changeUrl(item.url(), m_mouseButtons); - }*/ -} - -void FoldersPanel::dropUrls(const QModelIndex& index, QDropEvent* event) -{ - Q_UNUSED(event); - if (index.isValid()) { - /*const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - Q_ASSERT(!item.isNull()); - if (item.isDir()) { - Q_UNUSED(event); - //DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); - }*/ - } -} - -void FoldersPanel::expandToDir(const QModelIndex& index) -{ - m_treeView->setExpanded(index, true); - selectLeafDirectory(); -} - -void FoldersPanel::scrollToLeaf() -{ - /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid()) { - m_treeView->scrollTo(proxyIndex); - }*/ -} - void FoldersPanel::updateMouseButtons() { m_mouseButtons = QApplication::mouseButtons(); } -void FoldersPanel::slotDirListerCompleted() +void FoldersPanel::slotLoadingCompleted() { -// m_treeView->resizeColumnToContents(DolphinModel::Name); + const int index = fileItemModel()->index(url()); + if (index >= 0) { + m_controller->selectionManager()->setCurrentItem(index); + } } void FoldersPanel::slotHorizontalScrollBarMoved(int value) @@ -265,7 +237,7 @@ void FoldersPanel::slotHorizontalScrollBarMoved(int value) Q_UNUSED(value); // Disable the auto-scrolling until the vertical scrollbar has // been moved by the user. - m_treeView->setAutoHorizontalScroll(false); + //m_treeView->setAutoHorizontalScroll(false); } void FoldersPanel::slotVerticalScrollBarMoved(int value) @@ -273,7 +245,7 @@ void FoldersPanel::slotVerticalScrollBarMoved(int value) Q_UNUSED(value); // Enable the auto-scrolling again (it might have been disabled by // moving the horizontal scrollbar). - m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling()); + //m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling()); } void FoldersPanel::loadTree(const KUrl& url) @@ -283,10 +255,10 @@ void FoldersPanel::loadTree(const KUrl& url) KUrl baseUrl; if (url.isLocalFile()) { - // use the root directory as base for local URLs (#150941) + // Use the root directory as base for local URLs (#150941) baseUrl = QDir::rootPath(); } else { - // clear the path for non-local URLs and use it as base + // Clear the path for non-local URLs and use it as base baseUrl = url; baseUrl.setPath(QString('/')); } @@ -295,7 +267,14 @@ void FoldersPanel::loadTree(const KUrl& url) m_dirLister->stop(); m_dirLister->openUrl(baseUrl, KDirLister::Reload); } - //m_dolphinModel->expandToUrl(m_leafDir); + + KFileItemModel* model = fileItemModel(); + const int index = model->index(url); + if (index >= 0) { + m_controller->selectionManager()->setCurrentItem(index); + } else { + model->setExpanded(QSet() << url); + } } void FoldersPanel::selectLeafDirectory() @@ -317,4 +296,9 @@ void FoldersPanel::selectLeafDirectory() }*/ } +KFileItemModel* FoldersPanel::fileItemModel() const +{ + return static_cast(m_controller->model()); +} + #include "folderspanel.moc" diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h index 727fc7c71..70390da60 100644 --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -24,11 +24,8 @@ #include class KDirLister; -class DolphinModel; - -class DolphinSortFilterProxyModel; -class PanelTreeView; -class QModelIndex; +class KFileItemModel; +class KItemListController; /** * @brief Shows a tree view of the directories starting from @@ -77,28 +74,28 @@ private slots: * Updates the active view to the URL * which is given by the item with the index \a index. */ - void updateActiveView(const QModelIndex& index); + //void updateActiveView(const QModelIndex& index); /** * Is emitted if URLs have been dropped * to the index \a index. */ - void dropUrls(const QModelIndex& index, QDropEvent* event); + //void dropUrls(const QModelIndex& index, QDropEvent* event); /** * Expands the treeview to show the directory * specified by \a index. */ - void expandToDir(const QModelIndex& index); + //void expandToDir(const QModelIndex& index); /** * Assures that the leaf folder gets visible. */ - void scrollToLeaf(); + //void scrollToLeaf(); void updateMouseButtons(); - void slotDirListerCompleted(); + void slotLoadingCompleted(); void slotHorizontalScrollBarMoved(int value); @@ -119,13 +116,13 @@ private: */ void selectLeafDirectory(); + KFileItemModel* fileItemModel() const; + private: bool m_setLeafVisible; Qt::MouseButtons m_mouseButtons; KDirLister* m_dirLister; - //DolphinModel* m_dolphinModel; - //DolphinSortFilterProxyModel* m_proxyModel; - PanelTreeView* m_treeView; + KItemListController* m_controller; KUrl m_leafDir; }; diff --git a/src/panels/folders/ktreeview.cpp b/src/panels/folders/ktreeview.cpp deleted file mode 100644 index 765b934be..000000000 --- a/src/panels/folders/ktreeview.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by * - * Copyright (C) 2008 by * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "ktreeview.h" -#include "ktreeview_p.h" - -#include - -#include -#include -#include -#include - -KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) : - parent(parent), - autoHorizontalScroll(false), - timeLine(0) -{ - timeLine = new QTimeLine(500, this); - connect(timeLine, SIGNAL(frameChanged(int)), - this, SLOT(updateVerticalScrollBar(int))); - - connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), - this, SLOT(startScrolling())); - connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(startScrolling())); - connect(parent, SIGNAL(collapsed(QModelIndex)), - this, SLOT(startScrolling())); - connect(parent, SIGNAL(expanded(QModelIndex)), - this, SLOT(startScrolling())); -} - -void KTreeView::KTreeViewPrivate::startScrolling() -{ - if (!autoHorizontalScroll) { - return; - } - - // Determine the most left visual index - QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0)); - if (!visibleIndex.isValid()) { - return; - } - - QModelIndex index = visibleIndex; - int minimum = parent->width(); - do { - const QRect rect = parent->visualRect(visibleIndex); - if (rect.top() > parent->viewport()->height()) { - // the current index and all successors are not visible anymore - break; - } - if (rect.left() < minimum) { - minimum = rect.left(); - index = visibleIndex; - } - visibleIndex = parent->indexBelow(visibleIndex); - } while (visibleIndex.isValid()); - - // Start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible - Q_ASSERT(index.isValid()); - const QRect rect = parent->visualRect(index); - - QScrollBar* scrollBar = parent->horizontalScrollBar(); - const int oldScrollBarPos = scrollBar->value(); - - const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1; - const int availableWidth = parent->viewport()->width(); - int scrollBarPos = itemRight - availableWidth; - const int scrollBarPosMax = oldScrollBarPos + rect.left() - parent->indentation(); - if (scrollBarPos > scrollBarPosMax) { - scrollBarPos = scrollBarPosMax; - } - - if (scrollBarPos != oldScrollBarPos) { - timeLine->setFrameRange(oldScrollBarPos, scrollBarPos); - if (timeLine->state() == QTimeLine::Running) { - timeLine->stop(); - } - timeLine->start(); - } -} - -void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value) -{ - QScrollBar *scrollBar = parent->horizontalScrollBar(); - scrollBar->setValue(value); -} - -// ************************************************ - -KTreeView::KTreeView(QWidget *parent) : - QTreeView(parent), - d(new KTreeViewPrivate(this)) -{ - if (KGlobalSettings::graphicEffectsLevel() >= KGlobalSettings::SimpleAnimationEffects) { - setAutoHorizontalScroll(true); - } -} - -KTreeView::~KTreeView() -{ -} - -void KTreeView::setAutoHorizontalScroll(bool enable) -{ - d->autoHorizontalScroll = enable; - if (!enable) { - d->timeLine->stop(); - } -} - -bool KTreeView::autoHorizontalScroll() const -{ - return d->autoHorizontalScroll; -} - -void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint) -{ - const int value = horizontalScrollBar()->value(); - QTreeView::scrollTo(index, hint); - horizontalScrollBar()->setValue(value); -} - -void KTreeView::hideEvent(QHideEvent *event) -{ - d->timeLine->stop(); - QTreeView::hideEvent(event); -} - -#include "ktreeview.moc" -#include "ktreeview_p.moc" diff --git a/src/panels/folders/ktreeview.h b/src/panels/folders/ktreeview.h deleted file mode 100644 index 754ea6db3..000000000 --- a/src/panels/folders/ktreeview.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by * - * Copyright (C) 2008 by * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef KTREEVIEW_H -#define KTREEVIEW_H - -#include - -class KTreeView : public QTreeView -{ - Q_OBJECT - -public: - KTreeView(QWidget *parent = 0); - virtual ~KTreeView(); - - void setAutoHorizontalScroll(bool enable); - bool autoHorizontalScroll() const; - - virtual void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible); - -protected: - virtual void hideEvent(QHideEvent *event); - -private: - class KTreeViewPrivate; - KTreeViewPrivate *d; -}; - -#endif /* ifndef KTREEVIEW_H */ diff --git a/src/panels/folders/paneltreeview.cpp b/src/panels/folders/paneltreeview.cpp deleted file mode 100644 index 26a543d56..000000000 --- a/src/panels/folders/paneltreeview.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "paneltreeview.h" - -#include -#include -#include -#include -#include -#include - -PanelTreeView::PanelTreeView(QWidget* parent) : - KTreeView(parent) -{ - setAcceptDrops(true); - setUniformRowHeights(true); - setSelectionMode(QAbstractItemView::SingleSelection); - setEditTriggers(QAbstractItemView::NoEditTriggers); - setSortingEnabled(true); - setFrameStyle(QFrame::NoFrame); - setDragDropMode(QAbstractItemView::DragDrop); - setDropIndicatorShown(false); - - setVerticalScrollMode(QListView::ScrollPerPixel); - setHorizontalScrollMode(QListView::ScrollPerPixel); - - viewport()->setAttribute(Qt::WA_Hover); - - // make the background transparent and apply the window-text color - // to the text color, so that enough contrast is given for all color - // schemes - QPalette p = palette(); - p.setColor(QPalette::Active, QPalette::Text, p.color(QPalette::Active, QPalette::WindowText)); - p.setColor(QPalette::Inactive, QPalette::Text, p.color(QPalette::Inactive, QPalette::WindowText)); - p.setColor(QPalette::Disabled, QPalette::Text, p.color(QPalette::Disabled, QPalette::WindowText)); - setPalette(p); - viewport()->setAutoFillBackground(false); - - KFileItemDelegate* delegate = new KFileItemDelegate(this); - setItemDelegate(delegate); -} - -PanelTreeView::~PanelTreeView() -{ -} - -bool PanelTreeView::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::Polish: - // Hide all columns except of the 'Name' column - /*for (int i = DolphinModel::Name + 1; i < DolphinModel::ExtraColumnCount; ++i) { - hideColumn(i); - } - header()->hide();*/ - break; - - case QEvent::Show: - // TODO: The opening/closing animation of subtrees flickers in combination with the - // panel when using the Oxygen style. As workaround the animation is turned off: - setAnimated(false); - break; - - case QEvent::UpdateRequest: - // a wheel movement will scroll 1 item - if (model()->rowCount() > 0) { - verticalScrollBar()->setSingleStep(sizeHintForRow(0) / 3); - } - break; - - default: - break; - } - - return KTreeView::event(event); -} - -void PanelTreeView::startDrag(Qt::DropActions supportedActions) -{ - Q_UNUSED(supportedActions); - //DragAndDropHelper::instance().startDrag(this, supportedActions); -} - -void PanelTreeView::dragEnterEvent(QDragEnterEvent* event) -{ - KTreeView::dragEnterEvent(event); - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } -} - -void PanelTreeView::dragLeaveEvent(QDragLeaveEvent* event) -{ - KTreeView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void PanelTreeView::dragMoveEvent(QDragMoveEvent* event) -{ - KTreeView::dragMoveEvent(event); - - // TODO: remove this code when the issue #160611 is solved in Qt 4.4 - const QModelIndex index = indexAt(event->pos()); - setDirtyRegion(m_dropRect); - m_dropRect = visualRect(index); - setDirtyRegion(m_dropRect); - - if (event->mimeData()->hasUrls()) { - // accept url drops, independently from the destination item - event->acceptProposedAction(); - } -} - -void PanelTreeView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - if (index.isValid()) { - emit urlsDropped(index, event); - } - KTreeView::dropEvent(event); -} - -#include "paneltreeview.moc" diff --git a/src/panels/folders/paneltreeview.h b/src/panels/folders/paneltreeview.h deleted file mode 100644 index 73d17c236..000000000 --- a/src/panels/folders/paneltreeview.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef PANELTREEVIEW_H -#define PANELTREEVIEW_H - -#include -#include - -/** - * @brief Tree view widget which is used for the folders panel. - * - * @see FoldersPanel - */ -class PanelTreeView : public KTreeView -{ - Q_OBJECT - -public: - explicit PanelTreeView(QWidget* parent = 0); - virtual ~PanelTreeView(); - -signals: - /** - * Is emitted if the URL have been dropped to - * the index \a index. - */ - void urlsDropped(const QModelIndex& index, QDropEvent* event); - -protected: - virtual bool event(QEvent* event); - virtual void startDrag(Qt::DropActions supportedActions); - virtual void dragEnterEvent(QDragEnterEvent* event); - virtual void dragLeaveEvent(QDragLeaveEvent* event); - virtual void dragMoveEvent(QDragMoveEvent* event); - virtual void dropEvent(QDropEvent* event); - -private: - QRect m_dropRect; -}; - -#endif diff --git a/src/tests/kfileitemmodeltest.cpp b/src/tests/kfileitemmodeltest.cpp index c41fcb6df..f2d62fbad 100644 --- a/src/tests/kfileitemmodeltest.cpp +++ b/src/tests/kfileitemmodeltest.cpp @@ -451,7 +451,7 @@ void KFileItemModelTest::testExpandItems() QVERIFY(m_model->expandedUrls().empty()); m_dirLister->openUrl(m_testDir->url()); - m_model->restoreExpandedUrls(allFolders); + m_model->setExpanded(allFolders); QVERIFY(QTest::kWaitForSignal(m_model, SIGNAL(loadingCompleted()), DefaultTimeout)); QCOMPARE(m_model->count(), 5); // 5 items: "a/", "a/a/", "a/a/1", "a/a-1/", "a/a-1/1" QVERIFY(m_model->isExpanded(0)); diff --git a/src/views/dolphinitemlistcontainer.cpp b/src/views/dolphinitemlistcontainer.cpp index cd26ec876..0f2af9855 100644 --- a/src/views/dolphinitemlistcontainer.cpp +++ b/src/views/dolphinitemlistcontainer.cpp @@ -61,9 +61,9 @@ DolphinItemListContainer::~DolphinItemListContainer() CompactModeSettings::self()->writeConfig(); DetailsModeSettings::self()->writeConfig(); - KItemListView* view = controller()->view(); controller()->setView(0); - delete view; + delete m_fileItemListView; + m_fileItemListView = 0; } void DolphinItemListContainer::setPreviewsShown(bool show) diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 91d668e9d..578b93a2b 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -943,7 +943,7 @@ void DolphinView::restoreState(QDataStream& stream) // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) QSet urls; stream >> urls; - fileItemModel()->restoreExpandedUrls(urls); + fileItemModel()->setExpanded(urls); } void DolphinView::saveState(QDataStream& stream) diff --git a/src/views/folderexpander.cpp b/src/views/folderexpander.cpp deleted file mode 100644 index a9f5971c2..000000000 --- a/src/views/folderexpander.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Simon St James * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#include "folderexpander.h" - -#include -#include -#include -#include - -#include -#include - -#include - -#include - -FolderExpander::FolderExpander(QAbstractItemView *view, QSortFilterProxyModel *proxyModel) : - QObject(view), - m_enabled(true), - m_view(view), - m_proxyModel(proxyModel), - m_autoExpandTriggerTimer(0), - m_autoExpandPos() -{ - if (!m_view || !m_proxyModel) { - return; - } - KDirModel *m_dirModel = qobject_cast(m_proxyModel->sourceModel()); - if (!m_dirModel) { - return; - } - - // Initialise auto-expand timer. - m_autoExpandTriggerTimer = new QTimer(this); - m_autoExpandTriggerTimer->setSingleShot(true); - connect(m_autoExpandTriggerTimer, SIGNAL(timeout()), - this, SLOT(autoExpandTimeout())); - - // The view scrolling complicates matters, so we want to - // be informed if they occur. - connect(m_view->horizontalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(viewScrolled())); - connect(m_view->verticalScrollBar(), SIGNAL(valueChanged(int)), - this, SLOT(viewScrolled())); - - // "Dragging" events are sent to the QAbstractItemView's viewport. - m_view->viewport()->installEventFilter(this); -} - -void FolderExpander::setEnabled(bool enabled) -{ - m_enabled = enabled; -} - -bool FolderExpander::enabled() const -{ - return m_enabled; -} - -FolderExpander::~FolderExpander() -{ -} - -void FolderExpander::viewScrolled() -{ - if (m_autoExpandTriggerTimer->isActive()) { - m_autoExpandTriggerTimer->start(AUTO_EXPAND_DELAY); - } -} - -void FolderExpander::autoExpandTimeout() -{ - if (!m_enabled) { - return; - } - - // We want to find whether the file currently being hovered over is a - // directory. TODO - is there a simpler way, preferably without - // needing to pass in m_proxyModel that has a KDirModel as its sourceModel() ... ? - QModelIndex proxyIndexToExpand = m_view->indexAt(m_autoExpandPos); - QModelIndex indexToExpand = m_proxyModel->mapToSource(proxyIndexToExpand); - KDirModel* m_dirModel = qobject_cast< KDirModel* >(m_proxyModel->sourceModel()); - Q_ASSERT(m_dirModel); - KFileItem itemToExpand = m_dirModel->itemForIndex(indexToExpand); - - if (itemToExpand.isNull() || itemToExpand == m_dirModel->itemForIndex(QModelIndex())) { - // The second clause occurs when we are expanding the folder represented - // by the view, which is a case we should ignore (#182618). - return; - } - - if (itemToExpand.isDir()) { - QTreeView* treeView = qobject_cast(m_view); - if (treeView && treeView->itemsExpandable()) { - // Toggle expanded state of this directory. - treeView->setExpanded(proxyIndexToExpand, !treeView->isExpanded(proxyIndexToExpand)); - } - else { - emit enterDir(proxyIndexToExpand); - } - } -} - -bool FolderExpander::eventFilter(QObject* watched, QEvent* event) -{ - Q_UNUSED(watched); - // We're interested in reading Drag* events, but not filtering them, - // so always return false. - // We just store the position of the hover, here; actually working out - // what the hovered item is and whether it is expandable is done in - // autoExpandTimeout. - if (event->type() == QEvent::DragMove) { - QDragMoveEvent *dragMoveEvent = static_cast(event); - // (Re-)set the timer while we're still moving and dragging. - m_autoExpandTriggerTimer->start(AUTO_EXPAND_DELAY); - m_autoExpandPos = dragMoveEvent->pos(); - } else if (event->type() == QEvent::DragLeave || event->type() == QEvent::Drop) { - m_autoExpandTriggerTimer->stop(); - } - return false; -} diff --git a/src/views/folderexpander.h b/src/views/folderexpander.h deleted file mode 100644 index 63de57f4a..000000000 --- a/src/views/folderexpander.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Simon St James * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ - -#ifndef FOLDEREXPANDER_H -#define FOLDEREXPANDER_H - -// Needs to be exported as FoldersPanel uses it. -#include "libdolphin_export.h" - -#include -#include - -class QAbstractItemView; -class QTreeView; -class QTimer; -class QSortFilterProxyModel; -class QModelIndex; - -/** - * Grants auto expanding functionality to the provided item view. - * Qt has its own auto expand mechanism, but this works only - * for QTreeView. Auto expanding of folders is turned on - * per default. - * - * If the provided view is an instance of the class QTreeView, the - * expansion of the directory is automatically done on hover. Otherwise - * the enterDir() signal is emitted and the caller needs to ensure that - * the requested directory is entered. - * - * The FolderExpander becomes a child of the provided view. - */ -class LIBDOLPHINPRIVATE_EXPORT FolderExpander : public QObject -{ - Q_OBJECT - -public: - FolderExpander(QAbstractItemView* view, QSortFilterProxyModel* proxyModel); - virtual ~FolderExpander(); - - void setEnabled(bool enabled); - bool enabled() const; - -signals: - /** - * Is emitted if the directory \a dirModelIndex should be entered. The - * signal is not emitted when a QTreeView is used, as the entering of - * the directory is already provided by expanding the tree node. - */ - void enterDir(const QModelIndex& dirModelIndex); - - -private slots: - void viewScrolled(); - void autoExpandTimeout(); - -private: - bool m_enabled; - - QAbstractItemView* m_view; - QSortFilterProxyModel* m_proxyModel; - - QTimer* m_autoExpandTriggerTimer; - QPoint m_autoExpandPos; - - static const int AUTO_EXPAND_DELAY = 700; - - /** - * Watchs the drag/move events for the view to decide - * whether auto expanding of a folder should be triggered. - */ - bool eventFilter(QObject* watched, QEvent* event); -}; -#endif