]> cloud.milkyroute.net Git - dolphin.git/commitdiff
move the DolphinFileItemDelegate creation into ViewExtensionsFactory
authorPeter Penz <peter.penz19@gmail.com>
Sat, 29 Aug 2009 12:16:02 +0000 (12:16 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 29 Aug 2009 12:16:02 +0000 (12:16 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1016949

src/dolphincolumnview.cpp
src/dolphindetailsview.cpp
src/dolphinview.cpp
src/dolphinview.h
src/viewextensionsfactory.cpp
src/viewextensionsfactory.h

index 05544405bac54e402600a0d68e2eb54817f31481..57059e708135339658550e9683b18e47437f54cb 100644 (file)
@@ -91,10 +91,6 @@ DolphinColumnView::DolphinColumnView(QWidget* parent,
                        settings->italicFont());
     }
 
-   // KFileItemDelegate* delegate = new KFileItemDelegate(this);
-   // delegate->setShowToolTipWhenElided(false);
-   // setItemDelegate(delegate);
-
     activate();
 
     connect(this, SIGNAL(viewportEntered()),
index 460afd359067dc602bf699a17a7e1d81703eaa1a..f8e5898596b05611c152417a0dd7235b08a6ad7e 100644 (file)
@@ -155,6 +155,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
             this, SLOT(setFoldersExpandable(bool)));
 
     m_extensionsFactory = new ViewExtensionsFactory(this, controller);
+    m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
 }
 
 DolphinDetailsView::~DolphinDetailsView()
index 2af260f24f4bab1af5ac211308f743f6de2fe733..929a3ed1c61eb063b612c0cf352d07c91366c9f8 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "dolphinview.h"
 
+#include <QAbstractItemView>
 #include <QApplication>
 #include <QClipboard>
 #include <QKeyEvent>
@@ -90,7 +91,6 @@ DolphinView::DolphinView(QWidget* parent,
     m_mode(DolphinView::IconsView),
     m_topLayout(0),
     m_controller(0),
-    m_fileItemDelegate(0),
     m_viewAccessor(proxyModel),
     m_selectionChangedTimer(0),
     m_versionControlObserver(0),
@@ -229,7 +229,7 @@ void DolphinView::setMode(Mode mode)
     // the file item delegate has been recreated, apply the current
     // additional information manually
     const KFileItemDelegate::InformationList infoList = props.additionalInfo();
-    m_fileItemDelegate->setShowInformation(infoList);
+    m_viewAccessor.itemDelegate()->setShowInformation(infoList);
     emit additionalInfoChanged();
 
     // Not all view modes support categorized sorting. Adjust the sorting model
@@ -433,7 +433,7 @@ void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
     const KUrl viewPropsUrl = rootUrl();
     ViewProperties props(viewPropsUrl);
     props.setAdditionalInfo(info);
-    m_fileItemDelegate->setShowInformation(info);
+    m_viewAccessor.itemDelegate()->setShowInformation(info);
 
     emit additionalInfoChanged();
 
@@ -444,7 +444,7 @@ void DolphinView::setAdditionalInfo(KFileItemDelegate::InformationList info)
 
 KFileItemDelegate::InformationList DolphinView::additionalInfo() const
 {
-    return m_fileItemDelegate->showInformation();
+    return m_viewAccessor.itemDelegate()->showInformation();
 }
 
 void DolphinView::reload()
@@ -478,9 +478,7 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
     }
 
     m_controller->setUrl(url); // emits urlChanged, which we forward
-    if (m_viewAccessor.prepareUrlChange(url)) {
-        initializeView();
-    }
+    m_viewAccessor.prepareUrlChange(url);
     applyViewProperties();
     loadDirectory(url);
 
@@ -986,7 +984,7 @@ void DolphinView::updateAdditionalInfo(const KFileItemDelegate::InformationList&
     props.setAdditionalInfo(info);
     props.save();
 
-    m_fileItemDelegate->setShowInformation(info);
+    m_viewAccessor.itemDelegate()->setShowInformation(info);
 
     emit additionalInfoChanged();
 }
@@ -1017,7 +1015,7 @@ void DolphinView::updateAdditionalInfoActions(KActionCollection* collection)
     showGroupInfo->setEnabled(enable);
     showMimeInfo->setEnabled(enable);
 
-    foreach (KFileItemDelegate::Information info, m_fileItemDelegate->showInformation()) {
+    foreach (KFileItemDelegate::Information info, m_viewAccessor.itemDelegate()->showInformation()) {
         switch (info) {
         case KFileItemDelegate::Size:
             showSizeInfo->setChecked(true);
@@ -1272,8 +1270,8 @@ void DolphinView::applyViewProperties()
     }
 
     KFileItemDelegate::InformationList info = props.additionalInfo();
-    if (info != m_fileItemDelegate->showInformation()) {
-        m_fileItemDelegate->setShowInformation(info);
+    if (info != m_viewAccessor.itemDelegate()->showInformation()) {
+        m_viewAccessor.itemDelegate()->setShowInformation(info);
         emit additionalInfoChanged();
     }
 
@@ -1329,7 +1327,6 @@ void DolphinView::deleteView()
         view = 0;
 
         m_viewAccessor.deleteView();
-        m_fileItemDelegate = 0;
     }
 }
 
@@ -1360,11 +1357,6 @@ void DolphinView::initializeView()
 
     m_controller->setItemView(view);
 
-    m_fileItemDelegate = new DolphinFileItemDelegate(view);
-    m_fileItemDelegate->setShowToolTipWhenElided(false);
-    m_fileItemDelegate->setMinimizedNameColumn(m_mode == DetailsView);
-    view->setItemDelegate(m_fileItemDelegate);
-
     // TODO: reactivate selection model
     /*view->setModel(m_viewAccessor.proxyModel());
     if (m_selectionModel != 0) {
@@ -1486,12 +1478,11 @@ void DolphinView::ViewAccessor::deleteView()
 }
 
 
-bool DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url)
+void DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url)
 {
     if (m_columnsContainer != 0) {
-        return m_columnsContainer->showColumn(url);
+        m_columnsContainer->showColumn(url);
     }
-    return false;
 }
 
 QAbstractItemView* DolphinView::ViewAccessor::itemView() const
@@ -1511,6 +1502,11 @@ QAbstractItemView* DolphinView::ViewAccessor::itemView() const
     return 0;
 }
 
+KFileItemDelegate* DolphinView::ViewAccessor::itemDelegate() const
+{
+    return static_cast<KFileItemDelegate*>(itemView()->itemDelegate());
+}
+
 QWidget* DolphinView::ViewAccessor::layoutTarget() const
 {
     if (m_columnsContainer != 0) {
index 3637df444ffaa397cffbdd58b630d0e5ca67b4fc..08fe70e5f116cf92686dc20c00ffd1a1f8cbb8f9 100644 (file)
@@ -44,7 +44,6 @@ typedef KIO::FileUndoManager::CommandType CommandType;
 class DolphinController;
 class DolphinColumnViewContainer;
 class DolphinDetailsView;
-class DolphinFileItemDelegate;
 class DolphinIconsView;
 class DolphinMainWindow;
 class DolphinModel;
@@ -768,8 +767,15 @@ private:
 
         void createView(QWidget* parent, DolphinController* controller, Mode mode);
         void deleteView();
-        bool prepareUrlChange(const KUrl& url);
+
+        /**
+         * Must be invoked before the URL has been changed and allows view implementations
+         * like the column view to create a new column.
+         */
+        void prepareUrlChange(const KUrl& url);
+
         QAbstractItemView* itemView() const;
+        KFileItemDelegate* itemDelegate() const;
 
         /**
          * Returns the widget that should be added to the layout as target. Usually
@@ -817,7 +823,6 @@ private:
     QVBoxLayout* m_topLayout;
 
     DolphinController* m_controller;
-    DolphinFileItemDelegate* m_fileItemDelegate;
     ViewAccessor m_viewAccessor;
 
     QItemSelectionModel* m_selectionModel;
index b4b37983b04f9d2e1650055acf51fcfb2ee9b26a..198883d900c0b6803a8717a5909dc2ff79ac57e0 100644 (file)
@@ -20,6 +20,7 @@
 #include "viewextensionsfactory.h"
 
 #include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphinview.h"
 #include "dolphinviewautoscroller.h"
@@ -39,7 +40,8 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
     m_toolTipManager(0),
     m_previewGenerator(0),
     m_selectionManager(0),
-    m_autoScroller(0)
+    m_autoScroller(0),
+    m_fileItemDelegate(0)
 {
     GeneralSettings* settings = DolphinSettings::instance().generalSettings();
 
@@ -76,6 +78,11 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
     connect(controller, SIGNAL(currentIndexChanged(QModelIndex, QModelIndex)),
             m_autoScroller, SLOT(handleCurrentIndexChanged(QModelIndex, QModelIndex)));
 
+    // initialize file item delegate
+    m_fileItemDelegate = new DolphinFileItemDelegate(view);
+    m_fileItemDelegate->setShowToolTipWhenElided(false);
+    view->setItemDelegate(m_fileItemDelegate);
+
     view->viewport()->installEventFilter(this);
 }
 
@@ -88,6 +95,11 @@ void ViewExtensionsFactory::handleCurrentIndexChange(const QModelIndex& current,
     m_autoScroller->handleCurrentIndexChange(current, previous);
 }
 
+DolphinFileItemDelegate* ViewExtensionsFactory::fileItemDelegate() const
+{
+    return m_fileItemDelegate;
+}
+
 bool ViewExtensionsFactory::eventFilter(QObject* watched, QEvent* event)
 {
     Q_UNUSED(watched);
index e5e8056b733ebf890cf5ea2d94cd8db09f6af4c0..79b47a2eb1b8776bd4b61f4e29110b4e437399f0 100644 (file)
@@ -23,6 +23,7 @@
 #include <QObject>
 
 class DolphinController;
+class DolphinFileItemDelegate;
 class DolphinViewAutoScroller;
 class KFilePreviewGenerator;
 class QModelIndex;
@@ -55,6 +56,8 @@ public:
      */
     void handleCurrentIndexChange(const QModelIndex& current, const QModelIndex& previous);
 
+    DolphinFileItemDelegate* fileItemDelegate() const;
+
 protected:
     virtual bool eventFilter(QObject* watched, QEvent* event);
 
@@ -70,6 +73,7 @@ private:
     KFilePreviewGenerator* m_previewGenerator;
     SelectionManager* m_selectionManager;
     DolphinViewAutoScroller* m_autoScroller;
+    DolphinFileItemDelegate* m_fileItemDelegate;
 };
 
 #endif