Changeset 1648:dd8672338691 in lemon-0.x
- Timestamp:
- 08/26/05 09:35:23 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2161
- Location:
- gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/graph_displayer_canvas-event.cc
r1647 r1648 33 33 case NODE_MAP_EDIT: 34 34 { 35 GdkEvent * generated=new GdkEvent();36 generated->type=GDK_KEY_PRESS;37 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;38 entryWidgetChangeHandler(generated);39 entrywidget.hide();40 35 break; 41 36 } … … 549 544 { 550 545 if(actual_tool==EDGE_MAP_EDIT) 546 { 547 switch(e->type) 551 548 { 552 switch(e->type) 553 { 554 case GDK_KEY_PRESS: 555 //for Escape or Enter hide the displayed widget 556 { 557 nodeMapEditEventHandler(e); 558 break; 559 } 560 case GDK_BUTTON_PRESS: 561 //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. 562 { 563 //for determine, whether it was an edge 564 Edge clicked_edge=INVALID; 565 566 //find the activated item between texts 567 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 568 active_item=(get_item_at(clicked_x, clicked_y)); 569 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 570 { 571 if(edgetextmap[i]==active_item) 572 { 573 clicked_edge=i; 574 } 575 } 576 577 //if it was not between texts, search for it between edges 578 if(clicked_edge==INVALID) 579 { 580 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 581 { 582 //at the same time only one can be active 583 if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item)) 584 { 585 clicked_edge=i; 586 } 587 } 588 } 589 //if it was really an edge... 590 if(clicked_edge!=INVALID) 591 { 592 // the id map is not editable 593 if (edgemap_to_edit == "id") return 0; 594 595 //If there is already edited edge, it has to be saved first 596 if(entrywidget.is_visible()) 597 { 598 GdkEvent * generated=new GdkEvent(); 599 generated->type=GDK_KEY_PRESS; 600 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; 601 entryWidgetChangeHandler(generated); 602 } 603 //If the previous value could be saved, we can go further, otherwise not 604 if(!entrywidget.is_visible()) 605 { 606 //and there is activated map 607 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 608 { 609 //activate the general variable for it 610 active_edge=clicked_edge; 611 //delete visible widget if there is 612 if(canvasentrywidget) 613 { 614 delete(canvasentrywidget); 615 } 616 617 //initialize the entry 618 entrywidget.show(); 619 620 //fill in the correct value 621 entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value()); 622 623 //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc 624 xy<double> entry_coos; 625 entry_coos.x=(edgetextmap[active_edge])->property_x().get_value(); 626 entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2; 627 entry_coos.y=(edgetextmap[active_edge])->property_y().get_value(); 628 entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2; 629 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); 630 canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4); 631 canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5); 632 633 //setting the focus to newly created widget 634 parentwin->set_focus(entrywidget); 635 parentwin->activate_focus(); 636 } 637 } 638 } 639 //if it was not an edge... 640 else 641 { 642 //In this case the click did not happen on an edge 643 //if there is visible entry we save the value in it 644 //we pretend like an Enter was presse din the Entry widget 645 GdkEvent * generated=new GdkEvent(); 646 generated->type=GDK_KEY_PRESS; 647 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; 648 entryWidgetChangeHandler(generated); 649 } 650 break; 651 } 652 default: 653 break; 654 } 549 case GDK_BUTTON_PRESS: 550 { 551 //for determine, whether it was an edge 552 Edge clicked_edge=INVALID; 553 554 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 555 active_item=(get_item_at(clicked_x, clicked_y)); 556 557 //find the activated item between texts 558 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 559 { 560 //at the same time only one can be active 561 if(edgetextmap[i]==active_item) 562 { 563 clicked_edge=i; 564 } 565 } 566 567 //if it was not between texts, search for it between edges 568 if(clicked_edge==INVALID) 569 { 570 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) 571 { 572 //at the same time only one can be active 573 if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item)) 574 { 575 clicked_edge=i; 576 } 577 } 578 } 579 580 //if it was really an edge... 581 if(clicked_edge!=INVALID) 582 { 583 // the id map is not editable 584 if (edgemap_to_edit == "id") return 0; 585 586 //and there is activated map 587 if(edgetextmap[clicked_edge]->property_text().get_value()!="") 588 { 589 //activate the general variable for it 590 active_edge=clicked_edge; 591 592 //create a dialog 593 Gtk::Dialog dialog("Edit value", *parentwin, true); 594 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 595 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 596 Gtk::VBox* vbox = dialog.get_vbox(); 597 Gtk::Adjustment adj( 598 (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge], 599 -1000000.0, 600 1000000.0, 601 1.0, 5.0, 0.0); 602 //TODO: find out why doesn't it work with 603 //numeric_limits<double>::min/max 604 Gtk::SpinButton spin(adj); 605 spin.set_numeric(true); 606 spin.set_digits(4); 607 vbox->add(spin); 608 spin.show(); 609 switch (dialog.run()) 610 { 611 case Gtk::RESPONSE_NONE: 612 case Gtk::RESPONSE_CANCEL: 613 break; 614 case Gtk::RESPONSE_ACCEPT: 615 double new_value = spin.get_value(); 616 (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] = 617 new_value; 618 std::ostringstream ostr; 619 ostr << new_value; 620 edgetextmap[active_edge]->property_text().set_value( 621 ostr.str()); 622 //mapwin.updateEdge(active_edge); 623 mapwin.updateEdge(Edge(INVALID)); 624 } 625 } 626 } 627 break; 628 } 629 default: 630 break; 655 631 } 632 } 656 633 return false; 657 634 } … … 660 637 { 661 638 if(actual_tool==NODE_MAP_EDIT) 639 { 640 switch(e->type) 662 641 { 663 switch(e->type) 664 { 665 case GDK_KEY_PRESS: 666 //for Escape or Enter hide the displayed widget 667 { 668 switch(((GdkEventKey*)e)->keyval) 669 { 670 case GDK_Escape: 671 entrywidget.hide(); 672 break; 673 case GDK_Return: 674 case GDK_KP_Enter: 675 entrywidget.hide(); 676 break; 677 default: 678 break; 679 } 680 681 break; 682 } 683 case GDK_BUTTON_PRESS: 684 //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge. 685 { 686 //for determine, whether it was a node 687 Node clicked_node=INVALID; 688 689 //find the activated item between texts 690 active_item=(get_item_at(e->button.x, e->button.y)); 691 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 692 { 693 //at the same time only one can be active 694 if(nodetextmap[i]==active_item) 695 { 696 clicked_node=i; 697 } 698 } 699 700 //if there was not, search for it between nodes 701 if(clicked_node==INVALID) 702 { 703 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 704 active_item=(get_item_at(clicked_x, clicked_y)); 705 706 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 707 { 708 //at the same time only one can be active 709 if(nodesmap[i]==active_item) 710 { 711 clicked_node=i; 712 } 713 } 714 } 715 //if it was really an edge... 716 if(clicked_node!=INVALID) 717 { 718 // the id map is not editable 719 if (nodemap_to_edit == "id") return 0; 720 //If there is already edited edge, it has to be saved first 721 if(entrywidget.is_visible()) 722 { 723 GdkEvent * generated=new GdkEvent(); 724 generated->type=GDK_KEY_PRESS; 725 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; 726 entryWidgetChangeHandler(generated); 727 } 728 //If the previous value could be saved, we can go further, otherwise not 729 if(!entrywidget.is_visible()) 730 { 731 //and there is activated map 732 if(nodetextmap[clicked_node]->property_text().get_value()!="") 733 { 734 //activate the general variable for it 735 active_node=clicked_node; 736 //delete visible widget if there is 737 if(canvasentrywidget) 738 { 739 delete(canvasentrywidget); 740 } 741 742 //initialize the entry 743 entrywidget.show(); 744 745 //fill in the correct value 746 entrywidget.set_text(nodetextmap[active_node]->property_text().get_value()); 747 748 //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc 749 xy<double> entry_coos; 750 entry_coos.x=(nodetextmap[active_node])->property_x().get_value(); 751 entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2; 752 entry_coos.y=(nodetextmap[active_node])->property_y().get_value(); 753 entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2; 754 canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget); 755 canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4); 756 canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5); 757 } 758 } 759 } 760 //if it was not an edge... 761 else 762 { 763 //In this case the click did not happen on an edge 764 //if there is visible entry we save the value in it 765 //we pretend like an Enter was presse din the Entry widget 766 GdkEvent * generated=new GdkEvent(); 767 generated->type=GDK_KEY_PRESS; 768 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter; 769 entryWidgetChangeHandler(generated); 770 } 771 break; 772 } 773 default: 774 break; 775 } 642 case GDK_BUTTON_PRESS: 643 { 644 //for determine, whether it was a node 645 Node clicked_node=INVALID; 646 647 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 648 active_item=(get_item_at(clicked_x, clicked_y)); 649 650 //find the activated item between texts 651 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 652 { 653 //at the same time only one can be active 654 if(nodetextmap[i]==active_item) 655 { 656 clicked_node=i; 657 } 658 } 659 660 //if there was not, search for it between nodes 661 if(clicked_node==INVALID) 662 { 663 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 664 { 665 //at the same time only one can be active 666 if(nodesmap[i]==active_item) 667 { 668 clicked_node=i; 669 } 670 } 671 } 672 673 //if it was really a node... 674 if(clicked_node!=INVALID) 675 { 676 // the id map is not editable 677 if (nodemap_to_edit == "id") return 0; 678 679 //and there is activated map 680 if(nodetextmap[clicked_node]->property_text().get_value()!="") 681 { 682 //activate the general variable for it 683 active_node=clicked_node; 684 685 //create a dialog 686 Gtk::Dialog dialog("Edit value", *parentwin, true); 687 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); 688 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); 689 Gtk::VBox* vbox = dialog.get_vbox(); 690 Gtk::Adjustment adj( 691 (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node], 692 -1000000.0, 693 1000000.0, 694 1.0, 5.0, 0.0); 695 //TODO: find out why doesn't it work with 696 //numeric_limits<double>::min/max 697 Gtk::SpinButton spin(adj); 698 spin.set_numeric(true); 699 spin.set_digits(4); 700 vbox->add(spin); 701 spin.show(); 702 switch (dialog.run()) 703 { 704 case Gtk::RESPONSE_NONE: 705 case Gtk::RESPONSE_CANCEL: 706 break; 707 case Gtk::RESPONSE_ACCEPT: 708 double new_value = spin.get_value(); 709 (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] = 710 new_value; 711 std::ostringstream ostr; 712 ostr << new_value; 713 nodetextmap[active_node]->property_text().set_value( 714 ostr.str()); 715 //mapwin.updateNode(active_node); 716 mapwin.updateNode(Node(INVALID)); 717 } 718 } 719 } 720 break; 721 } 722 default: 723 break; 776 724 } 725 } 777 726 return false; 778 }779 780 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)781 {782 if(entrywidget.is_visible())783 {784 if(e->type==GDK_KEY_PRESS)785 {786 switch(((GdkEventKey*)e)->keyval)787 {788 case GDK_Escape:789 entrywidget.hide();790 break;791 case GDK_KP_Enter:792 case GDK_Return:793 {794 //these variables check whether the text in the entry is valid795 bool valid_double=true;796 int point_num=0;797 798 //getting the value from the entry and converting it to double799 Glib::ustring mapvalue_str = entrywidget.get_text();800 801 char * mapvalue_ch=new char [mapvalue_str.length()];802 for(int i=0;i<(int)(mapvalue_str.length());i++)803 {804 if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))805 {806 valid_double=false;807 }808 else809 {810 if(mapvalue_str[i]=='.')811 {812 point_num++;813 }814 }815 mapvalue_ch[i]=mapvalue_str[i];816 }817 818 //if the text in the entry was correct819 if((point_num<=1)&&(valid_double))820 {821 double mapvalue_d=atof(mapvalue_ch);822 823 //reconvert the double to string for the correct format824 std::ostringstream ostr;825 ostr << mapvalue_d;826 827 //save the value to the correct place828 switch(actual_tool)829 {830 case EDGE_MAP_EDIT:831 edgetextmap[active_edge]->property_text().set_value(ostr.str());832 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;833 mapwin.updateEdge(active_edge);834 break;835 case NODE_MAP_EDIT:836 nodetextmap[active_node]->property_text().set_value(ostr.str());837 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;838 mapwin.updateNode(active_node);839 break;840 default:841 break;842 }843 entrywidget.hide();844 }845 //the text in the entry was not correct for a double846 else847 {848 std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;849 }850 851 break;852 }853 default:854 break;855 }856 }857 }858 return false;859 727 } 860 728 -
gui/graph_displayer_canvas.cc
r1645 r1648 5 5 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) : 6 6 nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph), 7 nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), 8 canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),9 target_item(NULL), nodemap_to_edit(""),edgemap_to_edit(""), mapwin(mw)7 nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms), 8 isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""), 9 edgemap_to_edit(""), mapwin(mw) 10 10 { 11 11 parentwin=mainwin; … … 14 14 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); 15 15 actual_tool=MOVE; 16 17 //setting event handler for the editor widget18 entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);19 16 20 17 active_node=INVALID; … … 35 32 delete edgesmap[e]; 36 33 delete edgetextmap[e]; 37 }38 39 if(canvasentrywidget)40 {41 delete(canvasentrywidget);42 34 } 43 35 } -
gui/graph_displayer_canvas.h
r1643 r1648 91 91 bool nodeMapEditEventHandler(GdkEvent*); 92 92 93 ///event handler for the case when the entry widget is changed94 bool entryWidgetChangeHandler(GdkEvent*);95 96 93 public: 97 94 ///Moves the text to new place … … 141 138 Gnome::Canvas::Group displayed_graph; 142 139 143 ///Map editor entry144 Gtk::Entry entrywidget;145 146 ///GnomeCanvas holder for entry147 Gnome::Canvas::Widget * canvasentrywidget;148 149 140 ///Here we store the maps that can be displayed through properties. 150 141 MapStorage & mapstorage; … … 176 167 MapWin & mapwin; 177 168 178 ///We need to store the parent window to be able to set the focus on a given widget 179 ///We will use this variable to activate the set focus on entry widget in the case of editing map values. 169 ///pointer to the parent window 180 170 Gtk::Window * parentwin; 181 171 -
gui/map_win.cc
r1643 r1648 82 82 for(;emsi!=ms.endOfNodeMaps();emsi++) 83 83 { 84 listStrings.push_back(emsi->first); 84 if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y")) 85 { 86 listStrings.push_back(emsi->first); 87 } 85 88 } 86 89 … … 149 152 for(;emsi!=ms.endOfNodeMaps();emsi++) 150 153 { 151 listStrings.push_back(emsi->first); 154 if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y")) 155 { 156 listStrings.push_back(emsi->first); 157 } 152 158 } 153 159
Note: See TracChangeset
for help on using the changeset viewer.