def __init__(self, ruler, parent=None):
        QWidget.__init__(self, parent)

        # colors settings
        backgroundColor = ruler.data.get('background_color')
        linesColor = ruler.data.get('lines_color')
        divisionsColor = ruler.data.get('divisions_color')

        def updateBackgroundColor(newColor):
            ruler.data.update('background_color', newColor)
            ruler.update()

        def updateLinesColor(newColor):
            ruler.data.update('lines_color', newColor)
            ruler.update()

        def updateDivisionsColor(newColor):
            ruler.data.update('divisions_color', newColor)
            ruler.update()

        backgroundColorElement = ColorButton(self, 'Background',
                                             backgroundColor,
                                             updateBackgroundColor)
        linesColorElement = ColorButton(self, 'Lines', linesColor,
                                        updateLinesColor)
        divisionsColorElement = ColorButton(self, 'Divisions', divisionsColor,
                                            updateDivisionsColor)

        layout = QGridLayout()
        layout.setSpacing(10)

        # set the same width/height for all the columns/rows
        columnWidth = 120
        rowHeight = 25
        layout.setRowMinimumHeight(0, rowHeight)
        layout.setRowMinimumHeight(1, rowHeight)
        layout.setRowMinimumHeight(2, rowHeight)
        layout.setColumnMinimumWidth(0, columnWidth)
        layout.setColumnMinimumWidth(1, columnWidth)
        layout.setColumnMinimumWidth(2, columnWidth)

        # first column
        layout.addWidget(backgroundColorElement, 1, 0)

        # second column
        layout.addWidget(linesColorElement, 1, 1)

        # third column
        layout.addWidget(divisionsColorElement, 1, 2)

        layout.setSizeConstraint(QLayout.SetFixedSize)
        self.setLayout(layout)
    def __init__(self, ruler, parent=None):
        QWidget.__init__(self, parent)

        # units (cm/px/inch)
        unitsGroup = QButtonGroup(self)
        pixels = QRadioButton('Pixels')
        pixels.unit = 'px'
        centimeters = QRadioButton('Centimeters')
        centimeters.unit = 'cm'
        inches = QRadioButton('Inches')
        inches.unit = 'inch'

        selectedUnit = ruler.data.get('units')

        if selectedUnit == 'cm':
            centimeters.setChecked(True)

        elif selectedUnit == 'inch':
            inches.setChecked(True)

        else:
            pixels.setChecked(True)

        unitsGroup.addButton(pixels)
        unitsGroup.addButton(centimeters)
        unitsGroup.addButton(inches)

        def changeUnits(radioButton):
            nonlocal selectedUnit
            newUnit = radioButton.unit

            if newUnit != selectedUnit:
                ruler.data.update('units', newUnit)
                selectedUnit = newUnit
                ruler.update()

        unitsGroup.buttonClicked.connect(changeUnits)

        # orientation (horizontal/vertical)
        horizontalOrientation = ruler.data.get('horizontal_orientation')

        orientationGroup = QButtonGroup(self)
        self.horizontal_string = 'Horizontal'
        self.vertical_string = 'Vertical'
        horizontal = QRadioButton(self.horizontal_string)
        vertical = QRadioButton(self.vertical_string)

        if horizontalOrientation:
            horizontal.setChecked(True)
            self.selected_orientation = self.horizontal_string

        else:
            vertical.setChecked(True)
            self.selected_orientation = self.vertical_string

        def changeOrientation(radioButton):
            text = radioButton.text()

            if self.selected_orientation != text:

                self.selected_orientation = text
                ruler.rotate()

        orientationGroup.addButton(horizontal)
        orientationGroup.addButton(vertical)
        orientationGroup.buttonClicked.connect(changeOrientation)

        # length settings (always above + division lines + current length)
        alwaysAbove = QCheckBox('Always Above', self)
        alwaysAbove.setChecked(ruler.data.get('always_above'))

        def alwaysAboveSetting():

            if alwaysAbove.isChecked():

                ruler.data.update('always_above', True)
                ruler.setWindowFlags(ruler.windowFlags()
                                     | Qt.WindowStaysOnTopHint)

            else:
                ruler.data.update('always_above', False)
                ruler.setWindowFlags(ruler.windowFlags()
                                     & ~Qt.WindowStaysOnTopHint)

            ruler.show()

        alwaysAbove.clicked.connect(alwaysAboveSetting)

        divisionLines = QCheckBox('1/2 1/4 3/4 divisions', self)
        divisionLines.setChecked(ruler.data.get('division_lines'))

        def divisionLinesSetting():
            ruler.data.update('division_lines', divisionLines.isChecked())
            ruler.update()

        divisionLines.clicked.connect(divisionLinesSetting)

        currentLength = QLabel('0px')
        currentLength.setAlignment(Qt.AlignCenter)

        # setup the layout
        layout = QGridLayout()
        layout.setSpacing(10)

        # set the same width/height for all the columns/rows
        columnWidth = 120
        rowHeight = 25
        layout.setRowMinimumHeight(0, rowHeight)
        layout.setRowMinimumHeight(1, rowHeight)
        layout.setRowMinimumHeight(2, rowHeight)
        layout.setColumnMinimumWidth(0, columnWidth)
        layout.setColumnMinimumWidth(1, columnWidth)
        layout.setColumnMinimumWidth(2, columnWidth)

        # first column
        layout.addWidget(pixels, 0, 0)
        layout.addWidget(centimeters, 1, 0)
        layout.addWidget(inches, 2, 0)

        # second column
        layout.addWidget(horizontal, 0, 1)
        layout.addWidget(vertical, 1, 1)

        # third column
        layout.addWidget(alwaysAbove, 0, 2)
        layout.addWidget(divisionLines, 1, 2)
        layout.addWidget(currentLength, 2, 2)

        layout.setSizeConstraint(QLayout.SetFixedSize)

        self.current_length = currentLength
        self.vertical = vertical
        self.horizontal = horizontal
        self.setLayout(layout)
Exemple #3
0
    def __init__(self):
        super(Window, self).__init__()

        self.renderArea = RenderArea()

        self.shapeComboBox = QComboBox()
        self.shapeComboBox.addItem("Polygon", RenderArea.Polygon)
        self.shapeComboBox.addItem("Rectangle", RenderArea.Rect)
        self.shapeComboBox.addItem("Rounded Rectangle", RenderArea.RoundedRect)
        self.shapeComboBox.addItem("Ellipse", RenderArea.Ellipse)
        self.shapeComboBox.addItem("Pie", RenderArea.Pie)
        self.shapeComboBox.addItem("Chord", RenderArea.Chord)
        self.shapeComboBox.addItem("Path", RenderArea.Path)
        self.shapeComboBox.addItem("Line", RenderArea.Line)
        self.shapeComboBox.addItem("Polyline", RenderArea.Polyline)
        self.shapeComboBox.addItem("Arc", RenderArea.Arc)
        self.shapeComboBox.addItem("Points", RenderArea.Points)
        self.shapeComboBox.addItem("Text", RenderArea.Text)
        self.shapeComboBox.addItem("Pixmap", RenderArea.Pixmap)

        shapeLabel = QLabel("&Shape:")
        shapeLabel.setBuddy(self.shapeComboBox)

        self.penWidthSpinBox = QSpinBox()
        self.penWidthSpinBox.setRange(0, 20)
        self.penWidthSpinBox.setSpecialValueText("0 (cosmetic pen)")

        penWidthLabel = QLabel("Pen &Width:")
        penWidthLabel.setBuddy(self.penWidthSpinBox)

        self.penStyleComboBox = QComboBox()
        self.penStyleComboBox.addItem("Solid", Qt.SolidLine)
        self.penStyleComboBox.addItem("Dash", Qt.DashLine)
        self.penStyleComboBox.addItem("Dot", Qt.DotLine)
        self.penStyleComboBox.addItem("Dash Dot", Qt.DashDotLine)
        self.penStyleComboBox.addItem("Dash Dot Dot", Qt.DashDotDotLine)
        self.penStyleComboBox.addItem("None", Qt.NoPen)

        penStyleLabel = QLabel("&Pen Style:")
        penStyleLabel.setBuddy(self.penStyleComboBox)

        self.penCapComboBox = QComboBox()
        self.penCapComboBox.addItem("Flat", Qt.FlatCap)
        self.penCapComboBox.addItem("Square", Qt.SquareCap)
        self.penCapComboBox.addItem("Round", Qt.RoundCap)

        penCapLabel = QLabel("Pen &Cap:")
        penCapLabel.setBuddy(self.penCapComboBox)

        self.penJoinComboBox = QComboBox()
        self.penJoinComboBox.addItem("Miter", Qt.MiterJoin)
        self.penJoinComboBox.addItem("Bevel", Qt.BevelJoin)
        self.penJoinComboBox.addItem("Round", Qt.RoundJoin)

        penJoinLabel = QLabel("Pen &Join:")
        penJoinLabel.setBuddy(self.penJoinComboBox)

        self.brushStyleComboBox = QComboBox()
        self.brushStyleComboBox.addItem("Linear Gradient",
                                        Qt.LinearGradientPattern)
        self.brushStyleComboBox.addItem("Radial Gradient",
                                        Qt.RadialGradientPattern)
        self.brushStyleComboBox.addItem("Conical Gradient",
                                        Qt.ConicalGradientPattern)
        self.brushStyleComboBox.addItem("Texture", Qt.TexturePattern)
        self.brushStyleComboBox.addItem("Solid", Qt.SolidPattern)
        self.brushStyleComboBox.addItem("Horizontal", Qt.HorPattern)
        self.brushStyleComboBox.addItem("Vertical", Qt.VerPattern)
        self.brushStyleComboBox.addItem("Cross", Qt.CrossPattern)
        self.brushStyleComboBox.addItem("Backward Diagonal", Qt.BDiagPattern)
        self.brushStyleComboBox.addItem("Forward Diagonal", Qt.FDiagPattern)
        self.brushStyleComboBox.addItem("Diagonal Cross", Qt.DiagCrossPattern)
        self.brushStyleComboBox.addItem("Dense 1", Qt.Dense1Pattern)
        self.brushStyleComboBox.addItem("Dense 2", Qt.Dense2Pattern)
        self.brushStyleComboBox.addItem("Dense 3", Qt.Dense3Pattern)
        self.brushStyleComboBox.addItem("Dense 4", Qt.Dense4Pattern)
        self.brushStyleComboBox.addItem("Dense 5", Qt.Dense5Pattern)
        self.brushStyleComboBox.addItem("Dense 6", Qt.Dense6Pattern)
        self.brushStyleComboBox.addItem("Dense 7", Qt.Dense7Pattern)
        self.brushStyleComboBox.addItem("None", Qt.NoBrush)

        brushStyleLabel = QLabel("&Brush Style:")
        brushStyleLabel.setBuddy(self.brushStyleComboBox)

        otherOptionsLabel = QLabel("Other Options:")
        self.antialiasingCheckBox = QCheckBox("&Antialiasing")
        self.transformationsCheckBox = QCheckBox("&Transformations")

        self.shapeComboBox.activated.connect(self.shapeChanged)
        self.penWidthSpinBox.valueChanged.connect(self.penChanged)
        self.penStyleComboBox.activated.connect(self.penChanged)
        self.penCapComboBox.activated.connect(self.penChanged)
        self.penJoinComboBox.activated.connect(self.penChanged)
        self.brushStyleComboBox.activated.connect(self.brushChanged)
        self.antialiasingCheckBox.toggled.connect(
            self.renderArea.setAntialiased)
        self.transformationsCheckBox.toggled.connect(
            self.renderArea.setTransformed)

        mainLayout = QGridLayout()
        mainLayout.setColumnStretch(0, 1)
        mainLayout.setColumnStretch(3, 1)
        mainLayout.addWidget(self.renderArea, 0, 0, 1, 4)
        mainLayout.setRowMinimumHeight(1, 6)
        mainLayout.addWidget(shapeLabel, 2, 1, Qt.AlignRight)
        mainLayout.addWidget(self.shapeComboBox, 2, 2)
        mainLayout.addWidget(penWidthLabel, 3, 1, Qt.AlignRight)
        mainLayout.addWidget(self.penWidthSpinBox, 3, 2)
        mainLayout.addWidget(penStyleLabel, 4, 1, Qt.AlignRight)
        mainLayout.addWidget(self.penStyleComboBox, 4, 2)
        mainLayout.addWidget(penCapLabel, 5, 1, Qt.AlignRight)
        mainLayout.addWidget(self.penCapComboBox, 5, 2)
        mainLayout.addWidget(penJoinLabel, 6, 1, Qt.AlignRight)
        mainLayout.addWidget(self.penJoinComboBox, 6, 2)
        mainLayout.addWidget(brushStyleLabel, 7, 1, Qt.AlignRight)
        mainLayout.addWidget(self.brushStyleComboBox, 7, 2)
        mainLayout.setRowMinimumHeight(8, 6)
        mainLayout.addWidget(otherOptionsLabel, 9, 1, Qt.AlignRight)
        mainLayout.addWidget(self.antialiasingCheckBox, 9, 2)
        mainLayout.addWidget(self.transformationsCheckBox, 10, 2)
        self.setLayout(mainLayout)

        self.shapeChanged()
        self.penChanged()
        self.brushChanged()
        self.antialiasingCheckBox.setChecked(True)

        self.setWindowTitle("Basic Drawing")