X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/c8d8556950005dfd96ebdb41d2f43ad90356367c..305ecd86f9cdfd7d4e3e96fb5b7f3daab72c6ba5:/src/kitemviews/kitemlistwidget.cpp diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 61e06078b..b703fbfe2 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -28,6 +28,7 @@ #include +#include #include #include #include @@ -39,12 +40,13 @@ KItemListWidget::KItemListWidget(QGraphicsItem* parent) : m_selected(false), m_current(false), m_hovered(false), - m_alternatingBackgroundColors(false), + m_alternateBackground(false), m_enabledSelectionToggle(false), m_data(), m_visibleRoles(), - m_visibleRolesSizes(), + m_columnWidths(), m_styleOption(), + m_siblingsInfo(), m_hoverOpacity(0), m_hoverCache(0), m_hoverAnimation(0), @@ -91,6 +93,7 @@ void KItemListWidget::setData(const QHash& data, } dataChanged(m_data, roles); } + update(); } QHash KItemListWidget::data() const @@ -102,9 +105,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o { Q_UNUSED(option); - painter->setRenderHint(QPainter::Antialiasing); - - if (m_alternatingBackgroundColors && (m_index & 0x1)) { + if (m_alternateBackground) { const QColor backgroundColor = m_styleOption.palette.color(QPalette::AlternateBase); const QRectF backgroundRect(0, 0, size().width(), size().height()); painter->fillRect(backgroundRect, backgroundColor); @@ -121,18 +122,8 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o if (isCurrent()) { QStyleOptionFocusRect focusRectOption; focusRectOption.initFrom(widget); - - const QRect iconBounds = iconRect().toRect(); - const QRect textBounds = textRect().toRect(); - if (iconBounds.bottom() > textBounds.top()) { - focusRectOption.rect = textBounds; - } else { - // See KItemListWidget::drawItemStyleOption(): The selection rectangle - // gets decreased. - focusRectOption.rect = textBounds.adjusted(1, 1, -1, -1); - } - - focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item; + focusRectOption.rect = textFocusRect().toRect(); + focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange; if (m_selected) { focusRectOption.state |= QStyle::State_Selected; } @@ -166,7 +157,9 @@ void KItemListWidget::setVisibleRoles(const QList& roles) { const QList previousRoles = m_visibleRoles; m_visibleRoles = roles; + visibleRolesChanged(roles, previousRoles); + update(); } QList KItemListWidget::visibleRoles() const @@ -174,16 +167,20 @@ QList KItemListWidget::visibleRoles() const return m_visibleRoles; } -void KItemListWidget::setVisibleRolesSizes(const QHash rolesSizes) + +void KItemListWidget::setColumnWidth(const QByteArray& role, qreal width) { - const QHash previousRolesSizes = m_visibleRolesSizes; - m_visibleRolesSizes = rolesSizes; - visibleRolesSizesChanged(rolesSizes, previousRolesSizes); + if (m_columnWidths.value(role) != width) { + const qreal previousWidth = width; + m_columnWidths.insert(role, width); + columnWidthChanged(role, width, previousWidth); + update(); + } } -QHash KItemListWidget::visibleRolesSizes() const +qreal KItemListWidget::columnWidth(const QByteArray& role) const { - return m_visibleRolesSizes; + return m_columnWidths.value(role); } void KItemListWidget::setStyleOption(const KItemListStyleOption& option) @@ -193,6 +190,7 @@ void KItemListWidget::setStyleOption(const KItemListStyleOption& option) m_styleOption = option; styleOptionChanged(option, previous); + update(); } const KItemListStyleOption& KItemListWidget::styleOption() const @@ -207,7 +205,6 @@ void KItemListWidget::setSelected(bool selected) if (m_selectionToggle) { m_selectionToggle->setChecked(selected); } - selectedChanged(selected); update(); } @@ -222,7 +219,6 @@ void KItemListWidget::setCurrent(bool current) { if (m_current != current) { m_current = current; - currentChanged(current); update(); } @@ -243,7 +239,8 @@ void KItemListWidget::setHovered(bool hovered) if (!m_hoverAnimation) { m_hoverAnimation = new QPropertyAnimation(this, "hoverOpacity", this); - m_hoverAnimation->setDuration(200); + const int duration = (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) ? 1 : 200; + m_hoverAnimation->setDuration(duration); connect(m_hoverAnimation, SIGNAL(finished()), this, SLOT(slotHoverAnimationFinished())); } m_hoverAnimation->stop(); @@ -263,7 +260,6 @@ void KItemListWidget::setHovered(bool hovered) m_hoverAnimation->start(); hoveredChanged(hovered); - update(); } @@ -272,18 +268,18 @@ bool KItemListWidget::isHovered() const return m_hovered; } -void KItemListWidget::setAlternatingBackgroundColors(bool enable) +void KItemListWidget::setAlternateBackground(bool enable) { - if (m_alternatingBackgroundColors != enable) { - m_alternatingBackgroundColors = enable; - alternatingBackgroundColorsChanged(enable); + if (m_alternateBackground != enable) { + m_alternateBackground = enable; + alternateBackgroundChanged(enable); update(); } } -bool KItemListWidget::alternatingBackgroundColors() const +bool KItemListWidget::alternateBackground() const { - return m_alternatingBackgroundColors; + return m_alternateBackground; } void KItemListWidget::setEnabledSelectionToggle(bool enable) @@ -299,6 +295,19 @@ bool KItemListWidget::enabledSelectionToggle() const return m_enabledSelectionToggle; } +void KItemListWidget::setSiblingsInformation(const QBitArray& siblings) +{ + const QBitArray previous = m_siblingsInfo; + m_siblingsInfo = siblings; + siblingsInformationChanged(m_siblingsInfo, previous); + update(); +} + +QBitArray KItemListWidget::siblingsInformation() const +{ + return m_siblingsInfo; +} + bool KItemListWidget::contains(const QPointF& point) const { if (!QGraphicsWidget::contains(point)) { @@ -311,6 +320,11 @@ bool KItemListWidget::contains(const QPointF& point) const selectionToggleRect().contains(point); } +QRectF KItemListWidget::textFocusRect() const +{ + return textRect(); +} + QRectF KItemListWidget::selectionToggleRect() const { return QRectF(); @@ -326,7 +340,6 @@ void KItemListWidget::dataChanged(const QHash& current, { Q_UNUSED(current); Q_UNUSED(roles); - update(); } void KItemListWidget::visibleRolesChanged(const QList& current, @@ -334,15 +347,15 @@ void KItemListWidget::visibleRolesChanged(const QList& current, { Q_UNUSED(current); Q_UNUSED(previous); - update(); } -void KItemListWidget::visibleRolesSizesChanged(const QHash& current, - const QHash& previous) +void KItemListWidget::columnWidthChanged(const QByteArray& role, + qreal current, + qreal previous) { + Q_UNUSED(role); Q_UNUSED(current); Q_UNUSED(previous); - update(); } void KItemListWidget::styleOptionChanged(const KItemListStyleOption& current, @@ -350,7 +363,6 @@ void KItemListWidget::styleOptionChanged(const KItemListStyleOption& current, { Q_UNUSED(current); Q_UNUSED(previous); - update(); } void KItemListWidget::currentChanged(bool current) @@ -368,11 +380,17 @@ void KItemListWidget::hoveredChanged(bool hovered) Q_UNUSED(hovered); } -void KItemListWidget::alternatingBackgroundColorsChanged(bool enabled) +void KItemListWidget::alternateBackgroundChanged(bool enabled) { Q_UNUSED(enabled); } +void KItemListWidget::siblingsInformationChanged(const QBitArray& current, const QBitArray& previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); +} + void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) { QGraphicsWidget::resizeEvent(event); @@ -430,25 +448,13 @@ void KItemListWidget::clearHoverCache() void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState) { - const QRect iconBounds = iconRect().toRect(); - const QRect textBounds = textRect().toRect(); - QStyleOptionViewItemV4 viewItemOption; viewItemOption.initFrom(widget); viewItemOption.state = styleState; viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; viewItemOption.showDecorationSelected = true; - - if (iconBounds.bottom() > textBounds.top()) { - viewItemOption.rect = iconBounds | textBounds; - widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); - } else { - viewItemOption.rect = iconBounds; - widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); - - viewItemOption.rect = textBounds.adjusted(1, 1, -1, -1); - widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); - } + viewItemOption.rect = textRect().toRect(); + widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); } #include "kitemlistwidget.moc"