------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 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.Grid_Layouts.Constructors;
with Qt4.Labels.Constructors;
with Qt4.Line_Edits.Constructors;
with Qt4.Objects;
with Qt4.Push_Buttons.Constructors;
with Qt4.Strings;

with Echo_Windows.Moc;
pragma Unreferenced (Echo_Windows.Moc);

package body Echo_Windows is

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

   function Create (Echo : Echo_Interfaces.Echo_Interface_Access)
     return not null Echo_Window_Access
   is
      use type Qt4.Alignment_Flag;
      use type Echo_Interfaces.Echo_Interface_Access;

   begin
      return Self : constant not null Echo_Window_Access := new Echo_Window do
         declare
            Button : Qt4.Push_Buttons.Q_Push_Button_Access;
            Layout : Qt4.Grid_Layouts.Q_Grid_Layout_Access;

         begin
            Qt4.Widgets.Directors.Constructors.Initialize (Self);

            Self.Echo := Echo;

--    lineEdit = new QLineEdit;
            Self.Line_Edit := Qt4.Line_Edits.Constructors.Create;
--     label = new QLabel;
            Self.Label := Qt4.Labels.Constructors.Create;
--     label->setFrameStyle(QFrame::Box | QFrame::Plain);
--     button = new QPushButton(tr("Send Message"));
            Button :=
              Qt4.Push_Buttons.Constructors.Create
               (Qt4.Strings.From_Utf_16 ("Send Message"));
--
--  +  connect(lineEdit, SIGNAL(editingFinished()),
--             this, SLOT(sendEcho()));
            Qt4.Objects.Connect
             (Self.Line_Edit, Qt4.Signal ("editingFinished()"),
              Self, Qt4.Slot ("sendEcho()"));
--  +  connect(button, SIGNAL(clicked()),
--             this, SLOT(sendEcho()));
            Qt4.Objects.Connect
             (Button, Qt4.Signal ("clicked()"),
              Self, Qt4.Slot ("sendEcho()"));
--
--  +  layout = new QGridLayout;
            Layout := Qt4.Grid_Layouts.Constructors.Create;
--  +  layout->addWidget(new QLabel(tr("Message:")), 0, 0);
            Layout.Add_Widget
             (Qt4.Labels.Constructors.Create
               (Qt4.Strings.From_Utf_16 ("Message:")),
              0,
              0);
--     layout->addWidget(lineEdit, 0, 1);
            Layout.Add_Widget (Self.Line_Edit, 0, 1);
--     layout->addWidget(new QLabel(tr("Answer:")), 1, 0);
            Layout.Add_Widget
             (Qt4.Labels.Constructors.Create
               (Qt4.Strings.From_Utf_16 ("Answer:")),
              1,
              0);
--     layout->addWidget(label, 1, 1);
            Layout.Add_Widget (Self.Label, 1, 1);
--     layout->addWidget(button, 2, 1, Qt::AlignRight);
            Layout.Add_Widget (Button, 2, 1, +Qt4.Align_Right);
--     layout->setSizeConstraint(QLayout::SetFixedSize);

            Self.Set_Layout (Layout);
            Self.Set_Window_Title
             (Qt4.Strings.From_Utf_16 ("Echo Plugin Example"));

            if Self.Echo = null then
               Self.Line_Edit.Set_Enabled (False);
               Button.Set_Enabled (False);
            end if;
         end;
      end return;
   end Create;

   ---------------
   -- Send_Echo --
   ---------------

   procedure Send_Echo (Self : not null access Echo_Window'Class) is
   begin
      Self.Label.Set_Text (Self.Echo.Echo (Self.Line_Edit.Text));
   end Send_Echo;

end Echo_Windows;
