mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-12 12:54:29 +00:00
Add a hover effect for the selection toggle.
FIXED-IN: 4.13.0 REVIEW: 116028 BUG: 299328
This commit is contained in:
parent
eab1b76b76
commit
d980dccb12
|
@ -951,8 +951,13 @@ bool KItemListController::hoverMoveEvent(QGraphicsSceneHoverEvent* event, const
|
|||
|
||||
if (newHoveredWidget) {
|
||||
newHoveredWidget->setHovered(true);
|
||||
const QPointF mappedPos = newHoveredWidget->mapFromItem(m_view, pos);
|
||||
newHoveredWidget->setHoverPosition(mappedPos);
|
||||
emit itemHovered(newHoveredWidget->index());
|
||||
}
|
||||
} else if (oldHoveredWidget) {
|
||||
const QPointF mappedPos = oldHoveredWidget->mapFromItem(m_view, pos);
|
||||
oldHoveredWidget->setHoverPosition(mappedPos);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -279,6 +279,13 @@ bool KItemListWidget::isHovered() const
|
|||
return m_hovered;
|
||||
}
|
||||
|
||||
void KItemListWidget::setHoverPosition(const QPointF& pos)
|
||||
{
|
||||
if (m_selectionToggle) {
|
||||
m_selectionToggle->setHovered(m_selectionToggle->contains(pos));
|
||||
}
|
||||
}
|
||||
|
||||
void KItemListWidget::setAlternateBackground(bool enable)
|
||||
{
|
||||
if (m_alternateBackground != enable) {
|
||||
|
|
|
@ -108,6 +108,8 @@ public:
|
|||
void setHovered(bool hovered);
|
||||
bool isHovered() const;
|
||||
|
||||
void setHoverPosition(const QPointF& pos);
|
||||
|
||||
void setAlternateBackground(bool enable);
|
||||
bool alternateBackground() const;
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ KItemListSelectionToggle::KItemListSelectionToggle(QGraphicsItem* parent) :
|
|||
m_checked(false),
|
||||
m_hovered(false)
|
||||
{
|
||||
setAcceptHoverEvents(true);
|
||||
}
|
||||
|
||||
KItemListSelectionToggle::~KItemListSelectionToggle()
|
||||
|
@ -51,6 +50,15 @@ bool KItemListSelectionToggle::isChecked() const
|
|||
return m_checked;
|
||||
}
|
||||
|
||||
void KItemListSelectionToggle::setHovered(bool hovered)
|
||||
{
|
||||
if (m_hovered != hovered) {
|
||||
m_hovered = hovered;
|
||||
m_pixmap = QPixmap();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void KItemListSelectionToggle::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
|
||||
{
|
||||
Q_UNUSED(option);
|
||||
|
@ -65,20 +73,6 @@ void KItemListSelectionToggle::paint(QPainter* painter, const QStyleOptionGraphi
|
|||
painter->drawPixmap(x, y, m_pixmap);
|
||||
}
|
||||
|
||||
void KItemListSelectionToggle::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
QGraphicsWidget::hoverEnterEvent(event);
|
||||
m_hovered = true;
|
||||
m_pixmap = QPixmap();
|
||||
}
|
||||
|
||||
void KItemListSelectionToggle::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
|
||||
{
|
||||
QGraphicsWidget::hoverLeaveEvent(event);
|
||||
m_hovered = false;
|
||||
m_pixmap = QPixmap();
|
||||
}
|
||||
|
||||
void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event)
|
||||
{
|
||||
QGraphicsWidget::resizeEvent(event);
|
||||
|
@ -97,12 +91,9 @@ void KItemListSelectionToggle::resizeEvent(QGraphicsSceneResizeEvent* event)
|
|||
|
||||
void KItemListSelectionToggle::updatePixmap()
|
||||
{
|
||||
const char* icon = m_checked ? "list-remove" : "list-add";
|
||||
m_pixmap = KIconLoader::global()->loadIcon(QLatin1String(icon), KIconLoader::NoGroup, iconSize());
|
||||
|
||||
if (m_hovered) {
|
||||
KIconLoader::global()->iconEffect()->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::ActiveState);
|
||||
}
|
||||
const QString icon = m_checked ? "list-remove" : "list-add";
|
||||
const KIconLoader::States state = m_hovered ? KIconLoader::ActiveState : KIconLoader::DisabledState;
|
||||
m_pixmap = KIconLoader::global()->loadIcon(icon, KIconLoader::Desktop, iconSize(), state);
|
||||
}
|
||||
|
||||
int KItemListSelectionToggle::iconSize() const
|
||||
|
|
|
@ -41,11 +41,11 @@ public:
|
|||
void setChecked(bool checked);
|
||||
bool isChecked() const;
|
||||
|
||||
void setHovered(bool hovered);
|
||||
|
||||
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
|
||||
|
||||
protected:
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
|
||||
virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue