Esempio n. 1
0
    def exportToMobile(self, params):
        IMAGE_FORMAT = 'jpg'
        SKIPPED_FIELDS = ('edgeimg', 'photo1', 'photo2', 'photo3', 'photo4',
                          'obversedesigner', 'reversedesigner', 'catalognum2',
                          'catalognum3', 'catalognum4', 'saledate',
                          'saleprice', 'totalsaleprice', 'buyer', 'saleplace',
                          'saleinfo', 'paydate', 'payprice', 'totalpayprice',
                          'saller', 'payplace', 'payinfo', 'url',
                          'obversedesigner', 'reversedesigner')

        if os.path.isfile(params['file']):
            os.remove(params['file'])

        db = QSqlDatabase.addDatabase('QSQLITE', 'mobile')
        db.setDatabaseName(params['file'])
        if not db.open():
            print(db.lastError().text())
            QMessageBox.critical(self.parent(),
                                 self.tr("Create mobile collection"),
                                 self.tr("Can't open collection"))
            return

        mobile_settings = {
            'Version': 5,
            'Type': 'Mobile',
            'Filter': params['filter']
        }

        sql = """CREATE TABLE settings (
            title CHAR NOT NULL UNIQUE,
            value CHAR)"""
        QSqlQuery(sql, db)
        for key, value in mobile_settings.items():
            query = QSqlQuery(db)
            query.prepare("""INSERT INTO settings (title, value)
                    VALUES (?, ?)""")
            query.addBindValue(key)
            query.addBindValue(str(value))
            query.exec_()

        sql = """CREATE TABLE updates (
            title CHAR NOT NULL UNIQUE,
            value CHAR)"""
        QSqlQuery(sql, db)

        sql = """CREATE TABLE photos (
            id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
            image BLOB)"""
        QSqlQuery(sql, db)

        sqlFields = []
        fields = CollectionFieldsBase()
        for field in fields:
            if field.name == 'id':
                sqlFields.append(
                    'id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT')
            elif field.name == 'image':
                sqlFields.append('image INTEGER')
            elif field.name in SKIPPED_FIELDS:
                continue
            else:
                sqlFields.append("%s %s" %
                                 (field.name, Type.toSql(field.type)))

        sql = "CREATE TABLE coins (" + ", ".join(sqlFields) + ")"
        QSqlQuery(sql, db)

        model = self.model()
        while model.canFetchMore():
            model.fetchMore()

        dest_model = QSqlTableModel(self.parent(), db)
        dest_model.setEditStrategy(QSqlTableModel.OnManualSubmit)
        dest_model.setTable('coins')
        dest_model.select()

        height = 64
        if params['density'] == 'HDPI':
            height *= 1.5
        elif params['density'] == 'XHDPI':
            height *= 2
        elif params['density'] == 'XXHDPI':
            height *= 3
        elif params['density'] == 'XXXHDPI':
            height *= 4
        maxHeight = height * 4

        is_obverse_enabled = params['image'] in (ExportDialog.IMAGE_OBVERSE,
                                                 ExportDialog.IMAGE_BOTH)
        is_reverse_enabled = params['image'] in (ExportDialog.IMAGE_REVERSE,
                                                 ExportDialog.IMAGE_BOTH)

        fields = CollectionFieldsBase()
        count = model.rowCount()
        progressDlg = Gui.ProgressDialog(self.tr("Exporting records"),
                                         self.tr("Cancel"), count,
                                         self.parent())

        for i in range(count):
            progressDlg.step()
            if progressDlg.wasCanceled():
                break

            coin = model.record(i)
            if coin.value('status') in ('pass', 'sold'):
                continue

            dest_record = dest_model.record()

            for field in fields:
                if field.name in ('id', 'image', 'obverseimg', 'reverseimg'):
                    continue
                if field.name in SKIPPED_FIELDS:
                    continue

                val = coin.value(field.name)
                if val is None or val == '':
                    continue

                dest_record.setValue(field.name, val)

            # Process images
            is_obverse_present = not coin.isNull('obverseimg')
            is_reverse_present = not coin.isNull('reverseimg')
            if is_obverse_present or is_reverse_present:
                obverseImage = QImage()
                reverseImage = QImage()

                if is_obverse_present:
                    ba = QtCore.QByteArray()
                    buffer = QtCore.QBuffer(ba)
                    buffer.open(QtCore.QIODevice.WriteOnly)

                    obverseImage.loadFromData(coin.value('obverseimg'))
                    if not obverseImage.isNull() and not params[
                            'fullimage'] and obverseImage.height() > maxHeight:
                        scaledImage = obverseImage.scaled(
                            maxHeight, maxHeight, Qt.KeepAspectRatio,
                            Qt.SmoothTransformation)
                        scaledImage.save(buffer, IMAGE_FORMAT, 50)
                        save_data = ba
                    else:
                        if not obverseImage.isNull():
                            obverseImage.save(buffer, IMAGE_FORMAT, 50)
                            save_data = ba
                        else:
                            save_data = coin.value('obverseimg')

                    query = QSqlQuery(db)
                    query.prepare("""INSERT INTO photos (image)
                            VALUES (?)""")
                    query.addBindValue(save_data)
                    query.exec_()
                    img_id = query.lastInsertId()
                    dest_record.setValue('obverseimg', img_id)
                if not obverseImage.isNull():
                    obverseImage = obverseImage.scaledToHeight(
                        height, Qt.SmoothTransformation)

                if is_reverse_present:
                    ba = QtCore.QByteArray()
                    buffer = QtCore.QBuffer(ba)
                    buffer.open(QtCore.QIODevice.WriteOnly)

                    reverseImage.loadFromData(coin.value('reverseimg'))
                    if not reverseImage.isNull() and not params[
                            'fullimage'] and reverseImage.height() > maxHeight:
                        scaledImage = reverseImage.scaled(
                            maxHeight, maxHeight, Qt.KeepAspectRatio,
                            Qt.SmoothTransformation)
                        scaledImage.save(buffer, IMAGE_FORMAT, 50)
                        save_data = ba
                    else:
                        if not reverseImage.isNull():
                            reverseImage.save(buffer, IMAGE_FORMAT, 50)
                            save_data = ba
                        else:
                            save_data = coin.value('reverseimg')

                    query = QSqlQuery(db)
                    query.prepare("""INSERT INTO photos (image)
                            VALUES (?)""")
                    query.addBindValue(save_data)
                    query.exec_()
                    img_id = query.lastInsertId()
                    dest_record.setValue('reverseimg', img_id)
                if not reverseImage.isNull():
                    reverseImage = reverseImage.scaledToHeight(
                        height, Qt.SmoothTransformation)

                if not is_obverse_enabled:
                    obverseImage = QImage()
                if not is_reverse_enabled:
                    reverseImage = QImage()

                image = QImage(obverseImage.width() + reverseImage.width(),
                               height, QImage.Format_RGB32)
                image.fill(QColor(Qt.white).rgb())

                paint = QPainter(image)
                if is_obverse_present and is_obverse_enabled:
                    paint.drawImage(
                        QtCore.QRectF(0, 0, obverseImage.width(), height),
                        obverseImage,
                        QtCore.QRectF(0, 0, obverseImage.width(), height))
                if is_reverse_present and is_reverse_enabled:
                    paint.drawImage(
                        QtCore.QRectF(obverseImage.width(), 0,
                                      reverseImage.width(), height),
                        reverseImage,
                        QtCore.QRectF(0, 0, reverseImage.width(), height))
                paint.end()

                ba = QtCore.QByteArray()
                buffer = QtCore.QBuffer(ba)
                buffer.open(QtCore.QIODevice.WriteOnly)

                # Store as PNG for better view
                image.save(buffer, 'png')
                dest_record.setValue('image', ba)

            dest_model.insertRecord(-1, dest_record)

        progressDlg.setLabelText(self.tr("Saving..."))
        dest_model.submitAll()

        progressDlg.setLabelText(self.tr("Compact..."))
        QSqlQuery(
            """UPDATE coins
SET
  reverseimg = (select t2.id from coins t3 join (select id, image from photos group by image having count(*) > 1) t2 on t1.image = t2.image join photos t1 on t3.reverseimg = t1.id where t1.id <> t2.id and t3.id = coins.id)
WHERE coins.id in (select t3.id from coins t3 join (select id, image from photos group by image having count(*) > 1) t2 on t1.image = t2.image join photos t1 on t3.reverseimg = t1.id where t1.id <> t2.id)
""", db)
        QSqlQuery(
            """UPDATE coins
SET
  obverseimg = (select t2.id from coins t3 join (select id, image from photos group by image having count(*) > 1) t2 on t1.image = t2.image join photos t1 on t3.obverseimg = t1.id where t1.id <> t2.id and t3.id = coins.id)
WHERE coins.id in (select t3.id from coins t3 join (select id, image from photos group by image having count(*) > 1) t2 on t1.image = t2.image join photos t1 on t3.obverseimg = t1.id where t1.id <> t2.id)
""", db)

        QSqlQuery(
            """DELETE FROM photos
            WHERE id NOT IN (SELECT id FROM photos GROUP BY image)""", db)

        db.close()

        progressDlg.setLabelText(self.tr("Vacuum..."))
        db = QSqlDatabase.addDatabase('QSQLITE', 'mobile')
        db.setDatabaseName(params['file'])
        db.open()
        QSqlQuery("VACUUM", db)
        db.close()

        progressDlg.reset()
 def setSize(self, width, height):
     self.prepareGeometryChange()
     self.BoundingRect = QtCore.QRectF(0, 0, width * 3.75, height * 3.75)
     self.width = width
     self.height = height
 def setSize(self, width, height, xoff=0, yoff=0):
     self.prepareGeometryChange()
     self.BoundingRect = QtCore.QRectF(0, 0, width, height)
     self.setPos(xoff, yoff)
     self.width = width
     self.height = height
Esempio n. 4
0
 def hide(self):
     """
     Reset the rect and hide
     """
     self._rect = QtCore.QRectF(0, 0, 0, 0)
     super().hide()
Esempio n. 5
0
    def resize(self, mousePos):
        """
        Handle the interactive resize of the shape.
        :type mousePos: QtCore.QPointF
        """
        snap = self.session.action('toggle_grid').isChecked()
        size = self.diagram.GridSize
        moved = self.label.isMoved()

        background = self.background.geometry()
        selection = self.selection.geometry()
        polygon = self.polygon.geometry()

        R = QtCore.QRectF(self.boundingRect())
        D = QtCore.QPointF(0, 0)

        mbrh = 58
        mbrw = 78

        self.prepareGeometryChange()

        if self.mp_Handle == self.HandleTL:

            fromX = self.mp_Bound.left()
            fromY = self.mp_Bound.top()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, -4, snap)
            toY = snapF(toY, size, -4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setLeft(toX)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    R.top())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexB].y())
            selection[self.IndexL] = QtCore.QPointF(R.left(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(R.left(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                     R.top())
            background[self.IndexB] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexB].y())
            background[self.IndexL] = QtCore.QPointF(R.left(),
                                                     R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(R.left(),
                                                     R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  R.top() + 4)
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexB].y())
            polygon[self.IndexL] = QtCore.QPointF(R.left() + 4,
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(R.left() + 4,
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleTM:

            fromY = self.mp_Bound.top()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toY = snapF(toY, size, -4, snap)
            D.setY(toY - fromY)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(selection[self.IndexT].x(),
                                                    R.top())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                background[self.IndexT].x(), R.top())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(polygon[self.IndexT].x(),
                                                  R.top() + 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleTR:

            fromX = self.mp_Bound.right()
            fromY = self.mp_Bound.top()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, +4, snap)
            toY = snapF(toY, size, -4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setRight(toX)
            R.setTop(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())
            if R.height() < mbrh:
                D.setY(D.y() - mbrh + R.height())
                R.setTop(R.top() - mbrh + R.height())

            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    R.top())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexB].y())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(R.right(),
                                                    R.top() + R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                     R.top())
            background[self.IndexB] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexB].y())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(R.right(),
                                                     R.top() + R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  R.top() + 4)
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexB].y())
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(R.right() - 4,
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleML:

            fromX = self.mp_Bound.left()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toX = snapF(toX, size, -4, snap)
            D.setX(toX - fromX)
            R.setLeft(toX)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())

            selection[self.IndexL] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexB].y())

            background[self.IndexL] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                R.left(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexT] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexB].y())

            polygon[self.IndexL] = QtCore.QPointF(
                R.left() + 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(
                R.left() + 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexB].y())

        elif self.mp_Handle == self.HandleMR:

            fromX = self.mp_Bound.right()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toX = snapF(toX, size, +4, snap)
            D.setX(toX - fromX)
            R.setRight(toX)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())

            selection[self.IndexR] = QtCore.QPointF(
                R.right(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexB].y())

            background[self.IndexR] = QtCore.QPointF(
                R.right(),
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            background[self.IndexT] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexB].y())

            polygon[self.IndexR] = QtCore.QPointF(
                R.right() - 4,
                self.mp_Bound.top() + self.mp_Bound.height() / 2)
            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexB].y())

        elif self.mp_Handle == self.HandleBL:

            fromX = self.mp_Bound.left()
            fromY = self.mp_Bound.bottom()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, -4, snap)
            toY = snapF(toY, size, +4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setLeft(toX)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() - mbrw + R.width())
                R.setLeft(R.left() - mbrw + R.width())
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(
                selection[self.IndexR].x(),
                R.bottom() - R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                R.left() + R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                     R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                R.left(),
                R.bottom() - R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.bottom() - R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.left() + R.width() / 2,
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(R.left() + 4,
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(R.left() + 4,
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.bottom() - R.height() / 2)

        elif self.mp_Handle == self.HandleBM:

            fromY = self.mp_Bound.bottom()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toY = snapF(toY, size, +4, snap)
            D.setY(toY - fromY)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexB] = QtCore.QPointF(selection[self.IndexB].x(),
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(selection[self.IndexL].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(selection[self.IndexE].x(),
                                                    R.top() + R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(selection[self.IndexR].x(),
                                                    R.top() + R.height() / 2)

            background[self.IndexB] = QtCore.QPointF(
                background[self.IndexB].x(), R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.top() + R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.top() + R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                background[self.IndexR].x(),
                R.top() + R.height() / 2)

            polygon[self.IndexB] = QtCore.QPointF(polygon[self.IndexB].x(),
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.top() + R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(polygon[self.IndexR].x(),
                                                  R.top() + R.height() / 2)

        elif self.mp_Handle == self.HandleBR:

            fromX = self.mp_Bound.right()
            fromY = self.mp_Bound.bottom()
            toX = fromX + mousePos.x() - self.mp_Pos.x()
            toY = fromY + mousePos.y() - self.mp_Pos.y()
            toX = snapF(toX, size, +4, snap)
            toY = snapF(toY, size, +4, snap)
            D.setX(toX - fromX)
            D.setY(toY - fromY)
            R.setRight(toX)
            R.setBottom(toY)

            ## CLAMP SIZE
            if R.width() < mbrw:
                D.setX(D.x() + mbrw - R.width())
                R.setRight(R.right() + mbrw - R.width())
            if R.height() < mbrh:
                D.setY(D.y() + mbrh - R.height())
                R.setBottom(R.bottom() + mbrh - R.height())

            selection[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    selection[self.IndexT].y())
            selection[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                    R.bottom())
            selection[self.IndexL] = QtCore.QPointF(
                selection[self.IndexL].x(),
                R.bottom() - R.height() / 2)
            selection[self.IndexE] = QtCore.QPointF(
                selection[self.IndexE].x(),
                R.bottom() - R.height() / 2)
            selection[self.IndexR] = QtCore.QPointF(
                R.right(),
                R.bottom() - R.height() / 2)

            background[self.IndexT] = QtCore.QPointF(
                R.right() - R.width() / 2, background[self.IndexT].y())
            background[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                     R.bottom())
            background[self.IndexL] = QtCore.QPointF(
                background[self.IndexL].x(),
                R.bottom() - R.height() / 2)
            background[self.IndexE] = QtCore.QPointF(
                background[self.IndexE].x(),
                R.bottom() - R.height() / 2)
            background[self.IndexR] = QtCore.QPointF(
                R.right(),
                R.bottom() - R.height() / 2)

            polygon[self.IndexT] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  polygon[self.IndexT].y())
            polygon[self.IndexB] = QtCore.QPointF(R.right() - R.width() / 2,
                                                  R.bottom() - 4)
            polygon[self.IndexL] = QtCore.QPointF(polygon[self.IndexL].x(),
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexE] = QtCore.QPointF(polygon[self.IndexE].x(),
                                                  R.bottom() - R.height() / 2)
            polygon[self.IndexR] = QtCore.QPointF(R.right() - 4,
                                                  R.bottom() - R.height() / 2)

        self.background.setGeometry(background)
        self.selection.setGeometry(selection)
        self.polygon.setGeometry(polygon)

        self.updateNode(selected=True,
                        handle=self.mp_Handle,
                        anchors=(self.mp_Data, D))
        self.updateTextPos(moved=moved)
Esempio n. 6
0
 def getRectFromLine(self, pt1, pt2):
     x1, y1 = pt1.x(), pt1.y()
     x2, y2 = pt2.x(), pt2.y()
     return QtCore.QRectF(x1, y1, x2 - x1, y2 - y1)
Esempio n. 7
0
 def boundingRect(self):
     tl = QtCore.QPointF(self.xmin, self.ymin)
     br = QtCore.QPointF(self.xmax, self.ymax)
     return QtCore.QRectF(tl, br)
Esempio n. 8
0
 def boundingRect(self):
     return QtCore.QRectF(self.rect)
Esempio n. 9
0
 def Priosimulation(self):
     FullProject.preemptive_priority(int(self.ProcessNoText.text()))
     averagetime = FullProject.averagetime(int(self.ProcessNoText.text()))
     print(averagetime)
     self.WaitingTime_display.display(averagetime)
     for i in range(len(FullProject.SJprecurrent_running)):
         if FullProject.current_running[i] != "IDLE":
             FullProject.current_running[i] = "IDLE"
         else:
             FullProject.current_running[i] = "P" + str(
                 FullProject.current_running[i])
     print(FullProject.current_running)
     arr2 = []
     lastdone = FullProject.current_running[0]
     arr2.append(lastdone)
     for i in range(len(FullProject.current_running)):
         if FullProject.current_running[i] != lastdone:
             arr2.append(FullProject.current_running[i])
             lastdone = FullProject.current_running[i]
     print(arr2)
     burst = []
     jstart = 0
     for i in range(len(arr2)):
         searchn = arr2[i]
         burstno = 0
         index = 0
         for j in range(jstart, len(FullProject.current_running)):
             if FullProject.current_running[j] == searchn:
                 burstno += 1
             else:
                 break
         jstart = jstart + burstno
         burst.append(burstno)
     print(burst)
     SJFdep = []
     depsum = 0
     for i in range(len(arr2)):
         depsum = depsum + burst[i]
         SJFdep.append(depsum)
     arr = SJFdep
     scene = QtWidgets.QGraphicsScene()
     self.graphicsView.setScene(scene)
     pen = QtGui.QPen(QtCore.Qt.black, 3)
     brush = QtGui.QBrush(QtCore.Qt.lightGray)
     print(arr)
     print(arr2)
     print(burst)
     n = len(arr)
     next = 0
     for i in range(n):
         if burst[i] < 3:
             m = 20 * burst[i]
         elif burst[i] < 5:
             m = 10 * burst[i]
         else:
             m = burst[i]
         if i == 0:
             r = QtCore.QRectF(QtCore.QPointF(10, 0),
                               QtCore.QSizeF(m * burst[i], 80))
             scene.addRect(r, pen, brush)
             next = r.right()
             mytext1 = QGraphicsSimpleTextItem(str(arr2[i]))
             scene.addItem(mytext1)
             mytext1.setPos((next - burst[i] - 18), 30)
             mytext1.setScale(1.5)
             mytext2 = QGraphicsSimpleTextItem(str(arr[i]))
             scene.addItem(mytext2)
             mytext2.setPos(m * burst[i], 85)
             mytext2.setScale(1.3)
         else:
             r = QtCore.QRectF(QtCore.QPointF(next, 0),
                               QtCore.QSizeF(m * burst[i], 80))
             scene.addRect(r, pen, brush)
             mytext1 = QGraphicsSimpleTextItem(str(arr2[i]))
             scene.addItem(mytext1)
             mytext1.setPos(burst[i] + next, 30)
             mytext1.setScale(1.5)
             mytext2 = QGraphicsSimpleTextItem(str(arr[i]))
             scene.addItem(mytext2)
             mytext2.setPos(m * burst[i] + next, 85)
             mytext2.setScale(1.3)
             next = r.right()
Esempio n. 10
0
    def mousePressEvent(self, event):
        # Record mouse position.
        sceneRect = self.scene.sceneRect()

        # When pressed, snap to area within scene.
        globalX, globalY = self.keepMouseInBounds(event)
        if globalX is not None and globalY is not None:
            mousePos = self.mapToScene(
                self.mapFromGlobal(QtCore.QPoint(globalX, globalY)))
        elif globalX is not None:
            mousePos = self.mapToScene(
                self.mapFromGlobal(
                    QtCore.QPoint(globalX, self.mapToGlobal(event.y()))))
        elif globalY is not None:
            mousePos = self.mapToScene(
                self.mapFromGlobal(
                    QtCore.QPoint(self.mapToGlobal(event.x()), globalY)))
        else:
            mousePos = self.mapToScene(event.pos())

        # Initialise drag tracking for squares already created.
        self.dragging = False
        # Check leftbutton click:
        if event.button() == QtCore.Qt.LeftButton:
            try:
                # Check if click inside previously defined rectangle.
                if self.rect_item.mapRectToScene(
                        self.rect_item.boundingRect()).contains(mousePos):
                    self.dragging = True
                else:
                    self.dragging = False
            except AttributeError:
                self.dragging = False
                self.pressLoc = mousePos

            # Track mouse movement for drag / rectangle creation.
            self.setMouseTracking(True)

            # Process start locations for dragging / rectangle creation
            if self.dragging:
                self.dragLoc = mousePos
                print("Dragged from " + str(self.dragLoc))
            else:
                # New event, remove previous rect:
                try:
                    self.scene.removeItem(self.rect_item)
                except AttributeError:
                    pass
                self.pressLoc = mousePos
                self.rect_item = QtWidgets.QGraphicsRectItem(
                    QtCore.QRectF(self.pressLoc.x(), self.pressLoc.y(), 0, 0))
                self.scene.addItem(self.rect_item)
                print("Pressed at " + str(self.pressLoc))

        # Process right button click:
        elif event.button() == QtCore.Qt.RightButton:
            # Remove rectangle, reset drag.
            try:
                self.scene.removeItem(self.rect_item)
                self.dragging = False
                self.rectangleCleared.emit(self)
            except AttributeError:
                pass
        super(QtWidgets.QGraphicsView, self).mousePressEvent(event)
Esempio n. 11
0
 def boundingRect(self):
     return QtCore.QRectF(0, 0, self.width, self.height) 
Esempio n. 12
0
    def update_labels_pixmap(self, freq_list):
        labels_pixmaps_h_black = []
        labels_pixmaps_h_white = []
        labels_pixmaps_v_black = []
        labels_pixmaps_v_white = []

        w = h = 1
        test_pixmap = QtGui.QPixmap(w, h)
        test_pixmap.fill()
        test_painter = QtGui.QPainter(test_pixmap)
        f_rect = QtCore.QRectF(0, 0, w, h)

        transparent_color = QtGui.QColor(0, 0, 0, 0)

        for f in freq_list:
            # first, find the right pixmap size
            boundary_rect = test_painter.boundingRect(f_rect, Qt.Qt.AlignLeft,
                                                      f)

            # second, create the pixmap with the right size
            pixmap = QtGui.QPixmap(boundary_rect.width(),
                                   boundary_rect.height())
            pixmap.fill(transparent_color)  # transparent background
            painter = QtGui.QPainter(pixmap)
            painter.setPen(QtCore.Qt.black)
            painter.drawText(boundary_rect, Qt.Qt.AlignLeft, f)
            labels_pixmaps_h_black += [pixmap]

            pixmap = QtGui.QPixmap(boundary_rect.width(),
                                   boundary_rect.height())
            pixmap.fill(transparent_color)  # transparent background
            painter = QtGui.QPainter(pixmap)
            painter.setPen(QtCore.Qt.white)
            painter.drawText(boundary_rect, Qt.Qt.AlignLeft, f)
            labels_pixmaps_h_white += [pixmap]

        angle = -90
        for pix in labels_pixmaps_h_black:
            pixmap = QtGui.QPixmap(pix.height(), pix.width())
            pixmap.fill(transparent_color)  # transparent background
            painter = QtGui.QPainter(pixmap)
            painter.rotate(angle)
            painter.drawPixmap(-pix.width(), 0, pix)
            labels_pixmaps_v_black += [pixmap]

        for pix in labels_pixmaps_h_white:
            pixmap = QtGui.QPixmap(pix.height(), pix.width())
            pixmap.fill(transparent_color)  # transparent background
            painter = QtGui.QPainter(pixmap)
            painter.rotate(angle)
            painter.drawPixmap(-pix.width(), 0, pix)
            labels_pixmaps_v_white += [pixmap]

        test_painter.end()  # manually ends painting to satisfy Qt

        self.pix_h_widths = array(
            [pix.width() for pix in labels_pixmaps_h_white])
        self.max_label_pix_h_width = max(self.pix_h_widths)
        self.pix_h_heights = array(
            [pix.height() for pix in labels_pixmaps_h_white])

        self.pix_v_widths = array(
            [pix.width() for pix in labels_pixmaps_v_white])
        self.max_label_pix_v_width = max(self.pix_v_widths)
        self.pix_v_heights = array(
            [pix.height() for pix in labels_pixmaps_v_white])

        self.h_pixmaps = [[pix_white, pix_black]
                          for pix_white, pix_black in zip(
                              labels_pixmaps_h_white, labels_pixmaps_h_black)]

        self.v_pixmaps = [[pix_white, pix_black]
                          for pix_white, pix_black in zip(
                              labels_pixmaps_v_white, labels_pixmaps_v_black)]
Esempio n. 13
0
 def draw_text(self, painter):
     painter.drawText(QtCore.QRectF(0, 0, self.width, self.height),
                      QtCore.Qt.AlignCenter, self.text)
Esempio n. 14
0
 def boundingRect(self):
     return QtCore.QRectF(0, 0, 1, 1)
Esempio n. 15
0
 def end_loading(self, new_scene: qw.QGraphicsScene):
     self.setScene(new_scene)
     self._is_loading = False
     self.buffer_scene_rect()
     self.scene().invalidate(qc.QRectF(), qw.QGraphicsScene.AllLayers)
Esempio n. 16
0
    def draw_view_from_cartesian(self, graphics: QtWidgets.QGraphicsView,
                                 spin_boxes: QtWidgets.QDoubleSpinBox, *args):
        """
        This method perform the calculations need to draw the arm preview. This
        calculations are made from the cartesian coordinates selected by the user and by using
        the inverse kinematics model

        :param graphics: List of graphic views widgets.
        :param spin_boxes: List of spinboxes widgets.
        """
        x_coord, y_coord, z_coord = spin_boxes[0].value(), \
                                    spin_boxes[1].value(), \
                                    spin_boxes[2].value()

        angles = inverse_kinematics(x_coord, y_coord, z_coord)

        if angles:
            t0, t1, t2 = angles
            if not self.check_list(t0, t1, t2, x_coord, y_coord, z_coord):
                pen1 = pyqtgraph.mkPen(color=(255, 0, 0),
                                       width=8,
                                       style=QtCore.Qt.SolidLine)
                pen2 = pyqtgraph.mkPen(color=(255, 0, 0),
                                       width=8,
                                       style=QtCore.Qt.SolidLine)
                self.disable_execute_button(False)
            else:
                pen1 = pyqtgraph.mkPen(color=(0, 240, 0),
                                       width=8,
                                       style=QtCore.Qt.SolidLine)
                pen2 = pyqtgraph.mkPen(color=(0, 220, 215),
                                       width=8,
                                       style=QtCore.Qt.SolidLine)
                self.disable_execute_button(True)

            math_trans = math.pi / 180
            x_coord1 = 142.07 * math.cos((135 - t1) * math_trans)
            x_coord2  = x_coord1 + 158.08 * \
                        math.cos((180 - (135 - t1) - t2) * math_trans)
            z_coord1 = 142.07 * math.sin((135 - t1) * math_trans)
            z_coord2  = z_coord1 - 158.08 * \
                        math.sin((180 - (135 - t1) - t2) * math_trans)

            mid_x = x_coord1 * math.sin(t0 * math_trans)
            mid_y = x_coord1 * math.cos(t0 * math_trans)

            graphics[0].clear()
            rect_item = RectItem(QtCore.QRectF(-53.05, -53.05, 106.1, 106.1))
            graphics[0].addItem(rect_item)

            # Upper arm above Lower arm
            if z_coord2 > z_coord1 and x_coord2 > x_coord1:
                graphics[0].plot((0, mid_y), (0, mid_x),
                                 pen=pen1,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')
                graphics[0].plot((mid_y, y_coord), (mid_x, x_coord),
                                 pen=pen2,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')
            # Lowe arm above Upper arm
            elif z_coord2 < z_coord1 and x_coord2 < x_coord1:
                graphics[0].plot((mid_y, y_coord), (mid_x, x_coord),
                                 pen=pen1,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')
                graphics[0].plot((0, mid_y), (0, mid_x),
                                 pen=pen1,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')
            # neutral position
            else:
                graphics[0].plot((0, mid_y), (0, mid_x),
                                 pen=pen1,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')
                graphics[0].plot((mid_y, y_coord), (mid_x, x_coord),
                                 pen=pen2,
                                 symbol='o',
                                 symbolSize=15,
                                 symbolBrush='b')

            graphics[1].clear()
            rect_item2 = RectItem(QtCore.QRectF(-60, -133.2, 120, 113.2))
            rect_item3 = RectItem(QtCore.QRectF(-36, -20, 72, 20))
            graphics[1].addItem(rect_item2)
            graphics[1].addItem(rect_item3)
            graphics[1].plot((0, x_coord1), (0, z_coord1),
                             pen=pen1,
                             symbol='o',
                             symbolSize=15,
                             symbolBrush='b')
            graphics[1].plot((x_coord1, x_coord2), (z_coord1, z_coord2),
                             pen=pen2,
                             symbol='o',
                             symbolSize=15,
                             symbolBrush='b')
Esempio n. 17
0
    def iconFor(self, item):
        """
        Returns the appropriate icon for the given item.
        :type item: Item
        :rtype: QtGui.QIcon
        """
        icon = QtGui.QIcon()

        for i in (1.0, 2.0):

            pixmap = QtGui.QPixmap(60 * i, 44 * i)
            pixmap.setDevicePixelRatio(i)
            pixmap.fill(QtCore.Qt.transparent)

            #############################################
            # CONCEPT NODE
            #################################

            if item is Item.ConceptNode:
                painter = QtGui.QPainter(pixmap)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-27, -17, 54, 34))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-27, -17, 54, 34),
                                 QtCore.Qt.AlignCenter, 'concept')
                painter.end()

            #############################################
            # ROLE NODE
            #################################

            elif item is Item.RoleNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(0, +17),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(0, -17),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -17, 46, 34),
                                 QtCore.Qt.AlignCenter, 'role')
                painter.end()

            #############################################
            # ATTRIBUTE NODE
            #################################

            elif item is Item.AttributeNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'attribute')
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 30)
                painter.drawEllipse(QtCore.QRectF(-9, -9, 18, 18))
                painter.end()

            #############################################
            # VALUE-DOMAIN NODE
            #################################

            elif item is Item.ValueDomainNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRoundedRect(QtCore.QRectF(-27, -17, 54, 34), 6, 6)
                painter.setFont(Font('Roboto', 10, Font.Light))
                painter.drawText(QtCore.QRectF(-27, -17, 54, 34),
                                 QtCore.Qt.AlignCenter, 'xsd:string')
                painter.end()

            #############################################
            # INDIVIDUAL NODE
            #################################

            elif item is Item.IndividualNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-20, -((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(-20, +((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(-((40 / (1 + sqrt(2))) / 2), +20),
                        QtCore.QPointF(+((40 / (1 + sqrt(2))) / 2), +20),
                        QtCore.QPointF(+20, +((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(+20, -((40 / (1 + sqrt(2))) / 2)),
                        QtCore.QPointF(+((40 / (1 + sqrt(2))) / 2), -20),
                        QtCore.QPointF(-((40 / (1 + sqrt(2))) / 2), -20),
                        QtCore.QPointF(-20, -((40 / (1 + sqrt(2))) / 2)),
                    ]))
                painter.setFont(
                    Font('Roboto', 8 if self.isHDPI() else 9, Font.Light))
                painter.drawText(-16 if self.isHDPI() else -18, 4,
                                 'individual')
                painter.end()

            #############################################
            # FACET NODE
            #################################

            elif item is Item.FacetNode:

                polygonA = QtGui.QPolygonF([
                    QtCore.QPointF(-54 / 2 + 4, -32 / 2),
                    QtCore.QPointF(+54 / 2, -32 / 2),
                    QtCore.QPointF(+54 / 2 - 4 / 2, 0),
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                    QtCore.QPointF(-54 / 2 + 4, -32 / 2),
                ])
                polygonB = QtGui.QPolygonF([
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                    QtCore.QPointF(+54 / 2 - 4 / 2, 0),
                    QtCore.QPointF(+54 / 2 - 4, +32 / 2),
                    QtCore.QPointF(-54 / 2, +32 / 2),
                    QtCore.QPointF(-54 / 2 + 4 / 2, 0),
                ])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.setBrush(QtGui.QBrush(QtGui.QColor(222, 222, 222,
                                                           255)))
                painter.drawPolygon(polygonA)
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.drawPolygon(polygonB)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.drawText(QtCore.QPointF(-19 if _MACOS else -20, -5),
                                 Facet.length.value)
                painter.drawText(QtCore.QPointF(-8, 12), '"32"')
                painter.end()

            #############################################
            # DOMAIN RESTRICTION NODE
            #################################

            elif item is Item.DomainRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'restriction')
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-18 / 2, -18 / 2 + 6, 18, 18))
                painter.end()

            #############################################
            # RANGE RESTRICTION NODE
            #################################

            elif item is Item.RangeRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.translate(0, 0)
                painter.drawText(QtCore.QRectF(0, 0, 60, 22),
                                 QtCore.Qt.AlignCenter, 'restriction')
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.translate(30, 22)
                painter.drawRect(QtCore.QRectF(-18 / 2, -18 / 2 + 6, 18, 18))
                painter.end()

            #############################################
            # INTERSECTION NODE
            #################################

            elif item is Item.IntersectionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'and')
                painter.end()

            #############################################
            # ROLE CHAIN NODE
            #################################

            elif item is Item.RoleChainNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'chain')
                painter.end()

            #############################################
            # DATATYPE RESTRICTION NODE
            #################################

            elif item is Item.DatatypeRestrictionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'data')
                painter.end()

            #############################################
            # ROLE INVERSE NODE
            #################################

            elif item is Item.RoleInverseNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'inv')
                painter.end()

            #############################################
            # COMPLEMENT NODE
            #################################

            elif item is Item.ComplementNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'not')
                painter.end()

            #############################################
            # ENUMERATION NODE
            #################################

            elif item is Item.EnumerationNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'oneOf')
                painter.end()

            #############################################
            # UNION NODE
            #################################

            elif item is Item.UnionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.setFont(Font('Roboto', 11, Font.Light))
                painter.drawText(QtCore.QRectF(-23, -15, 46, 30),
                                 QtCore.Qt.AlignCenter, 'or')
                painter.end()

            #############################################
            # DISJOINT-UNION NODE
            #################################

            elif item is Item.DisjointUnionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.translate(30, 22)
                painter.drawPolygon(
                    QtGui.QPolygonF([
                        QtCore.QPointF(-23, 0),
                        QtCore.QPointF(-23 + 6, +15),
                        QtCore.QPointF(+23 - 6, +15),
                        QtCore.QPointF(+23, 0),
                        QtCore.QPointF(+23 - 6, -15),
                        QtCore.QPointF(-23 + 6, -15),
                        QtCore.QPointF(-23, 0),
                    ]))
                painter.end()

            #############################################
            # PROPERTY ASSERTION NODE
            #################################

            elif item is Item.PropertyAssertionNode:

                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.0,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.translate(30, 22)
                painter.drawRoundedRect(QtCore.QRectF(-23, -15, 46, 30), 14,
                                        14)
                painter.end()

            #############################################
            # INCLUSION EDGE
            #################################

            elif item is Item.InclusionEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.end()

            #############################################
            # EQUIVALENCE EDGE
            #################################

            elif item is Item.EquivalenceEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x(), L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                P1 = QtCore.QPointF(L1.p1().x(), L1.p1().y())
                P2 = P1 + QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 + QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                T1 = QtGui.QPolygonF([P1, P2, P3])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.drawPolygon(T1)
                painter.end()

            #############################################
            # INPUT EDGE
            #################################

            elif item is Item.InputEdge:

                P1 = QtCore.QPointF(3, 22)
                P2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(P1, P2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 4.0) * 8,
                    cos(A1 + M_PI / 4.0) * 8)
                P3 = P2 - QtCore.QPointF(
                    sin(A1 + 3.0 / 4.0 * M_PI) * 8,
                    cos(A1 + 3.0 / 4.0 * M_PI) * 8)
                p4 = P3 - QtCore.QPointF(
                    sin(A1 - 3.0 / 4.0 * M_PI) * 8,
                    cos(A1 - 3.0 / 4.0 * M_PI) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3, p4])
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                pen = QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                                 QtCore.Qt.CustomDashLine, QtCore.Qt.RoundCap,
                                 QtCore.Qt.RoundJoin)
                pen.setDashPattern([3, 3])
                painter.setPen(pen)
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(252, 252, 252,
                                                           255)))
                painter.drawPolygon(H1)
                painter.end()

            #############################################
            # MEMBERSHIP EDGE
            #################################

            elif item is Item.MembershipEdge:

                PP1 = QtCore.QPointF(2, 22)
                PP2 = QtCore.QPointF(55, 22)
                L1 = QtCore.QLineF(PP1, PP2)
                A1 = L1.angle()
                P1 = QtCore.QPointF(L1.p2().x() + 2, L1.p2().y())
                P2 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI / 3.0) * 8,
                    cos(A1 + M_PI / 3.0) * 8)
                P3 = P1 - QtCore.QPointF(
                    sin(A1 + M_PI - M_PI / 3.0) * 8,
                    cos(A1 + M_PI - M_PI / 3.0) * 8)
                H1 = QtGui.QPolygonF([P1, P2, P3])
                S1 = 2 if _MACOS else 0
                painter = QtGui.QPainter(pixmap)
                painter.setRenderHint(QtGui.QPainter.Antialiasing)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.drawLine(L1)
                painter.setPen(
                    QtGui.QPen(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)), 1.1,
                               QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))
                painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 0, 0, 255)))
                painter.drawPolygon(H1)
                painter.setFont(Font('Roboto', 9, Font.Light))
                painter.drawText(PP1.x() + S1, 18, 'instanceOf')
                painter.end()

            #############################################
            # ADD THE GENERATED PIXMAP TO THE ICON
            #################################

            icon.addPixmap(pixmap)

        return icon
Esempio n. 18
0
 def paintEvent(self, event: QtGui.QPaintEvent):
     if self.height() > 0 and self.width() > 0:
         painter = QtGui.QPainter(self)
         path = QtGui.QPainterPath()
         path2 = QtGui.QPainterPath()
         pen = QtGui.QPen(QtCore.Qt.NoPen)
         
         painter.setPen(pen)
         painter.setRenderHint(QtGui.QPainter.HighQualityAntialiasing)
         widthDistance = self.width() - self.height()
         
         if not self.isAnimationScheduled:
             if self.isChecked():
                 if self.buttonForegroundColor.alpha() < 255:
                     self.buttonForegroundColor.setAlpha(255)
             
             else:
                 if self.buttonForegroundColor.alpha() > 0:
                     self.buttonForegroundColor.setAlpha(0)
             
             if not self.isCircular():
                 painter.fillRect(self.rect(), self.buttonBackgroundColor)
                 painter.fillRect(self.rect(), self.buttonForegroundColor)
             
             elif self.isCircular():
                 path.addRoundedRect(QtCore.QRectF(self.rect()), self.RoundedRadius, self.height())
                 painter.fillPath(path, self.buttonBackgroundColor)
                 painter.fillPath(path, self.buttonForegroundColor)
             
             if self.isChecked():
                 switch_rect = QtCore.QRect(
                     widthDistance + self.ButtonPadding,  # X Position
                     self.ButtonPadding,  # Y Position
                     widthDistance - self.ButtonPadding * 2,  # Width
                     self.height() - self.ButtonPadding * 2  # Height
                 )
             
             else:
                 switch_rect = QtCore.QRect(
                     self.ButtonPadding,  # X Position
                     self.ButtonPadding,  # Y Position
                     widthDistance - self.ButtonPadding * 2,  # Width
                     self.height() - self.ButtonPadding * 2  # Height
                 )
             
             if not self.isCircular():
                 painter.fillRect(switch_rect, self.buttonColor)
             
             elif self.isCircular():
                 path2.addEllipse(QtCore.QRectF(
                     self.buttonXOffset,
                     self.ButtonPadding,
                     self.height() - self.ButtonPadding * 2,
                     self.height() - self.ButtonPadding * 2
                 ))
                 
                 painter.fillPath(path2, self.buttonColor)
                 painter.drawPath(path2)
         
         else:
             if self.buttonXOffset >= (widthDistance + self.ButtonPadding) \
                     or self.buttonXOffset <= self.ButtonPadding:
                 self.buttonForegroundColor.setAlpha(0 if self.isChecked() else 255)
             
             self.slideButton(painter)
             self.update()
Esempio n. 19
0
    def resizeEvent(self, e):
        # This ensures viewport resizes the scrollarea correctly.
        self.setSceneRect(QtCore.QRectF())

        self.itab.miniView.drawViewbox()
Esempio n. 20
0
 def slideButton(self, painter: QtGui.QPainter):
     if self.width() > 0 and self.height() > 0:
         path = QtGui.QPainterPath()
         path2 = QtGui.QPainterPath()
         
         widthDistance = self.width() - self.height()
         buttonXOffsetModifier = (widthDistance / self.width()) / 10
         alphaModifier = (1 / widthDistance) * buttonXOffsetModifier
         
         if self.isChecked():
             new_alpha = self.buttonForegroundColor.alphaF() + alphaModifier
             
             if new_alpha > 1:
                 new_alpha = 1
             
             self.buttonForegroundColor.setAlphaF(new_alpha)
             self.buttonXOffset += buttonXOffsetModifier
         
         else:
             new_alpha = self.buttonForegroundColor.alphaF() - alphaModifier
             
             if new_alpha < 0:
                 new_alpha = 0
             
             self.buttonForegroundColor.setAlphaF(new_alpha)
             self.buttonXOffset -= buttonXOffsetModifier
         
         if self.buttonXOffset >= (widthDistance + self.ButtonPadding) or self.buttonXOffset <= self.ButtonPadding:
             if self.buttonXOffset > (widthDistance + self.ButtonPadding):
                 self.buttonXOffset = widthDistance + self.ButtonPadding
             
             elif self.buttonXOffset < self.ButtonPadding:
                 self.buttonXOffset = self.ButtonPadding
             
             self.isAnimationScheduled = False
         
         else:
             if not self.isCircular():
                 painter.fillRect(self.rect(), self.buttonBackgroundColor)
                 painter.fillRect(self.rect(), self.buttonForegroundColor)
                 painter.fillRect(QtCore.QRect(
                     self.buttonXOffset,
                     self.ButtonPadding,
                     widthDistance - self.ButtonPadding * 2,
                     self.height() - self.ButtonPadding * 2
                 ), self.buttonColor)
             
             elif self.isCircular():
                 path.addRoundedRect(QtCore.QRectF(self.rect()), self.RoundedRadius, self.height() // 2)
                 painter.fillPath(path, self.buttonBackgroundColor)
                 painter.fillPath(path, self.buttonForegroundColor)
                 
                 path2.addEllipse(QtCore.QRectF(
                     self.buttonXOffset,
                     self.ButtonPadding,
                     self.height() - self.ButtonPadding * 2,
                     self.height() - self.ButtonPadding * 2
                 ))
                 
                 painter.fillPath(path2, self.buttonColor)
                 painter.drawPath(path)
Esempio n. 21
0
 def show(self):
     """
     Reset the maximum bounding rect and show
     """
     self._boundingRect = QtCore.QRectF(0, 0, 0, 0)
     super().show()
Esempio n. 22
0
 def boundingRect(self):
     return QtCore.QRectF(0,self.low,len(self.pictures),(self.high-self.low)) 
Esempio n. 23
0
 def __init__(self, parent=None):
     super().__init__(QtCore.QRectF(), parent)
     self.coords = None  #QtCore.QEvent()
Esempio n. 24
0
    def set_data(self, data, force=False, has_common_images=True):
        if not force and self.data == data and self.has_common_images == has_common_images:
            return

        self.data = data
        self.has_common_images = has_common_images

        if not force and self.parent().isHidden():
            return

        if not self.data:
            self.setPixmap(self.shadow)
            self.current_pixmap_key = None
            return

        if len(self.data) == 1:
            has_common_images = True

        w, h, displacements = self.scaled(128, 128, 20)
        key = hash(
            tuple(sorted(self.data, key=lambda x: x.types_as_string())) +
            (has_common_images, ))
        try:
            pixmap = self._pixmap_cache[key]
        except KeyError:
            if len(self.data) == 1:
                pixmap = QtGui.QPixmap()
                pixmap.loadFromData(self.data[0].data)
                pixmap = self.decorate_cover(pixmap)
            else:
                limited = len(self.data) > MAX_COVERS_TO_STACK
                if limited:
                    data_to_paint = data[:MAX_COVERS_TO_STACK - 1]
                    offset = displacements * len(data_to_paint)
                else:
                    data_to_paint = data
                    offset = displacements * (len(data_to_paint) - 1)
                stack_width, stack_height = (w + offset, h + offset)
                pixmap = QtGui.QPixmap(stack_width, stack_height)
                bgcolor = self.palette().color(QtGui.QPalette.Window)
                painter = QtGui.QPainter(pixmap)
                painter.fillRect(
                    QtCore.QRectF(0, 0, stack_width, stack_height), bgcolor)
                cx = stack_width - w // 2
                cy = h // 2
                if limited:
                    x, y = (cx - self.shadow.width() // 2,
                            cy - self.shadow.height() // 2)
                    for i in range(3):
                        painter.drawPixmap(x, y, self.shadow)
                        x -= displacements // 3
                        y += displacements // 3
                    cx -= displacements
                    cy += displacements
                else:
                    cx = stack_width - w // 2
                    cy = h // 2
                for image in reversed(data_to_paint):
                    if isinstance(image, QtGui.QPixmap):
                        thumb = image
                    else:
                        thumb = QtGui.QPixmap()
                        thumb.loadFromData(image.data)
                    thumb = self.decorate_cover(thumb)
                    x, y = (cx - thumb.width() // 2, cy - thumb.height() // 2)
                    painter.drawPixmap(x, y, thumb)
                    cx -= displacements
                    cy += displacements
                if not has_common_images:
                    color = QtGui.QColor("darkgoldenrod")
                    border_length = 10
                    for k in range(border_length):
                        color.setAlpha(255 - k * 255 // border_length)
                        painter.setPen(color)
                        painter.drawLine(x, y - k - 1, x + 121 + k + 1,
                                         y - k - 1)
                        painter.drawLine(x + 121 + k + 2, y - 1 - k,
                                         x + 121 + k + 2, y + 121 + 4)
                    for k in range(5):
                        bgcolor.setAlpha(80 + k * 255 // 7)
                        painter.setPen(bgcolor)
                        painter.drawLine(x + 121 + 2, y + 121 + 2 + k,
                                         x + 121 + border_length + 2,
                                         y + 121 + 2 + k)
                painter.end()
                pixmap = pixmap.scaled(w, h, QtCore.Qt.KeepAspectRatio,
                                       QtCore.Qt.SmoothTransformation)
            self._pixmap_cache[key] = pixmap

        pixmap.setDevicePixelRatio(self.pixel_ratio)
        self.setPixmap(pixmap)
        self.current_pixmap_key = key
Esempio n. 25
0
    def start_move(self, pos):
        try:
            if self.rect.contains(pos):
                top_left = self.rect.topLeft()
                # 1. calculate offset for choose borders
                self.selector_offsets = self.view.camera.to_scene(
                    self.view.camera.to_view(top_left) + QtCore.QPointF(
                        self.selector_size, self.selector_size)) - top_left

                top_left_rect = QtCore.QRectF(top_left.x(), top_left.y(),
                                              self.selector_offsets.x(),
                                              self.selector_offsets.y())
                if top_left_rect.contains(pos):
                    self.state = self.move_top_left
                    self.start_move_pos = pos
                    self.top_left = self.rect.topLeft()
                    return 1
                else:
                    top_right = self.rect.topRight()
                    top_right_rect = QtCore.QRectF(
                        top_right.x() - self.selector_offsets.x(),
                        top_left.y(), self.selector_offsets.x(),
                        self.selector_offsets.y())

                    if top_right_rect.contains(pos):
                        self.state = self.move_top_right
                        self.start_move_pos = pos
                        self.top_right = self.rect.topRight()
                        return 1
                    else:
                        bottom_left = self.rect.bottomLeft()
                        bottom_left_rect = QtCore.QRectF(
                            bottom_left.x(),
                            bottom_left.y() - self.selector_offsets.x(),
                            self.selector_offsets.x(),
                            self.selector_offsets.y())

                        if bottom_left_rect.contains(pos):
                            self.state = self.move_bottom_left
                            self.start_move_pos = pos
                            self.bottom_left = self.rect.bottomLeft()
                            return 1
                        else:
                            bottom_right = self.rect.bottomRight()
                            bottom_right_rect = QtCore.QRectF(
                                bottom_right.x() - self.selector_offsets.x(),
                                bottom_right.y() - self.selector_offsets.x(),
                                self.selector_offsets.x(),
                                self.selector_offsets.y())

                            if bottom_right_rect.contains(pos):
                                self.state = self.move_bottom_right
                                self.start_move_pos = pos
                                self.bottom_right = self.rect.bottomRight()
                                return 1
                            # move all
                            else:
                                self.state = self.move_state
                                self.start_move_pos = pos
                                self.top_left = self.rect.topLeft()

                                # get selected cell
                                width = self.rect.width() / self.columns
                                height = self.rect.height() / self.rows
                                pos = pos - self.rect.topLeft()
                                col = math.trunc(pos.x() / width)
                                row = math.trunc(pos.y() / height)
                                self.selected_cell = [col, row]
                                return 1
        finally:
            self.view.update()
Esempio n. 26
0
 def boundingRect(self):
     return QtCore.QRectF(self.picture.boundingRect())
Esempio n. 27
0
 def setSize(self, width, height, xoff=0, yoff=0):
     self.BoundingRect = QtCore.QRectF(0, 0, width, height)
     self.setPos(xoff, yoff)
Esempio n. 28
0
 def begin_loading(self):
     self._is_loading = True
     self.scene().invalidate(qc.QRectF(), qw.QGraphicsScene.AllLayers)
     qw.QApplication.processEvents()
Esempio n. 29
0
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(578, 564)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("../../../Icons/Base/Goblin.svg"),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        Dialog.setWindowIcon(icon)
        Dialog.setToolTip("")
        Dialog.setStyleSheet("")
        self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(370, 520, 161, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel
                                          | QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.graphic_background = QtWidgets.QGraphicsView(Dialog)
        self.graphic_background.setGeometry(QtCore.QRect(30, 25, 280, 425))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(65, 255, 240, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(65, 255, 240, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(240, 240, 240))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.graphic_background.setPalette(palette)
        self.graphic_background.setAcceptDrops(False)
        self.graphic_background.setToolTip("")
        self.graphic_background.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.graphic_background.setStyleSheet("font: 8pt \"HQModern\";")
        self.graphic_background.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.graphic_background.setFrameShadow(QtWidgets.QFrame.Plain)
        self.graphic_background.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphic_background.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphic_background.setInteractive(False)
        self.graphic_background.setAlignment(QtCore.Qt.AlignLeading
                                             | QtCore.Qt.AlignLeft
                                             | QtCore.Qt.AlignTop)
        self.graphic_background.setResizeAnchor(
            QtWidgets.QGraphicsView.AnchorUnderMouse)
        self.graphic_background.setObjectName("graphic_background")
        self.textEdit_name = QtWidgets.QTextEdit(Dialog)
        self.textEdit_name.setGeometry(QtCore.QRect(80, 38, 180, 29))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(140, 117, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(140, 117, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(240, 240, 240))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.textEdit_name.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("Gaze")
        font.setPointSize(18)
        self.textEdit_name.setFont(font)
        self.textEdit_name.setFocusPolicy(QtCore.Qt.WheelFocus)
        self.textEdit_name.setAutoFillBackground(False)
        self.textEdit_name.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.textEdit_name.setFrameShadow(QtWidgets.QFrame.Plain)
        self.textEdit_name.setLineWidth(-1)
        self.textEdit_name.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.textEdit_name.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.textEdit_name.setLineWrapColumnOrWidth(-4)
        self.textEdit_name.setObjectName("textEdit_name")
        self.graphicsView = QtWidgets.QGraphicsView(Dialog)
        self.graphicsView.setGeometry(QtCore.QRect(89, 68, 162, 189))
        self.graphicsView.setToolTipDuration(-1)
        self.graphicsView.setFrameShadow(QtWidgets.QFrame.Plain)
        self.graphicsView.setLineWidth(2)
        self.graphicsView.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphicsView.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.graphicsView.setSizeAdjustPolicy(
            QtWidgets.QAbstractScrollArea.AdjustToContents)
        self.graphicsView.setSceneRect(QtCore.QRectF(0.0, 0.0, 162.0, 189.0))
        self.graphicsView.setAlignment(QtCore.Qt.AlignLeading
                                       | QtCore.Qt.AlignLeft
                                       | QtCore.Qt.AlignTop)
        self.graphicsView.setObjectName("graphicsView")
        self.label_move = QtWidgets.QLabel(Dialog)
        self.label_move.setGeometry(QtCore.QRect(62, 260, 57, 16))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.label_move.setFont(font)
        self.label_move.setFocusPolicy(QtCore.Qt.NoFocus)
        self.label_move.setAlignment(QtCore.Qt.AlignCenter)
        self.label_move.setObjectName("label_move")
        self.label_at = QtWidgets.QLabel(Dialog)
        self.label_at.setGeometry(QtCore.QRect(110, 260, 41, 16))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.label_at.setFont(font)
        self.label_at.setAlignment(QtCore.Qt.AlignCenter)
        self.label_at.setObjectName("label_at")
        self.label_de = QtWidgets.QLabel(Dialog)
        self.label_de.setGeometry(QtCore.QRect(150, 260, 41, 16))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.label_de.setFont(font)
        self.label_de.setAlignment(QtCore.Qt.AlignCenter)
        self.label_de.setObjectName("label_de")
        self.label_bp = QtWidgets.QLabel(Dialog)
        self.label_bp.setGeometry(QtCore.QRect(190, 260, 41, 16))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.label_bp.setFont(font)
        self.label_bp.setAlignment(QtCore.Qt.AlignCenter)
        self.label_bp.setObjectName("label_bp")
        self.label_mp = QtWidgets.QLabel(Dialog)
        self.label_mp.setGeometry(QtCore.QRect(230, 260, 41, 16))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.label_mp.setFont(font)
        self.label_mp.setAlignment(QtCore.Qt.AlignCenter)
        self.label_mp.setObjectName("label_mp")
        self.plain_text_special_rules = QtWidgets.QPlainTextEdit(Dialog)
        self.plain_text_special_rules.setGeometry(
            QtCore.QRect(50, 329, 201, 101))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(64, 115, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(64, 115, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(240, 240, 240))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.plain_text_special_rules.setPalette(palette)
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(10)
        self.plain_text_special_rules.setFont(font)
        self.plain_text_special_rules.setAcceptDrops(False)
        self.plain_text_special_rules.setAutoFillBackground(False)
        self.plain_text_special_rules.setFrameShape(QtWidgets.QFrame.NoFrame)
        self.plain_text_special_rules.setFrameShadow(QtWidgets.QFrame.Plain)
        self.plain_text_special_rules.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.plain_text_special_rules.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.plain_text_special_rules.setBackgroundVisible(False)
        self.plain_text_special_rules.setObjectName("plain_text_special_rules")
        self.group_box_style = QtWidgets.QGroupBox(Dialog)
        self.group_box_style.setGeometry(QtCore.QRect(30, 480, 61, 71))
        self.group_box_style.setObjectName("group_box_style")
        self.verticalLayoutWidget_3 = QtWidgets.QWidget(self.group_box_style)
        self.verticalLayoutWidget_3.setGeometry(QtCore.QRect(10, 20, 41, 42))
        self.verticalLayoutWidget_3.setObjectName("verticalLayoutWidget_3")
        self.verticalLayout_3 = QtWidgets.QVBoxLayout(
            self.verticalLayoutWidget_3)
        self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.radio_us = QtWidgets.QRadioButton(self.verticalLayoutWidget_3)
        self.radio_us.setObjectName("radio_us")
        self.verticalLayout_3.addWidget(self.radio_us)
        self.radio_eu = QtWidgets.QRadioButton(self.verticalLayoutWidget_3)
        self.radio_eu.setChecked(True)
        self.radio_eu.setObjectName("radio_eu")
        self.verticalLayout_3.addWidget(self.radio_eu)
        self.at_diagonal = QtWidgets.QCheckBox(Dialog)
        self.at_diagonal.setGeometry(QtCore.QRect(360, 40, 70, 17))
        self.at_diagonal.setObjectName("at_diagonal")
        self.at_ranged = QtWidgets.QCheckBox(Dialog)
        self.at_ranged.setGeometry(QtCore.QRect(360, 60, 70, 17))
        self.at_ranged.setObjectName("at_ranged")
        self.group_box_at_symbol = QtWidgets.QGroupBox(Dialog)
        self.group_box_at_symbol.setGeometry(QtCore.QRect(440, 30, 120, 101))
        self.group_box_at_symbol.setObjectName("group_box_at_symbol")
        self.verticalLayoutWidget = QtWidgets.QWidget(self.group_box_at_symbol)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 20, 111, 74))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")
        self.radio_at_skull = QtWidgets.QRadioButton(self.verticalLayoutWidget)
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("skull.gif"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.radio_at_skull.setIcon(icon1)
        self.radio_at_skull.setChecked(True)
        self.radio_at_skull.setObjectName("radio_at_skull")
        self.verticalLayout.addWidget(self.radio_at_skull)
        self.radio_at_shield = QtWidgets.QRadioButton(
            self.verticalLayoutWidget)
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("white-shield.gif"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.radio_at_shield.setIcon(icon2)
        self.radio_at_shield.setObjectName("radio_at_shield")
        self.verticalLayout.addWidget(self.radio_at_shield)
        self.radio_at_walrus = QtWidgets.QRadioButton(
            self.verticalLayoutWidget)
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("black-shield.gif"), QtGui.QIcon.Normal,
                        QtGui.QIcon.Off)
        self.radio_at_walrus.setIcon(icon3)
        self.radio_at_walrus.setObjectName("radio_at_walrus")
        self.verticalLayout.addWidget(self.radio_at_walrus)
        self.icon_topleft = QtWidgets.QGraphicsView(Dialog)
        self.icon_topleft.setGeometry(QtCore.QRect(40, 36, 40, 40))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(240, 240, 240))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.icon_topleft.setPalette(palette)
        self.icon_topleft.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.icon_topleft.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.icon_topleft.setAlignment(QtCore.Qt.AlignLeading
                                       | QtCore.Qt.AlignLeft
                                       | QtCore.Qt.AlignTop)
        self.icon_topleft.setObjectName("icon_topleft")
        self.icon_bottomright = QtWidgets.QGraphicsView(Dialog)
        self.icon_bottomright.setGeometry(QtCore.QRect(260, 400, 40, 40))
        palette = QtGui.QPalette()
        brush = QtGui.QBrush(QtGui.QColor(121, 94, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(121, 94, 255, 0))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
        brush = QtGui.QBrush(QtGui.QColor(240, 240, 240))
        brush.setStyle(QtCore.Qt.SolidPattern)
        palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
        self.icon_bottomright.setPalette(palette)
        self.icon_bottomright.setVerticalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.icon_bottomright.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.icon_bottomright.setAlignment(QtCore.Qt.AlignLeading
                                           | QtCore.Qt.AlignLeft
                                           | QtCore.Qt.AlignTop)
        self.icon_bottomright.setResizeAnchor(
            QtWidgets.QGraphicsView.AnchorViewCenter)
        self.icon_bottomright.setRubberBandSelectionMode(
            QtCore.Qt.IntersectsItemBoundingRect)
        self.icon_bottomright.setObjectName("icon_bottomright")
        self.group_box_de_symbol = QtWidgets.QGroupBox(Dialog)
        self.group_box_de_symbol.setGeometry(QtCore.QRect(440, 230, 120, 101))
        self.group_box_de_symbol.setObjectName("group_box_de_symbol")
        self.verticalLayoutWidget_2 = QtWidgets.QWidget(
            self.group_box_de_symbol)
        self.verticalLayoutWidget_2.setGeometry(QtCore.QRect(10, 20, 111, 74))
        self.verticalLayoutWidget_2.setObjectName("verticalLayoutWidget_2")
        self.verticalLayout_2 = QtWidgets.QVBoxLayout(
            self.verticalLayoutWidget_2)
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.radio_de_skull = QtWidgets.QRadioButton(
            self.verticalLayoutWidget_2)
        self.radio_de_skull.setIcon(icon1)
        self.radio_de_skull.setObjectName("radio_de_skull")
        self.verticalLayout_2.addWidget(self.radio_de_skull)
        self.radio_de_shield = QtWidgets.QRadioButton(
            self.verticalLayoutWidget_2)
        self.radio_de_shield.setIcon(icon2)
        self.radio_de_shield.setObjectName("radio_de_shield")
        self.verticalLayout_2.addWidget(self.radio_de_shield)
        self.radio_de_walrus = QtWidgets.QRadioButton(
            self.verticalLayoutWidget_2)
        self.radio_de_walrus.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
        self.radio_de_walrus.setIcon(icon3)
        self.radio_de_walrus.setIconSize(QtCore.QSize(16, 16))
        self.radio_de_walrus.setChecked(True)
        self.radio_de_walrus.setAutoExclusive(True)
        self.radio_de_walrus.setObjectName("radio_de_walrus")
        self.verticalLayout_2.addWidget(self.radio_de_walrus)
        self.at_number = QtWidgets.QSpinBox(Dialog)
        self.at_number.setGeometry(QtCore.QRect(360, 120, 42, 22))
        self.at_number.setMaximum(20)
        self.at_number.setProperty("value", 1)
        self.at_number.setObjectName("at_number")
        self.label_6 = QtWidgets.QLabel(Dialog)
        self.label_6.setGeometry(QtCore.QRect(360, 100, 51, 20))
        self.label_6.setObjectName("label_6")
        self.label_7 = QtWidgets.QLabel(Dialog)
        self.label_7.setGeometry(QtCore.QRect(360, 150, 91, 16))
        self.label_7.setObjectName("label_7")
        self.at_damage_type = QtWidgets.QPlainTextEdit(Dialog)
        self.at_damage_type.setGeometry(QtCore.QRect(360, 170, 171, 31))
        self.at_damage_type.setObjectName("at_damage_type")
        self.de_guardian = QtWidgets.QCheckBox(Dialog)
        self.de_guardian.setGeometry(QtCore.QRect(360, 240, 70, 17))
        self.de_guardian.setObjectName("de_guardian")
        self.de_master = QtWidgets.QCheckBox(Dialog)
        self.de_master.setGeometry(QtCore.QRect(360, 260, 69, 17))
        self.de_master.setObjectName("de_master")
        self.de_phalanx = QtWidgets.QCheckBox(Dialog)
        self.de_phalanx.setGeometry(QtCore.QRect(360, 280, 70, 17))
        self.de_phalanx.setObjectName("de_phalanx")
        self.label_8 = QtWidgets.QLabel(Dialog)
        self.label_8.setGeometry(QtCore.QRect(360, 350, 91, 16))
        self.label_8.setObjectName("label_8")
        self.de_immune = QtWidgets.QPlainTextEdit(Dialog)
        self.de_immune.setGeometry(QtCore.QRect(360, 370, 171, 31))
        self.de_immune.setObjectName("de_immune")
        self.de_except = QtWidgets.QPlainTextEdit(Dialog)
        self.de_except.setGeometry(QtCore.QRect(360, 420, 171, 31))
        self.de_except.setObjectName("de_except")
        self.label_9 = QtWidgets.QLabel(Dialog)
        self.label_9.setGeometry(QtCore.QRect(360, 400, 91, 16))
        self.label_9.setObjectName("label_9")
        self.label_10 = QtWidgets.QLabel(Dialog)
        self.label_10.setGeometry(QtCore.QRect(120, 480, 91, 16))
        self.label_10.setObjectName("label_10")
        self.spells = QtWidgets.QPlainTextEdit(Dialog)
        self.spells.setGeometry(QtCore.QRect(120, 500, 171, 51))
        self.spells.setObjectName("spells")
        self.label_11 = QtWidgets.QLabel(Dialog)
        self.label_11.setGeometry(QtCore.QRect(360, 450, 91, 16))
        self.label_11.setObjectName("label_11")
        self.tags = QtWidgets.QPlainTextEdit(Dialog)
        self.tags.setGeometry(QtCore.QRect(360, 470, 171, 31))
        self.tags.setObjectName("tags")
        self.plainText_move = QtWidgets.QLineEdit(Dialog)
        self.plainText_move.setGeometry(QtCore.QRect(70, 280, 41, 41))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.plainText_move.setFont(font)
        self.plainText_move.setAlignment(QtCore.Qt.AlignCenter)
        self.plainText_move.setObjectName("plainText_move")
        self.plainText_at = QtWidgets.QLineEdit(Dialog)
        self.plainText_at.setGeometry(QtCore.QRect(110, 280, 41, 41))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.plainText_at.setFont(font)
        self.plainText_at.setAlignment(QtCore.Qt.AlignCenter)
        self.plainText_at.setObjectName("plainText_at")
        self.plainText_de = QtWidgets.QLineEdit(Dialog)
        self.plainText_de.setGeometry(QtCore.QRect(150, 280, 41, 41))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.plainText_de.setFont(font)
        self.plainText_de.setAlignment(QtCore.Qt.AlignCenter)
        self.plainText_de.setObjectName("plainText_de")
        self.plainText_bp = QtWidgets.QLineEdit(Dialog)
        self.plainText_bp.setGeometry(QtCore.QRect(190, 280, 41, 41))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.plainText_bp.setFont(font)
        self.plainText_bp.setAlignment(QtCore.Qt.AlignCenter)
        self.plainText_bp.setObjectName("plainText_bp")
        self.plainText_mp = QtWidgets.QLineEdit(Dialog)
        self.plainText_mp.setGeometry(QtCore.QRect(230, 280, 41, 41))
        font = QtGui.QFont()
        font.setFamily("HQModern")
        font.setPointSize(12)
        self.plainText_mp.setFont(font)
        self.plainText_mp.setAlignment(QtCore.Qt.AlignCenter)
        self.plainText_mp.setObjectName("plainText_mp")
        self.group_box_style.raise_()
        self.group_box_de_symbol.raise_()
        self.group_box_at_symbol.raise_()
        self.buttonBox.raise_()
        self.graphic_background.raise_()
        self.textEdit_name.raise_()
        self.graphicsView.raise_()
        self.label_move.raise_()
        self.label_at.raise_()
        self.label_de.raise_()
        self.label_bp.raise_()
        self.label_mp.raise_()
        self.plain_text_special_rules.raise_()
        self.at_diagonal.raise_()
        self.at_ranged.raise_()
        self.icon_topleft.raise_()
        self.icon_bottomright.raise_()
        self.at_number.raise_()
        self.label_6.raise_()
        self.label_7.raise_()
        self.at_damage_type.raise_()
        self.de_guardian.raise_()
        self.de_master.raise_()
        self.de_phalanx.raise_()
        self.label_8.raise_()
        self.de_immune.raise_()
        self.de_except.raise_()
        self.label_9.raise_()
        self.label_10.raise_()
        self.spells.raise_()
        self.label_11.raise_()
        self.tags.raise_()
        self.plainText_move.raise_()
        self.plainText_at.raise_()
        self.plainText_de.raise_()
        self.plainText_bp.raise_()
        self.plainText_mp.raise_()

        self.retranslateUi(Dialog)
        self.buttonBox.accepted.connect(Dialog.accept)
        self.buttonBox.rejected.connect(Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)
Esempio n. 30
0
    def _updateRecord(self, record):
        if self.proxy:
            self.proxy.setDynamicSortFilter(False)

        obverseImage = QImage()
        reverseImage = QImage()
        for field in self.fields.userFields:
            if field.type in [Type.Image, Type.EdgeImage]:
                # Convert image to DB format
                image = record.value(field.name)
                if isinstance(image, str):
                    # Copying record as text (from Excel) store missed images
                    # as string
                    record.setNull(field.name)
                elif isinstance(image, QImage):
                    ba = QtCore.QByteArray()
                    buffer = QtCore.QBuffer(ba)
                    buffer.open(QtCore.QIODevice.WriteOnly)

                    # Resize big images for storing in DB
                    sideLen = Settings()['ImageSideLen']
                    sideLen = int(sideLen)  # forced conversion to Integer
                    maxWidth = sideLen
                    maxHeight = sideLen
                    if image.width() > maxWidth or image.height() > maxHeight:
                        scaledImage = image.scaled(maxWidth, maxHeight,
                                                   Qt.KeepAspectRatio,
                                                   Qt.SmoothTransformation)
                    else:
                        scaledImage = image

                    if field.name == 'obverseimg':
                        obverseImage = scaledImage
                    if field.name == 'reverseimg':
                        reverseImage = scaledImage

                    scaledImage.save(buffer, self.IMAGE_FORMAT)
                    record.setValue(field.name, ba)
                elif isinstance(image, bytes):
                    ba = QtCore.QByteArray(image)
                    record.setValue(field.name, ba)

        # Creating preview image for list
        if record.isNull('obverseimg') and record.isNull('reverseimg'):
            record.setNull('image')
        else:
            # Get height of list view for resizing images
            tmp = QTableView()
            height = int(tmp.verticalHeader().defaultSectionSize() * 1.5 - 1)

            if not record.isNull('obverseimg') and obverseImage.isNull():
                obverseImage.loadFromData(record.value('obverseimg'))
            if not obverseImage.isNull():
                obverseImage = obverseImage.scaledToHeight(
                    height, Qt.SmoothTransformation)
            if not record.isNull('reverseimg') and reverseImage.isNull():
                reverseImage.loadFromData(record.value('reverseimg'))
            if not reverseImage.isNull():
                reverseImage = reverseImage.scaledToHeight(
                    height, Qt.SmoothTransformation)

            image = QImage(obverseImage.width() + reverseImage.width(), height,
                           QImage.Format_RGB32)
            image.fill(QColor(Qt.white).rgb())

            paint = QPainter(image)
            if not record.isNull('obverseimg'):
                paint.drawImage(
                    QtCore.QRectF(0, 0, obverseImage.width(), height),
                    obverseImage,
                    QtCore.QRectF(0, 0, obverseImage.width(), height))
            if not record.isNull('reverseimg'):
                paint.drawImage(
                    QtCore.QRectF(obverseImage.width(), 0,
                                  reverseImage.width(), height), reverseImage,
                    QtCore.QRectF(0, 0, reverseImage.width(), height))
            paint.end()

            ba = QtCore.QByteArray()
            buffer = QtCore.QBuffer(ba)
            buffer.open(QtCore.QIODevice.WriteOnly)

            # Store as PNG for better view
            image.save(buffer, 'png')
            record.setValue('image', ba)

        currentTime = QtCore.QDateTime.currentDateTimeUtc()
        record.setValue('updatedat', currentTime.toString(Qt.ISODate))