------------------------------------------------------------------------------
--                                                                          --
--                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: 3731 $ $Date: 2010-04-30 13:21:13 +0400 (Fri, 30 Apr 2010) $
------------------------------------------------------------------------------
pragma Style_Checks ("M32766");
with System.Address_To_Access_Conversions;

with Qt4.Images;

package body Qt4.Image_Writers is

   function initialize_QImageWriter
    (Storage : System.Address)
      return Internals.QImageWriter_Access;
   pragma Import (C, initialize_QImageWriter, "__QtAda_inititialize_QImageWriter");

   function initialize_QImageWriter_QStringCR_QByteArrayCR
    (Storage : System.Address;
     File_Name : Qt4.Strings.Internals.QString_Access;
     Format : Qt4.Byte_Arrays.Internals.QByteArray_Access)
      return Internals.QImageWriter_Access;
   pragma Import (C, initialize_QImageWriter_QStringCR_QByteArrayCR, "__QtAda_inititialize_QImageWriter_QStringCR_QByteArrayCR");

   procedure finalize_QImageWriter (Object : Internals.QImageWriter_Access);
   pragma Import (C, finalize_QImageWriter, "__QtAda_finalize_QImageWriter");

   function QImageWriter_canWrite
    (Self : Internals.QImageWriter_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImageWriter_canWrite, "__QtAda_QImageWriter_canWrite_Q");

   function QImageWriter_compression
    (Self : Internals.QImageWriter_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImageWriter_compression, "__QtAda_QImageWriter_compression_Q");

   function QImageWriter_error
    (Self : Internals.QImageWriter_Access)
       return Image_Writer_Error;
   pragma Import (C, QImageWriter_error, "__QtAda_QImageWriter_error_Q");

   procedure QImageWriter_errorString
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QImageWriter_Access);
   pragma Import (C, QImageWriter_errorString, "__QtAda_QImageWriter_errorString_Q");

   procedure QImageWriter_fileName
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QImageWriter_Access);
   pragma Import (C, QImageWriter_fileName, "__QtAda_QImageWriter_fileName_Q");

   procedure QImageWriter_format
    (Returns : Qt4.Byte_Arrays.Internals.QByteArray_Access;
     Self : Internals.QImageWriter_Access);
   pragma Import (C, QImageWriter_format, "__QtAda_QImageWriter_format_Q");

   function QImageWriter_gamma
    (Self : Internals.QImageWriter_Access)
       return Qt4.Q_Float;
   pragma Import (C, QImageWriter_gamma, "__QtAda_QImageWriter_gamma_Q");

   function QImageWriter_quality
    (Self : Internals.QImageWriter_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QImageWriter_quality, "__QtAda_QImageWriter_quality_Q");

   procedure QImageWriter_setCompression_int
    (Self : Internals.QImageWriter_Access;
     Compression : Qt4.Q_Integer);
   pragma Import (C, QImageWriter_setCompression_int, "__QtAda_QImageWriter_setCompression_int");

   procedure QImageWriter_setFileName_QStringCR
    (Self : Internals.QImageWriter_Access;
     File_Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QImageWriter_setFileName_QStringCR, "__QtAda_QImageWriter_setFileName_QStringCR");

   procedure QImageWriter_setFormat_QByteArrayCR
    (Self : Internals.QImageWriter_Access;
     Format : Qt4.Byte_Arrays.Internals.QByteArray_Access);
   pragma Import (C, QImageWriter_setFormat_QByteArrayCR, "__QtAda_QImageWriter_setFormat_QByteArrayCR");

   procedure QImageWriter_setGamma_float
    (Self : Internals.QImageWriter_Access;
     Gamma : Qt4.Q_Float);
   pragma Import (C, QImageWriter_setGamma_float, "__QtAda_QImageWriter_setGamma_float");

   procedure QImageWriter_setQuality_int
    (Self : Internals.QImageWriter_Access;
     Quality : Qt4.Q_Integer);
   pragma Import (C, QImageWriter_setQuality_int, "__QtAda_QImageWriter_setQuality_int");

   procedure QImageWriter_setText_QStringCR_QStringCR
    (Self : Internals.QImageWriter_Access;
     Key : Qt4.Strings.Internals.QString_Access;
     Text : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QImageWriter_setText_QStringCR_QStringCR, "__QtAda_QImageWriter_setText_QStringCR_QStringCR");

   function QImageWriter_supportsOption_ImageOption
    (Self : Internals.QImageWriter_Access;
     Option : Qt4.Image_IO_Handlers.Image_Option)
       return Interfaces.C.unsigned;
   pragma Import (C, QImageWriter_supportsOption_ImageOption, "__QtAda_QImageWriter_supportsOption_ImageOption_Q");

   function QImageWriter_write_QImageCR
    (Self : Internals.QImageWriter_Access;
     Image : Qt4.Images.Internals.QImage_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QImageWriter_write_QImageCR, "__QtAda_QImageWriter_write_QImageCR");

   procedure QImageWriter_supportedImageFormats
    (Returns : Qt4.List_Of_Q_Byte_Arrays.Internals.QListOfQByteArray_Access);
   pragma Import (C, QImageWriter_supportedImageFormats, "__QtAda_QImageWriter_supportedImageFormats_S");

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_Image_Writer) is
   begin
      if not Self.Wrapper then
         finalize_QImageWriter (Self.Object);
      end if;
   end Finalize;

   ----------------
   -- Initialize --
   ----------------

   overriding
   procedure Initialize (Self : in out Q_Image_Writer) is
      use type Internals.QImageWriter_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QImageWriter (Self.Storage'Address);
      end if;
   end Initialize;

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

   function Create
    (File_Name : Qt4.Strings.Q_String'Class;
     Format : Qt4.Byte_Arrays.Q_Byte_Array'Class)
       return Q_Image_Writer
   is
   begin
      return Self : Q_Image_Writer
        := (Ada.Finalization.Limited_Controlled with others => <>)
      do
         Self.Object := initialize_QImageWriter_QStringCR_QByteArrayCR (Self.Storage'Address, Qt4.Strings.Internals.QString_View (File_Name), Qt4.Byte_Arrays.Internals.QByteArray_View (Format));
      end return;
   end Create;

   ---------------
   -- Can_Write --
   ---------------

   function Can_Write
    (Self : Q_Image_Writer'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImageWriter_canWrite (Self.Object), 0);
   end Can_Write;

   -----------------
   -- Compression --
   -----------------

   function Compression
    (Self : Q_Image_Writer'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImageWriter_compression (Self.Object);
   end Compression;

   -----------
   -- Error --
   -----------

   function Error
    (Self : Q_Image_Writer'Class)
       return Image_Writer_Error
   is
   begin
      return QImageWriter_error (Self.Object);
   end Error;

   ------------------
   -- Error_String --
   ------------------

   function Error_String
    (Self : Q_Image_Writer'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QImageWriter_errorString (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end Error_String;

   ---------------
   -- File_Name --
   ---------------

   function File_Name
    (Self : Q_Image_Writer'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QImageWriter_fileName (Qt4.Strings.Internals.QString_View (Returns), Self.Object);
      end return;
   end File_Name;

   ------------
   -- Format --
   ------------

   function Format
    (Self : Q_Image_Writer'Class)
       return Qt4.Byte_Arrays.Q_Byte_Array
   is
   begin
      return Returns : Qt4.Byte_Arrays.Q_Byte_Array do
         QImageWriter_format (Qt4.Byte_Arrays.Internals.QByteArray_View (Returns), Self.Object);
      end return;
   end Format;

   -----------
   -- Gamma --
   -----------

   function Gamma
    (Self : Q_Image_Writer'Class)
       return Qt4.Q_Float
   is
   begin
      return QImageWriter_gamma (Self.Object);
   end Gamma;

   -------------
   -- Quality --
   -------------

   function Quality
    (Self : Q_Image_Writer'Class)
       return Qt4.Q_Integer
   is
   begin
      return QImageWriter_quality (Self.Object);
   end Quality;

   ---------------------
   -- Set_Compression --
   ---------------------

   procedure Set_Compression
    (Self : in out Q_Image_Writer'Class;
     Compression : Qt4.Q_Integer)
   is
   begin
      QImageWriter_setCompression_int (Self.Object, Compression);
   end Set_Compression;

   -------------------
   -- Set_File_Name --
   -------------------

   procedure Set_File_Name
    (Self : in out Q_Image_Writer'Class;
     File_Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QImageWriter_setFileName_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (File_Name));
   end Set_File_Name;

   ----------------
   -- Set_Format --
   ----------------

   procedure Set_Format
    (Self : in out Q_Image_Writer'Class;
     Format : Qt4.Byte_Arrays.Q_Byte_Array'Class)
   is
   begin
      QImageWriter_setFormat_QByteArrayCR (Self.Object, Qt4.Byte_Arrays.Internals.QByteArray_View (Format));
   end Set_Format;

   ---------------
   -- Set_Gamma --
   ---------------

   procedure Set_Gamma
    (Self : in out Q_Image_Writer'Class;
     Gamma : Qt4.Q_Float)
   is
   begin
      QImageWriter_setGamma_float (Self.Object, Gamma);
   end Set_Gamma;

   -----------------
   -- Set_Quality --
   -----------------

   procedure Set_Quality
    (Self : in out Q_Image_Writer'Class;
     Quality : Qt4.Q_Integer)
   is
   begin
      QImageWriter_setQuality_int (Self.Object, Quality);
   end Set_Quality;

   --------------
   -- Set_Text --
   --------------

   procedure Set_Text
    (Self : in out Q_Image_Writer'Class;
     Key : Qt4.Strings.Q_String'Class;
     Text : Qt4.Strings.Q_String'Class)
   is
   begin
      QImageWriter_setText_QStringCR_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Key), Qt4.Strings.Internals.QString_View (Text));
   end Set_Text;

   ---------------------
   -- Supports_Option --
   ---------------------

   function Supports_Option
    (Self : Q_Image_Writer'Class;
     Option : Qt4.Image_IO_Handlers.Image_Option)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImageWriter_supportsOption_ImageOption (Self.Object, Option), 0);
   end Supports_Option;

   -----------
   -- Write --
   -----------

   function Write
    (Self : not null access Q_Image_Writer'Class;
     Image : Qt4.Images.Q_Image'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QImageWriter_write_QImageCR (Self.Object, Qt4.Images.Internals.QImage_View (Image)), 0);
   end Write;

   -----------------------------
   -- Supported_Image_Formats --
   -----------------------------

   function Supported_Image_Formats
     return Qt4.List_Of_Q_Byte_Arrays.Q_List_Of_Q_Byte_Array
   is
   begin
      return Returns : Qt4.List_Of_Q_Byte_Arrays.Q_List_Of_Q_Byte_Array do
         QImageWriter_supportedImageFormats (Qt4.List_Of_Q_Byte_Arrays.Internals.QListOfQByteArray_View (Returns));
      end return;
   end Supported_Image_Formats;

   ---------------
   -- Internals --
   ---------------

   package body Internals is

   -----------------------
   -- QImageWriter_View --
   -----------------------

      function QImageWriter_View
       (Item : Q_Image_Writer'Class)
          return QImageWriter_Access
      is
      begin
         return Item.Object;
      end QImageWriter_View;

      package QImageWriter_Conversions is
        new System.Address_To_Access_Conversions
             (QImageWriter);

   ----------------------------
   -- QImageWriterTo_Pointer --
   ----------------------------

      function To_Pointer
       (Address : System.Address)
          return QImageWriter_Access
      is
      begin
         return
           QImageWriter_Access
            (QImageWriter_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   ----------------------------
   -- QImageWriterTo_Address --
   ----------------------------

      function To_Address
       (Pointer : QImageWriter_Access)
          return System.Address
      is
      begin
         return
           QImageWriter_Conversions.To_Address
            (QImageWriter_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : Internals.QImageWriter_Access)
          return Q_Image_Writer
      is
      begin
         return Q_Image_Writer'
          (Ada.Finalization.Limited_Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Image_Writers;
