------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2010 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.                                              --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3764 $ $Date: 2010-10-23 23:13:39 +0400 (Sat, 23 Oct 2010) $
------------------------------------------------------------------------------
private with Ada.Finalization;
with Interfaces.C;
with Qt4.Byte_Arrays;
with Qt4.Colors;
with Qt4.Image_IO_Handlers;
with Qt4.Images;
with Qt4.List_Of_Q_Byte_Arrays;
with Qt4.Rects;
with Qt4.Sizes;
with Qt4.String_Lists;
with Qt4.Strings;
private with Qt_Ada.Internals.Value_Class_Sizes;
with System;

package Qt4.Image_Readers is

   --  QImageReader::ImageReaderError

   type Image_Reader_Error is
    (Unknown_Error,
     File_Not_Found_Error,
     Device_Error,
     Unsupported_Format_Error,
     Invalid_Data_Error);
   pragma Convention (C, Image_Reader_Error);
   for Image_Reader_Error'Size use Interfaces.C.unsigned'Size;

   type Q_Image_Reader is tagged limited private;

   function Create
    (File_Name : Qt4.Strings.Q_String'Class;
     Format : Qt4.Byte_Arrays.Q_Byte_Array'Class)
       return Q_Image_Reader;

   function Auto_Detect_Image_Format
    (Self : Q_Image_Reader'Class)
       return Boolean;

   function Background_Color
    (Self : Q_Image_Reader'Class)
       return Qt4.Colors.Q_Color;

   function Can_Read
    (Self : Q_Image_Reader'Class)
       return Boolean;

   function Clip_Rect
    (Self : Q_Image_Reader'Class)
       return Qt4.Rects.Q_Rect;

   function Current_Image_Number
    (Self : Q_Image_Reader'Class)
       return Qt4.Q_Integer;

   function Current_Image_Rect
    (Self : Q_Image_Reader'Class)
       return Qt4.Rects.Q_Rect;

   function Decide_Format_From_Content
    (Self : Q_Image_Reader'Class)
       return Boolean;

   function Error
    (Self : Q_Image_Reader'Class)
       return Image_Reader_Error;

   function Error_String
    (Self : Q_Image_Reader'Class)
       return Qt4.Strings.Q_String;

   function File_Name
    (Self : Q_Image_Reader'Class)
       return Qt4.Strings.Q_String;

   function Format
    (Self : Q_Image_Reader'Class)
       return Qt4.Byte_Arrays.Q_Byte_Array;

   function Image_Count
    (Self : Q_Image_Reader'Class)
       return Qt4.Q_Integer;

   function Image_Format
    (Self : Q_Image_Reader'Class)
       return Qt4.Images.Image_Format;

   function Jump_To_Image
    (Self : not null access Q_Image_Reader'Class;
     Image_Number : Qt4.Q_Integer)
       return Boolean;

   function Jump_To_Next_Image
    (Self : not null access Q_Image_Reader'Class)
       return Boolean;

   function Loop_Count
    (Self : Q_Image_Reader'Class)
       return Qt4.Q_Integer;

   function Next_Image_Delay
    (Self : Q_Image_Reader'Class)
       return Duration;

   function Quality
    (Self : Q_Image_Reader'Class)
       return Qt4.Q_Integer;

   function Read
    (Self : not null access Q_Image_Reader'Class)
       return Qt4.Images.Q_Image;

   function Read
    (Self : not null access Q_Image_Reader'Class;
     Image : not null access Qt4.Images.Q_Image'Class)
       return Boolean;

   function Scaled_Clip_Rect
    (Self : Q_Image_Reader'Class)
       return Qt4.Rects.Q_Rect;

   function Scaled_Size
    (Self : Q_Image_Reader'Class)
       return Qt4.Sizes.Q_Size;

   procedure Set_Auto_Detect_Image_Format
    (Self : in out Q_Image_Reader'Class;
     Enabled : Boolean);

   procedure Set_Background_Color
    (Self : in out Q_Image_Reader'Class;
     Color : Qt4.Colors.Q_Color'Class);

   procedure Set_Clip_Rect
    (Self : in out Q_Image_Reader'Class;
     Rect : Qt4.Rects.Q_Rect'Class);

   procedure Set_Decide_Format_From_Content
    (Self : in out Q_Image_Reader'Class;
     Ignored : Boolean);

   procedure Set_File_Name
    (Self : in out Q_Image_Reader'Class;
     File_Name : Qt4.Strings.Q_String'Class);

   procedure Set_Format
    (Self : in out Q_Image_Reader'Class;
     Format : Qt4.Byte_Arrays.Q_Byte_Array'Class);

   procedure Set_Quality
    (Self : in out Q_Image_Reader'Class;
     Quality : Qt4.Q_Integer);

   procedure Set_Scaled_Clip_Rect
    (Self : in out Q_Image_Reader'Class;
     Rect : Qt4.Rects.Q_Rect'Class);

   procedure Set_Scaled_Size
    (Self : in out Q_Image_Reader'Class;
     Size : Qt4.Sizes.Q_Size'Class);

   function Size
    (Self : Q_Image_Reader'Class)
       return Qt4.Sizes.Q_Size;

   function Supports_Animation
    (Self : Q_Image_Reader'Class)
       return Boolean;

   function Supports_Option
    (Self : Q_Image_Reader'Class;
     Option : Qt4.Image_IO_Handlers.Image_Option)
       return Boolean;

   function Text
    (Self : Q_Image_Reader'Class;
     Key : Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String;

   function Text_Keys
    (Self : Q_Image_Reader'Class)
       return Qt4.String_Lists.Q_String_List;

   function Image_Format
    (File_Name : Qt4.Strings.Q_String'Class)
       return Qt4.Byte_Arrays.Q_Byte_Array;

   function Supported_Image_Formats
     return Qt4.List_Of_Q_Byte_Arrays.Q_List_Of_Q_Byte_Array;

   package Internals is

      type QImageReader is private;

      type QImageReader_Access is access all QImageReader;
      pragma Convention (C, QImageReader_Access);

      function QImageReader_View
       (Item : Q_Image_Reader'Class)
          return QImageReader_Access;
      pragma Inline (QImageReader_View);

      function To_Pointer
       (Address : System.Address)
          return QImageReader_Access;
      pragma Inline (To_Pointer);

      function To_Address
       (Pointer : QImageReader_Access)
          return System.Address;
      pragma Inline (To_Address);

      function Create_Wrapper
       (Item : Internals.QImageReader_Access)
          return Q_Image_Reader;

   private

      type QImageReader is record
         Placeholder : Interfaces.C.char_array (1 .. Qt_Ada.Internals.Value_Class_Sizes.QImageReader_C_Size_Of);
      end record;
      pragma Convention (C, QImageReader);

   end Internals;

private

   type Q_Image_Reader is new Ada.Finalization.Limited_Controlled with record
      Storage : aliased Internals.QImageReader;
      Object  : Internals.QImageReader_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Finalize (Self : in out Q_Image_Reader);

   overriding
   procedure Initialize (Self : in out Q_Image_Reader);

end Qt4.Image_Readers;
