# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'favourite_setting.ui'
#
# Created by: PyQt5 UI code generator 5.15.1
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_widget(object):
    def setupUi(self, widget, key, settings):
        self.key = key
        self.settings = settings
        self.current_value = float(self.settings.value(key, 0))
        widget.setObjectName("widget")
        widget.resize(600, 45)
        widget.setStyleSheet("#widget {\n"
                             "    background: black;\n"
                             "    border-bottom: 1px solid #CCC\n"
                             "}\n"
                             "\n"
                             "* {\n"
                             "    color: white\n"
                             "}")
        self.label_title = QtWidgets.QLabel(widget)
        self.label_title.setGeometry(QtCore.QRect(20, 10, 390, 25))
        font = QtGui.QFont()
        font.setFamily("Montserrat")
        font.setPointSize(14)
        self.label_title.setFont(font)
        self.label_title.setStyleSheet("")
        self.label_title.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter)
        self.label_title.setObjectName("label_title")
        self.frequency_box = QtWidgets.QWidget(widget)
        self.frequency_box.setEnabled(True)
        self.frequency_box.setGeometry(QtCore.QRect(415, 7, 130, 30))
        self.frequency_box.setStyleSheet("#frequency_box {\n"
                                         "    background: #252525; color: white\n"
                                         "}\n"
                                         "\n"
                                         "#frequency_box::hover {\n"
                                         "    background: #303030;\n"
                                         "}")
        self.frequency_box.setObjectName("frequency_box")
        self.label_frequency = QtWidgets.QLabel(self.frequency_box)
        self.label_frequency.setGeometry(QtCore.QRect(40, 5, 50, 20))
        font = QtGui.QFont()
        font.setFamily("Montserrat")
        font.setPointSize(13)
        self.label_frequency.setFont(font)
        self.label_frequency.setStyleSheet("")
        self.label_frequency.setAlignment(QtCore.Qt.AlignCenter)
        self.label_frequency.setObjectName("label_frequency")
        self.btn_decrease = QtWidgets.QLabel(self.frequency_box)
        self.btn_decrease.setGeometry(QtCore.QRect(5, 3, 24, 24))
        self.btn_decrease.setText("")
        self.btn_decrease.setPixmap(QtGui.QPixmap(":/images/minus.svg"))
        self.btn_decrease.setScaledContents(True)
        self.btn_decrease.setObjectName("btn_decrease")
        self.btn_decrease.mouseReleaseEvent = self.decrease
        self.btn_increase = QtWidgets.QLabel(self.frequency_box)
        self.btn_increase.setGeometry(QtCore.QRect(101, 3, 24, 24))
        self.btn_increase.setText("")
        self.btn_increase.setPixmap(QtGui.QPixmap(":/images/plus.svg"))
        self.btn_increase.setScaledContents(True)
        self.btn_increase.setObjectName("btn_increase")
        self.btn_increase.mouseReleaseEvent = self.increase
        self.btn_delete = QtWidgets.QWidget(widget)
        self.btn_delete.setEnabled(True)
        self.btn_delete.setGeometry(QtCore.QRect(555, 7, 30, 30))
        self.btn_delete.setStyleSheet("#btn_delete {\n"
                                      "    background: #252525; color: white\n"
                                      "}\n"
                                      "\n"
                                      "#btn_delete::hover {\n"
                                      "    background: #303030;\n"
                                      "}")
        self.btn_delete.setObjectName("btn_delete")
        self.btn_delete.mouseReleaseEvent = self.delete
        self.label_delete = QtWidgets.QLabel(self.btn_delete)
        self.label_delete.setGeometry(QtCore.QRect(3, 3, 24, 24))
        self.label_delete.setText("")
        self.label_delete.setPixmap(QtGui.QPixmap(":/images/remove.svg"))
        self.label_delete.setScaledContents(True)
        self.label_delete.setObjectName("label_delete")

        self.retranslateUi(widget)
        QtCore.QMetaObject.connectSlotsByName(widget)

    def retranslateUi(self, widget):
        _translate = QtCore.QCoreApplication.translate
        widget.setWindowTitle(_translate("widget", "Form"))
        self.label_title.setText(_translate("widget", "Title text"))
        if self.current_value == 0:
            self.label_frequency.setText("-")
        else:
            self.label_frequency.setText(format(self.current_value, ".1f"))

    def increase(self, event):
        if self.current_value == 0:
            self.current_value = 108.0
        self.current_value += 0.1
        if self.current_value > 108.0:
            self.current_value = 108.0
        self.settings.setValue(self.key, self.current_value)
        self.label_frequency.setText(format(self.current_value, ".1f"))
        self.onValueChange(self.current_value)

    def decrease(self, event):
        if self.current_value == 0:
            self.current_value = 87.5
        self.current_value -= 0.1
        if self.current_value < 87.5:
            self.current_value = 87.5
        self.settings.setValue(self.key, self.current_value)
        self.label_frequency.setText(format(self.current_value, ".1f"))
        self.onValueChange(self.current_value)

    def delete(self, event):
        self.current_value = 0
        self.settings.setValue(self.key, self.current_value)
        self.label_frequency.setText("-")
        self.onValueChange(self.current_value)

    def onValueChange(self, value):
        return
