- // Add a margin to the text rectangle
- m_textRect.adjust(-margin, -margin, margin, margin);
-}
-
-void KFileItemListWidget::updateCompactLayoutTextCache()
-{
- // +------+ Name role
- // | Icon | Additional role 1
- // +------+ Additional role 2
-
- const QHash<QByteArray, QVariant> values = data();
-
- const KItemListStyleOption& option = styleOption();
- const qreal widgetHeight = size().height();
- const qreal fontHeight = option.fontMetrics.height();
- const qreal textLinesHeight = qMax(visibleRoles().count(), 1) * fontHeight;
- const int scaledIconSize = (textLinesHeight < option.iconSize) ? widgetHeight - 2 * option.margin : option.iconSize;
-
- qreal maximumRequiredTextWidth = 0;
- const qreal x = option.margin * 3 + scaledIconSize;
- qreal y = (widgetHeight - textLinesHeight) / 2;
- const qreal maxWidth = size().width() - x - option.margin;
- foreach (const QByteArray& role, m_sortedVisibleRoles) {
- const TextId textId = roleTextId(role);
-
- const QString text = roleText(role, values);
- m_text[textId].setText(text);
-
- qreal requiredWidth = option.fontMetrics.width(text);
- if (requiredWidth > maxWidth) {
- requiredWidth = maxWidth;
- const QString elidedText = option.fontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
- m_text[textId].setText(elidedText);
- }
-
- m_textPos[textId] = QPointF(x, y);
- m_text[textId].setTextWidth(maxWidth);
-
- maximumRequiredTextWidth = qMax(maximumRequiredTextWidth, requiredWidth);
-
- y += fontHeight;
- }
-
- m_textRect = QRectF(x - option.margin, 0, maximumRequiredTextWidth + 2 * option.margin, widgetHeight);
-}
-
-void KFileItemListWidget::updateDetailsLayoutTextCache()
-{
- // Precondition: Requires already updated m_expansionArea
- // to determine the left position.
-
- // +------+
- // | Icon | Name role Additional role 1 Additional role 2
- // +------+
- m_textRect = QRectF();
-
- const KItemListStyleOption& option = styleOption();
- const QHash<QByteArray, QVariant> values = data();
-
- const qreal widgetHeight = size().height();
- const int scaledIconSize = widgetHeight - 2 * option.margin;
- const int fontHeight = option.fontMetrics.height();
-
- const qreal columnMargin = option.margin * 3;
- const qreal firstColumnInc = m_expansionArea.right() + option.margin * 2 + scaledIconSize;
- qreal x = firstColumnInc;
- const qreal y = qMax(qreal(option.margin), (widgetHeight - fontHeight) / 2);
-
- foreach (const QByteArray& role, m_sortedVisibleRoles) {
- const TextId textId = roleTextId(role);
-
- 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);
- const qreal columnWidth = visibleRolesSizes().value(role, QSizeF(0, 0)).width();
- qreal availableTextWidth = columnWidth - 2 * columnMargin;
- if (textId == Name) {
- availableTextWidth -= firstColumnInc;
- }
-
- if (requiredWidth > availableTextWidth) {
- text = option.fontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
- requiredWidth = option.fontMetrics.width(text);
- }
-
- m_text[textId].setText(text);
- m_textPos[textId] = QPointF(x + columnMargin, y);
- x += columnWidth;
-
- switch (textId) {
- case Name: {
- m_textRect = QRectF(m_textPos[textId].x() - option.margin, 0,
- requiredWidth + 2 * option.margin, size().height());
-
- // The column after the name should always be aligned on the same x-position independent
- // from the expansion-level shown in the name column
- x -= firstColumnInc;
- break;
- }
- case Size:
- // The values for the size should be right aligned
- m_textPos[textId].rx() += columnWidth - requiredWidth - 2 * columnMargin;
- break;
-
- default:
- break;
- }
- }
-}
-
-void KFileItemListWidget::updateAdditionalInfoTextColor()
-{
- QColor c1;
- if (m_customTextColor.isValid()) {
- c1 = m_customTextColor;
- } else if (isSelected() && m_layout != DetailsLayout) {
- c1 = styleOption().palette.highlightedText().color();
- } else {
- c1 = styleOption().palette.text().color();
- }
-
- // For the color of the additional info the inactive text color
- // is not used as this might lead to unreadable text for some color schemes. Instead
- // the text color c1 is slightly mixed with the background color.
- const QColor c2 = styleOption().palette.base().color();
- const int p1 = 70;
- const int p2 = 100 - p1;
- m_additionalInfoTextColor = QColor((c1.red() * p1 + c2.red() * p2) / 100,
- (c1.green() * p1 + c2.green() * p2) / 100,
- (c1.blue() * p1 + c2.blue() * p2) / 100);
-}
-
-void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
-{
- if (m_scaledPixmapSize != pixmap.size()) {
- QPixmap scaledPixmap = pixmap;
- KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize);
- painter->drawPixmap(m_pixmapPos, scaledPixmap);
-
-#ifdef KFILEITEMLISTWIDGET_DEBUG
- painter->setPen(Qt::blue);
- painter->drawRect(QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize)));
-#endif
- } else {
- painter->drawPixmap(m_pixmapPos, pixmap);
- }
-}
-
-QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
-{
- const KIcon icon(name);
-
- int requestedSize;
- if (size <= KIconLoader::SizeSmall) {
- requestedSize = KIconLoader::SizeSmall;
- } else if (size <= KIconLoader::SizeSmallMedium) {
- requestedSize = KIconLoader::SizeSmallMedium;
- } else if (size <= KIconLoader::SizeMedium) {
- requestedSize = KIconLoader::SizeMedium;
- } else if (size <= KIconLoader::SizeLarge) {
- requestedSize = KIconLoader::SizeLarge;
- } else if (size <= KIconLoader::SizeHuge) {
- requestedSize = KIconLoader::SizeHuge;
- } else if (size <= KIconLoader::SizeEnormous) {
- requestedSize = KIconLoader::SizeEnormous;
- } else if (size <= KIconLoader::SizeEnormous * 2) {
- requestedSize = KIconLoader::SizeEnormous * 2;
- } else {
- requestedSize = size;
- }
-
- QPixmap pixmap = icon.pixmap(requestedSize, requestedSize);
- if (requestedSize != size) {
- KPixmapModifier::scale(pixmap, QSize(size, size));
- }
-
- return pixmap;
-}
-
-KFileItemListWidget::TextId KFileItemListWidget::roleTextId(const QByteArray& role)
-{
- static QHash<QByteArray, TextId> rolesHash;
- if (rolesHash.isEmpty()) {
- rolesHash.insert("name", Name);
- rolesHash.insert("size", Size);
- rolesHash.insert("date", Date);
- rolesHash.insert("permissions", Permissions);
- rolesHash.insert("owner", Owner);
- rolesHash.insert("group", Group);
- rolesHash.insert("type", Type);
- rolesHash.insert("destination", Destination);
- rolesHash.insert("path", Path);
- }
-
- return rolesHash.value(role);
-}
-
-void KFileItemListWidget::applyCutEffect(QPixmap& pixmap)
-{
- KIconEffect* effect = KIconLoader::global()->iconEffect();
- pixmap = effect->apply(pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
-}
-
-void KFileItemListWidget::applyHiddenEffect(QPixmap& pixmap)
-{
- KIconEffect::semiTransparent(pixmap);