------------------------------------------------------------------------------
--                                                                          --
--                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.Image_IO_Handlers;
limited with Qt4.Images;
with Qt4.List_Of_Q_Byte_Arrays;
with Qt4.Strings;
private with Qt_Ada.Internals.Value_Class_Sizes;
with System;

package Qt4.Image_Writers is

   --  QImageWriter::ImageWriterError

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

   type Q_Image_Writer is tagged limited private;

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

   function Can_Write
    (Self : Q_Image_Writer'Class)
       return Boolean;

   function Compression
    (Self : Q_Image_Writer'Class)
       return Qt4.Q_Integer;

   function Error
    (Self : Q_Image_Writer'Class)
       return Image_Writer_Error;

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

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

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

   function Gamma
    (Self : Q_Image_Writer'Class)
       return Qt4.Q_Float;

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

   procedure Set_Compression
    (Self : in out Q_Image_Writer'Class;
     Compression : Qt4.Q_Integer);

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

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

   procedure Set_Gamma
    (Self : in out Q_Image_Writer'Class;
     Gamma : Qt4.Q_Float);

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

   procedure Set_Text
    (Self : in out Q_Image_Writer'Class;
     Key : Qt4.Strings.Q_String'Class;
     Text : Qt4.Strings.Q_String'Class);

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

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

   function Supported_Image_Formats
     return Qt4.List_Of_Q_Byte_Arrays.Q_List_Of_Q_Byte_Array;

   package Internals is

      type QImageWriter is private;

      type QImageWriter_Access is access all QImageWriter;
      pragma Convention (C, QImageWriter_Access);

      function QImageWriter_View
       (Item : Q_Image_Writer'Class)
          return QImageWriter_Access;
      pragma Inline (QImageWriter_View);

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

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

      function Create_Wrapper
       (Item : Internals.QImageWriter_Access)
          return Q_Image_Writer;

   private

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

   end Internals;

private

   type Q_Image_Writer is new Ada.Finalization.Limited_Controlled with record
      Storage : aliased Internals.QImageWriter;
      Object  : Internals.QImageWriter_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Finalize (Self : in out Q_Image_Writer);

   overriding
   procedure Initialize (Self : in out Q_Image_Writer);

end Qt4.Image_Writers;
