const KItemListSelectionManager* selectionManager = m_controller->selectionManager();
widget->setCurrent(index == selectionManager->currentItem());
widget->setSelected(selectionManager->isSelected(index));
-
widget->setHovered(false);
+ widget->setAlternatingBackgroundColors(false);
widget->setIndex(index);
widget->setData(m_model->data(index));
}
m_selected(false),
m_current(false),
m_hovered(false),
+ m_alternatingBackgroundColors(false),
m_data(),
m_visibleRoles(),
m_visibleRolesSizes(),
KItemListWidget::~KItemListWidget()
{
- clearCache();
+ clearHoverCache();
}
void KItemListWidget::setIndex(int index)
m_hoverAnimation->stop();
m_hoverOpacity = 0;
}
- clearCache();
+ clearHoverCache();
m_index = index;
}
void KItemListWidget::setData(const QHash<QByteArray, QVariant>& data,
const QSet<QByteArray>& roles)
{
- clearCache();
+ clearHoverCache();
if (roles.isEmpty()) {
m_data = data;
dataChanged(m_data);
painter->setRenderHint(QPainter::Antialiasing);
+ if (m_alternatingBackgroundColors && (m_index & 0x1)) {
+ const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase);
+ const QRectF backgroundRect(0, 0, size().width(), size().height());
+ painter->fillRect(backgroundRect, backgroundColor);
+ }
+
const QRect iconBounds = iconBoundingRect().toRect();
if (m_selected) {
QStyleOptionViewItemV4 viewItemOption;
void KItemListWidget::setStyleOption(const KItemListStyleOption& option)
{
const KItemListStyleOption previous = m_styleOption;
- clearCache();
+ clearHoverCache();
m_styleOption = option;
styleOptionChanged(option, previous);
return m_hovered;
}
+void KItemListWidget::setAlternatingBackgroundColors(bool enable)
+{
+ if (m_alternatingBackgroundColors != enable) {
+ m_alternatingBackgroundColors = enable;
+ alternatingBackgroundColorsChanged(enable);
+ update();
+ }
+}
+
+bool KItemListWidget::alternatingBackgroundColors() const
+{
+ return m_alternatingBackgroundColors;
+}
+
bool KItemListWidget::contains(const QPointF& point) const
{
if (!QGraphicsWidget::contains(point)) {
Q_UNUSED(hovered);
}
+void KItemListWidget::alternatingBackgroundColorsChanged(bool enabled)
+{
+ Q_UNUSED(enabled);
+}
+
void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
{
QGraphicsWidget::resizeEvent(event);
- clearCache();
+ clearHoverCache();
}
qreal KItemListWidget::hoverOpacity() const
update();
}
-void KItemListWidget::clearCache()
+void KItemListWidget::clearHoverCache()
{
delete m_hoverCache;
m_hoverCache = 0;
void setHovered(bool hovered);
bool isHovered() const;
+ void setAlternatingBackgroundColors(bool enable);
+ bool alternatingBackgroundColors() const;
+
/**
* @return True if \a point is inside KItemListWidget::hoverBoundingRect(),
* KItemListWidget::textBoundingRect(), KItemListWidget::selectionToggleRect()
virtual void currentChanged(bool current);
virtual void selectedChanged(bool selected);
virtual void hoveredChanged(bool hovered);
- virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
+ virtual void alternatingBackgroundColorsChanged(bool enabled);
+ virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
/**
* @return The current opacity of the hover-animation. When implementing a custom painting-code for a hover-state
private:
void setHoverOpacity(qreal opacity);
- void clearCache();
+ void clearHoverCache();
void drawFocusIndicator(QPainter* painter);
void drawTextBackground(QPainter* painter);
bool m_selected;
bool m_current;
bool m_hovered;
+ bool m_alternatingBackgroundColors;
QHash<QByteArray, QVariant> m_data;
QList<QByteArray> m_visibleRoles;
QHash<QByteArray, QSizeF> m_visibleRolesSizes;