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 | |
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 | |
Options & | getOptions () |
grants read/write access to the internal Options structure | |
const Options & | getOptions () 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::Rect > | getRects () const |
returns all current rects | |
utils::Rect | getRectAt (int x, int y) const |
returns the rectangle at given x/y location | |
std::vector< utils::Rect > | getAllRectsAt (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::Any & | getMetaData (int index) const |
gets the meta data associated with rect at given index | |
const utils::Any & | getMetaDataAt (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< DefinedRect > | rects |
list of defined rectanges | |
utils::Point | currBegin |
used for the currently defined rectangle | |
utils::Point | currCurr |
used for the currently defined rectangle | |
DefinedRect * | draggedRect |
use if any rectangle is currently moved or manipulated | |
Options | options |
options structure |
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
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.
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)
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
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
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::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
automatic visualiziation
The given ICLDrawWidget must be locked and reset before
used for the currently defined rectangle
used for the currently defined rectangle
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 structure
std::vector<DefinedRect> icl::qt::DefineRectanglesMouseHandler::rects [protected] |
list of defined rectanges