#include "cmwkeyboard.h"
#include "ui_cmwkeyboard.h"
#include "cctrllineedit.h"
#include <QKeyEvent>
#include <QCoreApplication>
#include <QPainter>
CMWKeyboard::CMWKeyboard(QWidget *parent) :
    CMWidget(parent),
    ui(new Ui::CMWKeyboard)
{
    ui->setupUi(this);
}

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

void CMWKeyboard::MoveToPos(QWidget *pWidget)
{
    if(pWidget)
    {
        QRect rect= pWidget->geometry();
        QPoint GlobalPoint(pWidget->mapToGlobal(QPoint(0, rect.height())));
        QWidget *pParent=(QWidget *)(this->parent());
        QPoint Point=pParent->mapFromGlobal(GlobalPoint);
         QRect rect1= geometry();
        setGeometry(Point.x(),Point.y(),
                      rect1.width(),rect1.height());
    }
}

void CMWKeyboard::paintEvent(QPaintEvent *pEvent)
{
    Q_UNUSED(pEvent);
 //   QPainter p(this);
 //   p.setPen(Qt::NoPen);
 //   p.setBrush(Qt::gray);
 //   p.drawRect(rect());
}



void CMWKeyboard::on_pushButton_0_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyRelease, Qt::Key_0, Qt::NoModifier,"0");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_1_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_1, Qt::NoModifier,"1");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_2_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_2, Qt::NoModifier,"2");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_3_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_3, Qt::NoModifier,"3");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_4_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_4, Qt::NoModifier,"4");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_5_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_5, Qt::NoModifier,"5");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_6_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_6, Qt::NoModifier,"6");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_7_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_7, Qt::NoModifier,"7");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}
void CMWKeyboard::on_pushButton_8_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_8, Qt::NoModifier,"8");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_9_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_9, Qt::NoModifier,"9");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}


void CMWKeyboard::on_pushButton_Enter_clicked()
{
//    if(m_gFoucsLineEdit)
    {
//    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier,"");
//    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
      hide();
    }
}

void CMWKeyboard::on_pushButton_Point_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_Greater, Qt::NoModifier,".");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_Sub_clicked()
{
    if(m_gFoucsLineEdit)
    {
    QKeyEvent tabKey(QEvent::KeyPress, Qt::Key_Minus, Qt::NoModifier,"-");
    QCoreApplication::sendEvent(m_gFoucsLineEdit, &tabKey);
    }
}

void CMWKeyboard::on_pushButton_Clear_clicked()
{
    if(m_gFoucsLineEdit)
    {
       m_gFoucsLineEdit->clear();
    }
}
