------------------------------------------------------------------------------
--                                                                          --
--                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: 3266 $ $Date: 2009-04-18 13:27:41 +0400 (Sat, 18 Apr 2009) $
------------------------------------------------------------------------------
with Qt4.Core_Applications;
with Qt4.Fonts;
with Qt4.Grid_Layouts.Constructors;
with Qt4.Objects;
with Qt4.Push_Buttons.Constructors;
with Qt4.Strings;

with LCD_Ranges;
with Cannon_Fields;
with My_Widgets.MOC;
pragma Warnings (Off, My_Widgets.MOC);
--  Child package MOC must be included in the application.

package body My_Widgets is

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

   function Create return not null My_Widget_Access is
      Self         : constant not null My_Widgets.My_Widget_Access
        := new My_Widgets.My_Widget;
      Quit         : constant not null Qt4.Push_Buttons.Q_Push_Button_Access
        := Qt4.Push_Buttons.Constructors.Create
            (Qt4.Strings.From_Utf_16 ("Quit"));
      Family       : constant Qt4.Strings.Q_String
        := Qt4.Strings.From_Utf_16 ("Times");
      Font         : constant Qt4.Fonts.Q_Font
        := Qt4.Fonts.Create (Family, 18, Qt4.Fonts.Weight_Bold);
      Angle        : constant not null LCD_Ranges.LCD_Range_Access
        := LCD_Ranges.Create;
      Cannon_Field : constant not null Cannon_Fields.Cannon_Field_Access
        := Cannon_Fields.Create;
      Grid         : constant not null Qt4.Grid_Layouts.Q_Grid_Layout_Access
        := Qt4.Grid_Layouts.Constructors.Create;

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

      Quit.Set_Font (Font);
      Qt4.Objects.Connect
       (Quit,
        Qt4.Signal ("clicked()"),
        Qt4.Core_Applications.Instance,
        Qt4.Slot ("quit()"));

      Angle.Set_Range (5, 70);
      Qt4.Objects.Connect
       (Angle,
        Qt4.Signal ("valueChanged(int)"),
        Cannon_Field,
        Qt4.Slot ("setAngle(int)"));
      Qt4.Objects.Connect
       (Cannon_Field,
        Qt4.Signal ("angleChanged(int)"),
        Angle,
        Qt4.Slot ("setValue(int)"));
      Grid.Add_Widget (Quit, 0, 0);
      Grid.Add_Widget (Angle, 1, 0);
      Grid.Add_Widget (Cannon_Field, 1, 1, 2, 1);
      Grid.Set_Column_Stretch (1, 10);
      Self.Set_Layout (Grid);
      Angle.Set_Value (60);
      Angle.Set_Focus;

      return Self;
   end Create;

end My_Widgets;
