From e8e8aba757dc9f8e44c1f1fa90acd9ecc56e0371 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 26 Feb 2014 16:38:33 +0100 Subject: [PATCH] support for copying an image to the clipboard --- src/mtsgui/mainwindow.cpp | 24 +++++++++++++++++++----- src/mtsgui/mainwindow.h | 1 + src/mtsgui/mainwindow.ui | 9 +++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/mtsgui/mainwindow.cpp b/src/mtsgui/mainwindow.cpp index 78ffb6a5..cdbc28b4 100644 --- a/src/mtsgui/mainwindow.cpp +++ b/src/mtsgui/mainwindow.cpp @@ -825,6 +825,7 @@ void MainWindow::updateUI() { ui->actionClose->setEnabled(hasTab); ui->actionDuplicateTab->setEnabled(hasTab); ui->actionAdjustSize->setEnabled(hasTab); + ui->actionCopyImage->setEnabled(hasTab); ui->actionShowKDTree->setEnabled(hasScene); ui->actionShowKDTree->setChecked(hasScene && context->showKDTree); ui->actionSceneDescription->setEnabled(hasScene); @@ -888,6 +889,7 @@ void MainWindow::on_tabBar_customContextMenuRequested(const QPoint &pt) { menu.addAction(ui->actionDuplicateTab); if (tabIndex == ui->tabBar->currentIndex()) menu.addAction(ui->actionAdjustSize); + menu.addAction(ui->actionCopyImage); menu.addAction(ui->actionClose); menu.exec(ui->tabBar->mapToGlobal(pt)); m_contextIndex = -1; @@ -1482,6 +1484,10 @@ inline float toSRGB(float value) { return 1.055f * std::pow(value, 0.41666f) - 0.055f; } +void MainWindow::on_actionCopyImage_triggered() { + exportImage("__clipboard__"); +} + #if MTSGUI_STATIC_QFILEDIALOG void MainWindow::on_actionExportImage_triggered() { @@ -1552,7 +1558,7 @@ void MainWindow::exportImage(const QString &fileName) { bool isHDR = true; if (fileName.endsWith(".exr")) { format = Bitmap::EOpenEXR; - } else if (fileName.endsWith(".png")) { + } else if (fileName.endsWith(".png") || fileName == "__clipboard__") { format = Bitmap::EPNG; isHDR = false; } else if (fileName.endsWith(".hdr") || fileName.endsWith(".rgbe")) { @@ -1568,9 +1574,6 @@ void MainWindow::exportImage(const QString &fileName) { return; } - ref fs = new FileStream(toFsPath(fileName), - FileStream::ETruncReadWrite); - const int currentIndex = ui->tabBar->currentIndex(); const SceneContext *ctx = m_context[currentIndex]; @@ -1595,7 +1598,18 @@ void MainWindow::exportImage(const QString &fileName) { ? (Float) 1.0f : std::pow((Float) 2, ctx->exposure)); } - bitmap->write(format, fs); + if (fileName == "__clipboard__") { + QImage image(bitmap->getWidth(), bitmap->getHeight(), QImage::Format_RGB888); + size_t scanlineSize = (size_t) bitmap->getWidth() * 3 * sizeof(uint8_t); + for (int i=0; igetHeight(); ++i) + memcpy(image.scanLine(i), bitmap->getUInt8Data() + scanlineSize * i, scanlineSize); + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setPixmap(QPixmap::fromImage(image)); + } else { + ref fs = new FileStream(toFsPath(fileName), + FileStream::ETruncReadWrite); + bitmap->write(format, fs); + } } } diff --git a/src/mtsgui/mainwindow.h b/src/mtsgui/mainwindow.h index 8b57b5fd..0d0f9e4e 100644 --- a/src/mtsgui/mainwindow.h +++ b/src/mtsgui/mainwindow.h @@ -172,6 +172,7 @@ private slots: void on_actionFocusAll_triggered(); void on_actionSceneDescription_triggered(); void on_actionEnableCommandLine_triggered(); + void on_actionCopyImage_triggered(); void on_tabBar_currentChanged(int index); bool on_tabBar_tabCloseRequested(int index); void on_tabBar_tabMoved(int from, int to); diff --git a/src/mtsgui/mainwindow.ui b/src/mtsgui/mainwindow.ui index e22019d0..f7c6b9dc 100644 --- a/src/mtsgui/mainwindow.ui +++ b/src/mtsgui/mainwindow.ui @@ -128,6 +128,7 @@ + @@ -475,6 +476,14 @@ Ctrl+F + + + &Copy image + + + Ctrl+C + + Report &Feedback