00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <QPainter>
00029
00030 #include "vclicklabel.h"
00031
00032
00033
00034 VClickLabel::VClickLabel(QWidget *parent)
00035 : QWidget(parent)
00036 {
00037 setCursor(Qt::PointingHandCursor);
00038 connect(&_anim, SIGNAL(frameChanged(int)),
00039 this, SLOT(animationFrameChanged(int)));
00040 }
00041
00042
00043 QSize
00044 VClickLabel::sizeHint() const
00045 {
00046 int height = qMax(_pixmap.height(), fontMetrics().height())+2;
00047 int width = _pixmap.width() + fontMetrics().width(_text)+2;
00048 return QSize(width, height);
00049 }
00050
00051
00052 QSize
00053 VClickLabel::minimumSizeHint() const
00054 {
00055 return sizeHint();
00056 }
00057
00058
00059 void
00060 VClickLabel::paintEvent(QPaintEvent *e)
00061 {
00062 QPainter p(this);
00063 QRect rect = this->rect();
00064 if (!_pixmap.isNull())
00065 p.drawPixmap(0, qMax((rect.height()-_pixmap.height())/2,0), _pixmap);
00066 if (!_text.isEmpty())
00067 p.drawText(_pixmap.width()+2, (rect.height()+fontInfo().pixelSize())/2, _text);
00068 e->accept();
00069 }
00070
00071
00072 void
00073 VClickLabel::setAnimation(const QPixmap &animPixmap)
00074 {
00075 _anim.setPixmap(animPixmap);
00076 _anim.start();
00077 }
00078
00079
00080 void
00081 VClickLabel::animationFrameChanged(int frameNumber)
00082 {
00083 Q_UNUSED(frameNumber);
00084 _pixmap = _anim.currentFrame();
00085 update();
00086 }
00087
00088
00089 void
00090 VClickLabel::mouseReleaseEvent(QMouseEvent *e)
00091 {
00092 if (e->button() == Qt::LeftButton) {
00093 emit clicked();
00094 }
00095 e->accept();
00096 }
00097
00098
00099 void
00100 VClickLabel::setText(const QString &text)
00101 {
00102 _text = text;
00103 update();
00104 }
00105
00106
00107 void
00108 VClickLabel::setPixmap(const QPixmap &pixmap)
00109 {
00110 _anim.stop();
00111 _pixmap = pixmap;
00112 update();
00113 }
00114