mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 18:32:50 +00:00
plasma: bring back the hover bits from 412c2d1d03
with some changes such as removing the unused QPixmap objects Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
871578c990
commit
4f0b33993a
2 changed files with 111 additions and 8 deletions
|
@ -114,13 +114,16 @@ void DesktopToolBox::init()
|
|||
{
|
||||
m_icon = KIcon("plasma");
|
||||
m_toolBacker = 0;
|
||||
m_animHighlightFrame = 0;
|
||||
m_hovering = false;
|
||||
m_background = new Plasma::FrameSvg(this);
|
||||
m_background->setImagePath("widgets/toolbox");
|
||||
|
||||
setZValue(INT_MAX);
|
||||
|
||||
setIsMovable(true);
|
||||
setFlags(flags()|QGraphicsItem::ItemIsFocusable);
|
||||
setAcceptHoverEvents(true);
|
||||
setFlags(flags() | QGraphicsItem::ItemIsFocusable);
|
||||
updateTheming();
|
||||
|
||||
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
|
||||
|
@ -261,10 +264,55 @@ void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
|
|||
m_background->paintFrame(painter, rect.topLeft());
|
||||
}
|
||||
|
||||
QRect iconRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignCenter, iconSize(), m_background->contentsRect().toRect());
|
||||
QRect iconRect = QStyle::alignedRect(
|
||||
QApplication::layoutDirection(), Qt::AlignCenter,
|
||||
iconSize(), m_background->contentsRect().toRect()
|
||||
);
|
||||
iconRect.moveTopLeft(iconRect.topLeft() + rect.topLeft().toPoint());
|
||||
const QPoint iconPos = iconRect.topLeft();
|
||||
|
||||
m_icon.paint(painter, QRect(iconRect.topLeft(), iconSize()), Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
||||
if (qFuzzyCompare(qreal(1.0), m_animHighlightFrame)) {
|
||||
m_icon.paint(painter, QRect(iconPos, iconSize()));
|
||||
} else if (qFuzzyCompare(qreal(1.0), 1 + m_animHighlightFrame)) {
|
||||
m_icon.paint(
|
||||
painter, QRect(iconPos, iconSize()),
|
||||
Qt::AlignCenter, QIcon::Disabled, QIcon::Off
|
||||
);
|
||||
} else {
|
||||
painter->drawPixmap(
|
||||
QRect(iconPos, iconSize()),
|
||||
Plasma::PaintUtils::transition(
|
||||
m_icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off),
|
||||
m_icon.pixmap(iconSize()), m_animHighlightFrame
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
if (isShowing() || m_hovering) {
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
highlight(true);
|
||||
|
||||
QGraphicsItem::hoverEnterEvent(event);
|
||||
}
|
||||
|
||||
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||
{
|
||||
//kDebug() << event->pos() << event->scenePos()
|
||||
// << m_toolBacker->rect().contains(event->scenePos().toPoint());
|
||||
if (!m_hovering || isShowing()) {
|
||||
QGraphicsItem::hoverLeaveEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
highlight(false);
|
||||
|
||||
QGraphicsItem::hoverLeaveEvent(event);
|
||||
}
|
||||
|
||||
QPainterPath DesktopToolBox::shape() const
|
||||
|
@ -329,7 +377,7 @@ void DesktopToolBox::showToolBox()
|
|||
fadeAnim->setProperty("startOpacity", 0);
|
||||
fadeAnim->setProperty("targetOpacity", 1);
|
||||
fadeAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
update();
|
||||
highlight(true);
|
||||
setFocus();
|
||||
}
|
||||
|
||||
|
@ -506,6 +554,7 @@ void DesktopToolBox::hideToolBox()
|
|||
fadeAnim->setProperty("targetOpacity", 0);
|
||||
fadeAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
}
|
||||
highlight(false);
|
||||
}
|
||||
|
||||
void DesktopToolBox::hideToolBacker()
|
||||
|
@ -513,6 +562,52 @@ void DesktopToolBox::hideToolBacker()
|
|||
m_toolBacker->hide();
|
||||
}
|
||||
|
||||
void DesktopToolBox::highlight(bool highlighting)
|
||||
{
|
||||
if (m_hovering == highlighting) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_hovering = highlighting;
|
||||
|
||||
QPropertyAnimation *anim = m_anim.data();
|
||||
if (m_hovering) {
|
||||
if (anim) {
|
||||
anim->stop();
|
||||
m_anim.clear();
|
||||
}
|
||||
anim = new QPropertyAnimation(this, "highlight", this);
|
||||
m_anim = anim;
|
||||
}
|
||||
|
||||
if (anim->state() != QAbstractAnimation::Stopped) {
|
||||
anim->stop();
|
||||
}
|
||||
|
||||
anim->setDuration(250);
|
||||
anim->setStartValue(0.0);
|
||||
anim->setEndValue(1.0);
|
||||
|
||||
if (m_hovering) {
|
||||
anim->start();
|
||||
} else {
|
||||
anim->setDirection(QAbstractAnimation::Backward);
|
||||
anim->start(QAbstractAnimation::DeleteWhenStopped);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DesktopToolBox::setHighlight(qreal progress)
|
||||
{
|
||||
m_animHighlightFrame = progress;
|
||||
update();
|
||||
}
|
||||
|
||||
qreal DesktopToolBox::highlight()
|
||||
{
|
||||
return m_animHighlightFrame;
|
||||
}
|
||||
|
||||
void DesktopToolBox::toggle()
|
||||
{
|
||||
setShowing(!isShowing());
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
#include <QGraphicsItem>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QWeakPointer>
|
||||
|
||||
#include <KIcon>
|
||||
|
||||
|
@ -39,7 +39,7 @@ class DesktopToolBoxPrivate;
|
|||
class DesktopToolBox : public InternalToolBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal highlight READ highlight WRITE setHighlight)
|
||||
public:
|
||||
explicit DesktopToolBox(Plasma::Containment *parent = 0);
|
||||
explicit DesktopToolBox(QObject *parent = 0, const QVariantList &args = QVariantList());
|
||||
|
@ -65,10 +65,14 @@ public Q_SLOTS:
|
|||
|
||||
protected:
|
||||
void init();
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) final;
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event) final;
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) final;
|
||||
void keyPressEvent(QKeyEvent *event) final;
|
||||
|
||||
protected Q_SLOTS:
|
||||
void setHighlight(qreal progress);
|
||||
qreal highlight();
|
||||
void updateTheming();
|
||||
void toolTriggered(bool);
|
||||
void hideToolBacker();
|
||||
|
@ -82,6 +86,7 @@ protected Q_SLOTS:
|
|||
void logout();
|
||||
|
||||
private:
|
||||
void highlight(bool highlighting);
|
||||
void adjustToolBackerGeometry();
|
||||
void adjustBackgroundBorders() const;
|
||||
|
||||
|
@ -90,6 +95,9 @@ private:
|
|||
QMultiMap<Plasma::AbstractToolBox::ToolType, Plasma::ToolButton *> m_tools;
|
||||
KIcon m_icon;
|
||||
EmptyGraphicsItem *m_toolBacker;
|
||||
QWeakPointer<QPropertyAnimation> m_anim;
|
||||
qreal m_animHighlightFrame;
|
||||
bool m_hovering;
|
||||
};
|
||||
|
||||
K_EXPORT_PLASMA_TOOLBOX(desktoptoolbox, DesktopToolBox)
|
||||
|
|
Loading…
Add table
Reference in a new issue