Browse Source

Add action to copy canvas as image to clipboard

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 4 years ago
parent
commit
47acfcfa61
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 23 additions and 0 deletions
  1. +9
    -0
      resources/ui/carla_host.ui
  2. +14
    -0
      source/frontend/carla_host.py

+ 9
- 0
resources/ui/carla_host.ui View File

@@ -541,6 +541,7 @@
<addaction name="act_canvas_save_image"/>
<addaction name="act_canvas_save_image_2x"/>
<addaction name="act_canvas_save_image_4x"/>
<addaction name="act_canvas_copy_clipboard"/>
</widget>
<widget class="QMenu" name="menu_Settings">
<property name="title">
@@ -1650,6 +1651,14 @@
<string>Save Image... (4x zoom)</string>
</property>
</action>
<action name="act_canvas_copy_clipboard">
<property name="text">
<string>Copy as Image to Clipboard</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+C</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>


+ 14
- 0
source/frontend/carla_host.py View File

@@ -500,6 +500,7 @@ class HostWindow(QMainWindow):
self.ui.act_canvas_save_image.triggered.connect(self.slot_canvasSaveImage)
self.ui.act_canvas_save_image_2x.triggered.connect(self.slot_canvasSaveImage)
self.ui.act_canvas_save_image_4x.triggered.connect(self.slot_canvasSaveImage)
self.ui.act_canvas_copy_clipboard.triggered.connect(self.slot_canvasCopyToClipboard)
self.ui.act_canvas_arrange.setEnabled(False) # TODO, later
self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
@@ -1591,6 +1592,19 @@ class HostWindow(QMainWindow):

iw.write(image)

@pyqtSlot()
def slot_canvasCopyToClipboard(self):
image = QImage(self.scene.width(), self.scene.height(), QImage.Format_RGB32)
painter = QPainter(image)
painter.save()
painter.setRenderHints(painter.renderHints() | QPainter.Antialiasing | QPainter.TextAntialiasing)
self.scene.clearSelection()
self.scene.render(painter)
painter.restore()
del painter

QApplication.clipboard().setImage(image)

# --------------------------------------------------------------------------------------------------------
# Canvas (canvas callbacks)



Loading…
Cancel
Save