resetRoles();
m_requestRole[NameRole] = true;
m_requestRole[IsDirRole] = true;
+ m_requestRole[IsLinkRole] = true;
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.
// 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);
// 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");
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());
}
KItemListWidget(informant, parent),
m_isCut(false),
m_isHidden(false),
+ m_customizedFont(),
+ m_customizedFontMetrics(m_customizedFont),
m_isExpandable(false),
m_supportsItemExpanding(false),
m_dirtyLayout(true),
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_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]);
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
}
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);
}
return rect;
return false;
}
+QFont KStandardItemListWidget::customizedFont(const QFont& baseFont) const
+{
+ return baseFont;
+}
+
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();
+ m_customizedFont = customizedFont(styleOption().font);
+ m_customizedFontMetrics = QFontMetrics(m_customizedFont);
updateExpansionArea();
updateTextsCache();
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;
}
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.
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;
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);
}
qreal requiredWidth = 0;
- QTextLayout layout(text, option.font);
+ QTextLayout layout(text, m_customizedFont);
QTextOption textOption;
textOption.setWrapMode(QTextOption::NoWrap);
layout.setTextOption(textOption);
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);
- requiredWidth = option.fontMetrics.width(elidedText);
+ requiredWidth = m_customizedFontMetrics.width(elidedText);
}
}
layout.endLayout();
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;
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;
- const QString elidedText = option.fontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
+ const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
textInfo->staticText.setText(elidedText);
}
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;
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;
}
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);