┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-03-20 16:58:59 +0000
committerPeter Penz <[email protected]>2008-03-20 16:58:59 +0000
commita8ada5e6857d6dec25edf8ef57af9f27a91471c1 (patch)
treecd76cdcbae8e02405c9d4fb768d51b04384109d6
parentf738a9ff2ba3a71a6015d388c835ffa7c7e0be02 (diff)
QListView does not support having a margin for grids. Originally it has been tried to bypass this by overwriting QListView::visualRect(), but this has some side effects (see #155378 and #155575). The clean approach is to return a proper size hint in the file item delegate.
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: [email protected] svn path=/trunk/KDE/kdebase/apps/; revision=788095
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/dolphinfileitemdelegate.cpp61
-rw-r--r--src/dolphinfileitemdelegate.h48
-rw-r--r--src/dolphiniconsview.cpp50
-rw-r--r--src/dolphiniconsview.h3
-rw-r--r--src/dolphinview.cpp4
-rw-r--r--src/dolphinview.h3
7 files changed, 120 insertions, 50 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fcecacd44..6af8fc9f3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -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
index 000000000..a9ecc2a71
--- /dev/null
+++ b/src/dolphinfileitemdelegate.cpp
@@ -0,0 +1,61 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <[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 *
+ ***************************************************************************/
+
+#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
index 000000000..2f0167cd9
--- /dev/null
+++ b/src/dolphinfileitemdelegate.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Peter Penz <[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 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
diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp
index 45fbf25b2..6235fcd87 100644
--- a/src/dolphiniconsview.cpp
+++ b/src/dolphiniconsview.cpp
@@ -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
diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h
index d96d7c7e9..e8e63eaf8 100644
--- a/src/dolphiniconsview.h
+++ b/src/dolphiniconsview.h
@@ -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);
diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp
index 257809b67..4800b9e9a 100644
--- a/src/dolphinview.cpp
+++ b/src/dolphinview.cpp
@@ -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);
diff --git a/src/dolphinview.h b/src/dolphinview.h
index 4f2964761..f7d95c6e2 100644
--- a/src/dolphinview.h
+++ b/src/dolphinview.h
@@ -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;