def paintEvent(self, event): QLabel.paintEvent(self, event) self.resize(self.viewWidth, self.viewHeight) for headInfo in self.headers: name = headInfo['name'] x = headInfo['x'] x = x - self.position if x + self.w < 0: continue if x > self.viewWidth: continue self.headLeftPos = x self.headRightPos = x + self.w self.headTopPos = self.t self.headBottomPos = self.t + self.h qp = QtGui.QPainter() qp.begin(self) qp.setBrush(headInfo['color']) qp.drawRect(x, self.t, self.w, self.h) qp.setPen(QtGui.QColor(20, 20, 30)) qp.setFont(QtGui.QFont('Decorative', 10)) leaf_name = list(reversed(name.split(".")))[0] parent_name = ".".join( list(reversed(list(reversed(name.split(".")))[1:]))) if parent_name == "": qp.setFont(QtGui.QFont('Decorative', 11)) wd = QtGui.QFontMetrics( self.font()).boundingRect(leaf_name).width() align_option = QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter if wd > self.w - 20 else QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter qp.drawText(QtCore.QRect(x + 10, self.t, self.w - 20, self.h), align_option, leaf_name) else: qp.setFont(QtGui.QFont('Decorative', 7)) wd = QtGui.QFontMetrics( self.font()).boundingRect(parent_name).width() align_option = QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter if wd > self.w - 20 else QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter qp.drawText( QtCore.QRect(x + 10, self.t, self.w - 20, self.h / 2), align_option, parent_name) qp.setFont(QtGui.QFont('Decorative', 11)) qp.drawText( QtCore.QRect(x + 10, self.t + self.h / 2, self.w - 20, self.h / 2), QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter, leaf_name) qp.drawLine(x + self.w / 2, self.h + self.t, x + self.w / 2, 90000) qp.end()
def firstPage(self): for i in range( self.mainLayout.count() ): item = self.mainLayout.itemAt(0) item.widget().setParent( None ) title = QLabel( "<p style='color:rgb( 137,129,120 )'>Welcome to the PingoTools Installer</p>" ) title.setFixedHeight( 50 ) titleFont = QFont() titleFont.setPixelSize( 18 ) titleFont.setBold( True ) titleFont.setFamily( "Helvetica [Cronyx]" ) title.setAlignment( QtCore.Qt.AlignCenter ) title.setFont( titleFont ) description = QLabel() description.setAlignment( QtCore.Qt.AlignCenter ) buttonsWidget = QWidget(); buttonsWidget.setMaximumHeight( 50 ) buttonsLayout = QHBoxLayout( buttonsWidget ) emptyArea = QLabel() buttonNext = QPushButton( 'Next > ' ) buttonCancel = QPushButton( 'Cancel' ) buttonsLayout.addWidget( emptyArea ) buttonsLayout.addWidget( buttonNext ); buttonNext.setFixedWidth( 100 ) buttonsLayout.addWidget( buttonCancel ); buttonCancel.setFixedWidth( 100 ) self.mainLayout.addWidget( title ) self.mainLayout.addWidget( description ) self.mainLayout.addWidget( buttonsWidget ) origWidth = 500 frontImage = QImage() frontImage.load( os.path.dirname( __file__ ) + '/images/pingoTools_main.jpg' ) trValue = QTransform().scale( float(origWidth)/frontImage.width(), float(origWidth)/frontImage.width() ) transformedImage = frontImage.transformed( trValue ) pixmap = QPixmap.fromImage( transformedImage ) description.setPixmap( pixmap ) description.setGeometry( 0,0, transformedImage.width() , transformedImage.height() ) description.paintEvent(QPaintEvent(QtCore.QRect( 0,0,self.width(), self.height() ))) QtCore.QObject.connect( buttonNext, QtCore.SIGNAL( 'clicked()' ), self.secondPage ) QtCore.QObject.connect( buttonCancel, QtCore.SIGNAL( 'clicked()' ), self.cmd_cancel )
class ImageBase(QLabel): def __init__(self, *args, **kwargs): self.transInfo = ImageBaseTranslateInfo() super(ImageBase, self).__init__(*args, **kwargs) self.installEventFilter(self) self.image = QImage() self.pixmap = QPixmap() self.label = QLabel(self) self.imagePath = "" self.aspect = 1 self.imageClean = True def clearImage(self): self.label.clear() self.imageClean = True def loadImage(self, filePath): self.imageClean = False if self.imagePath == filePath: return None self.imagePath = filePath self.aspect = 1 if self.image.load(filePath): pass self.transInfo.setDefault() widgetSize = min(self.parentWidget().width(), self.parentWidget().height()) * 0.9 imageWidth = self.image.width() self.transInfo.scale = widgetSize / float(imageWidth) self.resize() def resize(self): if self.imageClean: return None trValue = QTransform().scale(self.transInfo.scaleX(), self.transInfo.scaleY()) trValue *= QTransform().rotate(self.transInfo.rotValue) imageTransformed = self.image.transformed(trValue) imageWidth = imageTransformed.width() imageHeight = imageTransformed.height() self.pixmap = QPixmap.fromImage(imageTransformed) self.label.setPixmap(self.pixmap) marginLeft = (self.width() - imageWidth) / 2.0 marginTop = (self.height() - imageHeight) / 2.0 self.label.setGeometry(marginLeft + self.transInfo.x, marginTop + self.transInfo.y, imageWidth, imageHeight) self.label.paintEvent( QPaintEvent(QtCore.QRect(0, 0, self.width(), self.height()))) def flip(self, pressX): offsetX = pressX - self.width() / 2 self.transInfo.rotValue *= -1 self.transInfo.x = (self.transInfo.x - offsetX) * -1 + offsetX self.transInfo.scaleMultX *= -1 self.resize() def show(self): self.label.show() def eventFilter(self, Obj, event): if event.type() == QtCore.QEvent.Resize: self.resize() elif event.type() == QtCore.QEvent.MouseButtonPress: pressX = event.x() - self.width() / 2 pressY = event.y() - self.height() / 2 self.transInfo.buttonPress(event.button(), pressX, pressY) elif event.type() == QtCore.QEvent.MouseButtonRelease: if self.transInfo.x == self.transInfo.bx and self.transInfo.y == self.transInfo.by: pass self.transInfo.buttonRelease() Window_global.saveInfo() elif event.type() == QtCore.QEvent.MouseMove: pressX = event.x() - self.width() / 2 pressY = event.y() - self.height() / 2 self.transInfo.drag(pressX, pressY) self.resize() elif event.type() == QtCore.QEvent.MouseButtonDblClick: self.flip(event.x()) elif event.type() == QtCore.QEvent.Wheel: pressX = event.x() - self.width() / 2 pressY = event.y() - self.height() / 2 self.transInfo.buttonPress(QtCore.Qt.RightButton, pressX, pressY) self.transInfo.drag(pressX + event.delta() / 2, pressY) self.transInfo.buttonRelease() self.resize() Window_global.saveInfo() return True
class ImageBase(QLabel): def __init__(self, *args, **kwargs): self.transInfo = ImageBaseTranslateInfo() super(ImageBase, self).__init__(*args, **kwargs) self.installEventFilter(self) self.image = QImage() self.pixmap = QPixmap() self.label = QLabel(self) self.imagePath = "" self.aspect = 1 self.imageClean = True def clearImage(self): self.label.clear() self.imageClean = True def loadImage(self, filePath ): self.imageClean = False if self.imagePath == filePath: return None self.imagePath = filePath self.aspect = 1 if self.image.load(filePath): pass self.transInfo.setDefault() widgetSize = min( self.parentWidget().width(), self.parentWidget().height() ) * 0.9 imageWidth = self.image.width() self.transInfo.scale = widgetSize / float( imageWidth ) self.resize() def resize(self): if self.imageClean: return None trValue = QTransform().scale( self.transInfo.scaleX(), self.transInfo.scaleY() ) trValue *= QTransform().rotate( self.transInfo.rotValue ) imageTransformed = self.image.transformed(trValue) imageWidth = imageTransformed.width() imageHeight = imageTransformed.height() self.pixmap = QPixmap.fromImage( imageTransformed ) self.label.setPixmap( self.pixmap ) marginLeft = (self.width() - imageWidth)/2.0 marginTop = (self.height() - imageHeight)/2.0 self.label.setGeometry( marginLeft + self.transInfo.x,marginTop + self.transInfo.y, imageWidth, imageHeight ) self.label.paintEvent(QPaintEvent(QtCore.QRect( 0,0,self.width(), self.height() ))) def flip(self, pressX ): offsetX = pressX - self.width()/2 self.transInfo.rotValue *= -1 self.transInfo.x = (self.transInfo.x - offsetX)*-1 + offsetX self.transInfo.scaleMultX *= -1 self.resize() def show( self ): self.label.show() def eventFilter( self, Obj, event ): if event.type() == QtCore.QEvent.Resize: self.resize() elif event.type() == QtCore.QEvent.MouseButtonPress: pressX = event.x()-self.width()/2 pressY = event.y()-self.height()/2 self.transInfo.buttonPress(event.button(), pressX, pressY ) elif event.type() == QtCore.QEvent.MouseButtonRelease: if self.transInfo.x == self.transInfo.bx and self.transInfo.y == self.transInfo.by: pass self.transInfo.buttonRelease() Window_global.saveInfo() elif event.type() == QtCore.QEvent.MouseMove: pressX = event.x()-self.width()/2 pressY = event.y()-self.height()/2 self.transInfo.drag( pressX, pressY ) self.resize() elif event.type() == QtCore.QEvent.MouseButtonDblClick: self.flip( event.x() ) elif event.type() == QtCore.QEvent.Wheel: pressX = event.x()-self.width()/2 pressY = event.y()-self.height()/2 self.transInfo.buttonPress( QtCore.Qt.RightButton , pressX, pressY) self.transInfo.drag( pressX + event.delta()/2, pressY ) self.transInfo.buttonRelease() self.resize() Window_global.saveInfo() return True