- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- return m_isDir ? m_expansionArea : QRectF();
-}
-
-void KFileItemListWidget::invalidateCache()
-{
- m_dirtyLayout = true;
- m_dirtyContent = true;
-}
-
-void KFileItemListWidget::refreshCache()
-{
-}
-
-void KFileItemListWidget::setTextColor(const QColor& color)
-{
- if (color != m_customTextColor) {
- m_customTextColor = color;
- updateAdditionalInfoTextColor();
- update();
- }
-}
-
-QColor KFileItemListWidget::textColor() const
-{
- return m_customTextColor.isValid() ? m_customTextColor : styleOption().palette.text().color();
-}
-
-void KFileItemListWidget::setOverlay(const QPixmap& overlay)
-{
- m_overlay = overlay;
- m_dirtyContent = true;
- update();
-}
-
-QPixmap KFileItemListWidget::overlay() const
-{
- return m_overlay;
-}
-
-void KFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current,
- const QSet<QByteArray>& roles)
-{
- KItemListWidget::dataChanged(current, roles);
- m_dirtyContent = true;
-
- QSet<QByteArray> dirtyRoles;
- if (roles.isEmpty()) {
- dirtyRoles = visibleRoles().keys().toSet();
- dirtyRoles.insert("iconPixmap");
- dirtyRoles.insert("iconName");
- } else {
- dirtyRoles = roles;
- }
-
- QSetIterator<QByteArray> it(dirtyRoles);
- while (it.hasNext()) {
- const QByteArray& role = it.next();
- m_dirtyContentRoles.insert(role);
- }
-}
-
-void KFileItemListWidget::visibleRolesChanged(const QHash<QByteArray, int>& current,
- const QHash<QByteArray, int>& previous)
-{
- KItemListWidget::visibleRolesChanged(current, previous);
- m_dirtyLayout = true;
-
- // Cache the roles sorted into m_sortedVisibleRoles:
- const int visibleRolesCount = current.count();
- m_sortedVisibleRoles.clear();
- m_sortedVisibleRoles.reserve(visibleRolesCount);
- for (int i = 0; i < visibleRolesCount; ++i) {
- m_sortedVisibleRoles.append(QByteArray());
- }
-
- QHashIterator<QByteArray, int> it(current);
- while (it.hasNext()) {
- it.next();
-
- const int index = it.value();
- if (index < 0 || index >= visibleRolesCount || !m_sortedVisibleRoles.at(index).isEmpty()) {
- kWarning() << "The visible roles have an invalid sort order.";
- break;
- }
-
- const QByteArray& role = it.key();
- m_sortedVisibleRoles[index] = role;
- }
-}
-
-void KFileItemListWidget::visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current,
- const QHash<QByteArray, QSizeF>& previous)
-{
- KItemListWidget::visibleRolesSizesChanged(current, previous);
- m_dirtyLayout = true;
-}
-
-void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current,
- const KItemListStyleOption& previous)
-{
- KItemListWidget::styleOptionChanged(current, previous);
- updateAdditionalInfoTextColor();
- m_dirtyLayout = true;
-}
-
-void KFileItemListWidget::hoveredChanged(bool hovered)
-{
- Q_UNUSED(hovered);
- m_dirtyLayout = true;
-}
-
-void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
-{
- KItemListWidget::resizeEvent(event);
- m_dirtyLayout = true;
-}
-
-void KFileItemListWidget::triggerCacheRefreshing()
-{
- if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
- return;
- }
-
- refreshCache();
-
- m_isDir = data()["isDir"].toBool();
-
- updateExpansionArea();
- updateTextsCache();
- updatePixmapCache();
-
- m_dirtyLayout = false;
- m_dirtyContent = false;
- m_dirtyContentRoles.clear();
-}
-
-void KFileItemListWidget::updateExpansionArea()
-{
- if (m_layout == DetailsLayout) {
- const QHash<QByteArray, QVariant> values = data();
- Q_ASSERT(values.contains("expansionLevel"));
- const KItemListStyleOption& option = styleOption();
- const int expansionLevel = values.value("expansionLevel", 0).toInt();
-
- const qreal widgetHeight = size().height();
- const qreal expansionLevelSize = KIconLoader::SizeSmall;
- const qreal x = option.margin + expansionLevel * widgetHeight;
- const qreal y = (widgetHeight - expansionLevelSize) / 2;
- m_expansionArea = QRectF(x, y, expansionLevelSize, expansionLevelSize);
- } else {
- m_expansionArea = QRectF();
- }
-}
-
-void KFileItemListWidget::updatePixmapCache()
-{
- // Precondition: Requires already updated m_textPos values to calculate
- // the remaining height when the alignment is vertical.
-
- const bool iconOnTop = (m_layout == IconsLayout);
- const KItemListStyleOption& option = styleOption();
- const int iconHeight = option.iconSize;
-
- const QHash<QByteArray, QVariant> values = data();
- const QSizeF widgetSize = size();
-
- int scaledIconHeight = 0;
- if (iconOnTop) {
- scaledIconHeight = static_cast<int>(m_textPos[Name].y() - 3 * option.margin);
- } else {
- const int textRowsCount = (m_layout == CompactLayout) ? visibleRoles().count() : 1;
- const qreal requiredTextHeight = textRowsCount * option.fontMetrics.height();
- scaledIconHeight = (requiredTextHeight < iconHeight) ? widgetSize.height() - 2 * option.margin : iconHeight;
- }
-
- bool updatePixmap = (iconHeight != m_pixmap.height());
- if (!updatePixmap && m_dirtyContent) {
- updatePixmap = m_dirtyContentRoles.isEmpty()
- || m_dirtyContentRoles.contains("iconPixmap")
- || m_dirtyContentRoles.contains("iconName");
- }
-
- if (updatePixmap) {
- m_pixmap = values["iconPixmap"].value<QPixmap>();
- if (m_pixmap.isNull()) {
- // Use the icon that fits to the MIME-type
- QString iconName = values["iconName"].toString();
- if (iconName.isEmpty()) {
- // The icon-name has not been not resolved by KFileItemModelRolesUpdater,
- // use a generic icon as fallback
- iconName = QLatin1String("unknown");
- }
- m_pixmap = pixmapForIcon(iconName, iconHeight);
- m_hoverPixmapRect.setSize(m_pixmap.size());
- } else if (m_pixmap.size() != QSize(iconHeight, iconHeight)) {
- // A custom pixmap has been applied. Assure that the pixmap
- // is scaled to the available size.
- const bool scale = m_pixmap.width() > iconHeight || m_pixmap.height() > iconHeight ||
- (m_pixmap.width() < iconHeight && m_pixmap.height() < iconHeight);
- if (scale) {
- KPixmapModifier::scale(m_pixmap, QSize(iconHeight, iconHeight));
- }
- m_hoverPixmapRect.setSize(m_pixmap.size());