From 994095076cccdb703b2bb285d4118bd9c654fd93 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Wed, 15 Oct 2008 21:23:42 +0000 Subject: Assure that the item delegate draws the hover effect and the selection for the details view only above the icon + name. Open issue: The performance when selecting files by the rubberband is too slow (will be fixed before KDE 4.2). CCBUG: 165999 CCMAIL: simon@etotheipiplusone.com svn path=/trunk/KDE/kdebase/apps/; revision=871874 --- src/dolphinfileitemdelegate.cpp | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 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..53c1d781e --- /dev/null +++ b/src/dolphinfileitemdelegate.cpp @@ -0,0 +1,66 @@ +/*************************************************************************** + * 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" + +#include +#include +#include + +#include +#include + +DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) : + KFileItemDelegate(parent), + m_hasMinimizedNameColumn(false) +{ +} + +DolphinFileItemDelegate::~DolphinFileItemDelegate() +{ +} + +void DolphinFileItemDelegate::paint(QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const +{ + if (m_hasMinimizedNameColumn && (index.column() == KDirModel::Name)) { + QStyleOptionViewItemV4 opt(option); + + const QAbstractProxyModel* proxyModel = static_cast(index.model()); + const KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + const QModelIndex dirIndex = proxyModel->mapToSource(index); + const KFileItem item = dirModel->itemForIndex(dirIndex); + if (!item.isNull()) { + const int width = nameColumnWidth(item.name(), opt); + opt.rect.setWidth(width); + } + KFileItemDelegate::paint(painter, opt, index); + } else { + KFileItemDelegate::paint(painter, option, index); + } +} + +int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option) +{ + QFontMetrics fontMetrics(option.font); + return option.decorationSize.width() + fontMetrics.width(name) + 16; +} + +#include "dolphinfileitemdelegate.moc" -- cgit v1.3