diff options
| author | Peter Penz <[email protected]> | 2012-02-11 18:02:38 +0100 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-02-11 18:04:53 +0100 |
| commit | 056d12d60f93a052e19f6e2cff9b826e500eef16 (patch) | |
| tree | 45c79d8620617645e1e34cd996adf8cc02f268b1 /src/kitemviews/kitemlistgroupheader.cpp | |
| parent | e29e1cda15973969164d7b7fa805544189a5e172 (diff) | |
Group header layout fixes
- Don't use a margin for the first group header
- Provide margins between the groups
- Use a more subtle coloring
- Prevent animation glitches when resizing a window
Diffstat (limited to 'src/kitemviews/kitemlistgroupheader.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistgroupheader.cpp | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/src/kitemviews/kitemlistgroupheader.cpp b/src/kitemviews/kitemlistgroupheader.cpp index 03964e2b5..ffc81eb12 100644 --- a/src/kitemviews/kitemlistgroupheader.cpp +++ b/src/kitemviews/kitemlistgroupheader.cpp @@ -36,6 +36,8 @@ KItemListGroupHeader::KItemListGroupHeader(QGraphicsWidget* parent) : m_data(), m_styleOption(), m_scrollOrientation(Qt::Vertical), + m_itemIndex(-1), + m_lineColor(), m_roleColor(), m_roleBounds() { @@ -100,6 +102,21 @@ void KItemListGroupHeader::setScrollOrientation(Qt::Orientation orientation) } } +void KItemListGroupHeader::setItemIndex(int index) +{ + if (m_itemIndex != index) { + const int previous = m_itemIndex; + m_itemIndex = index; + m_dirtyCache = true; + itemIndexChanged(m_itemIndex, previous); + } +} + +int KItemListGroupHeader::itemIndex() const +{ + return m_itemIndex; +} + Qt::Orientation KItemListGroupHeader::scrollOrientation() const { return m_scrollOrientation; @@ -114,8 +131,13 @@ void KItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsIt updateCache(); } - if (m_scrollOrientation != Qt::Horizontal) { - painter->setPen(m_roleColor); + if (m_scrollOrientation == Qt::Horizontal) { + painter->setPen(m_lineColor); + const qreal x = m_roleBounds.x() - m_styleOption.padding; + painter->drawLine(x, 0, x, size().height() - 1); + + } else if (m_itemIndex > 0) { + painter->setPen(m_lineColor); const qreal y = m_roleBounds.y() - m_styleOption.padding; painter->drawLine(0, y, size().width() - 1, y); } @@ -155,6 +177,12 @@ void KItemListGroupHeader::scrollOrientationChanged(Qt::Orientation current, Qt: Q_UNUSED(previous); } +void KItemListGroupHeader::itemIndexChanged(int current, int previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); +} + void KItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event) { QGraphicsWidget::resizeEvent(event); @@ -167,26 +195,40 @@ void KItemListGroupHeader::updateCache() { Q_ASSERT(m_dirtyCache); - // Calculate the outline color. No alphablending is used for + // Calculate the role- and line-color. No alphablending is used for // performance reasons. const QColor c1 = m_styleOption.palette.text().color(); - const QColor c2 = m_styleOption.palette.background().color(); - const int p1 = 35; - const int p2 = 100 - p1; - m_roleColor = QColor((c1.red() * p1 + c2.red() * p2) / 100, - (c1.green() * p1 + c2.green() * p2) / 100, - (c1.blue() * p1 + c2.blue() * p2) / 100); + const QColor c2 = m_styleOption.palette.base().color(); + m_lineColor = mixedColor(c1, c2, 10); + m_roleColor = mixedColor(c1, c2, 50); + + int horizontalMargin = 0; + if (m_scrollOrientation == Qt::Vertical) { + // The x-position of the group-header-widget will always be 0, + // Add a minimum margin. + horizontalMargin = qMax(2, m_styleOption.horizontalMargin); + } - const int padding = m_styleOption.padding; + const int padding = qMax(2, m_styleOption.padding); const QFontMetrics fontMetrics(m_styleOption.font); const qreal roleHeight = fontMetrics.height(); - m_roleBounds = QRectF(padding, + m_roleBounds = QRectF(horizontalMargin + padding, size().height() - roleHeight - padding, - size().width() - 2 * padding, + size().width() - 2 * (horizontalMargin + padding), roleHeight); m_dirtyCache = false; } +QColor KItemListGroupHeader::mixedColor(const QColor& c1, const QColor& c2, int c1Percent) +{ + Q_ASSERT(c1Percent >= 0 && c1Percent <= 100); + + const int c2Percent = 100 - c1Percent; + return QColor((c1.red() * c1Percent + c2.red() * c2Percent) / 100, + (c1.green() * c1Percent + c2.green() * c2Percent) / 100, + (c1.blue() * c1Percent + c2.blue() * c2Percent) / 100); +} + #include "kitemlistgroupheader.moc" |
