m_data(),
m_styleOption(),
m_scrollOrientation(Qt::Vertical),
+ m_itemIndex(-1),
+ m_lineColor(),
m_roleColor(),
m_roleBounds()
{
}
}
+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;
updateCache();
}
- if (m_scrollOrientation != Qt::Horizontal) {
- painter->setPen(m_roleColor);
- const qreal y = m_roleBounds.y() - m_styleOption.margin;
- painter->drawLine(0, y, size().width() - 1, y);
+ if (m_itemIndex == 0) {
+ // No top- or left-line should be drawn for the first group-header
+ return;
+ }
+
+ painter->setPen(m_lineColor);
+
+ if (m_scrollOrientation == Qt::Horizontal) {
+ painter->drawLine(0, 0, 0, size().height() - 1);
+ } else {
+ painter->drawLine(0, 0, size().width() - 1, 0);
}
}
Q_UNUSED(previous);
}
+void KItemListGroupHeader::itemIndexChanged(int current, int previous)
+{
+ Q_UNUSED(current);
+ Q_UNUSED(previous);
+}
+
void KItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent* event)
{
QGraphicsWidget::resizeEvent(event);
{
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 int margin = m_styleOption.margin;
+ const QColor c2 = m_styleOption.palette.base().color();
+ m_lineColor = mixedColor(c1, c2, 10);
+ m_roleColor = mixedColor(c1, c2, 70);
+
+ const int padding = qMax(1, m_styleOption.padding);
+ const int horizontalMargin = qMax(2, m_styleOption.horizontalMargin);
+
const QFontMetrics fontMetrics(m_styleOption.font);
const qreal roleHeight = fontMetrics.height();
- m_roleBounds = QRectF(margin,
- size().height() - roleHeight - margin,
- size().width() - 2 * margin,
+ const int y = (m_scrollOrientation == Qt::Vertical) ? padding : horizontalMargin;
+
+ m_roleBounds = QRectF(horizontalMargin + padding,
+ y,
+ size().width() - 2 * padding - horizontalMargin,
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"