Ejemplo n.º 1
0
 def wheelEvent(self, event):
     """Mouse wheel event"""
     if QApplication.keyboardModifiers() == Qt.ControlModifier:
         factor = 1.41**(-event.angleDelta() / 240.0)
         self.scale(factor, factor)
     else:
         QGraphicsView.wheelEvent(self, event)
 def wheelEvent(self, event):
     """Mouse wheel event"""
     if QApplication.keyboardModifiers() == Qt.ControlModifier:
         if event.angleDelta().y() < 0:
             self.zoomOut()
         else:
             self.zoomIn()
     else:
         QGraphicsView.wheelEvent(self, event)
 def keyPressEvent(self, event):
     """Handles the key press events"""
     if event.key() == Qt.Key_Escape:
         self.sigEscapePressed.emit()
         event.accept()
     elif event.key() == Qt.Key_C and \
          event.modifiers() == Qt.ControlModifier:
         self.onCopy()
         event.accept()
     else:
         QGraphicsView.keyPressEvent(self, event)
Ejemplo n.º 4
0
    def __createLayout(self):
        """Creates the dialog layout"""
        self.setMinimumWidth(300)
        self.setMinimumHeight(250)
        self.resize(400, 300)
        self.setSizeGripEnabled(True)

        verticalLayout = QVBoxLayout(self)
        verticalLayout.setContentsMargins(5, 5, 5, 5)
        gridLayout = QGridLayout()

        bgLabel = QLabel('Select background color:', self)
        gridLayout.addWidget(bgLabel, 0, 0, 1, 1)
        self.__bgColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__bgColorButton, 0, 1, 1, 1)

        fgLabel = QLabel('Select foreground color:', self)
        gridLayout.addWidget(fgLabel, 1, 0, 1, 1)
        self.__fgColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__fgColorButton, 1, 1, 1, 1)

        borderLabel = QLabel('Select border color (*):', self)
        gridLayout.addWidget(borderLabel, 2, 0, 1, 1)
        self.__borderColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__borderColorButton, 2, 1, 1, 1)

        verticalLayout.addLayout(gridLayout)
        verticalLayout.addWidget(
            QLabel('(*): docstrings use it only when shown as badges'))

        # Sample area
        self.__scene = QGraphicsScene()
        self.__view = QGraphicsView()
        self.__view.setScene(self.__scene)
        verticalLayout.addWidget(self.__view)

        # Buttons at the bottom
        buttonBox = QDialogButtonBox(self)
        buttonBox.setOrientation(Qt.Horizontal)
        buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                     | QDialogButtonBox.Ok)
        verticalLayout.addWidget(buttonBox)

        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)
Ejemplo n.º 5
0
 def wheelEvent(self, event):
     """Mouse wheel event"""
     modifiers = QApplication.keyboardModifiers()
     if modifiers == Qt.ControlModifier:
         angleDelta = event.angleDelta()
         if not angleDelta.isNull():
             if angleDelta.y() > 0:
                 Settings().onFlowZoomIn()
             else:
                 Settings().onFlowZoomOut()
         event.accept()
     elif modifiers == Qt.ShiftModifier:
         angleDelta = event.angleDelta()
         if not angleDelta.isNull():
             if angleDelta.y() > 0:
                 self.__parentWidget.onSmartZoomLevelUp()
             else:
                 self.__parentWidget.onSmartZoomLevelDown()
         event.accept()
     else:
         QGraphicsView.wheelEvent(self, event)
 def setScene(self, scene):
     """Sets the scene to display"""
     scene.setBackgroundBrush(GlobalData().skin['nolexerPaper'])
     QGraphicsView.setScene(self, scene)
 def __init__(self, parent=None):
     QGraphicsView.__init__(self, parent)
Ejemplo n.º 8
0
class CustomColorsDialog(QDialog):
    """Custom colors dialog implementation"""
    def __init__(self, bgcolor, fgcolor, bordercolor, parent=None):
        """colors are instances of QColor"""
        QDialog.__init__(self, parent)
        self.setWindowTitle('Custom colors')

        self.__createLayout()
        self.__bgColorButton.setColor(bgcolor)
        self.__bgColorButton.sigColorChanged.connect(self.__onColorChanged)
        self.__fgColorButton.setColor(fgcolor)
        self.__fgColorButton.sigColorChanged.connect(self.__onColorChanged)
        self.__borderColorButton.setColor(bordercolor)
        self.__borderColorButton.sigColorChanged.connect(self.__onColorChanged)

        QTimer.singleShot(1, self.__onColorChanged)

    def __createLayout(self):
        """Creates the dialog layout"""
        self.setMinimumWidth(300)
        self.setMinimumHeight(250)
        self.resize(400, 300)
        self.setSizeGripEnabled(True)

        verticalLayout = QVBoxLayout(self)
        verticalLayout.setContentsMargins(5, 5, 5, 5)
        gridLayout = QGridLayout()

        bgLabel = QLabel('Select background color:', self)
        gridLayout.addWidget(bgLabel, 0, 0, 1, 1)
        self.__bgColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__bgColorButton, 0, 1, 1, 1)

        fgLabel = QLabel('Select foreground color:', self)
        gridLayout.addWidget(fgLabel, 1, 0, 1, 1)
        self.__fgColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__fgColorButton, 1, 1, 1, 1)

        borderLabel = QLabel('Select border color (*):', self)
        gridLayout.addWidget(borderLabel, 2, 0, 1, 1)
        self.__borderColorButton = ColorButton('', self)
        gridLayout.addWidget(self.__borderColorButton, 2, 1, 1, 1)

        verticalLayout.addLayout(gridLayout)
        verticalLayout.addWidget(
            QLabel('(*): docstrings use it only when shown as badges'))

        # Sample area
        self.__scene = QGraphicsScene()
        self.__view = QGraphicsView()
        self.__view.setScene(self.__scene)
        verticalLayout.addWidget(self.__view)

        # Buttons at the bottom
        buttonBox = QDialogButtonBox(self)
        buttonBox.setOrientation(Qt.Horizontal)
        buttonBox.setStandardButtons(QDialogButtonBox.Cancel
                                     | QDialogButtonBox.Ok)
        verticalLayout.addWidget(buttonBox)

        buttonBox.accepted.connect(self.accept)
        buttonBox.rejected.connect(self.reject)

    def __onColorChanged(self):
        """The user changed the color so redraw the sample"""
        viewWidth = self.__view.width()
        viewHeight = self.__view.height()

        self.__scene.clear()
        # without '-4' scrollbar will appear
        self.__scene.setSceneRect(0, 0, viewWidth - 4, viewHeight - 4)
        block = SampleBlock(getCflowSettings(self), self.backgroundColor(),
                            self.foregroundColor(), self.borderColor(),
                            viewWidth, viewHeight)
        self.__scene.addItem(block)
        self.__scene.update()

    def backgroundColor(self):
        """Provides the background color"""
        return self.__bgColorButton.color()

    def foregroundColor(self):
        """Provides the foreground color"""
        return self.__fgColorButton.color()

    def borderColor(self):
        """Provides the border color"""
        return self.__borderColorButton.color()