File indexing completed on 2025-03-09 04:10:19

0001 # SPDX-License-Identifier: CC0-1.0
0002 
0003 from PyQt5.QtWidgets import (QWidget, QSpinBox,
0004                              QVBoxLayout, QFormLayout, QComboBox)
0005 
0006 
0007 class ScaleTool(QWidget):
0008 
0009     def __init__(self, mainDialog, parent=None):
0010         super(ScaleTool, self).__init__(parent)
0011 
0012         self.setObjectName(i18n("Scale"))
0013 
0014         self.layout = QFormLayout()
0015         self.resolutionLayout = QVBoxLayout()
0016         self.widthSpinBox = QSpinBox()
0017         self.heightSpinBox = QSpinBox()
0018         self.xResSpinBox = QSpinBox()
0019         self.yResSpinBox = QSpinBox()
0020         self.strategyComboBox = QComboBox()
0021 
0022         self.strategyComboBox.setSizeAdjustPolicy(QComboBox.AdjustToContents)
0023         self.setLayout(self.layout)
0024         self.initialize()
0025 
0026     def initialize(self):
0027         self.widthSpinBox.setRange(1, 10000)
0028         self.heightSpinBox.setRange(1, 10000)
0029         self.xResSpinBox.setRange(1, 10000)
0030         self.yResSpinBox.setRange(1, 10000)
0031 
0032         strategies = ['Hermite', 'Bicubic', 'Box',
0033                       'Bilinear', 'Bell', 'BSpline',
0034                       'Kanczos3', 'Mitchell']
0035         self.strategyComboBox.addItems(strategies)
0036 
0037         self.resolutionLayout.addWidget(self.xResSpinBox)
0038         self.resolutionLayout.addWidget(self.yResSpinBox)
0039 
0040         self.layout.addRow(i18n("Width:"), self.widthSpinBox)
0041         self.layout.addRow(i18n("Height:"), self.heightSpinBox)
0042         self.layout.addRow(i18n("Resolution:"), self.resolutionLayout)
0043         self.layout.addRow(i18nc("Resize intepolation method list label", "Filter:"), self.strategyComboBox)
0044 
0045     def adjust(self, documents):
0046         for document in documents:
0047             document.scaleImage(self.widthSpinBox.value(),
0048                                 self.heightSpinBox.value(),
0049                                 self.xResSpinBox.value(),
0050                                 self.yResSpinBox.value(),
0051                                 self.strategyComboBox.currentText())