/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include <map>
#include <iostream>
#include <qcolordialog.h>
#include "ColorItem.h"
void CellTypeColorDialog::init(){  
}

void CellTypeColorDialog::loadCurrentValues(std::map<ushort,QColor> typeColorMap){
        using namespace std;
         
        typeColorTable->setNumCols(2);
        typeColorTable->setNumRows(typeColorMap.size());
        
//         static QPixmap pixmap;

/*        if(typeColorTable->numRows()>0){
            pixmap.resize(typeColorTable->columnWidth(1), typeColorTable->rowHeight(0));
        }*/
	for(
	     map<unsigned short,QColor>::iterator mitr=typeColorMap.begin()  ; 
	     mitr != typeColorMap.end() ;
	     ++mitr
                     ){
       cerr<<"mitr->first = "<<mitr->first<<endl;
		 typeColorTable->setText(mitr->first,0,QString(QString().setNum(mitr->first) ) );
//        pixmap.fill(mitr->second);
       QTableItem *item = new ColorItem(typeColorTable, mitr->first, 1,mitr->second);
//        new QTableItem(typeColorTable, QTableItem::Never);

//        item->setPixmap(pixmap);
       typeColorTable->setItem( mitr->first, 1, item);
       QColor cc = ((ColorItem*)typeColorTable->item(mitr->first, 1))->color();
       cerr<<"CHECK color row: "<<mitr->first<<" color: "<<cc.name()<<" color check: "<<mitr->second.name()<<endl;
       //typeColorTable->setPixmap( mitr->first, 1, pixmap );
       
		 
	     }
	
       	
}


void CellTypeColorDialog::getContourColor()
{
 QColor color=QColorDialog::getColor();
    contourColorLabel->setPaletteBackgroundColor(color);

}


void CellTypeColorDialog::getBorderColor()
{
   QColor color=QColorDialog::getColor();
    borderColorLabel->setPaletteBackgroundColor(color);
}


void CellTypeColorDialog::getCellColor(int row, int col, int button, const QPoint & mousePos )
{
//   static QPixmap pixmap;
  if(col==0)
    return;//only color cell can be changed

  
  QColor color=QColorDialog::getColor();
  


/*  pixmap.resize(typeColorTable->columnWidth(col),
		typeColorTable->rowHeight(row)
);
   pixmap.fill(color);*/
  
  QTableItem *item = new ColorItem(typeColorTable,row, col,color);
//   item->setPixmap(pixmap);

  typeColorTable->setItem(row,col,item);

  
  
}


void CellTypeColorDialog::newCellType()
{
  typeColorTable->insertRows(typeColorTable->numRows());
  int col,row;
  row=typeColorTable->numRows()-1;
  col=1;
  QColor color(black);
  QTableItem *item = new ColorItem(typeColorTable,row, col,color);
  typeColorTable->setItem(row,col,item);
}
