class Foldable(QWidget): _mainLayout: QGridLayout _toggleButton: QToolButton _headerLine: QFrame _contentArea: QScrollArea _folded: bool def __init__(self, title: str, initially_folded: bool = True, parent: QWidget = None): super().__init__(parent) self._folded = initially_folded self._toggleButton = QToolButton(self) self._toggleButton.setStyleSheet("QToolButton { height: 20px; }") font = self._toggleButton.font() font.setBold(True) font.setPixelSize(13) self._toggleButton.setFont(font) self._toggleButton.setMaximumHeight(20) self._toggleButton.setToolButtonStyle( Qt.ToolButtonStyle.ToolButtonTextBesideIcon) self._toggleButton.setArrowType(Qt.ArrowType.RightArrow) self._toggleButton.setText(title) self._toggleButton.setCheckable(True) self._toggleButton.setChecked(False) self._toggleButton.clicked.connect(self._on_click) self._headerLine = QFrame(self) self._headerLine.setFrameShape(QFrame.HLine) self._headerLine.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self._contentArea = QFrame(self) self._contentArea.setObjectName("foldable_contentArea") self._contentArea.setStyleSheet( "#foldable_contentArea { border: none; }") self._contentArea.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) self._mainLayout = QGridLayout(self) self._mainLayout.setVerticalSpacing(0) self._mainLayout.setContentsMargins(0, 0, 0, 0) self._mainLayout.addWidget(self._toggleButton, 0, 0, 1, 1, Qt.AlignLeft) self._mainLayout.addWidget(self._headerLine, 0, 1, 1, 1) self._mainLayout.addWidget(self._contentArea, 1, 0, 1, 2) @property def contents(self): return self._contentArea def _on_click(self, checked: bool): if self._folded: self._unfold() else: self._fold() def _unfold(self): self._folded = False self._contentArea.show() self._toggleButton.setArrowType(Qt.ArrowType.DownArrow) def _fold(self): self._folded = True self._contentArea.hide() self._toggleButton.setArrowType(Qt.ArrowType.RightArrow) def set_content_layout(self, content_layout: QLayout): self._contentArea.setLayout(content_layout) if self._folded: self._fold() else: self._unfold()
def __init__(self, result, parent=None): # Popup when "Add song to playlist" is clicked on # How this works is a QWidget that encompasses the entire window area, representing an unclickable translucent background. # Another QWidget is then contained inside that QWidget representing the popup. # result: (dict) Python dict containing information of the song clicked QWidget.__init__(self) self.setParent(parent) self.result = result # Signals are used to indicate to close the window self.SIGNALS = self.TranslucentWidgetSignals() # Make the window frameless and expanding. self.setWindowFlags(Qt.FramelessWindowHint) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) # Makes the window background colour translucent self.setAttribute(Qt.WA_StyledBackground) self.setStyleSheet( "PlaylistPopup { background-color: rgba(255, 255, 255, 0.5)}") # Sets the grid settings of the "background" and the "popup" layout = QGridLayout() layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) playlistAdd = QWidget(self) playlistAdd.setFixedSize(800, 300) playlistAdd.setStyleSheet( ".QWidget { background-color: rgba(255, 255, 255, 1)}") innerLayout = QGridLayout() innerLayout.setContentsMargins(20, 20, 20, 20) innerLayout.setSpacing(30) # Heading font font = QFont() font.setPointSize(24) # Default label font font2 = QFont() font2.setPointSize(16) # Heading label = QLabel("添加到播放列表/Add to Playlist", self) label.setAlignment(Qt.AlignCenter) label.setFont(font) innerLayout.addWidget(label, 0, 0) # Playlist selection self.comboBox = QComboBox(self) self.comboBox.setFont(font) playlists = DB.getPlaylists("") for playlist in playlists: self.comboBox.addItem(playlist["playlist_name"]) self.comboBox.setCurrentIndex(-1) innerLayout.addWidget(self.comboBox, 1, 0) # Textbox to create a new playlist self.textBox = QLineEdit(self) self.textBox.setFont(font2) self.textBox.setAlignment(Qt.AlignCenter) self.textBox.setPlaceholderText( "输入以创建新的播放列表/Type to create a new playlist") self.textBox.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Fixed) # TODO: resize textbox with window self.textBox.setFixedWidth(760) innerLayout.addWidget(self.textBox, 2, 0, Qt.AlignCenter) # Add actions for then the QComboBox or QLineEdit is changed. # This is done so there is only one action between "Add to existing Playlist" or "Add to new Playlist" self.comboBox.currentIndexChanged.connect(self.comboBoxChanged) self.textBox.textEdited.connect(self.textBoxChanged) # Confirm button confirmButton = QToolButton(self) confirmButton.setText("确认/Confirm") confirmButton.setFont(font) confirmButton.clicked.connect(self.processPlaylistRequest) innerLayout.addWidget(confirmButton, 3, 0, Qt.AlignCenter) # Exit button btn = QToolButton(self) btn.setFixedSize(44, 44) btn.setText("X") btn.setFont(font) btn.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) btn.clicked.connect(lambda: self.SIGNALS.CLOSE.emit()) innerLayout.addWidget(btn, 0, 0, Qt.AlignRight) playlistAdd.setLayout(innerLayout) layout.addWidget(playlistAdd, 0, 0, Qt.AlignCenter) self.setLayout(layout)
def __init__(self, heading, parent=None, counter=0, pastResults={}, grid=False): QWidget.__init__(self) self.setParent(parent) self.heading = heading self.counter = counter self.pastResults = pastResults # Set layout and spacings layout = QGridLayout() # The heading of the widget label = QLabel(heading) label.setAlignment(Qt.AlignCenter) label.setFixedHeight(40) # TODO: Change with global themes label.setStyleSheet("color: white;") # Font for the label font = QFont() font.setPixelSize(25) font.setBold(True) label.setFont(font) layout.addWidget(label, 0, 0) # Add back button if self.counter: backButton = QToolButton() backButton.setText("🡸") font = QFont() font.setPointSize(30) backButton.setFont(font) backButton.setFixedSize(QSize(40, 40)) backButton.setAutoRaise(True) backButton.setStyleSheet( "QToolButton { color: white; background-color: transparent;} QToolButton:pressed {background-color: rgba(255, 255, 255, 0.1);}" ) layout.addWidget(backButton, 0, 0) backButton.clicked.connect(self.goBack) # Sub heading if this is an indepth search sublabel = QLabel() sublabel.setFixedHeight(20) if self.pastResults: sublabel.setAlignment(Qt.AlignCenter) # TODO: Change with global themes sublabel.setStyleSheet("color: white;") if "artist_id" in self.pastResults: sublabel.setText("Artist: " + self.pastResults["artist_name"]) elif "language_id" in self.pastResults: sublabel.setText("Language: " + self.pastResults["language_name"]) elif "playlist_id" in self.pastResults: sublabel.setText("Playlist: " + self.pastResults["playlist_name"]) font = QFont() font.setPixelSize(15) font.setItalic(True) sublabel.setFont(font) layout.addWidget(sublabel, 1, 0) # Set searchbar self.searchBar = QLineEdit(self) # TODO: change with resizeEvent self.searchBar.setMinimumWidth(800) font = QFont() font.setPointSize(20) self.searchBar.setFont(font) layout.addWidget(self.searchBar, 2, 0) layout.setAlignment(self.searchBar, Qt.AlignCenter) # Set results page if (grid): self.results = self.ResultsGrid(self) layout.addWidget(self.results, 3, 0) else: self.results = self.ResultsList(self) layout.addWidget(self.results, 3, 0) self.searchBar.textEdited.connect(self.updateResults) self.updateResults() self.setLayout(layout)
def createItem(self): # Create a song item # Add Space to the beginning of the item labelQueue = self.formattedLabel(QLabel("", self)) labelQueue.setFixedWidth(70) labelQueue.setAlignment(Qt.AlignCenter) self.layout.addWidget(labelQueue) # Artist name labelArtist = self.formattedLabel( QLabel(self.song["artist_name"])) labelArtist.setFixedWidth(300) self.layout.addWidget(labelArtist) # Song Title labelTitle = self.formattedLabel( QLabel(self.song["song_title"])) self.layout.addWidget(labelTitle) # Set font (icon) size font = QFont() font.setPointSize(48) # Add buttons for queue-specific actions # Move the song up the queue btnMoveUp = QToolButton() btnMoveUp.setText("▲") btnMoveUp.setFixedSize(70, 70) btnMoveUp.setStyleSheet("color: white") btnMoveUp.setFont(font) btnMoveUp.clicked.connect(self.moveUp) self.layout.addWidget(btnMoveUp) # Move the song down the queue btnMoveDown = QToolButton() btnMoveDown.setText("▼") btnMoveDown.setFixedSize(70, 70) btnMoveDown.setStyleSheet("color: white") btnMoveDown.setFont(font) btnMoveDown.clicked.connect(self.moveDown) self.layout.addWidget(btnMoveDown) # Move the song to the top of the queue btnMoveTop = QToolButton() btnMoveTop.setText("⍏") btnMoveTop.setFixedSize(70, 70) btnMoveTop.setStyleSheet("color: white") btnMoveTop.setFont(font) btnMoveTop.clicked.connect(self.moveTop) self.layout.addWidget(btnMoveTop) # Play the song immediately btnPlay = QToolButton() btnPlay.setText("➤") btnPlay.setFixedSize(70, 70) btnPlay.setStyleSheet("color: white") btnPlay.setFont(font) btnPlay.clicked.connect(self.playSong) self.layout.addWidget(btnPlay) # Remove the song from the queue btnRemove = QToolButton() btnRemove.setText("X") btnRemove.setFixedSize(70, 70) btnRemove.setStyleSheet("color: white") btnRemove.setFont(font) btnRemove.clicked.connect(self.removeSong) self.layout.addWidget(btnRemove)