diff options
| author | Peter Penz <[email protected]> | 2012-03-27 00:44:39 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-03-27 00:48:34 +0200 |
| commit | 793311dac163592a8b63fc4859fdc054d7a22022 (patch) | |
| tree | 9645cd870530072b23d422d51fd0515f74de6c1f /src/kitemviews/kfileitemlistview.cpp | |
| parent | 8c986e22fd8fa34ea6c29ad2e88e08c2f9b34bf2 (diff) | |
KItemListView interface and implementation simplification
- Remove KItemListView::preferredRoleColumnWidth() and allow implementing
this as part of derived classes from KItemListWidget. Those derived
classes are aware about the layout and hence also can provide the
preferred role width.
- Make KItemListView::itemSizeHint() non-virtual and also allow
implementing the size hint as part of derived classes from KItemListWidget.
Diffstat (limited to 'src/kitemviews/kfileitemlistview.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemlistview.cpp | 106 |
1 files changed, 1 insertions, 105 deletions
diff --git a/src/kitemviews/kfileitemlistview.cpp b/src/kitemviews/kfileitemlistview.cpp index ab111b912..8f7c9c899 100644 --- a/src/kitemviews/kfileitemlistview.cpp +++ b/src/kitemviews/kfileitemlistview.cpp @@ -46,8 +46,7 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : m_itemLayout(IconsLayout), m_modelRolesUpdater(0), m_updateVisibleIndexRangeTimer(0), - m_updateIconSizeTimer(0), - m_minimumRolesWidths() + m_updateIconSizeTimer(0) { setAcceptDrops(true); @@ -66,8 +65,6 @@ KFileItemListView::KFileItemListView(QGraphicsWidget* parent) : connect(m_updateIconSizeTimer, SIGNAL(timeout()), this, SLOT(updateIconSize())); setVisibleRoles(QList<QByteArray>() << "name"); - - updateMinimumRolesWidths(); } KFileItemListView::~KFileItemListView() @@ -126,98 +123,6 @@ QStringList KFileItemListView::enabledPlugins() const return m_modelRolesUpdater ? m_modelRolesUpdater->enabledPlugins() : QStringList(); } -QSizeF KFileItemListView::itemSizeHint(int index) const -{ - const QHash<QByteArray, QVariant> values = model()->data(index); - const KItemListStyleOption& option = styleOption(); - const int additionalRolesCount = qMax(visibleRoles().count() - 1, 0); - - switch (m_itemLayout) { - case IconsLayout: { - const QString text = KStringHandler::preProcessWrap(values["name"].toString()); - - const qreal maxWidth = itemSize().width() - 2 * option.padding; - int textLinesCount = 0; - QTextLine line; - - // Calculate the number of lines required for wrapping the name - QTextOption textOption(Qt::AlignHCenter); - textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); - - QTextLayout layout(text, option.font); - layout.setTextOption(textOption); - layout.beginLayout(); - while ((line = layout.createLine()).isValid()) { - line.setLineWidth(maxWidth); - line.naturalTextWidth(); - ++textLinesCount; - } - layout.endLayout(); - - // Add one line for each additional information - textLinesCount += additionalRolesCount; - - const qreal height = textLinesCount * option.fontMetrics.height() + - option.iconSize + - option.padding * 3; - return QSizeF(itemSize().width(), height); - } - - case CompactLayout: { - // For each row exactly one role is shown. Calculate the maximum required width that is necessary - // to show all roles without horizontal clipping. - qreal maximumRequiredWidth = 0.0; - - foreach (const QByteArray& role, visibleRoles()) { - const QString text = KFileItemListWidget::roleText(role, values); - const qreal requiredWidth = option.fontMetrics.width(text); - maximumRequiredWidth = qMax(maximumRequiredWidth, requiredWidth); - } - - const qreal width = option.padding * 4 + option.iconSize + maximumRequiredWidth; - const qreal height = option.padding * 2 + qMax(option.iconSize, (1 + additionalRolesCount) * option.fontMetrics.height()); - return QSizeF(width, height); - } - - case DetailsLayout: { - // The width will be determined dynamically by KFileItemListView::visibleRoleSizes() - const qreal height = option.padding * 2 + qMax(option.iconSize, option.fontMetrics.height()); - return QSizeF(-1, height); - } - - default: - Q_ASSERT(false); - break; - } - - return QSize(); -} - -qreal KFileItemListView::preferredRoleColumnWidth(const QByteArray& role, int index) const -{ - const KItemListStyleOption& option = styleOption(); - - qreal width = m_minimumRolesWidths.value(role, 0); - - const QHash<QByteArray, QVariant> values = model()->data(index); - const QString text = KFileItemListWidget::roleText(role, values); - if (!text.isEmpty()) { - const qreal columnPadding = option.padding * 3; - width = qMax(width, qreal(2 * columnPadding + option.fontMetrics.width(text))); - } - - if (role == "name") { - // Increase the width by the expansion-toggle and the current expansion level - const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); - width += option.padding + (expandedParentsCount + 1) * itemSize().height() + KIconLoader::SizeSmall; - - // Increase the width by the required space for the icon - width += option.padding * 2 + option.iconSize; - } - - return width; -} - QPixmap KFileItemListView::createDragPixmap(const QSet<int>& indexes) const { if (!model()) { @@ -502,15 +407,6 @@ void KFileItemListView::updateTimersInterval() m_updateIconSizeTimer->setInterval(interval); } -void KFileItemListView::updateMinimumRolesWidths() -{ - m_minimumRolesWidths.clear(); - - const KItemListStyleOption& option = styleOption(); - const QString sizeText = QLatin1String("888888") + i18nc("@item:intable", "items"); - m_minimumRolesWidths.insert("size", option.fontMetrics.width(sizeText)); -} - void KFileItemListView::applyRolesToModel() { if (!model()) { |
