X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0397658b81ce371047d9ce6979aa37d8112f1a2c..bb642c92d31f0120b2306a9cb387d76f49112034:/src/kitemviews/kitemlistwidget.cpp diff --git a/src/kitemviews/kitemlistwidget.cpp b/src/kitemviews/kitemlistwidget.cpp index 24a3f079a..d02cbe3bb 100644 --- a/src/kitemviews/kitemlistwidget.cpp +++ b/src/kitemviews/kitemlistwidget.cpp @@ -22,10 +22,11 @@ #include "kitemlistwidget.h" -#include "kitemlistselectiontoggle_p.h" #include "kitemlistview.h" #include "kitemmodelbase.h" +#include "private/kitemlistselectiontoggle.h" + #include #include @@ -34,23 +35,33 @@ #include #include -KItemListWidget::KItemListWidget(QGraphicsItem* parent) : +KItemListWidgetInformant::KItemListWidgetInformant() +{ +} + +KItemListWidgetInformant::~KItemListWidgetInformant() +{ +} + +KItemListWidget::KItemListWidget(KItemListWidgetInformant* informant, QGraphicsItem* parent) : QGraphicsWidget(parent, 0), + m_informant(informant), m_index(-1), 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), - m_selectionToggle(0) + m_selectionToggle(0), + m_editedRole() { } @@ -105,15 +116,13 @@ 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); } - if (m_selected) { + if (m_selected && m_editedRole.isEmpty()) { const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0); drawItemStyleOption(painter, widget, activeState | QStyle::State_Enabled | @@ -121,20 +130,10 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o QStyle::State_Item); } - if (isCurrent()) { + if (m_current && m_editedRole.isEmpty()) { 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.rect = textFocusRect().toRect(); focusRectOption.state = QStyle::State_Enabled | QStyle::State_Item | QStyle::State_KeyboardFocusChange; if (m_selected) { focusRectOption.state |= QStyle::State_Selected; @@ -179,18 +178,20 @@ QList KItemListWidget::visibleRoles() const return m_visibleRoles; } -void KItemListWidget::setVisibleRolesSizes(const QHash rolesSizes) -{ - const QHash previousRolesSizes = m_visibleRolesSizes; - m_visibleRolesSizes = rolesSizes; - visibleRolesSizesChanged(rolesSizes, previousRolesSizes); - update(); +void KItemListWidget::setColumnWidth(const QByteArray& role, qreal width) +{ + 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) @@ -249,9 +250,9 @@ void KItemListWidget::setHovered(bool hovered) if (!m_hoverAnimation) { m_hoverAnimation = new QPropertyAnimation(this, "hoverOpacity", this); - const int duration = (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) ? 1 : 200; + const int duration = (KGlobalSettings::graphicEffectsLevel() == KGlobalSettings::NoEffects) ? 1 : 200; m_hoverAnimation->setDuration(duration); - connect(m_hoverAnimation, SIGNAL(finished()), this, SLOT(slotHoverAnimationFinished())); + connect(m_hoverAnimation, &QPropertyAnimation::finished, this, &KItemListWidget::slotHoverAnimationFinished); } m_hoverAnimation->stop(); @@ -278,18 +279,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) @@ -318,6 +319,20 @@ QBitArray KItemListWidget::siblingsInformation() const return m_siblingsInfo; } +void KItemListWidget::setEditedRole(const QByteArray& role) +{ + if (m_editedRole != role) { + const QByteArray previous = m_editedRole; + m_editedRole = role; + editedRoleChanged(role, previous); + } +} + +QByteArray KItemListWidget::editedRole() const +{ + return m_editedRole; +} + bool KItemListWidget::contains(const QPointF& point) const { if (!QGraphicsWidget::contains(point)) { @@ -330,6 +345,11 @@ bool KItemListWidget::contains(const QPointF& point) const selectionToggleRect().contains(point); } +QRectF KItemListWidget::textFocusRect() const +{ + return textRect(); +} + QRectF KItemListWidget::selectionToggleRect() const { return QRectF(); @@ -340,6 +360,31 @@ QRectF KItemListWidget::expansionToggleRect() const return QRectF(); } +QPixmap KItemListWidget::createDragPixmap(const QStyleOptionGraphicsItem* option, + QWidget* widget) +{ + QPixmap pixmap(size().toSize()); + pixmap.fill(Qt::transparent); + + QPainter painter(&pixmap); + + const bool oldAlternateBackground = m_alternateBackground; + const bool wasSelected = m_selected; + const bool wasHovered = m_hovered; + + setAlternateBackground(false); + setSelected(false); + setHovered(false); + + paint(&painter, option, widget); + + setAlternateBackground(oldAlternateBackground); + setSelected(wasSelected); + setHovered(wasHovered); + + return pixmap; +} + void KItemListWidget::dataChanged(const QHash& current, const QSet& roles) { @@ -354,9 +399,11 @@ void KItemListWidget::visibleRolesChanged(const QList& current, Q_UNUSED(previous); } -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); } @@ -383,7 +430,7 @@ void KItemListWidget::hoveredChanged(bool hovered) Q_UNUSED(hovered); } -void KItemListWidget::alternatingBackgroundColorsChanged(bool enabled) +void KItemListWidget::alternateBackgroundChanged(bool enabled) { Q_UNUSED(enabled); } @@ -394,10 +441,22 @@ void KItemListWidget::siblingsInformationChanged(const QBitArray& current, const Q_UNUSED(previous); } +void KItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous) +{ + Q_UNUSED(current); + Q_UNUSED(previous); +} + void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event) { QGraphicsWidget::resizeEvent(event); clearHoverCache(); + + if (m_selectionToggle) { + const QRectF& toggleRect = selectionToggleRect(); + m_selectionToggle->setPos(toggleRect.topLeft()); + m_selectionToggle->resize(toggleRect.size()); + } } qreal KItemListWidget::hoverOpacity() const @@ -451,14 +510,12 @@ void KItemListWidget::clearHoverCache() void KItemListWidget::drawItemStyleOption(QPainter* painter, QWidget* widget, QStyle::State styleState) { - const QRect textBounds = textRect().toRect(); - QStyleOptionViewItemV4 viewItemOption; viewItemOption.initFrom(widget); viewItemOption.state = styleState; viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; viewItemOption.showDecorationSelected = true; - viewItemOption.rect = textBounds.adjusted(1, 0, -1, 0); + viewItemOption.rect = textRect().toRect(); widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget); }