def scene_item_rects_updated(self, items): """The user moved or resized items in the scene """ debug_print('GraphicsItemView.item_rects_updated') for index, item in izip(self.indexes_of_items(items), items): # item.sceneBoundingRect() is the items rects in the correct # coordinates system debug_print('Row [{0}] updated'.format(index.row())) rect = item.sceneBoundingRect() # Cumbersome conversion to ints rect = QRect(rect.left(), rect.top(), rect.width(), rect.height()) self.model().setData(index, rect, RectRole)
def set_rect(self, new_rect): """Sets a new QRect in integer coordinates """ # Cumbersome conversion to ints current = self.sceneBoundingRect() current = QRect(current.left(), current.top(), current.width(), current.height()) if current != new_rect: msg = 'Update rect for [{0}] from [{1}] to [{2}]' debug_print(msg.format(self, current, new_rect)) self.prepareGeometryChange() # setrect() expects floating point rect self.setRect(QRectF(new_rect))
def scene_box_added(self, rect): """The user added a box """ m = self.model() row = len(self._rows) if not m.insertRow(row): raise InselectError('Could not insert row') else: # Cumbersome conversion to ints rect = QRect(rect.left(), rect.top(), rect.width(), rect.height()) if not m.setData(m.index(row, 0), rect, RectRole): raise InselectError('Could not set rect') else: # Select the new box self.scene.clearSelection() item = self.items_of_rows([row]).next() item.setSelected(True) item.update()
def dataChanged(self, topLeft, bottomRight): """QAbstractItemView virtual """ debug_print('GraphicsItemView.dataChanged', topLeft.row(), bottomRight.row()) for row in xrange(topLeft.row(), 1 + bottomRight.row()): # new is a QRect - integer coordinates new = self.model().index(row, 0).data(RectRole) # Cumbersome conversion to ints item = self._rows[row] current = item.sceneBoundingRect() current = QRect(current.left(), current.top(), current.width(), current.height()) if current != new: msg = 'Update rect for [{0}] from [{1}] to [{2}]' debug_print(msg.format(row, current, new)) item.prepareGeometryChange() # setrect() expects floating point rect item.setRect(QRectF(new))
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