Beispiel #1
0
class ConfLine(QtWidgets.QWidget):
    """Composite widget with line format configuration tools"""
    join = [QtCore.Qt.MiterJoin, QtCore.Qt.BevelJoin, QtCore.Qt.RoundJoin]
    cap = [QtCore.Qt.FlatCap, QtCore.Qt.RoundCap, QtCore.Qt.SquareCap]
    line = [QtCore.Qt.SolidLine, QtCore.Qt.DashLine, QtCore.Qt.DotLine,
            QtCore.Qt.DashDotLine, QtCore.Qt.DashDotDotLine]

    def __init__(self, pen=None, parent=None):
        super(ConfLine, self).__init__(parent)
        lyt = QtWidgets.QVBoxLayout(self)

        lyt1 = QtWidgets.QHBoxLayout()
        lyt1.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Line")))
        self.ColorButtonLine = ColorSelector()
        self.ColorButtonLine.setToolTip(
            QtWidgets.QApplication.translate("pychemqt", "Default line color"))
        lyt1.addWidget(self.ColorButtonLine)
        self.width = Entrada_con_unidades(
            float, width=50, decimales=1, spinbox=True, step=0.1,
            textounidad="px")
        self.width.entrada.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Line Width"))
        lyt1.addWidget(self.width)
        lyt.addLayout(lyt1)

        lyt2 = QtWidgets.QHBoxLayout()
        lyt2.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Join")))
        self.mitterLimit = Entrada_con_unidades(
            float, width=50, decimales=1, spinbox=True, step=0.1)
        self.mitterLimit.entrada.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Mitter Limit"))
        lyt2.addWidget(self.mitterLimit)
        toolJoinMitter = QtWidgets.QToolButton()
        toolJoinMitter.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-join-miter.png"))))
        toolJoinMitter.setIconSize(QtCore.QSize(24, 24))
        toolJoinMitter.setCheckable(True)
        toolJoinMitter.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt",
            "Join mitter: The triangular notch between the two lines is not "
            "filled"))
        lyt2.addWidget(toolJoinMitter)
        toolJoinBevel = QtWidgets.QToolButton()
        toolJoinBevel.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-join-bevel.png"))))
        toolJoinBevel.setIconSize(QtCore.QSize(24, 24))
        toolJoinBevel.setCheckable(True)
        toolJoinBevel.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt",
            "Join bevel: The triangular notch between the two lines is "
            "filled"))
        lyt2.addWidget(toolJoinBevel)
        toolJoinRound = QtWidgets.QToolButton()
        toolJoinRound.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-join-round.png"))))
        toolJoinRound.setIconSize(QtCore.QSize(24, 24))
        toolJoinRound.setCheckable(True)
        toolJoinRound.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt",
            "Join round: A circular arc between the two lines is filled"))
        lyt2.addWidget(toolJoinRound)

        self.groupJoint = QtWidgets.QButtonGroup()
        self.groupJoint.addButton(toolJoinMitter)
        self.groupJoint.addButton(toolJoinBevel)
        self.groupJoint.addButton(toolJoinRound)
        self.groupJoint.buttonClicked["int"].connect(self.mitterlimitEnabled)
        lyt.addLayout(lyt2)

        lyt3 = QtWidgets.QHBoxLayout()
        lyt3.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Cap")))
        toolCapFlat = QtWidgets.QToolButton()
        toolCapFlat.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-cap-butt.png"))))
        toolCapFlat.setIconSize(QtCore.QSize(24, 24))
        toolCapFlat.setCheckable(True)
        toolCapFlat.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt",
            "Flat Cap: A square line end that does not cover the end point of "
            "the line"))
        lyt3.addWidget(toolCapFlat)
        toolCapRound = QtWidgets.QToolButton()
        toolCapRound.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-cap-round.png"))))
        toolCapRound.setIconSize(QtCore.QSize(24, 24))
        toolCapRound.setCheckable(True)
        toolCapRound.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Round Cap: A rounded line end"))
        lyt3.addWidget(toolCapRound)
        toolCapSquare = QtWidgets.QToolButton()
        toolCapSquare.setIcon(QtGui.QIcon(QtGui.QPixmap(
            os.environ["pychemqt"] +
            os.path.join("images", "button", "stroke-cap-square.png"))))
        toolCapSquare.setIconSize(QtCore.QSize(24, 24))
        toolCapSquare.setCheckable(True)
        toolCapSquare.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt",
            "Square Cap: A square line end that covers the end point and "
            "extends beyond it by half the line width"))
        lyt3.addWidget(toolCapSquare)

        self.groupCap = QtWidgets.QButtonGroup()
        self.groupCap.addButton(toolCapFlat)
        self.groupCap.addButton(toolCapRound)
        self.groupCap.addButton(toolCapSquare)
        lyt.addLayout(lyt3)

        lyt4 = QtWidgets.QHBoxLayout()
        lyt4.addWidget(QtWidgets.QLabel(
            QtWidgets.QApplication.translate("pychemqt", "Dash")))
        self.guion = PFDLineCombo()
        lyt4.addWidget(self.guion)
        self.dashOffset = Entrada_con_unidades(
            float, width=50, decimales=1, spinbox=True, step=0.1)
        self.dashOffset.entrada.setToolTip(QtWidgets.QApplication.translate(
            "pychemqt", "Dash offset"))
        lyt4.addWidget(self.dashOffset)
        lyt.addLayout(lyt4)
        lyt.addItem(QtWidgets.QSpacerItem(
            0, 0, QtWidgets.QSizePolicy.Expanding,
            QtWidgets.QSizePolicy.Expanding))

        if pen:
            self.ColorButtonLine.setColor(pen.color().name())
            self.groupJoint.button((self.join.index(
                pen.joinStyle())+2)*-1).setChecked(True)
            self.mitterLimit.setValue(pen.miterLimit())
            self.groupCap.button((self.cap.index(
                pen.capStyle())+2)*-1).setChecked(True)
            self.guion.setCurrentIndex(self.line.index(pen.style()))
            self.dashOffset.setValue(pen.dashOffset())
            self.width.setValue(pen.widthF())

    def mitterlimitEnabled(self, id):
        self.mitterLimit.setEnabled(id == -2)

    def pen(self):
        """Return a QPen with the live configuration"""
        pen = QtGui.QPen(QtGui.QColor(self.ColorButtonLine.color.name()))
        pen.setWidthF(self.width.value)
        pen.setJoinStyle(self.join[abs(self.groupJoint.checkedId())-2])
        pen.setMiterLimit(self.mitterLimit.value)
        pen.setCapStyle(self.cap[abs(self.groupCap.checkedId())-2])
        pen.setStyle(self.line[self.guion.currentIndex()])
        pen.setDashOffset(self.dashOffset.value)
        return pen
Beispiel #2
0
class ConfLine(QtWidgets.QWidget):
    """Composite widget with line format configuration tools"""
    join = [QtCore.Qt.MiterJoin, QtCore.Qt.BevelJoin, QtCore.Qt.RoundJoin]
    cap = [QtCore.Qt.FlatCap, QtCore.Qt.RoundCap, QtCore.Qt.SquareCap]
    line = [
        QtCore.Qt.SolidLine, QtCore.Qt.DashLine, QtCore.Qt.DotLine,
        QtCore.Qt.DashDotLine, QtCore.Qt.DashDotDotLine
    ]

    def __init__(self, pen=None, parent=None):
        super(ConfLine, self).__init__(parent)
        lyt = QtWidgets.QVBoxLayout(self)

        lyt1 = QtWidgets.QHBoxLayout()
        lyt1.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Line")))
        self.ColorButtonLine = ColorSelector()
        self.ColorButtonLine.setToolTip(
            QtWidgets.QApplication.translate("pychemqt", "Default line color"))
        lyt1.addWidget(self.ColorButtonLine)
        self.width = Entrada_con_unidades(float,
                                          width=50,
                                          decimales=1,
                                          spinbox=True,
                                          step=0.1,
                                          textounidad="px")
        self.width.entrada.setToolTip(
            QtWidgets.QApplication.translate("pychemqt", "Line Width"))
        lyt1.addWidget(self.width)
        lyt.addLayout(lyt1)

        lyt2 = QtWidgets.QHBoxLayout()
        lyt2.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Join")))
        self.mitterLimit = Entrada_con_unidades(float,
                                                width=50,
                                                decimales=1,
                                                spinbox=True,
                                                step=0.1)
        self.mitterLimit.entrada.setToolTip(
            QtWidgets.QApplication.translate("pychemqt", "Mitter Limit"))
        lyt2.addWidget(self.mitterLimit)
        toolJoinMitter = QtWidgets.QToolButton()
        toolJoinMitter.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["CheProcess"] + os.path.join(
                    "images", "button", "stroke-join-miter.png"))))
        toolJoinMitter.setIconSize(QtCore.QSize(24, 24))
        toolJoinMitter.setCheckable(True)
        toolJoinMitter.setToolTip(
            QtWidgets.QApplication.translate(
                "pychemqt",
                "Join mitter: The triangular notch between the two lines is not "
                "filled"))
        lyt2.addWidget(toolJoinMitter)
        toolJoinBevel = QtWidgets.QToolButton()
        toolJoinBevel.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["CheProcess"] + os.path.join(
                    "images", "button", "stroke-join-bevel.png"))))
        toolJoinBevel.setIconSize(QtCore.QSize(24, 24))
        toolJoinBevel.setCheckable(True)
        toolJoinBevel.setToolTip(
            QtWidgets.QApplication.translate(
                "pychemqt",
                "Join bevel: The triangular notch between the two lines is "
                "filled"))
        lyt2.addWidget(toolJoinBevel)
        toolJoinRound = QtWidgets.QToolButton()
        toolJoinRound.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["CheProcess"] + os.path.join(
                    "images", "button", "stroke-join-round.png"))))
        toolJoinRound.setIconSize(QtCore.QSize(24, 24))
        toolJoinRound.setCheckable(True)
        toolJoinRound.setToolTip(
            QtWidgets.QApplication.translate(
                "pychemqt",
                "Join round: A circular arc between the two lines is filled"))
        lyt2.addWidget(toolJoinRound)

        self.groupJoint = QtWidgets.QButtonGroup()
        self.groupJoint.addButton(toolJoinMitter)
        self.groupJoint.addButton(toolJoinBevel)
        self.groupJoint.addButton(toolJoinRound)
        self.groupJoint.buttonClicked["int"].connect(self.mitterlimitEnabled)
        lyt.addLayout(lyt2)

        lyt3 = QtWidgets.QHBoxLayout()
        lyt3.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Cap")))
        toolCapFlat = QtWidgets.QToolButton()
        toolCapFlat.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(
                    os.environ["CheProcess"] +
                    os.path.join("images", "button", "stroke-cap-butt.png"))))
        toolCapFlat.setIconSize(QtCore.QSize(24, 24))
        toolCapFlat.setCheckable(True)
        toolCapFlat.setToolTip(
            QtWidgets.QApplication.translate(
                "pychemqt",
                "Flat Cap: A square line end that does not cover the end point of "
                "the line"))
        lyt3.addWidget(toolCapFlat)
        toolCapRound = QtWidgets.QToolButton()
        toolCapRound.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(
                    os.environ["CheProcess"] +
                    os.path.join("images", "button", "stroke-cap-round.png"))))
        toolCapRound.setIconSize(QtCore.QSize(24, 24))
        toolCapRound.setCheckable(True)
        toolCapRound.setToolTip(
            QtWidgets.QApplication.translate("pychemqt",
                                             "Round Cap: A rounded line end"))
        lyt3.addWidget(toolCapRound)
        toolCapSquare = QtWidgets.QToolButton()
        toolCapSquare.setIcon(
            QtGui.QIcon(
                QtGui.QPixmap(os.environ["CheProcess"] + os.path.join(
                    "images", "button", "stroke-cap-square.png"))))
        toolCapSquare.setIconSize(QtCore.QSize(24, 24))
        toolCapSquare.setCheckable(True)
        toolCapSquare.setToolTip(
            QtWidgets.QApplication.translate(
                "pychemqt",
                "Square Cap: A square line end that covers the end point and "
                "extends beyond it by half the line width"))
        lyt3.addWidget(toolCapSquare)

        self.groupCap = QtWidgets.QButtonGroup()
        self.groupCap.addButton(toolCapFlat)
        self.groupCap.addButton(toolCapRound)
        self.groupCap.addButton(toolCapSquare)
        lyt.addLayout(lyt3)

        lyt4 = QtWidgets.QHBoxLayout()
        lyt4.addWidget(
            QtWidgets.QLabel(
                QtWidgets.QApplication.translate("pychemqt", "Dash")))
        self.guion = PFDLineCombo()
        lyt4.addWidget(self.guion)
        self.dashOffset = Entrada_con_unidades(float,
                                               width=50,
                                               decimales=1,
                                               spinbox=True,
                                               step=0.1)
        self.dashOffset.entrada.setToolTip(
            QtWidgets.QApplication.translate("pychemqt", "Dash offset"))
        lyt4.addWidget(self.dashOffset)
        lyt.addLayout(lyt4)
        lyt.addItem(
            QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding,
                                  QtWidgets.QSizePolicy.Expanding))

        if pen:
            self.ColorButtonLine.setColor(pen.color().name())
            self.groupJoint.button(
                (self.join.index(pen.joinStyle()) + 2) * -1).setChecked(True)
            self.mitterLimit.setValue(pen.miterLimit())
            self.groupCap.button(
                (self.cap.index(pen.capStyle()) + 2) * -1).setChecked(True)
            self.guion.setCurrentIndex(self.line.index(pen.style()))
            self.dashOffset.setValue(pen.dashOffset())
            self.width.setValue(pen.widthF())

    def mitterlimitEnabled(self, id):
        self.mitterLimit.setEnabled(id == -2)

    def pen(self):
        """Return a QPen with the live configuration"""
        pen = QtGui.QPen(QtGui.QColor(self.ColorButtonLine.color.name()))
        pen.setWidthF(self.width.value)
        pen.setJoinStyle(self.join[abs(self.groupJoint.checkedId()) - 2])
        pen.setMiterLimit(self.mitterLimit.value)
        pen.setCapStyle(self.cap[abs(self.groupCap.checkedId()) - 2])
        pen.setStyle(self.line[self.guion.currentIndex()])
        pen.setDashOffset(self.dashOffset.value)
        return pen