|
|
@@ -60,7 +60,7 @@ class ImageFitter(DockWidget):
|
|
|
self.setWidget(widget)
|
|
|
|
|
|
# Hook up the action to the button.
|
|
|
- goButton.clicked.connect( self.fitImage )
|
|
|
+ goButton.clicked.connect( self.fitImageLoop )
|
|
|
|
|
|
|
|
|
# notifies when views are added or removed
|
|
|
@@ -73,25 +73,37 @@ class ImageFitter(DockWidget):
|
|
|
# Slots
|
|
|
##########
|
|
|
|
|
|
- # Actually fits the image.
|
|
|
- def fitImage(self, e):
|
|
|
+ def fitImageLoop(self, e):
|
|
|
+ self.doc = Krita.instance().activeDocument()
|
|
|
+
|
|
|
+ # Get the selected layer(s).
|
|
|
+ w = Krita.instance().activeWindow()
|
|
|
+ v = w.activeView()
|
|
|
+ layers = v.selectedNodes()
|
|
|
+ didNotRun = True
|
|
|
+ for layer in layers:
|
|
|
+ if layer.type() == 'paintlayer':
|
|
|
+ self.fitImage(layer)
|
|
|
+ didNotRun = False
|
|
|
|
|
|
- # Get the current layer.
|
|
|
- doc = Krita.instance().activeDocument()
|
|
|
- layer = doc.activeNode()
|
|
|
- if layer.type() != 'paintlayer':
|
|
|
+ if didNotRun:
|
|
|
dialog = QDialog()
|
|
|
dialog.setWindowTitle("Paint Layer Required")
|
|
|
layout = QVBoxLayout()
|
|
|
- layout.addWidget(QLabel('Page slicer only works on paint layers. Please select one.'))
|
|
|
+ layout.addWidget(QLabel('Image Fitter only works on paint layers. Please select one.'))
|
|
|
dialog.setLayout(layout)
|
|
|
dialog.exec_()
|
|
|
- return
|
|
|
+ else:
|
|
|
+ # Refresh the view, or changes will not be immediately reflected.
|
|
|
+ self.doc.refreshProjection()
|
|
|
+
|
|
|
+ # Actually fits the image.
|
|
|
+ def fitImage(self, layer):
|
|
|
|
|
|
# Get centres and bounds for the layer and the target rectangle.
|
|
|
bds = layer.bounds()
|
|
|
layerCentre = self.getCentre(bds.left(), bds.right() + 1, bds.top(), bds.bottom() + 1)
|
|
|
- tbds = self.getTargetBounds(doc, layerCentre)
|
|
|
+ tbds = self.getTargetBounds(layerCentre)
|
|
|
targetCentre = self.getCentre(tbds['left'], tbds['right'], tbds['top'], tbds['bottom'])
|
|
|
|
|
|
# Handle Scaling. Don't scale if not needed.
|
|
|
@@ -148,23 +160,20 @@ class ImageFitter(DockWidget):
|
|
|
layerPos = layer.position()
|
|
|
layer.move(layerPos.x() - diffX, layerPos.y() - diffY)
|
|
|
|
|
|
- # Refresh the view, or the moved will not be immediately reflected.
|
|
|
- doc.refreshProjection()
|
|
|
-
|
|
|
|
|
|
def getCentre(self, left, right, top, bottom):
|
|
|
return {'x': (left + right)/2, 'y': (top + bottom)/2}
|
|
|
|
|
|
|
|
|
- def getTargetBounds(self, doc, layerCentre):
|
|
|
+ def getTargetBounds(self, layerCentre):
|
|
|
# Horizontal guides provide the Vertical y-axis points and vice versa.
|
|
|
# Also include the edges of the image for the rectangle.
|
|
|
- vPoints = doc.horizontalGuides()
|
|
|
- hPoints = doc.verticalGuides()
|
|
|
+ vPoints = self.doc.horizontalGuides()
|
|
|
+ hPoints = self.doc.verticalGuides()
|
|
|
vPoints.insert(0, 0)
|
|
|
- vPoints.append(doc.height())
|
|
|
+ vPoints.append(self.doc.height())
|
|
|
hPoints.insert(0, 0)
|
|
|
- hPoints.append(doc.width())
|
|
|
+ hPoints.append(self.doc.width())
|
|
|
|
|
|
# Sanitize points. Guide values are floats, and may contain unexpected
|
|
|
# extra fractional values.
|