Login.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. QString strTip;
  52. QString strUser = ui->userNameLineEdit->text().trimmed();
  53. if (!strUser.isEmpty())
  54. {
  55. QString strPass = ui->passLineEdit->text().trimmed();
  56. if (!strPass.isEmpty())
  57. {
  58. //JEncryption::Encryption();
  59. emit SendSwitchOriginalWndSignals();
  60. /*if (QStackedWidget* parent = qobject_cast<QStackedWidget*>(this->parentWidget()))
  61. {
  62. OriginalWnd* originalWnd = new OriginalWnd(this);
  63. parent->addWidget(originalWnd);
  64. parent->setCurrentIndex(parent->indexOf(originalWnd));
  65. }*/
  66. return;
  67. }
  68. else
  69. {
  70. strTip = tr("Please enter your password", "请输入密码");
  71. }
  72. }
  73. else
  74. {
  75. strTip = tr("Please enter your username", "请输入用户名称");
  76. }
  77. JMessageTip::Message_warning(strTip);
  78. }
  79. void Login::on_ExitButton_clicked()
  80. {
  81. emit CloseMainWndSig();
  82. }