Image Component Library (ICL)
|
MouseEvent Handler. More...
#include <MouseHandler.h>
Public Types | |
typedef void(* | mouse_handler )(const MouseEvent &event) |
mouse_handler function type | |
Public Slots | |
void | handleEvent (const MouseEvent &event) |
connected to the ICLWidget's signal mouseEventOccured | |
Public Member Functions | |
MouseHandler (mouse_handler handler) | |
Create a mouse handler with given callback function. | |
virtual void | process (const MouseEvent &event) |
this function is called automatically when the handleEvent slot is invoked | |
Protected Member Functions | |
MouseHandler () | |
This constructor can be called from derived classes. | |
Private Attributes | |
mouse_handler | m_handler |
internal mouse handler function | |
Friends | |
class | ICLWidget |
ICLWidget is allowed to connect to the private slot handleEvent. |
MouseEvent Handler.
Here's a short example:
#include <ICLQt/Common.h> #include <iterator> GenericGrabber *grabber; ICLWidget *widget; class Mouse : public MouseHandler{ public: virtual void process(const MouseEvent &event){ std::cout << "image location: " << event.getPos() << std::endl; std::cout << "widget location: " << event.getWidgetPos() << std::endl; std::string eventNames[] = {"MoveEvent","DragEvent","PressEvent","ReleaseEvent", "EnterEvent","LeaveEvent"}; std::cout << "type: " << eventNames[event.getType()] << std::endl; if(event.isPressEvent()){ if(event.getColor().size()){ std::cout << "color:"; std::copy(event.getColor().begin(),event.getColor().end(),std::ostream_iterator<icl64f>(std::cout,",")); std::cout << endl; }else{ std::cout << "no color here!" << std::endl; } } } } mouse; void init(){ widget = new ICLWidget(0); widget->setGeometry(200,200,640,480); widget->show(); grabber = new GenericGrabber; widget->install(&mouse); } void run(){ widget->setImage(grabber->grab()); widget->update(); } int main(int n, char **ppc){ return ICLApp(n,ppc,"",init,run).exec(); }
typedef void(* icl::qt::MouseHandler::mouse_handler)(const MouseEvent &event) |
mouse_handler function type
icl::qt::MouseHandler::MouseHandler | ( | mouse_handler | handler | ) | [inline, explicit] |
Create a mouse handler with given callback function.
In most cases a MouseHandler can be used directly by passing a mouse_handler function to it's constructor. The mouse handler function is called by virtual void process automatically
icl::qt::MouseHandler::MouseHandler | ( | ) | [inline, protected] |
This constructor can be called from derived classes.
derived classes will reimplement virtual void process(const MouseEvent &event), so in this case, no external mouse_handler function needs to be passed
void icl::qt::MouseHandler::handleEvent | ( | const MouseEvent & | event | ) | [slot] |
connected to the ICLWidget's signal mouseEventOccured
virtual void icl::qt::MouseHandler::process | ( | const MouseEvent & | event | ) | [virtual] |
this function is called automatically when the handleEvent slot is invoked
It can be reimplemented for custom mouse interaction. If a mouse handling function is enough for your purpose, you can also pass a function of type mouse_handler to the constructor of a MouseHandler instance. The default implementation of process calls the handler function if it's not null.
Reimplemented in icl::geom::SceneMouseHandler, icl::qt::DefineRectanglesMouseHandler, icl::qt::DragRectangleMouseHandler, and icl::qt::DefineQuadrangleMouseHandler.
internal mouse handler function