Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DefineRectanglesMouseHandler.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/DefineRectanglesMouseHandler.h         **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLQt/MouseHandler.h>
00034 #include <ICLUtils/Lockable.h>
00035 #include <ICLCore/Color.h>
00036 #include <ICLUtils/Any.h>
00037 
00038 namespace icl{
00039   namespace qt{
00040   
00042     class ICLDrawWidget;
00046 
00047 
00073 
00076 
00080 
00100     class DefineRectanglesMouseHandler :  public MouseHandler, protected utils::Lockable{
00101       public:
00103       class Options{
00104         friend class DefineRectanglesMouseHandler;
00106         Options(const core::Color4D &edgeColor=core::Color4D(0,255,0,255), 
00107                 const core::Color4D &fillColor=core::Color4D(0,255,0,50), 
00108                 const core::Color4D &centerColor=core::Color4D(0,255,0,255),
00109                 const core::Color4D &metaColor=core::Color4D(0,255,0,255),
00110                 int handleWidth=3, bool visualizeCenter=false,
00111                 bool visualizeHovering=true,
00112                 bool showOffsetText=false, 
00113                 bool showSizeText=false, 
00114                 bool showCenterText=false,
00115                 bool showMetaData=false,
00116                 int lineWidth=1,
00117                 float textSize=9);
00118         public:
00119         core::Color4D edgeColor;     
00120         core::Color4D fillColor;     
00121         core::Color4D centerColor;   
00122         core::Color4D metaColor;     
00123         int handleWidth;       
00124         bool visualizeCenter;  
00125         bool visualizeHovering;
00126         bool showOffsetText;   
00127         bool showSizeText;     
00128         bool showCenterText;   
00129         bool showMetaData;     
00130         int lineWidth;         
00131         float textSize;        
00132       };
00133   
00134       protected:
00135       
00137       struct DefinedRect : public utils::Rect{
00139         friend class DefineRectanglesMouseHandler;
00140   
00142         enum Edge{ 
00143           T, 
00144           R, 
00145           B, 
00146           L  
00147         };
00149         enum State{ 
00150           nothing, 
00151           hovered, 
00152           dragged  
00153         };
00154   
00156         State states[4];
00157   
00159         utils::Point allDragOffs;
00160   
00162         DefineRectanglesMouseHandler::Options *options;
00163         
00165         utils::Rect edge(Edge e) const;
00167         utils::Rect edgei(int i) const;
00169         utils::Rect inner() const;
00171         utils::Rect outer() const;
00173         bool allHovered() const;
00175         bool allDragged() const; 
00177         bool anyDragged() const;
00178   
00180         DefinedRect(const utils::Rect &r=utils::Rect::null, DefineRectanglesMouseHandler::Options *options=0);
00181   
00183         State event(const MouseEvent &e);
00184         
00186         void visualize(ICLDrawWidget &w);
00187   
00189         utils::Any meta;
00190       };
00191     
00192       
00193       int maxRects; 
00194       int minDim;   
00195       std::vector<DefinedRect> rects; 
00196       utils::Point currBegin; 
00197       utils::Point currCurr;  
00198       DefinedRect *draggedRect; 
00199       Options options;  
00200       public:
00201       
00203 
00206       DefineRectanglesMouseHandler(int maxRects=10, int minDim=4);
00207       
00209       void process(const MouseEvent &e);
00210       
00212 
00213       void visualize(ICLDrawWidget &w);
00214       
00216       Options &getOptions();
00217       
00219       const Options &getOptions() const;
00220       
00222       void clearAllRects();
00223       
00225 
00228       void clearRectAt(int x, int y, bool all=false);
00229       
00231 
00232       void addRect(const utils::Rect &rect);
00233       
00235 
00236       void setMaxRects(int maxRects);
00237       
00239       void setMinDim(int minDim);
00240       
00242       int getNumRects() const;
00243       
00245 
00246       utils::Rect getRectAtIndex(int index) const;
00247       
00249       std::vector<utils::Rect> getRects() const;
00250       
00252 
00255       utils::Rect getRectAt(int x, int y) const;
00256       
00258       std::vector<utils::Rect> getAllRectsAt(int x, int y) const;
00259       
00261       int getMinDim() const;
00262       
00264       int getMaxRects() const;
00265       
00267       const utils::Any &getMetaData(int index) const;
00268       
00270       const utils::Any &getMetaDataAt(int x, int y) const;
00271       
00273       void setMetaData(int index, const utils::Any &data);
00274   
00276       void setMetaDataAt(int x, int y, const utils::Any &data);
00277   
00279       void bringToFront(int idx);
00280       
00282       void bringToBack(int idx);
00283     };
00284   } // namespace qt
00285 }
00286 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines