def _draw_peak_values(self, painter, labels): #mainlog.debug('_draw_peak_values : {}'.format(labels)) text_pen = QPen() text_pen.setCapStyle(Qt.RoundCap) text_pen.setColor(Qt.GlobalColor.white) # alpha=255=fully opaque text_pen.setWidth(1) fm = painter.fontMetrics() rects = [] painter.setPen(text_pen) # The sort allow to draw the peak values which are lower first. # We do that to visually connect a peak value to its bar in a # (hopefully) better way for i in sorted( range(len(labels)), key=lambda i:self._item_coordinates(i)[1]): x, y_top, y_below = self._item_coordinates(i) label = labels[i] w = fm.boundingRect(label).width() h = fm.boundingRect(label).height() r = QRect(self.x_centers[i] - int(w/2), self.y_base-y_top - 5 - h, w, h) i = 0 while i < len(rects): old_r = rects[i] if r.intersect(old_r): i = 0 # Move r atop old_r r.translate(0, -(r.bottom() - old_r.y()) - 2) else: i += 1 rects.append(r) self._draw_box_under_text(painter, r.x(), r.y() + h,label) painter.drawText( r.x(), r.y() + h,label)
class EmbDetailsDialog(QDialog): """ Class implementing the Details dialog. """ def __init__(self, theScene, parent): """ Default class constructor. :param `theScene`: TOWRITE :type `theScene`: QGraphicsScene :param `parent`: parent widget instance of this dialog. :type `parent`: QWidget """ super(EmbDetailsDialog, self).__init__(parent) self.setMinimumSize(750, 550) self.getInfo() mainWidget = self.createMainWidget() buttonBox = QDialogButtonBox(QDialogButtonBox.Ok) buttonBox.accepted.connect(self.accept) vboxLayoutMain = QVBoxLayout(self) vboxLayoutMain.addWidget(mainWidget) vboxLayoutMain.addWidget(buttonBox) self.setLayout(vboxLayoutMain) self.setWindowTitle(self.tr("Embroidery Design Details")) QApplication.setOverrideCursor(Qt.ArrowCursor) def __del__(self): """Class destructor""" QApplication.restoreOverrideCursor() def getInfo(self): """TOWRITE""" # TODO: generate a temporary pattern from the scene data. # TODO: grab this information from the pattern self.stitchesTotal = 5 # TODO: embStitchList_count(pattern->stitchList, TOTAL) self.stitchesReal = 4 # TODO: embStitchList_count(pattern->stitchList, NORMAL) self.stitchesJump = 3 # TODO: embStitchList_count(pattern->stitchList, JUMP) self.stitchesTrim = 2 # TODO: embStitchList_count(pattern->stitchList, TRIM) self.colorTotal = 1 # TODO: embThreadList_count(pattern->threadList, TOTAL) self.colorChanges = 0 # TODO: embThreadList_count(pattern->threadList, CHANGES) self.boundingRect = QRect() #TODO/FIXME# self.boundingRect.setRect( 0, 0, 50, 100) # TODO: embPattern_calcBoundingBox(pattern) def createMainWidget(self): """ TOWRITE :return: TOWRITE :rtype: QScrollArea """ widget = QWidget(self) # Misc groupBoxMisc = QGroupBox(self.tr("General Information"), widget) labelStitchesTotal = QLabel(self.tr("Total Stitches:"), self) labelStitchesReal = QLabel(self.tr("Real Stitches:"), self) labelStitchesJump = QLabel(self.tr("Jump Stitches:"), self) labelStitchesTrim = QLabel(self.tr("Trim Stitches:"), self) labelColorTotal = QLabel(self.tr("Total Colors:"), self) labelColorChanges = QLabel(self.tr("Color Changes:"), self) labelRectLeft = QLabel(self.tr("Left:"), self) labelRectTop = QLabel(self.tr("Top:"), self) labelRectRight = QLabel(self.tr("Right:"), self) labelRectBottom = QLabel(self.tr("Bottom:"), self) labelRectWidth = QLabel(self.tr("Width:"), self) labelRectHeight = QLabel(self.tr("Height:"), self) fieldStitchesTotal = QLabel(u'%s' % (self.stitchesTotal), self) fieldStitchesReal = QLabel(u'%s' % (self.stitchesReal), self) fieldStitchesJump = QLabel(u'%s' % (self.stitchesJump), self) fieldStitchesTrim = QLabel(u'%s' % (self.stitchesTrim), self) fieldColorTotal = QLabel(u'%s' % (self.colorTotal), self) fieldColorChanges = QLabel(u'%s' % (self.colorChanges), self) fieldRectLeft = QLabel(u'%s' % (str(self.boundingRect.left()) + " mm"), self) fieldRectTop = QLabel(u'%s' % (str(self.boundingRect.top()) + " mm"), self) fieldRectRight = QLabel( u'%s' % (str(self.boundingRect.right()) + " mm"), self) fieldRectBottom = QLabel( u'%s' % (str(self.boundingRect.bottom()) + " mm"), self) fieldRectWidth = QLabel( u'%s' % (str(self.boundingRect.width()) + " mm"), self) fieldRectHeight = QLabel( u'%s' % (str(self.boundingRect.height()) + " mm"), self) gridLayoutMisc = QGridLayout(groupBoxMisc) gridLayoutMisc.addWidget(labelStitchesTotal, 0, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesReal, 1, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesJump, 2, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesTrim, 3, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelColorTotal, 4, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelColorChanges, 5, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectLeft, 6, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectTop, 7, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectRight, 8, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectBottom, 9, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectWidth, 10, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectHeight, 11, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesTotal, 0, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesReal, 1, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesJump, 2, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesTrim, 3, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldColorTotal, 4, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldColorChanges, 5, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectLeft, 6, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectTop, 7, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectRight, 8, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectBottom, 9, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectWidth, 10, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectHeight, 11, 1, Qt.AlignLeft) gridLayoutMisc.setColumnStretch(1, 1) groupBoxMisc.setLayout(gridLayoutMisc) # TODO: Color Histogram # Stitch Distribution # groupBoxDist = QGroupBox(self.tr("Stitch Distribution"), widget) # TODO: Stitch Distribution Histogram # Widget Layout vboxLayoutMain = QVBoxLayout(widget) vboxLayoutMain.addWidget(groupBoxMisc) # vboxLayoutMain.addWidget(groupBoxDist) vboxLayoutMain.addStretch(1) widget.setLayout(vboxLayoutMain) scrollArea = QScrollArea(self) scrollArea.setWidgetResizable(True) scrollArea.setWidget(widget) return scrollArea
def paint(self, painter, option, index): """ Overrideoljuk a saját igényeinkre""" rect = option.rect movieObj = index.data(Qt.UserRole) # BACKGROUND rect painter.setPen(Qt.NoPen) if option.state & QStyle.State_Selected: painter.setBrush(self.selectedColor) else: painter.setBrush(self.bgColor) painter.drawRect(rect) # POSTER rect painter.setBrush(self.posterBrush) painter.setPen(self.posterOutline) # Posert image rect pixmap = QPixmap(movieObj.poster) pixmapRect = QRect(rect.x() + 5, rect.y() + 5, pixmap.width(), pixmap.height()) painter.drawPixmap(pixmapRect, pixmap) # TITLE rect painter.setFont(self.font) titleRect = QRect(pixmapRect.left(), pixmapRect.bottom(), pixmapRect.width(), 40) painter.drawText(titleRect, Qt.AlignVCenter | Qt.AlignHCenter, movieObj.name) if option.state & QStyle.State_Selected: painter.setPen(Qt.NoPen) painter.setBrush(self.transparentBG) painter.drawRect(rect) if movieObj.getMovieWatchedStatus() == 1: watchedRect = QRect(rect.x() + 2, rect.y() + 2, 25, 25) watchedIcon = QPixmap(fileUtils.get_icon("watchedfiltericon")) painter.setBrush(self.watchedBG) painter.drawPixmap(watchedRect, watchedIcon) painter.setBrush(self.watchedBG) painter.setPen(Qt.NoPen) painter.drawRect( QRect(rect.x() - 2, rect.y() - 2, rect.width() + 4, rect.height() + 4)) elif movieObj.getMovieWatchedStatus() == 0: painter.setBrush(self.unWatchedBG) painter.setPen(Qt.NoPen) painter.drawRect( QRect(rect.x() - 2, rect.y() - 2, rect.width() + 4, rect.height() + 4))
class EmbDetailsDialog(QDialog): """ Subclass of `QDialog`_ Class implementing the Details dialog. .. sphinx_generate_methods_summary:: EmbDetailsDialog """ def __init__(self, theScene, parent): """ Default class constructor. :param `theScene`: TOWRITE :type `theScene`: `QGraphicsScene`_ :param `parent`: Pointer to a parent widget instance. :type `parent`: `QWidget`_ """ super(EmbDetailsDialog, self).__init__(parent) self.setMinimumSize(750, 550) self.getInfo() mainWidget = self.createMainWidget() buttonBox = QDialogButtonBox(QDialogButtonBox.Ok) buttonBox.accepted.connect(self.accept) vboxLayoutMain = QVBoxLayout(self) vboxLayoutMain.addWidget(mainWidget) vboxLayoutMain.addWidget(buttonBox) self.setLayout(vboxLayoutMain) self.setWindowTitle(self.tr("Embroidery Design Details")) QApplication.setOverrideCursor(Qt.ArrowCursor) def __del__(self): """Class destructor""" QApplication.restoreOverrideCursor() def getInfo(self): """TOWRITE""" # TODO: generate a temporary pattern from the scene data. # TODO: grab this information from the pattern self.stitchesTotal = 5 # TODO: embStitchList_count(pattern->stitchList, TOTAL) self.stitchesReal = 4 # TODO: embStitchList_count(pattern->stitchList, NORMAL) self.stitchesJump = 3 # TODO: embStitchList_count(pattern->stitchList, JUMP) self.stitchesTrim = 2 # TODO: embStitchList_count(pattern->stitchList, TRIM) self.colorTotal = 1 # TODO: embThreadList_count(pattern->threadList, TOTAL) self.colorChanges = 0 # TODO: embThreadList_count(pattern->threadList, CHANGES) self.boundingRect = QRect() #TODO/FIXME# self.boundingRect.setRect(0, 0, 50, 100) # TODO: embPattern_calcBoundingBox(pattern) def createMainWidget(self): """ TOWRITE :return: TOWRITE :rtype: `QScrollArea`_ """ widget = QWidget(self) # Misc groupBoxMisc = QGroupBox(self.tr("General Information"), widget) labelStitchesTotal = QLabel(self.tr("Total Stitches:"), self) labelStitchesReal = QLabel(self.tr("Real Stitches:"), self) labelStitchesJump = QLabel(self.tr("Jump Stitches:"), self) labelStitchesTrim = QLabel(self.tr("Trim Stitches:"), self) labelColorTotal = QLabel(self.tr("Total Colors:"), self) labelColorChanges = QLabel(self.tr("Color Changes:"), self) labelRectLeft = QLabel(self.tr("Left:"), self) labelRectTop = QLabel(self.tr("Top:"), self) labelRectRight = QLabel(self.tr("Right:"), self) labelRectBottom = QLabel(self.tr("Bottom:"), self) labelRectWidth = QLabel(self.tr("Width:"), self) labelRectHeight = QLabel(self.tr("Height:"), self) fieldStitchesTotal = QLabel(u'%s' % (self.stitchesTotal), self) fieldStitchesReal = QLabel(u'%s' % (self.stitchesReal), self) fieldStitchesJump = QLabel(u'%s' % (self.stitchesJump), self) fieldStitchesTrim = QLabel(u'%s' % (self.stitchesTrim), self) fieldColorTotal = QLabel(u'%s' % (self.colorTotal), self) fieldColorChanges = QLabel(u'%s' % (self.colorChanges), self) fieldRectLeft = QLabel(u'%s' % (str(self.boundingRect.left()) + " mm"), self) fieldRectTop = QLabel(u'%s' % (str(self.boundingRect.top()) + " mm"), self) fieldRectRight = QLabel(u'%s' % (str(self.boundingRect.right()) + " mm"), self) fieldRectBottom = QLabel(u'%s' % (str(self.boundingRect.bottom()) + " mm"), self) fieldRectWidth = QLabel(u'%s' % (str(self.boundingRect.width()) + " mm"), self) fieldRectHeight = QLabel(u'%s' % (str(self.boundingRect.height()) + " mm"), self) gridLayoutMisc = QGridLayout(groupBoxMisc) gridLayoutMisc.addWidget(labelStitchesTotal, 0, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesReal, 1, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesJump, 2, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelStitchesTrim, 3, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelColorTotal, 4, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelColorChanges, 5, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectLeft, 6, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectTop, 7, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectRight, 8, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectBottom, 9, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectWidth, 10, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(labelRectHeight, 11, 0, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesTotal, 0, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesReal, 1, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesJump, 2, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldStitchesTrim, 3, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldColorTotal, 4, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldColorChanges, 5, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectLeft, 6, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectTop, 7, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectRight, 8, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectBottom, 9, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectWidth, 10, 1, Qt.AlignLeft) gridLayoutMisc.addWidget(fieldRectHeight, 11, 1, Qt.AlignLeft) gridLayoutMisc.setColumnStretch(1,1) groupBoxMisc.setLayout(gridLayoutMisc) # TODO: Color Histogram # Stitch Distribution # groupBoxDist = QGroupBox(self.tr("Stitch Distribution"), widget) # TODO: Stitch Distribution Histogram # Widget Layout vboxLayoutMain = QVBoxLayout(widget) vboxLayoutMain.addWidget(groupBoxMisc) # vboxLayoutMain.addWidget(groupBoxDist) vboxLayoutMain.addStretch(1) widget.setLayout(vboxLayoutMain) scrollArea = QScrollArea(self) scrollArea.setWidgetResizable(True) scrollArea.setWidget(widget) return scrollArea