Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Protected Attributes
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

List of all members.

Classes

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

Public Member Functions

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

Protected Attributes

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

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

        DefineRectanglesMouseHandler mouse;
        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)


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

Adds a new rectangels to the internal list.

The new rectangle becomes manipulatable automatically and immediately

brings one rectangle to the back internally

brings one rectangle to the front internally

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

returns the curren maximum rectangle count

gets the meta data associated with rect at given index

gets the meta data associated with rect at given index

returns the current minimun rectangle dimension

returns the number of rectangles that are currently defined

grants read/write access to the internal Options structure

grants read-only access to the internal Options structure (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

returns the rectangle at given index

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

returns all current rects

overwrittern MouseHandler method

Reimplemented from icl::qt::MouseHandler.

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

sets the minimal dimension for defined rectangles

automatic visualiziation

The given ICLDrawWidget must be locked and reset before


Member Data Documentation

used for the currently defined rectangle

used for the currently defined rectangle

use if any rectangle is currently moved or manipulated

maximum count of rectangles

minimum dimension of rectangles

options structure

list of defined rectanges


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines