/***************************************************************************
                          BinWordsEditor.cpp  -  description
                             -------------------
    begin                : jeu jun 26 2003
    copyright            : (C) 2003 by Alain Gibaud
    email                : alain.gibaud@univ-valenciennes.fr
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "BinWordsEditor.h"
#include "BinWordEditor.h"

#include <qcombobox.h>
#include <qstring.h>
#include <qtooltip.h>
#include <klocale.h>

#include <iostream>
using namespace std ;

BinWordsEditor::BinWordsEditor(FragBuffer& me, unsigned int index1 , unsigned int index2,
	const QString& desc,
	const QString& title,bool byteAddr, QWidget *parent) : QVGroupBox(title,parent)
{
  QString lab ;
  QComboBox *chooser = new QComboBox(this) ;
  addSpace(5) ;
  stack = new   QWidgetStack(this) ;
  BinWordEditor *we = 0 ;

  connect(chooser, SIGNAL(activated(int)), this, SLOT(slotRaiseBWE(int))) ;
  QToolTip::add(chooser, byteAddr ? i18n("Bytes adresses") : i18n("Words adresses")) ;

    
  for(unsigned int i= index1, k = 0  ; i <= index2 ; ++i, ++k )
  {
    lab.sprintf("%6X", byteAddr ? 2*i : i) ;
    chooser->insertItem(lab) ;
    QString s =  desc.section(";",k,k) ;
    if(s.isNull()) s = "" ;

    we = new BinWordEditor(me,i,s , byteAddr, this) ;
    stack->addWidget(we) ;
    weditors.push_back(we) ;
    connect(this, SIGNAL(wordsChanged()), we, SLOT(updateDisplay())) ;
  }
  slotRaiseBWE(0) ;
    
}
BinWordsEditor::~BinWordsEditor(){
}
/** raise a word editor widget */
void BinWordsEditor::slotRaiseBWE(int numwidget)
{
  weditors[numwidget]->updateDisplay() ;
  stack->raiseWidget(weditors[numwidget]) ;
}
