/* -*- 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();
  comboBox->setCurrentIndex(value);
}
 
void 
EndorseComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
  QComboBox *comboBox = static_cast<QComboBox*>(editor);
  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
