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