group.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PAPYRUSGROUP_H
00021 #define PAPYRUSGROUP_H
00022
00023 #include <list>
00024 #include <map>
00025 #include <vector>
00026
00027 #include <papyrus/drawable.h>
00028 #include <papyrus/fill.h>
00029 #include <papyrus/rgba.h>
00030 #include <papyrus/stroke.h>
00031
00061 namespace Papyrus
00062 {
00063
00064 typedef std::vector<Drawable::pointer> Selection;
00065
00086 class Group : public Drawable
00087 {
00088 protected:
00089
00090 Group(const Glib::ustring& id=Glib::ustring());
00091
00092 Group(const AttributeValueMap& avmap);
00093
00094 public:
00095 PAPYRUS_DRAWABLE(Group);
00096
00097 static pointer create(const Glib::ustring& id=Glib::ustring());
00098
00099 static pointer create(const AttributeValueMap& avmap);
00100
00107 typedef std::list<Drawable::pointer> Layer;
00108
00113 typedef std::map<int,Layer> Layers;
00114
00115 friend class Canvas;
00116
00117 virtual ~Group();
00118
00119 const Glib::ustring& title() const;
00120
00121 void set_title( const Glib::ustring& t );
00122
00123 sigc::signal<void>& signal_title_changed();
00124
00125 const Glib::ustring& description() const;
00126
00127 void set_description( const Glib::ustring& d );
00128
00129 sigc::signal<void>& signal_description_changed();
00130
00135 virtual void freeze();
00136
00143 virtual void thaw(bool force_redraw=false);
00144
00145 virtual bool is_intermediate_drawing_enabled();
00146
00147 virtual void enable_intermediate_drawing(bool enabled=true);
00148
00149 virtual void set( const AttributeValueMap& avmap );
00150
00157 virtual bool add( Drawable::pointer item, int layer=0 );
00158
00162 virtual bool remove( Drawable::pointer object );
00163
00168 virtual bool remove( Drawable* object );
00169
00173 virtual bool clear();
00174
00180 Drawable::pointer child( const Glib::ustring& id ) const;
00181
00196 template <class T>
00197 PapyrusPointer<T> child( const Glib::ustring& id ) const
00198 {
00199 Layers::const_iterator ilayer;
00200 Layer::const_reverse_iterator ichild;
00201
00202 for ( ilayer = m_layers.begin(); ilayer != m_layers.end(); ilayer++ )
00203 {
00204 for ( ichild = ilayer->second.rbegin(); ichild != ilayer->second.rend(); ichild++ )
00205 {
00206 if ( (*ichild)->id() == id )
00207 {
00208 PapyrusPointer<T> ptr;
00209 try {
00210 ptr = papyrus_dynamic_pointer_cast<T>(*ichild);
00211 return ptr;
00212 }
00213 catch ( std::bad_cast )
00214 {
00215 }
00216 }
00217 }
00218 }
00219
00220 return PapyrusPointer<T>();
00221 }
00222
00227 virtual bool raise( Drawable::pointer item, int steps=1 );
00228
00230 virtual bool raise_to_top( Drawable::pointer item );
00231
00236 virtual bool lower( Drawable::pointer item, int steps=1 );
00237
00243 virtual bool lower_to_bottom( Drawable::pointer item );
00244
00249 virtual bool move_to_layer( int layer, Drawable::pointer item );
00250
00252 size_t size() const;
00253
00255 const Layers& layers() const;
00256
00263 const Layer& layer(int l) const throw (std::out_of_range);
00264
00266 bool has_layer( int l );
00267
00269 bool has( Drawable::pointer d ) const;
00270
00277 virtual bool inside( double x, double y );
00278
00279 virtual Selection select( double x, double y, unsigned depth = 1 );
00280
00281 sigc::signal<void, Drawable::pointer>& signal_child_added();
00282
00283 sigc::signal<void, Drawable::pointer>& signal_child_removed();
00284
00285 virtual bool is_group();
00286
00290 Fill::pointer fill();
00291
00298 void set_fill( Fill::pointer fill );
00299
00300 void set_fill ( Paint::pointer paint );
00301
00302 void set_fill( const RGBA& color );
00303
00304 void set_fill( const Glib::ustring& fill );
00305
00309 Stroke::pointer stroke();
00310
00317 void set_stroke( Stroke::pointer stroke );
00318
00319 void set_stroke ( Paint::pointer paint );
00320
00321 void set_stroke ( const RGBA& color );
00322
00323 void set_stroke ( const Glib::ustring& stroke );
00324
00326 const PaintDictionary& paint_dictionary() const;
00327
00333 Paint::pointer lookup_paint( const Glib::ustring& name ) const;
00334
00336 void add_paint_to_dictionary( const Glib::ustring& name, Paint::pointer p );
00337
00339 void remove_paint_from_dictionary( const Glib::ustring& name );
00340
00342 void clear_paint_dictionary();
00343
00345 sigc::signal<void, const Glib::ustring& >& signal_paint_added_to_dictionary();
00346
00348 sigc::signal<void, const Glib::ustring& >& signal_paint_removed_from_dictionary();
00349
00351 const DrawableDictionary& drawable_dictionary() const;
00352
00360 Drawable::pointer lookup_drawable( const Glib::ustring& name ) const;
00361
00363 void add_drawable_to_dictionary( const Glib::ustring& name, Drawable::pointer p );
00364
00366 void remove_drawable_from_dictionary( const Glib::ustring& name );
00367
00373 void clear_drawable_dictionary();
00374
00376 sigc::signal<void, const Glib::ustring& >& signal_drawable_added_to_dictionary();
00377
00379 sigc::signal<void, const Glib::ustring& >& signal_drawable_removed_from_dictionary();
00380
00381 virtual Glib::ustring svg(unsigned depth=0);
00382
00383 protected:
00384
00385
00386 Layers m_layers;
00387 size_t m_size;
00388
00389 typedef std::map<Drawable::pointer, sigc::connection> Connections;
00390 Connections m_redraw_connections;
00391 Connections m_changed_connections;
00392
00393 sigc::signal<void, Drawable::pointer> m_signal_child_added;
00394 sigc::signal<void, Drawable::pointer> m_signal_child_removed;
00395
00396 Fill::pointer m_fill;
00397 Stroke::pointer m_stroke;
00398
00399 PaintDictionary m_paint_dictionary;
00400 sigc::signal<void, const Glib::ustring& > m_signal_paint_added_to_dictionary;
00401 sigc::signal<void, const Glib::ustring& > m_signal_paint_removed_from_dictionary;
00402
00403 DrawableDictionary m_drawable_dictionary;
00404 sigc::signal<void, const Glib::ustring& > m_signal_drawable_added_to_dictionary;
00405 sigc::signal<void, const Glib::ustring& > m_signal_drawable_removed_from_dictionary;
00406
00407 Glib::ustring m_title;
00408 sigc::signal<void> m_signal_title_changed;
00409
00410 Glib::ustring m_description;
00411 sigc::signal<void> m_signal_description_changed;
00412
00413 bool m_intermediate_drawing_enabled;
00414
00415
00416
00425 virtual void on_child_changed( Drawable::pointer child );
00426
00427 virtual Region calculate_extents(const Matrix& m = Matrix::Identity, ExtentsPerformance ep = EXTENTS_QUICK) const;
00428
00429 void on_child_redraw( double x, double y, double w, double h, Drawable::pointer child );
00430
00431 virtual void draw( Context& cairo ) const;
00432
00433 void freeze_children();
00434
00435 void thaw_children(bool force_redraw=false);
00436
00437 private:
00438
00443 void on_child_changed_proxy( Drawable::pointer child );
00444
00445 };
00446
00447 }
00448
00449 #endif