def __init__(self,window):
		qtgui.QDialog.__init__(self,window)

		self.scene=qtgui.QGraphicsScene()
		self.view=qtgui.QGraphicsView(self.scene,self)

		self.ui=Ui_CanvasSizeDialog()
		self.ui.setupUi(self)

		replaceWidget(self.ui.image_preview,self.view)

		image=window.scene.getImageCopy()
		self.startwidth=image.width()
		self.startheight=image.height()

		self.item=CanvasAdjustPreview(image)

		self.scene.addItem(self.item)
		self.view.fitInView(self.item,qtcore.Qt.KeepAspectRatio)
		self.view.setHorizontalScrollBarPolicy(qtcore.Qt.ScrollBarAlwaysOff)
		self.view.setVerticalScrollBarPolicy(qtcore.Qt.ScrollBarAlwaysOff)
		self.view.setBackgroundBrush(qtgui.QColor(200,200,200))
		self.view.setAlignment(qtcore.Qt.AlignCenter)
		self.ui.image_preview=self.scene

		self.topadj=0
		self.leftadj=0
		self.rightadj=0
		self.bottomadj=0
class CanvasAdjustDialog(qtgui.QDialog):
	def __init__(self,window):
		qtgui.QDialog.__init__(self,window)

		self.scene=qtgui.QGraphicsScene()
		self.view=qtgui.QGraphicsView(self.scene,self)

		self.ui=Ui_CanvasSizeDialog()
		self.ui.setupUi(self)

		replaceWidget(self.ui.image_preview,self.view)

		image=window.scene.getImageCopy()
		self.startwidth=image.width()
		self.startheight=image.height()

		self.item=CanvasAdjustPreview(image)

		self.scene.addItem(self.item)
		self.view.fitInView(self.item,qtcore.Qt.KeepAspectRatio)
		self.view.setHorizontalScrollBarPolicy(qtcore.Qt.ScrollBarAlwaysOff)
		self.view.setVerticalScrollBarPolicy(qtcore.Qt.ScrollBarAlwaysOff)
		self.view.setBackgroundBrush(qtgui.QColor(200,200,200))
		self.view.setAlignment(qtcore.Qt.AlignCenter)
		self.ui.image_preview=self.scene

		self.topadj=0
		self.leftadj=0
		self.rightadj=0
		self.bottomadj=0

	def showEvent(self,event):
		self.refreshPreview()
		return qtgui.QDialog.showEvent(self,event)

	def on_Top_Adjust_Box_valueChanged(self,value):
		if type(value)==type(int()):
			self.topadj=value
			if self.startheight+self.topadj+self.bottomadj<1:
				self.topadj=1-self.bottomadj-self.startheight
				self.ui.Top_Adjust_Box.setValue(self.topadj)
			self.refreshPreview()
	def on_Bottom_Adjust_Box_valueChanged(self,value):
		if type(value)==type(int()):
			self.bottomadj=value
			if self.startheight+self.topadj+self.bottomadj<1:
				self.bottomadj=1-self.topadj-self.startheight
				self.ui.Bottom_Adjust_Box.setValue(self.bottomadj)
			self.refreshPreview()
	def on_Left_Adjust_Box_valueChanged(self,value):
		if type(value)==type(int()):
			self.leftadj=value
			if self.startwidth+self.leftadj+self.rightadj<1:
				self.leftadj=1-self.rightadj-self.startwidth
				self.ui.Left_Adjust_Box.setValue(self.leftadj)
			self.refreshPreview()
	def on_Right_Adjust_Box_valueChanged(self,value):
		if type(value)==type(int()):
			self.rightadj=value
			if self.startwidth+self.leftadj+self.rightadj<1:
				self.rightadj=1-self.leftadj-self.startwidth
				self.ui.Left_Adjust_Box.setValue(self.rightadj)
			self.refreshPreview()

	def refreshPreview(self):
		self.item.newAdjustments(self.leftadj,self.topadj,self.rightadj,self.bottomadj)
		self.view.fitInView(self.item,qtcore.Qt.KeepAspectRatio)