Rev 179 | Rev 201 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 179 | Rev 180 | ||
---|---|---|---|
Line 401... | Line 401... | ||
401 | drawFocus(painter, opt, displayRect); |
401 | drawFocus(painter, opt, displayRect); |
402 | 402 | ||
403 | // done
|
403 | // done
|
404 | painter->restore(); |
404 | painter->restore(); |
405 | }
|
405 | }
|
- | 406 | ||
- | 407 | ||
- | 408 | ||
- | 409 | ||
- | 410 | ||
- | 411 | ||
- | 412 | IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent) |
|
- | 413 | {
|
|
- | 414 | }
|
|
- | 415 | ||
- | 416 | ||
- | 417 | ||
- | 418 | ||
- | 419 | ||
- | 420 | QWidget *IconDelegate::createEditor(QWidget *parent, |
|
- | 421 | const QStyleOptionViewItem &/* option */, |
|
- | 422 | const QModelIndex & /* index */) const |
|
- | 423 | {
|
|
- | 424 | ||
- | 425 | IconForm *editor = new IconForm(parent); |
|
- | 426 | ||
- | 427 | return editor; |
|
- | 428 | ||
- | 429 | }
|
|
- | 430 | ||
- | 431 | ||
- | 432 | ||
- | 433 | ||
- | 434 | void IconDelegate::setEditorData(QWidget *editor, |
|
- | 435 | const QModelIndex &index) const |
|
- | 436 | {
|
|
- | 437 | ||
- | 438 | ||
- | 439 | const QAbstractItemModel * model = index.model(); |
|
- | 440 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
|
- | 441 | QVariant currentImage = model->data(index,0); |
|
- | 442 | QByteArray bytes = currentImage.toByteArray(); |
|
- | 443 | if (currentImage.isValid()) { |
|
- | 444 | m_pxPicture.loadFromData(bytes); |
|
- | 445 | }
|
|
- | 446 | else { |
|
- | 447 | //QItemDelegate::paint(painter, option, index);
|
|
- | 448 | ||
- | 449 | ||
- | 450 | return; |
|
- | 451 | }
|
|
- | 452 | icnFrm->setPixmap(m_pxPicture); |
|
- | 453 | // tblView->setRowHeight(index.row(), icnFrm->geometry().height());
|
|
- | 454 | }
|
|
- | 455 | ||
- | 456 | ||
- | 457 | ||
- | 458 | ||
- | 459 | void IconDelegate::setModelData( |
|
- | 460 | QWidget *editor,
|
|
- | 461 | QAbstractItemModel *model,
|
|
- | 462 | const QModelIndex& index) const { |
|
- | 463 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
|
- | 464 | if (!(icnFrm->dataIsChanged())) return; |
|
- | 465 | ||
- | 466 | m_pxPicture = icnFrm->pixmap(); |
|
- | 467 | QImage currentImage = m_pxPicture.toImage(); |
|
- | 468 | QByteArray bytes;
|
|
- | 469 | QBuffer buffer(&bytes); |
|
- | 470 | buffer.open(QIODevice::WriteOnly); |
|
- | 471 | currentImage.save(&buffer, "PNG"); |
|
- | 472 | ||
- | 473 | ||
- | 474 | ||
- | 475 | ||
- | 476 | model->setData(index, QVariant (bytes), Qt::EditRole); |
|
- | 477 | ||
- | 478 | // int widht = m_pxPicture.width();
|
|
- | 479 | // int heigh = m_pxPicture.height();
|
|
- | 480 | // tblView->setRowHeight(index.row(), heigh + 10);
|
|
- | 481 | // model->submitAll();
|
|
- | 482 | ||
- | 483 | ||
- | 484 | ||
- | 485 | ||
- | 486 | // model->setData(index, value);
|
|
- | 487 | }
|
|
- | 488 | ||
- | 489 | ||
- | 490 | ||
- | 491 | void IconDelegate::updateEditorGeometry( |
|
- | 492 | QWidget *editor,
|
|
- | 493 | const QStyleOptionViewItem &option, |
|
- | 494 | const QModelIndex& /* index */) const { |
|
- | 495 | ||
- | 496 | ||
- | 497 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
|
- | 498 | // editor->setGeometry(r);
|
|
- | 499 | ||
- | 500 | editor->setGeometry(option.rect); |
|
- | 501 | }
|
|
- | 502 | ||
- | 503 | ||
- | 504 | ||
- | 505 | ||
- | 506 | void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
|
- | 507 | {
|
|
- | 508 | ||
- | 509 | ||
- | 510 | m_pxPicture.fill( QColor(Qt::white) ); |
|
- | 511 | ||
- | 512 | const QAbstractItemModel * model = index.model(); |
|
- | 513 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
|
- | 514 | ||
- | 515 | QVariant currentImage = model->data(index,0); |
|
- | 516 | ||
- | 517 | ||
- | 518 | QByteArray bytes = currentImage.toByteArray(); |
|
- | 519 | // QImage image;
|
|
- | 520 | // image.loadFromData(bytes);
|
|
- | 521 | ||
- | 522 | ||
- | 523 | if (currentImage.isValid()) { |
|
- | 524 | m_pxPicture.loadFromData(bytes); |
|
- | 525 | ||
- | 526 | }
|
|
- | 527 | else { |
|
- | 528 | //QItemDelegate::paint(painter, option, index);
|
|
- | 529 | return; |
|
- | 530 | }
|
|
- | 531 | ||
- | 532 | ||
- | 533 | ||
- | 534 | ||
- | 535 | ||
- | 536 | /*
|
|
- | 537 | ||
- | 538 | if ( !sFileName.isEmpty() )
|
|
- | 539 | m_pxPicture.load( sFileName );
|
|
- | 540 | else {
|
|
- | 541 | //QItemDelegate::paint(painter, option, index);
|
|
- | 542 | return;
|
|
- | 543 | }
|
|
- | 544 | */
|
|
- | 545 | ||
- | 546 | ||
- | 547 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
|
- | 548 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
|
- | 549 | QPalette::Disabled; |
|
- | 550 | ||
- | 551 | if (option.state & QStyle::State_Selected) |
|
- | 552 | ||
- | 553 | ||
- | 554 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
|
- | 555 | ||
- | 556 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
|
- | 557 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
|
- | 558 | painter->drawPixmap( nX, nY, m_pxPicture ); |
|
- | 559 | ||
- | 560 | ||
- | 561 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
|
- | 562 | ||
- | 563 | /*
|
|
- | 564 | QPen pen = painter->pen();
|
|
- | 565 | painter->setPen(option.palette.color(QPalette::Mid));
|
|
- | 566 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
|
- | 567 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
|
- | 568 | painter->setPen(pen);
|
|
- | 569 | */
|
|
- | 570 | }
|
|
- | 571 | ||
- | 572 | ||
- | 573 | void IconDelegate::setTableView(QTableView* table){ |
|
- | 574 | tblView = table; |
|
- | 575 | }
|