Image Component Library (ICL)
|
Utility mouse handler implementation that allows to define rectangles via drag and drop. More...
#include <DefineRectanglesMouseHandler.h>
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... | |
Options & | getOptions () |
grants read/write access to the internal Options structure More... | |
const Options & | getOptions () 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::Rect > | getRects () 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::Rect > | getAllRectsAt (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::Any & | getMetaData (int index) const |
gets the meta data associated with rect at given index More... | |
const utils::Any & | getMetaDataAt (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< DefinedRect > | rects |
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... | |
DefinedRect * | draggedRect |
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, Callback > | callbacks |
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... | |
Lockable & | operator= (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... | |
Mutex & | getMutex () const |
returns mutex of this object More... | |
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.
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'.
Options can be set like
Please read the default options from the default arguments of the DefineRectanglesMouseHandler::Options::Options constructor.
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.
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.
All methods of this class are implemented in a thread-saft manner. Therefore no additional locking is neccessary (and Lockable is inherited protectedly)
|
private |
icl::qt::DefineRectanglesMouseHandler::DefineRectanglesMouseHandler | ( | int | maxRects = 10 , |
int | minDim = 4 |
||
) |
Default constructor with optionally given maximum rectangle count an minimum rectangle dimension.
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
|
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
|
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)
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
|
private |
|
protected |
used for the currently defined rectangle
|
protected |
used for the currently defined rectangle
|
protected |
use if any rectangle is currently moved or manipulated
|
protected |
maximum count of rectangles
|
protected |
minimum dimension of rectangles
|
protected |
options structure
|
protected |
list of defined rectanges