diff options
| author | Peter Penz <[email protected]> | 2011-11-20 19:32:52 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-11-20 19:35:01 +0100 |
| commit | b27e599429731337af4bb18b986933c968bea279 (patch) | |
| tree | e807863400a9c3f6f48194a0f69f4c3d450ca092 /src/views | |
| parent | 693f254252da3932d1307f65bc2a1bcaaad566ac (diff) | |
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.
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinitemlistcontainer.cpp | 4 | ||||
| -rw-r--r-- | src/views/dolphinview.cpp | 2 | ||||
| -rw-r--r-- | src/views/folderexpander.cpp | 138 | ||||
| -rw-r--r-- | src/views/folderexpander.h | 89 |
4 files changed, 3 insertions, 230 deletions
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<KUrl> 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 <[email protected]> * - * * - * 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 <QTimer> -#include <QAbstractItemView> -#include <QTreeView> -#include <QScrollBar> - -#include <QEvent> -#include <QDragMoveEvent> - -#include <QSortFilterProxyModel> - -#include <KDirModel> - -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<KDirModel*>(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<QTreeView*>(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<QDragMoveEvent*>(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 <[email protected]> * - * * - * 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 <QObject> -#include <QPoint> - -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 |
