diff --git a/src/ExtendedTableWidget.cpp b/src/ExtendedTableWidget.cpp index 62933983..ded544d0 100644 --- a/src/ExtendedTableWidget.cpp +++ b/src/ExtendedTableWidget.cpp @@ -10,6 +10,7 @@ #include #include #include +#include ExtendedTableWidget::ExtendedTableWidget(QWidget* parent) : QTableView(parent) @@ -35,6 +36,17 @@ void ExtendedTableWidget::copy() return; qSort(indices); + SqliteTableModel* m = qobject_cast(model()); + + // If single image cell selected - copy it to clipboard + if (indices.size() == 1) { + QImage img; + if (img.loadFromData(m->data(indices.first(), Qt::EditRole).toByteArray())) { + qApp->clipboard()->setImage(img); + return; + } + } + // Check whether selection is rectangular QItemSelection rect(indices.first(), indices.last()); bool correct = true; @@ -61,7 +73,6 @@ void ExtendedTableWidget::copy() // If any of the cells contain binary data - we use inner buffer bool containsBinary = false; - SqliteTableModel* m = qobject_cast(model()); foreach (const QModelIndex& index, indices) if (m->isBinary(index)) { containsBinary = true; @@ -119,6 +130,19 @@ void ExtendedTableWidget::paste() SqliteTableModel* m = qobject_cast(model()); + // If clipboard contains image - just insert it + QImage img = qApp->clipboard()->image(); + if (!img.isNull()) { + QByteArray ba; + QBuffer buffer(&ba); + buffer.open(QIODevice::WriteOnly); + img.save(&buffer, "PNG"); + buffer.close(); + + m->setData(indices.first(), ba); + return; + } + if (qApp->clipboard()->text().isEmpty() && !m_buffer.isEmpty()) { // If buffer contains something - use it instead of clipboard int rows = m_buffer.size();