def setScale(self, scale =1): """ Set scale factor """ if scale!=self.viewScale: self.viewScale = float(scale) matrix = qt.QWMatrix(self.viewScale,0.,0.,self.viewScale,0.,0.) self.setWorldMatrix(matrix)
def draw(self, p): """ """ if self.fullRedrawFlag: scale = float(self.width())/self.imageWidth wm = p.worldMatrix() nwm = qt.QWMatrix(wm.m11(),wm.m12(),wm.m21(),wm.m22(),wm.dx(),wm.dy()) nwm = nwm.scale(scale, scale) np = qt.QPainter(p.device()) np.setWorldMatrix(nwm) np.drawPixmap(int(self.x()/scale)+1, int(self.y()/scale)+1, \ self.pixmap) PrintCanvasRectangle.draw(self, p)
def __rectangleZoomChanged(self,drawingMgr) : self.__zoomFitOrFill.setState(False) rect = drawingMgr.rect() canvas = self.__mainView.view() matrix = canvas.matrix() vp = canvas.viewport() viewWidth,viewHeight = vp.width(),vp.height() zoomX = float(viewWidth) / rect.width() zoomY = float(viewHeight) / rect.height() zoom = max(zoomX,zoomY) newMatrix = qt.QWMatrix(zoom,0,0,zoom,matrix.dx(),matrix.dy()) rect = newMatrix.map(rect) zoom = min(zoom,20) canvas.setZoom(zoom,zoom) canvas.setContentsPos(rect.x(),rect.y()) self.__zoomList.writeStrValue("%d%%" % (zoom * 100))
def get_qimage(self, image, canvas, zoom=1): """ Gets the QImage from a parent widget. :param image: The QWidget that contains the image to extract :type image: QWidget :param canvas: The QCanvas obejct to add as overlay :type canvas: QCanvas :param zoom: Zoom level :type zoom: int. :returns: The QImage contained in the parent widget. :rtype: QImage """ if canvas is not None and image is not None: device = qt.QPixmap(image) painter = qt.QPainter(device) zoom = 1.0 / zoom painter.setWorldMatrix(qt.QWMatrix(zoom, 0, 0, zoom, 0, 0)) if isinstance(canvas, list): itemsList = canvas else: itemsList = canvas.allItems() for item in itemsList: if item.isVisible(): if hasattr(item, 'setScrollView'): #remove standalone items continue item.draw(painter) painter.end() img = device.convertToImage() else: img = image return img
def onListSelected(self): item = self.list.selectedItem() pixmap = None if item is None: pass elif item == self.root: pass else: element = self.device.getComponentByAddress(item.text(0)) if element is not None: if element.isLeaf(): img_str = element.fetchImage() if img_str is not None: pixmap = qt.QPixmap() pixmap.loadFromData(img_str) if self.inversed_image: m = qt.QWMatrix() m.scale(1.0, -1.0) pixmap = pixmap.xForm(m) x = element.getImageX() y = element.getImageY() if (x is not None) and (y is not None): # Overlays p = qt.QPainter() p.begin(pixmap) p.setPen(qt.QPen(qt.QColor(0xE0, 0xE0, 0), 2)) size = 8 center = qt.QPoint( int(x / 100.0 * pixmap.width()), int(y / 100.0 * pixmap.height()), ) if self.inversed_image: center.setY( int((100.0 - y) / 100.0 * pixmap.height())) p.drawLine( qt.QPoint(center.x(), center.y() - size), qt.QPoint(center.x(), center.y() + size), ) p.drawLine( qt.QPoint(center.x() - size, center.y()), qt.QPoint(center.x() + size, center.y()), ) p.setPen(qt.QPen(qt.QColor(0, 0xC0, 0), 2)) size = 20 center = qt.QPoint( int(x / 100.0 * pixmap.width()), int(y / 100.0 * pixmap.height()), ) if self.inversed_image: center.setY( int((100.0 - y) / 100.0 * pixmap.height())) p.drawLine( qt.QPoint(center.x(), center.y() - size), qt.QPoint(center.x(), center.y() + size), ) p.drawLine( qt.QPoint(center.x() - size, center.y()), qt.QPoint(center.x() + size, center.y()), ) p.end() self.widget.lbImage.setPixmap(pixmap) # This check because don't know how to clear QLabel but assigniong an empty pixmap, what prints a warning message # if pixmap!=self._empty_image_pixmap or self.widget.lbImage.pixmap() is None or self.widget.lbImage.pixmap().width()>0: # self.widget.lbImage.setPixmap(pixmap) # self.widget.lbImage.setVisible(pixmap != self._empty_image_pixmap) if pixmap is not None: self.widget.lbImage.setPixmap(pixmap) self.widget.lbImage.show() else: self.widget.lbImage.clear() self.widget.lbImage.hide()