- }
-
- painter->setPen(m_additionalInfoTextColor);
- painter->setFont(itemListStyleOption.font);
-
- for (int i = 1; i < m_sortedVisibleRoles.count(); ++i) {
- const TextInfo* textInfo = m_textInfo.value(m_sortedVisibleRoles[i]);
- painter->drawStaticText(textInfo->pos, textInfo->staticText);
- }
-
- if (clipAdditionalInfoBounds) {
- painter->restore();
- }
-
-#ifdef KFILEITEMLISTWIDGET_DEBUG
- painter->setBrush(Qt::NoBrush);
- painter->setPen(Qt::green);
- painter->drawRect(m_iconRect);
-
- painter->setPen(Qt::red);
- painter->drawText(QPointF(0, itemListStyleOption.fontMetrics.height()), QString::number(index()));
- painter->drawRect(rect());
-#endif
-}
-
-QRectF KFileItemListWidget::iconRect() const
-{
- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- return m_iconRect;
-}
-
-QRectF KFileItemListWidget::textRect() const
-{
- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- return m_textRect;
-}
-
-QRectF KFileItemListWidget::textFocusRect() const
-{
- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- if (m_layout == CompactLayout) {
- // In the compact layout a larger textRect() is returned to be aligned
- // with the iconRect(). This is useful to have a larger selection/hover-area
- // when having a quite large icon size but only one line of text. Still the
- // focus rectangle should be shown as narrow as possible around the text.
- QRectF rect = m_textRect;
- const TextInfo* topText = m_textInfo.value(m_sortedVisibleRoles.first());
- const TextInfo* bottomText = m_textInfo.value(m_sortedVisibleRoles.last());
- rect.setTop(topText->pos.y());
- rect.setBottom(bottomText->pos.y() + bottomText->staticText.size().height());
- return rect;
- }
- return m_textRect;
-}
-
-QRectF KFileItemListWidget::expansionToggleRect() const
-{
- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
- return m_isExpandable ? m_expansionArea : QRectF();
-}
-
-QRectF KFileItemListWidget::selectionToggleRect() const
-{
- const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
-
- const int iconHeight = styleOption().iconSize;
-
- int toggleSize = KIconLoader::SizeSmall;
- if (iconHeight >= KIconLoader::SizeEnormous) {
- toggleSize = KIconLoader::SizeMedium;
- } else if (iconHeight >= KIconLoader::SizeLarge) {
- toggleSize = KIconLoader::SizeSmallMedium;
- }
-
- QPointF pos = iconRect().topLeft();
-
- // If the selection toggle has a very small distance to the
- // widget borders, the size of the selection toggle will get
- // increased to prevent an accidental clicking of the item
- // when trying to hit the toggle.
- const int widgetHeight = size().height();
- const int widgetWidth = size().width();
- const int minMargin = 2;
-
- if (toggleSize + minMargin * 2 >= widgetHeight) {
- pos.rx() -= (widgetHeight - toggleSize) / 2;
- toggleSize = widgetHeight;
- pos.setY(0);
- }
- if (toggleSize + minMargin * 2 >= widgetWidth) {
- pos.ry() -= (widgetWidth - toggleSize) / 2;
- toggleSize = widgetWidth;
- pos.setX(0);
- }
-
- return QRectF(pos, QSizeF(toggleSize, toggleSize));
-}
-
-QSizeF KFileItemListWidget::itemSizeHint(int index, const KItemListView* view)
-{
- const QHash<QByteArray, QVariant> values = view->model()->data(index);
- const KItemListStyleOption& option = view->styleOption();
- const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
-
- switch (static_cast<const KFileItemListView*>(view)->itemLayout()) {
- case IconsLayout: {
- const QString text = KStringHandler::preProcessWrap(values["name"].toString());
-
- const qreal maxWidth = view->itemSize().width() - 2 * option.padding;
- QTextLine line;
-
- // Calculate the number of lines required for wrapping the name
- QTextOption textOption(Qt::AlignHCenter);
- textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
-
- qreal textHeight = 0;
- QTextLayout layout(text, option.font);
- layout.setTextOption(textOption);
- layout.beginLayout();
- while ((line = layout.createLine()).isValid()) {
- line.setLineWidth(maxWidth);
- line.naturalTextWidth();
- textHeight += line.height();