aboutsummaryrefslogtreecommitdiffstats
path: root/SoundsListWidget.py
blob: 540103e6fa22d2880a007a39d03c186ca474819c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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)