------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2008, 2009 Vadim Godunko <vgodunko@gmail.com>                --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3225 $ $Date: 2009-04-03 17:20:32 +0400 (Fri, 03 Apr 2009) $
------------------------------------------------------------------------------
with Qt4.Graphics_Scenes.Constructors;
with Qt4.Graphics_Views.Directors;
with Qt4.Painters;
with Qt4.Strings;

with Edges.Constructors;
with Graph_Widgets.MOC;
pragma Warnings (Off, Graph_Widgets.MOC);
--  Child package MOC must be included in the executable file.
with Nodes.Constructors;

package body Graph_Widgets.Constructors is

   ------------
   -- Create --
   ------------

   function Create return not null Graph_Widget_Access is
      use type Qt4.Graphics_Views.Cache_Mode_Flags;
      use type Qt4.Q_Real;

      Self : constant Graph_Widgets.Graph_Widget_Access
        := new Graph_Widgets.Graph_Widget;

   begin
      Qt4.Graphics_Views.Directors.Constructors.Initialize (Self);

      declare
         Scene : constant not null Qt4.Graphics_Scenes.Q_Graphics_Scene_Access
           := Qt4.Graphics_Scenes.Constructors.Create (Self);

      begin
         Scene.Set_Item_Index_Method (Qt4.Graphics_Scenes.No_Index);
         Scene.Set_Scene_Rect (-200.0, -200.0, 400.0, 400.0);
         Self.Set_Scene (Scene);
         Self.Set_Cache_Mode (+Qt4.Graphics_Views.Cache_Background);
         Self.Set_Viewport_Update_Mode
          (Qt4.Graphics_Views.Bounding_Rect_Viewport_Update);
         Self.Set_Render_Hint (Qt4.Painters.Antialiasing);
         Self.Set_Transformation_Anchor
          (Qt4.Graphics_Views.Anchor_Under_Mouse);
         Self.Set_Resize_Anchor (Qt4.Graphics_Views.Anchor_View_Center);

         Self.Node_1 := Nodes.Constructors.Create (Self);
         Self.Node_2 := Nodes.Constructors.Create (Self);
         Self.Node_3 := Nodes.Constructors.Create (Self);
         Self.Node_4 := Nodes.Constructors.Create (Self);
         Self.Center_Node := Nodes.Constructors.Create (Self);
         Self.Node_6 := Nodes.Constructors.Create (Self);
         Self.Node_7 := Nodes.Constructors.Create (Self);
         Self.Node_8 := Nodes.Constructors.Create (Self);
         Self.Node_9 := Nodes.Constructors.Create (Self);

         Scene.Add_Item (Self.Node_1);
         Scene.Add_Item (Self.Node_2);
         Scene.Add_Item (Self.Node_3);
         Scene.Add_Item (Self.Node_4);
         Scene.Add_Item (Self.Center_Node);
         Scene.Add_Item (Self.Node_6);
         Scene.Add_Item (Self.Node_7);
         Scene.Add_Item (Self.Node_8);
         Scene.Add_Item (Self.Node_9);

         Self.Edge_1_2 := Edges.Constructors.Create (Self.Node_1, Self.Node_2);
         Self.Edge_2_3 := Edges.Constructors.Create (Self.Node_2, Self.Node_3);
         Self.Edge_2_C :=
           Edges.Constructors.Create (Self.Node_2, Self.Center_Node);
         Self.Edge_3_6 := Edges.Constructors.Create (Self.Node_3, Self.Node_6);
         Self.Edge_4_1 := Edges.Constructors.Create (Self.Node_4, Self.Node_1);
         Self.Edge_4_C :=
           Edges.Constructors.Create (Self.Node_4, Self.Center_Node);
         Self.Edge_C_6 :=
           Edges.Constructors.Create (Self.Center_Node, Self.Node_6);
         Self.Edge_C_8 :=
           Edges.Constructors.Create (Self.Center_Node, Self.Node_8);
         Self.Edge_6_9 := Edges.Constructors.Create (Self.Node_6, Self.Node_9);
         Self.Edge_7_4 := Edges.Constructors.Create (Self.Node_7, Self.Node_4);
         Self.Edge_8_7 := Edges.Constructors.Create (Self.Node_8, Self.Node_7);
         Self.Edge_9_8 := Edges.Constructors.Create (Self.Node_9, Self.Node_8);

         Scene.Add_Item (Self.Edge_1_2);
         Scene.Add_Item (Self.Edge_2_3);
         Scene.Add_Item (Self.Edge_2_C);
         Scene.Add_Item (Self.Edge_3_6);
         Scene.Add_Item (Self.Edge_4_1);
         Scene.Add_Item (Self.Edge_4_C);
         Scene.Add_Item (Self.Edge_C_6);
         Scene.Add_Item (Self.Edge_C_8);
         Scene.Add_Item (Self.Edge_6_9);
         Scene.Add_Item (Self.Edge_7_4);
         Scene.Add_Item (Self.Edge_8_7);
         Scene.Add_Item (Self.Edge_9_8);

         Self.Node_1.Set_Pos (-50.0, -50.0);
         Self.Node_2.Set_Pos (0.0, -50.0);
         Self.Node_3.Set_Pos (50.0, -50.0);
         Self.Node_4.Set_Pos (-50.0, 0.0);
         Self.Center_Node.Set_Pos (0.0, 0.0);
         Self.Node_6.Set_Pos (50.0, 0.0);
         Self.Node_7.Set_Pos (-50.0, 50.0);
         Self.Node_8.Set_Pos (0.0, 50.0);
         Self.Node_9.Set_Pos (50.0, 50.0);

         Self.Scale (0.8, 0.8);
         Self.Set_Minimum_Size (400, 400);
         Self.Set_Window_Title (Qt4.Strings.From_Utf_16 ("Elastic Nodes"));
      end;

      return Self;
   end Create;

end Graph_Widgets.Constructors;
