]> cloud.milkyroute.net Git - dolphin.git/commitdiff
QListView does not support having a margin for grids. Originally it has been tried...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 20 Mar 2008 16:58:59 +0000 (16:58 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 20 Mar 2008 16:58:59 +0000 (16:58 +0000)
Currently a custom item delegate has been made for Dolphin, but we'll discuss whether it makes sense providing this feature already in KFileItemDelegate...

BUG: 155378
BUG: 155575
CCMAIL: fredrik@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=788095

src/CMakeLists.txt
src/dolphinfileitemdelegate.cpp [new file with mode: 0644]
src/dolphinfileitemdelegate.h [new file with mode: 0644]
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinview.cpp
src/dolphinview.h

index fcecacd440a99a8182b967a3dddd02ce87b86a24..6af8fc9f33336175aecc7630e2d76e7444720601 100644 (file)
@@ -18,6 +18,7 @@ set(dolphinprivate_LIB_SRCS
     dolphincolumnview.cpp
     dolphincolumnwidget.cpp
     dolphindropcontroller.cpp
+    dolphinfileitemdelegate.cpp
     dolphinsortfilterproxymodel.cpp
     draganddrophelper.cpp
     dolphinmodel.cpp
diff --git a/src/dolphinfileitemdelegate.cpp b/src/dolphinfileitemdelegate.cpp
new file mode 100644 (file)
index 0000000..a9ecc2a
--- /dev/null
@@ -0,0 +1,61 @@
+/***************************************************************************
+ *   Copyright (C) 2008 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 "dolphinfileitemdelegate.h"
+
+DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) :
+    KFileItemDelegate(parent),
+    m_maxSize(0, 0)
+{
+}
+
+DolphinFileItemDelegate::~DolphinFileItemDelegate()
+{
+}
+
+void DolphinFileItemDelegate::setMaximumSize(const QSize& size)
+{
+    m_maxSize = size;
+}
+
+
+QSize DolphinFileItemDelegate::maximumSize() const
+{
+    return m_maxSize;
+}
+
+QSize DolphinFileItemDelegate::sizeHint(const QStyleOptionViewItem& option,
+                                        const QModelIndex& index) const
+{
+    QSize size = KFileItemDelegate::sizeHint(option, index);
+
+    const int maxWidth = m_maxSize.width();
+    if ((maxWidth > 0) && (size.width() > maxWidth)) {
+        size.setWidth(maxWidth);
+    }
+
+    const int maxHeight = m_maxSize.height();
+    if ((maxHeight > 0) && (size.height() > maxHeight)) {
+        size.setHeight(maxHeight);
+    }
+
+    return size;
+}
+
+#include "dolphinfileitemdelegate.moc"
diff --git a/src/dolphinfileitemdelegate.h b/src/dolphinfileitemdelegate.h
new file mode 100644 (file)
index 0000000..2f0167c
--- /dev/null
@@ -0,0 +1,48 @@
+/***************************************************************************
+ *   Copyright (C) 2008 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 DOLPHINFILEITEMDELEGATE_H
+#define DOLPHINFILEITEMDELEGATE_H
+
+#include <kfileitemdelegate.h>
+
+/**
+ * @brief Extends KFileItemDelegate with the ability to set
+ *        a maximum size.
+ */
+class DolphinFileItemDelegate : public KFileItemDelegate
+{
+    Q_OBJECT
+
+public:
+    explicit DolphinFileItemDelegate(QObject* parent = 0);
+    virtual ~DolphinFileItemDelegate();
+
+    void setMaximumSize(const QSize& size);
+    QSize maximumSize() const;
+
+    /** @see QItemDelegate::sizeHint() */
+    virtual QSize sizeHint(const QStyleOptionViewItem& option,
+                           const QModelIndex& index) const;
+
+private:
+    QSize m_maxSize;
+};
+
+#endif
index 45fbf25b2888f80b83bbadaf020f08f299721df1..6235fcd871ddfa947a420bb8f7e980ac13c3e341 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "dolphincategorydrawer.h"
 #include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
 #include "dolphinsettings.h"
 #include "dolphin_iconsmodesettings.h"
 #include "dolphin_generalsettings.h"
@@ -132,50 +133,6 @@ DolphinIconsView::~DolphinIconsView()
     m_categoryDrawer = 0;
 }
 
-QRect DolphinIconsView::visualRect(const QModelIndex& index) const
-{
-    const bool leftToRightFlow = (flow() == QListView::LeftToRight);
-
-    QRect itemRect = KCategorizedView::visualRect(index);
-
-    const int maxWidth  = m_itemSize.width();
-    const int maxHeight = m_itemSize.height();
-
-    if (itemRect.width() > maxWidth) {
-        // assure that the maximum item width is not exceeded
-        if (leftToRightFlow) {
-            const int left = itemRect.left() + (itemRect.width() - maxWidth) / 2;
-            itemRect.setLeft(left);
-        }
-        itemRect.setWidth(maxWidth);
-    }
-
-    if (itemRect.height() > maxHeight) {
-        // assure that the maximum item height is not exceeded
-        if (!leftToRightFlow) {
-            const int top = itemRect.top() + (itemRect.height() - maxHeight) / 2;
-            itemRect.setTop(top);
-        }
-        itemRect.setHeight(maxHeight);
-    }
-
-    KCategorizedSortFilterProxyModel* proxyModel = dynamic_cast<KCategorizedSortFilterProxyModel*>(model());
-    if (leftToRightFlow && !proxyModel->isCategorizedModel()) {
-        // TODO: QListView::visualRect() calculates a wrong position of the items under
-        // certain circumstances (e. g. if the text is too long). This issue is bypassed
-        // by the following code (I'll try create a patch for Qt but as Dolphin must also work with
-        // Qt 4.3.0 this workaround must get applied at least for KDE 4.0).
-        const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-        const int margin = settings->gridSpacing();
-        const int gridWidth = gridSize().width();
-        const int gridIndex = (itemRect.left() - margin + 1) / gridWidth;
-        const int centerInc = (maxWidth - itemRect.width()) / 2;
-        itemRect.moveLeft((gridIndex * gridWidth) + margin + centerInc);
-    }
-
-    return itemRect;
-}
-
 QStyleOptionViewItem DolphinIconsView::viewOptions() const
 {
     QStyleOptionViewItem viewOptions = KCategorizedView::viewOptions();
@@ -461,6 +418,11 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 
     m_controller->setZoomInPossible(isZoomInPossible());
     m_controller->setZoomOutPossible(isZoomOutPossible());
+
+    DolphinFileItemDelegate* delegate = qobject_cast<DolphinFileItemDelegate*>(itemDelegate());
+    if (delegate != 0) {
+        delegate->setMaximumSize(m_itemSize);
+    }
 }
 
 int DolphinIconsView::additionalInfoCount() const
index d96d7c7e904e2883f124edc93750b8a9c32a6420..e8e63eaf877a657bf984ac1560480eb00eda371d 100644 (file)
@@ -48,9 +48,6 @@ public:
     explicit DolphinIconsView(QWidget* parent, DolphinController* controller);
     virtual ~DolphinIconsView();
 
-    /** @see QAbstractItemView::visualRect() */
-    virtual QRect visualRect(const QModelIndex& index) const;
-
 protected:
     virtual QStyleOptionViewItem viewOptions() const;
     virtual void contextMenuEvent(QContextMenuEvent* event);
index 257809b670608b9ffe8e3fe69818ed0840936f6a..4800b9e9ab620e18eabbc3a029df52aa3768a5c2 100644 (file)
@@ -31,7 +31,6 @@
 #include <kactioncollection.h>
 #include <kcolorscheme.h>
 #include <kdirlister.h>
-#include <kfileitemdelegate.h>
 #include <kiconeffect.h>
 #include <klocale.h>
 #include <kio/deletejob.h>
@@ -50,6 +49,7 @@
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
+#include "dolphinfileitemdelegate.h"
 #include "dolphinsortfilterproxymodel.h"
 #include "dolphindetailsview.h"
 #include "dolphiniconsview.h"
@@ -909,7 +909,7 @@ void DolphinView::createView()
 
     m_controller->setItemView(view);
 
-    m_fileItemDelegate = new KFileItemDelegate(view);
+    m_fileItemDelegate = new DolphinFileItemDelegate(view);
     view->setItemDelegate(m_fileItemDelegate);
 
     view->setModel(m_proxyModel);
index 4f296476133d02c6bb49de884a4791723d681197..f7d95c6e28418f10557f861b643ee68d8bdeb18e 100644 (file)
@@ -41,6 +41,7 @@
 class DolphinController;
 class DolphinColumnView;
 class DolphinDetailsView;
+class DolphinFileItemDelegate;
 class DolphinIconsView;
 class DolphinMainWindow;
 class DolphinModel;
@@ -635,7 +636,7 @@ private:
     DolphinIconsView* m_iconsView;
     DolphinDetailsView* m_detailsView;
     DolphinColumnView* m_columnView;
-    KFileItemDelegate* m_fileItemDelegate;
+    DolphinFileItemDelegate* m_fileItemDelegate;
     QItemSelectionModel* m_selectionModel;
 
     DolphinModel* m_dolphinModel;