Commit b8920587 authored by Emmanuel Pescosta's avatar Emmanuel Pescosta
Browse files

Fix Bug 326210 - Dolphin unnecessarily truncates names of soft links in compact mode

FIXED-IN: 4.13.0
BUG: 326210
BUG: 310592
REVIEW: 116121
parent 8dc43672
......@@ -46,6 +46,15 @@ QString KFileItemListWidgetInformant::itemText(int index, const KItemListView* v
return item.text();
}
bool KFileItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const
{
Q_ASSERT(qobject_cast<KFileItemModel*>(view->model()));
KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(view->model());
const KFileItem item = fileItemModel->fileItem(index);
return item.isLink();
}
QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
const QHash<QByteArray, QVariant>& values) const
{
......@@ -81,6 +90,15 @@ QString KFileItemListWidgetInformant::roleText(const QByteArray& role,
return text;
}
QFont KFileItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont) const
{
// The customized font should be italic if the file is a symbolic link.
QFont font(baseFont);
font.setItalic(true);
return font;
}
KFileItemListWidget::KFileItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
KStandardItemListWidget(informant, parent)
{
......
......@@ -32,7 +32,9 @@ public:
protected:
virtual QString itemText(int index, const KItemListView* view) const;
virtual bool itemIsLink(int index, const KItemListView* view) const;
virtual QString roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values) const;
virtual QFont customizedFontForLinks(const QFont& baseFont) const;
};
class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget : public KStandardItemListWidget
......
......@@ -86,16 +86,22 @@ qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArra
const QString text = roleText(role, values);
qreal width = KStandardItemListWidget::columnPadding(option);
const QFontMetrics& normalFontMetrics = option.fontMetrics;
const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font));
if (role == "rating") {
width += KStandardItemListWidget::preferredRatingSize(option).width();
} else {
width += option.fontMetrics.width(text);
// If current item is a link, we use the customized link font metrics instead of the normal font metrics.
const QFontMetrics& fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics;
width += fontMetrics.width(text);
if (role == "text") {
if (view->supportsItemExpanding()) {
// Increase the width by the expansion-toggle and the current expansion level
const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt();
const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
const qreal height = option.padding * 2 + qMax(option.iconSize, fontMetrics.height());
width += (expandedParentsCount + 1) * height;
}
......@@ -112,6 +118,11 @@ QString KStandardItemListWidgetInformant::itemText(int index, const KItemListVie
return view->model()->data(index).value("text").toString();
}
bool KStandardItemListWidgetInformant::itemIsLink(int index, const KItemListView* view) const
{
return false;
}
QString KStandardItemListWidgetInformant::roleText(const QByteArray& role,
const QHash<QByteArray, QVariant>& values) const
{
......@@ -122,10 +133,15 @@ QString KStandardItemListWidgetInformant::roleText(const QByteArray& role,
return values.value(role).toString();
}
QFont KStandardItemListWidgetInformant::customizedFontForLinks(const QFont& baseFont) const
{
return baseFont;
}
void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
{
const KItemListStyleOption& option = view->styleOption();
const QFont& font = option.font;
const QFont& normalFont = option.font;
const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
const qreal itemWidth = view->itemSize().width();
......@@ -133,6 +149,8 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
const qreal additionalRolesSpacing = additionalRolesCount * option.fontMetrics.lineSpacing();
const qreal spacingAndIconHeight = option.iconSize + option.padding * 3;
const QFont linkFont = customizedFontForLinks(normalFont);
QTextOption textOption(Qt::AlignHCenter);
textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
......@@ -141,6 +159,9 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
continue;
}
// If the current item is a link, we use the customized link font instead of the normal font.
const QFont& font = itemIsLink(index, view) ? linkFont : normalFont;
const QString& text = KStringHandler::preProcessWrap(itemText(index, view));
// Calculate the number of lines required for wrapping the name
......@@ -172,20 +193,25 @@ void KStandardItemListWidgetInformant::calculateIconsLayoutItemSizeHints(QVector
void KStandardItemListWidgetInformant::calculateCompactLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const
{
const KItemListStyleOption& option = view->styleOption();
const QFontMetrics& fontMetrics = option.fontMetrics;
const QFontMetrics& normalFontMetrics = option.fontMetrics;
const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
const QList<QByteArray>& visibleRoles = view->visibleRoles();
const bool showOnlyTextRole = (visibleRoles.count() == 1) && (visibleRoles.first() == "text");
const qreal maxWidth = option.maxTextWidth;
const qreal paddingAndIconWidth = option.padding * 4 + option.iconSize;
const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.lineSpacing());
const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * normalFontMetrics.lineSpacing());
const QFontMetrics linkFontMetrics(customizedFontForLinks(option.font));
for (int index = 0; index < sizeHints.count(); ++index) {
if (!sizeHints.at(index).isEmpty()) {
continue;
}
// If the current item is a link, we use the customized link font metrics instead of the normal font metrics.
const QFontMetrics& fontMetrics = itemIsLink(index, view) ? linkFontMetrics : normalFontMetrics;
// For each row exactly one role is shown. Calculate the maximum required width that is necessary
// to show all roles without horizontal clipping.
qreal maximumRequiredWidth = 0.0;
......
......@@ -53,6 +53,13 @@ protected:
*/
virtual QString itemText(int index, const KItemListView* view) const;
/**
* @return The value of the "isLink" role. The default implementation returns false.
* The derived class should reimplement this function, when information about
* links is available and in usage.
*/
virtual bool itemIsLink(int index, const KItemListView* view) const;
/**
* @return String representation of the role \a role. The representation of
* a role might depend on other roles, so the values of all roles
......@@ -61,6 +68,11 @@ protected:
virtual QString roleText(const QByteArray& role,
const QHash<QByteArray, QVariant>& values) const;
/**
* @return A font based on baseFont which is customized for symlinks.
*/
virtual QFont customizedFontForLinks(const QFont& baseFont) const;
void calculateIconsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
void calculateCompactLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
void calculateDetailsLayoutItemSizeHints(QVector<QSizeF>& sizeHints, const KItemListView* view) const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment