- QGraphicsWidget::hoverMoveEvent(event);
-
- const QPointF& pos = event->pos();
- updateHoveredRoleIndex(pos);
- if (m_hoveredRoleIndex >= 0 && isAboveRoleGrip(pos, m_hoveredRoleIndex)) {
- setCursor(Qt::SplitHCursor);
- } else {
- unsetCursor();
- }
-}
-
-void KItemListHeader::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
-{
- Q_UNUSED(current);
- Q_UNUSED(previous);
- update();
-}
-
-void KItemListHeader::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
-{
- Q_UNUSED(current);
- Q_UNUSED(previous);
- update();
-}
-
-void KItemListHeader::paintRole(QPainter* painter,
- const QByteArray& role,
- const QRectF& rect,
- int orderIndex)
-{
- // The following code is based on the code from QHeaderView::paintSection().
- // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
- QStyleOptionHeader option;
- option.section = orderIndex;
- option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal;
- if (isEnabled()) {
- option.state |= QStyle::State_Enabled;
- }
- if (window() && window()->isActiveWindow()) {
- option.state |= QStyle::State_Active;
- }
- if (m_hoveredRoleIndex == orderIndex) {
- option.state |= QStyle::State_MouseOver;
- }
- if (m_pressedRoleIndex == orderIndex) {
- option.state |= QStyle::State_Sunken;
- }
- if (m_model->sortRole() == role) {
- option.sortIndicator = (m_model->sortOrder() == Qt::AscendingOrder) ?
- QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
- }
- option.rect = rect.toRect();
-
- if (m_visibleRoles.count() == 1) {
- option.position = QStyleOptionHeader::OnlyOneSection;
- } else if (orderIndex == 0) {
- option.position = QStyleOptionHeader::Beginning;
- } else if (orderIndex == m_visibleRoles.count() - 1) {
- option.position = QStyleOptionHeader::End;
- } else {
- option.position = QStyleOptionHeader::Middle;
- }
-
- option.orientation = Qt::Horizontal;
- option.selectedPosition = QStyleOptionHeader::NotAdjacent;
- option.text = m_model->roleDescription(role);
-
- style()->drawControl(QStyle::CE_Header, &option, painter);
-}
-
-void KItemListHeader::updatePressedRoleIndex(const QPointF& pos)
-{
- const int pressedIndex = roleIndexAt(pos);
- if (m_pressedRoleIndex != pressedIndex) {
- m_pressedRoleIndex = pressedIndex;
- update();
- }
-}
-
-void KItemListHeader::updateHoveredRoleIndex(const QPointF& pos)
-{
- const int hoverIndex = roleIndexAt(pos);
- if (m_hoveredRoleIndex != hoverIndex) {
- m_hoveredRoleIndex = hoverIndex;
- update();
- }
-}
-
-int KItemListHeader::roleIndexAt(const QPointF& pos) const
-{
- int index = -1;
-
- qreal x = 0;
- foreach (const QByteArray& role, m_visibleRoles) {
- ++index;
- x += m_visibleRolesWidths.value(role);
- if (pos.x() <= x) {
- break;