1
#include "TranslucentButtons.h"
3
#include <QtGui/QPainter>
6
#include <QtCore/QTimer>
7
#include <QDragEnterEvent>
8
#include <QDragMoveEvent>
9
#include <QDragLeaveEvent>
13
TranslucentButtons::TranslucentButtons(QWidget* parent):QPushButton(parent),m_enabled(true),m_pTimer(0),m_CurrentState(0),m_pImg(0)
16
m_CurrentColor = "black";
17
m_CurrentColor.setAlpha(0);
21
TranslucentButtons::~TranslucentButtons()
27
void TranslucentButtons::paintEvent(QPaintEvent* event)
30
QPainter customPainter(this);
31
customPainter.setBackground(m_CurrentColor);
32
customPainter.setBrush(m_CurrentColor);
33
customPainter.setPen(Qt::NoPen);
34
customPainter.drawRoundedRect(rect(), 10, 10);
35
customPainter.setPen(m_Pen);
38
customPainter.drawImage(QRect(QPoint(rect().x()+rect().width()-50,10),QSize(40,rect().height()-20)),*m_pImg, QRectF(m_pImg->rect()));
41
QFont font = customPainter.font();
43
customPainter.setFont(font);
44
customPainter.drawText (rect(), Qt::AlignVCenter|Qt::AlignHCenter, text().replace("&","") );
47
///Override the visibility toggler
48
void TranslucentButtons::setVisible(bool enabled)
50
kDebug() << "Enabling!";
51
if (m_enabled != enabled) {
56
m_pTimer = new QTimer(this); //TODO LEAK
57
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(changeVisibility()));
59
m_CurrentColor = "black";
60
m_CurrentColor.setAlpha(0);
66
QWidget::setVisible(enabled);
69
///Step by step animation
70
void TranslucentButtons::changeVisibility()
73
m_CurrentColor.setAlpha(0.1*m_step*m_step);
79
void TranslucentButtons::dragEnterEvent ( QDragEnterEvent *e )
84
void TranslucentButtons::dragMoveEvent ( QDragMoveEvent *e )
89
void TranslucentButtons::dragLeaveEvent ( QDragLeaveEvent *e )
94
///Propagate the mime data
95
///@note This propagate like this: button -> tree item -> treewidget
96
void TranslucentButtons::dropEvent(QDropEvent *e)
98
kDebug() << "Drop accepted";
99
emit dataDropped((QMimeData*)e->mimeData());
102
///Set the state when the user hover the widget
103
///@note This is not called directly to avoid a Qt bug/limitation
104
void TranslucentButtons::setHoverState(bool hover)
106
if (hover != m_CurrentState) {
108
int alpha = m_CurrentColor.alpha();
109
m_CurrentColor = "grey";
110
m_CurrentColor.setAlpha(alpha);
111
m_Pen.setColor("black");
114
int alpha = m_CurrentColor.alpha();
115
m_CurrentColor = "black";
116
m_CurrentColor.setAlpha(alpha);
117
m_Pen.setColor("white");
120
m_CurrentState = hover;
124
///Set the button pixmap
125
void TranslucentButtons::setPixmap(QImage* img)
b'\\ No newline at end of file'