Ejemplo n.º 1
0
 def add_input_row(self, form, n=1):
     """ Adds n amount of input rows to the form. """
     for _ in range(n):
         l = QtGui.QHBoxLayout()
         service_combo = QtGui.QComboBox()
         service_combo.insertItem(0, get_service_icon(SERVICE_TWITCH), "", SERVICE_TWITCH)
         # service_combo.insertItem(0, get_service_icon(SERVICE_OWN3D), "", SERVICE_OWN3D)
         # service_combo.insertItem(0, get_service_icon(SERVICE_JUSTIN), "", SERVICE_JUSTIN)
         stream_id_edit = QtGui.QLineEdit()
         l.addWidget(stream_id_edit)
         l.addWidget(service_combo)
         form.addRow("Stream", l)
Ejemplo n.º 2
0
    def paint(self, painter, option, index):
        """
        Re-implementation of the paint method. 
        This will render a stream item that contains an icon, the name, 
        a description, the game being played, and a dropdown menu.
        """
        super(StreamItemDelegate, self).paint(painter, option, index)
        stream = index.data()

        if option.state & QStyle.State_MouseOver:
            painter.fillRect(option.rect, option.palette.color(QPalette.Highlight))
            painter.setPen(Qt.white)
        else:
            painter.setPen(Qt.black)

        # I'll have a rectangle pls.
        r = option.rect

        # Draw the Service icon (Twitch, etc)
        icon = get_service_icon(stream.service)
        icon_size = 16
        icon_offset = (r.height()/2) - (icon_size/2)
        if stream.status == 0: #offline
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Disabled) 
        else:
            icon.paint(painter, r.left()+10, r.top()+icon_offset, icon_size, icon_size, Qt.AlignLeft | Qt.AlignVCenter, mode=QIcon.Normal) 

        # Paint the stream name
        painter.drawText(r.left()+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.name)

        # Paint the game name, if any.
        painter.save()
        name_len = painter.fontMetrics().width(stream.name)
        font = painter.font()
        font.setPixelSize(9)
        font.setItalic(True)
        painter.setFont(font)
        painter.setPen(QColor(*get_game_colour(stream.game)))
        # Position of the left edge + the length of the name text + the offset of the stream name + an additional offset for padding.
        painter.drawText((r.left()+name_len)+40, r.top()-8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.game)
        painter.restore()

        # Paint a dropdown button for options.
        x1 = 50; y1 = 8; iw = 9; ih = 6; 
        orect = r.adjusted(name_len+x1, y1, -(r.width()-(name_len+x1+iw)), -(r.height()-(y1+ih))) # Rectangle to store the dropdown icon
        hrect = orect.adjusted(-4, -3, 6, 5) # Rectangle to hover within.
        hbg = orect.adjusted(-2, -1, 2, 1) # Rectangle to draw the rounded background in
        options_button = QStyleOptionButton()
        # Cursor must be translated to relative positioning via the parent widget, note that is this is not a widget.
        if hrect.contains(self.parent.mapFromGlobal(QCursor.pos())):
            # Hover event for the dropdown options button
            options_button.icon = self.icons["down_hover"]
            # Draw a background behind the icon
            painter.save()
            painter.setRenderHints(painter.Antialiasing | painter.HighQualityAntialiasing)
            painter.setPen(QPen(QColor(101, 99, 98)))
            painter.setBrush(QBrush(QColor(101, 99, 98)))
            painter.drawRoundRect(QRectF(hbg), 10.0, 5.0)
            painter.restore()
        else:
            options_button.icon = self.icons["down_default"]
        options_button.iconSize = QSize(iw, ih)
        options_button.rect = orect
        options_button.features = QStyleOptionButton.Flat
        # Paint a Push Button Control.
        QApplication.style().drawControl(QStyle.CE_PushButton, options_button, painter)
         
        # Paint the description/status?
        painter.save()
        if stream.status == 0: #offline
            painter.setPen(Qt.darkGray)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, "Offline")
        else:
            painter.setPen(Qt.darkGreen)
            painter.drawText(r.left()+40, r.top()+8, r.width(), r.height(), Qt.AlignVCenter | Qt.AlignLeft, stream.channel.status)
        painter.restore()