support for copying an image to the clipboard

metadata
Wenzel Jakob 2014-02-26 16:38:33 +01:00
parent e41de8d5fb
commit e8e8aba757
3 changed files with 29 additions and 5 deletions

View File

@ -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<FileStream> fs = new FileStream(toFsPath(fileName),
FileStream::ETruncReadWrite);
const int currentIndex = ui->tabBar->currentIndex();
const SceneContext *ctx = m_context[currentIndex];
@ -1595,8 +1598,19 @@ void MainWindow::exportImage(const QString &fileName) {
? (Float) 1.0f : std::pow((Float) 2, ctx->exposure));
}
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; i<bitmap->getHeight(); ++i)
memcpy(image.scanLine(i), bitmap->getUInt8Data() + scanlineSize * i, scanlineSize);
QClipboard *clipboard = QApplication::clipboard();
clipboard->setPixmap(QPixmap::fromImage(image));
} else {
ref<FileStream> fs = new FileStream(toFsPath(fileName),
FileStream::ETruncReadWrite);
bitmap->write(format, fs);
}
}
}
void MainWindow::on_actionSave_triggered() {

View File

@ -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);

View File

@ -128,6 +128,7 @@
<addaction name="separator"/>
<addaction name="actionSave"/>
<addaction name="actionSaveAs"/>
<addaction name="actionCopyImage"/>
<addaction name="actionExportImage"/>
<addaction name="separator"/>
<addaction name="actionClose"/>
@ -475,6 +476,14 @@
<string>Ctrl+F</string>
</property>
</action>
<action name="actionCopyImage">
<property name="text">
<string>&amp;Copy image</string>
</property>
<property name="shortcut">
<string>Ctrl+C</string>
</property>
</action>
<action name="actionFeedback">
<property name="text">
<string>Report &amp;Feedback</string>