mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-20 17:50:17 +00:00
wip: split RatingClassSelector
component
This commit is contained in:
parent
f4fe7bf754
commit
accf547e90
@ -138,71 +138,7 @@
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="RatingClassRadioButton" name="pstButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">PAST</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="RatingClassRadioButton" name="prsButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">PRESENT</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="RatingClassRadioButton" name="ftrButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">FUTURE</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="RatingClassRadioButton" name="bydButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">BEYOND</string>
|
||||
</property>
|
||||
<property name="autoExclusive">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="RatingClassSelector" name="ratingClassSelector" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -238,14 +174,12 @@
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>RatingClassRadioButton</class>
|
||||
<extends>QRadioButton</extends>
|
||||
<header>ui.implements.components.ratingClassRadioButton</header>
|
||||
<class>RatingClassSelector</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>ui.implements.components.ratingClassSelector</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>bydButton</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -3,7 +3,7 @@
|
||||
################################################################################
|
||||
## Form generated from reading UI file 'chartSelector.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.5.0
|
||||
## Created by: Qt User Interface Compiler version 6.5.2
|
||||
##
|
||||
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
################################################################################
|
||||
@ -19,7 +19,7 @@ from PySide6.QtWidgets import (QApplication, QComboBox, QGroupBox, QHBoxLayout,
|
||||
QLabel, QLineEdit, QPushButton, QSizePolicy,
|
||||
QSpacerItem, QVBoxLayout, QWidget)
|
||||
|
||||
from ui.implements.components.ratingClassRadioButton import RatingClassRadioButton
|
||||
from ui.implements.components.ratingClassSelector import RatingClassSelector
|
||||
|
||||
class Ui_ChartSelector(object):
|
||||
def setupUi(self, ChartSelector):
|
||||
@ -104,45 +104,10 @@ class Ui_ChartSelector(object):
|
||||
self.horizontalLayout_2 = QHBoxLayout(self.ratingClassGroupBox)
|
||||
self.horizontalLayout_2.setSpacing(0)
|
||||
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||
self.pstButton = RatingClassRadioButton(self.ratingClassGroupBox)
|
||||
self.pstButton.setObjectName(u"pstButton")
|
||||
sizePolicy1 = QSizePolicy(QSizePolicy.Minimum, QSizePolicy.MinimumExpanding)
|
||||
sizePolicy1.setHorizontalStretch(0)
|
||||
sizePolicy1.setVerticalStretch(0)
|
||||
sizePolicy1.setHeightForWidth(self.pstButton.sizePolicy().hasHeightForWidth())
|
||||
self.pstButton.setSizePolicy(sizePolicy1)
|
||||
self.pstButton.setText(u"PAST")
|
||||
self.pstButton.setAutoExclusive(False)
|
||||
self.ratingClassSelector = RatingClassSelector(self.ratingClassGroupBox)
|
||||
self.ratingClassSelector.setObjectName(u"ratingClassSelector")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.pstButton)
|
||||
|
||||
self.prsButton = RatingClassRadioButton(self.ratingClassGroupBox)
|
||||
self.prsButton.setObjectName(u"prsButton")
|
||||
sizePolicy1.setHeightForWidth(self.prsButton.sizePolicy().hasHeightForWidth())
|
||||
self.prsButton.setSizePolicy(sizePolicy1)
|
||||
self.prsButton.setText(u"PRESENT")
|
||||
self.prsButton.setAutoExclusive(False)
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.prsButton)
|
||||
|
||||
self.ftrButton = RatingClassRadioButton(self.ratingClassGroupBox)
|
||||
self.ftrButton.setObjectName(u"ftrButton")
|
||||
sizePolicy1.setHeightForWidth(self.ftrButton.sizePolicy().hasHeightForWidth())
|
||||
self.ftrButton.setSizePolicy(sizePolicy1)
|
||||
self.ftrButton.setText(u"FUTURE")
|
||||
self.ftrButton.setAutoExclusive(False)
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.ftrButton)
|
||||
|
||||
self.bydButton = RatingClassRadioButton(self.ratingClassGroupBox)
|
||||
self.bydButton.setObjectName(u"bydButton")
|
||||
self.bydButton.setEnabled(False)
|
||||
sizePolicy1.setHeightForWidth(self.bydButton.sizePolicy().hasHeightForWidth())
|
||||
self.bydButton.setSizePolicy(sizePolicy1)
|
||||
self.bydButton.setText(u"BEYOND")
|
||||
self.bydButton.setAutoExclusive(False)
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.bydButton)
|
||||
self.horizontalLayout_2.addWidget(self.ratingClassSelector)
|
||||
|
||||
|
||||
self.mainVerticalLayout.addWidget(self.ratingClassGroupBox)
|
||||
@ -151,11 +116,11 @@ class Ui_ChartSelector(object):
|
||||
self.resultsHorizontalLayout.setObjectName(u"resultsHorizontalLayout")
|
||||
self.resultLabel = QLabel(ChartSelector)
|
||||
self.resultLabel.setObjectName(u"resultLabel")
|
||||
sizePolicy2 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
sizePolicy2.setHorizontalStretch(0)
|
||||
sizePolicy2.setVerticalStretch(0)
|
||||
sizePolicy2.setHeightForWidth(self.resultLabel.sizePolicy().hasHeightForWidth())
|
||||
self.resultLabel.setSizePolicy(sizePolicy2)
|
||||
sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
|
||||
sizePolicy1.setHorizontalStretch(0)
|
||||
sizePolicy1.setVerticalStretch(0)
|
||||
sizePolicy1.setHeightForWidth(self.resultLabel.sizePolicy().hasHeightForWidth())
|
||||
self.resultLabel.setSizePolicy(sizePolicy1)
|
||||
self.resultLabel.setText(u"...")
|
||||
self.resultLabel.setTextFormat(Qt.RichText)
|
||||
|
||||
|
@ -22,23 +22,6 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
self.db = Database()
|
||||
self.setupUi(self)
|
||||
|
||||
self.pstButton.setColors(QColor("#399bb2"), QColor("#f0f8fa"))
|
||||
self.prsButton.setColors(QColor("#809955"), QColor("#f7f9f4"))
|
||||
self.ftrButton.setColors(QColor("#702d60"), QColor("#f7ebf4"))
|
||||
self.bydButton.setColors(QColor("#710f25"), QColor("#f9ced8"))
|
||||
self.__RATING_CLASS_BUTTONS = [
|
||||
self.pstButton,
|
||||
self.prsButton,
|
||||
self.ftrButton,
|
||||
self.bydButton,
|
||||
]
|
||||
self.pstButton.clicked.connect(self.selectRatingClass)
|
||||
self.prsButton.clicked.connect(self.selectRatingClass)
|
||||
self.ftrButton.clicked.connect(self.selectRatingClass)
|
||||
self.bydButton.clicked.connect(self.selectRatingClass)
|
||||
self.deselectAllRatingClassButtons()
|
||||
self.updateRatingClassButtonsEnabled([])
|
||||
|
||||
self.previousPackageButton.clicked.connect(
|
||||
lambda: self.quickSwitchSelection("previous", "package")
|
||||
)
|
||||
@ -71,10 +54,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
self.packageComboBox.setItemDelegate(DescriptionDelegate(self.packageComboBox))
|
||||
self.songIdComboBox.setItemDelegate(DescriptionDelegate(self.songIdComboBox))
|
||||
|
||||
self.pstButton.toggled.connect(self.valueChanged)
|
||||
self.prsButton.toggled.connect(self.valueChanged)
|
||||
self.ftrButton.toggled.connect(self.valueChanged)
|
||||
self.bydButton.toggled.connect(self.valueChanged)
|
||||
self.ratingClassSelector.valueChanged.connect(self.valueChanged)
|
||||
self.packageComboBox.currentIndexChanged.connect(self.valueChanged)
|
||||
self.songIdComboBox.currentIndexChanged.connect(self.valueChanged)
|
||||
|
||||
@ -104,7 +84,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
def value(self):
|
||||
packageId = self.packageComboBox.currentData()
|
||||
songId = self.songIdComboBox.currentData()
|
||||
ratingClass = self.selectedRatingClass()
|
||||
ratingClass = self.ratingClassSelector.value()
|
||||
|
||||
if packageId and songId and isinstance(ratingClass, int):
|
||||
return self.db.get_chart(songId, ratingClass)
|
||||
@ -185,11 +165,11 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
|
||||
@Slot(int)
|
||||
def on_songIdComboBox_currentIndexChanged(self, index: int):
|
||||
rating_classes = []
|
||||
ratingClasses = []
|
||||
if index > -1:
|
||||
charts = self.db.get_charts_by_song_id(self.songIdComboBox.currentData())
|
||||
rating_classes = [chart.rating_class for chart in charts]
|
||||
self.updateRatingClassButtonsEnabled(rating_classes)
|
||||
ratingClasses = [chart.rating_class for chart in charts]
|
||||
self.ratingClassSelector.setButtonsEnabled(ratingClasses)
|
||||
|
||||
@Slot()
|
||||
def on_resetButton_clicked(self):
|
||||
@ -219,7 +199,7 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
# QMessageBox
|
||||
return
|
||||
|
||||
self.selectRatingClass(chart.rating_class)
|
||||
self.ratingClassSelector.select(chart.rating_class)
|
||||
|
||||
@Slot(QModelIndex)
|
||||
def fuzzySearchCompleterSetSelection(self, index: QModelIndex):
|
||||
@ -228,35 +208,3 @@ class ChartSelector(Ui_ChartSelector, QWidget):
|
||||
|
||||
self.fuzzySearchLineEdit.clear()
|
||||
self.fuzzySearchLineEdit.clearFocus()
|
||||
|
||||
def ratingClassButtons(self):
|
||||
return self.__RATING_CLASS_BUTTONS
|
||||
|
||||
def selectedRatingClass(self):
|
||||
for i, button in enumerate(self.__RATING_CLASS_BUTTONS):
|
||||
if button.isChecked():
|
||||
return i
|
||||
|
||||
def updateRatingClassButtonsEnabled(self, rating_classes: list[int]):
|
||||
for i, button in enumerate(self.__RATING_CLASS_BUTTONS):
|
||||
if i in rating_classes:
|
||||
button.setEnabled(True)
|
||||
else:
|
||||
button.setChecked(False)
|
||||
button.setEnabled(False)
|
||||
|
||||
def deselectAllRatingClassButtons(self):
|
||||
[button.setChecked(False) for button in self.__RATING_CLASS_BUTTONS]
|
||||
|
||||
@Slot()
|
||||
def selectRatingClass(self, rating_class: int | None = None):
|
||||
if type(rating_class) == int and rating_class in range(4):
|
||||
self.deselectAllRatingClassButtons()
|
||||
button = self.__RATING_CLASS_BUTTONS[rating_class]
|
||||
if button.isEnabled():
|
||||
button.setChecked(True)
|
||||
else:
|
||||
button = self.sender()
|
||||
if isinstance(button, RatingClassRadioButton) and button.isEnabled():
|
||||
self.deselectAllRatingClassButtons()
|
||||
button.setChecked(True)
|
||||
|
100
ui/implements/components/ratingClassSelector.py
Normal file
100
ui/implements/components/ratingClassSelector.py
Normal file
@ -0,0 +1,100 @@
|
||||
from typing import Type
|
||||
|
||||
from PySide6.QtCore import Signal
|
||||
from PySide6.QtGui import QColor
|
||||
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget
|
||||
|
||||
from ui.implements.components.ratingClassRadioButton import RatingClassRadioButton
|
||||
|
||||
|
||||
class RatingClassSelector(QWidget):
|
||||
valueChanged = Signal()
|
||||
selected = Signal(int)
|
||||
|
||||
def __init__(
|
||||
self, parent=None, layout: Type[QHBoxLayout] | Type[QVBoxLayout] = QHBoxLayout
|
||||
):
|
||||
super().__init__(parent)
|
||||
|
||||
self.preferredLayout = layout(self)
|
||||
self.preferredLayout.setSpacing(0)
|
||||
|
||||
self.pstButton = RatingClassRadioButton(self)
|
||||
self.pstButton.setObjectName("self.pstButton")
|
||||
self.pstButton.setText("PAST")
|
||||
self.pstButton.setAutoExclusive(False)
|
||||
self.preferredLayout.addWidget(self.pstButton)
|
||||
|
||||
self.prsButton = RatingClassRadioButton(self)
|
||||
self.prsButton.setObjectName("self.prsButton")
|
||||
self.prsButton.setText("PRESENT")
|
||||
self.prsButton.setAutoExclusive(False)
|
||||
self.preferredLayout.addWidget(self.prsButton)
|
||||
|
||||
self.ftrButton = RatingClassRadioButton(self)
|
||||
self.ftrButton.setObjectName("self.ftrButton")
|
||||
self.ftrButton.setText("FUTURE")
|
||||
self.ftrButton.setAutoExclusive(False)
|
||||
self.preferredLayout.addWidget(self.ftrButton)
|
||||
|
||||
self.bydButton = RatingClassRadioButton(self)
|
||||
self.bydButton.setObjectName("self.bydButton")
|
||||
self.bydButton.setText("BEYOND")
|
||||
self.bydButton.setAutoExclusive(False)
|
||||
self.preferredLayout.addWidget(self.bydButton)
|
||||
|
||||
self.buttons = [self.pstButton, self.prsButton, self.ftrButton, self.bydButton]
|
||||
self.pstButton.setColors(QColor("#399bb2"), QColor("#f0f8fa"))
|
||||
self.prsButton.setColors(QColor("#809955"), QColor("#f7f9f4"))
|
||||
self.ftrButton.setColors(QColor("#702d60"), QColor("#f7ebf4"))
|
||||
self.bydButton.setColors(QColor("#710f25"), QColor("#f9ced8"))
|
||||
|
||||
self.pstButton.clicked.connect(self.select)
|
||||
self.prsButton.clicked.connect(self.select)
|
||||
self.ftrButton.clicked.connect(self.select)
|
||||
self.bydButton.clicked.connect(self.select)
|
||||
self.reset()
|
||||
self.setButtonsEnabled([])
|
||||
|
||||
def value(self):
|
||||
for i, button in enumerate(self.buttons):
|
||||
if button.isChecked():
|
||||
return i
|
||||
return None
|
||||
|
||||
def reset(self):
|
||||
for button in self.buttons:
|
||||
button.setChecked(False)
|
||||
self.valueChanged.emit()
|
||||
|
||||
def setButtonsEnabled(self, ratingClasses: list[int]):
|
||||
for i, button in enumerate(self.buttons):
|
||||
if i in ratingClasses:
|
||||
button.setEnabled(True)
|
||||
else:
|
||||
button.setChecked(False)
|
||||
button.setEnabled(False)
|
||||
self.valueChanged.emit()
|
||||
|
||||
def select(self, ratingClass: int | bool | None = None):
|
||||
if not (
|
||||
type(ratingClass) == int
|
||||
or type(ratingClass) == bool
|
||||
or ratingClass is not None
|
||||
):
|
||||
return
|
||||
|
||||
if ratingClass is None or isinstance(ratingClass, bool):
|
||||
button = self.sender()
|
||||
elif ratingClass in range(4):
|
||||
button = self.buttons[ratingClass]
|
||||
else:
|
||||
return
|
||||
|
||||
if not button.isEnabled():
|
||||
return
|
||||
|
||||
self.reset()
|
||||
button.setChecked(True)
|
||||
self.valueChanged.emit()
|
||||
self.selected.emit(self.buttons.index(button))
|
Loading…
x
Reference in New Issue
Block a user