]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Initial version for a column view support (thanks a lot to Benjamin Meyer for QColumn...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 27 Mar 2007 19:08:44 +0000 (19:08 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 27 Mar 2007 19:08:44 +0000 (19:08 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=647234

src/CMakeLists.txt
src/dolphin_directoryviewpropertysettings.kcfg
src/dolphincolumnview.cpp [new file with mode: 0644]
src/dolphincolumnview.h [new file with mode: 0644]
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinui.rc
src/dolphinview.cpp
src/dolphinview.h

index 2ad4814e20eb7ec2c73463fa4d0d6717494adbeb..81eaf9452f576c8c35190763e0f40e2d35f02e4d 100644 (file)
@@ -41,6 +41,7 @@ set(dolphin_SRCS
    bookmarkssidebarpage.cpp
    detailsviewsettingspage.cpp
    dolphinapplication.cpp
+   dolphincolumnview.cpp
    dolphinmainwindow.cpp
    dolphinnewmenu.cpp
    dolphinview.cpp
index bd8cf6c16d9fa18f4d326a6a4af76b5629b0a75e..1d074100a5f3838092a4cf7f23411e9f0df8ca67 100644 (file)
@@ -17,7 +17,7 @@
     <group name="Dolphin">
         <entry name="ViewMode" type="Int" >
             <label>View Mode</label>
-            <whatsthis>This option controls the style of the view. Currently supported values include icons (0) and details (1) views.</whatsthis>
+            <whatsthis>This option controls the style of the view. Currently supported values include icons (0), details (1) and column (2) views.</whatsthis>
             <default>DolphinView::IconsView</default>
             <min>0</min>
             <max code="true">DolphinView::MaxModeEnum</max>
diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp
new file mode 100644 (file)
index 0000000..41fb89f
--- /dev/null
@@ -0,0 +1,134 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at)                  *
+ *                                                                         *
+ *   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 "dolphincolumnview.h"
+
+#include "dolphincontroller.h"
+#include "dolphinsettings.h"
+
+//#include "dolphin_iconsmodesettings.h"
+
+#include <kdirmodel.h>
+#include <kfileitem.h>
+#include <kfileitemdelegate.h>
+
+#include <QAbstractProxyModel>
+#include <QPoint>
+
+DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* controller) :
+    QColumnView(parent),
+    m_controller(controller)
+{
+    Q_ASSERT(controller != 0);
+
+    viewport()->setAttribute(Qt::WA_Hover);
+
+    connect(this, SIGNAL(clicked(const QModelIndex&)),
+            controller, SLOT(triggerItem(const QModelIndex&)));
+    connect(this, SIGNAL(activated(const QModelIndex&)),
+            controller, SLOT(triggerItem(const QModelIndex&)));
+    connect(controller, SIGNAL(showPreviewChanged(bool)),
+            this, SLOT(updateGridSize(bool)));
+    connect(controller, SIGNAL(zoomIn()),
+            this, SLOT(zoomIn()));
+    connect(controller, SIGNAL(zoomOut()),
+            this, SLOT(zoomOut()));
+
+    // apply the icons mode settings to the widget
+    //const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    //Q_ASSERT(settings != 0);
+
+    m_viewOptions = QColumnView::viewOptions();
+
+    /*QFont font(settings->fontFamily(), settings->fontSize());
+    font.setItalic(settings->italicFont());
+    font.setBold(settings->boldFont());
+    m_viewOptions.font = font;
+
+    updateGridSize(controller->showPreview());
+
+    if (settings->arrangement() == QColumnView::TopToBottom) {
+        setFlow(QColumnView::LeftToRight);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Top;
+    }
+    else {
+        setFlow(QColumnView::TopToBottom);
+        m_viewOptions.decorationPosition = QStyleOptionViewItem::Left;
+    }*/
+}
+
+DolphinColumnView::~DolphinColumnView()
+{
+}
+
+QStyleOptionViewItem DolphinColumnView::viewOptions() const
+{
+    return m_viewOptions;
+}
+
+void DolphinColumnView::contextMenuEvent(QContextMenuEvent* event)
+{
+    QColumnView::contextMenuEvent(event);
+    m_controller->triggerContextMenuRequest(event->pos());
+}
+
+void DolphinColumnView::mouseReleaseEvent(QMouseEvent* event)
+{
+    QColumnView::mouseReleaseEvent(event);
+    m_controller->triggerActivation();
+}
+
+void DolphinColumnView::dragEnterEvent(QDragEnterEvent* event)
+{
+    if (event->mimeData()->hasUrls()) {
+        event->acceptProposedAction();
+    }
+}
+
+void DolphinColumnView::dropEvent(QDropEvent* event)
+{
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (!urls.isEmpty()) {
+        m_controller->indicateDroppedUrls(urls,
+                                          indexAt(event->pos()),
+                                          event->source());
+        event->acceptProposedAction();
+    }
+    QColumnView::dropEvent(event);
+}
+
+void DolphinColumnView::zoomIn()
+{
+}
+
+void DolphinColumnView::zoomOut()
+{
+}
+
+bool DolphinColumnView::isZoomInPossible() const
+{
+    return false;
+}
+
+bool DolphinColumnView::isZoomOutPossible() const
+{
+    return false;
+}
+
+#include "dolphincolumnview.moc"
diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h
new file mode 100644 (file)
index 0000000..649d2a7
--- /dev/null
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at)                  *
+ *                                                                         *
+ *   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 DOLPHINCOLUMNVIEW_H
+#define DOLPHINCOLUMNVIEW_H
+
+#include <QColumnView>
+#include <QStyleOptionViewItem>
+#include <libdolphin_export.h>
+
+class DolphinController;
+class DolphinView;
+
+/**
+ * @brief TODO
+ */
+class LIBDOLPHINPRIVATE_EXPORT DolphinColumnView : public QColumnView
+{
+    Q_OBJECT
+
+public:
+    explicit DolphinColumnView(QWidget* parent, DolphinController* controller);
+    virtual ~DolphinColumnView();
+
+protected:
+    virtual QStyleOptionViewItem viewOptions() const;
+    virtual void contextMenuEvent(QContextMenuEvent* event);
+    virtual void mouseReleaseEvent(QMouseEvent* event);
+    virtual void dragEnterEvent(QDragEnterEvent* event);
+    virtual void dropEvent(QDropEvent* event);
+
+private slots:
+    void zoomIn();
+    void zoomOut();
+
+private:
+    bool isZoomInPossible() const;
+    bool isZoomOutPossible() const;
+
+private:
+    DolphinController* m_controller;
+    QStyleOptionViewItem m_viewOptions;
+};
+
+#endif
index e86ad13fac289f7fd62b5699be0e774ea6fb802b..278d63c97696ad7f14365cfcf946339812560e6e 100644 (file)
@@ -704,6 +704,11 @@ void DolphinMainWindow::setDetailsView()
     m_activeView->setMode(DolphinView::DetailsView);\r
 }\r
 \r
+void DolphinMainWindow::setColumnView()\r
+{\r
+    m_activeView->setMode(DolphinView::ColumnView);\r
+}\r
+\r
 void DolphinMainWindow::sortByName()\r
 {\r
     m_activeView->setSorting(DolphinView::SortByName);\r
@@ -1152,9 +1157,16 @@ void DolphinMainWindow::setupActions()
     detailsView->setIcon(KIcon("fileview-text"));\r
     connect(detailsView, SIGNAL(triggered()), this, SLOT(setDetailsView()));\r
 \r
+    KToggleAction* columnView = actionCollection()->add<KToggleAction>("columns");\r
+    columnView->setText(i18n("Columns"));\r
+    columnView->setShortcut(Qt::CTRL | Qt::Key_3);\r
+    columnView->setIcon(KIcon("view-tree"));\r
+    connect(columnView, SIGNAL(triggered()), this, SLOT(setColumnView()));\r
+\r
     QActionGroup* viewModeGroup = new QActionGroup(this);\r
     viewModeGroup->addAction(iconsView);\r
     viewModeGroup->addAction(detailsView);\r
+    viewModeGroup->addAction(columnView);\r
 \r
     KToggleAction* sortByName = actionCollection()->add<KToggleAction>("by_name");\r
     sortByName->setText(i18n("By Name"));\r
@@ -1414,6 +1426,9 @@ void DolphinMainWindow::updateViewActions()
         case DolphinView::DetailsView:\r
             action = actionCollection()->action("details");\r
             break;\r
+        case DolphinView::ColumnView:\r
+            action = actionCollection()->action("columns");\r
+            break;\r
         default:\r
             break;\r
     }\r
index d8c64da7c1a81be55e8f9398abbbdf9aadee8611..c6b46817f2bc5edc8f460cdd136e1ccf4edf1ee0 100644 (file)
@@ -232,6 +232,9 @@ private slots:
     /** The current active view is switched to the details mode. */
     void setDetailsView();
 
+    /** The current active view is switched to the column mode. */
+    void setColumnView();
+
     /** The sorting of the current view should be done by the name. */
     void sortByName();
 
index 06f94826cf04233fa19e44abe36cfab3f422ef2a..bb3e2d7291be6443f6eb30e4e0343e501907ec89 100644 (file)
@@ -20,6 +20,7 @@
     <text>View Mode</text>
     <Action name="icons" />
     <Action name="details" />
+    <Action name="columns" />
    </Menu>
    <Menu name="sort">
     <text>Sort</text>
   <Separator name="separator_1" />
   <Action name="icons" />
   <Action name="details" />
+  <Action name="columns" />
   <Separator name="separator_0" />
   <Action name="show_preview" />
   <Action name="split_view" />
index 17bbd608dd5080287d1ad3e3e1b6a9eeb886eecd..04b949a7d3c3f78453e8f306396e24704623bed7 100644 (file)
@@ -39,6 +39,7 @@
 #include <konq_operations.h>
 #include <kurl.h>
 
+#include "dolphincolumnview.h"
 #include "dolphincontroller.h"
 #include "dolphinstatusbar.h"
 #include "dolphinmainwindow.h"
@@ -71,6 +72,7 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
     m_controller(0),
     m_iconsView(0),
     m_detailsView(0),
+    m_columnView(0),
     m_fileItemDelegate(0),
     m_filterBar(0),
     m_statusBar(0),
@@ -597,7 +599,16 @@ void DolphinView::loadDirectory(const KUrl& url)
     const ViewProperties props(url);
 
     const Mode mode = props.viewMode();
-    if (m_mode != mode) {
+    bool changeMode = (m_mode != mode);
+    if (changeMode && isColumnViewActive()) {
+        // The column view is active. Only change the
+        // mode if the current URL is no child of the column view.
+        if (m_dirLister->url().isParentOf(url)) {
+            changeMode = false;
+        }
+    }
+
+    if (changeMode) {
         m_mode = mode;
         createView();
         emit modeChanged();
@@ -824,7 +835,15 @@ void DolphinView::startDirLister(const KUrl& url, bool reload)
     m_cutItemsCache.clear();
     m_blockContentsMovedSignal = true;
     m_dirLister->stop();
-    m_dirLister->openUrl(url, false, reload);
+
+    bool keepOldDirs = isColumnViewActive();
+    if (keepOldDirs && !m_dirLister->url().isParentOf(url)) {
+        // The current URL is not a child of the dir lister
+        // URL. This may happen when e. g. a bookmark has been selected
+        // and hence the view must be reset.
+        keepOldDirs = false;
+    }
+    m_dirLister->openUrl(url, keepOldDirs, reload);
 }
 
 QString DolphinView::defaultStatusBarText() const
@@ -1072,11 +1091,13 @@ void DolphinView::createView()
         view = 0;
         m_iconsView = 0;
         m_detailsView = 0;
+        m_columnView = 0;
         m_fileItemDelegate = 0;
     }
 
     Q_ASSERT(m_iconsView == 0);
     Q_ASSERT(m_detailsView == 0);
+    Q_ASSERT(m_columnView == 0);
 
     // ... and recreate it representing the current mode
     switch (m_mode) {
@@ -1089,6 +1110,11 @@ void DolphinView::createView()
             m_detailsView = new DolphinDetailsView(this, m_controller);
             view = m_detailsView;
             break;
+
+        case ColumnView:
+            m_columnView = new DolphinColumnView(this, m_controller);
+            view = m_columnView;
+            break;
     }
 
     Q_ASSERT(view != 0);
@@ -1125,10 +1151,13 @@ void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
 
 QAbstractItemView* DolphinView::itemView() const
 {
-    Q_ASSERT((m_iconsView == 0) || (m_detailsView == 0));
     if (m_detailsView != 0) {
         return m_detailsView;
     }
+    else if (m_columnView != 0) {
+        return m_columnView;
+    }
+
     return m_iconsView;
 }
 
index 14c8372d3e64de9ad7cb343718a3128c1f464229..6aabf2d34652e6ba0848ac17e45977bc25af5b87 100644 (file)
@@ -43,6 +43,7 @@ class KFileItemDelegate;
 class KUrl;
 class KDirModel;
 class UrlNavigator;
+class DolphinColumnView;
 class DolphinDetailsView;
 class DolphinDirLister;
 class DolphinIconsView;
@@ -58,11 +59,12 @@ class ViewProperties;
  * @short Represents a view for the directory content
  *        including the navigation bar, filter bar and status bar.
  *
- * View modes for icons and details are supported. Currently
+ * View modes for icons, details and columns are supported. Currently
  * Dolphin allows to have up to two views inside the main window.
  *
  * @see DolphinIconsView
  * @see DolphinDetailsView
+ * @see DolphinColumnView
  * @see UrlNavigator
  * @see DolphinStatusBar
  */
@@ -90,7 +92,12 @@ public:
          * for date, group and permissions.
          */
         DetailsView = 1,
-        MaxModeEnum = DetailsView
+
+        /**
+         * Each folder is shown in a separate column.
+         */
+        ColumnView = 2,
+        MaxModeEnum = ColumnView
     };
 
     /** Defines the sort order for the items of a directory. */
@@ -542,6 +549,13 @@ private:
     /** Applies an item effect to all cut items. */
     void applyCutItemEffect();
 
+    /**
+     * Returns true, if the ColumnView is activated. As the column view
+     * requires some special handling for iterating through directories,
+     * this method has been introduced for convenience.
+     */
+    bool isColumnViewActive() const { return m_columnView != 0; }
+
 private:
     /**
      * Remembers the original pixmap for an item before
@@ -567,6 +581,7 @@ private:
     DolphinController* m_controller;
     DolphinIconsView* m_iconsView;
     DolphinDetailsView* m_detailsView;
+    DolphinColumnView* m_columnView;
     KFileItemDelegate* m_fileItemDelegate;
 
     FilterBar* m_filterBar;