graph_displayer_canvas.h
author hegyi
Fri, 10 Jun 2005 12:11:50 +0000
branchgui
changeset 10 43ddd0c9d881
parent 6 603b85626bc0
child 11 09b2a893fc9d
permissions -rw-r--r--
Sorry, forgot to commit two new files.
ladanyi@6
     1
// -*- C++ -*- //
ladanyi@6
     2
ladanyi@6
     3
#ifndef GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     4
#define GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     5
ladanyi@6
     6
#include <all_include.h>
ladanyi@6
     7
#include <mapstorage.h>
ladanyi@6
     8
#include <libgnomecanvasmm.h>
ladanyi@6
     9
#include <libgnomecanvasmm/polygon.h>
ladanyi@6
    10
ladanyi@6
    11
///This class is the canvas, on which the graph can be drawn.
ladanyi@6
    12
class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
ladanyi@6
    13
{
ladanyi@6
    14
  typedef Gnome::Canvas::CanvasAA Parent;
ladanyi@6
    15
ladanyi@6
    16
public:
ladanyi@6
    17
  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
ladanyi@6
    18
  virtual ~GraphDisplayerCanvas();
ladanyi@6
    19
ladanyi@6
    20
  ///Changes the linewidth attribute according to the given map.
ladanyi@6
    21
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    22
  int changeLineWidth (std::string mapname);
ladanyi@6
    23
ladanyi@6
    24
  ///Changes the linecolor attribute according to the given map.
ladanyi@6
    25
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    26
  int changeColor (std::string mapname);
ladanyi@6
    27
ladanyi@6
    28
  ///Changes the text of line attribute according to the given map.
ladanyi@6
    29
  ///\param mapname is the name of the map which contains the new values
ladanyi@6
    30
  int changeText (std::string mapname);
ladanyi@6
    31
ladanyi@6
    32
  ///Callback for 'ViewZoomIn' action.
ladanyi@6
    33
  virtual void zoomIn();
ladanyi@6
    34
  ///Callback for 'ViewZoomOut' action.
ladanyi@6
    35
  virtual void zoomOut();
ladanyi@6
    36
  ///Callback for 'ViewZoomFit' action.
ladanyi@6
    37
  virtual void zoomFit();
ladanyi@6
    38
  ///Callback for 'ViewZoom100' action.
ladanyi@6
    39
  virtual void zoom100();
ladanyi@6
    40
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@6
    41
  void updateScrollRegion();
ladanyi@6
    42
hegyi@9
    43
  ///This function changes the tool in the graph-editor's hand
hegyi@9
    44
  void changeEditorialTool(int);
hegyi@9
    45
ladanyi@6
    46
protected:
ladanyi@6
    47
ladanyi@6
    48
  //maximizing, minimizing, restoring window, etc. 
ladanyi@6
    49
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@6
    50
ladanyi@6
    51
private:
ladanyi@6
    52
ladanyi@6
    53
  ///This function is responsible for the correct
ladanyi@6
    54
  ///reaction of any action happened in the territory
ladanyi@6
    55
  ///of the canvas
ladanyi@6
    56
  bool event_handler(GdkEvent* e, Node n);
ladanyi@6
    57
hegyi@9
    58
  ///actual event handler
hegyi@9
    59
  ///
hegyi@9
    60
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@9
    61
  sigc::connection actual_handler;
hegyi@9
    62
hegyi@9
    63
  ///event handler for the case when move-tool is active
hegyi@9
    64
  bool move_event_handler(GdkEvent*);
hegyi@9
    65
  ///event handler for the case when create_node-tool is active
hegyi@9
    66
  bool create_node_event_handler(GdkEvent*);
hegyi@9
    67
  ///event handler for the case when create_edge-tool is active
hegyi@9
    68
  bool create_edge_event_handler(GdkEvent*);
hegyi@9
    69
ladanyi@6
    70
  ///The graph, on which we work
ladanyi@6
    71
  Graph g;
ladanyi@6
    72
ladanyi@6
    73
  ///Map of nodes of graph
ladanyi@6
    74
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
    75
ladanyi@6
    76
  ///Map of edges of graph
ladanyi@6
    77
  Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
ladanyi@6
    78
ladanyi@6
    79
  ///Map of texts to write on edges
ladanyi@6
    80
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
    81
ladanyi@6
    82
  ///Group of graphical elements of displayed_graph
ladanyi@6
    83
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
    84
ladanyi@6
    85
  ///Here we store the maps that can be displayed through properties.
ladanyi@6
    86
  MapStorage mapstorage;
ladanyi@6
    87
ladanyi@6
    88
  ///Indicates whether the button of mouse is pressed or not
ladanyi@6
    89
  bool isbutton;
ladanyi@6
    90
ladanyi@6
    91
  ///At this location was the mousebutton pressed.
ladanyi@6
    92
  ///It helps to calculate the distance of dragging.
ladanyi@6
    93
  double clicked_x, clicked_y;
ladanyi@6
    94
ladanyi@6
    95
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
    96
  ///this variable is needed, because
ladanyi@6
    97
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
    98
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
ladanyi@6
    99
  Gnome::Canvas::Item * active_item;
hegyi@9
   100
  Graph::NodeIt active_node;
ladanyi@6
   101
ladanyi@6
   102
  static const int zoom_step = 5;
ladanyi@6
   103
};
ladanyi@6
   104
ladanyi@6
   105
#endif //GRAPH_DISPLAYER_CANVAS_H