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.LGPL **
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 <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/Lockable.h>
00035 #include <ICLUtils/Any.h>
00036 #include <ICLCore/Color.h>
00037 #include <ICLQt/MouseHandler.h>
00038 
00039 namespace icl{
00040   namespace qt{
00041   
00043     class ICLDrawWidget;
00047 
00048 
00074 
00077 
00081 
00101     class ICLQt_API DefineRectanglesMouseHandler : public MouseHandler, protected utils::Lockable{
00102       public:
00104         class ICLQt_API Options{
00105         friend class DefineRectanglesMouseHandler;
00107         Options(const core::Color4D &edgeColor=core::Color4D(0,255,0,255), 
00108                 const core::Color4D &fillColor=core::Color4D(0,255,0,50), 
00109                 const core::Color4D &centerColor=core::Color4D(0,255,0,255),
00110                 const core::Color4D &metaColor=core::Color4D(0,255,0,255),
00111                 int handleWidth=3, bool visualizeCenter=false,
00112                 bool visualizeHovering=true,
00113                 bool showOffsetText=false, 
00114                 bool showSizeText=false, 
00115                 bool showCenterText=false,
00116                 bool showMetaData=false,
00117                 int lineWidth=1,
00118                 float textSize=9);
00119         public:
00120         core::Color4D edgeColor;     
00121         core::Color4D fillColor;     
00122         core::Color4D centerColor;   
00123         core::Color4D metaColor;     
00124         int handleWidth;       
00125         bool visualizeCenter;  
00126         bool visualizeHovering;
00127         bool showOffsetText;   
00128         bool showSizeText;     
00129         bool showCenterText;   
00130         bool showMetaData;     
00131         int lineWidth;         
00132         float textSize;        
00133       };
00134   
00135       protected:
00136       
00138       struct ICLQt_API DefinedRect : public utils::Rect{
00140         friend class DefineRectanglesMouseHandler;
00141   
00143         enum Edge{ 
00144           T, 
00145           R, 
00146           B, 
00147           L  
00148         };
00150         enum State{ 
00151           nothing, 
00152           hovered, 
00153           dragged  
00154         };
00155   
00157         State states[4];
00158   
00160         utils::Point allDragOffs;
00161   
00163         DefineRectanglesMouseHandler::Options *options;
00164         
00166         utils::Rect edge(Edge e) const;
00168         utils::Rect edgei(int i) const;
00170         utils::Rect inner() const;
00172         utils::Rect outer() const;
00174         bool allHovered() const;
00176         bool allDragged() const; 
00178         bool anyDragged() const;
00179   
00181         DefinedRect(const utils::Rect &r=utils::Rect::null, DefineRectanglesMouseHandler::Options *options=0);
00182   
00184         State event(const MouseEvent &e);
00185         
00187         void visualize(ICLDrawWidget &w);
00188   
00190         utils::Any meta;
00191       };
00192     
00193       
00194       int maxRects; 
00195       int minDim;   
00196       std::vector<DefinedRect> rects; 
00197       utils::Point currBegin; 
00198       utils::Point currCurr;  
00199       DefinedRect *draggedRect; 
00200       Options options;  
00201       public:
00202       
00204 
00207       DefineRectanglesMouseHandler(int maxRects=10, int minDim=4);
00208       
00210       void process(const MouseEvent &e);
00211       
00213 
00214       void visualize(ICLDrawWidget &w);
00215       
00217       Options &getOptions();
00218       
00220       const Options &getOptions() const;
00221       
00223       void clearAllRects();
00224       
00226 
00229       void clearRectAt(int x, int y, bool all=false);
00230       
00232 
00233       void addRect(const utils::Rect &rect);
00234       
00236 
00237       void setMaxRects(int maxRects);
00238       
00240       void setMinDim(int minDim);
00241       
00243       int getNumRects() const;
00244       
00246 
00247       utils::Rect getRectAtIndex(int index) const;
00248       
00250       std::vector<utils::Rect> getRects() const;
00251       
00253 
00256       utils::Rect getRectAt(int x, int y) const;
00257       
00259       std::vector<utils::Rect> getAllRectsAt(int x, int y) const;
00260       
00262       int getMinDim() const;
00263       
00265       int getMaxRects() const;
00266       
00268       const utils::Any &getMetaData(int index) const;
00269       
00271       const utils::Any &getMetaDataAt(int x, int y) const;
00272       
00274       void setMetaData(int index, const utils::Any &data);
00275   
00277       void setMetaDataAt(int x, int y, const utils::Any &data);
00278   
00280       void bringToFront(int idx);
00281       
00283       void bringToBack(int idx);
00284     };
00285   } // namespace qt
00286 }
00287 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines