Refactor InputObject(EventFilter and VirtualKeyboard).

This commit is contained in:
sunwen
2022-06-14 14:03:19 +08:00
parent 589262781d
commit 020b40c55d
36 changed files with 783 additions and 598 deletions

View File

@@ -4,8 +4,6 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QDateTime> #include <QDateTime>
#include <QLineEdit>
#include <QTextEdit>
#include <QToolButton> #include <QToolButton>
#include <QSqlTableModel> #include <QSqlTableModel>
#include <QUuid> #include <QUuid>
@@ -13,16 +11,20 @@
#include "dialogs/SelectDialog.h" #include "dialogs/SelectDialog.h"
#include "DateSelectDialog.h" #include "DateSelectDialog.h"
#include "components/ListBox.h" #include "components/ListBox.h"
#include "components/ULineEdit.h"
#include "components/UTextEdit.h"
int queryValue(QSqlTableModel* model, int colID, const QVariant& var) int queryValue(QSqlTableModel* model, int colID, const QVariant& var)
{ {
for (int i = 0; i < model->rowCount(); ++i) { for (int i = 0; i < model->rowCount(); ++i)
{
if (model->data(model->index(i, colID)) == var) return i; if (model->data(model->index(i, colID)) == var) return i;
} }
return -1; return -1;
} }
EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { EditPatientDialog::EditPatientDialog(QWidget* parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f)
{
QVBoxLayout* layout = new QVBoxLayout(mFormWidget); QVBoxLayout* layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10); layout->setSpacing(10);
// add title // add title
@@ -35,7 +37,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
//add old password //add old password
QLabel* lbl_id = new QLabel(this); QLabel* lbl_id = new QLabel(this);
lbl_id->setText(tr("ID")); lbl_id->setText(tr("ID"));
le_id = new QLineEdit(this); le_id = new ULineEdit(this);
layout->addWidget(lbl_id); layout->addWidget(lbl_id);
layout->addWidget(le_id); layout->addWidget(le_id);
QLabel* lbl_endline1 = new QLabel(this); QLabel* lbl_endline1 = new QLabel(this);
@@ -44,7 +46,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
QLabel* lbl_name = new QLabel(this); QLabel* lbl_name = new QLabel(this);
lbl_name->setText(tr("Name")); lbl_name->setText(tr("Name"));
le_name = new QLineEdit(this); le_name = new ULineEdit(this);
layout->addWidget(lbl_name); layout->addWidget(lbl_name);
layout->addWidget(le_name); layout->addWidget(le_name);
QLabel* lbl_endline2 = new QLabel(this); QLabel* lbl_endline2 = new QLabel(this);
@@ -71,7 +73,8 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
dialog.setValues(items); dialog.setValues(items);
dialog.setSelectedValue(items[btnSex->property("idx").toInt()]); dialog.setSelectedValue(items[btnSex->property("idx").toInt()]);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
if (dialog.exec() == QDialog::Accepted){ if (dialog.exec() == QDialog::Accepted)
{
btnSex->setText(dialog.getSelectedValue()); btnSex->setText(dialog.getSelectedValue());
btnSex->setProperty("idx", items.indexOf(dialog.getSelectedValue())); btnSex->setProperty("idx", items.indexOf(dialog.getSelectedValue()));
} }
@@ -99,7 +102,8 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
DateSelectDialog dialog(this); DateSelectDialog dialog(this);
dialog.setSelectedValue(btnDate->text()); dialog.setSelectedValue(btnDate->text());
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
if (dialog.exec() == QDialog::Accepted){ if (dialog.exec() == QDialog::Accepted)
{
btnDate->setText(dialog.getSelectedValue()); btnDate->setText(dialog.getSelectedValue());
} }
}); });
@@ -110,7 +114,7 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
QLabel* lbl_comment = new QLabel(this); QLabel* lbl_comment = new QLabel(this);
lbl_comment->setText(tr("Comment")); lbl_comment->setText(tr("Comment"));
te_comment = new QTextEdit(this); te_comment = new UTextEdit(this);
layout->addWidget(lbl_comment); layout->addWidget(lbl_comment);
layout->addWidget(te_comment); layout->addWidget(te_comment);
QLabel* lbl_endline6 = new QLabel(this); QLabel* lbl_endline6 = new QLabel(this);
@@ -122,11 +126,13 @@ EditPatientDialog::EditPatientDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo
layout->addWidget(lbl_error); layout->addWidget(lbl_error);
} }
EditPatientDialog::~EditPatientDialog() { EditPatientDialog::~EditPatientDialog()
{
} }
void EditPatientDialog::setPatientInformation(PatientInformation* information) { void EditPatientDialog::setPatientInformation(PatientInformation* information)
{
if (information) if (information)
{ {
le_id->setText(information->ID); le_id->setText(information->ID);
@@ -140,14 +146,16 @@ void EditPatientDialog::setPatientInformation(PatientInformation* information) {
} }
} }
void EditPatientDialog::clearPatientInformation() { void EditPatientDialog::clearPatientInformation()
{
le_id->setText(""); le_id->setText("");
// le_date->setText(""); // le_date->setText("");
le_name->setText(""); le_name->setText("");
te_comment->setText(""); te_comment->setText("");
} }
void EditPatientDialog::storePatientInformation() { void EditPatientDialog::storePatientInformation()
{
store.PatientUID = currentPatientUID; store.PatientUID = currentPatientUID;
// store.AddDate = AddDate; // store.AddDate = AddDate;
store.ID = le_id->text(); store.ID = le_id->text();
@@ -157,15 +165,18 @@ void EditPatientDialog::storePatientInformation() {
store.Comment = te_comment->toPlainText(); store.Comment = te_comment->toPlainText();
} }
bool EditPatientDialog::updateReferenceData() { bool EditPatientDialog::updateReferenceData()
{
PatientInformation* inf = getPatientInformation(); PatientInformation* inf = getPatientInformation();
if (le_id->text().isEmpty()){ if (le_id->text().isEmpty())
{
lbl_error->setText("ID can't be empty!"); lbl_error->setText("ID can't be empty!");
lbl_error->setVisible(true); lbl_error->setVisible(true);
return false; return false;
} }
inf->ID = le_id->text().trimmed(); inf->ID = le_id->text().trimmed();
if (le_name->text().isEmpty()){ if (le_name->text().isEmpty())
{
lbl_error->setText("Patient Name can't be empty!"); lbl_error->setText("Patient Name can't be empty!");
lbl_error->setVisible(true); lbl_error->setVisible(true);
return false; return false;
@@ -173,7 +184,8 @@ bool EditPatientDialog::updateReferenceData() {
inf->Name = le_name->text().trimmed(); inf->Name = le_name->text().trimmed();
int selectedRow = 0; int selectedRow = 0;
bool isAdd = currentPatientUID.isEmpty(); bool isAdd = currentPatientUID.isEmpty();
if (isAdd) { if (isAdd)
{
int ref_rowid = queryValue(model, 1, inf->ID); int ref_rowid = queryValue(model, 1, inf->ID);
if (ref_rowid >= 0) if (ref_rowid >= 0)
{ {
@@ -185,7 +197,8 @@ bool EditPatientDialog::updateReferenceData() {
inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); inf->AddDate = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
model->insertRow(0); model->insertRow(0);
} }
else{ else
{
inf->PatientUID = currentPatientUID; inf->PatientUID = currentPatientUID;
selectedRow = queryValue(model, 1, inf->ID); selectedRow = queryValue(model, 1, inf->ID);
inf->AddDate = AddDate; inf->AddDate = AddDate;
@@ -203,7 +216,8 @@ bool EditPatientDialog::updateReferenceData() {
{ {
return true; return true;
} }
else { else
{
lbl_error->setText("Submit to database error!"); lbl_error->setText("Submit to database error!");
lbl_error->setVisible(true); lbl_error->setVisible(true);
return false; return false;

View File

@@ -8,8 +8,8 @@
#include "dialogs/GUIFormBaseDialog.h" #include "dialogs/GUIFormBaseDialog.h"
#include "forms/select/editpatientform.h" #include "forms/select/editpatientform.h"
class QLineEdit; class ULineEdit;
class QTextEdit; class UTextEdit;
class QLabel; class QLabel;
class QToolButton; class QToolButton;
class QSqlTableModel; class QSqlTableModel;
@@ -19,11 +19,13 @@ public:
explicit EditPatientDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit EditPatientDialog(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~EditPatientDialog(); ~EditPatientDialog();
void setModel(QSqlTableModel * m){ void setModel(QSqlTableModel* m)
{
model = m; model = m;
} }
PatientInformation * getPatientInformation(){ PatientInformation* getPatientInformation()
{
return &store; return &store;
} }
void setPatientInformation(PatientInformation* information); void setPatientInformation(PatientInformation* information);
@@ -35,11 +37,11 @@ protected:
bool updateReferenceData() override; bool updateReferenceData() override;
private: private:
QLineEdit* le_id= nullptr; ULineEdit* le_id = nullptr;
QLineEdit* le_name = nullptr; ULineEdit* le_name = nullptr;
QLineEdit* le_sex = nullptr; ULineEdit* le_sex = nullptr;
QLineEdit* le_date = nullptr; ULineEdit* le_date = nullptr;
QTextEdit* te_comment = nullptr; UTextEdit* te_comment = nullptr;
QLabel* lbl_error = nullptr; QLabel* lbl_error = nullptr;
PatientInformation store; PatientInformation store;
QString currentPatientUID; QString currentPatientUID;

22
src/UsctApplication.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "UsctApplication.h"
#include "utilities/TouchScreenSignalSender.h"
UsctApplication::UsctApplication(int& argc, char** argv)
: QApplication(argc, argv)
{
}
UsctApplication::~UsctApplication()
{
}
bool UsctApplication::notify(QObject* aReceiver, QEvent* aEvent)
{
if (aEvent->type() == QEvent::MouseButtonPress)
{
TouchScreenSignalSender::getInstance()->sendTouchScreenSignal();
}
return QApplication::notify(aReceiver, aEvent);
}

17
src/UsctApplication.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef USCTAPPLICATION_H
#define USCTAPPLICATION_H
#include <QApplication>
class UsctApplication : public QApplication
{
Q_OBJECT
public:
UsctApplication(int& argc, char** argv);
~UsctApplication();
private:
bool notify(QObject* aReceiver, QEvent* aEvent);
};
#endif // USCTAPPLICATION_H

View File

@@ -0,0 +1,17 @@
#include "ULineEdit.h"
#include <QEvent>
#include "keyboard/KeyboardManager.h"
ULineEdit::ULineEdit(QWidget* aParent)
: QLineEdit(aParent)
{
}
ULineEdit::~ULineEdit()
{
}
void ULineEdit::mouseReleaseEvent(QMouseEvent* /*aEvent*/)
{
KeyboardManager::getInstance()->showKeyboardPanel(this);
}

View File

@@ -0,0 +1,19 @@
#ifndef ULINEEDIT_H
#define ULINEEDIT_H
#include <QLineEdit>
class ULineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit ULineEdit(QWidget* aParent);
~ULineEdit();
protected:
void mouseReleaseEvent(QMouseEvent* aEvent);
};
#endif // ULINEEDIT_H

View File

@@ -0,0 +1,17 @@
#include "UTextEdit.h"
#include <QEvent>
#include "keyboard/KeyboardManager.h"
UTextEdit::UTextEdit(QWidget* aParent)
: QTextEdit(aParent)
{
}
UTextEdit::~UTextEdit()
{
}
void UTextEdit::mouseReleaseEvent(QMouseEvent* /*aEvent*/)
{
KeyboardManager::getInstance()->showKeyboardPanel(this);
}

View File

@@ -0,0 +1,19 @@
#ifndef UTEXTEDIT_H
#define UTEXTEDIT_H
#include <QTextEdit>
class UTextEdit : public QTextEdit
{
Q_OBJECT
public:
explicit UTextEdit(QWidget* aParent);
~UTextEdit();
protected:
void mouseReleaseEvent(QMouseEvent* aEvent);
};
#endif // UTEXTEDIT_H

View File

@@ -9,13 +9,13 @@
#include <QDebug> #include <QDebug>
#include <QToolButton> #include <QToolButton>
#include <QPushButton> #include <QPushButton>
#include <QLineEdit>
#include "ChangePasswordFormDialog.h" #include "ChangePasswordFormDialog.h"
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include "log/UserOperationLog.h" #include "log/UserOperationLog.h"
#include "db/SQLHelper.h" #include "db/SQLHelper.h"
#include "models/User.h" #include "models/User.h"
#include "AlertDialog.h" #include "AlertDialog.h"
#include "components/ULineEdit.h"
AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f) AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f) : GUIFormBaseDialog(parent, f)
@@ -23,9 +23,9 @@ AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::
, mCommentChanged(false) , mCommentChanged(false)
, mRoleChanged(false) , mRoleChanged(false)
, mMode(mode) , mMode(mode)
, mLeUserCode(new QLineEdit(this)) , mLeUserCode(new ULineEdit(this))
, mLeUserName(new QLineEdit(this)) , mLeUserName(new ULineEdit(this))
, mLeComment(new QLineEdit(this)) , mLeComment(new ULineEdit(this))
, mLePwd(nullptr) , mLePwd(nullptr)
, mBtnPwd(nullptr) , mBtnPwd(nullptr)
, mLblError(new QLabel(this)) , mLblError(new QLabel(this))
@@ -42,7 +42,8 @@ AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::
auto hlayout = new QHBoxLayout; auto hlayout = new QHBoxLayout;
layout->addLayout(hlayout); layout->addLayout(hlayout);
if (mMode == Self)addSelfModeUI(hlayout); if (mMode == Self)addSelfModeUI(hlayout);
if (mMode != New) { if (mMode != New)
{
addButtonPwd(hlayout); addButtonPwd(hlayout);
addEndLine(layout); addEndLine(layout);
connect(mBtnPwd, &QPushButton::clicked, this, mMode == Self ? connect(mBtnPwd, &QPushButton::clicked, this, mMode == Self ?
@@ -58,42 +59,49 @@ AccountFormDialog::AccountFormDialog(QWidget* parent, AccountEditMode mode, Qt::
}); });
} }
void AccountFormDialog::addEndLine(QVBoxLayout *layout) { void AccountFormDialog::addEndLine(QVBoxLayout* layout)
{
auto lblEndline = new QLabel(this); auto lblEndline = new QLabel(this);
lblEndline->setFixedHeight(2); lblEndline->setFixedHeight(2);
lblEndline->setObjectName("endline"); lblEndline->setObjectName("endline");
layout->addWidget(lblEndline); layout->addWidget(lblEndline);
} }
void AccountFormDialog::resetUserPassword() { void AccountFormDialog::resetUserPassword()
{
AlertDialog dialog(this); AlertDialog dialog(this);
dialog.setGeometry(geometry()); dialog.setGeometry(geometry());
dialog.setButtonMode(OkAndCancel); dialog.setButtonMode(OkAndCancel);
dialog.setWindowModality(Qt::WindowModal); dialog.setWindowModality(Qt::WindowModal);
dialog.setAlertMessage(tr("Reset password to \"123456\" ?")); dialog.setAlertMessage(tr("Reset password to \"123456\" ?"));
if (dialog.exec() == Accepted) { if (dialog.exec() == Accepted)
{
User user; User user;
dialog.setButtonMode(OkOnly); dialog.setButtonMode(OkOnly);
if (!User::getUser(mUserID, user)) { if (!User::getUser(mUserID, user))
{
dialog.setAlertMessage(tr("Inner error, can't find reference user!")); dialog.setAlertMessage(tr("Inner error, can't find reference user!"));
dialog.exec(); dialog.exec();
return; return;
} }
if (!user.resetPassword()) { if (!user.resetPassword())
{
dialog.setAlertMessage(tr("Submit change to database fail!")); dialog.setAlertMessage(tr("Submit change to database fail!"));
dialog.exec(); dialog.exec();
} }
} }
} }
void AccountFormDialog::changeSelfPassword() { void AccountFormDialog::changeSelfPassword()
{
ChangePasswordFormDialog dia(this); ChangePasswordFormDialog dia(this);
dia.setGeometry(geometry()); dia.setGeometry(geometry());
dia.setWindowModality(Qt::WindowModal); dia.setWindowModality(Qt::WindowModal);
dia.exec(); dia.exec();
} }
void AccountFormDialog::addButtonPwd(QHBoxLayout *layout) { void AccountFormDialog::addButtonPwd(QHBoxLayout* layout)
{
mBtnPwd = new QToolButton(this); mBtnPwd = new QToolButton(this);
mBtnPwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); mBtnPwd->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mBtnPwd->setObjectName("editvalBtn"); mBtnPwd->setObjectName("editvalBtn");
@@ -104,13 +112,15 @@ void AccountFormDialog::addButtonPwd(QHBoxLayout *layout) {
layout->addWidget(mBtnPwd); layout->addWidget(mBtnPwd);
} }
void AccountFormDialog::addWarnLabel(QVBoxLayout *layout) { void AccountFormDialog::addWarnLabel(QVBoxLayout* layout)
{
mLblError->setObjectName("warn"); mLblError->setObjectName("warn");
mLblError->setVisible(false); mLblError->setVisible(false);
layout->addWidget(mLblError); layout->addWidget(mLblError);
} }
void AccountFormDialog::addCommentLabel(QVBoxLayout *layout) { void AccountFormDialog::addCommentLabel(QVBoxLayout* layout)
{
auto lblComment = new QLabel(this); auto lblComment = new QLabel(this);
lblComment->setText(tr("Comment")); lblComment->setText(tr("Comment"));
layout->addWidget(lblComment); layout->addWidget(lblComment);
@@ -118,7 +128,8 @@ void AccountFormDialog::addCommentLabel(QVBoxLayout *layout) {
addEndLine(layout); addEndLine(layout);
} }
void AccountFormDialog::initUserNameUI(QVBoxLayout *layout) { void AccountFormDialog::initUserNameUI(QVBoxLayout* layout)
{
auto lblUserName = new QLabel(this); auto lblUserName = new QLabel(this);
lblUserName->setText(tr("Name")); lblUserName->setText(tr("Name"));
@@ -128,7 +139,8 @@ void AccountFormDialog::initUserNameUI(QVBoxLayout *layout) {
addEndLine(layout); addEndLine(layout);
} }
void AccountFormDialog::initUserCodeUI(QVBoxLayout *layout) { void AccountFormDialog::initUserCodeUI(QVBoxLayout* layout)
{
auto lblUserCode = new QLabel(this); auto lblUserCode = new QLabel(this);
lblUserCode->setText(tr("User ID")); lblUserCode->setText(tr("User ID"));
@@ -139,7 +151,8 @@ void AccountFormDialog::initUserCodeUI(QVBoxLayout *layout) {
addEndLine(layout); addEndLine(layout);
} }
void AccountFormDialog::addTitleLabel(QVBoxLayout *layout) { void AccountFormDialog::addTitleLabel(QVBoxLayout* layout)
{
auto lblTitle = new QLabel(this); auto lblTitle = new QLabel(this);
lblTitle->setAlignment(Qt::AlignCenter); lblTitle->setAlignment(Qt::AlignCenter);
lblTitle->setText(tr("Account")); lblTitle->setText(tr("Account"));
@@ -147,7 +160,8 @@ void AccountFormDialog::addTitleLabel(QVBoxLayout *layout) {
layout->addWidget(lblTitle); layout->addWidget(lblTitle);
} }
void AccountFormDialog::addSelfModeUI(QHBoxLayout *hlayout) { void AccountFormDialog::addSelfModeUI(QHBoxLayout* hlayout)
{
auto btnLogout = new QToolButton(this); auto btnLogout = new QToolButton(this);
btnLogout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); btnLogout->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
btnLogout->setIcon(QIcon(":/icons/logout.png")); btnLogout->setIcon(QIcon(":/icons/logout.png"));
@@ -163,7 +177,8 @@ void AccountFormDialog::addSelfModeUI(QHBoxLayout *hlayout) {
EventCenter::Default()->triggerEvent(RequestLogin, nullptr, nullptr); EventCenter::Default()->triggerEvent(RequestLogin, nullptr, nullptr);
}); });
// load current user data // load current user data
if (User::Current()) { if (User::Current())
{
mLeUserCode->setText(User::Current()->getUserCode()); mLeUserCode->setText(User::Current()->getUserCode());
mLeUserName->setText(User::Current()->getUserName()); mLeUserName->setText(User::Current()->getUserName());
mUserID = User::Current()->getUserID(); mUserID = User::Current()->getUserID();
@@ -171,11 +186,12 @@ void AccountFormDialog::addSelfModeUI(QHBoxLayout *hlayout) {
} }
} }
void AccountFormDialog::addNewModeUI(QVBoxLayout *layout) { void AccountFormDialog::addNewModeUI(QVBoxLayout* layout)
{
auto lblPwd = new QLabel(this); auto lblPwd = new QLabel(this);
lblPwd->setText(tr("Password")); lblPwd->setText(tr("Password"));
layout->addWidget(lblPwd); layout->addWidget(lblPwd);
mLePwd = new QLineEdit(this); mLePwd = new ULineEdit(this);
mLePwd->setPlaceholderText(tr("Input password")); mLePwd->setPlaceholderText(tr("Input password"));
mLePwd->setEchoMode(QLineEdit::Password); mLePwd->setEchoMode(QLineEdit::Password);
layout->addWidget(mLePwd); layout->addWidget(mLePwd);
@@ -183,11 +199,15 @@ void AccountFormDialog::addNewModeUI(QVBoxLayout *layout) {
addEndLine(layout); addEndLine(layout);
} }
bool AccountFormDialog::updateReferenceData() { bool AccountFormDialog::updateReferenceData()
if (mMode == Self) { {
if (mMode == Self)
{
if (!this->mUserNameChanged && !this->mCommentChanged) return true; if (!this->mUserNameChanged && !this->mCommentChanged) return true;
if (!this->mUserNameChanged) { if (!this->mUserNameChanged)
if (mNewUserName.isEmpty()) { {
if (mNewUserName.isEmpty())
{
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; return false;
} }
@@ -195,21 +215,26 @@ bool AccountFormDialog::updateReferenceData() {
} }
if (!this->mCommentChanged) User::Current()->setUserName(mLeComment->text()); if (!this->mCommentChanged) User::Current()->setUserName(mLeComment->text());
bool ret = User::Current()->submitChange(); bool ret = User::Current()->submitChange();
if (ret) { if (ret)
{
hideWarn(); hideWarn();
LOG_USER_OPERATION(ChangeUserName) LOG_USER_OPERATION(ChangeUserName)
} }
else { else
{
warn(tr("Submit change to database fail!")); warn(tr("Submit change to database fail!"));
} }
return ret; return ret;
} }
else if (mMode == Admin) { else if (mMode == Admin)
{
if (!this->mUserNameChanged && !this->mRoleChanged) return true; if (!this->mUserNameChanged && !this->mRoleChanged) return true;
User user; User user;
if (!User::getUser(mUserID, user)) return true; if (!User::getUser(mUserID, user)) return true;
if (this->mUserNameChanged) { if (this->mUserNameChanged)
if (mNewUserName.isEmpty()) { {
if (mNewUserName.isEmpty())
{
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; return false;
} }
@@ -218,31 +243,38 @@ bool AccountFormDialog::updateReferenceData() {
if (this->mRoleChanged) user.setRoleID(mRoleID); if (this->mRoleChanged) user.setRoleID(mRoleID);
if (!this->mCommentChanged) user.setComment(mLeComment->text()); if (!this->mCommentChanged) user.setComment(mLeComment->text());
bool ret = user.submitChange(); bool ret = user.submitChange();
if (ret) { if (ret)
{
LOG_USER_OPERATION(AdminChangeAcountInformation) LOG_USER_OPERATION(AdminChangeAcountInformation)
} }
return ret; return ret;
} }
else { else
{
//add new //add new
User user; User user;
if (mLeUserCode->text().isEmpty()) { if (mLeUserCode->text().isEmpty())
{
warn(tr("User ID can't be empty!")); warn(tr("User ID can't be empty!"));
return false; return false;
} }
if (mLeUserName->text().isEmpty()) { if (mLeUserName->text().isEmpty())
{
warn(tr("User Name can't be empty!")); warn(tr("User Name can't be empty!"));
return false; return false;
} }
if (mLePwd->text().isEmpty()) { if (mLePwd->text().isEmpty())
{
warn(tr("Password can't be empty!")); warn(tr("Password can't be empty!"));
return false; return false;
} }
if (!mRefModel) { if (!mRefModel)
{
warn(tr("Inner error ,unset data model!")); warn(tr("Inner error ,unset data model!"));
return false; return false;
} }
if (User::existsUser(mLeUserCode->text())) { if (User::existsUser(mLeUserCode->text()))
{
warn(tr("User Id exists!")); warn(tr("User Id exists!"));
return false; return false;
} }
@@ -274,10 +306,13 @@ bool AccountFormDialog::updateReferenceData() {
#undef USER_READONLY_PROPERTY #undef USER_READONLY_PROPERTY
#undef USER_PROPERTY #undef USER_PROPERTY
if (mRefModel->submit()) { if (mRefModel->submit())
{
hideWarn(); hideWarn();
return true; return true;
} else { }
else
{
warn(tr("Submit to data base fail!")); warn(tr("Submit to data base fail!"));
return false; return false;
} }
@@ -285,7 +320,8 @@ bool AccountFormDialog::updateReferenceData() {
return true; return true;
} }
void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& values) { void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& values)
{
mLeUserCode->setText(values["UserCode"].toString()); mLeUserCode->setText(values["UserCode"].toString());
mLeUserName->setText(values["UserName"].toString()); mLeUserName->setText(values["UserName"].toString());
mLeComment->setText(values["Comment"].toString()); mLeComment->setText(values["Comment"].toString());
@@ -293,11 +329,13 @@ void AccountFormDialog::setAccountInformation(const QMap<QString, QVariant>& val
mUserPwd = values["Password"].toString(); mUserPwd = values["Password"].toString();
} }
void AccountFormDialog::warn(const QString& msg) { void AccountFormDialog::warn(const QString& msg)
{
mLblError->setText(msg); mLblError->setText(msg);
mLblError->setVisible(true); mLblError->setVisible(true);
} }
void AccountFormDialog::hideWarn() { void AccountFormDialog::hideWarn()
{
mLblError->setVisible(false); mLblError->setVisible(false);
} }

View File

@@ -5,7 +5,7 @@
#ifndef GUI_ACCOUNTFORMDIALOG_H #ifndef GUI_ACCOUNTFORMDIALOG_H
#define GUI_ACCOUNTFORMDIALOG_H #define GUI_ACCOUNTFORMDIALOG_H
class QLabel; class QLabel;
class QLineEdit; class ULineEdit;
class QToolButton; class QToolButton;
class QSqlTableModel; class QSqlTableModel;
@@ -21,7 +21,8 @@ public:
explicit AccountFormDialog(QWidget* parent = nullptr, AccountEditMode mode = Self, Qt::WindowFlags f = Qt::WindowFlags()); explicit AccountFormDialog(QWidget* parent = nullptr, AccountEditMode mode = Self, Qt::WindowFlags f = Qt::WindowFlags());
~AccountFormDialog() override = default; ~AccountFormDialog() override = default;
void setAccountInformation(const QMap<QString, QVariant>& values); void setAccountInformation(const QMap<QString, QVariant>& values);
void setReferenceModel(QSqlTableModel* model){ void setReferenceModel(QSqlTableModel* model)
{
mRefModel = model; mRefModel = model;
} }
protected: protected:
@@ -48,10 +49,10 @@ private:
bool mCommentChanged; bool mCommentChanged;
bool mRoleChanged; bool mRoleChanged;
AccountEditMode mMode; AccountEditMode mMode;
QLineEdit* mLeUserCode; ULineEdit* mLeUserCode;
QLineEdit* mLeUserName; ULineEdit* mLeUserName;
QLineEdit* mLeComment; ULineEdit* mLeComment;
QLineEdit* mLePwd; ULineEdit* mLePwd;
QToolButton* mBtnPwd; QToolButton* mBtnPwd;
QLabel* mLblError; QLabel* mLblError;

View File

@@ -4,22 +4,23 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QtWidgets/QLineEdit> #include "components/ULineEdit.h"
#include "models/User.h" #include "models/User.h"
#include "log/UserOperationLog.h" #include "log/UserOperationLog.h"
#include "ChangePasswordFormDialog.h" #include "ChangePasswordFormDialog.h"
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f) ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget* parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f) : GUIFormBaseDialog(parent, f)
, mLEPasswd(new QLineEdit(this)) , mLEPasswd(new ULineEdit(this))
, mLENewPasswd(new QLineEdit(this)) , mLENewPasswd(new ULineEdit(this))
, mLEConfirmPasswd(new QLineEdit(this)) , mLEConfirmPasswd(new ULineEdit(this))
, mLblError(new QLabel(this)) , mLblError(new QLabel(this))
{ {
initLayout(); initLayout();
} }
void ChangePasswordFormDialog::initLayout() { void ChangePasswordFormDialog::initLayout()
{
auto layout = new QVBoxLayout(mFormWidget); auto layout = new QVBoxLayout(mFormWidget);
layout->setSpacing(10); layout->setSpacing(10);
// add title // add title
@@ -67,13 +68,15 @@ void ChangePasswordFormDialog::initLayout() {
} }
bool ChangePasswordFormDialog::updateReferenceData() { bool ChangePasswordFormDialog::updateReferenceData()
{
if (mLEPasswd->text().isEmpty()) if (mLEPasswd->text().isEmpty())
{ {
mLblError->setText(tr("Please enter your old password!")); mLblError->setText(tr("Please enter your old password!"));
return false; return false;
} }
if (mLENewPasswd->text().length() < 6) { if (mLENewPasswd->text().length() < 6)
{
mLblError->setText(tr("New password should at least 6 characters!")); mLblError->setText(tr("New password should at least 6 characters!"));
return false; return false;
} }
@@ -89,7 +92,8 @@ bool ChangePasswordFormDialog::updateReferenceData() {
return false; return false;
} }
User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text())); User::Current()->setPassword(User::getEncryptedPassword(mLENewPasswd->text()));
if (!User::Current()->submitChange()) { if (!User::Current()->submitChange())
{
mLblError->setText(tr("Database update error!")); mLblError->setText(tr("Database update error!"));
User::Current()->restorePassword(encryptPwd); User::Current()->restorePassword(encryptPwd);
return false; return false;

View File

@@ -6,7 +6,7 @@
#define GUI_CHANGEPASSWORDFORMDIALOG_H #define GUI_CHANGEPASSWORDFORMDIALOG_H
#include "GUIFormBaseDialog.h" #include "GUIFormBaseDialog.h"
class QLineEdit; class ULineEdit;
class QLabel; class QLabel;
class ChangePasswordFormDialog :public GUIFormBaseDialog { class ChangePasswordFormDialog :public GUIFormBaseDialog {
Q_OBJECT Q_OBJECT
@@ -19,9 +19,9 @@ protected:
private: private:
void initLayout(); void initLayout();
QLineEdit* mLEPasswd; ULineEdit* mLEPasswd;
QLineEdit* mLENewPasswd; ULineEdit* mLENewPasswd;
QLineEdit* mLEConfirmPasswd; ULineEdit* mLEConfirmPasswd;
QLabel* mLblError; QLabel* mLblError;

View File

@@ -29,11 +29,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="tbx_ID"> <widget class="ULineEdit" name="tbx_ID" native="true">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="readOnly"> <property name="readOnly" stdset="0">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
@@ -46,11 +46,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="tbx_Name"> <widget class="ULineEdit" name="tbx_Name" native="true">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="readOnly"> <property name="readOnly" stdset="0">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
@@ -63,11 +63,11 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLineEdit" name="tbx_Sex"> <widget class="ULineEdit" name="tbx_Sex" native="true">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="readOnly"> <property name="readOnly" stdset="0">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
@@ -121,7 +121,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QTextEdit" name="rtbx_Comment"> <widget class="UTextEdit" name="rtbx_Comment">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
@@ -135,6 +135,18 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>ULineEdit</class>
<extends>QLineEdit</extends>
<header>components/ULineEdit.h</header>
</customwidget>
<customwidget>
<class>UTextEdit</class>
<extends>QTextEdit</extends>
<header>components/UTextEdit.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@@ -6,14 +6,13 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QDebug> #include <QDebug>
#include <QLabel> #include <QLabel>
#include <QLineEdit>
#include <QEvent> #include <QEvent>
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include "json/jsonobject.h" #include "json/jsonobject.h"
#include "src/dialogs/SelectDialog.h" #include "src/dialogs/SelectDialog.h"
#include "src/utilities/locker.h" #include "src/utilities/locker.h"
#include "src/utilities/languageswitcher.h" #include "src/utilities/languageswitcher.h"
#include "components/ULineEdit.h"
GeneralForm::GeneralForm(QWidget* parent) : QWidget(parent) GeneralForm::GeneralForm(QWidget* parent) : QWidget(parent)
{ {
@@ -34,14 +33,14 @@ GeneralForm::GeneralForm(QWidget* parent) : QWidget(parent)
QHBoxLayout* instHeaderLayout = new QHBoxLayout(instHeader); QHBoxLayout* instHeaderLayout = new QHBoxLayout(instHeader);
QLabel* lbl_ins = new QLabel(tr("Institution Name")); QLabel* lbl_ins = new QLabel(tr("Institution Name"));
instHeaderLayout->addWidget(lbl_ins); instHeaderLayout->addWidget(lbl_ins);
QLineEdit* instName = new QLineEdit(instHeader); QLineEdit* instName = new ULineEdit(instHeader);
instName->setMaximumSize(QSize(300, 32768)); instName->setMaximumSize(QSize(300, 32768));
instHeaderLayout->addWidget(instName); instHeaderLayout->addWidget(instName);
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Fixed)); instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Fixed));
QLabel* lbl_insaddr = new QLabel(tr("Institution Addr")); QLabel* lbl_insaddr = new QLabel(tr("Institution Addr"));
instHeaderLayout->addWidget(lbl_insaddr); instHeaderLayout->addWidget(lbl_insaddr);
QLineEdit* instAddr = new QLineEdit(instHeader); QLineEdit* instAddr = new ULineEdit(instHeader);
instHeaderLayout->addWidget(instAddr); instHeaderLayout->addWidget(instAddr);
instAddr->setMaximumSize(QSize(300, 32768)); instAddr->setMaximumSize(QSize(300, 32768));
instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding)); instHeaderLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
@@ -53,7 +52,7 @@ GeneralForm::GeneralForm(QWidget* parent) : QWidget(parent)
QLabel* lbl_lock = new QLabel(tr("Lock Screen")); QLabel* lbl_lock = new QLabel(tr("Lock Screen"));
lockHeaderLayout->addWidget(lbl_lock); lockHeaderLayout->addWidget(lbl_lock);
QLineEdit* lockTime = new QLineEdit(lockHeader); QLineEdit* lockTime = new ULineEdit(lockHeader);
lockTime->setMaximumSize(QSize(300, 32768)); lockTime->setMaximumSize(QSize(300, 32768));
lockHeaderLayout->addWidget(lockTime); lockHeaderLayout->addWidget(lockTime);

View File

@@ -3,7 +3,6 @@
#include <QPushButton> #include <QPushButton>
#include <QDebug> #include <QDebug>
#include <QLineEdit>
#include <QToolButton> #include <QToolButton>
#include <QGridLayout> #include <QGridLayout>

View File

@@ -5,10 +5,10 @@
class QPushButton; class QPushButton;
class QVBoxLayout; class QVBoxLayout;
class SelectDialog; class SelectDialog;
class QLineEdit;
class ImageSwitch; class ImageSwitch;
namespace Ui { namespace Ui
{
class systemSettingForm; class systemSettingForm;
} }

View File

@@ -0,0 +1,23 @@
#include "KeyboardManager.h"
#include "KeyboardPanel.h"
KeyboardManager* KeyboardManager::getInstance()
{
static KeyboardManager instance;
return &instance;
}
KeyboardManager::KeyboardManager()
: mKeyboardPanel(new KeyboardPanel())
{
}
KeyboardManager::~KeyboardManager()
{
}
void KeyboardManager::showKeyboardPanel(QWidget* aInputWidget)
{
mKeyboardPanel->showPanel(aInputWidget);
}

View File

@@ -0,0 +1,27 @@
#ifndef KEYBOARDMANAGER_H
#define KEYBOARDMANAGER_H
#include <QObject>
#include <memory>
class KeyboardPanel;
typedef std::shared_ptr<KeyboardPanel> KeyboardPanelPointer;
class KeyboardManager : public QObject
{
Q_OBJECT
public:
static KeyboardManager* getInstance();
void showKeyboardPanel(QWidget* aInputWidget);
private:
explicit KeyboardManager();
~KeyboardManager();
private:
KeyboardPanelPointer mKeyboardPanel;
};
#endif // KEYBOARDMANAGER_H

View File

@@ -1,37 +1,35 @@
#include "InputObject.h" #include "KeyboardPanel.h"
#include "ui_InputObject.h" #include "ui_KeyboardPanel.h"
#include <QDebug>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QComboBox> #include <QComboBox>
#include <QDateEdit> #include <QDateEdit>
#include <QtVirtualKeyboard>
#include <QKeyEvent> #include <QKeyEvent>
#include <QLineEdit> #include <QLineEdit>
#include <QAbstractSpinBox> #include <QAbstractSpinBox>
InputObject::InputObject(QWidget* aParent) KeyboardPanel::KeyboardPanel(QWidget* aParent)
: QWidget(aParent) : QWidget(aParent)
, mUI(new Ui::InputObject) , mUI(new Ui::KeyboardPanel)
, mCurrentDateEdit(nullptr)
, mCurrentLineEdit(nullptr) , mCurrentLineEdit(nullptr)
, mCurrentTextEdit(nullptr) , mCurrentTextEdit(nullptr)
{ {
mUI->setupUi(this); mUI->setupUi(this);
initializeStyle();
initUi(); initUi();
setVisible(false); setVisible(false);
setWindowFlags(Qt::Tool | Qt::FramelessWindowHint); setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
} }
InputObject::~InputObject() KeyboardPanel::~KeyboardPanel()
{ {
delete mUI; delete mUI;
} }
void InputObject::initUi() void KeyboardPanel::initializeStyle()
{ {
//#3c3c3c //#3c3c3c
#ifdef CUTE_STYLE #ifdef CUTE_STYLE
@@ -66,108 +64,37 @@ void InputObject::initUi()
; ;
#endif #endif
setStyleSheet(style); setStyleSheet(style);
}
mUI->dateEdit->setVisible(false); void KeyboardPanel::initUi()
mUI->dateEdit->setMaximumDate(QDate::currentDate()); {
mUI->dateEdit->setDisplayFormat("yyyy/MM/dd");
mUI->dateEdit->setStyleSheet(style);
connect(QGuiApplication::inputMethod(), &QInputMethod::visibleChanged, [=]() { connect(QGuiApplication::inputMethod(), &QInputMethod::visibleChanged, [=]() {
if (QGuiApplication::inputMethod()->isVisible()) if (QGuiApplication::inputMethod()->isVisible())
{ {
return; return;
} }
HidePanel(); hidePanel();
hide(); hide();
}); });
} }
bool InputObject::eventFilter(QObject* aObject, QEvent* aEvent) void KeyboardPanel::showPanel(QWidget* aInputWidget)
{ {
if (aEvent->type() == QEvent::MouseButtonPress) if (!aInputWidget)
{
emit touchScreen();
}
if (aEvent->type() == QEvent::KeyPress)
{
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(aEvent);
if (keyEvent->key() == Qt::Key_Return && mCurrentDateEdit)
{
HidePanel();
hide();
}
}
//mouse button release means setfocus is useless
if (aEvent->type() == QEvent::MouseButtonRelease)
{
if (aObject->objectName() == QString("qt_spinbox_lineedit"))
{
QDateEdit* dateEdit = qobject_cast<QDateEdit*>(aObject->parent());
if (dateEdit == mUI->dateEdit)
{
return true;
}
if (dateEdit->isEnabled())
{
ShowPanel();
return true;
}
}
if (aObject->objectName() == QString("qt_scrollarea_viewport"))
{
QTextEdit* textEdit = qobject_cast<QTextEdit*>(aObject->parent());
if (!textEdit)
{
return false;
}
if (textEdit == mUI->textEdit)
{
return true;
}
if (textEdit->isEnabled())
{
ShowPanel();
return true;
}
}
if (aObject->inherits("QLineEdit"))
{
QLineEdit* lineEdit = qobject_cast<QLineEdit*>(aObject);
//you have to tell whether it is coming from qdateedit!!!
if (mUI->lineEdit != lineEdit && lineEdit->isEnabled())
{
ShowPanel();
return true;
}
}
}
return QObject::eventFilter(aObject, aEvent);
}
void InputObject::ShowPanel()
{
if (!qApp->focusWidget())
{ {
return; return;
} }
if (qApp->focusWidget()->inherits("QLineEdit"))
if (aInputWidget->inherits("QLineEdit"))
{ {
mCurrentLineEdit = qobject_cast<QLineEdit*>(qApp->focusWidget()); mCurrentLineEdit = qobject_cast<QLineEdit*>(aInputWidget);
mUI->dateEdit->setVisible(false); mUI->dateEdit->setVisible(false);
mUI->lineEdit->setVisible(true); mUI->lineEdit->setVisible(true);
mUI->textEdit->setVisible(false); mUI->textEdit->setVisible(false);
} }
if (qApp->focusWidget()->inherits("QDateEdit")) else if (aInputWidget->inherits("QTextEdit"))
{ {
mCurrentDateEdit = qobject_cast<QDateEdit*>(qApp->focusWidget()); mCurrentTextEdit = qobject_cast<QTextEdit*>(aInputWidget);
mUI->dateEdit->setVisible(true);
mUI->lineEdit->setVisible(false);
mUI->textEdit->setVisible(false);
}
if (qApp->focusWidget()->inherits("QTextEdit"))
{
mCurrentTextEdit = qobject_cast<QTextEdit*>(qApp->focusWidget());
mUI->dateEdit->setVisible(false); mUI->dateEdit->setVisible(false);
mUI->lineEdit->setVisible(false); mUI->lineEdit->setVisible(false);
mUI->textEdit->setVisible(true); mUI->textEdit->setVisible(true);
@@ -179,7 +106,7 @@ void InputObject::ShowPanel()
activateWindow(); //it is quite important!!! activateWindow(); //it is quite important!!!
while (QApplication::activeWindow() != this) while (QApplication::activeWindow() != this)
{ {
qApp->processEvents(); QApplication::processEvents();
} }
if (mCurrentLineEdit) if (mCurrentLineEdit)
@@ -192,21 +119,7 @@ void InputObject::ShowPanel()
QEvent event(QEvent::RequestSoftwareInputPanel); QEvent event(QEvent::RequestSoftwareInputPanel);
QApplication::sendEvent(mUI->lineEdit, &event); QApplication::sendEvent(mUI->lineEdit, &event);
} }
if (mCurrentDateEdit) else if (mCurrentTextEdit)
{
mUI->dateEdit->setDateTime(mCurrentDateEdit->dateTime());
mUI->dateEdit->setFocus();
while (QGuiApplication::focusObject() != mUI->dateEdit)
{
qApp->processEvents();
}
qDebug() << QGuiApplication::focusObject();
QEvent event(QEvent::RequestSoftwareInputPanel);
QApplication::sendEvent(mUI->dateEdit, &event);
}
if (mCurrentTextEdit)
{ {
mUI->textEdit->setPlainText(mCurrentTextEdit->toPlainText()); mUI->textEdit->setPlainText(mCurrentTextEdit->toPlainText());
mUI->textEdit->setFocus(); mUI->textEdit->setFocus();
@@ -219,7 +132,7 @@ void InputObject::ShowPanel()
} }
} }
void InputObject::HidePanel() void KeyboardPanel::hidePanel()
{ {
if (mCurrentLineEdit) if (mCurrentLineEdit)
{ {
@@ -228,13 +141,6 @@ void InputObject::HidePanel()
mUI->lineEdit->clear(); mUI->lineEdit->clear();
mCurrentLineEdit = nullptr; mCurrentLineEdit = nullptr;
} }
else if (mCurrentDateEdit)
{
mCurrentDateEdit->setDateTime(mUI->dateEdit->dateTime());
mUI->dateEdit->clearFocus();
mUI->dateEdit->clear();
mCurrentDateEdit = nullptr;
}
else if (mCurrentTextEdit) else if (mCurrentTextEdit)
{ {
mCurrentTextEdit->setText(mUI->textEdit->toPlainText()); mCurrentTextEdit->setText(mUI->textEdit->toPlainText());

View File

@@ -0,0 +1,35 @@
#ifndef KEYBOARDPANEL_H
#define KEYBOARDPANEL_H
#include <QWidget>
class QLineEdit;
class QDateEdit;
class QTextEdit;
namespace Ui
{
class KeyboardPanel;
}
class KeyboardPanel : public QWidget
{
Q_OBJECT
public:
explicit KeyboardPanel(QWidget* aParent = nullptr);
~KeyboardPanel();
void showPanel(QWidget* aInputWidget);
void hidePanel();
private:
void initializeStyle();
void initUi();
private:
Ui::KeyboardPanel* mUI;
QLineEdit* mCurrentLineEdit;
QTextEdit* mCurrentTextEdit;
};
#endif // KEYBOARDPANEL_H

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>InputObject</class> <class>KeyboardPanel</class>
<widget class="QWidget" name="InputObject"> <widget class="QWidget" name="KeyboardPanel">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>

View File

@@ -1,7 +1,6 @@
#include "windows/MainWindow.h" #include "windows/MainWindow.h"
#include <QApplication> #include "UsctApplication.h"
#include "windows/LoginDialog.h" #include "windows/LoginDialog.h"
#include "src/utilities/InputObject.h"
#include <QQmlApplicationEngine> #include <QQmlApplicationEngine>
#include "db/SQLHelper.h" #include "db/SQLHelper.h"
#include <QTextCodec> #include <QTextCodec>
@@ -13,8 +12,10 @@
#include <QTranslator> #include <QTranslator>
#include <src/device/DeviceManager.h> #include <src/device/DeviceManager.h>
#include "json/jsonobject.h" #include "json/jsonobject.h"
#include "src/utilities/locker.h" #include "src/utilities/Locker.h"
#include "src/utilities/languageswitcher.h" #include "src/utilities/LanguageSwitcher.h"
#include "utilities/TouchScreenSignalSender.h"
QString loadFontFromFile(QString path) QString loadFontFromFile(QString path)
{ {
static QString font; static QString font;
@@ -41,7 +42,7 @@ int main(int argc, char* argv[])
//qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true")); //qputenv("QT_LOGGING_RULES", QByteArray("qt.virtualkeyboard=true"));
QApplication a(argc, argv); UsctApplication a(argc, argv);
QString layouts_path = QString(QCoreApplication::applicationDirPath()).append("/layouts"); QString layouts_path = QString(QCoreApplication::applicationDirPath()).append("/layouts");
qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(layouts_path.toStdString().c_str())); qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(layouts_path.toStdString().c_str()));
@@ -59,15 +60,13 @@ int main(int argc, char* argv[])
QFont font(fontName); QFont font(fontName);
QApplication::setFont(font); QApplication::setFont(font);
InputObject* obj = new InputObject();
a.installEventFilter(obj);
SQLHelper::Open(); SQLHelper::Open();
MainWindow w; MainWindow w;
UserOperationLog::Default()->init(); UserOperationLog::Default()->init();
//暂时为了调试关闭锁屏 //暂时为了调试关闭锁屏
//Locker::Instance()->start(); //Locker::getInstance()->start();
//QObject::connect(obj, SIGNAL(touchScreen()), Locker::Instance(), SLOT(refreshTimer())); //QObject::connect(TouchScreenSignalSender::getInstance(), SIGNAL(touchScreen()), Locker::getInstance(), SLOT(refreshTimer()));
QList<Qt::GestureType> gestures; QList<Qt::GestureType> gestures;
gestures << Qt::SwipeGesture; gestures << Qt::SwipeGesture;
gestures << Qt::PanGesture; gestures << Qt::PanGesture;

View File

@@ -70,13 +70,13 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="wl_IP"/> <widget class="ULineEdit" name="wl_IP"/>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QLineEdit" name="wl_Port"/> <widget class="ULineEdit" name="wl_Port"/>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="wl_AE"/> <widget class="ULineEdit" name="wl_AE"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="verticalSpacer_3"> <spacer name="verticalSpacer_3">
@@ -129,7 +129,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="wl_Name"/> <widget class="ULineEdit" name="wl_Name"/>
</item> </item>
<item row="6" column="2"> <item row="6" column="2">
<widget class="QToolButton" name="toolButton_2"> <widget class="QToolButton" name="toolButton_2">
@@ -157,10 +157,10 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="pacs_IP"/> <widget class="ULineEdit" name="pacs_IP"/>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="pacs_AE"/> <widget class="ULineEdit" name="pacs_AE"/>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="lbl_Name_2"> <widget class="QLabel" name="lbl_Name_2">
@@ -190,7 +190,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="pacs_Port"/> <widget class="ULineEdit" name="pacs_Port"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
@@ -209,7 +209,7 @@
</spacer> </spacer>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="pacs_Name"/> <widget class="ULineEdit" name="pacs_Name"/>
</item> </item>
<item row="5" column="0"> <item row="5" column="0">
<widget class="QLabel" name="lbl_Port_2"> <widget class="QLabel" name="lbl_Port_2">
@@ -247,7 +247,7 @@
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="recon_Name"/> <widget class="ULineEdit" name="recon_Name"/>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
@@ -280,7 +280,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="recon_IP"/> <widget class="ULineEdit" name="recon_IP"/>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="lbl_Name_3"> <widget class="QLabel" name="lbl_Name_3">
@@ -296,7 +296,7 @@
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="6" column="1">
<widget class="QLineEdit" name="recon_Port"/> <widget class="ULineEdit" name="recon_Port"/>
</item> </item>
<item row="4" column="0"> <item row="4" column="0">
<widget class="QLabel" name="lbl_AE_3"> <widget class="QLabel" name="lbl_AE_3">
@@ -306,7 +306,7 @@
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="4" column="1">
<widget class="QLineEdit" name="recon_AE"/> <widget class="ULineEdit" name="recon_AE"/>
</item> </item>
<item row="6" column="2"> <item row="6" column="2">
<widget class="QToolButton" name="toolButton_3"> <widget class="QToolButton" name="toolButton_3">
@@ -382,4 +382,11 @@
</hints> </hints>
</connection> </connection>
</connections> </connections>
<customwidgets>
<customwidget>
<class>ULineEdit</class>
<extends>QLineEdit</extends>
<header location="global">components/ULineEdit.h</header>
</customwidget>
</customwidgets>
</ui> </ui>

View File

@@ -5,7 +5,7 @@
#include <QFormLayout> #include <QFormLayout>
#include <QLabel> #include <QLabel>
#include <QtWidgets/QLineEdit> #include "components/ULineEdit.h"
#ifndef WIN32 #ifndef WIN32
#include <src/device/networkmanager.h> #include <src/device/networkmanager.h>
@@ -13,7 +13,7 @@
GetAdminPsw::GetAdminPsw(QWidget* parent, Qt::WindowFlags f) GetAdminPsw::GetAdminPsw(QWidget* parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f) : GUIFormBaseDialog(parent, f)
, mPsw(new QLineEdit(this)) , mPsw(new ULineEdit(this))
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);

View File

@@ -7,7 +7,7 @@
#include "src/dialogs/GUIFormBaseDialog.h" #include "src/dialogs/GUIFormBaseDialog.h"
class QLineEdit; class ULineEdit;
class QLabel; class QLabel;
class GetAdminPsw : public GUIFormBaseDialog class GetAdminPsw : public GUIFormBaseDialog
@@ -22,7 +22,7 @@ protected:
bool updateReferenceData(); bool updateReferenceData();
private: private:
QLineEdit* mPsw = nullptr; ULineEdit* mPsw = nullptr;
QLabel* mLabelError = nullptr; QLabel* mLabelError = nullptr;
}; };

View File

@@ -6,14 +6,14 @@
#include <QFormLayout> #include <QFormLayout>
#include <QLabel> #include <QLabel>
#include <QtWidgets/QLineEdit> #include "components/ULineEdit.h"
#include "device/networkmanager.h" #include "device/networkmanager.h"
GetIPDialog::GetIPDialog(QWidget* parent, Qt::WindowFlags f) GetIPDialog::GetIPDialog(QWidget* parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f) : GUIFormBaseDialog(parent, f)
, mIp(new QLineEdit(this)) , mIp(new ULineEdit(this))
, mMask(new QLineEdit(this)) , mMask(new ULineEdit(this))
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);

View File

@@ -7,7 +7,7 @@
#include "src/dialogs/GUIFormBaseDialog.h" #include "src/dialogs/GUIFormBaseDialog.h"
class QLineEdit; class ULineEdit;
class QLabel; class QLabel;
class GetIPDialog :public GUIFormBaseDialog class GetIPDialog :public GUIFormBaseDialog
@@ -24,8 +24,8 @@ protected:
bool updateReferenceData(); bool updateReferenceData();
private: private:
QLineEdit* mIp = nullptr; ULineEdit* mIp = nullptr;
QLineEdit* mMask = nullptr; ULineEdit* mMask = nullptr;
QLabel* mLabelError = nullptr; QLabel* mLabelError = nullptr;
}; };

View File

@@ -6,15 +6,15 @@
#include <QFormLayout> #include <QFormLayout>
#include <QLabel> #include <QLabel>
#include <QtWidgets/QLineEdit> #include "components/ULineEdit.h"
#include "device/networkmanager.h" #include "device/networkmanager.h"
GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f) GetRouteDialog::GetRouteDialog(QWidget* parent, Qt::WindowFlags f)
: GUIFormBaseDialog(parent, f) : GUIFormBaseDialog(parent, f)
, mDestination(new QLineEdit(this)) , mDestination(new ULineEdit(this))
, mNetmask(new QLineEdit(this)) , mNetmask(new ULineEdit(this))
, mGateway(new QLineEdit(this)) , mGateway(new ULineEdit(this))
, mLabelError(new QLabel(this)) , mLabelError(new QLabel(this))
{ {
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);

View File

@@ -7,7 +7,7 @@
#include "src/dialogs/GUIFormBaseDialog.h" #include "src/dialogs/GUIFormBaseDialog.h"
class QLineEdit; class ULineEdit;
class QLabel; class QLabel;
class GetRouteDialog :public GUIFormBaseDialog class GetRouteDialog :public GUIFormBaseDialog
@@ -24,9 +24,9 @@ protected:
bool updateReferenceData(); bool updateReferenceData();
private: private:
QLineEdit* mDestination = nullptr; ULineEdit* mDestination = nullptr;
QLineEdit* mNetmask = nullptr; ULineEdit* mNetmask = nullptr;
QLineEdit* mGateway = nullptr; ULineEdit* mGateway = nullptr;
QLabel* mLabelError = nullptr; QLabel* mLabelError = nullptr;
}; };

View File

@@ -37,7 +37,7 @@
background:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #ABABAB, stop: 1.0 #CDCDCD); background:qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #ABABAB, stop: 1.0 #CDCDCD);
} }
QLineEdit#led_inface{font-size:15px;border: 0px;} ULineEdit#led_inface{font-size:15px;border: 0px;}
</string> </string>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_5">
@@ -103,7 +103,7 @@
</spacer> </spacer>
</item> </item>
<item row="5" column="0"> <item row="5" column="0">
<widget class="QLineEdit" name="addr_ip"/> <widget class="ULineEdit" name="addr_ip"/>
</item> </item>
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
@@ -152,7 +152,7 @@
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="led_inface"> <widget class="ULineEdit" name="led_inface">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@@ -187,7 +187,7 @@
</widget> </widget>
</item> </item>
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="addr_mask"/> <widget class="ULineEdit" name="addr_mask"/>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
@@ -301,7 +301,7 @@
<widget class="QWidget" name="widget_4" native="true"> <widget class="QWidget" name="widget_4" native="true">
<layout class="QGridLayout" name="gridLayout_3"> <layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLineEdit" name="led_gw"> <widget class="ULineEdit" name="led_gw">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@@ -453,13 +453,13 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLineEdit" name="daq_AE"/> <widget class="ULineEdit" name="daq_AE"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLineEdit" name="daq_Name"/> <widget class="ULineEdit" name="daq_Name"/>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLineEdit" name="daq_Port"/> <widget class="ULineEdit" name="daq_Port"/>
</item> </item>
<item row="3" column="0"> <item row="3" column="0">
<widget class="QLabel" name="lbl_Port"> <widget class="QLabel" name="lbl_Port">
@@ -496,7 +496,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="daq_IP"> <widget class="ULineEdit" name="daq_IP">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
@@ -563,6 +563,11 @@
<extends>QTableView</extends> <extends>QTableView</extends>
<header location="global">components/SlideTableView.h</header> <header location="global">components/SlideTableView.h</header>
</customwidget> </customwidget>
<customwidget>
<class>ULineEdit</class>
<extends>QLineEdit</extends>
<header location="global">components/ULineEdit.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@@ -1,37 +0,0 @@
#ifndef INPUTOBJECT_H
#define INPUTOBJECT_H
#include <QWidget>
class QLineEdit;
class QDateEdit;
class QTextEdit;
namespace Ui
{
class InputObject;
}
class InputObject : public QWidget
{
Q_OBJECT
public:
explicit InputObject(QWidget* aParent = nullptr);
~InputObject();
bool eventFilter(QObject* aObject, QEvent* aEvent);
signals:
void touchScreen();
private:
Ui::InputObject* mUI;
void initUi();
void ShowPanel();
void HidePanel();
QDateEdit* mCurrentDateEdit = nullptr;
QLineEdit* mCurrentLineEdit = nullptr;
QTextEdit* mCurrentTextEdit = nullptr;
};
#endif // INPUTOBJECT_H

View File

@@ -0,0 +1,20 @@
#include "TouchScreenSignalSender.h"
TouchScreenSignalSender* TouchScreenSignalSender::getInstance()
{
static TouchScreenSignalSender instance;
return &instance;
}
TouchScreenSignalSender::TouchScreenSignalSender()
{
}
TouchScreenSignalSender::~TouchScreenSignalSender()
{
}
void TouchScreenSignalSender::sendTouchScreenSignal()
{
emit touchScreen();
}

View File

@@ -0,0 +1,22 @@
#ifndef TOUCHSCREENSIGNALSENDER_H
#define TOUCHSCREENSIGNALSENDER_H
#include <QObject>
class TouchScreenSignalSender : public QObject
{
Q_OBJECT
public:
static TouchScreenSignalSender* getInstance();
void sendTouchScreenSignal();
signals:
void touchScreen();
private:
explicit TouchScreenSignalSender();
~TouchScreenSignalSender();
};
#endif // TOUCHSCREENSIGNALSENDER_H

View File

@@ -1,7 +1,6 @@
#include "LoginDialog.h" #include "LoginDialog.h"
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLineEdit>
#include <QToolButton> #include <QToolButton>
#include <QFrame> #include <QFrame>
#include <QInputMethodEvent> #include <QInputMethodEvent>
@@ -11,11 +10,11 @@
#include "guimacros.h" #include "guimacros.h"
#include "event/EventCenter.h" #include "event/EventCenter.h"
#include "db/SQLHelper.h" #include "db/SQLHelper.h"
#include "utilities/InputObject.h"
#include "models/User.h" #include "models/User.h"
#include "log/UserOperationLog.h" #include "log/UserOperationLog.h"
#include "json/jsonobject.h" #include "json/jsonobject.h"
#include "dialogs/guimessagedialog.h" #include "dialogs/guimessagedialog.h"
#include "components/ULineEdit.h"
LoginDialog::LoginDialog(QWidget* aParent) LoginDialog::LoginDialog(QWidget* aParent)
: QDialog(aParent) : QDialog(aParent)
@@ -23,8 +22,8 @@ LoginDialog::LoginDialog(QWidget* aParent)
, mDialogTitle(new QLabel(this)) , mDialogTitle(new QLabel(this))
, mDialogFrame(new QFrame(this)) , mDialogFrame(new QFrame(this))
, mDialogContentsLayout(new QVBoxLayout(mDialogFrame)) , mDialogContentsLayout(new QVBoxLayout(mDialogFrame))
, mAccountEdit(new QLineEdit(mDialogFrame)) , mAccountEdit(new ULineEdit(mDialogFrame))
, mPasswordEdit(new QLineEdit(mDialogFrame)) , mPasswordEdit(new ULineEdit(mDialogFrame))
, mLoginButton(nullptr) , mLoginButton(nullptr)
, mErrorMessage(new QLabel(this)) , mErrorMessage(new QLabel(this))
{ {

View File

@@ -6,7 +6,7 @@
#include <QDialog> #include <QDialog>
class QVBoxLayout; class QVBoxLayout;
class QLineEdit; class ULineEdit;
class QToolButton; class QToolButton;
class QFrame; class QFrame;
class QLabel; class QLabel;
@@ -41,8 +41,8 @@ private:
QLabel* mDialogTitle; QLabel* mDialogTitle;
QFrame* mDialogFrame; QFrame* mDialogFrame;
QVBoxLayout* mDialogContentsLayout; QVBoxLayout* mDialogContentsLayout;
QLineEdit* mAccountEdit; ULineEdit* mAccountEdit;
QLineEdit* mPasswordEdit; ULineEdit* mPasswordEdit;
QToolButton* mLoginButton; QToolButton* mLoginButton;
QLabel* mErrorMessage; QLabel* mErrorMessage;
}; };

View File

@@ -3,7 +3,6 @@
#include <qtabwidget.h> #include <qtabwidget.h>
#include <QSizePolicy> #include <QSizePolicy>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QTextEdit>
#include <QScrollBar> #include <QScrollBar>
#include <QDateTime> #include <QDateTime>
#include <QGestureEvent> #include <QGestureEvent>
@@ -24,6 +23,7 @@
#include "LoginDialog.h" #include "LoginDialog.h"
#include "models/User.h" #include "models/User.h"
#include "appvals/AppGlobalValues.h" #include "appvals/AppGlobalValues.h"
#include "components/UTextEdit.h"
MainWindow::MainWindow(QWidget* aParent) MainWindow::MainWindow(QWidget* aParent)
: QMainWindow(aParent) : QMainWindow(aParent)
@@ -256,8 +256,7 @@ void MainWindow::QMessageOutput(QtMsgType aType, const QMessageLogContext& aCont
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
mThread->quit(); mThread->terminate();
mThread->wait();
mThread->deleteLater(); mThread->deleteLater();
delete mUI; delete mUI;
} }
@@ -322,7 +321,7 @@ void MainWindow::debugConsoleOn()
mDebugConsoleWidget->setAllowedAreas(Qt::RightDockWidgetArea); mDebugConsoleWidget->setAllowedAreas(Qt::RightDockWidgetArea);
this->addDockWidget(static_cast<Qt::DockWidgetArea>(2), mDebugConsoleWidget); this->addDockWidget(static_cast<Qt::DockWidgetArea>(2), mDebugConsoleWidget);
mDebugMessageConsole = new QTextEdit(this); mDebugMessageConsole = new UTextEdit(this);
mDebugMessageConsole->setFocusPolicy(Qt::NoFocus); mDebugMessageConsole->setFocusPolicy(Qt::NoFocus);
mDebugConsoleWidget->setWidget(mDebugMessageConsole); mDebugConsoleWidget->setWidget(mDebugMessageConsole);