Browse Source

Add 2x and 4x zoom save image actions, compress output

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 4 years ago
parent
commit
96a914ebca
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 39 additions and 11 deletions
  1. +12
    -0
      resources/ui/carla_host.ui
  2. +27
    -11
      source/frontend/carla_host.py

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

@@ -539,6 +539,8 @@
<addaction name="menu_Canvas_Zoom"/>
<addaction name="separator"/>
<addaction name="act_canvas_save_image"/>
<addaction name="act_canvas_save_image_2x"/>
<addaction name="act_canvas_save_image_4x"/>
</widget>
<widget class="QMenu" name="menu_Settings">
<property name="title">
@@ -1638,6 +1640,16 @@
<string>Open custom driver panel...</string>
</property>
</action>
<action name="act_canvas_save_image_2x">
<property name="text">
<string>Save Image... (2x zoom)</string>
</property>
</action>
<action name="act_canvas_save_image_4x">
<property name="text">
<string>Save Image... (4x zoom)</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>


+ 27
- 11
source/frontend/carla_host.py View File

@@ -28,7 +28,7 @@ except ImportError:
PYQT_VERSION = 0x50600

from PyQt5.QtCore import QT_VERSION, qCritical, QEventLoop, QFileInfo, QModelIndex, QPointF, QTimer, QEvent
from PyQt5.QtGui import QImage, QPalette, QBrush
from PyQt5.QtGui import QImage, QImageWriter, QPalette, QBrush
from PyQt5.QtWidgets import QAction, QApplication, QInputDialog, QFileSystemModel, QListWidgetItem, QGraphicsView, QMainWindow

# ------------------------------------------------------------------------------------------------------------
@@ -192,8 +192,6 @@ class HostWindow(QMainWindow):
# ----------------------------------------------------------------------------------------------------
# Internal stuff (patchbay)

self.fExportImage = QImage()

self.fPeaksCleared = True

self.fExternalPatchbay = False
@@ -500,6 +498,8 @@ class HostWindow(QMainWindow):
self.ui.act_canvas_zoom_out.triggered.connect(self.slot_canvasZoomOut)
self.ui.act_canvas_zoom_100.triggered.connect(self.slot_canvasZoomReset)
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_arrange.setEnabled(False) # TODO, later
self.ui.graphicsView.horizontalScrollBar().valueChanged.connect(self.slot_horizontalScrollBarChanged)
self.ui.graphicsView.verticalScrollBar().valueChanged.connect(self.slot_verticalScrollBarChanged)
@@ -1533,25 +1533,41 @@ class HostWindow(QMainWindow):
if not newPath:
return

sender = self.sender()
if sender == self.ui.act_canvas_save_image_2x:
zoom = 2.0
elif sender == self.ui.act_canvas_save_image_4x:
zoom = 4.0
else:
zoom = 1.0

self.scene.clearSelection()

if newPath.lower().endswith((".jpg", ".jpeg")):
imgFormat = "JPG"
imgFormat = b"JPG"
elif newPath.lower().endswith((".png",)):
imgFormat = "PNG"
imgFormat = b"PNG"
else:
# File-dialog may not auto-add the extension
imgFormat = "PNG"
imgFormat = b"PNG"
newPath += ".png"

self.fExportImage = QImage(self.scene.sceneRect().width(), self.scene.sceneRect().height(), QImage.Format_RGB32)
painter = QPainter(self.fExportImage)
image = QImage(self.scene.width()*zoom, self.scene.height()*zoom, QImage.Format_RGB32)
painter = QPainter(image)
painter.save()
painter.setRenderHint(QPainter.Antialiasing) # TODO - set true, cleanup this
painter.setRenderHint(QPainter.TextAntialiasing)
painter.setRenderHints(painter.renderHints() | QPainter.Antialiasing | QPainter.TextAntialiasing)
self.scene.render(painter)
self.fExportImage.save(newPath, imgFormat, 100)
painter.restore()
del painter

iw = QImageWriter(newPath)
iw.setFormat(imgFormat)
iw.setCompression(-1)

if QT_VERSION >= 0x50500:
iw.setOptimizedWrite(True)

iw.write(image)

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


Loading…
Cancel
Save