------------------------------------------------------------------------------
--                                                                          --
--                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.Widgets;
private with Qt4.Paint_Events;
private with Qt4.Painters;
private with Qt4.Points;
private with Qt4.Rects;
private with Qt4.Timers;
private with Qt4.Widgets.Directors;

package Cannon_Fields is

   type Cannon_Field is limited new Qt4.Widgets.Q_Widget with private;

   type Cannon_Field_Access is access all Cannon_Field'Class;

   function Angle (Self : not null access Cannon_Field'Class)
     return Qt4.Q_Integer;

   procedure Set_Angle
    (Self  : not null access Cannon_Field'Class;
     Angle : Qt4.Q_Integer);
   pragma Q_Slot (Set_Angle, "setAngle(int)");

   function Force (Self : not null access Cannon_Field'Class)
     return Qt4.Q_Integer;

   procedure Set_Force
    (Self  : not null access Cannon_Field'Class;
     Force : Qt4.Q_Integer);
   pragma Q_Slot (Set_Force, "setForce(int)");

   function Game_Over (Self : not null access Cannon_Field'Class)
     return Boolean;

   function Is_Shooting (Self : not null access Cannon_Field'Class)
     return Boolean;

   procedure Shoot (Self  : not null access Cannon_Field'Class);
   pragma Q_Slot (Shoot, "shoot()");

   procedure New_Target (Self  : not null access Cannon_Field'Class);
   pragma Q_Slot (New_Target, "newTarget()");

   procedure Set_Game_Over (Self  : not null access Cannon_Field'Class);
   pragma Q_Slot (Set_Game_Over, "setGameOver()");

   procedure Restart_Game (Self  : not null access Cannon_Field'Class);
   pragma Q_Slot (Restart_Game, "restartGame()");

   function Create (Parent : access Qt4.Widgets.Q_Widget'Class := null)
     return not null Cannon_Field_Access;

private

   type Cannon_Field is new Qt4.Widgets.Directors.Q_Widget_Director with record
      Current_Angle    : Qt4.Q_Integer;
      Current_Force    : Qt4.Q_Integer;
      Timer_Count      : Qt4.Q_Integer;
      Auto_Shoot_Timer : Qt4.Timers.Q_Timer_Access;
      Shoot_Angle      : Qt4.Q_Float;
      Shoot_Force      : Qt4.Q_Float;
      Target           : Qt4.Points.Q_Point;
      Game_Ended       : Boolean;
   end record;

   overriding procedure Paint_Event
    (Self  : not null access Cannon_Field;
     Event : not null access Qt4.Paint_Events.Q_Paint_Event'Class);

   function Cannon_Rect (Self : not null access Cannon_Field'Class)
     return Qt4.Rects.Q_Rect;

   function Shot_Rect (Self : not null access Cannon_Field'Class)
     return Qt4.Rects.Q_Rect;

   function Target_Rect (Self : not null access Cannon_Field'Class)
     return Qt4.Rects.Q_Rect;

   procedure Paint_Shot
    (Self    : not null access Cannon_Field'Class;
     Painter : in out Qt4.Painters.Q_Painter);

   procedure Paint_Target
    (Self    : not null access Cannon_Field'Class;
     Painter : in out Qt4.Painters.Q_Painter);

   procedure Paint_Cannon
    (Self    : not null access Cannon_Field'Class;
     Painter : in out Qt4.Painters.Q_Painter);

   procedure Move_Shot (Self : not null access Cannon_Field'Class);
   pragma Q_Slot (Move_Shot, "moveShot()");

   procedure Emit_Angle_Changed
    (Self      : not null access Cannon_Field'Class;
     New_Angle : Qt4.Q_Integer);
   pragma Q_Signal (Emit_Angle_Changed, "angleChanged(int)");

   procedure Emit_Force_Changed
    (Self      : not null access Cannon_Field'Class;
     New_Force : Qt4.Q_Integer);
   pragma Q_Signal (Emit_Force_Changed, "forceChanged(int)");

   procedure Emit_Hit (Self : not null access Cannon_Field'Class);
   pragma Q_Signal (Emit_Hit, "hit()");

   procedure Emit_Missed (Self : not null access Cannon_Field'Class);
   pragma Q_Signal (Emit_Missed, "missed()");

   procedure Emit_Can_Shoot
    (Self : not null access Cannon_Field'Class;
     Can  : Boolean);
   pragma Q_Signal (Emit_Can_Shoot, "canShoot(bool)");

end Cannon_Fields;
