From f37ecd6ecfab9bc1d2929504b4f6e4363f8137b9 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 14 Jan 2009 20:14:36 +0000 Subject: Cleanup panel related class names: The terms "sidebar"/"sidebarpage" are relicts from the KDE 3 version of Dolphin and are called "Panels" in the KDE 4 version of Dolphin. Yes, renaming classes may take more than 1 year ;-) svn path=/trunk/KDE/kdebase/apps/; revision=911089 --- src/panels/folders/folderspanel.cpp | 279 +++++++++++++++++++++++++++++ src/panels/folders/folderspanel.h | 135 ++++++++++++++ src/panels/folders/paneltreeview.cpp | 147 +++++++++++++++ src/panels/folders/paneltreeview.h | 58 ++++++ src/panels/folders/sidebartreeview.cpp | 147 --------------- src/panels/folders/sidebartreeview.h | 58 ------ src/panels/folders/treeviewcontextmenu.cpp | 4 +- src/panels/folders/treeviewcontextmenu.h | 8 +- src/panels/folders/treeviewsidebarpage.cpp | 279 ----------------------------- src/panels/folders/treeviewsidebarpage.h | 135 -------------- 10 files changed, 625 insertions(+), 625 deletions(-) create mode 100644 src/panels/folders/folderspanel.cpp create mode 100644 src/panels/folders/folderspanel.h create mode 100644 src/panels/folders/paneltreeview.cpp create mode 100644 src/panels/folders/paneltreeview.h delete mode 100644 src/panels/folders/sidebartreeview.cpp delete mode 100644 src/panels/folders/sidebartreeview.h delete mode 100644 src/panels/folders/treeviewsidebarpage.cpp delete mode 100644 src/panels/folders/treeviewsidebarpage.h (limited to 'src/panels/folders') diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp new file mode 100644 index 000000000..72d9a0952 --- /dev/null +++ b/src/panels/folders/folderspanel.cpp @@ -0,0 +1,279 @@ +/*************************************************************************** + * 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 "folderspanel.h" + +#include "dolphinmodel.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphinview.h" +#include "settings/dolphinsettings.h" +#include "dolphin_folderspanelsettings.h" +#include "dolphin_generalsettings.h" +#include "draganddrophelper.h" +#include "folderexpander.h" +#include "renamedialog.h" +#include "paneltreeview.h" +#include "treeviewcontextmenu.h" + +#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_leafDir() +{ + setLayoutDirection(Qt::LeftToRight); +} + +FoldersPanel::~FoldersPanel() +{ + FoldersPanelSettings::self()->writeConfig(); + + delete m_proxyModel; + m_proxyModel = 0; + delete m_dolphinModel; + m_dolphinModel = 0; + m_dirLister = 0; // deleted by m_dolphinModel +} + +QSize FoldersPanel::sizeHint() const +{ + return QSize(200, 400); +} + +void FoldersPanel::setShowHiddenFiles(bool show) +{ + FoldersPanelSettings::setShowHiddenFiles(show); + if (m_dirLister != 0) { + m_dirLister->setShowingDotFiles(show); + m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); + } +} + +bool FoldersPanel::showHiddenFiles() const +{ + return FoldersPanelSettings::showHiddenFiles(); +} + +void FoldersPanel::rename(const KFileItem& item) +{ + if (DolphinSettings::instance().generalSettings()->renameInline()) { + const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + m_treeView->edit(proxyIndex); + } else { + KFileItemList items; + items.append(item); + RenameDialog dialog(this, items); + if (dialog.exec() == QDialog::Accepted) { + const QString& newName = dialog.newName(); + if (!newName.isEmpty()) { + KUrl newUrl = item.url(); + newUrl.setFileName(newName); + KonqOperations::rename(this, item.url(), newUrl); + } + } + } +} + +void FoldersPanel::setUrl(const KUrl& url) +{ + if (!url.isValid() || (url == Panel::url())) { + return; + } + + Panel::setUrl(url); + if (m_dirLister != 0) { + m_setLeafVisible = true; + loadTree(url); + } +} + +void FoldersPanel::showEvent(QShowEvent* event) +{ + if (event->spontaneous()) { + Panel::showEvent(event); + return; + } + + if (m_dirLister == 0) { + // Postpone the creating of the dir lister to the first show event. + // This assures that no performance and memory overhead is given when the TreeView is not + // used at all (see FoldersPanel::setUrl()). + m_dirLister = new KDirLister(); + m_dirLister->setDirOnlyMode(true); + m_dirLister->setAutoUpdate(true); + m_dirLister->setMainWindow(window()); + m_dirLister->setDelayedMimeTypes(true); + m_dirLister->setAutoErrorHandlingEnabled(false, this); + m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); + + Q_ASSERT(m_dolphinModel == 0); + m_dolphinModel = new DolphinModel(this); + m_dolphinModel->setDirLister(m_dirLister); + m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); + connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), + this, SLOT(expandToDir(const QModelIndex&))); + + Q_ASSERT(m_proxyModel == 0); + m_proxyModel = new DolphinSortFilterProxyModel(this); + m_proxyModel->setSourceModel(m_dolphinModel); + + Q_ASSERT(m_treeView == 0); + m_treeView = new PanelTreeView(this); + m_treeView->setModel(m_proxyModel); + m_proxyModel->setSorting(DolphinView::SortByName); + m_proxyModel->setSortOrder(Qt::AscendingOrder); + + new FolderExpander(m_treeView, m_proxyModel); + + connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), + this, SLOT(updateActiveView(const QModelIndex&))); + connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), + this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); + connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), + this, SLOT(updateMouseButtons())); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setMargin(0); + layout->addWidget(m_treeView); + } + + loadTree(url()); + Panel::showEvent(event); +} + +void FoldersPanel::contextMenuEvent(QContextMenuEvent* event) +{ + Panel::contextMenuEvent(event); + + KFileItem item; + const QModelIndex index = m_treeView->indexAt(event->pos()); + if (index.isValid()) { + const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); + item = m_dolphinModel->itemForIndex(dolphinModelIndex); + emit changeSelection(KFileItemList()); + } + + TreeViewContextMenu contextMenu(this, item); + contextMenu.open(); +} + +void FoldersPanel::updateActiveView(const QModelIndex& 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) +{ + if (index.isValid()) { + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + KFileItem item = m_dolphinModel->itemForIndex(dirIndex); + Q_ASSERT(!item.isNull()); + if (item.isDir()) { + DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); + } + } +} + +void FoldersPanel::expandToDir(const QModelIndex& index) +{ + m_treeView->setExpanded(index, true); + selectLeafDirectory(); + m_treeView->resizeColumnToContents(DolphinModel::Name); +} + +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::loadTree(const KUrl& url) +{ + Q_ASSERT(m_dirLister != 0); + m_leafDir = url; + + KUrl baseUrl; + if (url.isLocalFile()) { + // 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 + baseUrl = url; + baseUrl.setPath(QString('/')); + } + + if (m_dirLister->url() != baseUrl) { + m_dirLister->stop(); + m_dirLister->openUrl(baseUrl, KDirLister::Reload); + } + m_dolphinModel->expandToUrl(m_leafDir); +} + +void FoldersPanel::selectLeafDirectory() +{ + const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (!proxyIndex.isValid()) { + return; + } + + if (m_setLeafVisible) { + // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by + // scrollToLeaf(). This assures that the scrolling is done after + // the horizontal scrollbar gets visible (otherwise the scrollbar + // might hide the leaf). + QTimer::singleShot(100, this, SLOT(scrollToLeaf())); + m_setLeafVisible = false; + } + + QItemSelectionModel* selModel = m_treeView->selectionModel(); + selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); +} + +#include "folderspanel.moc" diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h new file mode 100644 index 000000000..90f506fd0 --- /dev/null +++ b/src/panels/folders/folderspanel.h @@ -0,0 +1,135 @@ +/*************************************************************************** + * 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 FOLDERSPANEL_H +#define FOLDERSPANEL_H + +#include +#include + +class KDirLister; +class DolphinModel; + +class DolphinSortFilterProxyModel; +class PanelTreeView; +class QModelIndex; + +/** + * @brief Shows a tree view of the directories starting from + * the currently selected place. + * + * The tree view is always synchronized with the currently active view + * from the main window. + */ +class FoldersPanel : public Panel +{ + Q_OBJECT + +public: + FoldersPanel(QWidget* parent = 0); + virtual ~FoldersPanel(); + + /** @see QWidget::sizeHint() */ + virtual QSize sizeHint() const; + + void setShowHiddenFiles(bool show); + bool showHiddenFiles() const; + + void rename(const KFileItem& item); + +signals: + /** + * Is emitted if the an URL change is requested. + */ + void changeUrl(const KUrl& url, Qt::MouseButtons buttons); + + /** + * This signal is emitted when the panel requests a change in the + * current selection. The file-management view recieving this signal is + * not required to select all listed files, limiting the selection to + * e.g. the current folder. The new selection will be reported via the + * setSelection slot. + */ + void changeSelection(const KFileItemList& selection); + +public slots: + /** + * Changes the current selection inside the tree to \a url. + */ + virtual void setUrl(const KUrl& url); + +protected: + /** @see QWidget::showEvent() */ + virtual void showEvent(QShowEvent* event); + + /** @see QWidget::contextMenuEvent() */ + virtual void contextMenuEvent(QContextMenuEvent* event); + +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); + + /** + * Is emitted if URLs have been dropped + * to the index \a index. + */ + void dropUrls(const QModelIndex& index, QDropEvent* event); + + /** + * Expands the treeview to show the directory + * specified by \a index. + */ + void expandToDir(const QModelIndex& index); + + /** + * Assures that the leaf folder gets visible. + */ + void scrollToLeaf(); + + void updateMouseButtons(); + +private: + /** + * Initializes the base URL of the tree and expands all + * directories until \a url. + * @param url URL of the leaf directory that should get expanded. + */ + void loadTree(const KUrl& url); + + /** + * Selects the current leaf directory m_leafDir and assures + * that the directory is visible if the leaf has been set by + * FoldersPanel::setUrl(). + */ + void selectLeafDirectory(); + +private: + bool m_setLeafVisible; + Qt::MouseButtons m_mouseButtons; + KDirLister* m_dirLister; + DolphinModel* m_dolphinModel; + DolphinSortFilterProxyModel* m_proxyModel; + PanelTreeView* m_treeView; + KUrl m_leafDir; +}; + +#endif // FOLDERSPANEL_H diff --git a/src/panels/folders/paneltreeview.cpp b/src/panels/folders/paneltreeview.cpp new file mode 100644 index 000000000..b285789f0 --- /dev/null +++ b/src/panels/folders/paneltreeview.cpp @@ -0,0 +1,147 @@ +/*************************************************************************** + * 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 "dolphincontroller.h" +#include "dolphinmodel.h" +#include "draganddrophelper.h" + +#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 + hideColumn(DolphinModel::Size); + hideColumn(DolphinModel::ModifiedTime); + hideColumn(DolphinModel::Permissions); + hideColumn(DolphinModel::Owner); + hideColumn(DolphinModel::Group); + hideColumn(DolphinModel::Type); + hideColumn(DolphinModel::Rating); + hideColumn(DolphinModel::Tags); + 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) +{ + 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 new file mode 100644 index 000000000..0f0996875 --- /dev/null +++ b/src/panels/folders/paneltreeview.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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/panels/folders/sidebartreeview.cpp b/src/panels/folders/sidebartreeview.cpp deleted file mode 100644 index a876ee6c3..000000000 --- a/src/panels/folders/sidebartreeview.cpp +++ /dev/null @@ -1,147 +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 "sidebartreeview.h" - -#include "dolphincontroller.h" -#include "dolphinmodel.h" -#include "draganddrophelper.h" - -#include -#include -#include -#include -#include - -SidebarTreeView::SidebarTreeView(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); -} - -SidebarTreeView::~SidebarTreeView() -{ -} - -bool SidebarTreeView::event(QEvent* event) -{ - switch (event->type()) { - case QEvent::Polish: - // hide all columns except of the 'Name' column - hideColumn(DolphinModel::Size); - hideColumn(DolphinModel::ModifiedTime); - hideColumn(DolphinModel::Permissions); - hideColumn(DolphinModel::Owner); - hideColumn(DolphinModel::Group); - hideColumn(DolphinModel::Type); - hideColumn(DolphinModel::Rating); - hideColumn(DolphinModel::Tags); - header()->hide(); - break; - - case QEvent::Show: - // TODO: The opening/closing animation of subtrees flickers in combination with the - // sidebar 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 SidebarTreeView::startDrag(Qt::DropActions supportedActions) -{ - DragAndDropHelper::instance().startDrag(this, supportedActions); -} - -void SidebarTreeView::dragEnterEvent(QDragEnterEvent* event) -{ - KTreeView::dragEnterEvent(event); - if (event->mimeData()->hasUrls()) { - event->acceptProposedAction(); - } -} - -void SidebarTreeView::dragLeaveEvent(QDragLeaveEvent* event) -{ - KTreeView::dragLeaveEvent(event); - setDirtyRegion(m_dropRect); -} - -void SidebarTreeView::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 SidebarTreeView::dropEvent(QDropEvent* event) -{ - const QModelIndex index = indexAt(event->pos()); - if (index.isValid()) { - emit urlsDropped(index, event); - } - KTreeView::dropEvent(event); -} - -#include "sidebartreeview.moc" diff --git a/src/panels/folders/sidebartreeview.h b/src/panels/folders/sidebartreeview.h deleted file mode 100644 index a5e8b63ce..000000000 --- a/src/panels/folders/sidebartreeview.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 SIDEBARTREEVIEW_H -#define SIDEBARTREEVIEW_H - -#include -#include - -/** - * @brief Tree view widget which is used for the sidebar panel. - * - * @see TreeViewSidebarPage - */ -class SidebarTreeView : public KTreeView -{ - Q_OBJECT - -public: - explicit SidebarTreeView(QWidget* parent = 0); - virtual ~SidebarTreeView(); - -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/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 9e8638002..c63772a38 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -32,12 +32,12 @@ #include #include -#include "treeviewsidebarpage.h" +#include "folderspanel.h" #include #include -TreeViewContextMenu::TreeViewContextMenu(TreeViewSidebarPage* parent, +TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : QObject(parent), m_parent(parent), diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h index 20a603573..8da23721b 100644 --- a/src/panels/folders/treeviewcontextmenu.h +++ b/src/panels/folders/treeviewcontextmenu.h @@ -23,7 +23,7 @@ #include #include -class TreeViewSidebarPage; +class FoldersPanel; /** * @brief Represents the context menu which appears when doing a right @@ -35,13 +35,13 @@ class TreeViewContextMenu : public QObject public: /** - * @parent Pointer to the treeview sidebar page the context menu + * @parent Pointer to the folders panel the context menu * belongs to. * @fileInfo Pointer to the file item the context menu * is applied. If 0 is passed, the context menu * is above the viewport. */ - TreeViewContextMenu(TreeViewSidebarPage* parent, + TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo); virtual ~TreeViewContextMenu(); @@ -81,7 +81,7 @@ private: void populateMimeData(QMimeData* mimeData, bool cut); private: - TreeViewSidebarPage* m_parent; + FoldersPanel* m_parent; KFileItem m_fileInfo; }; diff --git a/src/panels/folders/treeviewsidebarpage.cpp b/src/panels/folders/treeviewsidebarpage.cpp deleted file mode 100644 index 7801a97cc..000000000 --- a/src/panels/folders/treeviewsidebarpage.cpp +++ /dev/null @@ -1,279 +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 "treeviewsidebarpage.h" - -#include "dolphinmodel.h" -#include "dolphinsortfilterproxymodel.h" -#include "dolphinview.h" -#include "settings/dolphinsettings.h" -#include "dolphin_folderspanelsettings.h" -#include "dolphin_generalsettings.h" -#include "draganddrophelper.h" -#include "folderexpander.h" -#include "renamedialog.h" -#include "sidebartreeview.h" -#include "treeviewcontextmenu.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -TreeViewSidebarPage::TreeViewSidebarPage(QWidget* parent) : - SidebarPage(parent), - m_setLeafVisible(false), - m_mouseButtons(Qt::NoButton), - m_dirLister(0), - m_dolphinModel(0), - m_proxyModel(0), - m_treeView(0), - m_leafDir() -{ - setLayoutDirection(Qt::LeftToRight); -} - -TreeViewSidebarPage::~TreeViewSidebarPage() -{ - FoldersPanelSettings::self()->writeConfig(); - - delete m_proxyModel; - m_proxyModel = 0; - delete m_dolphinModel; - m_dolphinModel = 0; - m_dirLister = 0; // deleted by m_dolphinModel -} - -QSize TreeViewSidebarPage::sizeHint() const -{ - return QSize(200, 400); -} - -void TreeViewSidebarPage::setShowHiddenFiles(bool show) -{ - FoldersPanelSettings::setShowHiddenFiles(show); - if (m_dirLister != 0) { - m_dirLister->setShowingDotFiles(show); - m_dirLister->openUrl(m_dirLister->url(), KDirLister::Reload); - } -} - -bool TreeViewSidebarPage::showHiddenFiles() const -{ - return FoldersPanelSettings::showHiddenFiles(); -} - -void TreeViewSidebarPage::rename(const KFileItem& item) -{ - if (DolphinSettings::instance().generalSettings()->renameInline()) { - const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - m_treeView->edit(proxyIndex); - } else { - KFileItemList items; - items.append(item); - RenameDialog dialog(this, items); - if (dialog.exec() == QDialog::Accepted) { - const QString& newName = dialog.newName(); - if (!newName.isEmpty()) { - KUrl newUrl = item.url(); - newUrl.setFileName(newName); - KonqOperations::rename(this, item.url(), newUrl); - } - } - } -} - -void TreeViewSidebarPage::setUrl(const KUrl& url) -{ - if (!url.isValid() || (url == SidebarPage::url())) { - return; - } - - SidebarPage::setUrl(url); - if (m_dirLister != 0) { - m_setLeafVisible = true; - loadTree(url); - } -} - -void TreeViewSidebarPage::showEvent(QShowEvent* event) -{ - if (event->spontaneous()) { - SidebarPage::showEvent(event); - return; - } - - if (m_dirLister == 0) { - // Postpone the creating of the dir lister to the first show event. - // This assures that no performance and memory overhead is given when the TreeView is not - // used at all (see TreeViewSidebarPage::setUrl()). - m_dirLister = new KDirLister(); - m_dirLister->setDirOnlyMode(true); - m_dirLister->setAutoUpdate(true); - m_dirLister->setMainWindow(window()); - m_dirLister->setDelayedMimeTypes(true); - m_dirLister->setAutoErrorHandlingEnabled(false, this); - m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles()); - - Q_ASSERT(m_dolphinModel == 0); - m_dolphinModel = new DolphinModel(this); - m_dolphinModel->setDirLister(m_dirLister); - m_dolphinModel->setDropsAllowed(DolphinModel::DropOnDirectory); - connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(expandToDir(const QModelIndex&))); - - Q_ASSERT(m_proxyModel == 0); - m_proxyModel = new DolphinSortFilterProxyModel(this); - m_proxyModel->setSourceModel(m_dolphinModel); - - Q_ASSERT(m_treeView == 0); - m_treeView = new SidebarTreeView(this); - m_treeView->setModel(m_proxyModel); - m_proxyModel->setSorting(DolphinView::SortByName); - m_proxyModel->setSortOrder(Qt::AscendingOrder); - - new FolderExpander(m_treeView, m_proxyModel); - - connect(m_treeView, SIGNAL(clicked(const QModelIndex&)), - this, SLOT(updateActiveView(const QModelIndex&))); - connect(m_treeView, SIGNAL(urlsDropped(const QModelIndex&, QDropEvent*)), - this, SLOT(dropUrls(const QModelIndex&, QDropEvent*))); - connect(m_treeView, SIGNAL(pressed(const QModelIndex&)), - this, SLOT(updateMouseButtons())); - - QVBoxLayout* layout = new QVBoxLayout(this); - layout->setMargin(0); - layout->addWidget(m_treeView); - } - - loadTree(url()); - SidebarPage::showEvent(event); -} - -void TreeViewSidebarPage::contextMenuEvent(QContextMenuEvent* event) -{ - SidebarPage::contextMenuEvent(event); - - KFileItem item; - const QModelIndex index = m_treeView->indexAt(event->pos()); - if (index.isValid()) { - const QModelIndex dolphinModelIndex = m_proxyModel->mapToSource(index); - item = m_dolphinModel->itemForIndex(dolphinModelIndex); - emit changeSelection(KFileItemList()); - } - - TreeViewContextMenu contextMenu(this, item); - contextMenu.open(); -} - -void TreeViewSidebarPage::updateActiveView(const QModelIndex& 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 TreeViewSidebarPage::dropUrls(const QModelIndex& index, QDropEvent* event) -{ - if (index.isValid()) { - const QModelIndex dirIndex = m_proxyModel->mapToSource(index); - KFileItem item = m_dolphinModel->itemForIndex(dirIndex); - Q_ASSERT(!item.isNull()); - if (item.isDir()) { - DragAndDropHelper::instance().dropUrls(item, item.url(), event, this); - } - } -} - -void TreeViewSidebarPage::expandToDir(const QModelIndex& index) -{ - m_treeView->setExpanded(index, true); - selectLeafDirectory(); - m_treeView->resizeColumnToContents(DolphinModel::Name); -} - -void TreeViewSidebarPage::scrollToLeaf() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (proxyIndex.isValid()) { - m_treeView->scrollTo(proxyIndex); - } -} - -void TreeViewSidebarPage::updateMouseButtons() -{ - m_mouseButtons = QApplication::mouseButtons(); -} - -void TreeViewSidebarPage::loadTree(const KUrl& url) -{ - Q_ASSERT(m_dirLister != 0); - m_leafDir = url; - - KUrl baseUrl; - if (url.isLocalFile()) { - // 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 - baseUrl = url; - baseUrl.setPath(QString('/')); - } - - if (m_dirLister->url() != baseUrl) { - m_dirLister->stop(); - m_dirLister->openUrl(baseUrl, KDirLister::Reload); - } - m_dolphinModel->expandToUrl(m_leafDir); -} - -void TreeViewSidebarPage::selectLeafDirectory() -{ - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - if (!proxyIndex.isValid()) { - return; - } - - if (m_setLeafVisible) { - // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by - // scrollToLeaf(). This assures that the scrolling is done after - // the horizontal scrollbar gets visible (otherwise the scrollbar - // might hide the leaf). - QTimer::singleShot(100, this, SLOT(scrollToLeaf())); - m_setLeafVisible = false; - } - - QItemSelectionModel* selModel = m_treeView->selectionModel(); - selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); -} - -#include "treeviewsidebarpage.moc" diff --git a/src/panels/folders/treeviewsidebarpage.h b/src/panels/folders/treeviewsidebarpage.h deleted file mode 100644 index 39f2323ad..000000000 --- a/src/panels/folders/treeviewsidebarpage.h +++ /dev/null @@ -1,135 +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 TREEVIEWSIDEBARPAGE_H -#define TREEVIEWSIDEBARPAGE_H - -#include -#include - -class KDirLister; -class DolphinModel; - -class DolphinSortFilterProxyModel; -class SidebarTreeView; -class QModelIndex; - -/** - * @brief Shows a tree view of the directories starting from - * the currently selected place. - * - * The tree view is always synchronized with the currently active view - * from the main window. - */ -class TreeViewSidebarPage : public SidebarPage -{ - Q_OBJECT - -public: - TreeViewSidebarPage(QWidget* parent = 0); - virtual ~TreeViewSidebarPage(); - - /** @see QWidget::sizeHint() */ - virtual QSize sizeHint() const; - - void setShowHiddenFiles(bool show); - bool showHiddenFiles() const; - - void rename(const KFileItem& item); - -signals: - /** - * Is emitted if the an URL change is requested. - */ - void changeUrl(const KUrl& url, Qt::MouseButtons buttons); - - /** - * This signal is emitted when the sidebar requests a change in the - * current selection. The file-management view recieving this signal is - * not required to select all listed files, limiting the selection to - * e.g. the current folder. The new selection will be reported via the - * setSelection slot. - */ - void changeSelection(const KFileItemList& selection); - -public slots: - /** - * Changes the current selection inside the tree to \a url. - */ - virtual void setUrl(const KUrl& url); - -protected: - /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event); - - /** @see QWidget::contextMenuEvent() */ - virtual void contextMenuEvent(QContextMenuEvent* event); - -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); - - /** - * Is emitted if URLs have been dropped - * to the index \a index. - */ - void dropUrls(const QModelIndex& index, QDropEvent* event); - - /** - * Expands the treeview to show the directory - * specified by \a index. - */ - void expandToDir(const QModelIndex& index); - - /** - * Assures that the leaf folder gets visible. - */ - void scrollToLeaf(); - - void updateMouseButtons(); - -private: - /** - * Initializes the base URL of the tree and expands all - * directories until \a url. - * @param url URL of the leaf directory that should get expanded. - */ - void loadTree(const KUrl& url); - - /** - * Selects the current leaf directory m_leafDir and assures - * that the directory is visible if the leaf has been set by - * TreeViewSidebarPage::setUrl(). - */ - void selectLeafDirectory(); - -private: - bool m_setLeafVisible; - Qt::MouseButtons m_mouseButtons; - KDirLister* m_dirLister; - DolphinModel* m_dolphinModel; - DolphinSortFilterProxyModel* m_proxyModel; - SidebarTreeView* m_treeView; - KUrl m_leafDir; -}; - -#endif // TREEVIEWSIDEBARPAGE_H -- cgit v1.3