diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 275c64323c..6487faace3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,6 +49,7 @@ set(dolphinprivate_LIB_SRCS tooltips/kformattedballoontipdelegate.cpp tooltips/tooltipmanager.cpp versioncontrolobserver.cpp + viewextensionsfactory.cpp viewproperties.cpp zoomlevelinfo.cpp ) diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 5d52a62c49..9256635680 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -33,12 +33,12 @@ #include "selectionmanager.h" #include "tooltips/tooltipmanager.h" #include "versioncontrolobserver.h" +#include "viewextensionsfactory.h" #include "zoomlevelinfo.h" #include #include #include -#include #include #include #include @@ -58,6 +58,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, m_container(container), m_selectionManager(0), m_autoScroller(0), + m_extensionsFactory(0), m_url(url), m_childUrl(), m_font(), @@ -65,8 +66,6 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, m_dirLister(0), m_dolphinModel(0), m_proxyModel(0), - m_previewGenerator(0), - m_toolTipManager(0), m_dropRect() { setMouseTracking(true); @@ -149,13 +148,6 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, m_selectionManager, SLOT(reset())); } - //m_previewGenerator = new KFilePreviewGenerator(this); - //m_previewGenerator->setPreviewShown(m_container->m_controller->dolphinView()->showPreview()); - - //if (DolphinSettings::instance().generalSettings()->showToolTips()) { - // m_toolTipManager = new ToolTipManager(this, m_proxyModel); - //} - //m_dirLister->openUrl(url, KDirLister::NoFlags); connect(KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()), @@ -180,6 +172,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, this, SLOT(setNameFilter(const QString&))); updateDecorationSize(dolphinView->showPreview()); + + m_extensionsFactory = new ViewExtensionsFactory(this, controller); } DolphinColumnView::~DolphinColumnView() @@ -391,10 +385,6 @@ void DolphinColumnView::keyPressEvent(QKeyEvent* event) default: break; } - - if (m_toolTipManager != 0) { - m_toolTipManager->hideTip(); - } } void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event) @@ -413,10 +403,6 @@ void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event) clearSelection(); } - if (m_toolTipManager != 0) { - m_toolTipManager->hideTip(); - } - const QPoint pos = m_container->viewport()->mapFromGlobal(event->globalPos()); Q_ASSERT(m_container->m_controller->itemView() == this); m_container->m_controller->triggerContextMenuRequest(pos); diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 0a601b7fae..97f498c97f 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -34,11 +34,10 @@ class DolphinModel; class DolphinSortFilterProxyModel; class DolphinDirLister; class DolphinViewAutoScroller; -class KFilePreviewGenerator; class KFileItem; class KFileItemList; class SelectionManager; -class ToolTipManager; +class ViewExtensionsFactory; /** * Represents one column inside the DolphinColumnViewContainer. @@ -127,6 +126,7 @@ private: DolphinColumnViewContainer* m_container; SelectionManager* m_selectionManager; DolphinViewAutoScroller* m_autoScroller; + ViewExtensionsFactory* m_extensionsFactory; KUrl m_url; // URL of the directory that is shown KUrl m_childUrl; // URL of the next column that is shown @@ -137,10 +137,6 @@ private: DolphinModel* m_dolphinModel; DolphinSortFilterProxyModel* m_proxyModel; - KFilePreviewGenerator* m_previewGenerator; - - ToolTipManager* m_toolTipManager; - QRect m_dropRect; friend class DolphinColumnViewContainer; diff --git a/src/dolphincolumnviewcontainer.cpp b/src/dolphincolumnviewcontainer.cpp index 80c4ff7a0c..ca9cfe0f10 100644 --- a/src/dolphincolumnviewcontainer.cpp +++ b/src/dolphincolumnviewcontainer.cpp @@ -26,13 +26,12 @@ #include "dolphin_columnmodesettings.h" -#include - #include #include #include -DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent, DolphinController* controller) : +DolphinColumnViewContainer::DolphinColumnViewContainer(QWidget* parent, + DolphinController* controller) : QScrollArea(parent), m_controller(controller), m_active(false), @@ -358,8 +357,6 @@ void DolphinColumnViewContainer::deleteColumn(DolphinColumnView* column) } // deleteWhenNotDragSource(column) does not necessarily delete column, // and we want its preview generator destroyed immediately. - column->m_previewGenerator->deleteLater(); - column->m_previewGenerator = 0; column->hide(); // Prevent automatic destruction of column when this DolphinColumnViewContainer // is destroyed. diff --git a/src/dolphincolumnviewcontainer.h b/src/dolphincolumnviewcontainer.h index 93a0c30fe3..0d8c87b160 100644 --- a/src/dolphincolumnviewcontainer.h +++ b/src/dolphincolumnviewcontainer.h @@ -44,7 +44,8 @@ class DolphinColumnViewContainer : public QScrollArea Q_OBJECT public: - explicit DolphinColumnViewContainer(QWidget* parent, DolphinController* controller); + explicit DolphinColumnViewContainer(QWidget* parent, + DolphinController* controller); virtual ~DolphinColumnViewContainer(); KUrl rootUrl() const; diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index 47c661e83e..b3801bda8d 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -46,6 +46,7 @@ void DolphinController::setUrl(const KUrl& url) { if (m_url != url) { m_url = url; + emit cancelPreviews(); emit urlChanged(url); } } diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index c87aaa43a1..ccfef53064 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -67,8 +67,6 @@ class QPoint; * * The communication of the abstract view to the view implementations is done by: * - setUrl() - * - setShowHiddenFiles() - * - setShowPreview() * - indicateActivationChange() * - setNameFilter() * - setZoomLevel() @@ -397,6 +395,11 @@ signals: */ void hideToolTip(); + /** + * Is emitted if pending previews should be canceled (e. g. because of an URL change). + */ + void cancelPreviews(); + private slots: void updateMouseButtonState(); diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index 92ffd5e1f4..2769064e44 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -28,6 +28,7 @@ #include "dolphinviewautoscroller.h" #include "draganddrophelper.h" #include "selectionmanager.h" +#include "viewextensionsfactory.h" #include "viewproperties.h" #include "zoomlevelinfo.h" @@ -45,7 +46,9 @@ #include #include -DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* controller) : +DolphinDetailsView::DolphinDetailsView(QWidget* parent, + DolphinController* controller, + DolphinSortFilterProxyModel* proxyModel) : QTreeView(parent), m_autoResize(true), m_expandingTogglePressed(false), @@ -55,6 +58,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr m_controller(controller), m_selectionManager(0), m_autoScroller(0), + m_extensionsFactory(0), m_expandableFoldersAction(0), m_font(), m_decorationSize(), @@ -75,6 +79,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr setRootIsDecorated(settings->expandableFolders()); setItemsExpandable(settings->expandableFolders()); setEditTriggers(QAbstractItemView::NoEditTriggers); + setModel(proxyModel); setMouseTracking(true); m_autoScroller = new DolphinViewAutoScroller(this); @@ -160,6 +165,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr m_expandableFoldersAction->setCheckable(true); connect(m_expandableFoldersAction, SIGNAL(toggled(bool)), this, SLOT(setFoldersExpandable(bool))); + + m_extensionsFactory = new ViewExtensionsFactory(this, controller); } DolphinDetailsView::~DolphinDetailsView() diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 483d57dd8e..93c27ac502 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -27,7 +27,9 @@ class DolphinController; class SelectionManager; +class DolphinSortFilterProxyModel; class DolphinViewAutoScroller; +class ViewExtensionsFactory; /** * @brief Represents the details view which shows the name, size, @@ -42,7 +44,9 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinDetailsView : public QTreeView Q_OBJECT public: - explicit DolphinDetailsView(QWidget* parent, DolphinController* controller); + explicit DolphinDetailsView(QWidget* parent, + DolphinController* controller, + DolphinSortFilterProxyModel* model); virtual ~DolphinDetailsView(); protected: @@ -202,6 +206,7 @@ private: DolphinController* m_controller; SelectionManager* m_selectionManager; DolphinViewAutoScroller* m_autoScroller; + ViewExtensionsFactory* m_extensionsFactory; QAction* m_expandableFoldersAction; QFont m_font; diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index 81b5c18d96..b07ce5a046 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -28,6 +28,7 @@ #include "dolphin_generalsettings.h" #include "draganddrophelper.h" #include "selectionmanager.h" +#include "viewextensionsfactory.h" #include "zoomlevelinfo.h" #include @@ -39,12 +40,15 @@ #include #include -DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controller) : +DolphinIconsView::DolphinIconsView(QWidget* parent, + DolphinController* controller, + DolphinSortFilterProxyModel* proxyModel) : KCategorizedView(parent), m_controller(controller), m_selectionManager(0), m_autoScroller(0), m_categoryDrawer(0), + m_extensionsFactory(0), m_font(), m_decorationSize(), m_decorationPosition(QStyleOptionViewItem::Top), @@ -53,6 +57,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle m_dropRect() { Q_ASSERT(controller != 0); + setModel(proxyModel); setLayoutDirection(Qt::LeftToRight); setViewMode(QListView::IconMode); setResizeMode(QListView::Adjust); @@ -130,6 +135,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle connect(KGlobalSettings::self(), SIGNAL(settingsChanged(int)), this, SLOT(slotGlobalSettingsChanged(int))); + + m_extensionsFactory = new ViewExtensionsFactory(this, controller); } DolphinIconsView::~DolphinIconsView() diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index f4eb5e2609..7a6dda3d44 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -34,7 +34,9 @@ class DolphinController; class SelectionManager; class DolphinCategoryDrawer; +class DolphinSortFilterProxyModel; class DolphinViewAutoScroller; +class ViewExtensionsFactory; /** * @brief Represents the view, where each item is shown as an icon. @@ -47,7 +49,9 @@ class LIBDOLPHINPRIVATE_EXPORT DolphinIconsView : public KCategorizedView Q_OBJECT public: - explicit DolphinIconsView(QWidget* parent, DolphinController* controller); + explicit DolphinIconsView(QWidget* parent, + DolphinController* controller, + DolphinSortFilterProxyModel* proxyModel); virtual ~DolphinIconsView(); protected slots: @@ -96,6 +100,7 @@ private: SelectionManager* m_selectionManager; DolphinViewAutoScroller* m_autoScroller; DolphinCategoryDrawer* m_categoryDrawer; + ViewExtensionsFactory* m_extensionsFactory; QFont m_font; QSize m_decorationSize; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 2e41b4aa48..42305be1f6 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -62,7 +61,6 @@ #include "draganddrophelper.h" #include "folderexpander.h" #include "renamedialog.h" -#include "tooltips/tooltipmanager.h" #include "settings/dolphinsettings.h" #include "versioncontrolobserver.h" #include "viewproperties.h" @@ -96,8 +94,6 @@ DolphinView::DolphinView(QWidget* parent, m_viewAccessor(proxyModel), m_selectionModel(0), m_selectionChangedTimer(0), - m_previewGenerator(0), - m_toolTipManager(0), m_versionControlObserver(0), m_rootUrl(), m_activeItemUrl(), @@ -388,7 +384,6 @@ void DolphinView::setZoomLevel(int level) if (level != zoomLevel()) { m_controller->setZoomLevel(level); - m_previewGenerator->updateIcons(); emit zoomLevelChanged(level); } } @@ -483,7 +478,6 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl) return; } - m_previewGenerator->cancelPreviews(); m_controller->setUrl(url); // emits urlChanged, which we forward if (m_viewAccessor.prepareUrlChange(url)) { initializeView(); @@ -754,8 +748,6 @@ void DolphinView::setShowPreview(bool show) props.setShowPreview(show); m_showPreview = show; - m_previewGenerator->setPreviewShown(show); - const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); @@ -886,10 +878,6 @@ bool DolphinView::eventFilter(QObject* watched, QEvent* event) case QEvent::KeyPress: if (watched == m_viewAccessor.itemView()) { - if (m_toolTipManager != 0) { - m_toolTipManager->hideTip(); - } - // clear the selection when Escape has been pressed QKeyEvent* keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Escape) { @@ -924,9 +912,6 @@ void DolphinView::triggerItem(const KFileItem& item) return; } - if (m_toolTipManager != 0) { - m_toolTipManager->hideTip(); - } emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart } @@ -953,10 +938,6 @@ void DolphinView::openContextMenu(const QPoint& pos, item = m_viewAccessor.dirModel()->itemForIndex(dolphinModelIndex); } - if (m_toolTipManager != 0) { - m_toolTipManager->hideTip(); - } - m_isContextMenuOpen = true; // TODO: workaround for Qt-issue 207192 emit requestContextMenu(item, url(), customActions); m_isContextMenuOpen = false; @@ -1300,8 +1281,6 @@ void DolphinView::applyViewProperties() const bool showPreview = props.showPreview(); if (showPreview != m_showPreview) { m_showPreview = showPreview; - m_previewGenerator->setPreviewShown(showPreview); - const int oldZoomLevel = m_controller->zoomLevel(); emit showPreviewChanged(); @@ -1342,11 +1321,6 @@ void DolphinView::deleteView() m_topLayout->removeWidget(view); view->close(); - // m_previewGenerator's parent is not always destroyed, and we - // don't want two active at once - manually delete. - delete m_previewGenerator; - m_previewGenerator = 0; - disconnect(view); m_controller->disconnect(view); view->disconnect(); @@ -1357,7 +1331,6 @@ void DolphinView::deleteView() m_viewAccessor.deleteView(); m_fileItemDelegate = 0; - m_toolTipManager = 0; } } @@ -1412,9 +1385,6 @@ void DolphinView::initializeView() view->setSelectionMode(QAbstractItemView::ExtendedSelection); - m_previewGenerator = new KFilePreviewGenerator(view); - m_previewGenerator->setPreviewShown(m_showPreview); - m_versionControlObserver = new VersionControlObserver(view); connect(m_versionControlObserver, SIGNAL(infoMessage(const QString&)), this, SIGNAL(infoMessage(const QString&))); @@ -1423,12 +1393,6 @@ void DolphinView::initializeView() connect(m_versionControlObserver, SIGNAL(operationCompletedMessage(const QString&)), this, SIGNAL(operationCompletedMessage(const QString&))); - if (DolphinSettings::instance().generalSettings()->showToolTips()) { - m_toolTipManager = new ToolTipManager(view, m_viewAccessor.proxyModel()); - connect(m_controller, SIGNAL(hideToolTip()), - m_toolTipManager, SLOT(hideTip())); - } - connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), this, SLOT(emitDelayedSelectionChangedSignal())); connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)), @@ -1493,11 +1457,11 @@ void DolphinView::ViewAccessor::createView(QWidget* parent, switch (mode) { case IconsView: - m_iconsView = new DolphinIconsView(parent, controller); + m_iconsView = new DolphinIconsView(parent, controller, m_proxyModel); break; case DetailsView: - m_detailsView = new DolphinDetailsView(parent, controller); + m_detailsView = new DolphinDetailsView(parent, controller, m_proxyModel); break; case ColumnView: diff --git a/src/dolphinview.h b/src/dolphinview.h index b9a7ff9cea..3637df444f 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -54,7 +54,6 @@ class KAction; class KActionCollection; class KDirLister; class KUrl; -class ToolTipManager; class VersionControlObserver; class ViewProperties; @@ -824,9 +823,6 @@ private: QItemSelectionModel* m_selectionModel; QTimer* m_selectionChangedTimer; - KFilePreviewGenerator* m_previewGenerator; - ToolTipManager* m_toolTipManager; - VersionControlObserver* m_versionControlObserver; KUrl m_rootUrl; diff --git a/src/tooltips/tooltipmanager.cpp b/src/tooltips/tooltipmanager.cpp index ae514f896d..fbb36aaf5b 100644 --- a/src/tooltips/tooltipmanager.cpp +++ b/src/tooltips/tooltipmanager.cpp @@ -86,6 +86,7 @@ ToolTipManager::ToolTipManager(QAbstractItemView* parent, this, SLOT(hideTip())); m_view->viewport()->installEventFilter(this); + m_view->installEventFilter(this); } ToolTipManager::~ToolTipManager() @@ -99,7 +100,16 @@ void ToolTipManager::hideTip() bool ToolTipManager::eventFilter(QObject* watched, QEvent* event) { - if ((watched == m_view->viewport()) && (event->type() == QEvent::Leave)) { + if (watched == m_view->viewport()) { + switch (event->type()) { + case QEvent::Leave: + case QEvent::MouseButtonPress: + hideToolTip(); + break; + default: + break; + } + } else if ((watched == m_view) && (event->type() == QEvent::KeyPress)) { hideToolTip(); } diff --git a/src/viewextensionsfactory.cpp b/src/viewextensionsfactory.cpp new file mode 100644 index 0000000000..91f9ff4667 --- /dev/null +++ b/src/viewextensionsfactory.cpp @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (C) 2009 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 "viewextensionsfactory.h" + +#include "dolphincontroller.h" +#include "dolphinsortfilterproxymodel.h" +#include "dolphinview.h" +#include "settings/dolphinsettings.h" +#include "tooltips/tooltipmanager.h" + +#include "dolphin_generalsettings.h" + +#include +#include + +ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view, + DolphinController* controller) : + QObject(view), + m_controller(controller), + m_toolTipManager(0), + m_previewGenerator(0) +{ + if (DolphinSettings::instance().generalSettings()->showToolTips()) { + DolphinSortFilterProxyModel* proxyModel = static_cast(view->model()); + m_toolTipManager = new ToolTipManager(view, proxyModel); + + connect(controller, SIGNAL(hideToolTip()), + m_toolTipManager, SLOT(hideTip())); + } + + m_previewGenerator = new KFilePreviewGenerator(view); + m_previewGenerator->setPreviewShown(controller->dolphinView()->showPreview()); + connect(controller, SIGNAL(zoomLevelChanged(int)), + this, SLOT(updateIcons())); + connect(controller, SIGNAL(cancelPreviews()), + this, SLOT(cancelPreviews())); + connect(controller->dolphinView(), SIGNAL(showPreviewChanged()), + this, SLOT(slotShowPreviewChanged())); +} + +ViewExtensionsFactory::~ViewExtensionsFactory() +{ +} + +void ViewExtensionsFactory::updateIcons() +{ + m_previewGenerator->updateIcons(); +} + +void ViewExtensionsFactory::cancelPreviews() +{ + m_previewGenerator->cancelPreviews(); +} + +void ViewExtensionsFactory::slotShowPreviewChanged() +{ + const bool show = m_controller->dolphinView()->showPreview(); + m_previewGenerator->setPreviewShown(show); +} + +#include "viewextensionsfactory.moc" + diff --git a/src/viewextensionsfactory.h b/src/viewextensionsfactory.h new file mode 100644 index 0000000000..dd819249b1 --- /dev/null +++ b/src/viewextensionsfactory.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2009 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 VIEWEXTENSIONSFACTORY_H +#define VIEWEXTENSIONSFACTORY_H + +#include + +class DolphinController; +class KFilePreviewGenerator; +class ToolTipManager; +class QAbstractItemView; + +class ViewExtensionsFactory : public QObject +{ + Q_OBJECT + + public: + explicit ViewExtensionsFactory(QAbstractItemView* view, + DolphinController* controller); + virtual ~ViewExtensionsFactory(); + + private slots: + /** + * Tells the preview generator to update all icons. + */ + void updateIcons(); + + /** + * Tells the preview generator to cancel all pending previews. + */ + void cancelPreviews(); + + void slotShowPreviewChanged(); + + private: + DolphinController* m_controller; + ToolTipManager* m_toolTipManager; + KFilePreviewGenerator* m_previewGenerator; +}; + +#endif +