X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a8ada5e6857d6dec25edf8ef57af9f27a91471c1..b1c9b5126d:/src/dolphinfileitemdelegate.cpp diff --git a/src/dolphinfileitemdelegate.cpp b/src/dolphinfileitemdelegate.cpp index a9ecc2a71..3fa05cbb5 100644 --- a/src/dolphinfileitemdelegate.cpp +++ b/src/dolphinfileitemdelegate.cpp @@ -19,9 +19,16 @@ #include "dolphinfileitemdelegate.h" +#include +#include +#include + +#include +#include + DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) : KFileItemDelegate(parent), - m_maxSize(0, 0) + m_hasMinimizedNameColumn(false) { } @@ -29,33 +36,36 @@ DolphinFileItemDelegate::~DolphinFileItemDelegate() { } -void DolphinFileItemDelegate::setMaximumSize(const QSize& size) +void DolphinFileItemDelegate::paint(QPainter* painter, + const QStyleOptionViewItem& option, + const QModelIndex& index) const { - m_maxSize = size; -} + if (m_hasMinimizedNameColumn && (index.column() == KDirModel::Name)) { + QStyleOptionViewItemV4 opt(option); - -QSize DolphinFileItemDelegate::maximumSize() const -{ - return m_maxSize; + 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.text(), opt); + opt.rect.setWidth(width); + } + KFileItemDelegate::paint(painter, opt, index); + } else { + KFileItemDelegate::paint(painter, option, index); + } } -QSize DolphinFileItemDelegate::sizeHint(const QStyleOptionViewItem& option, - const QModelIndex& index) const +int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option) { - QSize size = KFileItemDelegate::sizeHint(option, index); - - const int maxWidth = m_maxSize.width(); - if ((maxWidth > 0) && (size.width() > maxWidth)) { - size.setWidth(maxWidth); - } + QFontMetrics fontMetrics(option.font); + int width = option.decorationSize.width() + fontMetrics.width(name) + 16; - const int maxHeight = m_maxSize.height(); - if ((maxHeight > 0) && (size.height() > maxHeight)) { - size.setHeight(maxHeight); + const int defaultWidth = option.rect.width(); + if ((defaultWidth > 0) && (defaultWidth < width)) { + width = defaultWidth; } - - return size; + return width; } -#include "dolphinfileitemdelegate.moc"