/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2013, Regents of the University of California
 *                     Yingdi Yu
 *
 * BSD license, See the LICENSE file for more information
 *
 * Author: Yingdi Yu <yingdi@cs.ucla.edu>
 */

#include "endorse-combobox-delegate.h"

#include <QComboBox>
#include <QApplication>

#ifndef Q_MOC_RUN
#include "logging.h"
#include "exception.h"
#endif

INIT_LOGGER("EndorseComboBoxDelegate");

EndorseComboBoxDelegate::EndorseComboBoxDelegate(QObject *parent)
 : QItemDelegate(parent)
{
  m_items.push_back("Not Endorsed");
  m_items.push_back("Endorsed");
}
 
 
QWidget*
EndorseComboBoxDelegate::createEditor(QWidget *parent, 
			       const QStyleOptionViewItem &/* option */, 
			       const QModelIndex &/* index */) const
{
  QComboBox* editor = new QComboBox(parent);
  for(unsigned int i = 0; i < m_items.size(); ++i)
      editor->addItem(m_items[i].c_str());
  return editor;
}
 
void 
EndorseComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
  QComboBox *comboBox = static_cast<QComboBox*>(editor);
  int value = index.model()->data(index, Qt::EditRole).toUInt();
  _LOG_DEBUG("value: " << value);
  comboBox->setCurrentIndex(value);
}
 
void 
EndorseComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
  QComboBox *comboBox = static_cast<QComboBox*>(editor);
  _LOG_DEBUG("currentIndex: " << comboBox->currentIndex());
  model->setData(index, comboBox->currentIndex(), Qt::EditRole);
}
 
void 
EndorseComboBoxDelegate::updateEditorGeometry(QWidget *editor, 
				       const QStyleOptionViewItem &option, 
				       const QModelIndex &/* index */) const
{
  editor->setGeometry(option.rect);
}
 
void 
EndorseComboBoxDelegate::paint(QPainter *painter, 
			       const QStyleOptionViewItem &option, 
			       const QModelIndex &index) const
{
  QStyleOptionViewItemV4 myOption = option;
  QString text = m_items[index.model()->data(index, Qt::EditRole).toUInt()].c_str();
 
  myOption.text = text;
 
  QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &myOption, painter);
}

#if WAF
#include "endorse-combobox-delegate.moc"
#include "endorse-combobox-delegate.cpp.moc"
#endif
