diff options
Diffstat (limited to 'src/panels')
| -rw-r--r-- | src/panels/folders/folderspanel.cpp | 132 | ||||
| -rw-r--r-- | src/panels/folders/folderspanel.h | 48 | ||||
| -rw-r--r-- | src/panels/folders/ktreeview_p.h | 46 | ||||
| -rw-r--r-- | src/panels/folders/treeviewcontextmenu.cpp | 52 | ||||
| -rw-r--r-- | src/panels/folders/treeviewcontextmenu.h | 16 |
5 files changed, 140 insertions, 154 deletions
diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index cf458e508..484d8c2ed 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -37,6 +37,7 @@ #include <QApplication> #include <QBoxLayout> #include <QGraphicsView> +#include <QPropertyAnimation> #include <QTimer> #include <views/renamedialog.h> @@ -45,11 +46,9 @@ FoldersPanel::FoldersPanel(QWidget* parent) : Panel(parent), - m_setLeafVisible(false), - m_mouseButtons(Qt::NoButton), + m_updateCurrentItem(false), m_dirLister(0), - m_controller(0), - m_leafDir() + m_controller(0) { setLayoutDirection(Qt::LeftToRight); } @@ -121,7 +120,6 @@ bool FoldersPanel::urlChanged() } if (m_dirLister) { - m_setLeafVisible = true; loadTree(url()); } @@ -158,6 +156,10 @@ void FoldersPanel::showEvent(QShowEvent* event) const qreal itemHeight = qMax(int(KIconLoader::SizeSmall), styleOption.fontMetrics.height()); view->setItemSize(QSizeF(-1, itemHeight + 2 * styleOption.margin)); view->setItemLayout(KFileItemListView::DetailsLayout); + // Set the opacity to 0 initially. The opacity will be increased after the loading of the initial tree + // has been finished in slotLoadingCompleted(). This prevents an unnecessary animation-mess when + // opening the folders panel. + view->setOpacity(0); KFileItemModel* model = new KFileItemModel(m_dirLister, this); // Use a QueuedConnection to give the view the possibility to react first on the @@ -168,6 +170,12 @@ void FoldersPanel::showEvent(QShowEvent* event) m_controller = container->controller(); m_controller->setView(view); m_controller->setModel(model); + m_controller->setSelectionBehavior(KItemListController::SingleSelection); + + connect(m_controller, SIGNAL(itemActivated(int)), this, SLOT(slotItemActivated(int))); + connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int))); + connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF))); + connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF))); // TODO: Check whether it makes sense to make an explicit API for KItemListContainer // to make the background transparent. @@ -194,22 +202,6 @@ void FoldersPanel::showEvent(QShowEvent* event) 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); - }*/ - - QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, item); - contextMenu->open(); - delete contextMenu; -} - void FoldersPanel::keyPressEvent(QKeyEvent* event) { const int key = event->key(); @@ -221,17 +213,65 @@ void FoldersPanel::keyPressEvent(QKeyEvent* event) } } -void FoldersPanel::updateMouseButtons() +void FoldersPanel::slotItemActivated(int index) +{ + const KFileItem item = fileItemModel()->fileItem(index); + if (!item.isNull()) { + emit changeUrl(item.url(), Qt::LeftButton); + } +} + +void FoldersPanel::slotItemMiddleClicked(int index) { - m_mouseButtons = QApplication::mouseButtons(); + const KFileItem item = fileItemModel()->fileItem(index); + if (!item.isNull()) { + emit changeUrl(item.url(), Qt::MiddleButton); + } +} + +void FoldersPanel::slotItemContextMenuRequested(int index, const QPointF& pos) +{ + Q_UNUSED(pos); + + const KFileItem fileItem = fileItemModel()->fileItem(index); + + QWeakPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, fileItem); + contextMenu.data()->open(); + if (contextMenu.data()) { + delete contextMenu.data(); + } +} + +void FoldersPanel::slotViewContextMenuRequested(const QPointF& pos) +{ + Q_UNUSED(pos); + + QWeakPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, KFileItem()); + contextMenu.data()->open(); + if (contextMenu.data()) { + delete contextMenu.data(); + } } void FoldersPanel::slotLoadingCompleted() { - const int index = fileItemModel()->index(url()); - if (index >= 0) { - m_controller->selectionManager()->setCurrentItem(index); + if (m_controller->view()->opacity() == 0) { + // The loading of the initial tree after opening the Folders panel + // has been finished. Trigger the increasing of the opacity after + // a short delay to give the view the chance to finish its internal + // animations. + // TODO: Check whether it makes sense to allow accessing the + // view-internal delay for usecases like this. + QTimer::singleShot(250, this, SLOT(startFadeInAnimation())); + } + + if (!m_updateCurrentItem) { + return; } + + const int index = fileItemModel()->index(url()); + updateCurrentItem(index); + m_updateCurrentItem = false; } void FoldersPanel::slotHorizontalScrollBarMoved(int value) @@ -250,10 +290,21 @@ void FoldersPanel::slotVerticalScrollBarMoved(int value) //m_treeView->setAutoHorizontalScroll(FoldersPanelSettings::autoScrolling()); } +void FoldersPanel::startFadeInAnimation() +{ + QPropertyAnimation* anim = new QPropertyAnimation(m_controller->view(), "opacity", this); + anim->setStartValue(0); + anim->setEndValue(1); + anim->setEasingCurve(QEasingCurve::InOutQuad); + anim->start(QAbstractAnimation::DeleteWhenStopped); + anim->setDuration(200); +} + void FoldersPanel::loadTree(const KUrl& url) { Q_ASSERT(m_dirLister); - m_leafDir = url; + + m_updateCurrentItem = false; KUrl baseUrl; if (url.isLocalFile()) { @@ -266,6 +317,7 @@ void FoldersPanel::loadTree(const KUrl& url) } if (m_dirLister->url() != baseUrl) { + m_updateCurrentItem = true; m_dirLister->stop(); m_dirLister->openUrl(baseUrl, KDirLister::Reload); } @@ -273,29 +325,23 @@ void FoldersPanel::loadTree(const KUrl& url) KFileItemModel* model = fileItemModel(); const int index = model->index(url); if (index >= 0) { - m_controller->selectionManager()->setCurrentItem(index); + updateCurrentItem(index); } else { + m_updateCurrentItem = true; model->setExpanded(QSet<KUrl>() << url); + // slotLoadingCompleted() will be invoked after the model has + // expanded the url } } -void FoldersPanel::selectLeafDirectory() +void FoldersPanel::updateCurrentItem(int index) { - /*const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + KItemListSelectionManager* selectionManager = m_controller->selectionManager(); + selectionManager->setCurrentItem(index); + selectionManager->clearSelection(); + selectionManager->setSelected(index); - if (proxyIndex.isValid()) { - QItemSelectionModel* selModel = m_treeView->selectionModel(); - selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect); - - if (m_setLeafVisible) { - // Invoke scrollToLeaf() asynchronously. This assures that - // the horizontal scrollbar is shown after resizing the column - // (otherwise the scrollbar might hide the leaf). - QTimer::singleShot(0, this, SLOT(scrollToLeaf())); - m_setLeafVisible = false; - } - }*/ + m_controller->view()->scrollToItem(index); } KFileItemModel* FoldersPanel::fileItemModel() const diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h index 70390da60..d249f850f 100644 --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -63,37 +63,14 @@ protected: /** @see QWidget::showEvent() */ virtual void showEvent(QShowEvent* event); - /** @see QWidget::contextMenuEvent() */ - virtual void contextMenuEvent(QContextMenuEvent* event); - /** @see QWidget::keyPressEvent() */ virtual void keyPressEvent(QKeyEvent* 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(); + void slotItemActivated(int index); + void slotItemMiddleClicked(int index); + void slotItemContextMenuRequested(int index, const QPointF& pos); + void slotViewContextMenuRequested(const QPointF& pos); void slotLoadingCompleted(); @@ -101,6 +78,12 @@ private slots: void slotVerticalScrollBarMoved(int value); + /** + * Increases the opacity of the view step by step until it is fully + * opaque. + */ + void startFadeInAnimation(); + private: /** * Initializes the base URL of the tree and expands all @@ -110,20 +93,17 @@ private: 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(). + * Sets the item with the index \a index as current item, selects + * the item and assures that the item will be visible. */ - void selectLeafDirectory(); + void updateCurrentItem(int index); KFileItemModel* fileItemModel() const; private: - bool m_setLeafVisible; - Qt::MouseButtons m_mouseButtons; + bool m_updateCurrentItem; KDirLister* m_dirLister; KItemListController* m_controller; - KUrl m_leafDir; }; #endif // FOLDERSPANEL_H diff --git a/src/panels/folders/ktreeview_p.h b/src/panels/folders/ktreeview_p.h deleted file mode 100644 index 9ea4ac7ee..000000000 --- a/src/panels/folders/ktreeview_p.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by <haraldhv (at) stud.ntnu.no> * - * Copyright (C) 2008 by <[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 KTREEVIEW_P_H -#define KTREEVIEW_P_H - -#include <QObject> - -#include "ktreeview.h" - -class QTimeLine; - -class KTreeView::KTreeViewPrivate : public QObject -{ - Q_OBJECT - -public Q_SLOTS: - void startScrolling(); - void updateVerticalScrollBar(int value); - -public: - KTreeViewPrivate(KTreeView *parent); - KTreeView *parent; - - bool autoHorizontalScroll; - QTimeLine *timeLine; -}; - -#endif /* ifndef KTREEVIEW_P_H */ diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 5db3e2c2a..daf14ab4a 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -39,7 +39,7 @@ TreeViewContextMenu::TreeViewContextMenu(FoldersPanel* parent, const KFileItem& fileInfo) : QObject(parent), m_parent(parent), - m_fileInfo(fileInfo) + m_fileItem(fileInfo) { } @@ -51,8 +51,8 @@ void TreeViewContextMenu::open() { KMenu* popup = new KMenu(m_parent); - if (!m_fileInfo.isNull()) { - KFileItemListProperties capabilities(KFileItemList() << m_fileInfo); + if (!m_fileItem.isNull()) { + KFileItemListProperties capabilities(KFileItemList() << m_fileItem); // insert 'Cut', 'Copy' and 'Paste' QAction* cutAction = new QAction(KIcon("edit-cut"), i18nc("@action:inmenu", "Cut"), this); @@ -85,7 +85,7 @@ void TreeViewContextMenu::open() KConfigGroup configGroup(globalConfig, "KDE"); bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false); - const KUrl url = m_fileInfo.url(); + const KUrl url = m_fileItem.url(); if (url.isLocalFile()) { QAction* moveToTrashAction = new QAction(KIcon("user-trash"), i18nc("@action:inmenu", "Move to Trash"), this); @@ -115,34 +115,40 @@ void TreeViewContextMenu::open() popup->addSeparator(); } - QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this); - showHiddenFilesAction->setCheckable(true); - showHiddenFilesAction->setChecked(m_parent->hiddenFilesShown()); - popup->addAction(showHiddenFilesAction); - connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool))); + if (m_fileItem.isNull()) { + QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this); + showHiddenFilesAction->setCheckable(true); + showHiddenFilesAction->setChecked(m_parent->hiddenFilesShown()); + popup->addAction(showHiddenFilesAction); + connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool))); - QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this); - autoScrollingAction->setCheckable(true); - autoScrollingAction->setChecked(m_parent->autoScrolling()); - popup->addAction(autoScrollingAction); - connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool))); + QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this); + autoScrollingAction->setCheckable(true); + autoScrollingAction->setChecked(m_parent->autoScrolling()); + // TODO: Temporary disabled. Horizontal autoscrolling will be implemented later either + // in KItemViews or manually as part of the FoldersPanel + //popup->addAction(autoScrollingAction); + connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool))); + } - popup->addSeparator(); foreach (QAction* action, m_parent->customContextMenuActions()) { popup->addAction(action); } + QWeakPointer<KMenu> popupPtr = popup; popup->exec(QCursor::pos()); - popup->deleteLater(); + if (popupPtr.data()) { + popupPtr.data()->deleteLater(); + } } void TreeViewContextMenu::populateMimeData(QMimeData* mimeData, bool cut) { KUrl::List kdeUrls; - kdeUrls.append(m_fileInfo.url()); + kdeUrls.append(m_fileItem.url()); KUrl::List mostLocalUrls; bool dummy; - mostLocalUrls.append(m_fileInfo.mostLocalUrl(dummy)); + mostLocalUrls.append(m_fileItem.mostLocalUrl(dummy)); KonqMimeData::populateMimeData(mimeData, kdeUrls, mostLocalUrls, cut); } @@ -166,7 +172,7 @@ void TreeViewContextMenu::paste() const QMimeData* mimeData = clipboard->mimeData(); const KUrl::List source = KUrl::List::fromMimeData(mimeData); - const KUrl& dest = m_fileInfo.url(); + const KUrl& dest = m_fileItem.url(); if (KonqMimeData::decodeIsCutSelection(mimeData)) { KonqOperations::copy(m_parent, KonqOperations::MOVE, source, dest); clipboard->clear(); @@ -177,22 +183,22 @@ void TreeViewContextMenu::paste() void TreeViewContextMenu::rename() { - m_parent->rename(m_fileInfo); + m_parent->rename(m_fileItem); } void TreeViewContextMenu::moveToTrash() { - KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileInfo.url()); + KonqOperations::del(m_parent, KonqOperations::TRASH, m_fileItem.url()); } void TreeViewContextMenu::deleteItem() { - KonqOperations::del(m_parent, KonqOperations::DEL, m_fileInfo.url()); + KonqOperations::del(m_parent, KonqOperations::DEL, m_fileItem.url()); } void TreeViewContextMenu::showProperties() { - KPropertiesDialog* dialog = new KPropertiesDialog(m_fileInfo.url(), m_parent); + KPropertiesDialog* dialog = new KPropertiesDialog(m_fileItem.url(), m_parent); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->show(); } diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h index e33bb70c5..0b3fd79bd 100644 --- a/src/panels/folders/treeviewcontextmenu.h +++ b/src/panels/folders/treeviewcontextmenu.h @@ -50,25 +50,25 @@ public: void open(); private slots: - /** Cuts the item m_fileInfo. */ + /** Cuts the item m_fileItem. */ void cut(); - /** Copies the item m_fileInfo. */ + /** Copies the item m_fileItem. */ void copy(); - /** Paste the clipboard to m_fileInfo. */ + /** Paste the clipboard to m_fileItem. */ void paste(); - /** Renames the item m_fileInfo. */ + /** Renames the item m_fileItem. */ void rename(); - /** Moves the item m_fileInfo to the trash. */ + /** Moves the item m_fileItem to the trash. */ void moveToTrash(); - /** Deletes the item m_fileInfo. */ + /** Deletes the item m_fileItem. */ void deleteItem(); - /** Shows the properties of the item m_fileInfo. */ + /** Shows the properties of the item m_fileItem. */ void showProperties(); /** @@ -88,7 +88,7 @@ private: private: FoldersPanel* m_parent; - KFileItem m_fileInfo; + KFileItem m_fileItem; }; #endif |
