/**********************************************************************
 *     EPSCAN, an EPSON ES-1200 scanner driver     
 *     Adam P. Jenkins <ajenkins@cs.umass.edu>
 *     
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License
 *     as published by the Free Software Foundation; either version 2
 *     of the License, or (at your option) any later version.
 *     
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT 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
 *     along with this program; if not, write to the Free Software
 *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 **********************************************************************/

#include <qpushbt.h>
#include <qmlined.h>
#include <qfile.h>
#include <qlayout.h>
#include <qtextstream.h>

#include "HelpWindow.h"


HelpWindow::HelpWindow(const char *helpfile, QWidget *parent, 
                       const char *name) : QWidget(parent, name)
{
  setCaption("Epscan Help");
  setIconText("Epscan Help");
  
  QBoxLayout *helpLayout = new QBoxLayout(this, QBoxLayout::TopToBottom,
                                          10);
  CHECK_PTR( helpLayout );
  
  helpText = new QMultiLineEdit(this);
  CHECK_PTR( helpText );
  helpText->setMinimumSize(200, 400);
  helpText->setReadOnly(true);
  
  setHelpFile(helpfile);

  helpLayout->addWidget(helpText, 10);

  QPushButton *dismiss = new QPushButton("Dismiss", this);
  CHECK_PTR(dismiss);
  dismiss->setFixedSize(dismiss->size());
  connect(dismiss, SIGNAL(clicked()), SLOT(hideHelp()));
  
  helpLayout->addWidget(dismiss);

  helpLayout->activate();
}

bool
HelpWindow::setHelpFile(const char *helpfile)
{
  QFile helpFiled(helpfile);
  if (!helpFiled.open(IO_ReadOnly)) {
    warning("Failed to open help file");
    return false;
  }
  QTextStream helpFile(&helpFiled);
  
  _helpFileName = helpfile;

  QString line;
  while (!helpFile.eof()) {
    line = helpFile.readLine();
    helpText->insertLine(line);
  }

  helpText->setCursorPosition(0, 0);
  return true;
}

