#include "keyboardui.h"

KeyboardUi::KeyboardUi(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
    setAttribute(Qt::WA_DeleteOnClose);
    mVlayout = new QVBoxLayout(this);
    mVlayout->setContentsMargins(0, 0, 0, 0);
    mVlayout->setSpacing(8);
    initUI();
}

KeyboardUi::~KeyboardUi()
{

}

void KeyboardUi::initUI()
{
    mKeyboardFrame = new SettingGroup(this);
    mKeyboardSetTitleLabel = new TitleLabel(this);
    //~ contents_path /Keyboard/Keyboard Settings
    mKeyboardSetTitleLabel->setText(tr("Keyboard Settings"));
    mKeyboardSetTitleLabel->setContentsMargins(16, 0, 0, 0);

    setKeyRepeatFrame();
    setDelayFrame();
    setSpeedFrame();
    setInputTestFrame();
    setKeyTipsFrame();
    setInputMethodFrame();

    /* add widget */
    mKeyboardFrame->insertWidget(0, mKeyRepeatFrame);
    mKeyboardFrame->insertWidget(1, mDelayFrame);
    mKeyboardFrame->insertWidget(2, mSpeedFrame);
    mKeyboardFrame->insertWidget(3, mInputTestFrame);
    mKeyboardFrame->insertWidget(4, mKeyTipsFrame);

    mVlayout->addWidget(mKeyboardSetTitleLabel);
    mVlayout->addWidget(mKeyboardFrame);
    mVlayout->addWidget(mInputMethodSetBtn);
    mVlayout->addStretch();
}

void KeyboardUi::setKeyRepeatFrame()
{
    /* Key Repeat */
    //~ contents_path /Keyboard/Key repeat
    mKeyRepeatFrame = new SwitchWidget(tr("Key repeat"), this, UkccFrame::None);
    mKeyRepeatFrame->setObjectName("Key repeat");
}

void KeyboardUi::setDelayFrame()
{
    /* delay */
    //~ contents_path /Keyboard/Delay
    mDelayFrame = new SliderWidget(tr("Delay"), false, this);
    mDelayFrame->slider()->setSliderType(KSliderType::StepSlider);
    mDelayFrame->setObjectName("Delay");
    mDelayFrame->setLeftText(tr("Short"));
    mDelayFrame->setRightText(tr("Long"));
    mDelayFrame->slider()->setMinimum(200);
    mDelayFrame->slider()->setMaximum(2100);
    mDelayFrame->slider()->setPageStep(20);
    mDelayFrame->slider()->setSingleStep(20);
    mDelayFrame->slider()->installEventFilter(this);
}

void KeyboardUi::setSpeedFrame()
{
    /* Speed */
    //~ contents_path /Keyboard/Speed
    mSpeedFrame = new SliderWidget(tr("Speed"), false, this);
    mSpeedFrame->setObjectName("Speed");
    mSpeedFrame->setLeftText(tr("Slow"));
    mSpeedFrame->setRightText(tr("Fast"));
    mSpeedFrame->slider()->setMinimum(10);
    mSpeedFrame->slider()->setMaximum(110);
    mSpeedFrame->slider()->setPageStep(1);
    mSpeedFrame->slider()->installEventFilter(this);
}

void KeyboardUi::setInputTestFrame()
{
    /* Input test */
    //~ contents_path /Keyboard/Input test
    mInputTestFrame = new LineEditWidget(tr("Input test"), this);

}

void KeyboardUi::setKeyTipsFrame()
{
    /* key tips */
    //~ contents_path /Keyboard/Key tips
    mKeyTipsFrame = new SwitchWidget(tr("Key tips"), this, UkccFrame::None);
    mKeyTipsFrame->setObjectName("Key tips");
}

void KeyboardUi::setInputMethodFrame()
{
    /* Input method */
    mInputMethodSetBtn = new QPushButton(this);
    //~ contents_path /Keyboard/Input settings
    mInputMethodSetBtn->setText(tr("Input settings"));
    mInputMethodSetBtn->setObjectName("Input settings");
    mInputMethodSetBtn->setMinimumWidth(160);
    mInputMethodSetBtn->setMaximumWidth(180);
}
