config1digitsetdlg.cpp 2.26 KB
#include <QDebug>
#include "config1digitsetdlg.h"
#include "ui_config1digitsetdlg.h"
#include "soundplayer.h"

using namespace Define;

Config1DigitSetDlg::Config1DigitSetDlg(QWidget *parent, ConfigType type) :
    QDialog(parent),
    ui(new Ui::Config1DigitSetDlg)
{
    Config* cfg = Config::getInstance();
    QString strTemp1,strTemp2;
    config_1digit_set setting_val;
    config_item item;
    ui->setupUi(this);
    this->setWindowFlags( Qt::FramelessWindowHint);
    this->setAttribute( Qt::WA_DeleteOnClose);

    foreach (QPushButton *button, findChildren<QPushButton *>())
        connect(button, &QPushButton::pressed, SoundPlayer::playClick);

    m_nType = type;

    ui->ctrLbTitle->setText(cfg->getTitleString(m_nType));
    item = cfg->getConfigValue(m_nType);
    ui->ctrSpBxValue->setValue(item.d32);

    switch(m_nType){
        case config_set_auto_darkness:
        setting_val = auto_darkness_dlgset;
        break;
    case config_set_load_ready:
        setting_val = load_ready_dlgset;
        break;
    default:
        setting_val.min = 0;
        setting_val.str_unit[0] = 0;
        setting_val.maxlen=2;
        setting_val.max = 10;
        break;
    }

    ui->ctrSpBxValue->setMaximum(setting_val.max);
    ui->ctrSpBxValue->setMinimum(setting_val.min);
    strTemp1.sprintf("(%%0%dd ~ %%0%dd %s)", setting_val.maxlen,setting_val.maxlen,setting_val.str_unit);
    qDebug() <<strTemp1;
    strTemp2.sprintf(strTemp1.toLocal8Bit().constData(), setting_val.min,setting_val.max);

    ui->ctrLbRange->setText(strTemp2);

    strTemp1.sprintf("%%0%d",setting_val.maxlen);

    ui->ctrSpBxValue->installEventFilter(this);

}

Config1DigitSetDlg::~Config1DigitSetDlg()
{
    delete ui;
}

void Config1DigitSetDlg::on_ctrBtnOk_clicked()
{
    Config* cfg = Config::getInstance();
    config_item item;
    item.d32 = ui->ctrSpBxValue->value();
    cfg->setConfigValue(m_nType,item);
    accept();
}

void Config1DigitSetDlg::on_ctrBtnCancel_clicked()
{
    reject();
}

bool Config1DigitSetDlg::eventFilter(QObject *object, QEvent *event){
        if (object == ui->ctrSpBxValue && event->type() == QEvent::MouseButtonRelease )
        {
            ui->ctrSpBxValue->selectAll();
            qDebug() << "Mouse Release2";

        }
        return QWidget::eventFilter(object, event);
}