- 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());
-
- // To simplify the handling of scaling the original pixmap
- // will be embedded into a square pixmap.
- QPixmap squarePixmap(iconHeight, iconHeight);
- squarePixmap.fill(Qt::transparent);
-
- QPainter painter(&squarePixmap);
- int x, y;
- if (iconOnTop) {
- x = (iconHeight - m_pixmap.width()) / 2; // Center horizontally
- y = iconHeight - m_pixmap.height(); // Align on bottom
- painter.drawPixmap(x, y, m_pixmap);
- } else {
- x = iconHeight - m_pixmap.width(); // Align right
- y = (iconHeight - m_pixmap.height()) / 2; // Center vertically
- painter.drawPixmap(x, y, m_pixmap);
- }
-
- m_pixmap = squarePixmap;
- } else {
- m_hoverPixmapRect.setSize(m_pixmap.size());
- }
-
- if (m_isCut) {
- applyCutEffect(m_pixmap);
- }
-
- if (m_isHidden) {
- applyHiddenEffect(m_pixmap);