gui/graph_displayer_canvas-event.cc
changeset 1562 73c3f5d0079c
parent 1551 2b45f64f6377
child 1579 ed7da82bbecf
equal deleted inserted replaced
5:bdef6c9a4e96 6:87f14fb42fd1
    11   return true;
    11   return true;
    12 }
    12 }
    13 
    13 
    14 void GraphDisplayerCanvas::changeEditorialTool(int newtool)
    14 void GraphDisplayerCanvas::changeEditorialTool(int newtool)
    15 {
    15 {
    16   actual_handler.disconnect();
    16   if(actual_tool!=newtool)
    17 
       
    18   if(actual_tool==CREATE_EDGE)
       
    19     {
    17     {
    20 	GdkEvent * generated=new GdkEvent();
    18 
    21 	generated->type=GDK_BUTTON_RELEASE;
    19       actual_handler.disconnect();
    22 	generated->button.button=3;
    20 
    23 	createEdgeEventHandler(generated);      
    21       switch(actual_tool)
    24     }
    22 	{
    25 
    23 	case CREATE_EDGE:
    26   actual_tool=newtool;
    24 	  {
    27 
    25 	    GdkEvent * generated=new GdkEvent();
    28   active_item=NULL; 
    26 	    generated->type=GDK_BUTTON_RELEASE;
    29   target_item=NULL; 
    27 	    generated->button.button=3;
    30   active_edge=INVALID;	
    28 	    createEdgeEventHandler(generated);      
    31   active_node=INVALID;	
    29 	    break;
    32 
    30 	  }
    33   switch(newtool)
    31 	case EDGE_MAP_EDIT:
    34     {
    32 	  break;
    35     case MOVE:
    33 	default:
    36       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    34 	  break;
    37       break;
    35 	}
    38 
    36 
    39     case CREATE_NODE:
    37       active_item=NULL; 
    40       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
    38       target_item=NULL; 
    41       break;
    39       active_edge=INVALID;	
    42 
    40       active_node=INVALID;	
    43     case CREATE_EDGE:
    41 
    44       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
    42 
    45       break;
    43       actual_tool=newtool;
    46 
    44   
    47     case ERASER:
    45       switch(newtool)
    48       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
    46 	{
    49       break;
    47 	case MOVE:
    50 
    48 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    51     case EDGE_MAP_EDIT:
    49 	  break;
    52       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
    50 
    53       break;
    51 	case CREATE_NODE:
    54 
    52 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
    55     case NODE_MAP_EDIT:
    53 	  break;
    56       actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
    54 
    57       break;
    55 	case CREATE_EDGE:
    58 
    56 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
    59     default:
    57 	  break;
    60       break;
    58 
       
    59 	case ERASER:
       
    60 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
       
    61 	  break;
       
    62 
       
    63 	case EDGE_MAP_EDIT:
       
    64 	  grab_focus();
       
    65 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
       
    66 	  break;
       
    67 
       
    68 	case NODE_MAP_EDIT:
       
    69 	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
       
    70 	  break;
       
    71 
       
    72 	default:
       
    73 	  break;
       
    74 	}
    61     }
    75     }
    62 }
    76 }
    63 
    77 
    64 int GraphDisplayerCanvas::getActualTool()
    78 int GraphDisplayerCanvas::getActualTool()
    65 {
    79 {
   490 
   504 
   491 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
   505 bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
   492 {
   506 {
   493   switch(e->type)
   507   switch(e->type)
   494     {
   508     {
       
   509     case GDK_KEY_PRESS:
       
   510       {
       
   511 	std::cout << "Any button was pressed" << std::endl;
       
   512 	switch(((GdkEventKey*)e)->keyval)
       
   513 	  {
       
   514 	  case GDK_A:
       
   515 	    std::cout << "A button was pressed" << std::endl;
       
   516 	    break;
       
   517 	  default:
       
   518 	    break;
       
   519 	  }
       
   520   
       
   521 	break;
       
   522       }
   495     case GDK_BUTTON_PRESS:
   523     case GDK_BUTTON_PRESS:
   496       window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   524       {
   497       active_item=(get_item_at(clicked_x, clicked_y));
   525 	window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   498       active_edge=INVALID;
   526 	active_item=(get_item_at(clicked_x, clicked_y));
   499       for (EdgeIt i(g); i!=INVALID; ++i)
   527 	Graph::EdgeIt clicked_edge=INVALID;
   500 	{
   528 	for (EdgeIt i(g); i!=INVALID; ++i)
   501 	  if(edgesmap[i]==active_item)
   529 	  {
   502 	    {
   530 	    if(edgesmap[i]==active_item)
   503 	      active_edge=i;
   531 	      {
   504 	    }
   532 		clicked_edge=i;
   505 	}
   533 	      }
   506       if((active_edge!=INVALID)&&(edgetextmap[active_edge]->property_text().get_value()!=""))
   534 	  }
   507 	{
   535 	if(clicked_edge!=INVALID)
   508 	  if(canvasentrywidget)
   536 	  {
   509 	    {
   537 	    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
   510 	      delete(canvasentrywidget);
   538 	      {
   511 	    }
   539 		active_edge=clicked_edge;
   512 	  entrywidget.show();
   540 		if(canvasentrywidget)
   513 	  entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
   541 		  {
   514 	  xy<double> entry_coos;
   542 		    delete(canvasentrywidget);
   515 	  entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
   543 		  }
   516 	  entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
   544 		entrywidget.show();
   517 	  entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
   545 		entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
   518 	  entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
   546 		xy<double> entry_coos;
   519 	  canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
   547 		entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
   520 	  canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
   548 		entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
   521 	  canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
   549 		entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
   522 	}
   550 		entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
   523       break;
   551 		canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
       
   552 		canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*1.5);
       
   553 		canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
       
   554 	      }
       
   555 	  }
       
   556 	else
       
   557 	  {
       
   558 	    //mentse el -> problema, hogy nem tudja melyik map-be
       
   559 	    entrywidget.hide();
       
   560 	  }
       
   561 	break;
       
   562       }
   524     default:
   563     default:
   525       break;
   564       break;
   526     }
   565     }
   527   return false;  
   566   return false;  
   528 }
   567 }
   529 
   568 
   530 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
   569 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
   531 {
   570 {
       
   571   e=e;
       
   572   return false;
       
   573 }
       
   574 
       
   575 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
       
   576 {
       
   577   Glib::ustring mapvalue = entrywidget.get_text();
       
   578   std::cout << mapvalue << std::endl;
   532   e=e;
   579   e=e;
   533   return false;
   580   return false;
   534 }
   581 }
   535 
   582 
   536 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
   583 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)