Image Component Library (ICL)
Classes | Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
icl::qt::DefineRectanglesMouseHandler Class Reference

Utility mouse handler implementation that allows to define rectangles via drag and drop. More...

#include <DefineRectanglesMouseHandler.h>

Inheritance diagram for icl::qt::DefineRectanglesMouseHandler:
icl::qt::MouseHandler icl::utils::Lockable

Classes

struct  DefinedRect
 Internally used utils::Rect structure. More...
 
class  Options
 Cummulative Options structure. More...
 

Public Member Functions

void registerCallback (const std::string &id, Callback cb)
 
void unregisterCallback (const std::string &id)
 
 DefineRectanglesMouseHandler (int maxRects=10, int minDim=4)
 Default constructor with optionally given maximum rectangle count an minimum rectangle dimension. More...
 
void process (const MouseEvent &e)
 overwrittern MouseHandler method More...
 
void visualize (ICLDrawWidget &w)
 automatic visualiziation More...
 
OptionsgetOptions ()
 grants read/write access to the internal Options structure More...
 
const OptionsgetOptions () const
 grants read-only access to the internal Options structure (const) More...
 
void clearAllRects ()
 remove all current rectangles More...
 
void clearRectAt (int x, int y, bool all=false)
 remove the first/all rectangles, that contain the given x/y coordinates More...
 
void addRect (const utils::Rect &rect)
 Adds a new rectangels to the internal list. More...
 
void setMaxRects (int maxRects)
 sets the maximum number of possible rects (more rectangles cannot be added or defined) More...
 
void setMinDim (int minDim)
 sets the minimal dimension for defined rectangles More...
 
int getNumRects () const
 returns the number of rectangles that are currently defined More...
 
utils::Rect getRectAtIndex (int index) const
 returns the rectangle at given index More...
 
std::vector< utils::RectgetRects () const
 returns all current rects More...
 
utils::Rect getRectAt (int x, int y) const
 returns the rectangle at given x/y location More...
 
std::vector< utils::RectgetAllRectsAt (int x, int y) const
 returns all rectangles that contain the given location More...
 
int getMinDim () const
 returns the current minimun rectangle dimension More...
 
int getMaxRects () const
 returns the curren maximum rectangle count More...
 
const utils::AnygetMetaData (int index) const
 gets the meta data associated with rect at given index More...
 
const utils::AnygetMetaDataAt (int x, int y) const
 gets the meta data associated with rect at given index More...
 
void setMetaData (int index, const utils::Any &data)
 associates some meta data with rect at given index More...
 
void setMetaDataAt (int x, int y, const utils::Any &data)
 sets the meta data at the rect at given x,y-position More...
 
void bringToFront (int idx)
 brings one rectangle to the front internally More...
 
void bringToBack (int idx)
 brings one rectangle to the back internally More...
 
- Public Member Functions inherited from icl::qt::MouseHandler
 MouseHandler (mouse_handler handler)
 Create a mouse handler with given callback function. More...
 

Protected Attributes

int maxRects
 maximum count of rectangles More...
 
int minDim
 minimum dimension of rectangles More...
 
std::vector< DefinedRectrects
 list of defined rectanges More...
 
utils::Point currBegin
 used for the currently defined rectangle More...
 
utils::Point currCurr
 used for the currently defined rectangle More...
 
DefinedRectdraggedRect
 use if any rectangle is currently moved or manipulated More...
 
Options options
 options structure More...
 

Private Types

typedef utils::Function< void, const std::vector< utils::Rect > & > Callback
 

Private Member Functions

void callCallbacks ()
 

Private Attributes

std::map< std::string, Callbackcallbacks
 

Additional Inherited Members

- Public Types inherited from icl::qt::MouseHandler
typedef void(* mouse_handler) (const MouseEvent &event)
 mouse_handler function type More...
 
- Public Slots inherited from icl::qt::MouseHandler
void handleEvent (const MouseEvent &event)
 connected to the ICLWidget's signal mouseEventOccured More...
 
- Protected Member Functions inherited from icl::qt::MouseHandler
 MouseHandler ()
 This constructor can be called from derived classes. More...
 
- Protected Member Functions inherited from icl::utils::Lockable
 Lockable (bool recursive=false)
 Default constructor. More...
 
 Lockable (const Lockable &l)
 copy constructor (does not copy the source mutex) More...
 
Lockableoperator= (const Lockable &l)
 assignment operator (does not copy the source mutex) More...
 
 ~Lockable ()
 Destructor. More...
 
void lock () const
 lock object More...
 
void unlock () const
 unlock object More...
 
MutexgetMutex () const
 returns mutex of this object More...
 

Detailed Description

Utility mouse handler implementation that allows to define rectangles via drag and drop.

The DefineRectanglesMouseHandler can easily be installed on an ICLDrawWidget instance. It's current state can be visualized by using it's visualize-method in the applications working loop.

Mouse Interaction

Detailed Description

The left mouse button is used for most interaction stuff. It is used to define new rectangles: Simply use a drag and drop gesture to define the rectangle. The left mouse button is also used to modify already existing rectangles: the user can either drag edges of existing rectangles or corners (i.e. two edges) or the whole rect by dragging any point in the center of the rectangle. The right mouse button is used to delete existing rectangles. The middle mousebutton can be used to chage a rectangles layer. Rectangles that were defined first are preferred during interaction. If you press the middle mouse button on a rectangle it is put to the back of the internal list, i.e. all other are 'in front of it'.

Operations

Options can be set like

mouse.getOptions().edgeColor = Color4D(255,0,0,255);
mouse.getOptions().fillColor[3] = 0;
mouse.getOptions().handleWidth = 7;

Please read the default options from the default arguments of the DefineRectanglesMouseHandler::Options::Options constructor.

Maximum Rectangle Count

Due to performance issues, one should not use this interactor to manipulate more than some hundred rectangles. To avoid an overflow, the maxinum rectangle count is used.

Minimum Rectangle Size

The minimal size for rectagles is used to avoid very small rectangles that can only hardly be manipulated (if the rectangle is only 1x1-pixels, it becomes hard to grab it or one of it's edge handles. If the minimum rectangle count is set afterwards, extra rectagles are dropped automatically.

Thread Safety

All methods of this class are implemented in a thread-saft manner. Therefore no additional locking is neccessary (and Lockable is inherited protectedly)

Member Typedef Documentation

Constructor & Destructor Documentation

icl::qt::DefineRectanglesMouseHandler::DefineRectanglesMouseHandler ( int  maxRects = 10,
int  minDim = 4 
)

Default constructor with optionally given maximum rectangle count an minimum rectangle dimension.

See also
Maximum Rectangle Count
Minimum Rectangle Size

Member Function Documentation

void icl::qt::DefineRectanglesMouseHandler::addRect ( const utils::Rect rect)

Adds a new rectangels to the internal list.

The new rectangle becomes manipulatable automatically and immediately

void icl::qt::DefineRectanglesMouseHandler::bringToBack ( int  idx)

brings one rectangle to the back internally

void icl::qt::DefineRectanglesMouseHandler::bringToFront ( int  idx)

brings one rectangle to the front internally

void icl::qt::DefineRectanglesMouseHandler::callCallbacks ( )
private
void icl::qt::DefineRectanglesMouseHandler::clearAllRects ( )

remove all current rectangles

void icl::qt::DefineRectanglesMouseHandler::clearRectAt ( int  x,
int  y,
bool  all = false 
)

remove the first/all rectangles, that contain the given x/y coordinates

Since rectangles might overlap more that one rectangle might contain the given coordinates. Set the parameter all to true if you want to delete all rectangles that contain the given x/y point.

std::vector<utils::Rect> icl::qt::DefineRectanglesMouseHandler::getAllRectsAt ( int  x,
int  y 
) const

returns all rectangles that contain the given location

int icl::qt::DefineRectanglesMouseHandler::getMaxRects ( ) const

returns the curren maximum rectangle count

const utils::Any& icl::qt::DefineRectanglesMouseHandler::getMetaData ( int  index) const

gets the meta data associated with rect at given index

const utils::Any& icl::qt::DefineRectanglesMouseHandler::getMetaDataAt ( int  x,
int  y 
) const

gets the meta data associated with rect at given index

int icl::qt::DefineRectanglesMouseHandler::getMinDim ( ) const

returns the current minimun rectangle dimension

int icl::qt::DefineRectanglesMouseHandler::getNumRects ( ) const

returns the number of rectangles that are currently defined

Options& icl::qt::DefineRectanglesMouseHandler::getOptions ( )

grants read/write access to the internal Options structure

const Options& icl::qt::DefineRectanglesMouseHandler::getOptions ( ) const

grants read-only access to the internal Options structure (const)

utils::Rect icl::qt::DefineRectanglesMouseHandler::getRectAt ( int  x,
int  y 
) const

returns the rectangle at given x/y location

Here only the top-most rectangle is returned. If you want to obtain all rectangles, that contain the given position, you have to use the getAllRects-method

utils::Rect icl::qt::DefineRectanglesMouseHandler::getRectAtIndex ( int  index) const

returns the rectangle at given index

If index is < 0 or >= getNumRects(), utils::Rect::null is returned

std::vector<utils::Rect> icl::qt::DefineRectanglesMouseHandler::getRects ( ) const

returns all current rects

void icl::qt::DefineRectanglesMouseHandler::process ( const MouseEvent e)
virtual

overwrittern MouseHandler method

Reimplemented from icl::qt::MouseHandler.

void icl::qt::DefineRectanglesMouseHandler::registerCallback ( const std::string &  id,
Callback  cb 
)
void icl::qt::DefineRectanglesMouseHandler::setMaxRects ( int  maxRects)

sets the maximum number of possible rects (more rectangles cannot be added or defined)

See also
Maximum Rectangle Count
void icl::qt::DefineRectanglesMouseHandler::setMetaData ( int  index,
const utils::Any data 
)

associates some meta data with rect at given index

void icl::qt::DefineRectanglesMouseHandler::setMetaDataAt ( int  x,
int  y,
const utils::Any data 
)

sets the meta data at the rect at given x,y-position

void icl::qt::DefineRectanglesMouseHandler::setMinDim ( int  minDim)

sets the minimal dimension for defined rectangles

void icl::qt::DefineRectanglesMouseHandler::unregisterCallback ( const std::string &  id)
void icl::qt::DefineRectanglesMouseHandler::visualize ( ICLDrawWidget w)

automatic visualiziation

The given ICLDrawWidget must be locked and reset before

Member Data Documentation

std::map<std::string,Callback> icl::qt::DefineRectanglesMouseHandler::callbacks
private
utils::Point icl::qt::DefineRectanglesMouseHandler::currBegin
protected

used for the currently defined rectangle

utils::Point icl::qt::DefineRectanglesMouseHandler::currCurr
protected

used for the currently defined rectangle

DefinedRect* icl::qt::DefineRectanglesMouseHandler::draggedRect
protected

use if any rectangle is currently moved or manipulated

int icl::qt::DefineRectanglesMouseHandler::maxRects
protected

maximum count of rectangles

int icl::qt::DefineRectanglesMouseHandler::minDim
protected

minimum dimension of rectangles

Options icl::qt::DefineRectanglesMouseHandler::options
protected

options structure

std::vector<DefinedRect> icl::qt::DefineRectanglesMouseHandler::rects
protected

list of defined rectanges


The documentation for this class was generated from the following file: