Subversion Repositories OpenInventory

Compare Revisions

Ignore whitespace Rev 164 → Rev 165

/trunk/ClassEditor/delegate.cpp
277,16 → 277,102
{
}
 
 
 
 
 
QWidget *CPictureDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/* option */,
const QModelIndex &/* index */) const
{
 
IconForm *editor = new IconForm(parent);
return editor;
 
}
 
 
 
 
void CPictureDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
 
 
const QAbstractItemModel * model = index.model();
IconForm *icnFrm = static_cast<IconForm*>(editor);
QVariant currentImage = model->data(index,0);
QByteArray bytes = currentImage.toByteArray();
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
}
else {
//QItemDelegate::paint(painter, option, index);
return;
}
icnFrm->setPixmap(m_pxPicture);
}
 
 
 
 
void CPictureDelegate::setModelData(
QWidget *editor,
QAbstractItemModel *model,
const QModelIndex& index) const {
IconForm *icnFrm = static_cast<IconForm*>(editor);
m_pxPicture = icnFrm->pixmap();
QImage currentImage = m_pxPicture.toImage();
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
currentImage.save(&buffer, "PNG");
 
 
 
 
model->setData(index, QVariant (bytes), Qt::EditRole);
 
// int widht = m_pxPicture.width();
// int heigh = m_pxPicture.height();
// tblView->setRowHeight(index.row(), heigh + 10);
// model->submitAll();
 
 
 
 
// model->setData(index, value);
}
 
 
 
void CPictureDelegate::updateEditorGeometry(
QWidget *editor,
const QStyleOptionViewItem &option,
const QModelIndex& /* index */) const {
 
 
// QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
// editor->setGeometry(r);
 
editor->setGeometry(option.rect);
}
 
 
 
 
void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
m_pxPicture.fill( QColor(Qt::white) );
 
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
 
QVariant currentImage = model->data(index,0);
m_pxPicture.fill( QColor(Qt::white) );
 
const QAbstractItemModel * model = index.model();
QString sFileName = model->data( index, Qt::DisplayRole ).toString();
 
QVariant currentImage = model->data(index,0);
 
 
QByteArray bytes = currentImage.toByteArray();
// QImage image;
// image.loadFromData(bytes);
294,6 → 380,7
 
if (currentImage.isValid()) {
m_pxPicture.loadFromData(bytes);
 
}
else {
//QItemDelegate::paint(painter, option, index);
301,6 → 388,9
}
 
 
 
 
 
/*
 
if ( !sFileName.isEmpty() )
317,14 → 407,16
QPalette::Disabled;
 
if (option.state & QStyle::State_Selected)
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
 
 
painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
 
int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
painter->drawPixmap( nX, nY, m_pxPicture );
 
 
//// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
 
/*
QPen pen = painter->pen();
333,6 → 425,9
painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
painter->setPen(pen);
*/
}
}
 
 
void CPictureDelegate::setTableView(QTableView* table){
tblView = table;
}