00001 // vim:set ts=4 sw=4 noet cin: 00002 #ifndef CLICKABLELABEL_H_ 00003 #define CLICKABLELABEL_H_ 00004 00005 #include <QLabel> 00006 00011 class ClickHandler { 00012 public: 00013 virtual ~ClickHandler() {} 00014 virtual void clickEvent(QPoint pos, bool rightButton) = 0; 00015 }; 00016 00022 class MoveHandler { 00023 public: 00024 virtual ~MoveHandler() {} 00025 virtual void moveEvent(QPoint pos) = 0; 00026 }; 00027 00032 class ClickableLabel : public QLabel { 00033 public: 00034 ClickableLabel(QWidget* parent = NULL) : QLabel(parent), handler(0), moveHandler(0) {} 00039 void setClickHandler(ClickHandler* aHandler) { handler = aHandler; } 00044 void setMoveHandler(MoveHandler* aHandler) { moveHandler = aHandler; setMouseTracking(moveHandler != NULL); } 00045 protected: 00046 virtual void mousePressEvent(QMouseEvent * e); 00047 virtual void mouseMoveEvent(QMouseEvent * e); 00048 00049 ClickHandler* handler; 00050 MoveHandler* moveHandler; 00051 }; 00052 00053 #endif