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 <QStyleOption>
37 #include <QTextLayout>
40 //#define KFILEITEMLISTWIDGET_DEBUG
42 KFileItemListWidget::KFileItemListWidget(QGraphicsItem
* parent
) :
43 KItemListWidget(parent
),
47 m_dirtyContentRoles(),
48 m_layout(IconsLayout
),
57 m_sortedVisibleRoles(),
60 m_additionalInfoTextColor(),
63 for (int i
= 0; i
< TextIdCount
; ++i
) {
64 m_text
[i
].setTextFormat(Qt::PlainText
);
65 m_text
[i
].setPerformanceHint(QStaticText::AggressiveCaching
);
69 KFileItemListWidget::~KFileItemListWidget()
73 void KFileItemListWidget::setLayout(Layout layout
)
75 if (m_layout
!= layout
) {
82 KFileItemListWidget::Layout
KFileItemListWidget::layout() const
87 void KFileItemListWidget::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
89 KItemListWidget::paint(painter
, option
, widget
);
91 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
93 // Draw expansion toggle '>' or 'V'
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 KItemListStyleOption
& itemListStyleOption
= styleOption();
104 // Blend the unhovered and hovered pixmap if the hovering
105 // animation is ongoing
106 if (hoverOpacity() < 1.0) {
107 drawPixmap(painter
, m_pixmap
);
110 const qreal opacity
= painter
->opacity();
111 painter
->setOpacity(hoverOpacity() * opacity
);
112 drawPixmap(painter
, m_hoverPixmap
);
113 painter
->setOpacity(opacity
);
115 drawPixmap(painter
, m_pixmap
);
118 painter
->setFont(itemListStyleOption
.font
);
119 painter
->setPen(textColor());
120 painter
->drawStaticText(m_textPos
[Name
], m_text
[Name
]);
122 painter
->setPen(m_additionalInfoTextColor
);
123 painter
->setFont(itemListStyleOption
.font
);
124 for (int i
= Name
+ 1; i
< TextIdCount
; ++i
) {
125 painter
->drawStaticText(m_textPos
[i
], m_text
[i
]);
128 #ifdef KFILEITEMLISTWIDGET_DEBUG
129 painter
->setPen(Qt::red
);
130 painter
->setBrush(Qt::NoBrush
);
131 painter
->drawText(QPointF(0, itemListStyleOption
.fontMetrics
.height()), QString::number(index()));
132 painter
->drawRect(rect());
136 QRectF
KFileItemListWidget::iconBoundingRect() const
138 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
140 QRectF bounds
= m_hoverPixmapRect
;
141 const qreal margin
= styleOption().margin
;
142 bounds
.adjust(-margin
, -margin
, margin
, margin
);
146 QRectF
KFileItemListWidget::textBoundingRect() const
148 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
149 return m_textBoundingRect
;
152 QRectF
KFileItemListWidget::expansionToggleRect() const
154 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
155 return m_isDir
? m_expansionArea
: QRectF();
158 void KFileItemListWidget::invalidateCache()
160 m_dirtyLayout
= true;
161 m_dirtyContent
= true;
164 void KFileItemListWidget::refreshCache()
168 void KFileItemListWidget::setTextColor(const QColor
& color
)
170 if (color
!= m_customTextColor
) {
171 m_customTextColor
= color
;
172 updateAdditionalInfoTextColor();
177 QColor
KFileItemListWidget::textColor() const
179 return m_customTextColor
.isValid() ? m_customTextColor
: styleOption().palette
.text().color();
182 void KFileItemListWidget::setOverlay(const QPixmap
& overlay
)
185 m_dirtyContent
= true;
189 QPixmap
KFileItemListWidget::overlay() const
194 void KFileItemListWidget::dataChanged(const QHash
<QByteArray
, QVariant
>& current
,
195 const QSet
<QByteArray
>& roles
)
197 KItemListWidget::dataChanged(current
, roles
);
198 m_dirtyContent
= true;
200 QSet
<QByteArray
> dirtyRoles
;
201 if (roles
.isEmpty()) {
202 dirtyRoles
= visibleRoles().keys().toSet();
203 dirtyRoles
.insert("iconPixmap");
204 dirtyRoles
.insert("iconName");
209 QSetIterator
<QByteArray
> it(dirtyRoles
);
210 while (it
.hasNext()) {
211 const QByteArray
& role
= it
.next();
212 m_dirtyContentRoles
.insert(role
);
216 void KFileItemListWidget::visibleRolesChanged(const QHash
<QByteArray
, int>& current
,
217 const QHash
<QByteArray
, int>& previous
)
219 KItemListWidget::visibleRolesChanged(current
, previous
);
220 m_dirtyLayout
= true;
222 // Cache the roles sorted into m_sortedVisibleRoles:
223 const int visibleRolesCount
= current
.count();
224 m_sortedVisibleRoles
.clear();
225 m_sortedVisibleRoles
.reserve(visibleRolesCount
);
226 for (int i
= 0; i
< visibleRolesCount
; ++i
) {
227 m_sortedVisibleRoles
.append(QByteArray());
230 QHashIterator
<QByteArray
, int> it(current
);
231 while (it
.hasNext()) {
234 const int index
= it
.value();
235 if (index
< 0 || index
>= visibleRolesCount
|| !m_sortedVisibleRoles
.at(index
).isEmpty()) {
236 kWarning() << "The visible roles have an invalid sort order.";
240 const QByteArray
& role
= it
.key();
241 m_sortedVisibleRoles
[index
] = role
;
245 void KFileItemListWidget::visibleRolesSizesChanged(const QHash
<QByteArray
, QSizeF
>& current
,
246 const QHash
<QByteArray
, QSizeF
>& previous
)
248 KItemListWidget::visibleRolesSizesChanged(current
, previous
);
249 m_dirtyLayout
= true;
252 void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption
& current
,
253 const KItemListStyleOption
& previous
)
255 KItemListWidget::styleOptionChanged(current
, previous
);
256 updateAdditionalInfoTextColor();
257 m_dirtyLayout
= true;
260 void KFileItemListWidget::hoveredChanged(bool hovered
)
263 m_dirtyLayout
= true;
266 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent
* event
)
268 KItemListWidget::resizeEvent(event
);
269 m_dirtyLayout
= true;
272 void KFileItemListWidget::triggerCacheRefreshing()
274 if ((!m_dirtyContent
&& !m_dirtyLayout
) || index() < 0) {
280 m_isDir
= data()["isDir"].toBool();
282 updateExpansionArea();
286 m_dirtyLayout
= false;
287 m_dirtyContent
= false;
288 m_dirtyContentRoles
.clear();
291 void KFileItemListWidget::updateExpansionArea()
293 if (m_layout
== DetailsLayout
) {
294 const QHash
<QByteArray
, QVariant
> values
= data();
295 Q_ASSERT(values
.contains("expansionLevel"));
296 const KItemListStyleOption
& option
= styleOption();
297 const int expansionLevel
= values
.value("expansionLevel", 0).toInt();
299 const qreal widgetHeight
= size().height();
300 const qreal expansionLevelSize
= KIconLoader::SizeSmall
;
301 const qreal x
= option
.margin
+ expansionLevel
* widgetHeight
;
302 const qreal y
= (widgetHeight
- expansionLevelSize
) / 2;
303 m_expansionArea
= QRectF(x
, y
, expansionLevelSize
, expansionLevelSize
);
305 m_expansionArea
= QRectF();
309 void KFileItemListWidget::updatePixmapCache()
311 // Precondition: Requires already updated m_textPos values to calculate
312 // the remaining height when the alignment is vertical.
314 const bool iconOnTop
= (m_layout
== IconsLayout
);
315 const KItemListStyleOption
& option
= styleOption();
316 const int iconHeight
= option
.iconSize
;
318 const QHash
<QByteArray
, QVariant
> values
= data();
319 const QSizeF widgetSize
= size();
321 int scaledIconHeight
= 0;
323 scaledIconHeight
= static_cast<int>(m_textPos
[Name
].y() - 3 * option
.margin
);
325 const int textRowsCount
= (m_layout
== CompactLayout
) ? visibleRoles().count() : 1;
326 const qreal requiredTextHeight
= textRowsCount
* option
.fontMetrics
.height();
327 scaledIconHeight
= (requiredTextHeight
< iconHeight
) ? widgetSize
.height() - 2 * option
.margin
: iconHeight
;
330 bool updatePixmap
= (iconHeight
!= m_pixmap
.height());
331 if (!updatePixmap
&& m_dirtyContent
) {
332 updatePixmap
= m_dirtyContentRoles
.isEmpty()
333 || m_dirtyContentRoles
.contains("iconPixmap")
334 || m_dirtyContentRoles
.contains("iconName");
338 m_pixmap
= values
["iconPixmap"].value
<QPixmap
>();
339 if (m_pixmap
.isNull()) {
340 // Use the icon that fits to the MIME-type
341 QString iconName
= values
["iconName"].toString();
342 if (iconName
.isEmpty()) {
343 // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
344 // use a generic icon as fallback
345 iconName
= QLatin1String("unknown");
347 m_pixmap
= pixmapForIcon(iconName
, iconHeight
);
348 m_hoverPixmapRect
.setSize(m_pixmap
.size());
349 } else if (m_pixmap
.size() != QSize(iconHeight
, iconHeight
)) {
350 // A custom pixmap has been applied. Assure that the pixmap
351 // is scaled to the available size.
352 const bool scale
= m_pixmap
.width() > iconHeight
|| m_pixmap
.height() > iconHeight
||
353 (m_pixmap
.width() < iconHeight
&& m_pixmap
.height() < iconHeight
);
355 KPixmapModifier::scale(m_pixmap
, QSize(iconHeight
, iconHeight
));
357 m_hoverPixmapRect
.setSize(m_pixmap
.size());
359 // To simplify the handling of scaling the original pixmap
360 // will be embedded into a square pixmap.
361 QPixmap
squarePixmap(iconHeight
, iconHeight
);
362 squarePixmap
.fill(Qt::transparent
);
364 QPainter
painter(&squarePixmap
);
366 const int x
= (iconHeight
- m_pixmap
.width()) / 2; // Center horizontally
367 const int y
= iconHeight
- m_pixmap
.height(); // Align on bottom
368 painter
.drawPixmap(x
, y
, m_pixmap
);
370 const int x
= iconHeight
- m_pixmap
.width(); // Align right
371 const int y
= (iconHeight
- m_pixmap
.height()) / 2; // Center vertically
372 painter
.drawPixmap(x
, y
, m_pixmap
);
375 m_pixmap
= squarePixmap
;
377 m_hoverPixmapRect
.setSize(m_pixmap
.size());
380 Q_ASSERT(m_pixmap
.height() == iconHeight
);
382 if (!m_overlay
.isNull()) {
383 QPainter
painter(&m_pixmap
);
384 painter
.drawPixmap(0, m_pixmap
.height() - m_overlay
.height(), m_overlay
);
387 m_scaledPixmapSize
= QSize(scaledIconHeight
, scaledIconHeight
);
390 m_pixmapPos
.setX((widgetSize
.width() - m_scaledPixmapSize
.width()) / 2);
392 m_pixmapPos
.setX(m_textPos
[Name
].x() - 2 * option
.margin
- scaledIconHeight
);
394 m_pixmapPos
.setY(option
.margin
);
396 // Center the hover rectangle horizontally and align it on bottom
397 const qreal x
= m_pixmapPos
.x() + (m_scaledPixmapSize
.width() - m_hoverPixmapRect
.width()) / 2.0;
398 const qreal y
= m_pixmapPos
.y() + m_scaledPixmapSize
.height() - m_hoverPixmapRect
.height();
399 m_hoverPixmapRect
.moveTopLeft(QPointF(x
, y
));
401 // Prepare the pixmap that is used when the item gets hovered
403 m_hoverPixmap
= m_pixmap
;
404 KIconEffect
* effect
= KIconLoader::global()->iconEffect();
405 // In the KIconLoader terminology, active = hover.
406 if (effect
->hasEffect(KIconLoader::Desktop
, KIconLoader::ActiveState
)) {
407 m_hoverPixmap
= effect
->apply(m_pixmap
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
409 m_hoverPixmap
= m_pixmap
;
411 } else if (hoverOpacity() <= 0.0) {
412 // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
413 m_hoverPixmap
= QPixmap();
417 void KFileItemListWidget::updateTextsCache()
419 QTextOption textOption
;
422 textOption
.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere
);
423 textOption
.setAlignment(Qt::AlignHCenter
);
427 textOption
.setAlignment(Qt::AlignLeft
);
428 textOption
.setWrapMode(QTextOption::NoWrap
);
435 for (int i
= 0; i
< TextIdCount
; ++i
) {
436 m_text
[i
].setText(QString());
437 m_text
[i
].setTextOption(textOption
);
441 case IconsLayout
: updateIconsLayoutTextCache(); break;
442 case CompactLayout
: updateCompactLayoutTextCache(); break;
443 case DetailsLayout
: updateDetailsLayoutTextCache(); break;
444 default: Q_ASSERT(false); break;
448 void KFileItemListWidget::updateIconsLayoutTextCache()
455 // might get wrapped above
460 const QHash
<QByteArray
, QVariant
> values
= data();
462 const KItemListStyleOption
& option
= styleOption();
463 const qreal maxWidth
= size().width() - 2 * option
.margin
;
464 const qreal widgetHeight
= size().height();
465 const qreal fontHeight
= option
.fontMetrics
.height();
467 // Initialize properties for the "name" role. It will be used as anchor
468 // for initializing the position of the other roles.
469 m_text
[Name
].setText(KStringHandler::preProcessWrap(values
["name"].toString()));
471 // Calculate the number of lines required for the name and the required width
472 int textLinesCountForName
= 0;
473 qreal requiredWidthForName
= 0;
476 QTextLayout
layout(m_text
[Name
].text(), option
.font
);
477 layout
.setTextOption(m_text
[Name
].textOption());
478 layout
.beginLayout();
479 while ((line
= layout
.createLine()).isValid()) {
480 line
.setLineWidth(maxWidth
);
481 requiredWidthForName
= qMax(requiredWidthForName
, line
.naturalTextWidth());
482 ++textLinesCountForName
;
486 // Use one line for each additional information
487 int textLinesCount
= textLinesCountForName
;
488 const int additionalRolesCount
= qMax(visibleRoles().count() - 1, 0);
489 textLinesCount
+= additionalRolesCount
;
491 m_text
[Name
].setTextWidth(maxWidth
);
492 m_textPos
[Name
] = QPointF(option
.margin
, widgetHeight
- textLinesCount
* fontHeight
- option
.margin
);
493 m_textBoundingRect
= QRectF(option
.margin
+ (maxWidth
- requiredWidthForName
) / 2,
495 requiredWidthForName
,
496 m_text
[Name
].size().height());
498 // Calculate the position for each additional information
499 qreal y
= m_textPos
[Name
].y() + textLinesCountForName
* fontHeight
;
500 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
501 const TextId textId
= roleTextId(role
);
502 if (textId
== Name
) {
506 const QString text
= roleText(textId
, values
[role
]);
507 m_text
[textId
].setText(text
);
509 qreal requiredWidth
= 0;
511 QTextLayout
layout(text
, option
.font
);
512 layout
.setTextOption(m_text
[textId
].textOption());
513 layout
.beginLayout();
514 QTextLine textLine
= layout
.createLine();
515 if (textLine
.isValid()) {
516 textLine
.setLineWidth(maxWidth
);
517 requiredWidth
= textLine
.naturalTextWidth();
518 if (textLine
.textLength() < text
.length()) {
519 // TODO: QFontMetrics::elidedText() works different regarding the given width
520 // in comparison to QTextLine::setLineWidth(). It might happen that the text does
521 // not get elided although it does not fit into the given width. As workaround
522 // the margin is substracted.
523 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
- option
.margin
);
524 m_text
[textId
].setText(elidedText
);
529 m_textPos
[textId
] = QPointF(option
.margin
, y
);
530 m_text
[textId
].setTextWidth(maxWidth
);
532 const QRectF
textBoundingRect(option
.margin
+ (maxWidth
- requiredWidth
) / 2, y
, requiredWidth
, fontHeight
);
533 m_textBoundingRect
|= textBoundingRect
;
538 // Add a margin to the text bounding rectangle
539 const qreal margin
= option
.margin
;
540 m_textBoundingRect
.adjust(-margin
, -margin
, margin
, margin
);
543 void KFileItemListWidget::updateCompactLayoutTextCache()
545 // +------+ Name role
546 // | Icon | Additional role 1
547 // +------+ Additional role 2
549 const QHash
<QByteArray
, QVariant
> values
= data();
551 const KItemListStyleOption
& option
= styleOption();
552 const qreal widgetHeight
= size().height();
553 const qreal fontHeight
= option
.fontMetrics
.height();
554 const qreal textLinesHeight
= qMax(visibleRoles().count(), 1) * fontHeight
;
555 const int scaledIconSize
= (textLinesHeight
< option
.iconSize
) ? widgetHeight
- 2 * option
.margin
: option
.iconSize
;
557 qreal maximumRequiredTextWidth
= 0;
558 const qreal x
= option
.margin
* 3 + scaledIconSize
;
559 qreal y
= (widgetHeight
- textLinesHeight
) / 2;
560 const qreal maxWidth
= size().width() - x
- option
.margin
;
561 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
562 const TextId textId
= roleTextId(role
);
564 const QString text
= roleText(textId
, values
[role
]);
565 m_text
[textId
].setText(text
);
567 qreal requiredWidth
= option
.fontMetrics
.width(text
);
568 if (requiredWidth
> maxWidth
) {
569 requiredWidth
= maxWidth
;
570 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
);
571 m_text
[textId
].setText(elidedText
);
574 m_textPos
[textId
] = QPointF(x
, y
);
575 m_text
[textId
].setTextWidth(maxWidth
);
577 maximumRequiredTextWidth
= qMax(maximumRequiredTextWidth
, requiredWidth
);
582 m_textBoundingRect
= QRectF(x
- option
.margin
, 0, maximumRequiredTextWidth
+ 2 * option
.margin
, widgetHeight
);
585 void KFileItemListWidget::updateDetailsLayoutTextCache()
587 // Precondition: Requires already updated m_expansionArea
588 // to determine the left position.
591 // | Icon | Name role Additional role 1 Additional role 2
593 m_textBoundingRect
= QRectF();
595 const KItemListStyleOption
& option
= styleOption();
596 const QHash
<QByteArray
, QVariant
> values
= data();
598 const qreal widgetHeight
= size().height();
599 const int scaledIconSize
= widgetHeight
- 2 * option
.margin
;
600 const int fontHeight
= option
.fontMetrics
.height();
602 qreal x
= m_expansionArea
.right() + option
.margin
* 3 + scaledIconSize
;
603 const qreal y
= qMax(qreal(option
.margin
), (widgetHeight
- fontHeight
) / 2);
605 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
606 const TextId textId
= roleTextId(role
);
608 const QString text
= roleText(textId
, values
[role
]);
609 m_text
[textId
].setText(text
);
611 const qreal requiredWidth
= option
.fontMetrics
.width(text
);
612 m_textPos
[textId
] = QPointF(x
, y
);
614 const qreal columnWidth
= visibleRolesSizes().value(role
, QSizeF(0, 0)).width();
619 m_textBoundingRect
= QRectF(m_textPos
[textId
].x() - option
.margin
, 0,
620 requiredWidth
+ 2 * option
.margin
, size().height());
622 // The column after the name should always be aligned on the same x-position independent
623 // from the expansion-level shown in the name column
624 x
-= m_expansionArea
.right();
628 // The values for the size should be right aligned
629 m_textPos
[textId
].rx() += columnWidth
- requiredWidth
- 2 * option
.margin
;
638 void KFileItemListWidget::updateAdditionalInfoTextColor()
640 // For the color of the additional info the inactive text color
641 // is not used as this might lead to unreadable text for some color schemes. Instead
642 // the text color is slightly mixed with the background color.
643 const QColor c1
= textColor();
644 const QColor c2
= styleOption().palette
.background().color();
646 const int p2
= 100 - p1
;
647 m_additionalInfoTextColor
= QColor((c1
.red() * p1
+ c2
.red() * p2
) / 100,
648 (c1
.green() * p1
+ c2
.green() * p2
) / 100,
649 (c1
.blue() * p1
+ c2
.blue() * p2
) / 100);
652 QString
KFileItemListWidget::roleText(TextId textId
, const QVariant
& roleValue
) const
664 text
= roleValue
.toString();
668 if (data().value("isDir").toBool()) {
669 // The item represents a directory. Show the number of sub directories
670 // instead of the file size of the directory.
671 if (!roleValue
.isNull()) {
672 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
673 text
= i18ncp("@item:intable", "%1 item", "%1 items", size
);
676 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
677 text
= KIO::convertSize(size
);
683 const QDateTime dateTime
= roleValue
.toDateTime();
684 text
= KGlobal::locale()->formatDateTime(dateTime
);
696 void KFileItemListWidget::drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
)
698 const bool isHiddenItem
= m_text
[Name
].text().startsWith(QLatin1Char('.'));
701 opacity
= painter
->opacity();
702 painter
->setOpacity(opacity
* 0.3);
705 if (m_scaledPixmapSize
!= pixmap
.size()) {
706 QPixmap scaledPixmap
= pixmap
;
707 KPixmapModifier::scale(scaledPixmap
, m_scaledPixmapSize
);
708 painter
->drawPixmap(m_pixmapPos
, scaledPixmap
);
710 #ifdef KFILEITEMLISTWIDGET_DEBUG
711 painter
->setPen(Qt::green
);
712 painter
->drawRect(QRectF(m_pixmapPos
, QSizeF(scaledPixmap
.size())));
715 painter
->drawPixmap(m_pixmapPos
, pixmap
);
719 painter
->setOpacity(opacity
);
723 QPixmap
KFileItemListWidget::pixmapForIcon(const QString
& name
, int size
)
725 const KIcon
icon(name
);
728 if (size
<= KIconLoader::SizeSmall
) {
729 requestedSize
= KIconLoader::SizeSmall
;
730 } else if (size
<= KIconLoader::SizeSmallMedium
) {
731 requestedSize
= KIconLoader::SizeSmallMedium
;
732 } else if (size
<= KIconLoader::SizeMedium
) {
733 requestedSize
= KIconLoader::SizeMedium
;
734 } else if (size
<= KIconLoader::SizeLarge
) {
735 requestedSize
= KIconLoader::SizeLarge
;
736 } else if (size
<= KIconLoader::SizeHuge
) {
737 requestedSize
= KIconLoader::SizeHuge
;
738 } else if (size
<= KIconLoader::SizeEnormous
) {
739 requestedSize
= KIconLoader::SizeEnormous
;
740 } else if (size
<= KIconLoader::SizeEnormous
* 2) {
741 requestedSize
= KIconLoader::SizeEnormous
* 2;
743 requestedSize
= size
;
746 QPixmap pixmap
= icon
.pixmap(requestedSize
, requestedSize
);
747 if (requestedSize
!= size
) {
748 KPixmapModifier::scale(pixmap
, QSize(size
, size
));
754 KFileItemListWidget::TextId
KFileItemListWidget::roleTextId(const QByteArray
& role
)
756 static QHash
<QByteArray
, TextId
> rolesHash
;
757 if (rolesHash
.isEmpty()) {
758 rolesHash
.insert("name", Name
);
759 rolesHash
.insert("size", Size
);
760 rolesHash
.insert("date", Date
);
761 rolesHash
.insert("permissions", Permissions
);
762 rolesHash
.insert("owner", Owner
);
763 rolesHash
.insert("group", Group
);
764 rolesHash
.insert("type", Type
);
765 rolesHash
.insert("destination", Destination
);
766 rolesHash
.insert("path", Path
);
769 return rolesHash
.value(role
);
772 #include "kfileitemlistwidget.moc"