/***************************************************************************
                          kzerofilldialog.cpp  -  description
                             -------------------
    begin                : Tue Oct 28 2003
    copyright            : (C) 2003 by Armando Navarro-Vazquez
    email                : qoajnv@usc.es
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/


#include <cstdlib>
#include <kmessagebox.h>
#include <klocale.h>

#include <qcombobox.h>
#include <qlayout.h>
#include <qlabel.h>
#include <q3whatsthis.h>
//Added by qt3to4:
#include <Q3GridLayout>
 
#include "kzerofilldialog.h"


KZeroFillDialog::KZeroFillDialog(int npoints, QWidget* parent) :  KDialog(parent)
{

  m_currentpoints=npoints;
  QString scurrent;
  scurrent.sprintf("Current: %d complex points",m_currentpoints);

  Q3GridLayout* v= new Q3GridLayout(this,2,2,spacingHint(),spacingHint());

  m_label= new QLabel(scurrent,this);

  m_npointscombo= new QComboBox(this,"zerofillcombo");
  QLabel* labelcombo=new QLabel(this,"Fill to");
  v->addWidget(m_label,0,0);
  v->addWidget(labelcombo,1,0);
  v->addWidget(m_npointscombo,1,1);

  //Ok, add powers of two to combobox

  int start=512;
  QStringList plist;
  for(int i=0;i<9;i++)
  {
    QString str;
    plist << str.setNum(start);
    start <<=1;
  }

  int j=2;

  do
  {
    j <<=1;
  } while( j<= m_currentpoints);

  m_npointscombo->insertStringList(plist);

  m_npointscombo->setCurrentText(scurrent.setNum(j));

  Q3WhatsThis::add(m_npointscombo,"Enter here the number of complex points to fill the fid up");
  Q3WhatsThis::add(this,"Choose the desired number (a power of two) of complex points in the"
  "combo box or enter your own number");
}
KZeroFillDialog::~KZeroFillDialog(){
}

void KZeroFillDialog::slotOk()
{
  if(ChangePoints())
  {
    emit npoints(m_currentpoints);
    accept();
  }
}

void KZeroFillDialog::slotApply()
{
  if(ChangePoints())
    emit npoints(m_currentpoints);
}

bool KZeroFillDialog::ChangePoints()
{
  int n =m_npointscombo->currentText().toInt();

  if (n>=1)
  {
      m_currentpoints=n;
      return true;
  }
  else
  {
    KMessageBox::sorry(this,"Enter a valid number for zero filling");
    return false;
  }
}
