BUG: 298218
FIXED-IN: 4.9.0
roles.insert("iconName");
roles.insert("text");
roles.insert("isDir");
roles.insert("iconName");
roles.insert("text");
roles.insert("isDir");
+ roles.insert("isLink");
if (supportsItemExpanding()) {
roles.insert("isExpanded");
roles.insert("isExpandable");
if (supportsItemExpanding()) {
roles.insert("isExpanded");
roles.insert("isExpandable");
return data().value("text").toString().startsWith(QLatin1Char('.'));
}
return data().value("text").toString().startsWith(QLatin1Char('.'));
}
+QFont KFileItemListWidget::customizedFont(const QFont& baseFont) const
+{
+ // The customized font should be italic if the file is a symbolic link.
+ QFont font(baseFont);
+ font.setItalic(data().value("isLink").toBool());
+ return font;
+}
+
#include "kfileitemlistwidget.moc"
#include "kfileitemlistwidget.moc"
protected:
virtual bool isRoleRightAligned(const QByteArray& role) const;
virtual bool isHidden() const;
protected:
virtual bool isRoleRightAligned(const QByteArray& role) const;
virtual bool isHidden() const;
+ virtual QFont customizedFont(const QFont& baseFont) const;
resetRoles();
m_requestRole[NameRole] = true;
m_requestRole[IsDirRole] = true;
resetRoles();
m_requestRole[NameRole] = true;
m_requestRole[IsDirRole] = true;
+ m_requestRole[IsLinkRole] = true;
m_roles.insert("text");
m_roles.insert("isDir");
m_roles.insert("text");
m_roles.insert("isDir");
+ m_roles.insert("isLink");
// For slow KIO-slaves like used for searching it makes sense to show results periodically even
// before the completed() or canceled() signal has been emitted.
// For slow KIO-slaves like used for searching it makes sense to show results periodically even
// before the completed() or canceled() signal has been emitted.
// Insert internal roles (take care to synchronize the implementation
// with KFileItemModel::roleForType() in case if a change is done).
roles.insert("isDir", IsDirRole);
// Insert internal roles (take care to synchronize the implementation
// with KFileItemModel::roleForType() in case if a change is done).
roles.insert("isDir", IsDirRole);
+ roles.insert("isLink", IsLinkRole);
roles.insert("isExpanded", IsExpandedRole);
roles.insert("isExpandable", IsExpandableRole);
roles.insert("expandedParentsCount", ExpandedParentsCountRole);
roles.insert("isExpanded", IsExpandedRole);
roles.insert("isExpandable", IsExpandableRole);
roles.insert("expandedParentsCount", ExpandedParentsCountRole);
// Insert internal roles (take care to synchronize the implementation
// with KFileItemModel::typeForRole() in case if a change is done).
roles.insert(IsDirRole, "isDir");
// Insert internal roles (take care to synchronize the implementation
// with KFileItemModel::typeForRole() in case if a change is done).
roles.insert(IsDirRole, "isDir");
+ roles.insert(IsLinkRole, "isLink");
roles.insert(IsExpandedRole, "isExpanded");
roles.insert(IsExpandableRole, "isExpandable");
roles.insert(ExpandedParentsCountRole, "expandedParentsCount");
roles.insert(IsExpandedRole, "isExpanded");
roles.insert(IsExpandableRole, "isExpandable");
roles.insert(ExpandedParentsCountRole, "expandedParentsCount");
data.insert("isDir", isDir);
}
data.insert("isDir", isDir);
}
+ if (m_requestRole[IsLinkRole]) {
+ const bool isLink = item.isLink();
+ data.insert("isLink", isLink);
+ }
+
if (m_requestRole[NameRole]) {
data.insert("text", item.text());
}
if (m_requestRole[NameRole]) {
data.insert("text", item.text());
}
WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
CopiedFromRole,
// Non-visible roles:
WordCountRole, LineCountRole, ArtistRole, AlbumRole, DurationRole, TrackRole,
CopiedFromRole,
// Non-visible roles:
- IsDirRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
+ IsDirRole, IsLinkRole, IsExpandedRole, IsExpandableRole, ExpandedParentsCountRole,
// Mandatory last entry:
RolesCount
};
// Mandatory last entry:
RolesCount
};
KItemListWidget(informant, parent),
m_isCut(false),
m_isHidden(false),
KItemListWidget(informant, parent),
m_isCut(false),
m_isHidden(false),
+ m_customizedFont(),
+ m_customizedFontMetrics(m_customizedFont),
m_isExpandable(false),
m_supportsItemExpanding(false),
m_dirtyLayout(true),
m_isExpandable(false),
m_supportsItemExpanding(false),
m_dirtyLayout(true),
drawPixmap(painter, m_pixmap);
}
drawPixmap(painter, m_pixmap);
}
- painter->setFont(itemListStyleOption.font);
+ painter->setFont(m_customizedFont);
painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
const TextInfo* textInfo = m_textInfo.value("text");
painter->drawStaticText(textInfo->pos, textInfo->staticText);
painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
const TextInfo* textInfo = m_textInfo.value("text");
painter->drawStaticText(textInfo->pos, textInfo->staticText);
}
painter->setPen(m_additionalInfoTextColor);
}
painter->setPen(m_additionalInfoTextColor);
- painter->setFont(itemListStyleOption.font);
+ painter->setFont(m_customizedFont);
for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) {
const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]);
for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) {
const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]);
painter->drawRect(m_iconRect);
painter->setPen(Qt::red);
painter->drawRect(m_iconRect);
painter->setPen(Qt::red);
- painter->drawText(QPointF(0, itemListStyleOption.fontMetrics.height()), QString::number(index()));
+ painter->drawText(QPointF(0, m_customizedFontMetrics.height()), QString::number(index()));
painter->drawRect(rect());
#endif
}
painter->drawRect(rect());
#endif
}
const KItemListStyleOption& option = styleOption();
if (option.extendedSelectionRegion) {
const QString text = textInfo->staticText.text();
const KItemListStyleOption& option = styleOption();
if (option.extendedSelectionRegion) {
const QString text = textInfo->staticText.text();
- rect.setWidth(option.fontMetrics.width(text) + 2 * option.padding);
+ rect.setWidth(m_customizedFontMetrics.width(text) + 2 * option.padding);
+QFont KStandardItemListWidget::customizedFont(const QFont& baseFont) const
+{
+ return baseFont;
+}
+
void KStandardItemListWidget::setTextColor(const QColor& color)
{
if (color != m_customTextColor) {
void KStandardItemListWidget::setTextColor(const QColor& color)
{
if (color != m_customTextColor) {
const QHash<QByteArray, QVariant> values = data();
m_isExpandable = m_supportsItemExpanding && values["isExpandable"].toBool();
m_isHidden = isHidden();
const QHash<QByteArray, QVariant> values = data();
m_isExpandable = m_supportsItemExpanding && values["isExpandable"].toBool();
m_isHidden = isHidden();
+ m_customizedFont = customizedFont(styleOption().font);
+ m_customizedFontMetrics = QFontMetrics(m_customizedFont);
updateExpansionArea();
updateTextsCache();
updateExpansionArea();
updateTextsCache();
scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding);
} else {
const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1;
scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding);
} else {
const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1;
- const qreal requiredTextHeight = textRowsCount * option.fontMetrics.height();
+ const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height();
scaledIconSize = (requiredTextHeight < maxIconHeight) ?
widgetSize.height() - 2 * padding : maxIconHeight;
}
scaledIconSize = (requiredTextHeight < maxIconHeight) ?
widgetSize.height() - 2 * padding : maxIconHeight;
}
const qreal padding = option.padding;
const qreal maxWidth = size().width() - 2 * padding;
const qreal widgetHeight = size().height();
const qreal padding = option.padding;
const qreal maxWidth = size().width() - 2 * padding;
const qreal widgetHeight = size().height();
- const qreal lineSpacing = option.fontMetrics.lineSpacing();
+ const qreal lineSpacing = m_customizedFontMetrics.lineSpacing();
// Initialize properties for the "text" role. It will be used as anchor
// for initializing the position of the other roles.
// Initialize properties for the "text" role. It will be used as anchor
// for initializing the position of the other roles.
const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
const int maxNameLines = (option.maxTextSize.height() / int(lineSpacing)) - additionalRolesCount;
const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
const int maxNameLines = (option.maxTextSize.height() / int(lineSpacing)) - additionalRolesCount;
- QTextLayout layout(nameTextInfo->staticText.text(), option.font);
+ QTextLayout layout(nameTextInfo->staticText.text(), m_customizedFont);
layout.setTextOption(nameTextInfo->staticText.textOption());
layout.beginLayout();
int nameLineIndex = 0;
layout.setTextOption(nameTextInfo->staticText.textOption());
layout.beginLayout();
int nameLineIndex = 0;
if (textLength < nameText.length()) {
// Elide the last line of the text
QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
if (textLength < nameText.length()) {
// Elide the last line of the text
QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
- lastTextLine = option.fontMetrics.elidedText(lastTextLine,
- Qt::ElideRight,
- line.naturalTextWidth() - 1);
+ lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
+ Qt::ElideRight,
+ line.naturalTextWidth() - 1);
const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
nameTextInfo->staticText.setText(elidedText);
}
const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
nameTextInfo->staticText.setText(elidedText);
}
- QTextLayout layout(text, option.font);
+ QTextLayout layout(text, m_customizedFont);
QTextOption textOption;
textOption.setWrapMode(QTextOption::NoWrap);
layout.setTextOption(textOption);
QTextOption textOption;
textOption.setWrapMode(QTextOption::NoWrap);
layout.setTextOption(textOption);
textLine.setLineWidth(maxWidth);
requiredWidth = textLine.naturalTextWidth();
if (requiredWidth > maxWidth) {
textLine.setLineWidth(maxWidth);
requiredWidth = textLine.naturalTextWidth();
if (requiredWidth > maxWidth) {
- const QString elidedText = option.fontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
+ const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
textInfo->staticText.setText(elidedText);
textInfo->staticText.setText(elidedText);
- requiredWidth = option.fontMetrics.width(elidedText);
+ requiredWidth = m_customizedFontMetrics.width(elidedText);
const KItemListStyleOption& option = styleOption();
const qreal widgetHeight = size().height();
const KItemListStyleOption& option = styleOption();
const qreal widgetHeight = size().height();
- const qreal lineSpacing = option.fontMetrics.lineSpacing();
+ const qreal lineSpacing = m_customizedFontMetrics.lineSpacing();
const qreal textLinesHeight = qMax(visibleRoles().count(), 1) * lineSpacing;
const int scaledIconSize = (textLinesHeight < option.iconSize) ? widgetHeight - 2 * option.padding : option.iconSize;
const qreal textLinesHeight = qMax(visibleRoles().count(), 1) * lineSpacing;
const int scaledIconSize = (textLinesHeight < option.iconSize) ? widgetHeight - 2 * option.padding : option.iconSize;
TextInfo* textInfo = m_textInfo.value(role);
textInfo->staticText.setText(text);
TextInfo* textInfo = m_textInfo.value(role);
textInfo->staticText.setText(text);
- qreal requiredWidth = option.fontMetrics.width(text);
+ qreal requiredWidth = m_customizedFontMetrics.width(text);
if (requiredWidth > maxWidth) {
requiredWidth = maxWidth;
if (requiredWidth > maxWidth) {
requiredWidth = maxWidth;
- const QString elidedText = option.fontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
+ const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
textInfo->staticText.setText(elidedText);
}
textInfo->staticText.setText(elidedText);
}
const qreal widgetHeight = size().height();
const int scaledIconSize = widgetHeight - 2 * option.padding;
const qreal widgetHeight = size().height();
const int scaledIconSize = widgetHeight - 2 * option.padding;
- const int fontHeight = option.fontMetrics.height();
+ const int fontHeight = m_customizedFontMetrics.height();
const qreal columnWidthInc = columnPadding(option);
qreal firstColumnInc = scaledIconSize;
const qreal columnWidthInc = columnPadding(option);
qreal firstColumnInc = scaledIconSize;
QString text = roleText(role, values);
// Elide the text in case it does not fit into the available column-width
QString text = roleText(role, values);
// Elide the text in case it does not fit into the available column-width
- qreal requiredWidth = option.fontMetrics.width(text);
+ qreal requiredWidth = m_customizedFontMetrics.width(text);
const qreal roleWidth = columnWidth(role);
qreal availableTextWidth = roleWidth - columnWidthInc;
const qreal roleWidth = columnWidth(role);
qreal availableTextWidth = roleWidth - columnWidthInc;
}
if (requiredWidth > availableTextWidth) {
}
if (requiredWidth > availableTextWidth) {
- text = option.fontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
- requiredWidth = option.fontMetrics.width(text);
+ text = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
+ requiredWidth = m_customizedFontMetrics.width(text);
}
TextInfo* textInfo = m_textInfo.value(role);
}
TextInfo* textInfo = m_textInfo.value(role);
*/
virtual bool isHidden() const;
*/
virtual bool isHidden() const;
+ /**
+ * @return A font based on baseFont which is customized according to the data shown in the widget.
+ */
+ virtual QFont customizedFont(const QFont& baseFont) const;
+
void setTextColor(const QColor& color);
QColor textColor() const;
void setTextColor(const QColor& color);
QColor textColor() const;
private:
bool m_isCut;
bool m_isHidden;
private:
bool m_isCut;
bool m_isHidden;
+ QFont m_customizedFont;
+ QFontMetrics m_customizedFontMetrics;
bool m_isExpandable;
bool m_supportsItemExpanding;
bool m_isExpandable;
bool m_supportsItemExpanding;
void KFileItemModelTest::testDefaultRoles()
{
const QSet<QByteArray> roles = m_model->roles();
void KFileItemModelTest::testDefaultRoles()
{
const QSet<QByteArray> roles = m_model->roles();
- QCOMPARE(roles.count(), 2);
+ QCOMPARE(roles.count(), 3);
QVERIFY(roles.contains("text"));
QVERIFY(roles.contains("isDir"));
QVERIFY(roles.contains("text"));
QVERIFY(roles.contains("isDir"));
+ QVERIFY(roles.contains("isLink"));
}
void KFileItemModelTest::testDefaultSortRole()
}
void KFileItemModelTest::testDefaultSortRole()