------------------------------------------------------------------------------
--                                                                          --
--                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 Qt4.V_Box_Layouts.Constructors;

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

package body My_Widgets is

   ------------------
   -- Constructors --
   ------------------

   package body Constructors is

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

      function Create return not null My_Widget_Access is
         use type LCD_Ranges.LCD_Range_Access;

         Self           : constant My_Widgets.My_Widget_Access
           := new My_Widgets.My_Widget;
         Quit           : constant not null access
           Qt4.Push_Buttons.Q_Push_Button'Class
             := 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);
         Grid           : constant not null access
           Qt4.Grid_Layouts.Q_Grid_Layout'Class
             := Qt4.Grid_Layouts.Constructors.Create;
         Layout         : constant not null access
           Qt4.V_Box_Layouts.Q_V_Box_Layout'Class
             := Qt4.V_Box_Layouts.Constructors.Create;
         Previous_Range : LCD_Ranges.LCD_Range_Access;

      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()"));

         for Row in Qt4.Q_Integer'(1) .. Qt4.Q_Integer'(3) loop
            for Column in Qt4.Q_Integer'(1) .. Qt4.Q_Integer'(3) loop
               declare
                  The_LCD_Range : constant not null LCD_Ranges.LCD_Range_Access
                    := LCD_Ranges.Create;

               begin
                  Grid.Add_Widget (The_LCD_Range, Row, Column);

                  if Previous_Range /= null then
                     Qt4.Objects.Connect
                      (The_LCD_Range,
                       Qt4.Signal ("valueChanged(int)"),
                       Previous_Range,
                       Qt4.Slot ("setValue(int)"));
                  end if;

                  Previous_Range := The_LCD_Range;
               end;
            end loop;
         end loop;

         Layout.Add_Widget (Quit);
         Layout.Add_Layout (Grid);
         Self.Set_Layout (Layout);

         return Self;
      end Create;

   end Constructors;

end My_Widgets;
