def keyPressEvent(self, event):
        # preflight | suppress if over header
        is_child_of_header = TansuModelViewWidget.isWidgetUnderCursorChildOfHeader(
        )
        if is_child_of_header:
            tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)

            return tab_tansu_widget.headerWidget().keyPressEvent(event)

        # Tansu functions
        TansuBaseWidget.keyPressEvent(self, event)

        # Global escape
        if event.key() == Qt.Key_Escape:
            tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)
            if tab_tansu_widget:
                tab_tansu_widget.updateDelegateDisplay()
                tab_tansu_widget.toggleDelegateSpacerWidget()

        # TODO TOGGLE DELEGATE KEY
        # This is also maintained under the TansuHeader

        tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)
        if event.key() in tab_tansu_widget.TOGGLE_DELEGATE_KEYS:
            header_widget = tab_tansu_widget.headerWidget()
            if not header_widget.delegateWidgetAlwaysOn():
                header_widget.toggleDelegateWidget(event)
Esempio n. 2
0
    def drawGradient(self):
        """
        Draws the gradient that will be displayed to the user
        """

        _gradient = draw.drawColorTypeGradient(self.gradient_type, self.width(), self.height())
        direction = self.linearCrosshairDirection()
        self.rgba_foreground.hide()

        # show gradient for RGBA gradient
        if self.gradient_type == attrs.RGBA:
            """
            for some reason the darker it gets the harder of a time the picker has
            and the steps become larger and larger =/
            """
            # get value
            main_widget = getWidgetAncestor(self.views()[0], ColorGradientDelegate)
            value = main_widget.color().valueF()
            self.rgba_foreground.updateSize(QRectF(0, 0, self.width(), self.height()))
            self.rgba_foreground.updateGradient(value, self.width(), self.height())

            self.rgba_foreground.show()

        # update linear gradient
        else:
            if direction == Qt.Horizontal:
                _gradient.setFinalStop(QPoint(self.width(), 0))
            elif direction == Qt.Vertical:
                # TODO Move this to draw utils (gradient inversion)
                _gradient.setStart(QPoint(0, self.height()))
                _gradient.setFinalStop(QPoint(0, 0))

        self.setBackgroundBrush(QBrush(_gradient))
Esempio n. 3
0
    def mouseReleaseEvent(self, *args, **kwargs):
        # reset everything back to default state

        # reset gradient
        self.__hideRGBACrosshair(False)
        self.__hideLinearCrosshair(True)
        self.scene().gradient_type = attrs.RGBA
        self.scene().drawGradient()

        # reset picking attrs
        self._picking = False
        self._black_select = False

        # reset cursor
        self.unsetCursor()
        QCursor.setPos(self._orig_pos)

        # disable labels
        color_gradient_widget = getWidgetAncestor(self, ColorGradientDelegate)
        color_arg_widgets_dict = color_gradient_widget.header_widget.getWidgetDict()
        for color_arg in color_arg_widgets_dict:
            color_arg_widgets_dict[color_arg].setSelected(False)

        # update rgba crosshair pos
        self.scene().updateRGBACrosshair()

        return QGraphicsView.mouseReleaseEvent(self, *args, **kwargs)
 def selectionChanged(self, selected, deselected):
     top_level_widget = getWidgetAncestor(self, TansuModelViewWidget)
     if top_level_widget:
         # for index in selected.indexes():
         #     if index.column() == 0:
         #         print(index.internalPointer().columnData()['name'])
         top_level_widget.updateDelegateDisplayFromSelection(
             selected, deselected)
Esempio n. 5
0
    def updateUserInputItem(self, *args):
        try:
            widget = getWidgetAncestor(self, TansuModelDelegateWidget)
            widget.item().columnData()['value'] = self.text()

            # add user input event
            widget.item().userInputEvent(self.text())

        except AttributeError:
            pass
Esempio n. 6
0
 def updateUserInputItem(self, *args):
     """
     When the user inputs text, this will update the model item
     """
     try:
         widget = getWidgetAncestor(self, TansuModelDelegateWidget)
         widget.item().columnData()['value'] = self.getInput()
         widget.item().userInputEvent(self.getInput())
     except AttributeError:
         pass
    def keyPressEvent(self, event):
        # TODO TOGGLE DELEGATE KEY
        # tansu hotkeys esc/~
        tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)
        if event.key() in tab_tansu_widget.TOGGLE_DELEGATE_KEYS:
            header_widget = tab_tansu_widget.headerWidget()
            if not header_widget.delegateWidgetAlwaysOn():
                header_widget.toggleDelegateWidget(event)

        return AbstractDragDropAbstractView.keyPressEvent(self, event)
Esempio n. 8
0
    def _getColor(self, event):
        """
        Gets the color from the user selection and sends it to the
        setColor on the main widget ( ColorInputWidget )

        """
        # get attrs
        delegate = getWidgetAncestor(self, ColorGradientDelegate)
        selection_type = self.scene().gradient_type

        # 2D Gradient
        if selection_type == attrs.RGBA:
            # RGBA (HUE / SATURATION)
            color = self._getRGBAValue(event)
            delegate.setColor(color)
            return

        # Linear Gradient
        else:
            self.scene().linear_crosshair_item.setCrosshairPos(event.pos())

            pos = event.globalPos()
            orig_color = delegate.color()
            new_color = self._pickColor(pos)
            # TODO DUPLICATE SET COLOR VALUE FROM ARG
            """ TODO UPDATE COLOR"""
            # saturation
            if selection_type == attrs.SATURATION:
                hue = orig_color.hueF()
                sat = new_color.valueF()
                value = orig_color.valueF()

                orig_color.setHsvF(hue, sat, value)
            # value
            elif selection_type == attrs.VALUE:
                # get HSV values
                hue = orig_color.hueF()
                sat = orig_color.saturationF()
                value = new_color.valueF()
                orig_color.setHsvF(hue, sat, value)
            # red
            elif selection_type == attrs.RED:
                red = new_color.redF()
                orig_color.setRedF(red)
            # green
            elif selection_type == attrs.GREEN:
                green = new_color.greenF()
                orig_color.setGreenF(green)
            # blue
            elif selection_type == attrs.BLUE:
                blue = new_color.blueF()
                orig_color.setBlueF(blue)

            delegate.setColor(orig_color)
            return
Esempio n. 9
0
    def updateUserInputItem(self, *args):
        try:
            widget = getWidgetAncestor(self, TansuModelDelegateWidget)
            widget.item().setValue(self.currentText())

            # add user input event
            widget.item().userInputEvent(self.currentText())

        except AttributeError:

            pass
    def dropEvent(self, event):
        # resolve drop event
        return_val = super(self.__class__, self).dropEvent(event)

        # get main widget
        main_widget = getWidgetAncestor(self, TansuModelViewWidget)

        # clear selection
        main_widget.delegateWidget().displayAllWidgets(False)
        self.selectionModel().clearSelection()

        return return_val
Esempio n. 11
0
    def updateUserInputItem(self, *args):
        """
        When the user clicks on this
        """
        try:
            widget = getWidgetAncestor(self, TansuModelDelegateWidget)
            widget.item().columnData()['value'] = self.is_clicked
            self.is_clicked = self.is_clicked

            # add user input event
            widget.item().userInputEvent(self.is_clicked)
        except AttributeError:
            pass
    def keyPressEvent(self, event):
        """
        Note duplicate to view...

         must it be duplicate?
        :param event:
        :return:
        """
        # TODO TOGGLE DELEGATE KEY
        # this is also maintained under... TansuMainDelegateWidget
        tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)
        if event.key() in tab_tansu_widget.TOGGLE_DELEGATE_KEYS:
            if not self.delegateWidgetAlwaysOn():
                self.toggleDelegateWidget(event)
 def showEvent(self, event):
     tab_tansu_widget = getWidgetAncestor(self, TansuModelViewWidget)
     if tab_tansu_widget:
         tab_tansu_widget.updateDelegateDisplay()
 def isWidgetUnderCursorChildOfHeader():
     pos = QCursor.pos()
     widget_pressed = qApp.widgetAt(pos)
     is_child_of_header = getWidgetAncestor(widget_pressed, TansuHeader)
     return True if is_child_of_header else False
Esempio n. 15
0
 def updateRGBACrosshair(self):
     main_widget = getWidgetAncestor(self, ColorGradientDelegate)
     xpos = (main_widget.color().hueF() * self.width())
     ypos = math.fabs((main_widget.color().saturationF() * self.height()) - self.height())
     pos = QPoint(xpos, ypos)
     self.setRGBACrosshairPos(pos)
Esempio n. 16
0
    def mousePressEvent(self, event, *args, **kwargs):
        """
        Attrs:
            _picking (bool): tells the widget that the user is now attempting
                to pick a value
            _in_gradient_widget (bool) tells the widget that the cursor is
                in the gradient widget
        """
        modifiers = QApplication.keyboardModifiers()
        button = event.button()
        if button in [Qt.LeftButton, Qt.RightButton, Qt.MiddleButton]:
            # move rgba

            # HSV
            self._picking = True
            self._black_select = False
            self._in_gradient_widget = True
            self._orig_pos = QCursor.pos()
            # setup default crosshair
            self.__hideRGBACrosshair(True)
            self.__hideLinearCrosshair(False)

            # RGB
            main_widget = getWidgetAncestor(self, ColorGradientDelegate)
            color = main_widget.color()
            pos = QPoint(0, 0)

            # TODO Check hack after upgrading to 5.15
            # katana is not registering the alt + mmb?
            if modifiers in [Qt.AltModifier, Qt.ControlModifier]:
                # RED
                if button == Qt.LeftButton:
                    pos = QPoint(color.redF() * self.width(), color.redF() * self.height())
                    self.scene().gradient_type = attrs.RED
                # GREEN
                elif button == Qt.MiddleButton:
                    pos = QPoint(color.greenF() * self.width(), color.greenF() * self.height())
                    self.scene().gradient_type = attrs.GREEN
                # BLUE
                elif button == Qt.RightButton:
                    pos = QPoint(color.blueF() * self.width(), color.blueF() * self.height())
                    self.scene().gradient_type = attrs.BLUE

            # HSV
            else:
                if button == Qt.LeftButton:
                    self.__hideRGBACrosshair(False)
                    self.__hideLinearCrosshair(True)
                    self.scene().gradient_type = attrs.RGBA
                # VALUE
                elif button == Qt.MiddleButton:
                    pos = QPoint(color.valueF() * self.width(), color.valueF() * self.height())
                    self.scene().gradient_type = attrs.VALUE
                # SATURATION
                elif button == Qt.RightButton:
                    pos = QPoint(color.saturationF() * self.width(), color.saturationF() * self.height())
                    self.scene().gradient_type = attrs.SATURATION

            # update display label to show selected value
            color_gradient_widget = getWidgetAncestor(self, ColorGradientDelegate)
            color_arg_widgets_dict = color_gradient_widget.header_widget.getWidgetDict()
            if self.scene().gradient_type != attrs.RGBA:
                color_arg_widgets_dict[self.scene().gradient_type].setSelected(True)

            # draw gradient / hide cursor
            self.scene().drawGradient()

            # set up cursor
            self.setCursor(Qt.BlankCursor)
            if pos:
                self.scene().linear_crosshair_item.setCrosshairPos(pos)
                QCursor.setPos(self.mapToGlobal(pos))

        return QGraphicsView.mousePressEvent(self, event, *args, **kwargs)