From a8ada5e6857d6dec25edf8ef57af9f27a91471c1 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 20 Mar 2008 16:58:59 +0000 Subject: 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: fredrik@kde.org svn path=/trunk/KDE/kdebase/apps/; revision=788095 --- src/dolphinfileitemdelegate.cpp | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/dolphinfileitemdelegate.cpp (limited to 'src/dolphinfileitemdelegate.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 * + * * + * 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" -- cgit v1.3