Vidalia
0.2.17
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file VClickLabel.h 00013 ** \brief Custom widget to create a clickable label with both an image and text. 00014 */ 00015 00016 #ifndef _VCLICKLABEL_H 00017 #define _VCLICKLABEL_H 00018 00019 #include <QWidget> 00020 #include <QPixmap> 00021 #include <QMouseEvent> 00022 #include <QSize> 00023 00024 00025 class VClickLabel : public QWidget 00026 { 00027 Q_OBJECT 00028 00029 public: 00030 /** Default constructor. */ 00031 VClickLabel(QWidget *parent = 0); 00032 00033 /** Returns the current size hint for this widget's current contents. */ 00034 virtual QSize sizeHint() const; 00035 /** Returns the minimum size hint for this widget's current contents. */ 00036 virtual QSize minimumSizeHint() const; 00037 00038 /** Sets the label text to <b>text</b>. */ 00039 void setText(const QString &text); 00040 /** Sets the widget's image to <b>img</b>. */ 00041 void setPixmap(const QPixmap &img); 00042 00043 const QString& text() const { return _text; } 00044 const QPixmap& pixmap() const { return _pixmap; } 00045 00046 Q_PROPERTY(QString text READ text WRITE setText USER true); 00047 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap USER true); 00048 00049 signals: 00050 /** Emitted when the widget is left-clicked. */ 00051 void clicked(); 00052 00053 protected: 00054 /** Overloaded paint event to draw a pixmap and a text label. */ 00055 virtual void paintEvent(QPaintEvent *e); 00056 /** Overloaded mouse event to catch left mouse button clicks. */ 00057 virtual void mouseReleaseEvent(QMouseEvent *e); 00058 00059 private: 00060 QString _text; /**< Text label to display in the widget. */ 00061 QPixmap _pixmap; /**< Image to display in the widget. */ 00062 }; 00063 00064 #endif 00065