Login.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "Login.h"
  2. #include "OriginalWnd/OriginalWnd.h"
  3. #include "ui_Login.h"
  4. #include <QStackedWidget>
  5. #include <qDebug>
  6. #include <QSettings>
  7. #include "Src/common/JMessageTip.h"
  8. #include "Src/common/UserManagementShared.h"
  9. Login::Login(QWidget *parent)
  10. : QMainWindow(parent)
  11. , ui(new Ui::Login)
  12. {
  13. ui->setupUi(this);
  14. initForm();
  15. if(gen_if.getLanguageValue() == 0){
  16. }else{
  17. setChineseMode(this);
  18. }
  19. }
  20. Login::~Login()
  21. {
  22. delete ui;
  23. }
  24. void Login::initForm()
  25. {
  26. QPixmap pixmap(":/images/logo.png");
  27. QPixmap scaledPixmap = pixmap.scaled(283, 40, Qt::KeepAspectRatio);
  28. ui->label_logo->setPixmap(scaledPixmap);
  29. ui->userNameLineEdit->setPlaceholderText(tr("Please enter the account number"));
  30. ui->passLineEdit->setPlaceholderText(tr("Please enter your password"));
  31. connect(ui->userNameLineEdit, &QLineEdit::textChanged, this, &Login::onUserNameChanged);
  32. }
  33. void Login::setChineseMode(QMainWindow *Login)
  34. {
  35. Login->setWindowTitle(tr("Login", "主界面"));
  36. ui->SinginButton->setText(tr("Login", "登录"));
  37. ui->label_logo->setText(QString());
  38. ui->label_pass->setText(QString());
  39. ui->label_user->setText(QString());
  40. ui->ExitButton->setText(tr("Login", "退出"));
  41. ui->userNameLineEdit->setPlaceholderText("请输入账号");
  42. ui->passLineEdit->setPlaceholderText("请输入密码");
  43. }
  44. void Login::onUserNameChanged(const QString &userName)
  45. {
  46. QSettings settings("YourCompany_2", "YourAppName_2");
  47. settings.setValue("userName", userName);
  48. }
  49. void Login::on_SinginButton_clicked()
  50. {
  51. emit SendSwitchOriginalWndSignals();
  52. return;
  53. QString strTip;
  54. QString strUser = ui->userNameLineEdit->text().trimmed();
  55. if (!strUser.isEmpty())
  56. {
  57. QString strPass = ui->passLineEdit->text().trimmed();
  58. if (!strPass.isEmpty())
  59. {
  60. //JEncryption::Encryption();
  61. emit SendSwitchOriginalWndSignals();
  62. /*if (QStackedWidget* parent = qobject_cast<QStackedWidget*>(this->parentWidget()))
  63. {
  64. OriginalWnd* originalWnd = new OriginalWnd(this);
  65. parent->addWidget(originalWnd);
  66. parent->setCurrentIndex(parent->indexOf(originalWnd));
  67. }*/
  68. return;
  69. }
  70. else
  71. {
  72. strTip = tr("Please enter your password", "请输入密码");
  73. }
  74. }
  75. else
  76. {
  77. strTip = tr("Please enter your username", "请输入用户名称");
  78. }
  79. JMessageTip::Message_warning(strTip);
  80. }
  81. void Login::on_ExitButton_clicked()
  82. {
  83. emit CloseMainWndSig();
  84. }