]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kstandarditemlistwidget.cpp
Remove some dubious code for now (crash less)
[dolphin.git] / src / kitemviews / kstandarditemlistwidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "kstandarditemlistwidget.h"
21
22 #include "kfileitemlistview.h"
23 #include "kfileitemmodel.h"
24
25 #include <KIcon>
26 #include <KIconEffect>
27 #include <KIconLoader>
28 #include <KLocale>
29 #include <kratingpainter.h>
30 #include <KStringHandler>
31 #include <KDebug>
32
33 #include "private/kfileitemclipboard.h"
34 #include "private/kitemlistroleeditor.h"
35 #include "private/kpixmapmodifier.h"
36
37 #include <QFontMetricsF>
38 #include <QGraphicsScene>
39 #include <QGraphicsSceneResizeEvent>
40 #include <QGraphicsView>
41 #include <QPainter>
42 #include <QStyleOption>
43 #include <QTextLayout>
44 #include <QTextLine>
45
46 // #define KSTANDARDITEMLISTWIDGET_DEBUG
47
48 KStandardItemListWidgetInformant::KStandardItemListWidgetInformant() :
49 KItemListWidgetInformant()
50 {
51 }
52
53 KStandardItemListWidgetInformant::~KStandardItemListWidgetInformant()
54 {
55 }
56
57 QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemListView* view) const
58 {
59 const QHash<QByteArray, QVariant> values = view->model()->data(index);
60 const KItemListStyleOption& option = view->styleOption();
61 const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
62
63 switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
64 case KStandardItemListWidget::IconsLayout: {
65 const QString text = KStringHandler::preProcessWrap(values["text"].toString());
66
67 const qreal itemWidth = view->itemSize().width();
68 const qreal maxWidth = itemWidth - 2 * option.padding;
69 QTextLine line;
70
71 // Calculate the number of lines required for wrapping the name
72 QTextOption textOption(Qt::AlignHCenter);
73 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
74
75 qreal textHeight = 0;
76 QTextLayout layout(text, option.font);
77 layout.setTextOption(textOption);
78 layout.beginLayout();
79 while ((line = layout.createLine()).isValid()) {
80 line.setLineWidth(maxWidth);
81 line.naturalTextWidth();
82 textHeight += line.height();
83 }
84 layout.endLayout();
85
86 // Add one line for each additional information
87 textHeight += additionalRolesCount * option.fontMetrics.lineSpacing();
88
89 const qreal maxTextHeight = option.maxTextSize.height();
90 if (maxTextHeight > 0 && textHeight > maxTextHeight) {
91 textHeight = maxTextHeight;
92 }
93
94 return QSizeF(itemWidth, textHeight + option.iconSize + option.padding * 3);
95 }
96
97 case KStandardItemListWidget::CompactLayout: {
98 // For each row exactly one role is shown. Calculate the maximum required width that is necessary
99 // to show all roles without horizontal clipping.
100 qreal maximumRequiredWidth = 0.0;
101
102 foreach (const QByteArray& role, view->visibleRoles()) {
103 const QString text = roleText(role, values);
104 const qreal requiredWidth = option.fontMetrics.width(text);
105 maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth);
106 }
107
108 qreal width = option.padding * 4 + option.iconSize + maximumRequiredWidth;
109 const qreal maxWidth = option.maxTextSize.width();
110 if (maxWidth > 0 && width > maxWidth) {
111 width = maxWidth;
112 }
113 const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.lineSpacing());
114 return QSizeF(width, height);
115 }
116
117 case KStandardItemListWidget::DetailsLayout: {
118 const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
119 return QSizeF(-1, height);
120 }
121
122 default:
123 Q_ASSERT(false);
124 break;
125 }
126
127 return QSize();
128 }
129
130 qreal KStandardItemListWidgetInformant::preferredRoleColumnWidth(const QByteArray& role,
131 int index,
132 const KItemListView* view) const
133 {
134 const QHash<QByteArray, QVariant> values = view->model()->data(index);
135 const KItemListStyleOption& option = view->styleOption();
136
137 const QString text = roleText(role, values);
138 qreal width = KStandardItemListWidget::columnPadding(option);
139
140 if (role == "rating") {
141 width += KStandardItemListWidget::preferredRatingSize(option).width();
142 } else {
143 width += option.fontMetrics.width(text);
144
145 if (role == "text") {
146 if (view->supportsItemExpanding()) {
147 // Increase the width by the expansion-toggle and the current expansion level
148 const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt();
149 const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height());
150 width += (expandedParentsCount + 1) * height;
151 }
152
153 // Increase the width by the required space for the icon
154 width += option.padding * 2 + option.iconSize;
155 }
156 }
157
158 return width;
159 }
160
161 QString KStandardItemListWidgetInformant::roleText(const QByteArray& role,
162 const QHash<QByteArray, QVariant>& values) const
163 {
164 if (role == "rating") {
165 // Always use an empty text, as the rating is shown by the image m_rating.
166 return QString();
167 }
168 return values.value(role).toString();
169 }
170
171 KStandardItemListWidget::KStandardItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) :
172 KItemListWidget(informant, parent),
173 m_isCut(false),
174 m_isHidden(false),
175 m_customizedFont(),
176 m_customizedFontMetrics(m_customizedFont),
177 m_isExpandable(false),
178 m_supportsItemExpanding(false),
179 m_dirtyLayout(true),
180 m_dirtyContent(true),
181 m_dirtyContentRoles(),
182 m_layout(IconsLayout),
183 m_pixmapPos(),
184 m_pixmap(),
185 m_scaledPixmapSize(),
186 m_iconRect(),
187 m_hoverPixmap(),
188 m_textInfo(),
189 m_textRect(),
190 m_sortedVisibleRoles(),
191 m_expansionArea(),
192 m_customTextColor(),
193 m_additionalInfoTextColor(),
194 m_overlay(),
195 m_rating(),
196 m_roleEditor(0)
197 {
198 }
199
200 KStandardItemListWidget::~KStandardItemListWidget()
201 {
202 qDeleteAll(m_textInfo);
203 m_textInfo.clear();
204
205 delete m_roleEditor;
206 }
207
208 void KStandardItemListWidget::setLayout(Layout layout)
209 {
210 if (m_layout != layout) {
211 m_layout = layout;
212 m_dirtyLayout = true;
213 updateAdditionalInfoTextColor();
214 update();
215 }
216 }
217
218 KStandardItemListWidget::Layout KStandardItemListWidget::layout() const
219 {
220 return m_layout;
221 }
222
223 void KStandardItemListWidget::setSupportsItemExpanding(bool supportsItemExpanding)
224 {
225 if (m_supportsItemExpanding != supportsItemExpanding) {
226 m_supportsItemExpanding = supportsItemExpanding;
227 m_dirtyLayout = true;
228 update();
229 }
230 }
231
232 bool KStandardItemListWidget::supportsItemExpanding() const
233 {
234 return m_supportsItemExpanding;
235 }
236
237 void KStandardItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
238 {
239 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
240
241 KItemListWidget::paint(painter, option, widget);
242
243 if (!m_expansionArea.isEmpty()) {
244 drawSiblingsInformation(painter);
245 }
246
247 const KItemListStyleOption& itemListStyleOption = styleOption();
248 if (isHovered()) {
249 // Blend the unhovered and hovered pixmap if the hovering
250 // animation is ongoing
251 if (hoverOpacity() < 1.0) {
252 drawPixmap(painter, m_pixmap);
253 }
254
255 const qreal opacity = painter->opacity();
256 painter->setOpacity(hoverOpacity() * opacity);
257 drawPixmap(painter, m_hoverPixmap);
258 painter->setOpacity(opacity);
259 } else {
260 drawPixmap(painter, m_pixmap);
261 }
262
263 painter->setFont(m_customizedFont);
264 painter->setPen(m_isHidden ? m_additionalInfoTextColor : textColor());
265 const TextInfo* textInfo = m_textInfo.value("text");
266 painter->drawStaticText(textInfo->pos, textInfo->staticText);
267
268 bool clipAdditionalInfoBounds = false;
269 if (m_supportsItemExpanding) {
270 // Prevent a possible overlapping of the additional-information texts
271 // with the icon. This can happen if the user has minimized the width
272 // of the name-column to a very small value.
273 const qreal minX = m_pixmapPos.x() + m_pixmap.width() + 4 * itemListStyleOption.padding;
274 if (textInfo->pos.x() + columnWidth("text") > minX) {
275 clipAdditionalInfoBounds = true;
276 painter->save();
277 painter->setClipRect(minX, 0, size().width() - minX, size().height(), Qt::IntersectClip);
278 }
279 }
280
281 painter->setPen(m_additionalInfoTextColor);
282 painter->setFont(m_customizedFont);
283
284 for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) {
285 const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]);
286 painter->drawStaticText(textInfo->pos, textInfo->staticText);
287 }
288
289 if (!m_rating.isNull()) {
290 const TextInfo* ratingTextInfo = m_textInfo.value("rating");
291 QPointF pos = ratingTextInfo->pos;
292 const Qt::Alignment align = ratingTextInfo->staticText.textOption().alignment();
293 if (align & Qt::AlignHCenter) {
294 pos.rx() += (size().width() - m_rating.width()) / 2 - 2;
295 }
296 painter->drawPixmap(pos, m_rating);
297 }
298
299 if (clipAdditionalInfoBounds) {
300 painter->restore();
301 }
302
303 #ifdef KSTANDARDITEMLISTWIDGET_DEBUG
304 painter->setBrush(Qt::NoBrush);
305 painter->setPen(Qt::green);
306 painter->drawRect(m_iconRect);
307
308 painter->setPen(Qt::red);
309 painter->drawText(QPointF(0, m_customizedFontMetrics.height()), QString::number(index()));
310 painter->drawRect(rect());
311 #endif
312 }
313
314 QRectF KStandardItemListWidget::iconRect() const
315 {
316 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
317 return m_iconRect;
318 }
319
320 QRectF KStandardItemListWidget::textRect() const
321 {
322 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
323 return m_textRect;
324 }
325
326 QRectF KStandardItemListWidget::textFocusRect() const
327 {
328 // In the compact- and details-layout a larger textRect() is returned to be aligned
329 // with the iconRect(). This is useful to have a larger selection/hover-area
330 // when having a quite large icon size but only one line of text. Still the
331 // focus rectangle should be shown as narrow as possible around the text.
332
333 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
334
335 switch (m_layout) {
336 case CompactLayout: {
337 QRectF rect = m_textRect;
338 const TextInfo* topText = m_textInfo.value(m_sortedVisibleRoles.first());
339 const TextInfo* bottomText = m_textInfo.value(m_sortedVisibleRoles.last());
340 rect.setTop(topText->pos.y());
341 rect.setBottom(bottomText->pos.y() + bottomText->staticText.size().height());
342 return rect;
343 }
344
345 case DetailsLayout: {
346 QRectF rect = m_textRect;
347 const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles.first());
348 rect.setTop(textInfo->pos.y());
349 rect.setBottom(textInfo->pos.y() + textInfo->staticText.size().height());
350
351 const KItemListStyleOption& option = styleOption();
352 if (option.extendedSelectionRegion) {
353 const QString text = textInfo->staticText.text();
354 rect.setWidth(m_customizedFontMetrics.width(text) + 2 * option.padding);
355 }
356
357 return rect;
358 }
359
360 default:
361 break;
362 }
363
364 return m_textRect;
365 }
366
367 QRectF KStandardItemListWidget::expansionToggleRect() const
368 {
369 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
370 return m_isExpandable ? m_expansionArea : QRectF();
371 }
372
373 QRectF KStandardItemListWidget::selectionToggleRect() const
374 {
375 const_cast<KStandardItemListWidget*>(this)->triggerCacheRefreshing();
376
377 const int iconHeight = styleOption().iconSize;
378
379 int toggleSize = KIconLoader::SizeSmall;
380 if (iconHeight >= KIconLoader::SizeEnormous) {
381 toggleSize = KIconLoader::SizeMedium;
382 } else if (iconHeight >= KIconLoader::SizeLarge) {
383 toggleSize = KIconLoader::SizeSmallMedium;
384 }
385
386 QPointF pos = iconRect().topLeft();
387
388 // If the selection toggle has a very small distance to the
389 // widget borders, the size of the selection toggle will get
390 // increased to prevent an accidental clicking of the item
391 // when trying to hit the toggle.
392 const int widgetHeight = size().height();
393 const int widgetWidth = size().width();
394 const int minMargin = 2;
395
396 if (toggleSize + minMargin * 2 >= widgetHeight) {
397 pos.rx() -= (widgetHeight - toggleSize) / 2;
398 toggleSize = widgetHeight;
399 pos.setY(0);
400 }
401 if (toggleSize + minMargin * 2 >= widgetWidth) {
402 pos.ry() -= (widgetWidth - toggleSize) / 2;
403 toggleSize = widgetWidth;
404 pos.setX(0);
405 }
406
407 return QRectF(pos, QSizeF(toggleSize, toggleSize));
408 }
409
410 QPixmap KStandardItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option,
411 QWidget* widget)
412 {
413 QPixmap pixmap = KItemListWidget::createDragPixmap(option, widget);
414 if (m_layout != DetailsLayout) {
415 return pixmap;
416 }
417
418 // Only return the content of the text-column as pixmap
419 const int leftClip = m_pixmapPos.x();
420
421 const TextInfo* textInfo = m_textInfo.value("text");
422 const int rightClip = textInfo->pos.x() +
423 textInfo->staticText.size().width() +
424 2 * styleOption().padding;
425
426 QPixmap clippedPixmap(rightClip - leftClip + 1, pixmap.height());
427 clippedPixmap.fill(Qt::transparent);
428
429 QPainter painter(&clippedPixmap);
430 painter.drawPixmap(-leftClip, 0, pixmap);
431
432 return clippedPixmap;
433 }
434
435
436 KItemListWidgetInformant* KStandardItemListWidget::createInformant()
437 {
438 return new KStandardItemListWidgetInformant();
439 }
440
441 void KStandardItemListWidget::invalidateCache()
442 {
443 m_dirtyLayout = true;
444 m_dirtyContent = true;
445 }
446
447 void KStandardItemListWidget::refreshCache()
448 {
449 }
450
451 bool KStandardItemListWidget::isRoleRightAligned(const QByteArray& role) const
452 {
453 Q_UNUSED(role);
454 return false;
455 }
456
457 bool KStandardItemListWidget::isHidden() const
458 {
459 return false;
460 }
461
462 QFont KStandardItemListWidget::customizedFont(const QFont& baseFont) const
463 {
464 return baseFont;
465 }
466
467 QPalette::ColorRole KStandardItemListWidget::normalTextColorPalette() const
468 {
469 return QPalette::Text;
470 }
471
472 void KStandardItemListWidget::setTextColor(const QColor& color)
473 {
474 if (color != m_customTextColor) {
475 m_customTextColor = color;
476 updateAdditionalInfoTextColor();
477 update();
478 }
479 }
480
481 QColor KStandardItemListWidget::textColor() const
482 {
483 if (m_customTextColor.isValid() && !isSelected()) {
484 return m_customTextColor;
485 }
486
487 const QPalette::ColorGroup group = isActiveWindow() ? QPalette::Active : QPalette::Inactive;
488 const QPalette::ColorRole role = isSelected() ? QPalette::HighlightedText : normalTextColorPalette();
489 return styleOption().palette.brush(group, role).color();
490 }
491
492 void KStandardItemListWidget::setOverlay(const QPixmap& overlay)
493 {
494 m_overlay = overlay;
495 m_dirtyContent = true;
496 update();
497 }
498
499 QPixmap KStandardItemListWidget::overlay() const
500 {
501 return m_overlay;
502 }
503
504
505 QString KStandardItemListWidget::roleText(const QByteArray& role,
506 const QHash<QByteArray, QVariant>& values) const
507 {
508 return static_cast<const KStandardItemListWidgetInformant*>(informant())->roleText(role, values);
509 }
510
511 void KStandardItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current,
512 const QSet<QByteArray>& roles)
513 {
514 Q_UNUSED(current);
515
516 m_dirtyContent = true;
517
518 QSet<QByteArray> dirtyRoles;
519 if (roles.isEmpty()) {
520 dirtyRoles = visibleRoles().toSet();
521 } else {
522 dirtyRoles = roles;
523 }
524
525 // The icon-state might depend from other roles and hence is
526 // marked as dirty whenever a role has been changed
527 dirtyRoles.insert("iconPixmap");
528 dirtyRoles.insert("iconName");
529
530 QSetIterator<QByteArray> it(dirtyRoles);
531 while (it.hasNext()) {
532 const QByteArray& role = it.next();
533 m_dirtyContentRoles.insert(role);
534 }
535 }
536
537 void KStandardItemListWidget::visibleRolesChanged(const QList<QByteArray>& current,
538 const QList<QByteArray>& previous)
539 {
540 Q_UNUSED(previous);
541 m_sortedVisibleRoles = current;
542 m_dirtyLayout = true;
543 }
544
545 void KStandardItemListWidget::columnWidthChanged(const QByteArray& role,
546 qreal current,
547 qreal previous)
548 {
549 Q_UNUSED(role);
550 Q_UNUSED(current);
551 Q_UNUSED(previous);
552 m_dirtyLayout = true;
553 }
554
555 void KStandardItemListWidget::styleOptionChanged(const KItemListStyleOption& current,
556 const KItemListStyleOption& previous)
557 {
558 Q_UNUSED(current);
559 Q_UNUSED(previous);
560 updateAdditionalInfoTextColor();
561 m_dirtyLayout = true;
562 }
563
564 void KStandardItemListWidget::hoveredChanged(bool hovered)
565 {
566 Q_UNUSED(hovered);
567 m_dirtyLayout = true;
568 }
569
570 void KStandardItemListWidget::selectedChanged(bool selected)
571 {
572 Q_UNUSED(selected);
573 updateAdditionalInfoTextColor();
574 m_dirtyContent = true;
575 }
576
577 void KStandardItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous)
578 {
579 Q_UNUSED(current);
580 Q_UNUSED(previous);
581 m_dirtyLayout = true;
582 }
583
584 void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
585 {
586 Q_UNUSED(previous);
587
588 QGraphicsView* parent = scene()->views()[0];
589 if (current.isEmpty() || !parent || current != "text") {
590 if (m_roleEditor) {
591 emit roleEditingCanceled(index(), current, data().value(current));
592 m_roleEditor->deleteLater();
593 m_roleEditor = 0;
594 }
595 return;
596 }
597
598 Q_ASSERT(!m_roleEditor);
599
600 const TextInfo* textInfo = m_textInfo.value("text");
601
602 m_roleEditor = new KItemListRoleEditor(parent);
603 m_roleEditor->setIndex(index());
604 m_roleEditor->setRole(current);
605 m_roleEditor->setFont(styleOption().font);
606
607 const QString text = data().value(current).toString();
608 m_roleEditor->setPlainText(text);
609
610 QTextOption textOption = textInfo->staticText.textOption();
611 m_roleEditor->document()->setDefaultTextOption(textOption);
612
613 // Select the text without MIME-type extension
614 // TODO: This is file-item-specific and should be moved
615 // into KFileItemListWidget.
616 int selectionLength = text.length();
617
618 const QString extension = KMimeType::extractKnownExtension(text);
619 if (extension.isEmpty()) {
620 // For an unknown extension just exclude the extension after
621 // the last point. This does not work for multiple extensions like
622 // *.tar.gz but usually this is anyhow a known extension.
623 selectionLength = text.lastIndexOf(QLatin1Char('.'));
624 } else {
625 selectionLength -= extension.length() + 1;
626 }
627
628 if (selectionLength > 0) {
629 QTextCursor cursor = m_roleEditor->textCursor();
630 cursor.movePosition(QTextCursor::StartOfBlock);
631 cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, selectionLength);
632 m_roleEditor->setTextCursor(cursor);
633 }
634
635 connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
636 this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
637 connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
638 this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
639
640 // Adjust the geometry of the editor
641 QRectF rect = roleEditingRect(current);
642 const int frameWidth = m_roleEditor->frameWidth();
643 rect.adjust(-frameWidth, -frameWidth, frameWidth, frameWidth);
644 rect.translate(pos());
645 if (rect.right() > parent->width()) {
646 rect.setWidth(parent->width() - rect.left());
647 }
648 m_roleEditor->setGeometry(rect.toRect());
649 m_roleEditor->show();
650 m_roleEditor->setFocus();
651 }
652
653 void KStandardItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
654 {
655 if (m_roleEditor) {
656 setEditedRole(QByteArray());
657 Q_ASSERT(!m_roleEditor);
658 }
659
660 KItemListWidget::resizeEvent(event);
661
662 m_dirtyLayout = true;
663 }
664
665 void KStandardItemListWidget::showEvent(QShowEvent* event)
666 {
667 KItemListWidget::showEvent(event);
668
669 // Listen to changes of the clipboard to mark the item as cut/uncut
670 KFileItemClipboard* clipboard = KFileItemClipboard::instance();
671
672 const KUrl itemUrl = data().value("url").value<KUrl>();
673 m_isCut = clipboard->isCut(itemUrl);
674
675 connect(clipboard, SIGNAL(cutItemsChanged()),
676 this, SLOT(slotCutItemsChanged()));
677 }
678
679 void KStandardItemListWidget::hideEvent(QHideEvent* event)
680 {
681 disconnect(KFileItemClipboard::instance(), SIGNAL(cutItemsChanged()),
682 this, SLOT(slotCutItemsChanged()));
683
684 KItemListWidget::hideEvent(event);
685 }
686
687 void KStandardItemListWidget::slotCutItemsChanged()
688 {
689 const KUrl itemUrl = data().value("url").value<KUrl>();
690 const bool isCut = KFileItemClipboard::instance()->isCut(itemUrl);
691 if (m_isCut != isCut) {
692 m_isCut = isCut;
693 m_pixmap = QPixmap();
694 m_dirtyContent = true;
695 update();
696 }
697 }
698
699 void KStandardItemListWidget::slotRoleEditingCanceled(int index,
700 const QByteArray& role,
701 const QVariant& value)
702 {
703 closeRoleEditor();
704 emit roleEditingCanceled(index, role, value);
705 setEditedRole(QByteArray());
706 }
707
708 void KStandardItemListWidget::slotRoleEditingFinished(int index,
709 const QByteArray& role,
710 const QVariant& value)
711 {
712 closeRoleEditor();
713 emit roleEditingFinished(index, role, value);
714 setEditedRole(QByteArray());
715 }
716
717 void KStandardItemListWidget::triggerCacheRefreshing()
718 {
719 if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
720 return;
721 }
722
723 refreshCache();
724
725 const QHash<QByteArray, QVariant> values = data();
726 m_isExpandable = m_supportsItemExpanding && values["isExpandable"].toBool();
727 m_isHidden = isHidden();
728 m_customizedFont = customizedFont(styleOption().font);
729 m_customizedFontMetrics = QFontMetrics(m_customizedFont);
730
731 updateExpansionArea();
732 updateTextsCache();
733 updatePixmapCache();
734
735 m_dirtyLayout = false;
736 m_dirtyContent = false;
737 m_dirtyContentRoles.clear();
738 }
739
740 void KStandardItemListWidget::updateExpansionArea()
741 {
742 if (m_supportsItemExpanding) {
743 const QHash<QByteArray, QVariant> values = data();
744 Q_ASSERT(values.contains("expandedParentsCount"));
745 const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt();
746 if (expandedParentsCount >= 0) {
747 const qreal widgetHeight = size().height();
748 const qreal inc = (widgetHeight - KIconLoader::SizeSmall) / 2;
749 const qreal x = expandedParentsCount * widgetHeight + inc;
750 const qreal y = inc;
751 m_expansionArea = QRectF(x, y, KIconLoader::SizeSmall, KIconLoader::SizeSmall);
752 return;
753 }
754 }
755
756 m_expansionArea = QRectF();
757 }
758
759 void KStandardItemListWidget::updatePixmapCache()
760 {
761 // Precondition: Requires already updated m_textPos values to calculate
762 // the remaining height when the alignment is vertical.
763
764 const QSizeF widgetSize = size();
765 const bool iconOnTop = (m_layout == IconsLayout);
766 const KItemListStyleOption& option = styleOption();
767 const qreal padding = option.padding;
768
769 const int maxIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : option.iconSize;
770 const int maxIconHeight = option.iconSize;
771
772 const QHash<QByteArray, QVariant> values = data();
773
774 bool updatePixmap = (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight);
775 if (!updatePixmap && m_dirtyContent) {
776 updatePixmap = m_dirtyContentRoles.isEmpty()
777 || m_dirtyContentRoles.contains("iconPixmap")
778 || m_dirtyContentRoles.contains("iconName")
779 || m_dirtyContentRoles.contains("iconOverlays");
780 }
781
782 if (updatePixmap) {
783 m_pixmap = values["iconPixmap"].value<QPixmap>();
784 if (m_pixmap.isNull()) {
785 // Use the icon that fits to the MIME-type
786 QString iconName = values["iconName"].toString();
787 if (iconName.isEmpty()) {
788 // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
789 // use a generic icon as fallback
790 iconName = QLatin1String("unknown");
791 }
792 m_pixmap = pixmapForIcon(iconName, maxIconHeight);
793 } else if (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight) {
794 // A custom pixmap has been applied. Assure that the pixmap
795 // is scaled to the maximum available size.
796 KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight));
797 }
798
799 const QStringList overlays = values["iconOverlays"].toStringList();
800
801 // Strangely KFileItem::overlays() returns empty string-values, so
802 // we need to check first whether an overlay must be drawn at all.
803 // It is more efficient to do it here, as KIconLoader::drawOverlays()
804 // assumes that an overlay will be drawn and has some additional
805 // setup time.
806 foreach (const QString& overlay, overlays) {
807 if (!overlay.isEmpty()) {
808 // There is at least one overlay, draw all overlays above m_pixmap
809 // and cancel the check
810 KIconLoader::global()->drawOverlays(overlays, m_pixmap, KIconLoader::Desktop);
811 break;
812 }
813 }
814
815 if (m_isCut) {
816 KIconEffect* effect = KIconLoader::global()->iconEffect();
817 m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
818 }
819
820 if (m_isHidden) {
821 KIconEffect::semiTransparent(m_pixmap);
822 }
823
824 if (isSelected()) {
825 const QColor color = palette().brush(QPalette::Normal, QPalette::Highlight).color();
826 QImage image = m_pixmap.toImage();
827 KIconEffect::colorize(image, color, 1.0f);
828 m_pixmap = QPixmap::fromImage(image);
829 }
830 }
831
832 if (!m_overlay.isNull()) {
833 QPainter painter(&m_pixmap);
834 painter.drawPixmap(0, m_pixmap.height() - m_overlay.height(), m_overlay);
835 }
836
837 int scaledIconSize = 0;
838 if (iconOnTop) {
839 const TextInfo* textInfo = m_textInfo.value("text");
840 scaledIconSize = static_cast<int>(textInfo->pos.y() - 2 * padding);
841 } else {
842 const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1;
843 const qreal requiredTextHeight = textRowsCount * m_customizedFontMetrics.height();
844 scaledIconSize = (requiredTextHeight < maxIconHeight) ?
845 widgetSize.height() - 2 * padding : maxIconHeight;
846 }
847
848 const int maxScaledIconWidth = iconOnTop ? widgetSize.width() - 2 * padding : scaledIconSize;
849 const int maxScaledIconHeight = scaledIconSize;
850
851 m_scaledPixmapSize = m_pixmap.size();
852 m_scaledPixmapSize.scale(maxScaledIconWidth, maxScaledIconHeight, Qt::KeepAspectRatio);
853
854 if (iconOnTop) {
855 // Center horizontally and align on bottom within the icon-area
856 m_pixmapPos.setX((widgetSize.width() - m_scaledPixmapSize.width()) / 2);
857 m_pixmapPos.setY(padding + scaledIconSize - m_scaledPixmapSize.height());
858 } else {
859 // Center horizontally and vertically within the icon-area
860 const TextInfo* textInfo = m_textInfo.value("text");
861 m_pixmapPos.setX(textInfo->pos.x() - 2 * padding
862 - (scaledIconSize + m_scaledPixmapSize.width()) / 2);
863 m_pixmapPos.setY(padding
864 + (scaledIconSize - m_scaledPixmapSize.height()) / 2);
865 }
866
867 m_iconRect = QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize));
868
869 // Prepare the pixmap that is used when the item gets hovered
870 if (isHovered()) {
871 m_hoverPixmap = m_pixmap;
872 KIconEffect* effect = KIconLoader::global()->iconEffect();
873 // In the KIconLoader terminology, active = hover.
874 if (effect->hasEffect(KIconLoader::Desktop, KIconLoader::ActiveState)) {
875 m_hoverPixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState);
876 } else {
877 m_hoverPixmap = m_pixmap;
878 }
879 } else if (hoverOpacity() <= 0.0) {
880 // No hover animation is ongoing. Clear m_hoverPixmap to save memory.
881 m_hoverPixmap = QPixmap();
882 }
883 }
884
885 void KStandardItemListWidget::updateTextsCache()
886 {
887 QTextOption textOption;
888 switch (m_layout) {
889 case IconsLayout:
890 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
891 textOption.setAlignment(Qt::AlignHCenter);
892 break;
893 case CompactLayout:
894 case DetailsLayout:
895 textOption.setAlignment(Qt::AlignLeft);
896 textOption.setWrapMode(QTextOption::NoWrap);
897 break;
898 default:
899 Q_ASSERT(false);
900 break;
901 }
902
903 qDeleteAll(m_textInfo);
904 m_textInfo.clear();
905 for (int i = 0; i < m_sortedVisibleRoles.count(); ++i) {
906 TextInfo* textInfo = new TextInfo();
907 textInfo->staticText.setTextFormat(Qt::PlainText);
908 textInfo->staticText.setPerformanceHint(QStaticText::AggressiveCaching);
909 textInfo->staticText.setTextOption(textOption);
910 m_textInfo.insert(m_sortedVisibleRoles[i], textInfo);
911 }
912
913 switch (m_layout) {
914 case IconsLayout: updateIconsLayoutTextCache(); break;
915 case CompactLayout: updateCompactLayoutTextCache(); break;
916 case DetailsLayout: updateDetailsLayoutTextCache(); break;
917 default: Q_ASSERT(false); break;
918 }
919
920 const TextInfo* ratingTextInfo = m_textInfo.value("rating");
921 if (ratingTextInfo) {
922 // The text of the rating-role has been set to empty to get
923 // replaced by a rating-image showing the rating as stars.
924 const KItemListStyleOption& option = styleOption();
925 QSizeF ratingSize = preferredRatingSize(option);
926
927 const qreal availableWidth = (m_layout == DetailsLayout)
928 ? columnWidth("rating") - columnPadding(option)
929 : size().width();
930 if (ratingSize.width() > availableWidth) {
931 ratingSize.rwidth() = availableWidth;
932 }
933 m_rating = QPixmap(ratingSize.toSize());
934 m_rating.fill(Qt::transparent);
935
936 QPainter painter(&m_rating);
937 const QRect rect(0, 0, m_rating.width(), m_rating.height());
938 const int rating = data().value("rating").toInt();
939 KRatingPainter::paintRating(&painter, rect, Qt::AlignJustify | Qt::AlignVCenter, rating);
940 } else if (!m_rating.isNull()) {
941 m_rating = QPixmap();
942 }
943 }
944
945 void KStandardItemListWidget::updateIconsLayoutTextCache()
946 {
947 // +------+
948 // | Icon |
949 // +------+
950 //
951 // Name role that
952 // might get wrapped above
953 // several lines.
954 // Additional role 1
955 // Additional role 2
956
957 const QHash<QByteArray, QVariant> values = data();
958
959 const KItemListStyleOption& option = styleOption();
960 const qreal padding = option.padding;
961 const qreal maxWidth = size().width() - 2 * padding;
962 const qreal widgetHeight = size().height();
963 const qreal lineSpacing = m_customizedFontMetrics.lineSpacing();
964
965 // Initialize properties for the "text" role. It will be used as anchor
966 // for initializing the position of the other roles.
967 TextInfo* nameTextInfo = m_textInfo.value("text");
968 const QString nameText = KStringHandler::preProcessWrap(values["text"].toString());
969 nameTextInfo->staticText.setText(nameText);
970
971 // Calculate the number of lines required for the name and the required width
972 qreal nameWidth = 0;
973 qreal nameHeight = 0;
974 QTextLine line;
975
976 const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0);
977 const int maxNameLines = (option.maxTextSize.height() / int(lineSpacing)) - additionalRolesCount;
978
979 QTextLayout layout(nameTextInfo->staticText.text(), m_customizedFont);
980 layout.setTextOption(nameTextInfo->staticText.textOption());
981 layout.beginLayout();
982 int nameLineIndex = 0;
983 while ((line = layout.createLine()).isValid()) {
984 line.setLineWidth(maxWidth);
985 nameWidth = qMax(nameWidth, line.naturalTextWidth());
986 nameHeight += line.height();
987
988 ++nameLineIndex;
989 if (nameLineIndex == maxNameLines) {
990 // The maximum number of textlines has been reached. If this is
991 // the case provide an elided text if necessary.
992 const int textLength = line.textStart() + line.textLength();
993 if (textLength < nameText.length()) {
994 // Elide the last line of the text
995 QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
996 lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
997 Qt::ElideRight,
998 line.naturalTextWidth() - 1);
999 const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
1000 nameTextInfo->staticText.setText(elidedText);
1001 }
1002 break;
1003 }
1004 }
1005 layout.endLayout();
1006
1007 // Use one line for each additional information
1008 nameTextInfo->staticText.setTextWidth(maxWidth);
1009 nameTextInfo->pos = QPointF(padding, widgetHeight -
1010 nameHeight -
1011 additionalRolesCount * lineSpacing -
1012 padding);
1013 m_textRect = QRectF(padding + (maxWidth - nameWidth) / 2,
1014 nameTextInfo->pos.y(),
1015 nameWidth,
1016 nameHeight);
1017
1018 // Calculate the position for each additional information
1019 qreal y = nameTextInfo->pos.y() + nameHeight;
1020 foreach (const QByteArray& role, m_sortedVisibleRoles) {
1021 if (role == "text") {
1022 continue;
1023 }
1024
1025 const QString text = roleText(role, values);
1026 TextInfo* textInfo = m_textInfo.value(role);
1027 textInfo->staticText.setText(text);
1028
1029 qreal requiredWidth = 0;
1030
1031 QTextLayout layout(text, m_customizedFont);
1032 QTextOption textOption;
1033 textOption.setWrapMode(QTextOption::NoWrap);
1034 layout.setTextOption(textOption);
1035
1036 layout.beginLayout();
1037 QTextLine textLine = layout.createLine();
1038 if (textLine.isValid()) {
1039 textLine.setLineWidth(maxWidth);
1040 requiredWidth = textLine.naturalTextWidth();
1041 if (requiredWidth > maxWidth) {
1042 const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
1043 textInfo->staticText.setText(elidedText);
1044 requiredWidth = m_customizedFontMetrics.width(elidedText);
1045 } else if (role == "rating") {
1046 // Use the width of the rating pixmap, because the rating text is empty.
1047 requiredWidth = m_rating.width();
1048 }
1049 }
1050 layout.endLayout();
1051
1052 textInfo->pos = QPointF(padding, y);
1053 textInfo->staticText.setTextWidth(maxWidth);
1054
1055 const QRectF textRect(padding + (maxWidth - requiredWidth) / 2, y, requiredWidth, lineSpacing);
1056 m_textRect |= textRect;
1057
1058 y += lineSpacing;
1059 }
1060
1061 // Add a padding to the text rectangle
1062 m_textRect.adjust(-padding, -padding, padding, padding);
1063 }
1064
1065 void KStandardItemListWidget::updateCompactLayoutTextCache()
1066 {
1067 // +------+ Name role
1068 // | Icon | Additional role 1
1069 // +------+ Additional role 2
1070
1071 const QHash<QByteArray, QVariant> values = data();
1072
1073 const KItemListStyleOption& option = styleOption();
1074 const qreal widgetHeight = size().height();
1075 const qreal lineSpacing = m_customizedFontMetrics.lineSpacing();
1076 const qreal textLinesHeight = qMax(visibleRoles().count(), 1) * lineSpacing;
1077 const int scaledIconSize = (textLinesHeight < option.iconSize) ? widgetHeight - 2 * option.padding : option.iconSize;
1078
1079 qreal maximumRequiredTextWidth = 0;
1080 const qreal x = option.padding * 3 + scaledIconSize;
1081 qreal y = qRound((widgetHeight - textLinesHeight) / 2);
1082 const qreal maxWidth = size().width() - x - option.padding;
1083 foreach (const QByteArray& role, m_sortedVisibleRoles) {
1084 const QString text = roleText(role, values);
1085 TextInfo* textInfo = m_textInfo.value(role);
1086 textInfo->staticText.setText(text);
1087
1088 qreal requiredWidth = m_customizedFontMetrics.width(text);
1089 if (requiredWidth > maxWidth) {
1090 requiredWidth = maxWidth;
1091 const QString elidedText = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, maxWidth);
1092 textInfo->staticText.setText(elidedText);
1093 }
1094
1095 textInfo->pos = QPointF(x, y);
1096 textInfo->staticText.setTextWidth(maxWidth);
1097
1098 maximumRequiredTextWidth = qMax(maximumRequiredTextWidth, requiredWidth);
1099
1100 y += lineSpacing;
1101 }
1102
1103 m_textRect = QRectF(x - option.padding, 0, maximumRequiredTextWidth + 2 * option.padding, widgetHeight);
1104 }
1105
1106 void KStandardItemListWidget::updateDetailsLayoutTextCache()
1107 {
1108 // Precondition: Requires already updated m_expansionArea
1109 // to determine the left position.
1110
1111 // +------+
1112 // | Icon | Name role Additional role 1 Additional role 2
1113 // +------+
1114 m_textRect = QRectF();
1115
1116 const KItemListStyleOption& option = styleOption();
1117 const QHash<QByteArray, QVariant> values = data();
1118
1119 const qreal widgetHeight = size().height();
1120 const int scaledIconSize = widgetHeight - 2 * option.padding;
1121 const int fontHeight = m_customizedFontMetrics.height();
1122
1123 const qreal columnWidthInc = columnPadding(option);
1124 qreal firstColumnInc = scaledIconSize;
1125 if (m_supportsItemExpanding) {
1126 firstColumnInc += (m_expansionArea.left() + m_expansionArea.right() + widgetHeight) / 2;
1127 } else {
1128 firstColumnInc += option.padding;
1129 }
1130
1131 qreal x = firstColumnInc;
1132 const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2);
1133
1134 foreach (const QByteArray& role, m_sortedVisibleRoles) {
1135 QString text = roleText(role, values);
1136
1137 // Elide the text in case it does not fit into the available column-width
1138 qreal requiredWidth = m_customizedFontMetrics.width(text);
1139 const qreal roleWidth = columnWidth(role);
1140 qreal availableTextWidth = roleWidth - columnWidthInc;
1141
1142 const bool isTextRole = (role == "text");
1143 if (isTextRole) {
1144 availableTextWidth -= firstColumnInc;
1145 }
1146
1147 if (requiredWidth > availableTextWidth) {
1148 text = m_customizedFontMetrics.elidedText(text, Qt::ElideRight, availableTextWidth);
1149 requiredWidth = m_customizedFontMetrics.width(text);
1150 }
1151
1152 TextInfo* textInfo = m_textInfo.value(role);
1153 textInfo->staticText.setText(text);
1154 textInfo->pos = QPointF(x + columnWidthInc / 2, y);
1155 x += roleWidth;
1156
1157 if (isTextRole) {
1158 const qreal textWidth = option.extendedSelectionRegion
1159 ? size().width() - textInfo->pos.x()
1160 : requiredWidth + 2 * option.padding;
1161 m_textRect = QRectF(textInfo->pos.x() - option.padding, 0,
1162 textWidth, size().height());
1163
1164 // The column after the name should always be aligned on the same x-position independent
1165 // from the expansion-level shown in the name column
1166 x -= firstColumnInc;
1167 } else if (isRoleRightAligned(role)) {
1168 textInfo->pos.rx() += roleWidth - requiredWidth - columnWidthInc;
1169 }
1170 }
1171 }
1172
1173 void KStandardItemListWidget::updateAdditionalInfoTextColor()
1174 {
1175 QColor c1;
1176 if (m_customTextColor.isValid()) {
1177 c1 = m_customTextColor;
1178 } else if (isSelected() && m_layout != DetailsLayout) {
1179 c1 = styleOption().palette.highlightedText().color();
1180 } else {
1181 c1 = styleOption().palette.text().color();
1182 }
1183
1184 // For the color of the additional info the inactive text color
1185 // is not used as this might lead to unreadable text for some color schemes. Instead
1186 // the text color c1 is slightly mixed with the background color.
1187 const QColor c2 = styleOption().palette.base().color();
1188 const int p1 = 70;
1189 const int p2 = 100 - p1;
1190 m_additionalInfoTextColor = QColor((c1.red() * p1 + c2.red() * p2) / 100,
1191 (c1.green() * p1 + c2.green() * p2) / 100,
1192 (c1.blue() * p1 + c2.blue() * p2) / 100);
1193 }
1194
1195 void KStandardItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
1196 {
1197 if (m_scaledPixmapSize != pixmap.size()) {
1198 QPixmap scaledPixmap = pixmap;
1199 KPixmapModifier::scale(scaledPixmap, m_scaledPixmapSize);
1200 painter->drawPixmap(m_pixmapPos, scaledPixmap);
1201
1202 #ifdef KSTANDARDITEMLISTWIDGET_DEBUG
1203 painter->setPen(Qt::blue);
1204 painter->drawRect(QRectF(m_pixmapPos, QSizeF(m_scaledPixmapSize)));
1205 #endif
1206 } else {
1207 painter->drawPixmap(m_pixmapPos, pixmap);
1208 }
1209 }
1210
1211 void KStandardItemListWidget::drawSiblingsInformation(QPainter* painter)
1212 {
1213 const int siblingSize = size().height();
1214 const int x = (m_expansionArea.left() + m_expansionArea.right() - siblingSize) / 2;
1215 QRect siblingRect(x, 0, siblingSize, siblingSize);
1216
1217 QStyleOption option;
1218 bool isItemSibling = true;
1219
1220 const QBitArray siblings = siblingsInformation();
1221 for (int i = siblings.count() - 1; i >= 0; --i) {
1222 option.rect = siblingRect;
1223 option.state = siblings.at(i) ? QStyle::State_Sibling : QStyle::State_None;
1224
1225 if (isItemSibling) {
1226 option.state |= QStyle::State_Item;
1227 if (m_isExpandable) {
1228 option.state |= QStyle::State_Children;
1229 }
1230 if (data()["isExpanded"].toBool()) {
1231 option.state |= QStyle::State_Open;
1232 }
1233 isItemSibling = false;
1234 }
1235
1236 style()->drawPrimitive(QStyle::PE_IndicatorBranch, &option, painter);
1237
1238 siblingRect.translate(-siblingRect.width(), 0);
1239 }
1240 }
1241
1242 QRectF KStandardItemListWidget::roleEditingRect(const QByteArray& role) const
1243 {
1244 const TextInfo* textInfo = m_textInfo.value(role);
1245 if (!textInfo) {
1246 return QRectF();
1247 }
1248
1249 QRectF rect(textInfo->pos, textInfo->staticText.size());
1250 if (m_layout == DetailsLayout) {
1251 rect.setWidth(columnWidth(role) - rect.x());
1252 }
1253
1254 return rect;
1255 }
1256
1257 void KStandardItemListWidget::closeRoleEditor()
1258 {
1259 if (m_roleEditor->hasFocus()) {
1260 // If the editing was not ended by a FocusOut event, we have
1261 // to transfer the keyboard focus back to the KItemListContainer.
1262 scene()->views()[0]->parentWidget()->setFocus();
1263 }
1264 m_roleEditor->deleteLater();
1265 m_roleEditor = 0;
1266 }
1267
1268 QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, int size)
1269 {
1270 const KIcon icon(name);
1271
1272 int requestedSize;
1273 if (size <= KIconLoader::SizeSmall) {
1274 requestedSize = KIconLoader::SizeSmall;
1275 } else if (size <= KIconLoader::SizeSmallMedium) {
1276 requestedSize = KIconLoader::SizeSmallMedium;
1277 } else if (size <= KIconLoader::SizeMedium) {
1278 requestedSize = KIconLoader::SizeMedium;
1279 } else if (size <= KIconLoader::SizeLarge) {
1280 requestedSize = KIconLoader::SizeLarge;
1281 } else if (size <= KIconLoader::SizeHuge) {
1282 requestedSize = KIconLoader::SizeHuge;
1283 } else if (size <= KIconLoader::SizeEnormous) {
1284 requestedSize = KIconLoader::SizeEnormous;
1285 } else if (size <= KIconLoader::SizeEnormous * 2) {
1286 requestedSize = KIconLoader::SizeEnormous * 2;
1287 } else {
1288 requestedSize = size;
1289 }
1290
1291 QPixmap pixmap = icon.pixmap(requestedSize, requestedSize);
1292 if (requestedSize != size) {
1293 KPixmapModifier::scale(pixmap, QSize(size, size));
1294 }
1295
1296 return pixmap;
1297 }
1298
1299 QSizeF KStandardItemListWidget::preferredRatingSize(const KItemListStyleOption& option)
1300 {
1301 const qreal height = option.fontMetrics.ascent();
1302 return QSizeF(height * 5, height);
1303 }
1304
1305 qreal KStandardItemListWidget::columnPadding(const KItemListStyleOption& option)
1306 {
1307 return option.padding * 6;
1308 }
1309
1310 #include "kstandarditemlistwidget.moc"