diff options
Diffstat (limited to 'SoundsListWidget.py')
| -rw-r--r-- | SoundsListWidget.py | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/SoundsListWidget.py b/SoundsListWidget.py new file mode 100644 index 0000000..540103e --- /dev/null +++ b/SoundsListWidget.py @@ -0,0 +1,99 @@ +# Soundboard Engine - customizable soundboard +# Copyright (C) 2026 Vidhu Kant Sharma <vidhukant@vidhukant.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +from PySide6.QtCore import Signal +from PySide6.QtGui import Qt +from PySide6.QtWidgets import ( + QHBoxLayout, + QLabel, + QPushButton, + QScrollArea, + QVBoxLayout, + QWidget, +) + +from Soundboard import SoundboardCategory, SoundboardSound +from SoundListItemWidget import SoundListItemWidget + + +class SoundsListWidget(QWidget): + back_requested = Signal() + play_requested = Signal(SoundboardSound) + + def __init__(self, parent=None): + super().__init__(parent) + + layout = QVBoxLayout(self) + layout.setContentsMargins(0, 0, 0, 0) + + header_layout = QHBoxLayout() + header_layout.setContentsMargins(12, 8, 12, 8) + + self.title_label = QLabel() + font = self.title_label.font() + font.setBold(True) + font.setPointSize(13) + self.title_label.setFont(font) + header_layout.addWidget(self.title_label, stretch=1) + + self.back_btn = QPushButton("Back") + self.back_btn.clicked.connect(self.back_requested.emit) + header_layout.addWidget(self.back_btn) + + layout.addLayout(header_layout) + + self.scroll_area = QScrollArea() + self.scroll_area.setWidgetResizable(True) + self.scroll_area.setVerticalScrollBarPolicy( + Qt.ScrollBarPolicy.ScrollBarAlwaysOn + ) + self.scroll_area.setFrameShape(QScrollArea.Shape.NoFrame) + self.scroll_area.setStyleSheet(""" + QScrollArea { + border: 1px solid palette(shadow); + } + """) + + self.list_container = QWidget() + self.list_container.setObjectName("whitebg") + self.list_container.setStyleSheet(""" + #whitebg { + background-color: palette(light); + } + """) + self.list_layout = QVBoxLayout(self.list_container) + self.list_layout.setAlignment(Qt.AlignmentFlag.AlignTop) + self.list_layout.setSpacing(0) + self.list_layout.setContentsMargins(0, 0, 0, 0) + + self.scroll_area.setWidget(self.list_container) + + layout.addWidget(self.scroll_area, stretch=1) + + def load_category(self, category: SoundboardCategory): + self.category = category + self.title_label.setText(f"All {self.category.name} sounds") + + while self.list_layout.count(): + item = self.list_layout.takeAt(0) + widget = item.widget() + if widget: + widget.deleteLater() + + for sound in self.category.sounds: + _sound = SoundListItemWidget(sound) + _sound.play_requested.connect(self.play_requested.emit) + self.list_layout.addWidget(_sound) |