diff --git a/src/InputObject.cpp b/src/InputObject.cpp index 22e07ee..4599c03 100644 --- a/src/InputObject.cpp +++ b/src/InputObject.cpp @@ -1,22 +1,24 @@ #include "InputObject.h" -#include "ui_InputObject.h" -#include "qdesktopwidget.h" +#include "ui_inputobject.h" +//#include "qdesktopwidget.h" #include +#include #include #include #include #include - +#include +#include InputObject::InputObject(QWidget *parent) : QWidget(parent), ui(new Ui::InputObject) { ui->setupUi(this); - + initUi(); - + this->setVisible(false); this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); @@ -28,73 +30,86 @@ InputObject::~InputObject() delete ui; } -void InputObject::initUi() +void InputObject::initUi() { + //#3c3c3c + // - QString style = "*{background-color:#3c3c3c; font-family:Arial; color:white;margin:0;font-size:16px;}" - "QLabel#title{font-Size:98px;color:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," - "stop: 0.0 darkgray, stop: 0.5 lightgray, stop: 1.0 darkgray);}" - "QLabel#warn{color:#930000;background:transparent;font-size:20px;}" - "QFrame#login_frame_username{min-width:700px;max-width:700px;max-height:500px;min-height:500px;" - "border:1px solid #0078d8;border-radius:20px;" - "background:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,\n" - " stop: 0.0 darkgray, stop: 0.5 gray, stop: 1.0 darkgray);" - "}" - - - "QLineEdit,QDateEdit{min-height:100px;max-height:100px; min-width:250px;max-width:250px;border: 3px solid pink; border-radius:10px;font-size:26px;}" - "QLineEdit,QDateEdit:enabled{background-color: #515151}" + QString style = + "QWidget#WiBack{background-image: url(:/icons/bg.jpeg);}" + "QWidget#WiBo{background-color: black;}" + "QLineEdit,QDateEdit{background-color: rgba(0,0,0,0.5);\ + min-height:100px;max-height:100px; min-width:500px;max-width:500px;\ + border: 2px solid #ef9cba; border-radius:20px;\ + font-family:Arial; color:white;margin:0;font-size:36px;}" "QDateEdit::up-button{image: url(:/up.png);height:15px;}" "QDateEdit::down-button{image:url(:/down.png);height:15px;}" ; setStyleSheet(style); - this->setWindowOpacity(0.8); ui->dateEdit->setVisible(false); ui->dateEdit->setMaximumDate(QDate::currentDate()); ui->dateEdit->setDisplayFormat("yyyy/MM/dd"); ui->dateEdit->setStyleSheet(style); + //this->setWindowOpacity(0.8); - //ui->lineEdit->setFont(QFont("Arial", 25)); - //ui->dateEdit->setFont(QFont("Arial", 25, QFont::Bold)); + connect(QGuiApplication::inputMethod(), &QInputMethod::visibleChanged, [=]() { + if (QGuiApplication::inputMethod()->isVisible())return; + //qDebug() << "HidePanel"; + //qDebug() << "focusWidget" << qApp->focusWidget(); + this->HidePanel(); + this->hide(); + + }); } - -//QLineEdit* InputObject::lineEdit() -//{ -// return ui->lineEdit; -//} - bool InputObject::eventFilter(QObject *obj, QEvent *event) { - static bool _visible = false; - static bool excution = false; - if (obj->inherits("QQuickView")) + //mouse button release means setfocus is useless + if (event->type() == QEvent::MouseButtonRelease) { - if (_visible != QGuiApplication::inputMethod()->isVisible()) + //qDebug() << obj << event->type(); + + if (obj->objectName() == QString("qt_spinbox_lineedit")) { - - if (QGuiApplication::inputMethod()->isVisible()) + QDateEdit *_date = qobject_cast(obj->parent()); + if (_date == ui->dateEdit)return true; + if (_date->isEnabled()) { - if (excution == false) { - excution = true; - //make sure vkb hide and show again,without activating InputObject(both show/hide) - this->ShowPanel(); - excution = false; - } + this->ShowPanel(); + return true; } - else - { - if (excution == false) { - excution = true; - //make sure will not give rise to another vkb - this->HidePanel(); - excution = false; - } - } - _visible = QGuiApplication::inputMethod()->isVisible(); } + if (obj->objectName() == QString("qt_scrollarea_viewport")) + { + QTextEdit *_text= qobject_cast(obj->parent()); + if (_text == ui->textEdit) return true; // + if (_text->isEnabled()) + { + this->ShowPanel(); + return true; + } + } + + if (obj->inherits("QLineEdit")) { + QLineEdit *tbx = qobject_cast(obj); + //you have to tell whether it is coming from qdateedit!!! + if (ui->lineEdit != tbx && tbx->isEnabled()) + { + //qDebug() << "ShowPanel"; + //qDebug() << "focusWidget" << qApp->focusWidget(); + //qDebug() << "lineEdit" << ui->lineEdit; + //qDebug() << "obj" << obj; + this->ShowPanel(); + return true; + } + } + + + + + } return QObject::eventFilter(obj, event); } @@ -102,70 +117,125 @@ bool InputObject::eventFilter(QObject *obj, QEvent *event) void InputObject::ShowPanel() { if (qApp->focusWidget()->inherits("QLineEdit")) { - curEdit = qobject_cast(qApp->focusWidget()); + curLine = qobject_cast(qApp->focusWidget()); ui->dateEdit->setVisible(false); ui->lineEdit->setVisible(true); + ui->textEdit->setVisible(false); } - else if (qApp->focusWidget()->inherits("QComboBox")) - { - curEdit = qobject_cast(qApp->focusWidget())->lineEdit(); - ui->dateEdit->setVisible(false); - ui->lineEdit->setVisible(true); - } - else if(qApp->focusWidget()->inherits("QDateEdit")) + if (qApp->focusWidget()->inherits("QDateEdit")) { curDateEdit = qobject_cast(qApp->focusWidget()); ui->dateEdit->setVisible(true); ui->lineEdit->setVisible(false); + ui->textEdit->setVisible(false); } - else + + if (qApp->focusWidget()->inherits("QTextEdit")) { - return; + curText = qobject_cast(qApp->focusWidget()); + ui->dateEdit->setVisible(false); + ui->lineEdit->setVisible(false); + ui->textEdit->setVisible(true); } - QDesktopWidget w; - int deskWidth = w.availableGeometry().width(); - int deskHeight = w.availableGeometry().height(); - int vkbHeight = QGuiApplication::inputMethod()->keyboardRectangle().height(); - this->setGeometry(0, 0, deskWidth, deskHeight - vkbHeight); + + //else + //{ + // return; + //} + //QDesktopWidget w; + //int deskWidth = w.availableGeometry().width(); + //int deskHeight = w.availableGeometry().height(); + //int vkbHeight = QGuiApplication::inputMethod()->keyboardRectangle().height(); + + this->showFullScreen(); this->setVisible(true); this->activateWindow(); //it is quite important!!! - if (curEdit) { - ui->lineEdit->setText(curEdit->text()); - ui->lineEdit->setEchoMode(curEdit->echoMode()); - ui->lineEdit->setInputMethodHints(Qt::InputMethodHint::ImhNoAutoUppercase); - ui->lineEdit->setFocus(); + + if (curLine) { + ui->lineEdit->setText(curLine->text()); + ui->lineEdit->setEchoMode(curLine->echoMode()); + ui->lineEdit->setInputMethodHints(Qt::InputMethodHint::ImhNoAutoUppercase); + //qDebug() << "begin"; + ui->lineEdit->setFocus(); + //QFocusEvent event0(QEvent::FocusIn); + //QCoreApplication::sendEvent(ui->lineEdit, &event0); + while (QGuiApplication::focusObject() != ui->lineEdit) + { + qApp->processEvents(); + } + + //qDebug() << QGuiApplication::focusObject(); QEvent event(QEvent::RequestSoftwareInputPanel); - QApplication::sendEvent(ui->lineEdit, &event); + QCoreApplication::sendEvent(ui->lineEdit, &event); + + // QMouseEvent pressed(QEvent::MouseButtonPress, QPointF(10,10),Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + // QApplication::sendEvent(ui->lineEdit, &pressed); + // qDebug()<<"release"; + // QMouseEvent release(QEvent::MouseButtonRelease, QPointF(10,10),Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + // QApplication::sendEvent(ui->lineEdit, &release); + // qDebug() <dateEdit->setDateTime(curDateEdit->dateTime()); ui->dateEdit->setFocus(); + while (QGuiApplication::focusObject() != ui->dateEdit) + { + qApp->processEvents(); + } + qDebug() << QGuiApplication::focusObject(); QEvent event(QEvent::RequestSoftwareInputPanel); - QApplication::sendEvent(ui->dateEdit, &event); + QCoreApplication::sendEvent(ui->dateEdit, &event); } - + if (curText) + { + ui->textEdit->setPlainText(curText->toPlainText()); + ui->textEdit->setFocus(); + while (QGuiApplication::focusObject() != ui->textEdit) + { + qApp->processEvents(); + } + //qDebug() << QGuiApplication::focusObject(); + QEvent event(QEvent::RequestSoftwareInputPanel); + QCoreApplication::sendEvent(ui->textEdit, &event); + } } void InputObject::HidePanel() { - if (curEdit) { - curEdit->setText(ui->lineEdit->text()); + if (curLine) { + curLine->setText(ui->lineEdit->text()); ui->lineEdit->clearFocus(); ui->lineEdit->clear(); - this->setVisible(false); - curEdit = nullptr; + //this->setVisible(false); + curLine = nullptr; } - else if (curDateEdit) + else if (curDateEdit) { + //curDateEdit->setDateTime(QDateTime::currentDateTime()); curDateEdit->setDateTime(ui->dateEdit->dateTime()); ui->dateEdit->clearFocus(); ui->dateEdit->clear(); - this->setVisible(false); + //this->setVisible(false); curDateEdit = nullptr; } -} \ No newline at end of file + else if (curText) + { + curText->setText(ui->textEdit->toPlainText()); + ui->textEdit->clearFocus(); + ui->textEdit->clear(); + //this->setVisible(false); + curText = nullptr; + } + else + { + return; + } +} diff --git a/src/InputObject.h b/src/InputObject.h index 6f52df4..59a9917 100644 --- a/src/InputObject.h +++ b/src/InputObject.h @@ -1,28 +1,31 @@ -#pragma once +#ifndef INPUTOBJECT_H +#define INPUTOBJECT_H + #include class QLineEdit; class QDateEdit; - +class QTextEdit; namespace Ui { - class InputObject; +class InputObject; } class InputObject : public QWidget { - Q_OBJECT + Q_OBJECT public: - explicit InputObject(QWidget *parent = 0); - ~InputObject(); + explicit InputObject(QWidget *parent = nullptr); + ~InputObject(); bool eventFilter(QObject *obj, QEvent *event); - + void ShowPanel(); private: + Ui::InputObject *ui; void initUi(); - void ShowPanel(); +// void ShowPanel(); void HidePanel(); - - static InputObject *_instance; - Ui::InputObject *ui; QDateEdit *curDateEdit = nullptr; - QLineEdit* curEdit = nullptr; -}; \ No newline at end of file + QLineEdit* curLine = nullptr; + QTextEdit* curText = nullptr; +}; + +#endif // INPUTOBJECT_H diff --git a/src/inputobject.ui b/src/inputobject.ui index e30a569..5063f68 100644 --- a/src/inputobject.ui +++ b/src/inputobject.ui @@ -6,111 +6,125 @@ 0 0 - 916 - 305 + 952 + 660 - mask + Form - - - - + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - - - Qt::Horizontal - - - - 306 - 20 - - - - - - - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + - + - Qt::Vertical + Qt::Horizontal - 20 - 63 + 235 + 20 - - - - 0 - 0 - - - - - 250 - 60 - - - - border: 3px solid pink; - border-radius: 15px; - selection-background-color: darkgray; - - - - - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 214 + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 800 + + + + + - - - - 0 - 0 - - - - - 250 - 60 - - - - border: 3px solid pink; - border-radius: 15px; - selection-background-color: darkgray; - - - - 0 - 0 - 0 - 1994 - 11 - 29 - - - - - - + - Qt::Vertical + Qt::Horizontal - 20 - 62 + 235 + 20 @@ -119,22 +133,17 @@ - - - Qt::Horizontal - - + + - 306 - 20 + 0 + 50 - + - - - + diff --git a/src/loginwindow.cpp b/src/loginwindow.cpp index dc28ef4..5cd734b 100644 --- a/src/loginwindow.cpp +++ b/src/loginwindow.cpp @@ -3,12 +3,14 @@ #include #include #include -#include + #include #include #include "guimacros.h" #include #include "db/SQLHelper.h" +#include "InputObject.h" + #define splitFlag QString("-") LoginWindow::LoginWindow(QWidget* parent) @@ -144,10 +146,8 @@ void LoginWindow::doLogin() QString encryptPwd = getEncryptedPassword(strPassWord); - qDebug()<0) { accept(); diff --git a/src/main.cpp b/src/main.cpp index ef08e4f..2bfa650 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,8 +11,9 @@ int main(int argc, char *argv[]) qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", "..\\src\\layouts"); QApplication a(argc, argv); - InputObject *obj = new InputObject(); //a.installEventFilter(obj); + InputObject *obj = new InputObject(); + a.installEventFilter(obj); needLogin: