diff options
| author | Peter Penz <[email protected]> | 2012-02-14 18:04:47 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-02-14 18:05:29 +0100 |
| commit | 0397658b81ce371047d9ce6979aa37d8112f1a2c (patch) | |
| tree | ebdf42f5e00e3c857a36464dd5f9db2b1b72b207 /src/kitemviews/kfileitemlistwidget.cpp | |
| parent | 7f0aaff9b5d5f1527587dfd68d3b42e020a21122 (diff) | |
Details view: Fix indicator-branches
Up to now no indicator-branches have been drawn when showing a tree. The patch
fixes this so that that the style-dependent branches are drawn.
The main part of the patch is the implementation of
KItemListView::updateSiblingsInformation(). Most of the other changes are
related due to an internal renaming of the expansionsLevel-role to
expandedParentsCount and some related cleanups.
BUG: 290276
FIXED-IN: 4.8.1
Diffstat (limited to 'src/kitemviews/kfileitemlistwidget.cpp')
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.cpp | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index 64cc8b449..dc1554dab 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -94,13 +94,8 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte KItemListWidget::paint(painter, option, widget); - // Draw expansion toggle '>' or 'V' - if (m_isExpandable && !m_expansionArea.isEmpty()) { - QStyleOption arrowOption; - arrowOption.rect = m_expansionArea.toRect(); - const QStyle::PrimitiveElement arrow = data()["isExpanded"].toBool() - ? QStyle::PE_IndicatorArrowDown : QStyle::PE_IndicatorArrowRight; - style()->drawPrimitive(arrow, &arrowOption, painter); + if (!m_expansionArea.isEmpty()) { + drawSiblingsInformation(painter); } const KItemListStyleOption& itemListStyleOption = styleOption(); @@ -309,7 +304,8 @@ QPixmap KFileItemListWidget::overlay() const void KFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles) { - KItemListWidget::dataChanged(current, roles); + Q_UNUSED(current); + m_dirtyContent = true; QSet<QByteArray> dirtyRoles; @@ -331,7 +327,7 @@ void KFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current void KFileItemListWidget::visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous) { - KItemListWidget::visibleRolesChanged(current, previous); + Q_UNUSED(previous); m_sortedVisibleRoles = current; m_dirtyLayout = true; } @@ -339,14 +335,16 @@ void KFileItemListWidget::visibleRolesChanged(const QList<QByteArray>& current, void KFileItemListWidget::visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current, const QHash<QByteArray, QSizeF>& previous) { - KItemListWidget::visibleRolesSizesChanged(current, previous); + Q_UNUSED(current); + Q_UNUSED(previous); m_dirtyLayout = true; } void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous) { - KItemListWidget::styleOptionChanged(current, previous); + Q_UNUSED(current); + Q_UNUSED(previous); updateAdditionalInfoTextColor(); m_dirtyLayout = true; } @@ -363,6 +361,14 @@ void KFileItemListWidget::selectedChanged(bool selected) updateAdditionalInfoTextColor(); } +void KFileItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); + m_dirtyLayout = true; +} + + void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) { KItemListWidget::resizeEvent(event); @@ -428,15 +434,14 @@ 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(); - if (expansionLevel >= 0) { + Q_ASSERT(values.contains("expandedParentsCount")); + const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt(); + if (expandedParentsCount >= 0) { const qreal widgetHeight = size().height(); - const qreal expansionLevelSize = KIconLoader::SizeSmall; - const qreal x = option.padding + expansionLevel * widgetHeight; - const qreal y = (widgetHeight - expansionLevelSize) / 2; - m_expansionArea = QRectF(x, y, expansionLevelSize, expansionLevelSize); + const qreal inc = (widgetHeight - KIconLoader::SizeSmall) / 2; + const qreal x = expandedParentsCount * widgetHeight + inc; + const qreal y = inc; + m_expansionArea = QRectF(x, y, KIconLoader::SizeSmall, KIconLoader::SizeSmall); return; } } @@ -746,7 +751,8 @@ void KFileItemListWidget::updateDetailsLayoutTextCache() const int fontHeight = option.fontMetrics.height(); const qreal columnPadding = option.padding * 3; - const qreal firstColumnInc = m_expansionArea.right() + option.padding * 2 + scaledIconSize; + const qreal firstColumnInc = (m_expansionArea.left() + m_expansionArea.right() + widgetHeight) / 2 + + scaledIconSize; qreal x = firstColumnInc; const qreal y = qMax(qreal(option.padding), (widgetHeight - fontHeight) / 2); @@ -831,6 +837,37 @@ void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap) } } +void KFileItemListWidget::drawSiblingsInformation(QPainter* painter) +{ + const int siblingSize = size().height(); + const int x = (m_expansionArea.left() + m_expansionArea.right() - siblingSize) / 2; + QRect siblingRect(x, 0, siblingSize, siblingSize); + + QStyleOption option; + bool isItemSibling = true; + + const QBitArray siblings = siblingsInformation(); + for (int i = siblings.count() - 1; i >= 0; --i) { + option.rect = siblingRect; + option.state = siblings.at(i) ? QStyle::State_Sibling : QStyle::State_None; + + if (isItemSibling) { + option.state |= QStyle::State_Item; + if (m_isExpandable) { + option.state |= QStyle::State_Children; + } + if (data()["isExpanded"].toBool()) { + option.state |= QStyle::State_Open; + } + isItemSibling = false; + } + + style()->drawPrimitive(QStyle::PE_IndicatorBranch, &option, painter); + + siblingRect.translate(-siblingRect.width(), 0); + } +} + QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size) { const KIcon icon(name); |
