1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "kfileitemlistwidget.h"
22 #include "kfileitemmodel.h"
23 #include "kitemlistview.h"
24 #include "kpixmapmodifier_p.h"
27 #include <KIconEffect>
28 #include <KIconLoader>
30 #include <KStringHandler>
33 #include <QFontMetricsF>
34 #include <QGraphicsSceneResizeEvent>
36 #include <QTextLayout>
39 //#define KFILEITEMLISTWIDGET_DEBUG
41 KFileItemListWidget::KFileItemListWidget(QGraphicsItem
* parent
) :
42 KItemListWidget(parent
),
46 m_dirtyContentRoles(),
47 m_layout(IconsLayout
),
55 m_textsBoundingRect(),
56 m_sortedVisibleRoles(),
58 m_additionalInfoTextColor()
60 for (int i
= 0; i
< TextIdCount
; ++i
) {
61 m_text
[i
].setTextFormat(Qt::PlainText
);
62 m_text
[i
].setPerformanceHint(QStaticText::AggressiveCaching
);
66 KFileItemListWidget::~KFileItemListWidget()
70 void KFileItemListWidget::setLayout(Layout layout
)
72 if (m_layout
!= layout
) {
79 KFileItemListWidget::Layout
KFileItemListWidget::layout() const
84 void KFileItemListWidget::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
86 KItemListWidget::paint(painter
, option
, widget
);
88 painter
->setRenderHint(QPainter::Antialiasing
);
90 if (m_dirtyContent
|| m_dirtyLayout
) {
91 const_cast<KFileItemListWidget
*>(this)->updateCache();
94 if (m_isDir
&& !m_expansionArea
.isEmpty()) {
95 QStyleOption arrowOption
;
96 arrowOption
.rect
= m_expansionArea
.toRect();
97 const QStyle::PrimitiveElement arrow
= data()["isExpanded"].toBool()
98 ? QStyle::PE_IndicatorArrowDown
: QStyle::PE_IndicatorArrowRight
;
99 style()->drawPrimitive(arrow
, &arrowOption
, painter
);
102 const bool isHovered
= (hoverOpacity() > 0.0);
104 const KItemListStyleOption
& itemListStyleOption
= styleOption();
106 // Blend the unhovered and hovered pixmap if the hovering
107 // animation is ongoing
108 if (hoverOpacity() < 1.0) {
109 drawPixmap(painter
, m_pixmap
);
112 const qreal opacity
= painter
->opacity();
113 painter
->setOpacity(hoverOpacity() * opacity
);
114 drawPixmap(painter
, m_hoverPixmap
);
116 // Draw the hover background for the text
117 QRectF textsBoundingRect
= m_textsBoundingRect
;
118 const qreal marginDiff
= itemListStyleOption
.margin
/ 2;
119 textsBoundingRect
.adjust(marginDiff
, marginDiff
, -marginDiff
, -marginDiff
);
120 painter
->setOpacity(hoverOpacity() * opacity
* 0.1);
121 painter
->setPen(Qt::NoPen
);
122 painter
->setBrush(itemListStyleOption
.palette
.text());
123 painter
->drawRoundedRect(textsBoundingRect
, 4, 4);
125 painter
->setOpacity(opacity
);
127 drawPixmap(painter
, m_pixmap
);
130 painter
->setFont(itemListStyleOption
.font
);
131 painter
->setPen(itemListStyleOption
.palette
.text().color());
132 painter
->drawStaticText(m_textPos
[Name
], m_text
[Name
]);
134 painter
->setPen(m_additionalInfoTextColor
);
135 for (int i
= Name
+ 1; i
< TextIdCount
; ++i
) {
136 painter
->drawStaticText(m_textPos
[i
], m_text
[i
]);
139 #ifdef KFILEITEMLISTWIDGET_DEBUG
140 painter
->setPen(Qt::red
);
141 painter
->setBrush(Qt::NoBrush
);
142 painter
->drawText(QPointF(0, itemListStyleOption
.fontMetrics
.height()), QString::number(index()));
143 painter
->drawRect(rect());
147 bool KFileItemListWidget::contains(const QPointF
& point
) const
149 return KItemListWidget::contains(point
) || m_textsBoundingRect
.contains(point
);
152 QRectF
KFileItemListWidget::hoverBoundingRect() const
154 QRectF bounds
= m_hoverPixmapRect
;
155 const qreal margin
= styleOption().margin
;
156 bounds
.adjust(-margin
, -margin
, margin
, margin
);
160 QRectF
KFileItemListWidget::expansionToggleRect() const
162 return m_isDir
? m_expansionArea
: QRectF();
165 void KFileItemListWidget::dataChanged(const QHash
<QByteArray
, QVariant
>& current
,
166 const QSet
<QByteArray
>& roles
)
168 KItemListWidget::dataChanged(current
, roles
);
169 m_dirtyContent
= true;
171 QSet
<QByteArray
> dirtyRoles
;
172 if (roles
.isEmpty()) {
173 dirtyRoles
= visibleRoles().keys().toSet();
174 dirtyRoles
.insert("iconPixmap");
175 dirtyRoles
.insert("iconName");
180 QSetIterator
<QByteArray
> it(dirtyRoles
);
181 while (it
.hasNext()) {
182 const QByteArray
& role
= it
.next();
183 m_dirtyContentRoles
.insert(role
);
187 void KFileItemListWidget::visibleRolesChanged(const QHash
<QByteArray
, int>& current
,
188 const QHash
<QByteArray
, int>& previous
)
190 KItemListWidget::visibleRolesChanged(current
, previous
);
191 m_dirtyLayout
= true;
193 // Cache the roles sorted into m_sortedVisibleRoles:
194 const int visibleRolesCount
= current
.count();
195 m_sortedVisibleRoles
.clear();
196 m_sortedVisibleRoles
.reserve(visibleRolesCount
);
197 for (int i
= 0; i
< visibleRolesCount
; ++i
) {
198 m_sortedVisibleRoles
.append(QByteArray());
201 QHashIterator
<QByteArray
, int> it(current
);
202 while (it
.hasNext()) {
205 const int index
= it
.value();
206 if (index
< 0 || index
>= visibleRolesCount
|| !m_sortedVisibleRoles
.at(index
).isEmpty()) {
207 kWarning() << "The visible roles have an invalid sort order.";
211 const QByteArray
& role
= it
.key();
212 m_sortedVisibleRoles
[index
] = role
;
216 void KFileItemListWidget::visibleRolesSizesChanged(const QHash
<QByteArray
, QSizeF
>& current
,
217 const QHash
<QByteArray
, QSizeF
>& previous
)
219 KItemListWidget::visibleRolesSizesChanged(current
, previous
);
220 m_dirtyLayout
= true;
223 void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption
& current
,
224 const KItemListStyleOption
& previous
)
226 KItemListWidget::styleOptionChanged(current
, previous
);
228 // For the color of the additional info the inactive text color
229 // is not used as this might lead to unreadable text for some color schemes. Instead
230 // the text color is slightly mixed with the background color.
231 const QColor c1
= current
.palette
.text().color();
232 const QColor c2
= current
.palette
.background().color();
234 const int p2
= 100 - p1
;
235 m_additionalInfoTextColor
= QColor((c1
.red() * p1
+ c2
.red() * p2
) / 100,
236 (c1
.green() * p1
+ c2
.green() * p2
) / 100,
237 (c1
.blue() * p1
+ c2
.blue() * p2
) / 100);
239 m_dirtyLayout
= true;
242 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent
* event
)
244 KItemListWidget::resizeEvent(event
);
245 m_dirtyLayout
= true;
248 void KFileItemListWidget::updateCache()
254 m_isDir
= data()["isDir"].toBool();
256 updateExpansionArea();
260 m_dirtyLayout
= false;
261 m_dirtyContent
= false;
262 m_dirtyContentRoles
.clear();
265 void KFileItemListWidget::updateExpansionArea()
267 if (m_layout
== DetailsLayout
) {
268 const QHash
<QByteArray
, QVariant
> values
= data();
269 Q_ASSERT(values
.contains("expansionLevel"));
270 const KItemListStyleOption
& option
= styleOption();
271 const int expansionLevel
= values
.value("expansionLevel", 0).toInt();
273 const qreal widgetHeight
= size().height();
274 const qreal expansionLevelSize
= KIconLoader::SizeSmall
;
275 const qreal x
= option
.margin
+ expansionLevel
* widgetHeight
;
276 const qreal y
= (widgetHeight
- expansionLevelSize
) / 2;
277 m_expansionArea
= QRectF(x
, y
, expansionLevelSize
, expansionLevelSize
);
279 m_expansionArea
= QRectF();
283 void KFileItemListWidget::updatePixmapCache()
285 // Precondition: Requires already updated m_textPos values to calculate
286 // the remaining height when the alignment is vertical.
288 const bool iconOnTop
= (m_layout
== IconsLayout
);
289 const KItemListStyleOption
& option
= styleOption();
290 const int iconHeight
= option
.iconSize
;
292 const QHash
<QByteArray
, QVariant
> values
= data();
293 const QSizeF widgetSize
= size();
295 int scaledIconHeight
= 0;
297 scaledIconHeight
= static_cast<int>(m_textPos
[Name
].y() - 3 * option
.margin
);
299 const int textRowsCount
= (m_layout
== CompactLayout
) ? visibleRoles().count() : 1;
300 const qreal requiredTextHeight
= textRowsCount
* option
.fontMetrics
.height();
301 scaledIconHeight
= (requiredTextHeight
< iconHeight
) ? widgetSize
.height() - 2 * option
.margin
: iconHeight
;
304 bool updatePixmap
= (iconHeight
!= m_pixmap
.height());
305 if (!updatePixmap
&& m_dirtyContent
) {
306 updatePixmap
= m_dirtyContentRoles
.isEmpty()
307 || m_dirtyContentRoles
.contains("iconPixmap")
308 || m_dirtyContentRoles
.contains("iconName");
312 m_pixmap
= values
["iconPixmap"].value
<QPixmap
>();
313 if (m_pixmap
.isNull()) {
314 // Use the icon that fits to the MIME-type
315 QString iconName
= values
["iconName"].toString();
316 if (iconName
.isEmpty()) {
317 // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
318 // use a generic icon as fallback
319 iconName
= QLatin1String("unknown");
321 m_pixmap
= pixmapForIcon(iconName
, iconHeight
);
322 m_hoverPixmapRect
.setSize(m_pixmap
.size());
323 } else if (m_pixmap
.size() != QSize(iconHeight
, iconHeight
)) {
324 // A custom pixmap has been applied. Assure that the pixmap
325 // is scaled to the available size.
326 const bool scale
= m_pixmap
.width() > iconHeight
|| m_pixmap
.height() > iconHeight
||
327 (m_pixmap
.width() < iconHeight
&& m_pixmap
.height() < iconHeight
);
329 KPixmapModifier::scale(m_pixmap
, QSize(iconHeight
, iconHeight
));
331 m_hoverPixmapRect
.setSize(m_pixmap
.size());
333 // To simplify the handling of scaling the original pixmap
334 // will be embedded into a square pixmap.
335 QPixmap
squarePixmap(iconHeight
, iconHeight
);
336 squarePixmap
.fill(Qt::transparent
);
338 QPainter
painter(&squarePixmap
);
340 const int x
= (iconHeight
- m_pixmap
.width()) / 2; // Center horizontally
341 const int y
= iconHeight
- m_pixmap
.height(); // Align on bottom
342 painter
.drawPixmap(x
, y
, m_pixmap
);
344 const int x
= iconHeight
- m_pixmap
.width(); // Align right
345 const int y
= (iconHeight
- m_pixmap
.height()) / 2; // Center vertically
346 painter
.drawPixmap(x
, y
, m_pixmap
);
349 m_pixmap
= squarePixmap
;
351 m_hoverPixmapRect
.setSize(m_pixmap
.size());
354 Q_ASSERT(m_pixmap
.height() == iconHeight
);
357 m_scaledPixmapSize
= QSize(scaledIconHeight
, scaledIconHeight
);
360 m_pixmapPos
.setX((widgetSize
.width() - m_scaledPixmapSize
.width()) / 2);
362 m_pixmapPos
.setX(m_textPos
[Name
].x() - 2 * option
.margin
- scaledIconHeight
);
364 m_pixmapPos
.setY(option
.margin
);
366 // Center the hover rectangle horizontally and align it on bottom
367 const qreal x
= m_pixmapPos
.x() + (m_scaledPixmapSize
.width() - m_hoverPixmapRect
.width()) / 2.0;
368 const qreal y
= m_pixmapPos
.y() + m_scaledPixmapSize
.height() - m_hoverPixmapRect
.height();
369 m_hoverPixmapRect
.moveTopLeft(QPointF(x
, y
));
371 // Prepare the pixmap that is used when the item gets hovered
372 if (option
.state
& QStyle::State_MouseOver
) {
373 m_hoverPixmap
= m_pixmap
;
374 KIconEffect
* effect
= KIconLoader::global()->iconEffect();
375 // In the KIconLoader terminology, active = hover.
376 if (effect
->hasEffect(KIconLoader::Desktop
, KIconLoader::ActiveState
)) {
377 m_hoverPixmap
= effect
->apply(m_pixmap
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
379 m_hoverPixmap
= m_pixmap
;
381 } else if (hoverOpacity() <= 0.0) {
382 // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
383 m_hoverPixmap
= QPixmap();
387 void KFileItemListWidget::updateTextsCache()
389 QTextOption textOption
;
392 textOption
.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere
);
393 textOption
.setAlignment(Qt::AlignHCenter
);
397 textOption
.setAlignment(Qt::AlignLeft
);
398 textOption
.setWrapMode(QTextOption::NoWrap
);
405 for (int i
= 0; i
< TextIdCount
; ++i
) {
406 m_text
[i
].setText(QString());
407 m_text
[i
].setTextOption(textOption
);
411 case IconsLayout
: updateIconsLayoutTextCache(); break;
412 case CompactLayout
: updateCompactLayoutTextCache(); break;
413 case DetailsLayout
: updateDetailsLayoutTextCache(); break;
414 default: Q_ASSERT(false); break;
418 void KFileItemListWidget::updateIconsLayoutTextCache()
425 // might get wrapped above
430 const QHash
<QByteArray
, QVariant
> values
= data();
432 const KItemListStyleOption
& option
= styleOption();
433 const qreal maxWidth
= size().width() - 2 * option
.margin
;
434 const qreal widgetHeight
= size().height();
435 const qreal fontHeight
= option
.fontMetrics
.height();
437 // Initialize properties for the "name" role. It will be used as anchor
438 // for initializing the position of the other roles.
439 m_text
[Name
].setText(KStringHandler::preProcessWrap(values
["name"].toString()));
441 // Calculate the number of lines required for the name and the required width
442 int textLinesCountForName
= 0;
443 qreal requiredWidthForName
= 0;
446 QTextLayout
layout(m_text
[Name
].text(), option
.font
);
447 layout
.setTextOption(m_text
[Name
].textOption());
448 layout
.beginLayout();
449 while ((line
= layout
.createLine()).isValid()) {
450 line
.setLineWidth(maxWidth
);
451 requiredWidthForName
= qMax(requiredWidthForName
, line
.naturalTextWidth());
452 ++textLinesCountForName
;
456 // Use one line for each additional information
457 int textLinesCount
= textLinesCountForName
;
458 const int additionalRolesCount
= qMax(visibleRoles().count() - 1, 0);
459 textLinesCount
+= additionalRolesCount
;
461 m_text
[Name
].setTextWidth(maxWidth
);
462 m_textPos
[Name
] = QPointF(option
.margin
, widgetHeight
- textLinesCount
* fontHeight
- option
.margin
);
463 m_textsBoundingRect
= QRectF(option
.margin
+ (maxWidth
- requiredWidthForName
) / 2,
465 requiredWidthForName
,
466 m_text
[Name
].size().height());
468 // Calculate the position for each additional information
469 qreal y
= m_textPos
[Name
].y() + textLinesCountForName
* fontHeight
;
470 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
471 const TextId textId
= roleTextId(role
);
472 if (textId
== Name
) {
476 const QString text
= roleText(textId
, values
[role
]);
477 m_text
[textId
].setText(text
);
479 qreal requiredWidth
= 0;
481 QTextLayout
layout(text
, option
.font
);
482 layout
.setTextOption(m_text
[textId
].textOption());
483 layout
.beginLayout();
484 QTextLine textLine
= layout
.createLine();
485 if (textLine
.isValid()) {
486 textLine
.setLineWidth(maxWidth
);
487 requiredWidth
= textLine
.naturalTextWidth();
488 if (textLine
.textLength() < text
.length()) {
489 // TODO: QFontMetrics::elidedText() works different regarding the given width
490 // in comparison to QTextLine::setLineWidth(). It might happen that the text does
491 // not get elided although it does not fit into the given width. As workaround
492 // the margin is substracted.
493 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
- option
.margin
);
494 m_text
[textId
].setText(elidedText
);
499 m_textPos
[textId
] = QPointF(option
.margin
, y
);
500 m_text
[textId
].setTextWidth(maxWidth
);
502 const QRectF
textBoundingRect(option
.margin
+ (maxWidth
- requiredWidth
) / 2, y
, requiredWidth
, fontHeight
);
503 m_textsBoundingRect
|= textBoundingRect
;
508 // Add a margin to the text bounding rectangle
509 const qreal margin
= option
.margin
;
510 m_textsBoundingRect
.adjust(-margin
, -margin
, margin
, margin
);
513 void KFileItemListWidget::updateCompactLayoutTextCache()
515 // +------+ Name role
516 // | Icon | Additional role 1
517 // +------+ Additional role 2
519 const QHash
<QByteArray
, QVariant
> values
= data();
521 const KItemListStyleOption
& option
= styleOption();
522 const qreal widgetHeight
= size().height();
523 const qreal fontHeight
= option
.fontMetrics
.height();
524 const qreal textLinesHeight
= qMax(visibleRoles().count(), 1) * fontHeight
;
525 const int scaledIconSize
= (textLinesHeight
< option
.iconSize
) ? widgetHeight
- 2 * option
.margin
: option
.iconSize
;
527 qreal maximumRequiredTextWidth
= 0;
528 const qreal x
= option
.margin
* 3 + scaledIconSize
;
529 qreal y
= (widgetHeight
- textLinesHeight
) / 2;
530 const qreal maxWidth
= size().width() - x
- option
.margin
;
531 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
532 const TextId textId
= roleTextId(role
);
534 const QString text
= roleText(textId
, values
[role
]);
535 m_text
[textId
].setText(text
);
537 qreal requiredWidth
= option
.fontMetrics
.width(text
);
538 if (requiredWidth
> maxWidth
) {
539 requiredWidth
= maxWidth
;
540 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
);
541 m_text
[textId
].setText(elidedText
);
544 m_textPos
[textId
] = QPointF(x
, y
);
545 m_text
[textId
].setTextWidth(maxWidth
);
547 maximumRequiredTextWidth
= qMax(maximumRequiredTextWidth
, requiredWidth
);
552 m_textsBoundingRect
= QRectF(x
- option
.margin
, 0, maximumRequiredTextWidth
+ 2 * option
.margin
, widgetHeight
);
555 void KFileItemListWidget::updateDetailsLayoutTextCache()
557 // Precondition: Requires already updated m_expansionArea
558 // to determine the left position.
561 // | Icon | Name role Additional role 1 Additional role 2
563 m_textsBoundingRect
= QRectF();
565 const KItemListStyleOption
& option
= styleOption();
566 const QHash
<QByteArray
, QVariant
> values
= data();
568 const qreal widgetHeight
= size().height();
569 const int scaledIconSize
= widgetHeight
- 2 * option
.margin
;
570 const int fontHeight
= option
.fontMetrics
.height();
572 qreal x
= m_expansionArea
.right() + option
.margin
* 3 + scaledIconSize
;
573 const qreal y
= qMax(qreal(option
.margin
), (widgetHeight
- fontHeight
) / 2);
575 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
576 const TextId textId
= roleTextId(role
);
578 const QString text
= roleText(textId
, values
[role
]);
579 m_text
[textId
].setText(text
);
581 const qreal requiredWidth
= option
.fontMetrics
.width(text
);
582 m_textPos
[textId
] = QPointF(x
, y
);
584 const qreal columnWidth
= visibleRolesSizes().value(role
, QSizeF(0, 0)).width();
589 m_textsBoundingRect
= QRectF(m_textPos
[textId
].x() - option
.margin
, 0,
590 requiredWidth
+ 2 * option
.margin
, size().height());
592 // The column after the name should always be aligned on the same x-position independent
593 // from the expansion-level shown in the name column
594 x
-= m_expansionArea
.right();
598 // The values for the size should be right aligned
599 m_textPos
[textId
].rx() += columnWidth
- requiredWidth
- 2 * option
.margin
;
608 QString
KFileItemListWidget::roleText(TextId textId
, const QVariant
& roleValue
) const
620 text
= roleValue
.toString();
624 if (data().value("isDir").toBool()) {
625 // The item represents a directory. Show the number of sub directories
626 // instead of the file size of the directory.
627 if (!roleValue
.isNull()) {
628 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
629 text
= i18ncp("@item:intable", "%1 item", "%1 items", size
);
632 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
633 text
= KIO::convertSize(size
);
639 const QDateTime dateTime
= roleValue
.toDateTime();
640 text
= KGlobal::locale()->formatDateTime(dateTime
);
652 void KFileItemListWidget::drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
)
654 const bool isHiddenItem
= m_text
[Name
].text().startsWith(QLatin1Char('.'));
657 opacity
= painter
->opacity();
658 painter
->setOpacity(opacity
* 0.3);
661 if (m_scaledPixmapSize
!= pixmap
.size()) {
662 QPixmap scaledPixmap
= pixmap
;
663 KPixmapModifier::scale(scaledPixmap
, m_scaledPixmapSize
);
664 painter
->drawPixmap(m_pixmapPos
, scaledPixmap
);
666 #ifdef KFILEITEMLISTWIDGET_DEBUG
667 painter
->setPen(Qt::green
);
668 painter
->drawRect(QRectF(m_pixmapPos
, QSizeF(scaledPixmap
.size())));
671 painter
->drawPixmap(m_pixmapPos
, pixmap
);
675 painter
->setOpacity(opacity
);
679 QPixmap
KFileItemListWidget::pixmapForIcon(const QString
& name
, int size
)
681 const KIcon
icon(name
);
684 if (size
<= KIconLoader::SizeSmall
) {
685 requestedSize
= KIconLoader::SizeSmall
;
686 } else if (size
<= KIconLoader::SizeSmallMedium
) {
687 requestedSize
= KIconLoader::SizeSmallMedium
;
688 } else if (size
<= KIconLoader::SizeMedium
) {
689 requestedSize
= KIconLoader::SizeMedium
;
690 } else if (size
<= KIconLoader::SizeLarge
) {
691 requestedSize
= KIconLoader::SizeLarge
;
692 } else if (size
<= KIconLoader::SizeHuge
) {
693 requestedSize
= KIconLoader::SizeHuge
;
694 } else if (size
<= KIconLoader::SizeEnormous
) {
695 requestedSize
= KIconLoader::SizeEnormous
;
696 } else if (size
<= KIconLoader::SizeEnormous
* 2) {
697 requestedSize
= KIconLoader::SizeEnormous
* 2;
699 requestedSize
= size
;
702 QPixmap pixmap
= icon
.pixmap(requestedSize
, requestedSize
);
703 if (requestedSize
!= size
) {
704 KPixmapModifier::scale(pixmap
, QSize(size
, size
));
710 KFileItemListWidget::TextId
KFileItemListWidget::roleTextId(const QByteArray
& role
)
712 static QHash
<QByteArray
, TextId
> rolesHash
;
713 if (rolesHash
.isEmpty()) {
714 rolesHash
.insert("name", Name
);
715 rolesHash
.insert("size", Size
);
716 rolesHash
.insert("date", Date
);
717 rolesHash
.insert("permissions", Permissions
);
718 rolesHash
.insert("owner", Owner
);
719 rolesHash
.insert("group", Group
);
720 rolesHash
.insert("type", Type
);
721 rolesHash
.insert("destination", Destination
);
722 rolesHash
.insert("path", Path
);
725 return rolesHash
.value(role
);
728 #include "kfileitemlistwidget.moc"