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 bool clipAdditionalInfoBounds
= false;
123 if (m_layout
== DetailsLayout
) {
124 // Prevent a possible overlapping of the additional-information texts
125 // with the icon. This can happen if the user has minimized the width
126 // of the name-column to a very small value.
127 const qreal minX
= m_pixmapPos
.x() + m_pixmap
.width() + 4 * itemListStyleOption
.margin
;
128 if (m_textPos
[Name
+ 1].x() < minX
) {
129 clipAdditionalInfoBounds
= true;
131 painter
->setClipRect(minX
, 0, size().width() - minX
, size().height(), Qt::IntersectClip
);
135 painter
->setPen(m_additionalInfoTextColor
);
136 painter
->setFont(itemListStyleOption
.font
);
137 for (int i
= Name
+ 1; i
< TextIdCount
; ++i
) {
138 painter
->drawStaticText(m_textPos
[i
], m_text
[i
]);
141 if (clipAdditionalInfoBounds
) {
145 #ifdef KFILEITEMLISTWIDGET_DEBUG
146 painter
->setPen(Qt::red
);
147 painter
->setBrush(Qt::NoBrush
);
148 painter
->drawText(QPointF(0, itemListStyleOption
.fontMetrics
.height()), QString::number(index()));
149 painter
->drawRect(rect());
153 QRectF
KFileItemListWidget::iconRect() const
155 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
157 QRectF bounds
= m_hoverPixmapRect
;
158 const qreal margin
= styleOption().margin
;
159 bounds
.adjust(-margin
, -margin
, margin
, margin
);
163 QRectF
KFileItemListWidget::textRect() const
165 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
169 QRectF
KFileItemListWidget::expansionToggleRect() const
171 const_cast<KFileItemListWidget
*>(this)->triggerCacheRefreshing();
172 return m_isDir
? m_expansionArea
: QRectF();
175 QString
KFileItemListWidget::roleText(const QByteArray
& role
, const QHash
<QByteArray
, QVariant
>& values
)
178 const QVariant roleValue
= values
.value(role
);
180 switch (roleTextId(role
)) {
188 text
= roleValue
.toString();
192 if (values
.value("isDir").toBool()) {
193 // The item represents a directory. Show the number of sub directories
194 // instead of the file size of the directory.
195 if (roleValue
.isNull()) {
196 text
= i18nc("@item:intable", "Unknown");
198 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
199 text
= i18ncp("@item:intable", "%1 item", "%1 items", size
);
202 // Show the size in kilobytes (always round up)
203 const KLocale
* locale
= KGlobal::locale();
204 const int roundInc
= (locale
->binaryUnitDialect() == KLocale::MetricBinaryDialect
) ? 499 : 511;
205 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>() + roundInc
;
206 text
= locale
->formatByteSize(size
, 0, KLocale::DefaultBinaryDialect
, KLocale::UnitKiloByte
);
212 const QDateTime dateTime
= roleValue
.toDateTime();
213 text
= KGlobal::locale()->formatDateTime(dateTime
);
225 void KFileItemListWidget::invalidateCache()
227 m_dirtyLayout
= true;
228 m_dirtyContent
= true;
231 void KFileItemListWidget::refreshCache()
235 void KFileItemListWidget::setTextColor(const QColor
& color
)
237 if (color
!= m_customTextColor
) {
238 m_customTextColor
= color
;
239 updateAdditionalInfoTextColor();
244 QColor
KFileItemListWidget::textColor() const
246 return m_customTextColor
.isValid() ? m_customTextColor
: styleOption().palette
.text().color();
249 void KFileItemListWidget::setOverlay(const QPixmap
& overlay
)
252 m_dirtyContent
= true;
256 QPixmap
KFileItemListWidget::overlay() const
261 void KFileItemListWidget::dataChanged(const QHash
<QByteArray
, QVariant
>& current
,
262 const QSet
<QByteArray
>& roles
)
264 KItemListWidget::dataChanged(current
, roles
);
265 m_dirtyContent
= true;
267 QSet
<QByteArray
> dirtyRoles
;
268 if (roles
.isEmpty()) {
269 dirtyRoles
= visibleRoles().toSet();
270 dirtyRoles
.insert("iconPixmap");
271 dirtyRoles
.insert("iconName");
276 QSetIterator
<QByteArray
> it(dirtyRoles
);
277 while (it
.hasNext()) {
278 const QByteArray
& role
= it
.next();
279 m_dirtyContentRoles
.insert(role
);
283 void KFileItemListWidget::visibleRolesChanged(const QList
<QByteArray
>& current
,
284 const QList
<QByteArray
>& previous
)
286 KItemListWidget::visibleRolesChanged(current
, previous
);
287 m_sortedVisibleRoles
= current
;
288 m_dirtyLayout
= true;
291 void KFileItemListWidget::visibleRolesSizesChanged(const QHash
<QByteArray
, QSizeF
>& current
,
292 const QHash
<QByteArray
, QSizeF
>& previous
)
294 KItemListWidget::visibleRolesSizesChanged(current
, previous
);
295 m_dirtyLayout
= true;
298 void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption
& current
,
299 const KItemListStyleOption
& previous
)
301 KItemListWidget::styleOptionChanged(current
, previous
);
302 updateAdditionalInfoTextColor();
303 m_dirtyLayout
= true;
306 void KFileItemListWidget::hoveredChanged(bool hovered
)
309 m_dirtyLayout
= true;
312 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent
* event
)
314 KItemListWidget::resizeEvent(event
);
315 m_dirtyLayout
= true;
318 void KFileItemListWidget::triggerCacheRefreshing()
320 if ((!m_dirtyContent
&& !m_dirtyLayout
) || index() < 0) {
326 m_isDir
= data()["isDir"].toBool();
328 updateExpansionArea();
332 m_dirtyLayout
= false;
333 m_dirtyContent
= false;
334 m_dirtyContentRoles
.clear();
337 void KFileItemListWidget::updateExpansionArea()
339 if (m_layout
== DetailsLayout
) {
340 const QHash
<QByteArray
, QVariant
> values
= data();
341 Q_ASSERT(values
.contains("expansionLevel"));
342 const KItemListStyleOption
& option
= styleOption();
343 const int expansionLevel
= values
.value("expansionLevel", 0).toInt();
345 const qreal widgetHeight
= size().height();
346 const qreal expansionLevelSize
= KIconLoader::SizeSmall
;
347 const qreal x
= option
.margin
+ expansionLevel
* widgetHeight
;
348 const qreal y
= (widgetHeight
- expansionLevelSize
) / 2;
349 m_expansionArea
= QRectF(x
, y
, expansionLevelSize
, expansionLevelSize
);
351 m_expansionArea
= QRectF();
355 void KFileItemListWidget::updatePixmapCache()
357 // Precondition: Requires already updated m_textPos values to calculate
358 // the remaining height when the alignment is vertical.
360 const bool iconOnTop
= (m_layout
== IconsLayout
);
361 const KItemListStyleOption
& option
= styleOption();
362 const int iconHeight
= option
.iconSize
;
364 const QHash
<QByteArray
, QVariant
> values
= data();
365 const QSizeF widgetSize
= size();
367 int scaledIconHeight
= 0;
369 scaledIconHeight
= static_cast<int>(m_textPos
[Name
].y() - 3 * option
.margin
);
371 const int textRowsCount
= (m_layout
== CompactLayout
) ? visibleRoles().count() : 1;
372 const qreal requiredTextHeight
= textRowsCount
* option
.fontMetrics
.height();
373 scaledIconHeight
= (requiredTextHeight
< iconHeight
) ? widgetSize
.height() - 2 * option
.margin
: iconHeight
;
376 bool updatePixmap
= (iconHeight
!= m_pixmap
.height());
377 if (!updatePixmap
&& m_dirtyContent
) {
378 updatePixmap
= m_dirtyContentRoles
.isEmpty()
379 || m_dirtyContentRoles
.contains("iconPixmap")
380 || m_dirtyContentRoles
.contains("iconName");
384 m_pixmap
= values
["iconPixmap"].value
<QPixmap
>();
385 if (m_pixmap
.isNull()) {
386 // Use the icon that fits to the MIME-type
387 QString iconName
= values
["iconName"].toString();
388 if (iconName
.isEmpty()) {
389 // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
390 // use a generic icon as fallback
391 iconName
= QLatin1String("unknown");
393 m_pixmap
= pixmapForIcon(iconName
, iconHeight
);
394 m_hoverPixmapRect
.setSize(m_pixmap
.size());
395 } else if (m_pixmap
.size() != QSize(iconHeight
, iconHeight
)) {
396 // A custom pixmap has been applied. Assure that the pixmap
397 // is scaled to the available size.
398 const bool scale
= m_pixmap
.width() > iconHeight
|| m_pixmap
.height() > iconHeight
||
399 (m_pixmap
.width() < iconHeight
&& m_pixmap
.height() < iconHeight
);
401 KPixmapModifier::scale(m_pixmap
, QSize(iconHeight
, iconHeight
));
403 m_hoverPixmapRect
.setSize(m_pixmap
.size());
405 // To simplify the handling of scaling the original pixmap
406 // will be embedded into a square pixmap.
407 QPixmap
squarePixmap(iconHeight
, iconHeight
);
408 squarePixmap
.fill(Qt::transparent
);
410 QPainter
painter(&squarePixmap
);
412 const int x
= (iconHeight
- m_pixmap
.width()) / 2; // Center horizontally
413 const int y
= iconHeight
- m_pixmap
.height(); // Align on bottom
414 painter
.drawPixmap(x
, y
, m_pixmap
);
416 const int x
= iconHeight
- m_pixmap
.width(); // Align right
417 const int y
= (iconHeight
- m_pixmap
.height()) / 2; // Center vertically
418 painter
.drawPixmap(x
, y
, m_pixmap
);
421 m_pixmap
= squarePixmap
;
423 m_hoverPixmapRect
.setSize(m_pixmap
.size());
426 Q_ASSERT(m_pixmap
.height() == iconHeight
);
428 if (!m_overlay
.isNull()) {
429 QPainter
painter(&m_pixmap
);
430 painter
.drawPixmap(0, m_pixmap
.height() - m_overlay
.height(), m_overlay
);
433 m_scaledPixmapSize
= QSize(scaledIconHeight
, scaledIconHeight
);
436 m_pixmapPos
.setX((widgetSize
.width() - m_scaledPixmapSize
.width()) / 2);
438 m_pixmapPos
.setX(m_textPos
[Name
].x() - 2 * option
.margin
- scaledIconHeight
);
440 m_pixmapPos
.setY(option
.margin
);
442 // Center the hover rectangle horizontally and align it on bottom
443 const qreal x
= m_pixmapPos
.x() + (m_scaledPixmapSize
.width() - m_hoverPixmapRect
.width()) / 2.0;
444 const qreal y
= m_pixmapPos
.y() + m_scaledPixmapSize
.height() - m_hoverPixmapRect
.height();
445 m_hoverPixmapRect
.moveTopLeft(QPointF(x
, y
));
447 // Prepare the pixmap that is used when the item gets hovered
449 m_hoverPixmap
= m_pixmap
;
450 KIconEffect
* effect
= KIconLoader::global()->iconEffect();
451 // In the KIconLoader terminology, active = hover.
452 if (effect
->hasEffect(KIconLoader::Desktop
, KIconLoader::ActiveState
)) {
453 m_hoverPixmap
= effect
->apply(m_pixmap
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
455 m_hoverPixmap
= m_pixmap
;
457 } else if (hoverOpacity() <= 0.0) {
458 // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
459 m_hoverPixmap
= QPixmap();
463 void KFileItemListWidget::updateTextsCache()
465 QTextOption textOption
;
468 textOption
.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere
);
469 textOption
.setAlignment(Qt::AlignHCenter
);
473 textOption
.setAlignment(Qt::AlignLeft
);
474 textOption
.setWrapMode(QTextOption::NoWrap
);
481 for (int i
= 0; i
< TextIdCount
; ++i
) {
482 m_text
[i
].setText(QString());
483 m_text
[i
].setTextOption(textOption
);
487 case IconsLayout
: updateIconsLayoutTextCache(); break;
488 case CompactLayout
: updateCompactLayoutTextCache(); break;
489 case DetailsLayout
: updateDetailsLayoutTextCache(); break;
490 default: Q_ASSERT(false); break;
494 void KFileItemListWidget::updateIconsLayoutTextCache()
501 // might get wrapped above
506 const QHash
<QByteArray
, QVariant
> values
= data();
508 const KItemListStyleOption
& option
= styleOption();
509 const qreal maxWidth
= size().width() - 2 * option
.margin
;
510 const qreal widgetHeight
= size().height();
511 const qreal fontHeight
= option
.fontMetrics
.height();
513 // Initialize properties for the "name" role. It will be used as anchor
514 // for initializing the position of the other roles.
515 m_text
[Name
].setText(KStringHandler::preProcessWrap(values
["name"].toString()));
517 // Calculate the number of lines required for the name and the required width
518 int textLinesCountForName
= 0;
519 qreal requiredWidthForName
= 0;
522 QTextLayout
layout(m_text
[Name
].text(), option
.font
);
523 layout
.setTextOption(m_text
[Name
].textOption());
524 layout
.beginLayout();
525 while ((line
= layout
.createLine()).isValid()) {
526 line
.setLineWidth(maxWidth
);
527 requiredWidthForName
= qMax(requiredWidthForName
, line
.naturalTextWidth());
528 ++textLinesCountForName
;
532 // Use one line for each additional information
533 int textLinesCount
= textLinesCountForName
;
534 const int additionalRolesCount
= qMax(visibleRoles().count() - 1, 0);
535 textLinesCount
+= additionalRolesCount
;
537 m_text
[Name
].setTextWidth(maxWidth
);
538 m_textPos
[Name
] = QPointF(option
.margin
, widgetHeight
- textLinesCount
* fontHeight
- option
.margin
);
539 m_textRect
= QRectF(option
.margin
+ (maxWidth
- requiredWidthForName
) / 2,
541 requiredWidthForName
,
542 m_text
[Name
].size().height());
544 // Calculate the position for each additional information
545 qreal y
= m_textPos
[Name
].y() + textLinesCountForName
* fontHeight
;
546 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
547 const TextId textId
= roleTextId(role
);
548 if (textId
== Name
) {
552 const QString text
= roleText(role
, values
);
553 m_text
[textId
].setText(text
);
555 qreal requiredWidth
= 0;
557 QTextLayout
layout(text
, option
.font
);
558 layout
.setTextOption(m_text
[textId
].textOption());
559 layout
.beginLayout();
560 QTextLine textLine
= layout
.createLine();
561 if (textLine
.isValid()) {
562 textLine
.setLineWidth(maxWidth
);
563 requiredWidth
= textLine
.naturalTextWidth();
564 if (textLine
.textLength() < text
.length()) {
565 // TODO: QFontMetrics::elidedText() works different regarding the given width
566 // in comparison to QTextLine::setLineWidth(). It might happen that the text does
567 // not get elided although it does not fit into the given width. As workaround
568 // the margin is substracted.
569 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
- option
.margin
);
570 m_text
[textId
].setText(elidedText
);
575 m_textPos
[textId
] = QPointF(option
.margin
, y
);
576 m_text
[textId
].setTextWidth(maxWidth
);
578 const QRectF
textRect(option
.margin
+ (maxWidth
- requiredWidth
) / 2, y
, requiredWidth
, fontHeight
);
579 m_textRect
|= textRect
;
584 // Add a margin to the text rectangle
585 const qreal margin
= option
.margin
;
586 m_textRect
.adjust(-margin
, -margin
, margin
, margin
);
589 void KFileItemListWidget::updateCompactLayoutTextCache()
591 // +------+ Name role
592 // | Icon | Additional role 1
593 // +------+ Additional role 2
595 const QHash
<QByteArray
, QVariant
> values
= data();
597 const KItemListStyleOption
& option
= styleOption();
598 const qreal widgetHeight
= size().height();
599 const qreal fontHeight
= option
.fontMetrics
.height();
600 const qreal textLinesHeight
= qMax(visibleRoles().count(), 1) * fontHeight
;
601 const int scaledIconSize
= (textLinesHeight
< option
.iconSize
) ? widgetHeight
- 2 * option
.margin
: option
.iconSize
;
603 qreal maximumRequiredTextWidth
= 0;
604 const qreal x
= option
.margin
* 3 + scaledIconSize
;
605 qreal y
= (widgetHeight
- textLinesHeight
) / 2;
606 const qreal maxWidth
= size().width() - x
- option
.margin
;
607 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
608 const TextId textId
= roleTextId(role
);
610 const QString text
= roleText(role
, values
);
611 m_text
[textId
].setText(text
);
613 qreal requiredWidth
= option
.fontMetrics
.width(text
);
614 if (requiredWidth
> maxWidth
) {
615 requiredWidth
= maxWidth
;
616 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
);
617 m_text
[textId
].setText(elidedText
);
620 m_textPos
[textId
] = QPointF(x
, y
);
621 m_text
[textId
].setTextWidth(maxWidth
);
623 maximumRequiredTextWidth
= qMax(maximumRequiredTextWidth
, requiredWidth
);
628 m_textRect
= QRectF(x
- option
.margin
, 0, maximumRequiredTextWidth
+ 2 * option
.margin
, widgetHeight
);
631 void KFileItemListWidget::updateDetailsLayoutTextCache()
633 // Precondition: Requires already updated m_expansionArea
634 // to determine the left position.
637 // | Icon | Name role Additional role 1 Additional role 2
639 m_textRect
= QRectF();
641 const KItemListStyleOption
& option
= styleOption();
642 const QHash
<QByteArray
, QVariant
> values
= data();
644 const qreal widgetHeight
= size().height();
645 const int scaledIconSize
= widgetHeight
- 2 * option
.margin
;
646 const int fontHeight
= option
.fontMetrics
.height();
648 const qreal columnMargin
= option
.margin
* 3;
649 const qreal firstColumnInc
= m_expansionArea
.right() + option
.margin
* 2 + scaledIconSize
;
650 qreal x
= firstColumnInc
;
651 const qreal y
= qMax(qreal(option
.margin
), (widgetHeight
- fontHeight
) / 2);
653 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
654 const TextId textId
= roleTextId(role
);
656 QString text
= roleText(role
, values
);
658 // Elide the text in case it does not fit into the available column-width
659 qreal requiredWidth
= option
.fontMetrics
.width(text
);
660 const qreal columnWidth
= visibleRolesSizes().value(role
, QSizeF(0, 0)).width();
661 qreal availableTextWidth
= columnWidth
- 2 * columnMargin
;
662 if (textId
== Name
) {
663 availableTextWidth
-= firstColumnInc
;
666 if (requiredWidth
> availableTextWidth
) {
667 text
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, availableTextWidth
);
668 requiredWidth
= option
.fontMetrics
.width(text
);
671 m_text
[textId
].setText(text
);
672 m_textPos
[textId
] = QPointF(x
+ columnMargin
, y
);
677 m_textRect
= QRectF(m_textPos
[textId
].x() - option
.margin
, 0,
678 requiredWidth
+ 2 * option
.margin
, size().height());
680 // The column after the name should always be aligned on the same x-position independent
681 // from the expansion-level shown in the name column
686 // The values for the size should be right aligned
687 m_textPos
[textId
].rx() += columnWidth
- requiredWidth
- 2 * columnMargin
;
696 void KFileItemListWidget::updateAdditionalInfoTextColor()
698 // For the color of the additional info the inactive text color
699 // is not used as this might lead to unreadable text for some color schemes. Instead
700 // the text color is slightly mixed with the background color.
701 const QColor c1
= textColor();
702 const QColor c2
= styleOption().palette
.base().color();
704 const int p2
= 100 - p1
;
705 m_additionalInfoTextColor
= QColor((c1
.red() * p1
+ c2
.red() * p2
) / 100,
706 (c1
.green() * p1
+ c2
.green() * p2
) / 100,
707 (c1
.blue() * p1
+ c2
.blue() * p2
) / 100);
710 void KFileItemListWidget::drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
)
712 const bool isHiddenItem
= m_text
[Name
].text().startsWith(QLatin1Char('.'));
715 opacity
= painter
->opacity();
716 painter
->setOpacity(opacity
* 0.3);
719 if (m_scaledPixmapSize
!= pixmap
.size()) {
720 QPixmap scaledPixmap
= pixmap
;
721 KPixmapModifier::scale(scaledPixmap
, m_scaledPixmapSize
);
722 painter
->drawPixmap(m_pixmapPos
, scaledPixmap
);
724 #ifdef KFILEITEMLISTWIDGET_DEBUG
725 painter
->setPen(Qt::green
);
726 painter
->drawRect(QRectF(m_pixmapPos
, QSizeF(scaledPixmap
.size())));
729 painter
->drawPixmap(m_pixmapPos
, pixmap
);
733 painter
->setOpacity(opacity
);
737 QPixmap
KFileItemListWidget::pixmapForIcon(const QString
& name
, int size
)
739 const KIcon
icon(name
);
742 if (size
<= KIconLoader::SizeSmall
) {
743 requestedSize
= KIconLoader::SizeSmall
;
744 } else if (size
<= KIconLoader::SizeSmallMedium
) {
745 requestedSize
= KIconLoader::SizeSmallMedium
;
746 } else if (size
<= KIconLoader::SizeMedium
) {
747 requestedSize
= KIconLoader::SizeMedium
;
748 } else if (size
<= KIconLoader::SizeLarge
) {
749 requestedSize
= KIconLoader::SizeLarge
;
750 } else if (size
<= KIconLoader::SizeHuge
) {
751 requestedSize
= KIconLoader::SizeHuge
;
752 } else if (size
<= KIconLoader::SizeEnormous
) {
753 requestedSize
= KIconLoader::SizeEnormous
;
754 } else if (size
<= KIconLoader::SizeEnormous
* 2) {
755 requestedSize
= KIconLoader::SizeEnormous
* 2;
757 requestedSize
= size
;
760 QPixmap pixmap
= icon
.pixmap(requestedSize
, requestedSize
);
761 if (requestedSize
!= size
) {
762 KPixmapModifier::scale(pixmap
, QSize(size
, size
));
768 KFileItemListWidget::TextId
KFileItemListWidget::roleTextId(const QByteArray
& role
)
770 static QHash
<QByteArray
, TextId
> rolesHash
;
771 if (rolesHash
.isEmpty()) {
772 rolesHash
.insert("name", Name
);
773 rolesHash
.insert("size", Size
);
774 rolesHash
.insert("date", Date
);
775 rolesHash
.insert("permissions", Permissions
);
776 rolesHash
.insert("owner", Owner
);
777 rolesHash
.insert("group", Group
);
778 rolesHash
.insert("type", Type
);
779 rolesHash
.insert("destination", Destination
);
780 rolesHash
.insert("path", Path
);
783 return rolesHash
.value(role
);
786 #include "kfileitemlistwidget.moc"