Commit 2b40ed69 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig
Browse files

Add animation to detail widgets

parent 42ebc6b0
......@@ -32,12 +32,13 @@
#include <QtGui/QPaintEvent>
#include <QtGui/QPainter>
#include <QtGui/QStyleOption>
#include <QtCore/QPropertyAnimation>
#include <utils/stylehelper.h>
using namespace Utils;
DetailsButton::DetailsButton(QWidget *parent) : QAbstractButton(parent)
DetailsButton::DetailsButton(QWidget *parent) : QAbstractButton(parent), m_fader(0)
{
setCheckable(true);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
......@@ -49,12 +50,42 @@ QSize DetailsButton::sizeHint() const
return QSize(80, 22);
}
bool DetailsButton::event(QEvent *e)
{
switch(e->type()) {
case QEvent::Enter:
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
animation->setDuration(200);
animation->setEndValue(1.0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
break;
case QEvent::Leave:
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
animation->setDuration(200);
animation->setEndValue(0.0);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
break;
default:
return QAbstractButton::event(e);
}
return false;
}
void DetailsButton::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter p(this);
#ifndef Q_WS_MAC
// draw hover animation
if(!isDown() && m_fader>0)
p.fillRect(rect().adjusted(1, 1, -2, -2), QColor(255, 255, 255, int(m_fader*180)));
#endif
if (isChecked()) {
if (m_checkedPixmap.isNull() || m_checkedPixmap.size() != contentsRect().size())
m_checkedPixmap = cacheRendering(contentsRect().size(), true);
......@@ -64,6 +95,11 @@ void DetailsButton::paintEvent(QPaintEvent *e)
m_uncheckedPixmap = cacheRendering(contentsRect().size(), false);
p.drawPixmap(contentsRect(), m_uncheckedPixmap);
}
if (isDown()) {
p.setPen(Qt::NoPen);
p.setBrush(QColor(0, 0, 0, 20));
p.drawRoundedRect(rect().adjusted(1, 1, -1, -1), 1, 1);
}
}
QPixmap DetailsButton::cacheRendering(const QSize &size, bool checked)
......
......@@ -40,18 +40,25 @@ namespace Utils {
class QTCREATOR_UTILS_EXPORT DetailsButton : public QAbstractButton
{
Q_OBJECT
Q_PROPERTY(float fader READ fader WRITE setFader)
public:
DetailsButton(QWidget *parent = 0);
QSize sizeHint() const;
float fader() { return m_fader; }
void setFader(float value) { m_fader = value; update(); }
protected:
void paintEvent(QPaintEvent *e);
bool event(QEvent *e);
private:
QPixmap cacheRendering(const QSize &size, bool checked);
QPixmap m_checkedPixmap;
QPixmap m_uncheckedPixmap;
float m_fader;
};
}
#endif // DETAILSBUTTON_H
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment