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
),
56 m_textsBoundingRect(),
57 m_sortedVisibleRoles(),
59 m_additionalInfoTextColor()
61 for (int i
= 0; i
< TextIdCount
; ++i
) {
62 m_text
[i
].setTextFormat(Qt::PlainText
);
63 m_text
[i
].setPerformanceHint(QStaticText::AggressiveCaching
);
67 KFileItemListWidget::~KFileItemListWidget()
71 void KFileItemListWidget::setLayout(Layout layout
)
73 if (m_layout
!= layout
) {
80 KFileItemListWidget::Layout
KFileItemListWidget::layout() const
85 void KFileItemListWidget::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
87 KItemListWidget::paint(painter
, option
, widget
);
89 painter
->setRenderHint(QPainter::Antialiasing
);
91 if (m_dirtyContent
|| m_dirtyLayout
) {
92 const_cast<KFileItemListWidget
*>(this)->updateCache();
95 // Draw expansion toggle '>' or 'V'
96 if (m_isDir
&& !m_expansionArea
.isEmpty()) {
97 QStyleOption arrowOption
;
98 arrowOption
.rect
= m_expansionArea
.toRect();
99 const QStyle::PrimitiveElement arrow
= data()["isExpanded"].toBool()
100 ? QStyle::PE_IndicatorArrowDown
: QStyle::PE_IndicatorArrowRight
;
101 style()->drawPrimitive(arrow
, &arrowOption
, painter
);
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
);
131 drawFocusIndicator(painter
);
134 painter
->setFont(itemListStyleOption
.font
);
135 painter
->setPen(itemListStyleOption
.palette
.text().color());
136 painter
->drawStaticText(m_textPos
[Name
], m_text
[Name
]);
138 painter
->setPen(m_additionalInfoTextColor
);
139 painter
->setFont(itemListStyleOption
.font
);
140 for (int i
= Name
+ 1; i
< TextIdCount
; ++i
) {
141 painter
->drawStaticText(m_textPos
[i
], m_text
[i
]);
144 #ifdef KFILEITEMLISTWIDGET_DEBUG
145 painter
->setPen(Qt::red
);
146 painter
->setBrush(Qt::NoBrush
);
147 painter
->drawText(QPointF(0, itemListStyleOption
.fontMetrics
.height()), QString::number(index()));
148 painter
->drawRect(rect());
152 bool KFileItemListWidget::contains(const QPointF
& point
) const
154 return KItemListWidget::contains(point
) || m_textsBoundingRect
.contains(point
);
157 QRectF
KFileItemListWidget::hoverBoundingRect() const
159 QRectF bounds
= m_hoverPixmapRect
;
160 const qreal margin
= styleOption().margin
;
161 bounds
.adjust(-margin
, -margin
, margin
, margin
);
165 QRectF
KFileItemListWidget::expansionToggleRect() const
167 return m_isDir
? m_expansionArea
: QRectF();
170 void KFileItemListWidget::dataChanged(const QHash
<QByteArray
, QVariant
>& current
,
171 const QSet
<QByteArray
>& roles
)
173 KItemListWidget::dataChanged(current
, roles
);
174 m_dirtyContent
= true;
176 QSet
<QByteArray
> dirtyRoles
;
177 if (roles
.isEmpty()) {
178 dirtyRoles
= visibleRoles().keys().toSet();
179 dirtyRoles
.insert("iconPixmap");
180 dirtyRoles
.insert("iconName");
185 QSetIterator
<QByteArray
> it(dirtyRoles
);
186 while (it
.hasNext()) {
187 const QByteArray
& role
= it
.next();
188 m_dirtyContentRoles
.insert(role
);
192 void KFileItemListWidget::visibleRolesChanged(const QHash
<QByteArray
, int>& current
,
193 const QHash
<QByteArray
, int>& previous
)
195 KItemListWidget::visibleRolesChanged(current
, previous
);
196 m_dirtyLayout
= true;
198 // Cache the roles sorted into m_sortedVisibleRoles:
199 const int visibleRolesCount
= current
.count();
200 m_sortedVisibleRoles
.clear();
201 m_sortedVisibleRoles
.reserve(visibleRolesCount
);
202 for (int i
= 0; i
< visibleRolesCount
; ++i
) {
203 m_sortedVisibleRoles
.append(QByteArray());
206 QHashIterator
<QByteArray
, int> it(current
);
207 while (it
.hasNext()) {
210 const int index
= it
.value();
211 if (index
< 0 || index
>= visibleRolesCount
|| !m_sortedVisibleRoles
.at(index
).isEmpty()) {
212 kWarning() << "The visible roles have an invalid sort order.";
216 const QByteArray
& role
= it
.key();
217 m_sortedVisibleRoles
[index
] = role
;
221 void KFileItemListWidget::visibleRolesSizesChanged(const QHash
<QByteArray
, QSizeF
>& current
,
222 const QHash
<QByteArray
, QSizeF
>& previous
)
224 KItemListWidget::visibleRolesSizesChanged(current
, previous
);
225 m_dirtyLayout
= true;
228 void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption
& current
,
229 const KItemListStyleOption
& previous
)
231 KItemListWidget::styleOptionChanged(current
, previous
);
233 // For the color of the additional info the inactive text color
234 // is not used as this might lead to unreadable text for some color schemes. Instead
235 // the text color is slightly mixed with the background color.
236 const QColor c1
= current
.palette
.text().color();
237 const QColor c2
= current
.palette
.background().color();
239 const int p2
= 100 - p1
;
240 m_additionalInfoTextColor
= QColor((c1
.red() * p1
+ c2
.red() * p2
) / 100,
241 (c1
.green() * p1
+ c2
.green() * p2
) / 100,
242 (c1
.blue() * p1
+ c2
.blue() * p2
) / 100);
244 m_dirtyLayout
= true;
247 void KFileItemListWidget::hoveredChanged(bool hovered
)
250 m_dirtyLayout
= true;
253 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent
* event
)
255 KItemListWidget::resizeEvent(event
);
256 m_dirtyLayout
= true;
259 void KFileItemListWidget::updateCache()
265 m_isDir
= data()["isDir"].toBool();
267 updateExpansionArea();
271 m_dirtyLayout
= false;
272 m_dirtyContent
= false;
273 m_dirtyContentRoles
.clear();
276 void KFileItemListWidget::updateExpansionArea()
278 if (m_layout
== DetailsLayout
) {
279 const QHash
<QByteArray
, QVariant
> values
= data();
280 Q_ASSERT(values
.contains("expansionLevel"));
281 const KItemListStyleOption
& option
= styleOption();
282 const int expansionLevel
= values
.value("expansionLevel", 0).toInt();
284 const qreal widgetHeight
= size().height();
285 const qreal expansionLevelSize
= KIconLoader::SizeSmall
;
286 const qreal x
= option
.margin
+ expansionLevel
* widgetHeight
;
287 const qreal y
= (widgetHeight
- expansionLevelSize
) / 2;
288 m_expansionArea
= QRectF(x
, y
, expansionLevelSize
, expansionLevelSize
);
290 m_expansionArea
= QRectF();
294 void KFileItemListWidget::updatePixmapCache()
296 // Precondition: Requires already updated m_textPos values to calculate
297 // the remaining height when the alignment is vertical.
299 const bool iconOnTop
= (m_layout
== IconsLayout
);
300 const KItemListStyleOption
& option
= styleOption();
301 const int iconHeight
= option
.iconSize
;
303 const QHash
<QByteArray
, QVariant
> values
= data();
304 const QSizeF widgetSize
= size();
306 int scaledIconHeight
= 0;
308 scaledIconHeight
= static_cast<int>(m_textPos
[Name
].y() - 3 * option
.margin
);
310 const int textRowsCount
= (m_layout
== CompactLayout
) ? visibleRoles().count() : 1;
311 const qreal requiredTextHeight
= textRowsCount
* option
.fontMetrics
.height();
312 scaledIconHeight
= (requiredTextHeight
< iconHeight
) ? widgetSize
.height() - 2 * option
.margin
: iconHeight
;
315 bool updatePixmap
= (iconHeight
!= m_pixmap
.height());
316 if (!updatePixmap
&& m_dirtyContent
) {
317 updatePixmap
= m_dirtyContentRoles
.isEmpty()
318 || m_dirtyContentRoles
.contains("iconPixmap")
319 || m_dirtyContentRoles
.contains("iconName");
323 m_pixmap
= values
["iconPixmap"].value
<QPixmap
>();
324 if (m_pixmap
.isNull()) {
325 // Use the icon that fits to the MIME-type
326 QString iconName
= values
["iconName"].toString();
327 if (iconName
.isEmpty()) {
328 // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
329 // use a generic icon as fallback
330 iconName
= QLatin1String("unknown");
332 m_pixmap
= pixmapForIcon(iconName
, iconHeight
);
333 m_hoverPixmapRect
.setSize(m_pixmap
.size());
334 } else if (m_pixmap
.size() != QSize(iconHeight
, iconHeight
)) {
335 // A custom pixmap has been applied. Assure that the pixmap
336 // is scaled to the available size.
337 const bool scale
= m_pixmap
.width() > iconHeight
|| m_pixmap
.height() > iconHeight
||
338 (m_pixmap
.width() < iconHeight
&& m_pixmap
.height() < iconHeight
);
340 KPixmapModifier::scale(m_pixmap
, QSize(iconHeight
, iconHeight
));
342 m_hoverPixmapRect
.setSize(m_pixmap
.size());
344 // To simplify the handling of scaling the original pixmap
345 // will be embedded into a square pixmap.
346 QPixmap
squarePixmap(iconHeight
, iconHeight
);
347 squarePixmap
.fill(Qt::transparent
);
349 QPainter
painter(&squarePixmap
);
351 const int x
= (iconHeight
- m_pixmap
.width()) / 2; // Center horizontally
352 const int y
= iconHeight
- m_pixmap
.height(); // Align on bottom
353 painter
.drawPixmap(x
, y
, m_pixmap
);
355 const int x
= iconHeight
- m_pixmap
.width(); // Align right
356 const int y
= (iconHeight
- m_pixmap
.height()) / 2; // Center vertically
357 painter
.drawPixmap(x
, y
, m_pixmap
);
360 m_pixmap
= squarePixmap
;
362 m_hoverPixmapRect
.setSize(m_pixmap
.size());
365 Q_ASSERT(m_pixmap
.height() == iconHeight
);
368 m_scaledPixmapSize
= QSize(scaledIconHeight
, scaledIconHeight
);
371 m_pixmapPos
.setX((widgetSize
.width() - m_scaledPixmapSize
.width()) / 2);
373 m_pixmapPos
.setX(m_textPos
[Name
].x() - 2 * option
.margin
- scaledIconHeight
);
375 m_pixmapPos
.setY(option
.margin
);
377 // Center the hover rectangle horizontally and align it on bottom
378 const qreal x
= m_pixmapPos
.x() + (m_scaledPixmapSize
.width() - m_hoverPixmapRect
.width()) / 2.0;
379 const qreal y
= m_pixmapPos
.y() + m_scaledPixmapSize
.height() - m_hoverPixmapRect
.height();
380 m_hoverPixmapRect
.moveTopLeft(QPointF(x
, y
));
382 // Prepare the pixmap that is used when the item gets hovered
384 m_hoverPixmap
= m_pixmap
;
385 KIconEffect
* effect
= KIconLoader::global()->iconEffect();
386 // In the KIconLoader terminology, active = hover.
387 if (effect
->hasEffect(KIconLoader::Desktop
, KIconLoader::ActiveState
)) {
388 m_hoverPixmap
= effect
->apply(m_pixmap
, KIconLoader::Desktop
, KIconLoader::ActiveState
);
390 m_hoverPixmap
= m_pixmap
;
392 } else if (hoverOpacity() <= 0.0) {
393 // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
394 m_hoverPixmap
= QPixmap();
398 void KFileItemListWidget::updateTextsCache()
400 QTextOption textOption
;
403 textOption
.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere
);
404 textOption
.setAlignment(Qt::AlignHCenter
);
408 textOption
.setAlignment(Qt::AlignLeft
);
409 textOption
.setWrapMode(QTextOption::NoWrap
);
416 for (int i
= 0; i
< TextIdCount
; ++i
) {
417 m_text
[i
].setText(QString());
418 m_text
[i
].setTextOption(textOption
);
422 case IconsLayout
: updateIconsLayoutTextCache(); break;
423 case CompactLayout
: updateCompactLayoutTextCache(); break;
424 case DetailsLayout
: updateDetailsLayoutTextCache(); break;
425 default: Q_ASSERT(false); break;
429 void KFileItemListWidget::updateIconsLayoutTextCache()
436 // might get wrapped above
441 const QHash
<QByteArray
, QVariant
> values
= data();
443 const KItemListStyleOption
& option
= styleOption();
444 const qreal maxWidth
= size().width() - 2 * option
.margin
;
445 const qreal widgetHeight
= size().height();
446 const qreal fontHeight
= option
.fontMetrics
.height();
448 // Initialize properties for the "name" role. It will be used as anchor
449 // for initializing the position of the other roles.
450 m_text
[Name
].setText(KStringHandler::preProcessWrap(values
["name"].toString()));
452 // Calculate the number of lines required for the name and the required width
453 int textLinesCountForName
= 0;
454 qreal requiredWidthForName
= 0;
457 QTextLayout
layout(m_text
[Name
].text(), option
.font
);
458 layout
.setTextOption(m_text
[Name
].textOption());
459 layout
.beginLayout();
460 while ((line
= layout
.createLine()).isValid()) {
461 line
.setLineWidth(maxWidth
);
462 requiredWidthForName
= qMax(requiredWidthForName
, line
.naturalTextWidth());
463 ++textLinesCountForName
;
467 // Use one line for each additional information
468 int textLinesCount
= textLinesCountForName
;
469 const int additionalRolesCount
= qMax(visibleRoles().count() - 1, 0);
470 textLinesCount
+= additionalRolesCount
;
472 m_text
[Name
].setTextWidth(maxWidth
);
473 m_textPos
[Name
] = QPointF(option
.margin
, widgetHeight
- textLinesCount
* fontHeight
- option
.margin
);
474 m_textsBoundingRect
= QRectF(option
.margin
+ (maxWidth
- requiredWidthForName
) / 2,
476 requiredWidthForName
,
477 m_text
[Name
].size().height());
479 // Calculate the position for each additional information
480 qreal y
= m_textPos
[Name
].y() + textLinesCountForName
* fontHeight
;
481 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
482 const TextId textId
= roleTextId(role
);
483 if (textId
== Name
) {
487 const QString text
= roleText(textId
, values
[role
]);
488 m_text
[textId
].setText(text
);
490 qreal requiredWidth
= 0;
492 QTextLayout
layout(text
, option
.font
);
493 layout
.setTextOption(m_text
[textId
].textOption());
494 layout
.beginLayout();
495 QTextLine textLine
= layout
.createLine();
496 if (textLine
.isValid()) {
497 textLine
.setLineWidth(maxWidth
);
498 requiredWidth
= textLine
.naturalTextWidth();
499 if (textLine
.textLength() < text
.length()) {
500 // TODO: QFontMetrics::elidedText() works different regarding the given width
501 // in comparison to QTextLine::setLineWidth(). It might happen that the text does
502 // not get elided although it does not fit into the given width. As workaround
503 // the margin is substracted.
504 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
- option
.margin
);
505 m_text
[textId
].setText(elidedText
);
510 m_textPos
[textId
] = QPointF(option
.margin
, y
);
511 m_text
[textId
].setTextWidth(maxWidth
);
513 const QRectF
textBoundingRect(option
.margin
+ (maxWidth
- requiredWidth
) / 2, y
, requiredWidth
, fontHeight
);
514 m_textsBoundingRect
|= textBoundingRect
;
519 // Add a margin to the text bounding rectangle
520 const qreal margin
= option
.margin
;
521 m_textsBoundingRect
.adjust(-margin
, -margin
, margin
, margin
);
524 void KFileItemListWidget::updateCompactLayoutTextCache()
526 // +------+ Name role
527 // | Icon | Additional role 1
528 // +------+ Additional role 2
530 const QHash
<QByteArray
, QVariant
> values
= data();
532 const KItemListStyleOption
& option
= styleOption();
533 const qreal widgetHeight
= size().height();
534 const qreal fontHeight
= option
.fontMetrics
.height();
535 const qreal textLinesHeight
= qMax(visibleRoles().count(), 1) * fontHeight
;
536 const int scaledIconSize
= (textLinesHeight
< option
.iconSize
) ? widgetHeight
- 2 * option
.margin
: option
.iconSize
;
538 qreal maximumRequiredTextWidth
= 0;
539 const qreal x
= option
.margin
* 3 + scaledIconSize
;
540 qreal y
= (widgetHeight
- textLinesHeight
) / 2;
541 const qreal maxWidth
= size().width() - x
- option
.margin
;
542 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
543 const TextId textId
= roleTextId(role
);
545 const QString text
= roleText(textId
, values
[role
]);
546 m_text
[textId
].setText(text
);
548 qreal requiredWidth
= option
.fontMetrics
.width(text
);
549 if (requiredWidth
> maxWidth
) {
550 requiredWidth
= maxWidth
;
551 const QString elidedText
= option
.fontMetrics
.elidedText(text
, Qt::ElideRight
, maxWidth
);
552 m_text
[textId
].setText(elidedText
);
555 m_textPos
[textId
] = QPointF(x
, y
);
556 m_text
[textId
].setTextWidth(maxWidth
);
558 maximumRequiredTextWidth
= qMax(maximumRequiredTextWidth
, requiredWidth
);
563 m_textsBoundingRect
= QRectF(x
- option
.margin
, 0, maximumRequiredTextWidth
+ 2 * option
.margin
, widgetHeight
);
566 void KFileItemListWidget::updateDetailsLayoutTextCache()
568 // Precondition: Requires already updated m_expansionArea
569 // to determine the left position.
572 // | Icon | Name role Additional role 1 Additional role 2
574 m_textsBoundingRect
= QRectF();
576 const KItemListStyleOption
& option
= styleOption();
577 const QHash
<QByteArray
, QVariant
> values
= data();
579 const qreal widgetHeight
= size().height();
580 const int scaledIconSize
= widgetHeight
- 2 * option
.margin
;
581 const int fontHeight
= option
.fontMetrics
.height();
583 qreal x
= m_expansionArea
.right() + option
.margin
* 3 + scaledIconSize
;
584 const qreal y
= qMax(qreal(option
.margin
), (widgetHeight
- fontHeight
) / 2);
586 foreach (const QByteArray
& role
, m_sortedVisibleRoles
) {
587 const TextId textId
= roleTextId(role
);
589 const QString text
= roleText(textId
, values
[role
]);
590 m_text
[textId
].setText(text
);
592 const qreal requiredWidth
= option
.fontMetrics
.width(text
);
593 m_textPos
[textId
] = QPointF(x
, y
);
595 const qreal columnWidth
= visibleRolesSizes().value(role
, QSizeF(0, 0)).width();
600 m_textsBoundingRect
= QRectF(m_textPos
[textId
].x() - option
.margin
, 0,
601 requiredWidth
+ 2 * option
.margin
, size().height());
603 // The column after the name should always be aligned on the same x-position independent
604 // from the expansion-level shown in the name column
605 x
-= m_expansionArea
.right();
609 // The values for the size should be right aligned
610 m_textPos
[textId
].rx() += columnWidth
- requiredWidth
- 2 * option
.margin
;
619 QString
KFileItemListWidget::roleText(TextId textId
, const QVariant
& roleValue
) const
631 text
= roleValue
.toString();
635 if (data().value("isDir").toBool()) {
636 // The item represents a directory. Show the number of sub directories
637 // instead of the file size of the directory.
638 if (!roleValue
.isNull()) {
639 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
640 text
= i18ncp("@item:intable", "%1 item", "%1 items", size
);
643 const KIO::filesize_t size
= roleValue
.value
<KIO::filesize_t
>();
644 text
= KIO::convertSize(size
);
650 const QDateTime dateTime
= roleValue
.toDateTime();
651 text
= KGlobal::locale()->formatDateTime(dateTime
);
663 void KFileItemListWidget::drawPixmap(QPainter
* painter
, const QPixmap
& pixmap
)
665 const bool isHiddenItem
= m_text
[Name
].text().startsWith(QLatin1Char('.'));
668 opacity
= painter
->opacity();
669 painter
->setOpacity(opacity
* 0.3);
672 if (m_scaledPixmapSize
!= pixmap
.size()) {
673 QPixmap scaledPixmap
= pixmap
;
674 KPixmapModifier::scale(scaledPixmap
, m_scaledPixmapSize
);
675 painter
->drawPixmap(m_pixmapPos
, scaledPixmap
);
677 #ifdef KFILEITEMLISTWIDGET_DEBUG
678 painter
->setPen(Qt::green
);
679 painter
->drawRect(QRectF(m_pixmapPos
, QSizeF(scaledPixmap
.size())));
682 painter
->drawPixmap(m_pixmapPos
, pixmap
);
686 painter
->setOpacity(opacity
);
690 void KFileItemListWidget::drawFocusIndicator(QPainter
* painter
)
692 // Ideally style()->drawPrimitive(QStyle::PE_FrameFocusRect...)
693 // should be used, but Oxygen only draws indicators within classes
694 // derived from QAbstractItemView or Q3ListView. As a workaround
695 // the indicator is drawn manually. Code copied from oxygenstyle.cpp
696 // Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <hugo@oxygen-icons.org>
697 // TODO: Clarify with Oxygen maintainers how to proceed with this.
699 const KItemListStyleOption
& option
= styleOption();
700 const QPalette palette
= option
.palette
;
701 const QRect rect
= m_textsBoundingRect
.toRect().adjusted(0, 0, 0, -1);
703 QLinearGradient
gradient(rect
.bottomLeft(), rect
.bottomRight());
704 gradient
.setColorAt(0.0, Qt::transparent
);
705 gradient
.setColorAt(1.0, Qt::transparent
);
706 gradient
.setColorAt(0.2, palette
.color(QPalette::Text
));
707 gradient
.setColorAt(0.8, palette
.color(QPalette::Text
));
709 painter
->setRenderHint(QPainter::Antialiasing
, false);
710 painter
->setPen(QPen(gradient
, 1));
711 painter
->drawLine(rect
.bottomLeft(), rect
.bottomRight());
712 painter
->setRenderHint(QPainter::Antialiasing
, true);
715 QPixmap
KFileItemListWidget::pixmapForIcon(const QString
& name
, int size
)
717 const KIcon
icon(name
);
720 if (size
<= KIconLoader::SizeSmall
) {
721 requestedSize
= KIconLoader::SizeSmall
;
722 } else if (size
<= KIconLoader::SizeSmallMedium
) {
723 requestedSize
= KIconLoader::SizeSmallMedium
;
724 } else if (size
<= KIconLoader::SizeMedium
) {
725 requestedSize
= KIconLoader::SizeMedium
;
726 } else if (size
<= KIconLoader::SizeLarge
) {
727 requestedSize
= KIconLoader::SizeLarge
;
728 } else if (size
<= KIconLoader::SizeHuge
) {
729 requestedSize
= KIconLoader::SizeHuge
;
730 } else if (size
<= KIconLoader::SizeEnormous
) {
731 requestedSize
= KIconLoader::SizeEnormous
;
732 } else if (size
<= KIconLoader::SizeEnormous
* 2) {
733 requestedSize
= KIconLoader::SizeEnormous
* 2;
735 requestedSize
= size
;
738 QPixmap pixmap
= icon
.pixmap(requestedSize
, requestedSize
);
739 if (requestedSize
!= size
) {
740 KPixmapModifier::scale(pixmap
, QSize(size
, size
));
746 KFileItemListWidget::TextId
KFileItemListWidget::roleTextId(const QByteArray
& role
)
748 static QHash
<QByteArray
, TextId
> rolesHash
;
749 if (rolesHash
.isEmpty()) {
750 rolesHash
.insert("name", Name
);
751 rolesHash
.insert("size", Size
);
752 rolesHash
.insert("date", Date
);
753 rolesHash
.insert("permissions", Permissions
);
754 rolesHash
.insert("owner", Owner
);
755 rolesHash
.insert("group", Group
);
756 rolesHash
.insert("type", Type
);
757 rolesHash
.insert("destination", Destination
);
758 rolesHash
.insert("path", Path
);
761 return rolesHash
.value(role
);
764 #include "kfileitemlistwidget.moc"