From e2199df3a5d73b4d08441b2555595b99d166b472 Mon Sep 17 00:00:00 2001 From: ProYRB <68465426+ProYRB@users.noreply.github.com> Date: Sat, 10 Apr 2021 18:40:26 +0800 Subject: [PATCH] Add files via upload Update Debug 1.0. --- cencrypt.cpp | 34 + cencrypt.h | 36 + cgobangchessboard.cpp | 1335 ++++++++++++++++++++++++++ cgobangchessboard.h | 83 ++ cgobangchessman.cpp | 70 ++ cgobangchessman.h | 51 + cloginwindow.cpp | 219 +++++ cloginwindow.h | 70 ++ cloginwindow.ui | 781 +++++++++++++++ cmainwindow.cpp | 157 +++ cmainwindow.h | 47 + cmainwindow.ui | 1382 +++++++++++++++++++++++++++ cmodifypassworddialog.cpp | 141 +++ cmodifypassworddialog.h | 52 + cmodifypassworddialog.ui | 870 +++++++++++++++++ cmodifysecretivequestionsdialog.cpp | 122 +++ cmodifysecretivequestionsdialog.h | 50 + cmodifysecretivequestionsdialog.ui | 855 +++++++++++++++++ cproductinformationdialog.cpp | 20 + cproductinformationdialog.h | 29 + cproductinformationdialog.ui | 297 ++++++ cregisterdialog.cpp | 143 +++ cregisterdialog.h | 59 ++ cregisterdialog.ui | 1147 ++++++++++++++++++++++ cretrievedialog.cpp | 89 ++ cretrievedialog.h | 58 ++ cretrievedialog.ui | 861 +++++++++++++++++ cstring.cpp | 180 ++++ cstring.h | 62 ++ intelligentwindow.ico | Bin 0 -> 61310 bytes intelligentwindow.rc | 1 + intelligentwindowclient.pro | 70 ++ intelligentwindowclient.qrc | 45 + intelligentwindowclient_zh_CN.ts | 3 + main.cpp | 38 + 35 files changed, 9457 insertions(+) create mode 100644 cencrypt.cpp create mode 100644 cencrypt.h create mode 100644 cgobangchessboard.cpp create mode 100644 cgobangchessboard.h create mode 100644 cgobangchessman.cpp create mode 100644 cgobangchessman.h create mode 100644 cloginwindow.cpp create mode 100644 cloginwindow.h create mode 100644 cloginwindow.ui create mode 100644 cmainwindow.cpp create mode 100644 cmainwindow.h create mode 100644 cmainwindow.ui create mode 100644 cmodifypassworddialog.cpp create mode 100644 cmodifypassworddialog.h create mode 100644 cmodifypassworddialog.ui create mode 100644 cmodifysecretivequestionsdialog.cpp create mode 100644 cmodifysecretivequestionsdialog.h create mode 100644 cmodifysecretivequestionsdialog.ui create mode 100644 cproductinformationdialog.cpp create mode 100644 cproductinformationdialog.h create mode 100644 cproductinformationdialog.ui create mode 100644 cregisterdialog.cpp create mode 100644 cregisterdialog.h create mode 100644 cregisterdialog.ui create mode 100644 cretrievedialog.cpp create mode 100644 cretrievedialog.h create mode 100644 cretrievedialog.ui create mode 100644 cstring.cpp create mode 100644 cstring.h create mode 100644 intelligentwindow.ico create mode 100644 intelligentwindow.rc create mode 100644 intelligentwindowclient.pro create mode 100644 intelligentwindowclient.qrc create mode 100644 intelligentwindowclient_zh_CN.ts create mode 100644 main.cpp diff --git a/cencrypt.cpp b/cencrypt.cpp new file mode 100644 index 0000000..241dc24 --- /dev/null +++ b/cencrypt.cpp @@ -0,0 +1,34 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cencrypt.h" + +CEncrypt::CEncrypt() +{ + ; +} + +CEncrypt::~CEncrypt() +{ + ; +} + +QByteArray CEncrypt::XOR(QByteArray byteArray, CEncryptModel encryptMode) +{ + switch (encryptMode) { + case Model_XOR: + { + QByteArray KEY = "8A3500F5BBD2A41"; + int keyIndex; + for(int index = 0; index < byteArray.size(); ++index) + { + keyIndex = index % KEY.size(); + byteArray[index] = byteArray[index] ^ KEY[keyIndex]; + } + break; + } + } + return byteArray; +} diff --git a/cencrypt.h b/cencrypt.h new file mode 100644 index 0000000..97e4ebd --- /dev/null +++ b/cencrypt.h @@ -0,0 +1,36 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CENCRYPT_H +#define CENCRYPT_H + +#include +#include +#include + +class CEncrypt +{ +public: + enum CEncryptError + { + Error_None, //无错误 + }; + enum CEncryptModel + { + Model_XOR, //异或加密解密 + }; + + CEncrypt(); + ~CEncrypt(); + + QByteArray XOR(QByteArray, CEncryptModel); + +protected: + +private: + +}; + +#endif // CENCRYPT_H diff --git a/cgobangchessboard.cpp b/cgobangchessboard.cpp new file mode 100644 index 0000000..f2c4efa --- /dev/null +++ b/cgobangchessboard.cpp @@ -0,0 +1,1335 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cgobangchessboard.h" + +CGobangChessboard::CGobangChessboard(QWidget *parent) + : QLabel(parent) +{ + /** [InitializeVirtualChessboard] */ + m_virtualChessboard = (CGobangChessman**) new CGobangChessman*[15]; + for(int i = 0; i < 15; ++i) + { + m_virtualChessboard[i] = new CGobangChessman[15]; + } + for(int i = 0; i < 8; ++i) //初始化棋盘的分数 + { + for(int j = i; (-1 + i) < j && j < (15 - i); ++j) + { + for(int k = i; (-1 + i) < k && k < (15 - i); ++k) + { + m_virtualChessboard[j][k].addScore(1); + } + } + } + /* [InitializeVirtualChessboard] **/ + + + /** [PaintChessboard] */ + this->paintChessboard(); + /* [PaintChessboard] **/ + + + /** [PaintChesses] */ + setMouseTracking(true); + connect(this, &CGobangChessboard::targetChanged, this, &CGobangChessboard::paintPredictor); + /* [PaintChesses] **/ + + + /** [CheckWin] */ + connect(this, &CGobangChessboard::humanPlayed, this, &CGobangChessboard::checkWin); + connect(this, &CGobangChessboard::aiPlayed, this, &CGobangChessboard::checkWin); + /* [CheckWin] **/ + + + /** [Win] */ + connect(this, &CGobangChessboard::win, [&](){ m_playerChessmanType = CGobangChessman::CChessmanType::Type_None; }); + /* [Win] **/ + + + /** [UpdateScore] */ + connect(this, &CGobangChessboard::checked, this, &CGobangChessboard::updateScore); + /* [UpdateScore] **/ + + + /** [AI] */ + connect(this, &CGobangChessboard::aiReady, this, &CGobangChessboard::ai); + /* [AI] **/ +} + +void CGobangChessboard::restart() +{ + qDebug() << "=====重新开始====="; + + + /** [InitializeVirtualChessboard] */ + for(int i = 0; i < 15; ++i) //初始化棋盘 + { + for(int j = 0; j < 15; ++j) + { + m_virtualChessboard[i][j].restart(); + } + } + for(int i = 0; i < 8; ++i) //正态分布 + { + for(int j = i; (-1 + i) < j && j < (15 - i); ++j) + { + for(int k = i; (-1 + i) < k && k < (15 - i); ++k) + { + m_virtualChessboard[j][k].addScore(1); + } + } + } + /* [InitializeVirtualChessboard] **/ + + m_chessboardPositionIndexX = -1; + m_chessboardPositionIndexY = -1; + + m_vectorPlayImagesHistory.clear(); + m_vectorPlayPositionsIndexHistory.clear(); + + m_playerChessmanType = CGobangChessman::CChessmanType::Type_Black; + + this->paintChessboard(); +} + +void CGobangChessboard::ai() +{ + double highestScore = 0; + int highestScoreIndexX = -1; + int highestScoreIndexY = -1; + QVector highestChessmen; + + + /** [SeekHighestScore] */ + for(int i = 0; i < 15; ++i) + { + for(int j = 0; j < 15; ++j) + { + if(m_virtualChessboard[i][j].score() > highestScore) + { + highestScore = m_virtualChessboard[i][j].score(); + highestScoreIndexX = i; + highestScoreIndexY = j; + } + } + } + /* [SeekHighestScore] **/ + + + /** [SeekHighestChessmanVector] */ + for(int i = 0; i < 15; ++i) + { + for(int j = 0; j < 15; ++j) + { + if(m_virtualChessboard[i][j].score() == highestScore) + { + highestChessmen.append(&m_virtualChessboard[i][j]); + } + } + } + /* [SeekHighestChessmanVector] **/ + + + /** [RandomSelec] */ + qsrand(time(NULL)); //设置时间种子 + int index = qrand() % highestChessmen.size(); + for(int i = 0; i < 15; ++i) + { + for(int j = 0; j < 15; ++j) + { + if(&m_virtualChessboard[i][j] == highestChessmen[index]) + { + highestScoreIndexX = i; + highestScoreIndexY = j; + } + } + } + /* [RandomSelec] **/ + + + /** [Play] */ + qDebug() << "White:" << m_virtualChessboard[highestScoreIndexX][highestScoreIndexY].score(); + this->paintChessman(highestScoreIndexX, highestScoreIndexY, CGobangChessman::CChessmanType::Type_White); + m_virtualChessboard[highestScoreIndexX][highestScoreIndexY].setChessman(CGobangChessman::CChessmanType::Type_White); + m_playerChessmanType = CGobangChessman::CChessmanType::Type_Black; + emit aiPlayed(highestScoreIndexX, highestScoreIndexY, CGobangChessman::CChessmanType::Type_White); + /* [Play] **/ +} + +void CGobangChessboard::updateScore(int indexX, int indexY, CGobangChessman::CChessmanType chessmanType) +{ + /** [basicScore] */ + for(int i = -1; -1 < indexX + i && indexX + i < 15 && i < 2; ++i) + { + for(int j = -1; -1 < indexY + j && indexY + j < 15 && j < 2; ++j) + { + m_virtualChessboard[indexX + i][indexY + j].addScore(1); + } + } + /* [basicScore] **/ + + + /** [reduceScore] */ + for(int i = 1; i < 5; ++i) + { + switch(i) + { + case 1: + { + //"\" + QVector powerTargets; + double powerValue = POWERVALUE0_9; + for(int j = 1; indexX - j > -1 && indexY - j > -1; ++j) //在棋盘范围内搜索 + { + if(m_virtualChessboard[indexX - j][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX - j == 0 || indexX - j == 14 || indexY - j == 0 || indexY - j == 14) //判断是否抵达边界 + { + break; + } + else if(m_virtualChessboard[indexX - j - 1][indexY - j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY - j + 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY - j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY - j]); + } + } + else if(m_virtualChessboard[indexX - j][indexY - j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + powerTargets.clear(); + powerValue = POWERVALUE0_9; + for(int j = 1; indexX + j < 15 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX + j == 0 || indexX + j == 14 || indexY + j == 0 || indexY + j == 14) + { + break; + } + else if(m_virtualChessboard[indexX + j + 1][indexY + j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY + j - 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY + j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY + j]); + } + } + else if(m_virtualChessboard[indexX + j][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 2: + { + //"/" + QVector powerTargets; + double powerValue = POWERVALUE0_9; + for(int j = 1; indexX + j < 15 && indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX + j][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX + j == 0 || indexX + j == 14 || indexY - j == 0 || indexY - j == 14) + { + break; + } + else if(m_virtualChessboard[indexX + j + 1][indexY - j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY - j + 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY - j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY - j]); + } + } + else if(m_virtualChessboard[indexX + j][indexY - j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + powerTargets.clear(); + powerValue = POWERVALUE0_9; + for(int j = 1; indexX - j > -1 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX - j][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX - j == 0 || indexX - j == 14 || indexY + j == 0 || indexY + j == 14) + { + break; + } + else if(m_virtualChessboard[indexX - j - 1][indexY + j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY + j - 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY + j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY + j]); + } + } + else if(m_virtualChessboard[indexX - j][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 3: + { + //"-" + QVector powerTargets; + double powerValue = POWERVALUE0_9; + for(int j = 1; indexX - j > -1; ++j) + { + if(m_virtualChessboard[indexX - j][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX - j == 0 || indexX - j == 14 || indexY == 0 || indexY == 14) + { + break; + } + else if(m_virtualChessboard[indexX - j - 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY]); + } + } + else if(m_virtualChessboard[indexX - j][indexY].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + powerTargets.clear(); + powerValue = POWERVALUE0_9; + for(int j = 1; indexX + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX + j == 0 || indexX + j == 14 || indexY == 0 || indexY == 14) + { + break; + } + else if(m_virtualChessboard[indexX + j + 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY]); + } + } + else if(m_virtualChessboard[indexX + j][indexY].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 4: + { + //"|" + QVector powerTargets; + double powerValue = POWERVALUE0_9; + for(int j = 1; indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX == 0 || indexX == 14 || indexY - j == 0 || indexY - j == 14) + { + break; + } + else if(m_virtualChessboard[indexX][indexY - j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY - j + 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY - j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY - j]); + } + } + else if(m_virtualChessboard[indexX][indexY - j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + powerTargets.clear(); + powerValue = POWERVALUE0_9; + for(int j = 1; indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(indexX == 0 || indexX == 14 || indexY + j == 0 || indexY + j == 14) + { + break; + } + else if(m_virtualChessboard[indexX][indexY + j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY + j - 2].type() == chessmanType) + { + powerTargets.pop_back(); + } + break; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY + j]); + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY + j]); + } + } + else if(m_virtualChessboard[indexX][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE0_8; + break; + } + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + } + } + /* [reduceScore] **/ + + + /** [addScore] */ + for(int i = 1; i < 5; ++i) + { + switch(i) + { + case 1: + { + //"\" + QVector powerTargets; + double powerValue = POWERVALUE1_0; + for(int j = 1; indexX - j > -1 && indexY - j > -1; ++j) //在棋盘范围内搜索 + { + if(m_virtualChessboard[indexX - j][indexY - j].type() == chessmanType) //如果检索的棋子与当前棋子类型一致 + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX - j][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY - j + 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX - j == 0 || indexX - j == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX - j == 0 || indexX - j == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY - j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY - j]); + } + } + else + { + break; + } + } + for(int j = 1; indexX + j < 15 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX + j][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY + j - 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX + j == 0 || indexX + j == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX + j == 0 || indexX + j == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY + j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY + j]); + } + } + else + { + break; + } + } + powerValue -= powerTargets.size() * POWERVALUE0_1; + if(powerValue < 1.0) + { + powerValue = 1.0; + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 2: + { + //"/" + QVector powerTargets; + double powerValue = POWERVALUE1_0; + for(int j = 1; indexX + j < 15 && indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX + j][indexY - j].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX + j][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY - j + 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX + j == 0 || indexX + j == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX + j == 0 || indexX + j == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY - j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY - j]); + } + } + else + { + break; + } + } + for(int j = 1; indexX - j > -1 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX - j][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX - j][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY + j - 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX - j == 0 || indexX - j == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX - j == 0 || indexX - j == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY + j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY + j]); + } + } + else + { + break; + } + } + powerValue -= powerTargets.size() * POWERVALUE0_1; + if(powerValue < 1.0) + { + powerValue = 1.0; + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 3: + { + //"-" + QVector powerTargets; + double powerValue = POWERVALUE1_0; + for(int j = 1; indexX - j > -1; ++j) + { + if(m_virtualChessboard[indexX - j][indexY].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX - j][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX - j + 2][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX - j == 0 || indexX - j == 14 || indexY == 0 || indexY == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX - j == 0 || indexX - j == 14 || indexY == 0 || indexY == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX - j][indexY]); + } + } + else + { + break; + } + } + for(int j = 1; indexX + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX + j][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 1][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX + j - 2][indexY].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX + j == 0 || indexX + j == 14 || indexY == 0 || indexY == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX + j == 0 || indexX + j == 14 || indexY == 0 || indexY == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX + j][indexY]); + } + } + else + { + break; + } + } + powerValue -= powerTargets.size() * POWERVALUE0_1; + if(powerValue < 1.0) + { + powerValue = 1.0; + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + case 4: + { + //"|" + QVector powerTargets; + double powerValue = POWERVALUE1_0; + for(int j = 1; indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX][indexY - j].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX][indexY - j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY - j + 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY - j + 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX == 0 || indexX == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + break; + } + else + { + if(indexX == 0 || indexX == 14 || indexY - j == 0 || indexY - j == 14) + { + powerValue *= POWERVALUE0_8; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY - j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY - j]); + } + } + else + { + break; + } + } + for(int j = 1; indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX][indexY + j].type() == chessmanType) + { + powerValue *= POWERVALUE1_4; + } + else if(m_virtualChessboard[indexX][indexY + j].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY + j - 1].type() == CGobangChessman::CChessmanType::Type_None) + { + if(m_virtualChessboard[indexX][indexY + j - 2].type() == CGobangChessman::CChessmanType::Type_None) + { + powerTargets.pop_back(); + if(indexX == 0 || indexX == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_9; + } + break; + } + else + { + if(indexX == 0 || indexX == 14 || indexY + j == 0 || indexY + j == 14) + { + powerValue *= POWERVALUE0_9; + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY + j]); + } + } + } + else + { + powerTargets.append(&m_virtualChessboard[indexX][indexY + j]); + } + } + else + { + break; + } + } + powerValue -= powerTargets.size() * POWERVALUE0_1; + if(powerValue < 1.0) + { + powerValue = 1.0; + } + for(int j = 0; j < powerTargets.size(); ++j) + { + powerTargets[j]->powerScore(powerValue); + } + break; + } + } + } + /* [addScore] **/ + + + /** [aiReady] */ + if(chessmanType == CGobangChessman::CChessmanType::Type_Black) + { + emit aiReady(); + } + /* [aiReady] **/ +} + +void CGobangChessboard::checkWin(const int indexX, const int indexY, const CGobangChessman::CChessmanType type) +{ + const CGobangChessman::CChessmanType temporaryType = m_playerChessmanType; + m_playerChessmanType = CGobangChessman::CChessmanType::Type_None; + int chessmenNumber; + for(int i = 1; i < 5; ++i) + { + switch(i) + { + case 1: + { + //"\" + chessmenNumber = 1; + for(int j = 1; indexX - j > -1 && indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX - j][indexY - j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + for(int j = 1; indexX + j < 15 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY + j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + break; + } + case 2: + { + //"/" + chessmenNumber = 1; + for(int j = 1; indexX + j < 15 && indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX + j][indexY - j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + for(int j = 1; indexX - j > -1 && indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX - j][indexY + j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + break; + } + case 3: + { + //"-" + chessmenNumber = 1; + for(int j = 1; indexX - j > -1; ++j) + { + if(m_virtualChessboard[indexX - j][indexY].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + for(int j = 1; indexX + j < 15; ++j) + { + if(m_virtualChessboard[indexX + j][indexY].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + break; + } + case 4: + { + //"|" + chessmenNumber = 1; + for(int j = 1; indexY - j > -1; ++j) + { + if(m_virtualChessboard[indexX][indexY - j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + for(int j = 1; indexY + j < 15; ++j) + { + if(m_virtualChessboard[indexX][indexY + j].type() == type) + { + ++chessmenNumber; + } + else + { + break; + } + } + break; + } + } + if(chessmenNumber >= 5) + { + emit win(); + switch(type) + { + default: + { + break; + } + case CGobangChessman::CChessmanType::Type_Black: + { + emit blackWin(); + break; + } + case CGobangChessman::CChessmanType::Type_White: + { + emit whiteWin(); + break; + } + } + return; + } + } + m_playerChessmanType = temporaryType; + emit checked(indexX, indexY, type); +} + +void CGobangChessboard::mouseMoveEvent(QMouseEvent *mouseMoveEvent) +{ + double ratioX = double(mouseMoveEvent->x()) / (m_linesPixelSpace + m_penPixelLength); + double ratioY = double(mouseMoveEvent->y()) / (m_linesPixelSpace + m_penPixelLength); + int interRatioX = ratioX; + int interRatioY = ratioY; + double remainderX = ratioX - interRatioX; + double remainderY = ratioY - interRatioY; + int newChessboardPositionIndexX; + int newChessboardPositionIndexY; + + + /** [UpdateNewChessboardPositionIndexX] */ + if(remainderX < 0.5) + { + if(interRatioX == 0) + { + newChessboardPositionIndexX = 0; + } + else + { + newChessboardPositionIndexX = interRatioX - 1; + } + } + else + { + if(interRatioX == 15) + { + newChessboardPositionIndexX = interRatioX - 1; + } + else + { + newChessboardPositionIndexX = interRatioX; + } + } + /* [UpdateNewChessboardPositionIndexX] **/ + + + /** [UpdateNewChessboardPositionIndexY] */ + if(remainderY < 0.5) + { + if(interRatioY == 0) + { + newChessboardPositionIndexY = 0; + } + else + { + newChessboardPositionIndexY = interRatioY - 1; + } + } + else + { + if(interRatioY == 15) + { + newChessboardPositionIndexY = interRatioY - 1; + } + else + { + newChessboardPositionIndexY = interRatioY; + } + } + /* [UpdateNewChessboardPositionIndexY] **/ + + + /** [UpdateChessboardPositionIndex] */ + if(m_chessboardPositionIndexX != newChessboardPositionIndexX || m_chessboardPositionIndexY != newChessboardPositionIndexY) + { + m_chessboardPositionIndexX = newChessboardPositionIndexX; + m_chessboardPositionIndexY = newChessboardPositionIndexY; + emit targetChanged(); + } + /* [UpdateChessboardPositionIndex] **/ +} + +void CGobangChessboard::mouseReleaseEvent(QMouseEvent *mouseReleaseEvent) +{ + int newChessboardPositionIndexX = m_chessboardPositionIndexX; + int newChessboardPositionIndexY = m_chessboardPositionIndexY; + + if(m_playerChessmanType != CGobangChessman::CChessmanType::Type_Black) + { + return; + } + if(m_virtualChessboard[newChessboardPositionIndexX][newChessboardPositionIndexY].isEmpty()) + { + qDebug() << "Black:" << m_virtualChessboard[newChessboardPositionIndexX][newChessboardPositionIndexY].score(); + this->paintChessman(newChessboardPositionIndexX, newChessboardPositionIndexY, CGobangChessman::CChessmanType::Type_Black); + m_virtualChessboard[newChessboardPositionIndexX][newChessboardPositionIndexY].setChessman(CGobangChessman::CChessmanType::Type_Black); + m_playerChessmanType = CGobangChessman::CChessmanType::Type_White; + emit humanPlayed(newChessboardPositionIndexX, newChessboardPositionIndexY, CGobangChessman::CChessmanType::Type_Black); + } +} + +void CGobangChessboard::paintChessboard() +{ + /** [SetPainter] */ + QImage *temporaryImage = new QImage(m_chessboardImagePixelLength, m_chessboardImagePixelLength, QImage::Format_ARGB32); + QPainter painter; + painter.begin(temporaryImage); + painter.setPen(QPen(COLOR_BLACK)); + painter.setBrush(QBrush(COLOR_BLACK)); + painter.setRenderHint(QPainter::Antialiasing); //抗锯齿 + /* [SetPainter] **/ + + + /** [PaintLines] */ + for(int i = 0; i < 15; ++i) + { + painter.drawLine( + m_linesPixelSpace + (m_linesPixelSpace + m_penPixelLength) * i, + m_linesPixelSpace, + m_linesPixelSpace + (m_linesPixelSpace + m_penPixelLength) * i, + m_chessboardImagePixelLength - m_linesPixelSpace - 1 + ); + painter.drawLine( + m_linesPixelSpace, + m_linesPixelSpace + (m_linesPixelSpace + m_penPixelLength) * i, + m_chessboardImagePixelLength - m_linesPixelSpace - 1, + m_linesPixelSpace + (m_linesPixelSpace + m_penPixelLength) * i + ); + } + /* [PaintLines] **/ + + + /** [PaintEllipses] */ + painter.drawEllipse( + QPoint( + (m_linesPixelSpace + m_penPixelLength) * 4 - 1, + (m_linesPixelSpace + m_penPixelLength) * 4 - 1 + ), + m_ellipsePixelRadius, + m_ellipsePixelRadius + ); //左上 + painter.drawEllipse( + QPoint( + m_chessboardImagePixelLength - (m_linesPixelSpace + m_penPixelLength) * 4, + (m_linesPixelSpace + m_penPixelLength) * 4 - 1 + ), + m_ellipsePixelRadius, + m_ellipsePixelRadius); //右上 + painter.drawEllipse( + QPoint( + (m_linesPixelSpace + m_penPixelLength) * 8 - 1, + (m_linesPixelSpace + m_penPixelLength) * 8 - 1 + ), + m_ellipsePixelRadius, + m_ellipsePixelRadius); //中间 + painter.drawEllipse( + QPoint( + (m_linesPixelSpace + m_penPixelLength) * 4 - 1, + m_chessboardImagePixelLength - (m_linesPixelSpace + m_penPixelLength) * 4 + ), + m_ellipsePixelRadius, + m_ellipsePixelRadius); //左下 + painter.drawEllipse( + QPoint( + m_chessboardImagePixelLength - (m_linesPixelSpace + m_penPixelLength) * 4, + m_chessboardImagePixelLength - (m_linesPixelSpace + m_penPixelLength) * 4 + ), + m_ellipsePixelRadius, + m_ellipsePixelRadius); //右下 + /* [PaintEllipses] **/ + + + /** [LoadAndSavePaintedImage] */ + painter.end(); + this->setPixmap(QPixmap::fromImage(*temporaryImage)); + m_vectorPlayImagesHistory.append(temporaryImage); + /* [LoadPaintedImage] **/ +} + +void CGobangChessboard::paintPredictor() +{ + QImage *temporaryImage = new QImage(*m_vectorPlayImagesHistory.last()); + QPainter painter; + + /** [SetPainter] */ + painter.begin(temporaryImage); + painter.setPen(QPen(COLOR_BLACK)); + painter.setRenderHint(QPainter::Antialiasing); //抗锯齿 + /* [SetPainter] **/ + + + /** [PaintPredictor] */ + painter.drawEllipse( + QPoint( + (m_chessboardPositionIndexX + 1) * (m_linesPixelSpace + m_penPixelLength) - 1, + (m_chessboardPositionIndexY + 1) * (m_linesPixelSpace + m_penPixelLength) - 1 + ), + CHESSMAN_PIXEL_RADIUS, + CHESSMAN_PIXEL_RADIUS + ); + /* [PaintPredictor] **/ + + + /** [LoadPaintedImage] */ + painter.end(); + this->setPixmap(QPixmap::fromImage(*temporaryImage)); + delete temporaryImage; + /* [LoadPaintedImage] **/ +} + +bool CGobangChessboard::paintChessman(int indexX, int indexY, CGobangChessman::CChessmanType chessmanType) +{ + /** [SetPainter] */ + QImage *temporaryImage = new QImage(*m_vectorPlayImagesHistory.last()); + QPainter painter; + painter.begin(temporaryImage); + switch(chessmanType) + { + default: + { + return false; + } + case CGobangChessman::CChessmanType::Type_Black: + { + painter.setPen(QPen(COLOR_EDGE)); + painter.setBrush(QBrush(COLOR_BLACK)); + break; + } + case CGobangChessman::CChessmanType::Type_White: + { + painter.setPen(QPen(COLOR_EDGE)); + painter.setBrush(QBrush(COLOR_WHITE)); + break; + } + } + painter.setRenderHint(QPainter::Antialiasing); //抗锯齿 + /* [SetPainter] **/ + + + /** [PaintChessman] */ + painter.drawEllipse( + QPoint( + (indexX + 1) * (m_linesPixelSpace + m_penPixelLength) - 1, + (indexY + 1) * (m_linesPixelSpace + m_penPixelLength) - 1 + ), + CHESSMAN_PIXEL_RADIUS, + CHESSMAN_PIXEL_RADIUS + ); + /* [PaintChessman] **/ + + + /** [LoadPaintedImage] */ + painter.end(); + this->setPixmap(QPixmap::fromImage(*temporaryImage)); + m_vectorPlayImagesHistory.append(temporaryImage); + /* [LoadPaintedImage] **/ + + + return true; +} diff --git a/cgobangchessboard.h b/cgobangchessboard.h new file mode 100644 index 0000000..1c1af72 --- /dev/null +++ b/cgobangchessboard.h @@ -0,0 +1,83 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CGOBANGCHESSBOARD_H +#define CGOBANGCHESSBOARD_H + +#include "cgobangchessman.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CHESSMAN_PIXEL_RADIUS 13 +#define COLOR_BLACK QColor(0, 0, 0) +#define COLOR_EDGE QColor(130, 130, 130) +#define COLOR_WHITE QColor(255, 255, 255) + +#define POWERVALUE0_1 0.1 +#define POWERVALUE0_8 0.8 +#define POWERVALUE0_9 0.9 +#define POWERVALUE1_0 1.0 +#define POWERVALUE1_2 1.2 +#define POWERVALUE1_4 1.4 + +class CGobangChessboard : public QLabel +{ + Q_OBJECT + +signals: + void aiReady(); + void aiPlayed(int indexX, int indexY, CGobangChessman::CChessmanType type); + void blackWin(); + void checked(int indexX, int indexY, CGobangChessman::CChessmanType type); + void humanPlayed(int indexX, int indexY, CGobangChessman::CChessmanType type); + void targetChanged(); + void whiteWin(); + void win(); + +public: + explicit CGobangChessboard(QWidget *parent = nullptr); + + void restart(); + +protected: + +private: + const int m_chessboardImagePixelLength = 511; + const int m_ellipsePixelRadius = 2; + const int m_linesPixelSpace = 31; + const int m_penPixelLength = 1; + + int m_chessboardPositionIndexX = -1; + int m_chessboardPositionIndexY = -1; + + QVector m_vectorPlayPositionsIndexHistory; + QVector m_vectorPlayImagesHistory; + + CGobangChessman **m_virtualChessboard = nullptr; + CGobangChessman::CChessmanType m_playerChessmanType = CGobangChessman::CChessmanType::Type_Black; + +private slots: + void ai(); + void updateScore(int indexX, int indexY, CGobangChessman::CChessmanType type); + void checkWin(const int indexX, const int indexY, const CGobangChessman::CChessmanType type); + void mouseMoveEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void paintChessboard(); + void paintPredictor(); + + bool paintChessman(int indexX, int indexY, CGobangChessman::CChessmanType chessmanType); + +}; + +#endif // CGOBANGCHESSBOARD_H diff --git a/cgobangchessman.cpp b/cgobangchessman.cpp new file mode 100644 index 0000000..812b980 --- /dev/null +++ b/cgobangchessman.cpp @@ -0,0 +1,70 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cgobangchessman.h" + +CGobangChessman::CGobangChessman() +{ + m_isEmpty = true; + m_score = INITIALSCORE; + m_type = Type_None; +} + +CGobangChessman::~CGobangChessman() +{ + ; +} + +void CGobangChessman::addScore(int score) +{ + this->m_score += score; +} + +bool CGobangChessman::isEmpty() +{ + return this->m_isEmpty; +} + +bool CGobangChessman::powerScore(double power) +{ + if(this->m_isEmpty == true && power > 0) + { + this->m_score *= power; + return true; + } + return false; +} + +void CGobangChessman::restart() +{ + this->m_isEmpty = true; + this->m_score = INITIALSCORE; + this->m_type = Type_None; +} + +double CGobangChessman::score() +{ + if(m_type == Type_None) + { + return this->m_score; + } + return 0; +} + +bool CGobangChessman::setChessman(CChessmanType type) +{ + if(this->m_isEmpty) + { + this->m_type = type; + this->m_isEmpty = false; + return true; + } + return false; +} + +CGobangChessman::CChessmanType CGobangChessman::type() +{ + return this->m_type; +} diff --git a/cgobangchessman.h b/cgobangchessman.h new file mode 100644 index 0000000..b4c2703 --- /dev/null +++ b/cgobangchessman.h @@ -0,0 +1,51 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CGOBANGCHESSMAN_H +#define CGOBANGCHESSMAN_H + +#include + +#define INITIALSCORE 1000 + +class CGobangChessman : public QObject +{ + Q_OBJECT + +signals: + +public: + enum CChessmanType + { + Type_Black, + Type_None, + Type_White, + }; + + explicit CGobangChessman(); + ~CGobangChessman(); + + void addScore(int score); + bool isEmpty(); + bool powerScore(double power); + void restart(); + double score(); + bool setChessman(CChessmanType type); + + CChessmanType type(); + +protected: + +private: + bool m_isEmpty; //是否落子 + double m_score; //棋子初始化分数 + + CChessmanType m_type; //棋子类型 + +private slots: + +}; + +#endif // CGOBANGCHESSMAN_H diff --git a/cloginwindow.cpp b/cloginwindow.cpp new file mode 100644 index 0000000..246abdb --- /dev/null +++ b/cloginwindow.cpp @@ -0,0 +1,219 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cloginwindow.h" +#include "ui_cloginwindow.h" + +CLoginWindow::CLoginWindow(QWidget *parent) + : QWidget(parent) + , ui(new Ui::CLoginWindow) +{ + ui->setupUi(this); + + + /** [NetworkSystem] */ +// m_tcpSocket = new QTcpSocket(this); +// m_tcpSocket->connectToHost(QHostAddress(IP_SERVER), 8888); + /* [NetworkSystem] **/ + + + /** [FilesSystem] */ + m_userEncDir.setPath(m_path_system_users_enc); + if(!m_userEncDir.exists()) + { + m_userEncDir.mkpath(m_path_system_users_enc); + } + /* [FilesSystem] **/ + + + /** [MessagesLabel] */ + /* [MessagesLabel] **/ + + + /** [LineEdits] */ + ui->lineEditAccount->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9]{0,30}"), this)); //用正则表达式来限制输入 + ui->lineEditPassword->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9-@#&/*+]{0,30}"), this)); //用正则表达式来限制输入 + /* [LineEdits] **/ + + + /** [ConnectionState] */ +// connect(m_tcpSocket, &QTcpSocket::connected, [&]() +// { +// ui->pushButtonConnectServer->setIcon(QIcon(":/pictures/ico/wifi.ico")); +// }); +// connect(m_tcpSocket, &QTcpSocket::disconnected, [&]() +// { +// ui->pushButtonConnectServer->setIcon(QIcon(":/pictures/ico/stop.ico")); +// }); +// connect(ui->pushButtonConnectServer, &QPushButton::clicked, [&]() +// { +// this->clicked_PushButtonConnectServer(m_tcpSocket->state()); +// }); + /* [ConnectionState] **/ + + + /** [LoginButton] */ + connect(ui->toolButtonLogin, &QToolButton::clicked, [&]() + { +// this->clicked_ToolButtonLogin(m_tcpSocket->state()); + this->clickedToolButtonLogin(QTcpSocket::SocketState::UnconnectedState); + }); + /* [LoginButton] **/ + + + /** [RegisterAccount] */ + connect(ui->pushButtonRegisterAccount, &QPushButton::clicked, this, &CLoginWindow::clickedPushButtonRegisterAccount); + /* [RegisterAccount] **/ + + + /** [RetrievePassword] */ + connect(ui->pushButtonRetrievePassword, &QPushButton::clicked, this, &CLoginWindow::clickedPushButtonRetrievePassword); + /* [RetrievePassword] **/ +} + +CLoginWindow::~CLoginWindow() +{ + delete ui; +} + +void CLoginWindow::clickedPushButtonConnectServer(QTcpSocket::SocketState state) +{ + switch(state) + { + default: + { + break; + } + case QTcpSocket::SocketState::ConnectedState: + { + m_tcpSocket->disconnectFromHost(); + m_tcpSocket->close(); + break; + } + case QTcpSocket::SocketState::UnconnectedState: + { + m_tcpSocket->connectToHost(QHostAddress(IP_SERVER), 8888); + break; + } + } +} + +void CLoginWindow::clickedPushButtonRegisterAccount() +{ + CRegisterDialog registerDialog; + connect(®isterDialog, &CRegisterDialog::registered, [&](QString registerAccount, QString registerPassword) + { + ui->lineEditAccount->setText(registerAccount); + ui->lineEditPassword->setText(registerPassword); + }); + registerDialog.exec(); +} + +void CLoginWindow::clickedPushButtonRetrievePassword() +{ + CRetrieveDialog retrieveDialog; + retrieveDialog.exec(); +} + +void CLoginWindow::clickedToolButtonLogin(QTcpSocket::SocketState state) +{ + QString editAccount = ui->lineEditAccount->text(); + QString editPassword = ui->lineEditPassword->text(); + if(editAccount == "") + { + QMessageBox::warning(this, "提示", "账号不能为空!"); + return; + } + else if(editPassword == "") + { + QMessageBox::warning(this, "提示", "密码不能为空!"); + return; + } + switch(state) + { + default: + { + break; + } + case QTcpSocket::SocketState::ConnectedState: + { + +//加密 + m_tcpSocket->write(m_encrypt.XOR(QString("!BEGIN!").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("@LOGINACCOUNT@").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("<{").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(editAccount.toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("}>").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("@LOGINPASSWORD@").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("<{").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(editPassword.toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("}>").toLatin1(), CEncrypt::Model_XOR)); + m_tcpSocket->write(m_encrypt.XOR(QString("!END!").toLatin1(), CEncrypt::Model_XOR)); + +//未加密 +// m_tcpSocket->write(QString("!BEGIN!").toLatin1()); +// m_tcpSocket->write(QString("@LOGINACCOUNT@").toLatin1()); +// m_tcpSocket->write(QString("<{").toLatin1()); +// m_tcpSocket->write(editAccount.toLatin1()); +// m_tcpSocket->write(QString("}>").toLatin1()); +// m_tcpSocket->write(QString("@LOGINPASSWORD@").toLatin1()); +// m_tcpSocket->write(QString("<{").toLatin1()); +// m_tcpSocket->write(editPassword.toLatin1()); +// m_tcpSocket->write(QString("}>").toLatin1()); +// m_tcpSocket->write(QString("!END!").toLatin1()); + + if(m_tcpSocket->waitForReadyRead(3000)) + { + QByteArray readData = m_tcpSocket->readAll(); + qDebug() << readData.data(); + } + else + { + qDebug() << "接受信息失败"; + } + break; + } + case QTcpSocket::SocketState::UnconnectedState: + { + QFileInfoList usersFileInfoList = m_userEncDir.entryInfoList(QDir::Files | QDir::CaseSensitive); //过滤条件为只限文件并区分大小写 + for (int i = 0; i < usersFileInfoList.size(); ++i) + { + QString suffix = usersFileInfoList[i].suffix(); //获取后缀名 + if (suffix == "enc") + { + m_usersList.append(usersFileInfoList[i].baseName()); //获取满足条件的文件名称(不包含后缀) + } + } + + for(int i = 0; i < m_usersList.size(); ++i) + { + if(m_usersList[i] == editAccount) + { + QString fileHead; + QByteArray account, password, question1, answer1, question2, answer2; + QFile file_user_enc(m_path_system_users_enc + m_usersList[i] + ".enc"); + QDataStream outputStream(&file_user_enc); + file_user_enc.open(QIODevice::ReadOnly); + outputStream >> fileHead >> account >> password >> question1 >> answer1 >> question2 >> answer2; + file_user_enc.close(); + if(editPassword == m_encrypt.XOR(password, CEncrypt::Model_XOR).data()) + { + ui->lineEditAccount->setText(""); + ui->lineEditPassword->setText(""); + emit login(editAccount); + return; + } + else + { + QMessageBox::warning(this, "提示", "密码错误!"); + return; + } + } + } + QMessageBox::warning(this, "提示", "账号错误!"); + break; + } + } +} diff --git a/cloginwindow.h b/cloginwindow.h new file mode 100644 index 0000000..4cda31c --- /dev/null +++ b/cloginwindow.h @@ -0,0 +1,70 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CLOGINWINDOW_H +#define CLOGINWINDOW_H + +#include "cstring.h" +#include "cencrypt.h" +#include "cregisterdialog.h" +#include "cretrievedialog.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IP_SERVER "192.168.11.100" +#define PORT_SERVER 8888 + +namespace Ui { +class CLoginWindow; +} + +class CLoginWindow : public QWidget +{ + Q_OBJECT + +signals: + void login(QString account); //登录成功 + +public: + explicit CLoginWindow(QWidget *parent = nullptr); + ~CLoginWindow(); + +protected: + +private: + Ui::CLoginWindow *ui; + + const QString m_fileHead = "#APQA"; + const QString m_applicationDirPath = QCoreApplication::applicationDirPath(); + const QString m_path_users_dir = m_applicationDirPath + "/users/"; + const QString m_path_system_users_enc = m_applicationDirPath + "/system/users/"; + + QDir m_userEncDir; + QStringList m_usersList; + QTcpSocket *m_tcpSocket = nullptr; + + CEncrypt m_encrypt; + +private slots: + void clickedPushButtonConnectServer(QTcpSocket::SocketState state); + void clickedPushButtonRegisterAccount(); + void clickedPushButtonRetrievePassword(); + void clickedToolButtonLogin(QTcpSocket::SocketState state); + +}; + +#endif // CLOGINWINDOW_H diff --git a/cloginwindow.ui b/cloginwindow.ui new file mode 100644 index 0000000..0588144 --- /dev/null +++ b/cloginwindow.ui @@ -0,0 +1,781 @@ + + + CLoginWindow + + + + 0 + 0 + 430 + 266 + + + + + 0 + 0 + + + + + 430 + 266 + + + + + 430 + 266 + + + + + 等线 + 10 + + + + IntelligentWindowClient + + + + :/image/ico/intelligentwindow.ico:/image/ico/intelligentwindow.ico + + + false + + + #CLoginWidnow +{ + background:rgb(220, 220, 220); +} + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.95, stop:0 rgba(0, 0, 0, 255), stop:0.220339 rgba(220, 220, 220, 220)); + + + + 5 + + + 10 + + + 5 + + + 5 + + + 0 + + + + + + 0 + 0 + + + + + 104 + 104 + + + + + 104 + 104 + + + + background:rgb(0, 0, 0); +border-radius:52px; + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 100 + 100 + + + + + 100 + 100 + + + + + 等线 + 10 + 75 + true + + + + background:rgb(255, 255, 255); +border-radius:50px; + + + QFrame::NoFrame + + + QFrame::Sunken + + + + + + false + + + Qt::AlignCenter + + + false + + + Qt::NoTextInteraction + + + + + + + + + + + + + +background:rgb(220, 220, 220); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 5 + + + 2 + + + 5 + + + 10 + + + 0 + + + + + + 0 + 0 + + + + + 250 + 35 + + + + + 250 + 35 + + + + + 等线 + 14 + 75 + true + + + + PointingHandCursor + + + 点击登录 + + + background:rgb(5, 187, 251); +border-radius:8px; +color:rgb(255, 255, 255); + + + 登录 + + + Enter + + + false + + + false + + + false + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 30 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入账号 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 30 + + + true + + + QLineEdit::Password + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 请输入密码 + + + Qt::LogicalMoveStyle + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 30 + + + + + 16777215 + 30 + + + + + 等线 + 10 + 75 + true + + + + +background:rgb(220, 220, 220); + + + + 0 + + + 12 + + + 0 + + + 12 + + + 10 + + + + + + 65 + 22 + + + + + 65 + 22 + + + + + 等线 + 11 + 75 + true + + + + PointingHandCursor + + + background:transparent; +color:rgb(90, 90, 90); + + + 注册账号 + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 25 + 25 + + + + + 25 + 25 + + + + PointingHandCursor + + + background:transparent; +color:rgb(100, 100, 100); + + + + + + + :/pictures/ico/stop.ico:/pictures/ico/stop.ico + + + + 20 + 20 + + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 65 + 22 + + + + + 65 + 22 + + + + + 等线 + 11 + 75 + true + + + + PointingHandCursor + + + background:transparent; +color:rgb(90, 90, 90); + + + 找回密码 + + + true + + + + + + + + + + + + + diff --git a/cmainwindow.cpp b/cmainwindow.cpp new file mode 100644 index 0000000..5302183 --- /dev/null +++ b/cmainwindow.cpp @@ -0,0 +1,157 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cmainwindow.h" +#include "ui_cmainwindow.h" + +CMainWindow::CMainWindow(const QString account, QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::CMainWindow) + , m_account(new const QString(account)) +{ + ui->setupUi(this); //默认代码 + + + /** [NetworkSystem] */ + /* [NetworkSystem] **/ + + + /** [FilesSystem] */ + /* [FilesSystem] **/ + + + /** [Menu\Set] */ + connect(ui->actionModifyPassword, &QAction::triggered, [&]() + { + m_modifyPasswordDialog = new CModifyPasswordDialog(*m_account ,this); + m_modifyPasswordDialog->exec(); + connect(m_modifyPasswordDialog, &CModifyPasswordDialog::modified, [&]() + { + delete m_modifyPasswordDialog; + }); + }); + connect(ui->actionModifySecretiveQuestions, &QAction::triggered, [&]() + { + m_modifySecretiveQuestionsDialog = new CModifySecretiveQuestionsDialog(*m_account ,this); + m_modifySecretiveQuestionsDialog->exec(); + connect(m_modifySecretiveQuestionsDialog, &CModifySecretiveQuestionsDialog::modified, [&]() + { + delete m_modifySecretiveQuestionsDialog; + }); + }); + connect(ui->actionStyle, &QAction::triggered, [&]() + { + qDebug() << "修改样式!"; + }); + connect(ui->actionComponents, &QAction::triggered, [&]() + { + qDebug() << "设置插件!"; + }); + /* [Menu\Set] **/ + + + /** [Menu\Help] */ + connect(ui->actionOPI, &QAction::triggered, []() + { + CProductInformationDialog productInformationDialog; + productInformationDialog.exec(); + }); + connect(ui->actionUpdate, &QAction::triggered, [&]() + { + qDebug() << "获取更新!"; + }); + connect(ui->actionRepair, &QAction::triggered, [&]() + { + qDebug() << "修复错误!"; + }); + connect(ui->actionFeedback, &QAction::triggered, [&]() + { + qDebug() << "提交反馈!"; + }); + /* [Menu\Help] **/ + + + /** [SidedMenu] */ + ui->stackedWidgetMain->setCurrentIndex(0); + connect(ui->toolButtonHome, &QToolButton::clicked, [&]() + { + ui->stackedWidgetMain->setCurrentIndex(0); + }); + connect(ui->toolButtonStudy, &QToolButton::clicked, [&]() + { + ui->stackedWidgetMain->setCurrentIndex(1); + }); + connect(ui->toolButtonRecreation, &QToolButton::clicked, [&]() + { + ui->stackedWidgetMain->setCurrentIndex(2); + }); + connect(ui->toolButtonSociology, &QToolButton::clicked, [&]() + { + ui->stackedWidgetMain->setCurrentIndex(3); + }); + connect(ui->toolButtonTools, &QToolButton::clicked, [&]() + { + ui->stackedWidgetMain->setCurrentIndex(4); + }); + connect(ui->toolButtonLogout, &QToolButton::clicked, [&]() + { + emit logout(); + }); + /* [SidedMenu] **/ + + + /** [SidedMenu\Recreation\Gobang] */ + ui->tabWidgetRecreation->setCurrentIndex(0); + ui->stackedWidgetGobang->setCurrentIndex(0); + connect(ui->toolButtonGobangPVC, &QToolButton::clicked, [&]() + { + ui->stackedWidgetGobang->setCurrentIndex(0); + }); + connect(ui->toolButtonGobangPVP, &QToolButton::clicked, [&]() + { + ui->stackedWidgetGobang->setCurrentIndex(1); + }); + connect(ui->toolButtonGobangQualifying, &QToolButton::clicked, [&]() + { + ui->stackedWidgetGobang->setCurrentIndex(2); + }); + connect(ui->toolButtonGobangRecord, &QToolButton::clicked, [&]() + { + ui->stackedWidgetGobang->setCurrentIndex(3); + }); + connect(ui->toolButtonGobangSetting, &QToolButton::clicked, [&]() + { + ui->stackedWidgetGobang->setCurrentIndex(4); + }); + connect(ui->pushButtonRestart, &QPushButton::clicked, [&]() + { + ui->labelGobangPVCChessboard->restart(); + ui->labelGobangPVCMessageboard->setText(""); + + }); + connect(ui->labelGobangPVCChessboard, &CGobangChessboard::blackWin, [&]() + { + ui->labelGobangPVCMessageboard->setText("黑棋胜利!"); + }); + connect(ui->labelGobangPVCChessboard, &CGobangChessboard::whiteWin, [&]() + { + ui->labelGobangPVCMessageboard->setText("白棋胜利!"); + }); + /* [SidedMenu\Recreation\Gobang] **/ + + + /** [SidedMenu\Tools\EditPictures] */ + ui->tabWidgetTools->setCurrentIndex(0); + /* [SidedMenu\Tools\CalculateFormula] **/ + + + /** [StatusMenu] */ + /* [StatusMenu] **/ +} + +CMainWindow::~CMainWindow() +{ + delete ui; +} diff --git a/cmainwindow.h b/cmainwindow.h new file mode 100644 index 0000000..b43cb64 --- /dev/null +++ b/cmainwindow.h @@ -0,0 +1,47 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CMAINWINDOW_H +#define CMAINWINDOW_H + +#include "cmodifypassworddialog.h" +#include "cproductinformationdialog.h" +#include "cmodifysecretivequestionsdialog.h" + +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class CMainWindow; } +QT_END_NAMESPACE + +class CMainWindow : public QMainWindow +{ + Q_OBJECT + +signals: + void logout(); + +public: + explicit CMainWindow(const QString account, QWidget *parent = nullptr); + ~CMainWindow(); + +private: + Ui::CMainWindow *ui; + + const QString *m_account = nullptr; + + const QString path_users_dir = QCoreApplication::applicationDirPath() + "/users/"; + + bool isNetwork = false; + + CModifyPasswordDialog *m_modifyPasswordDialog = nullptr; + CModifySecretiveQuestionsDialog *m_modifySecretiveQuestionsDialog = nullptr; + +}; + +#endif // CMAINWINDOW_H diff --git a/cmainwindow.ui b/cmainwindow.ui new file mode 100644 index 0000000..e5524a8 --- /dev/null +++ b/cmainwindow.ui @@ -0,0 +1,1382 @@ + + + CMainWindow + + + + 0 + 0 + 1000 + 610 + + + + + 1000 + 610 + + + + + 微软雅黑 + 10 + 50 + false + + + + IntelligentWindowClient + + + + :/image/ico/intelligentwindow.ico:/image/ico/intelligentwindow.ico + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + false + + + QFrame::NoFrame + + + 2 + + + + + + + QFrame::Box + + + + + + :/image/jpg/4.jpg + + + true + + + + + + + + + + + QFrame::Box + + + + + + :/image/jpg/4.jpg + + + true + + + + + + + + false + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 等线 + 12 + 75 + true + + + + 0 + + + + 五子棋 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + 0 + 0 + + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 战绩 + + + + :/pictures/ico/history.ico:/pictures/ico/history.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + + + + 对弈 + + + + :/pictures/ico/users.ico:/pictures/ico/users.ico + + + + 28 + 28 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + + + + + + + 人机 + + + + :/pictures/ico/Calcbot.ico:/pictures/ico/Calcbot.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 设置 + + + + :/pictures/ico/settings.ico:/pictures/ico/settings.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 排位 + + + + :/pictures/ico/Trophy.ico:/pictures/ico/Trophy.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + QFrame::NoFrame + + + 0 + + + + + + + + 0 + 0 + + + + + 130 + 511 + + + + + 130 + 511 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 130 + 461 + + + + + 130 + 461 + + + + QFrame::Box + + + + + + + + + + + 0 + 0 + + + + + 130 + 40 + + + + + 130 + 40 + + + + + 等线 + 14 + 75 + true + + + + border-radius:10px; +background:qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:0, stop:0 rgb(255, 255, 0), stop:1 rgb(255, 85, 0)); + + + 重新开始 + + + + + + + + + + + 0 + 0 + + + + + 511 + 511 + + + + + 511 + 511 + + + + background:rgb(255, 162, 0); +border-radius:10px; + + + QFrame::NoFrame + + + + + + true + + + + + + + + + + 290 + 190 + 31 + 21 + + + + 对弈 + + + + + + + + 290 + 190 + 31 + 21 + + + + 排位 + + + + + + + + 290 + 190 + 31 + 21 + + + + 战绩 + + + + + + + + 290 + 190 + 31 + 21 + + + + 设置 + + + + + + + + + + + + + + + + QFrame::Box + + + + + + :/image/jpg/4.jpg + + + true + + + + + + + + + + + + + + + QFrame::Box + + + + + + :/image/jpg/4.jpg + + + true + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 等线 + 12 + 75 + true + + + + 0 + + + + 编辑图片 + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + 220 + 240 + 51 + 21 + + + + + + + + + + + + + + + + + true + + + + 0 + 0 + + + + true + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + + + + + + + 主页 + + + + :/pictures/ico/intelligentwindow.ico:/pictures/ico/intelligentwindow.ico + + + + 32 + 32 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + + + + 学习 + + + + :/pictures/ico/contacts.ico:/pictures/ico/contacts.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 娱乐 + + + + :/pictures/ico/xbox.ico:/pictures/ico/xbox.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 社交 + + + + :/pictures/ico/chat.ico:/pictures/ico/chat.ico + + + + 34 + 34 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 工具 + + + + :/pictures/ico/bag.ico:/pictures/ico/bag.ico + + + + 32 + 32 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 70 + 52 + + + + + 70 + 52 + + + + + 等线 + 12 + 75 + true + + + + 退出 + + + + :/pictures/ico/close.ico:/pictures/ico/close.ico + + + + 30 + 30 + + + + false + + + false + + + QToolButton::DelayedPopup + + + Qt::ToolButtonTextUnderIcon + + + true + + + + + + + + + + + + 0 + 0 + 1000 + 23 + + + + + 等线 + 12 + 75 + true + + + + + + 等线 + 12 + 75 + true + + + + + + + false + + + 设置 + + + false + + + false + + + + + 等线 + 12 + 75 + true + + + + + + + false + + + 个人中心 + + + + :/pictures/ico/netlog.ico:/pictures/ico/netlog.ico + + + + + + + + + + + + + + 等线 + 12 + 75 + true + + + + 帮助 + + + + + + + + + + + + + + + + + :/pictures/ico/hanger.ico:/pictures/ico/hanger.ico + + + 修改样式 + + + + + + :/pictures/ico/Market_Analysis.ico:/pictures/ico/Market_Analysis.ico + + + 提交反馈 + + + + + + :/pictures/ico/certificate.ico:/pictures/ico/certificate.ico + + + 产品信息 + + + + + + :/pictures/ico/cloud_download.ico:/pictures/ico/cloud_download.ico + + + 获取更新 + + + + + + :/pictures/ico/repair.ico:/pictures/ico/repair.ico + + + 修复错误 + + + + + + :/pictures/ico/64_plugin.ico:/pictures/ico/64_plugin.ico + + + 设置插件 + + + + + + :/pictures/ico/penciledit.ico:/pictures/ico/penciledit.ico + + + 修改密码 + + + + 等线 + 12 + 75 + true + + + + + + + :/pictures/ico/penciledit.ico:/pictures/ico/penciledit.ico + + + 修改秘问 + + + + 等线 + 12 + 75 + true + + + + + + + :/pictures/ico/FAQ.ico:/pictures/ico/FAQ.ico + + + 使用指南 + + + + + + CGobangChessboard + QLabel +
cgobangchessboard.h
+
+
+ + + + +
diff --git a/cmodifypassworddialog.cpp b/cmodifypassworddialog.cpp new file mode 100644 index 0000000..1042e66 --- /dev/null +++ b/cmodifypassworddialog.cpp @@ -0,0 +1,141 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cmodifypassworddialog.h" +#include "ui_cmodifypassworddialog.h" + +CModifyPasswordDialog::CModifyPasswordDialog(QString account, QWidget *parent) : + QDialog(parent), + ui(new Ui::CModifyPasswordDialog) +{ + ui->setupUi(this); //默认代码 + + /************************************************** + * 代码区块【文件系统】【开始】 + */ + + m_dirUsersEnc.setPath(m_path_users_enc); + if(!m_dirUsersEnc.exists()) + { + m_dirUsersEnc.mkpath(m_path_users_enc); + } + + QString fileCode; + QByteArray userAccount, userPassword, userQuestion1, userAnswer1, userQuestion2, userAnswer2; + QFile file_user_enc(m_path_users_enc + account + ".enc"); + QDataStream readStream(&file_user_enc); + file_user_enc.open(QIODevice::ReadOnly); + readStream >> fileCode >> userAccount >> userPassword >> userQuestion1 >> userAnswer1 >> userQuestion2 >> userAnswer2; + file_user_enc.close(); + + /** + * 代码区块【文件系统】【结束】 + **************************************************/ + + /************************************************** + * 代码区块【输入框】【开始】 + */ + + CEncrypt encrypt; + ui->lineEditSecretiveQuestion1->setText(encrypt.XOR(userQuestion1, CEncrypt::Model_XOR).data()); + ui->lineEditSecretiveQuestion2->setText(encrypt.XOR(userQuestion2, CEncrypt::Model_XOR).data()); + ui->lineEditNewPassword->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9-@#&/*+]{0,30}"), this)); //用正则表达式来限制输入 + + /** + * 代码区块【输入框】【结束】 + **************************************************/ + + /************************************************** + * 代码区块【修改】【开始】 + */ + + connect(ui->toolButtonModify, &QToolButton::clicked, [=](){ + if(isNetwork) + { + ; + } + else + { + QString secretiveAnswer1 = ui->lineEditSecretiveAnswer1->text(); + QString secretiveAnswer2 = ui->lineEditSecretiveAnswer2->text(); + QString newPassword = ui->lineEditNewPassword->text(); + + if(secretiveAnswer1 == "" || secretiveAnswer2 == "") + { + QMessageBox::warning(this, "提示", "答案不能为空!"); + return; + } + if(newPassword == "") + { + QMessageBox::warning(this, "提示", "密码不能为空!"); + return; + } + + QFileInfoList usersFilesInfoList = m_dirUsersEnc.entryInfoList(QDir::Files | QDir::CaseSensitive); //过滤条件为只限文件并区分大小写 + + for (int i = 0; i < usersFilesInfoList.size(); ++i) + { + QString fileSuffix = usersFilesInfoList[i].suffix(); //获取后缀名 + if (fileSuffix == "enc") + { + m_listUsers.append(usersFilesInfoList[i].baseName()); + } + } + for(int i = 0; i < m_listUsers.size(); ++i) + { + if(m_listUsers[i] == account) + { + CEncrypt myencrypt; + if(secretiveAnswer1 != myencrypt.XOR(userAnswer1, CEncrypt::Model_XOR).data()) + { + QMessageBox::warning(this, "提示", "第一个秘问答案输入错误!"); + return; + } + else if(secretiveAnswer2 != myencrypt.XOR(userAnswer2, CEncrypt::Model_XOR).data()) + { + QMessageBox::warning(this, "提示", "第二个秘问答案输入错误!"); + return; + } + else + { + QFile file_user_enc(m_path_users_enc + account + ".enc"); + file_user_enc.remove(); + file_user_enc.open(QIODevice::NewOnly); + file_user_enc.close(); + + QDataStream inputStream(&file_user_enc); + file_user_enc.open(QIODevice::WriteOnly); + inputStream << m_fileCode + << userAccount + << myencrypt.XOR(newPassword.toLatin1(), CEncrypt::Model_XOR) + << userQuestion1 + << userAnswer1 + << userQuestion2 + << userAnswer2; + file_user_enc.close(); + + QMessageBox::information(this, "提示", "修改成功!"); + emit modified(); + return; + } + } + else + { + QMessageBox::information(this, "提示", "修改失败!"); + return; + } + } + } + }); + + /** + * 代码区块【修改】【结束】 + **************************************************/ +} + +CModifyPasswordDialog::~CModifyPasswordDialog() +{ + delete ui; +} diff --git a/cmodifypassworddialog.h b/cmodifypassworddialog.h new file mode 100644 index 0000000..8efdc73 --- /dev/null +++ b/cmodifypassworddialog.h @@ -0,0 +1,52 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CMODIFYPASSWORDDIALOG_H +#define CMODIFYPASSWORDDIALOG_H + +#include "cstring.h" +#include "cencrypt.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class CModifyPasswordDialog; +} + +class CModifyPasswordDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CModifyPasswordDialog(const QString account, QWidget *parent = nullptr); + ~CModifyPasswordDialog(); + +protected: + +private: + Ui::CModifyPasswordDialog *ui; + + const QString m_fileCode = "#APQA"; + const QString m_path_users_enc = QCoreApplication::applicationDirPath() + "/system/users/"; + const QString m_path_users_dir = QCoreApplication::applicationDirPath() + "/users/"; + + bool isNetwork = false; + + QDir m_dirUsersEnc; + + QStringList m_listUsers; + +signals: + void modified(); + +}; + +#endif // CMODIFYPASSWORDDIALOG_H diff --git a/cmodifypassworddialog.ui b/cmodifypassworddialog.ui new file mode 100644 index 0000000..5ebf3aa --- /dev/null +++ b/cmodifypassworddialog.ui @@ -0,0 +1,870 @@ + + + CModifyPasswordDialog + + + + 0 + 0 + 280 + 232 + + + + + 0 + 0 + + + + + 280 + 232 + + + + + 280 + 232 + + + + 修改密码 + + + #CModifyPasswordDialog +{ + background:rgb(220, 220, 220); +} + + + false + + + + 0 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + true + + + + + + false + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 30 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入新密码 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 5 + + + 2 + + + 5 + + + 10 + + + 0 + + + + + + 0 + 0 + + + + + 250 + 35 + + + + + 250 + 35 + + + + + 等线 + 14 + 75 + true + + + + PointingHandCursor + + + 点击注册 + + + background:rgb(5, 187, 251); +border-radius:8px; +color:rgb(255, 255, 255); + + + 修改 + + + Enter + + + false + + + false + + + false + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + true + + + + + + false + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + diff --git a/cmodifysecretivequestionsdialog.cpp b/cmodifysecretivequestionsdialog.cpp new file mode 100644 index 0000000..0281179 --- /dev/null +++ b/cmodifysecretivequestionsdialog.cpp @@ -0,0 +1,122 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cmodifysecretivequestionsdialog.h" +#include "ui_cmodifysecretivequestionsdialog.h" + +CModifySecretiveQuestionsDialog::CModifySecretiveQuestionsDialog(const QString account, QWidget *parent) : + QDialog(parent), + ui(new Ui::CModifySecretiveQuestionsDialog) +{ + ui->setupUi(this); //默认代码 + + /** [FilesSystem] */ + m_dirUsersEnc.setPath(m_path_users_enc); + if(!m_dirUsersEnc.exists()) + { + m_dirUsersEnc.mkpath(m_path_users_enc); + } + QString fileCode; + QByteArray userAccount, userPassword, userQuestion1, userAnswer1, userQuestion2, userAnswer2; + QFile file_user_enc(m_path_users_enc + account + ".enc"); + QDataStream readStream(&file_user_enc); + file_user_enc.open(QIODevice::ReadOnly); + readStream >> fileCode >> userAccount >> userPassword >> userQuestion1 >> userAnswer1 >> userQuestion2 >> userAnswer2; + file_user_enc.close(); + /* [FilesSystem] **/ + + + /** [LineEdits] */ + ui->lineEditPassword->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9-@#&/*+]{0,30}"), this)); //用正则表达式来限制输入 + /* [LineEdits] **/ + + /** [Modify] */ + connect(ui->toolButtonModify, &QToolButton::clicked, [=](){ + if(isNetwork) + { + ; + } + else + { + QString linePassword = ui->lineEditPassword->text(); + QString secretiveQuestion1 = ui->lineEditSecretiveQuestion1->text(); + QString secretiveAnswer1 = ui->lineEditSecretiveAnswer1->text(); + QString secretiveQuestion2 = ui->lineEditSecretiveQuestion2->text(); + QString secretiveAnswer2 = ui->lineEditSecretiveAnswer2->text(); + + if(linePassword == "") + { + QMessageBox::warning(this, "提示", "密码不能为空!"); + return; + } + if(secretiveQuestion1 == "" || secretiveQuestion2 == "") + { + QMessageBox::warning(this, "提示", "问题不能为空!"); + return; + } + if(secretiveAnswer1 == "" || secretiveAnswer2 == "") + { + QMessageBox::warning(this, "提示", "答案不能为空!"); + return; + } + + QFileInfoList usersFilesInfoList = m_dirUsersEnc.entryInfoList(QDir::Files | QDir::CaseSensitive); //过滤条件为只限文件并区分大小写 + + for (int i = 0; i < usersFilesInfoList.size(); ++i) + { + QString fileSuffix = usersFilesInfoList[i].suffix(); //获取后缀名 + if (fileSuffix == "enc") + { + m_listUsers.append(usersFilesInfoList[i].baseName()); + } + } + for(int i = 0; i < m_listUsers.size(); ++i) + { + if(m_listUsers[i] == account) + { + CEncrypt myencrypt; + if(linePassword != myencrypt.XOR(userPassword, CEncrypt::Model_XOR).data()) + { + QMessageBox::warning(this, "提示", "密码输入错误!"); + return; + } + else + { + QFile file_user_enc(m_path_users_enc + account + ".enc"); + file_user_enc.remove(); + file_user_enc.open(QIODevice::NewOnly); + file_user_enc.close(); + + QDataStream inputStream(&file_user_enc); + file_user_enc.open(QIODevice::WriteOnly); + inputStream << m_fileCode + << userAccount + << userPassword + << myencrypt.XOR(secretiveQuestion1.toLatin1(), CEncrypt::Model_XOR) + << myencrypt.XOR(secretiveAnswer1.toLatin1(), CEncrypt::Model_XOR) + << myencrypt.XOR(secretiveQuestion2.toLatin1(), CEncrypt::Model_XOR) + << myencrypt.XOR(secretiveAnswer2.toLatin1(), CEncrypt::Model_XOR); + file_user_enc.close(); + + QMessageBox::information(this, "提示", "修改成功!"); + emit modified(); + return; + } + } + else + { + QMessageBox::information(this, "提示", "修改失败!"); + return; + } + } + } + }); + /* [Modify] **/ +} + +CModifySecretiveQuestionsDialog::~CModifySecretiveQuestionsDialog() +{ + delete ui; +} diff --git a/cmodifysecretivequestionsdialog.h b/cmodifysecretivequestionsdialog.h new file mode 100644 index 0000000..ff75bc6 --- /dev/null +++ b/cmodifysecretivequestionsdialog.h @@ -0,0 +1,50 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CMODIFYSECRETIVEQUESTIONSDIALOG_H +#define CMODIFYSECRETIVEQUESTIONSDIALOG_H + +#include "cstring.h" +#include "cencrypt.h" + +#include +#include +#include +#include +#include + +namespace Ui { +class CModifySecretiveQuestionsDialog; +} + +class CModifySecretiveQuestionsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CModifySecretiveQuestionsDialog(const QString account, QWidget *parent = nullptr); + ~CModifySecretiveQuestionsDialog(); + +protected: + +private: + Ui::CModifySecretiveQuestionsDialog *ui; + + const QString m_fileCode = "#APQA"; + const QString m_path_users_enc = QCoreApplication::applicationDirPath() + "/system/users/"; + const QString m_path_users_dir = QCoreApplication::applicationDirPath() + "/users/"; + + bool isNetwork = false; + + QDir m_dirUsersEnc; + + QStringList m_listUsers; + +signals: + void modified(); + +}; + +#endif // CMODIFYSECRETIVEQUESTIONSDIALOG_H diff --git a/cmodifysecretivequestionsdialog.ui b/cmodifysecretivequestionsdialog.ui new file mode 100644 index 0000000..5d0a66a --- /dev/null +++ b/cmodifysecretivequestionsdialog.ui @@ -0,0 +1,855 @@ + + + CModifySecretiveQuestionsDialog + + + + 0 + 0 + 280 + 232 + + + + + 280 + 232 + + + + + 280 + 232 + + + + 修改安全问题 + + + #CModifySecretiveQuestionsDialog +{ + background:rgb(220, 220, 220); +} + + + + 0 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 30 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入密码 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入第一个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入第二个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 5 + + + 2 + + + 5 + + + 10 + + + 0 + + + + + + 0 + 0 + + + + + 250 + 35 + + + + + 250 + 35 + + + + + 等线 + 14 + 75 + true + + + + PointingHandCursor + + + 点击注册 + + + background:rgb(5, 187, 251); +border-radius:8px; +color:rgb(255, 255, 255); + + + 修改 + + + Enter + + + false + + + false + + + false + + + + + + + + + + + diff --git a/cproductinformationdialog.cpp b/cproductinformationdialog.cpp new file mode 100644 index 0000000..7e58565 --- /dev/null +++ b/cproductinformationdialog.cpp @@ -0,0 +1,20 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cproductinformationdialog.h" +#include "ui_cproductinformationdialog.h" + +CProductInformationDialog::CProductInformationDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CProductInformationDialog) +{ + ui->setupUi(this); //默认代码 + setWindowFlags(Qt::WindowCloseButtonHint | Qt::MSWindowsFixedSizeDialogHint); //可以取消窗口右上角的"?"【其他窗口不一定适应】 +} + +CProductInformationDialog::~CProductInformationDialog() +{ + delete ui; +} diff --git a/cproductinformationdialog.h b/cproductinformationdialog.h new file mode 100644 index 0000000..56030a2 --- /dev/null +++ b/cproductinformationdialog.h @@ -0,0 +1,29 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CPRODUCTINFORMATIONDIALOG_H +#define CPRODUCTINFORMATIONDIALOG_H + +#include + +namespace Ui { +class CProductInformationDialog; +} + +class CProductInformationDialog : public QDialog +{ + Q_OBJECT + +public: + explicit CProductInformationDialog(QWidget *parent = nullptr); + ~CProductInformationDialog(); + +private: + Ui::CProductInformationDialog *ui; + + bool isNetwork = false; +}; + +#endif // CPRODUCTINFORMATIONDIALOG_H diff --git a/cproductinformationdialog.ui b/cproductinformationdialog.ui new file mode 100644 index 0000000..94feb5d --- /dev/null +++ b/cproductinformationdialog.ui @@ -0,0 +1,297 @@ + + + CProductInformationDialog + + + + 0 + 0 + 330 + 167 + + + + + 等线 + 12 + 75 + true + + + + 产品信息 + + + true + + + + + + + 0 + 0 + + + + + 200 + 25 + + + + + 200 + 25 + + + + IntelligentWindowClient + + + + + + + + 0 + 0 + + + + + 100 + 25 + + + + + 100 + 25 + + + + 特别说明: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 200 + 25 + + + + + 200 + 25 + + + + 内测版 1.0 + + + + + + + + 0 + 0 + + + + + 200 + 25 + + + + + 200 + 25 + + + + 所有权归制作人所有 + + + + + + + + 0 + 0 + + + + + 100 + 25 + + + + + 100 + 25 + + + + GitHub: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 100 + 25 + + + + + 100 + 25 + + + + 制作人: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 100 + 25 + + + + + 100 + 25 + + + + 当前版本: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 100 + 25 + + + + + 100 + 25 + + + + 名称: + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 200 + 25 + + + + + 200 + 25 + + + + ProYRB + + + + + + + + 0 + 0 + + + + + 200 + 25 + + + + + 200 + 25 + + + + @2453266068 + + + + + + + + diff --git a/cregisterdialog.cpp b/cregisterdialog.cpp new file mode 100644 index 0000000..8d87dab --- /dev/null +++ b/cregisterdialog.cpp @@ -0,0 +1,143 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cregisterdialog.h" +#include "ui_cregisterdialog.h" + +CRegisterDialog::CRegisterDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CRegisterDialog) +{ + ui->setupUi(this); //默认代码 + + + /** [FilesSystem] */ + m_dirUsersEnc.setPath(m_path_users_enc); + if(!m_dirUsersEnc.exists()) + { + m_dirUsersEnc.mkpath(m_path_users_enc); + } + /* [FilesSystem] **/ + + + /** [LineEdits] */ + ui->lineEditAccount->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9]{0,20}"), this)); //用正则表达式来限制输入 + ui->lineEditPassword->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9-@#&/*+]{0,20}"), this)); //用正则表达式来限制输入 + ui->lineEditPasswordAgain->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9-@#&/*+]{0,20}"), this)); //用正则表达式来限制输入 + /* [LineEdits] **/ + + + /** [Register] */ + connect(ui->toolButtonRegister, &QToolButton::clicked, [&](){ + if(isNetwork) + { + ; + } + else + { + QString registerAccount = ui->lineEditAccount->text(); + QString registerPassword = ui->lineEditPassword->text(); + QString registerPasswordAgain = ui->lineEditPasswordAgain->text(); + QString registerSecretiveQuestion1 = ui->lineEditSecretiveQuestion1->text(); + QString registerSecretiveAnswer1 = ui->lineEditSecretiveAnswer1->text(); + QString registerSecretiveQuestion2 = ui->lineEditSecretiveQuestion2->text(); + QString registerSecretiveAnswer2 = ui->lineEditSecretiveAnswer2->text(); + + if(registerAccount == "") + { + QMessageBox::warning(this, "提示", "账号不能为空!"); + return; + } + if(registerPassword == "" || registerPasswordAgain == "") + { + QMessageBox::warning(this, "提示", "密码不能为空!"); + return; + } + if(registerPassword != registerPasswordAgain) + { + QMessageBox::warning(this, "提示", "两次密码输入不一致!"); + return; + } + if(registerSecretiveQuestion1 == "" || registerSecretiveQuestion2 == "") + { + QMessageBox::warning(this, "提示", "安全问题不能为空!"); + return; + } + if(registerSecretiveAnswer1 == "" || registerSecretiveAnswer2 == "") + { + QMessageBox::warning(this, "提示", "问题答案不能为空!"); + return; + } + + QFileInfoList usersFilesInfoList = m_dirUsersEnc.entryInfoList(QDir::Files | QDir::CaseSensitive); //过滤条件为只限文件并区分大小写 + + for (int i = 0; i < usersFilesInfoList.size(); ++i) + { + QString fileSuffix = usersFilesInfoList[i].suffix(); //获取后缀名 + if (fileSuffix == "enc") + { + m_listUsers.append(usersFilesInfoList[i].baseName()); + } + } + for(int i = 0; i < m_listUsers.size(); ++i) + { + if(m_listUsers[i] == registerAccount) + { + QMessageBox::warning(this, "提示", "账号已存在!"); + return; + } + } + + QFile file_user_enc(m_path_users_enc + registerAccount + ".enc"); + file_user_enc.open(QIODevice::NewOnly); + file_user_enc.close(); + file_user_enc.open(QIODevice::WriteOnly); + + QDataStream inputStream(&file_user_enc); + CEncrypt encrypt; + inputStream << m_fileCode + << encrypt.XOR(registerAccount.toLatin1(), CEncrypt::Model_XOR) + << encrypt.XOR(registerPassword.toLatin1(), CEncrypt::Model_XOR) + << encrypt.XOR(registerSecretiveQuestion1.toLatin1(), CEncrypt::Model_XOR) + << encrypt.XOR(registerSecretiveAnswer1.toLatin1(), CEncrypt::Model_XOR) + << encrypt.XOR(registerSecretiveQuestion2.toLatin1(), CEncrypt::Model_XOR) + << encrypt.XOR(registerSecretiveAnswer2.toLatin1(), CEncrypt::Model_XOR); + file_user_enc.close(); + + m_dirUsersEnc.setPath(m_path_users_dir + registerAccount); + if(m_dirUsersEnc.exists()) + { + m_dirUsersEnc.removeRecursively(); + m_dirUsersEnc.mkpath(m_path_users_dir + registerAccount); + } + else + { + m_dirUsersEnc.mkpath(m_path_users_dir + registerAccount); + } + + QMessageBox::information(this, "提示", "注册成功!"); + emit registered(registerAccount, registerPassword); + } + }); + + connect(this, &CRegisterDialog::registered, this, &CRegisterDialog::clearLineEdits); + /* [Register] **/ +} + +CRegisterDialog::~CRegisterDialog() +{ + delete ui; +} + +void CRegisterDialog::clearLineEdits() +{ + ui->lineEditAccount->clear(); + ui->lineEditPassword->clear(); + ui->lineEditPasswordAgain->clear(); + ui->lineEditSecretiveQuestion1->clear(); + ui->lineEditSecretiveAnswer1->clear(); + ui->lineEditSecretiveQuestion2->clear(); + ui->lineEditSecretiveAnswer2->clear(); +} diff --git a/cregisterdialog.h b/cregisterdialog.h new file mode 100644 index 0000000..9b58023 --- /dev/null +++ b/cregisterdialog.h @@ -0,0 +1,59 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CREGISTERDIALOG_H +#define CREGISTERDIALOG_H + +#include "cstring.h" +#include "cencrypt.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class CRegisterDialog; +} + +class CRegisterDialog : public QDialog +{ + Q_OBJECT + +signals: + void registered(QString registerAccount, QString registerPassword); + +public: + explicit CRegisterDialog(QWidget *parent = nullptr); + ~CRegisterDialog(); + +protected: + +private: + Ui::CRegisterDialog *ui; + + const QString m_fileCode = "#APQA"; + const QString m_path_users_enc = QCoreApplication::applicationDirPath() + "/system/users/"; + const QString m_path_users_dir = QCoreApplication::applicationDirPath() + "/users/"; + + bool isNetwork = false; + + QDir m_dirUsersEnc; + + QStringList m_listUsers; + +private slots: + void clearLineEdits(); +}; + +#endif // CREGISTERDIALOG_H diff --git a/cregisterdialog.ui b/cregisterdialog.ui new file mode 100644 index 0000000..f3c8cb1 --- /dev/null +++ b/cregisterdialog.ui @@ -0,0 +1,1147 @@ + + + CRegisterDialog + + + + 0 + 0 + 280 + 302 + + + + + 0 + 0 + + + + + 280 + 300 + + + + + 280 + 302 + + + + 注册账号 + + + #CRegisterDialog +{ + background:rgb(220, 220, 220); +} + + + + 0 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入账号 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Password + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入密码 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Password + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请再次输入密码 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 10 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入第一个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 10 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入第二个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 5 + + + 2 + + + 5 + + + 10 + + + 0 + + + + + + 0 + 0 + + + + + 250 + 35 + + + + + 250 + 35 + + + + + 等线 + 14 + 75 + true + + + + PointingHandCursor + + + 点击注册 + + + background:rgb(5, 187, 251); +border-radius:8px; +color:rgb(255, 255, 255); + + + 注册 + + + Enter + + + false + + + false + + + false + + + + + + + + + + + diff --git a/cretrievedialog.cpp b/cretrievedialog.cpp new file mode 100644 index 0000000..9a22739 --- /dev/null +++ b/cretrievedialog.cpp @@ -0,0 +1,89 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cretrievedialog.h" +#include "ui_cretrievedialog.h" + +CRetrieveDialog::CRetrieveDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CRetrieveDialog) +{ + ui->setupUi(this); //默认代码 + + + /** [LineEdits] */ + ui->lineEditAccount->setValidator(new QRegExpValidator(QRegExp("[A-Za-z0-9]{0,20}"), this)); //用正则表达式来限制输入 + connect(ui->lineEditAccount, &QLineEdit::textChanged, [&](const QString &lineEditString) + { + QFile file_user_enc(m_path_users_enc + lineEditString + ".enc"); + if(file_user_enc.open(QIODevice::ReadOnly)) + { + QString fileCode; + QDataStream outputStream(&file_user_enc); + QByteArray account, password, question1, answer1, question2, answer2; + outputStream >> fileCode >> account >> password >> question1 >> answer1 >> question2 >> answer2; + file_user_enc.close(); + + CEncrypt encrypt; + m_password = encrypt.XOR(password, CEncrypt::Model_XOR); + m_answer1 = encrypt.XOR(answer1, CEncrypt::Model_XOR); + m_answer2 = encrypt.XOR(answer2, CEncrypt::Model_XOR); + ui->lineEditSecretiveQuestion1->setText(encrypt.XOR(question1, CEncrypt::Model_XOR).data()); + ui->lineEditSecretiveQuestion2->setText(encrypt.XOR(question2, CEncrypt::Model_XOR).data()); + } + else + { + ui->lineEditSecretiveQuestion1->clear(); + ui->lineEditSecretiveQuestion2->clear(); + } + }); + /* [LineEdits] **/ + + + /** [Retrieve] */ + connect(ui->toolButtonRetrieve, &QToolButton::clicked, [&]() + { + if(isNetwork) + { + ; + } + else + { + if(ui->lineEditAccount->text() == "") + { + QMessageBox::warning(this, "提示", "账号不能为空!"); + return; + } + if(ui->lineEditSecretiveAnswer1->text() == "" || ui->lineEditSecretiveAnswer2->text() == "") + { + QMessageBox::warning(this, "提示", "回答不能为空!"); + return; + } + if(ui->lineEditSecretiveAnswer1->text() == m_answer1 && ui->lineEditSecretiveAnswer2->text() == m_answer2) + { + QMessageBox::warning(this, "提示", "身份验证完成\n当前账号密码:" + m_password + "\n请牢记密码!"); + emit retrieved(); + } + else + { + QMessageBox::warning(this, "提示", "答案错误!"); + return; + } + } + }); + connect(this, &CRetrieveDialog::retrieved, this, &CRetrieveDialog::clearLineEdits); + /* [Retrieve] **/ +} + +CRetrieveDialog::~CRetrieveDialog() +{ + delete ui; +} +void CRetrieveDialog::clearLineEdits() +{ + ui->lineEditAccount->clear(); + ui->lineEditSecretiveAnswer1->clear(); + ui->lineEditSecretiveAnswer2->clear(); +} diff --git a/cretrievedialog.h b/cretrievedialog.h new file mode 100644 index 0000000..7fd044a --- /dev/null +++ b/cretrievedialog.h @@ -0,0 +1,58 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CRETRIEVEDIALOG_H +#define CRETRIEVEDIALOG_H + +#include "cstring.h" +#include "cencrypt.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Ui { +class CRetrieveDialog; +} + +class CRetrieveDialog : public QDialog +{ + Q_OBJECT + +signals: + void retrieved(); + +public: + explicit CRetrieveDialog(QWidget *parent = nullptr); + ~CRetrieveDialog(); + +protected: + +private: + Ui::CRetrieveDialog *ui; + + const QString m_fileCode = "#APQA"; + const QString m_path_users_enc = QCoreApplication::applicationDirPath() + "/system/users/"; + const QString m_path_users_dir = QCoreApplication::applicationDirPath() + "/users/"; + + bool isNetwork = false; + + QString m_password; + QString m_answer1; + QString m_answer2; + + QStringList m_listUsers; + +private slots: + void clearLineEdits(); +}; + +#endif // CRETRIEVEDIALOG_H diff --git a/cretrievedialog.ui b/cretrievedialog.ui new file mode 100644 index 0000000..834ea31 --- /dev/null +++ b/cretrievedialog.ui @@ -0,0 +1,861 @@ + + + CRetrieveDialog + + + + 0 + 0 + 280 + 232 + + + + + 0 + 0 + + + + + 280 + 230 + + + + + 280 + 232 + + + + 找回密码 + + + #CRetrieveDialog +{ + background:rgb(220, 220, 220); +} + + + + 0 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入账号 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 第一个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 第二个安全问题 + + + true + + + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + + + + 0 + 0 + + + + + 280 + 35 + + + + + 280 + 35 + + + + + 等线 + 10 + 75 + true + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 等线 + 10 + 75 + true + + + + Qt::Vertical + + + + 20 + 20 + + + + + + + + + 25 + 25 + + + + + 250 + 25 + + + + + 250 + 25 + + + + + Consolas + 16 + 50 + false + false + + + + + + + false + + + background:rgb(255, 255, 255); +border-radius:5px; +color:rgb(0, 0, 0); + + + + + + + + + 20 + + + true + + + QLineEdit::Normal + + + 0 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + 请输入问题答案 + + + true + + + + + + + + + + + 0 + 0 + + + + background:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0.0965909 rgba(0, 0, 0, 255), stop:0.903409 rgba(220, 220, 220, 220)); + + + + 5 + + + 2 + + + 5 + + + 10 + + + 0 + + + + + + 0 + 0 + + + + + 250 + 35 + + + + + 250 + 35 + + + + + 等线 + 14 + 75 + true + + + + PointingHandCursor + + + 点击注册 + + + background:rgb(5, 187, 251); +border-radius:8px; +color:rgb(255, 255, 255); + + + 找回 + + + Enter + + + false + + + false + + + false + + + + + + + + + + + diff --git a/cstring.cpp b/cstring.cpp new file mode 100644 index 0000000..3895119 --- /dev/null +++ b/cstring.cpp @@ -0,0 +1,180 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cstring.h" + +CString::CString() +{ + ; +} + +CString::~CString() +{ + ; +} + +bool CString::isEmpty() +{ + if(this->m_qstring == "") + { + return true; + } + return false; +} + +qint16 CString::getSize() +{ + return this->m_qstring.size(); +} + +QString CString::getString() +{ + return this->m_qstring; +} + +CString::CStringError CString::check(const int index) +{ + if(index < 0 || index > this->m_qstring.size() - 1) + { + return Error_NullIndex; + } + QChar targetChar = this->m_qstring[index]; + switch (m_checkModel) + { + default: + { + return Error_NullModel; + } + case Model_Account: + { + if(((47 < targetChar) && (targetChar < 58)) || ((64 < targetChar) && (targetChar < 91)) || ((96 < targetChar) && (targetChar < 123))) + { + return Error_None; + } + break; + } + case Model_Password: + { + if(((32 < targetChar) && (targetChar < 91)) || ((96 < targetChar) && (targetChar < 123))) + { + return Error_None; + } + break; + } + case Model_Code: + { + if((31 < targetChar) && (targetChar < 127)) + { + return Error_None; + } + break; + } + } + return Error_NullChar; +} + +CString::CStringError CString::check(const int beginIndex, const int endIndex) +{ + if(beginIndex < 0 || endIndex > this->m_qstring.size() - 1 || beginIndex > endIndex) + { + return Error_NullIndex; + } + for(int i = beginIndex; i <= endIndex; ++i) + { + if(check(beginIndex, endIndex) != Error_None) + { + return Error_NullString; + } + } + return Error_None; +} + +CString::CStringError CString::eliminate(const int index) +{ + return this->eliminate(index, index); +} + +CString::CStringError CString::eliminate(const int beginIndex, const int endIndex) +{ + if(beginIndex < 0 || endIndex > this->m_qstring.size() - 1 || beginIndex > endIndex) + { + return Error_NullIndex; + } + QString temporaryString; + for(int i = 0; i < beginIndex; ++i) + { + temporaryString += this->m_qstring[i]; + } + for(int i = endIndex + 1; i > endIndex && i < this->m_qstring.size(); ++i) + { + temporaryString += this->m_qstring[i]; + } + if(this->m_qstring.size() == temporaryString.size() + (endIndex - beginIndex + 1)) + { + this->m_qstring = temporaryString; + return Error_None; + } + return Error_AbortedEliminate; +} + +CString::CStringError CString::insert(const int index, const QChar targetChar) +{ + QString targetString = QString(targetChar); + return this->insert(index, targetString); +} + +CString::CStringError CString::insert(const int index, const QString target) +{ + if(index < 0 || index > this->m_qstring.size() - 1) + { + return Error_NullIndex; + } + else if(target == "") + { + return Error_NullString; + } + QString temporaryString; + for(int i = 0; i < index; ++i) + { + temporaryString += this->m_qstring[i]; + } + temporaryString += target; + for(int i = index; i < this->m_qstring.size(); ++i) + { + temporaryString += this->m_qstring[i]; + } + if(this->m_qstring.size() == temporaryString.size() - target.size()) + { + this->m_qstring = temporaryString; + return Error_None; + } + return Error_AbortedInset; +} + +CString::CStringError CString::replace(const int index, const QChar targetChar) +{ + QString targetString = QString(targetChar); + return this->replace(index, index, targetString); +} + +CString::CStringError CString::replace(const int beginIndex, const int endIndex, const QString targetString) +{ + CStringError abc = this->eliminate(beginIndex, endIndex); + if(abc == Error_None) + { + return this->insert(beginIndex, targetString); + } + return Error_AbortedReplace; +} + +CString::CStringError CString::set(const QString setString) +{ + this->m_qstring = setString; + if(this->m_qstring == setString) + { + return Error_None; + } + return Error_AbortedSet; +} diff --git a/cstring.h b/cstring.h new file mode 100644 index 0000000..9841791 --- /dev/null +++ b/cstring.h @@ -0,0 +1,62 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#ifndef CSTRING_H +#define CSTRING_H + +#include +#include +#include + +class CString : public QString +{ +public: + enum CStringError + { + Error_AbortedEliminate, //删除失败 + Error_AbortedInset, //插入失败 + Error_AbortedReplace, //替换失败 + Error_AbortedSet, //设置失败 + Error_None, //无错误 + Error_NullChar, //无效的字符 + Error_NullIndex, //无效的下标 + Error_NullModel, //无效的模式 + Error_NullString, //无效字符串 + }; + enum CStringModel + { + Model_None, //针对空白类型 + Model_Account, //针对账号类型 + Model_Code, //针对代码类型 + Model_Password, //针对密码类型 + }; + + CString(); + CString(QString qstring, CStringModel checkModel = Model_None) : m_qstring(qstring), m_checkModel(checkModel) {}; //构造函数的重载 + ~CString(); + + bool isEmpty(); //处理对象是否为空 + qint16 getSize(); //返回当前字符串的大小 + QString getString(); //返回当前字符串 + + CStringError check(const int index); //检查指定对象 + CStringError check(const int beginIndex, const int endIndex); //检查指定范围内的对象 + CStringError eliminate(const int index); //删除指定对象 + CStringError eliminate(const int beginIndex, const int endIndex); //删除指定对象 + CStringError insert(const int index, const QChar targetChar); //在指定位置插入指定对象 + CStringError insert(const int index, const QString targetString); //在指定位置插入指定对象 + CStringError replace(const int index, const QChar targetChar); //替换指定对象 + CStringError replace(const int beginIndex, const int endIndex, const QString targetString); //替换指定对象 + CStringError set(const QString string); //设置处理对象 + +protected: + +private: + QString m_qstring; //处理对象 + CStringModel m_checkModel = Model_None; //检查模式 + +}; + +#endif // CSTRING_H diff --git a/intelligentwindow.ico b/intelligentwindow.ico new file mode 100644 index 0000000000000000000000000000000000000000..e2339de47ceba638078756e1075cc8788939697e GIT binary patch literal 61310 zcmeI5d2AHd9mmIz;5Ka_L1|i*`@S)kIgB}NbD6_{jSV)G8*^hYz5c2HL~4i7h|ye zG`I?G0hK^L!a2VIn!r6E6`znb6|8waKa^$QEs#X#na=q-V$lYAfY|1MKDW=Kd;w&N zLz3Tf5R(NuMg{AGVeVL;+dPyXfF!%lcJALxfd3uhK5Op3hS=OkIS|K}&h4$@Kdb+X zh|OnX?tcc(@0#R5#vC|K?qlx16z6wZ{NLsOZ-~iMa!+`+KdoL;+;`_Z z5p!}+JOthZVfp_h+I|3}j;A~4B-?t60LL8VVGxG@TWEI=ABVT2m)hNp0LLBW81Nnl zItTuWHirZ0``wl4b9){8UMQajLHqwP+PsI3L0;iRfMTy{Lm9OH-Q0dSXD_XC{87#Z z{{}(jz%{g04rJ^PISsXgFQNQB2+IGj(H8yg5%Sqf^W*^B3(kU|{Qm@P^#mdyy^d%XYhU>@L*Kw*RS7$m2>8N@!0W4U;XxDkE=p* z?2+T=rj?g}p@0AWk&TD;M9xaVU3r=*54zN&ZI^>b!3FRZ_*KMtXJT2|wesoH)wJ@$ zK>MCJaiW7byc6+QkgLn!W$*}C3VMUiTyW>Wph1HyV!(g_Jy53>Tml~fRZQUcRS*RF<({-5~nYh$-Y?Q|SX`8P8IS=;lKd82E-znojNaMg3?O%H}&4Il6 zr#zr}!Ja+)6kUsCEC_Zi@aup0@Zkz_ zZtS18@#>#*;lP1IYR8UUa!n}EctHLaFJ6+fAG1eY2Iily2{Jz{%y{6}|HzRe9iU9{ z+y8kSppxc?yLPq8X9js33)sJ@M_tcG8MuEQ3uJznzp=ot|52kxIY5~}In&UvF6Zxm z?!KODnLabvy?d{W1>GDA-2P2m>N++`WB;^GzWsB4$o#N-V?o;gQlozC$`5<==+O>P zCKS>?UlZt_l6-#XJr~ITk|k;XCN6ayPyT6}LiK+h2dJda4EX-Ce2#3E3+&&6d+PJ{ zm@#7%u(h%VE-Q6Q=cy? z|2!7R{P6A^@auovxN#0pri9u5**}*uKfIj>?BCR*u4kk4=)Wn@`5(K^R`UEX>7N<+ z^*?_6cn2s`8XKeKpYtN=&m58eWy@-fJ!;=}T>MiWB>9uwlj{{UD z@tGs`Z|YIkvr)#*Kj%V{=7)a$)A!i{`d&LD8XMO~YW~Nrvz1ACCOz$cxsgMcYa7ds zYdz=oO-;q+pYtN_^F#7qTkG9_Sy`C_lqtpPpYkBi&!n?|Q;)iyjWRL*c`Tr7LTk+a z&7xoblO|1afHI|+`#<~VGEVoD*uSYqUC*98d9njkE_lC9O&f}8{>QGfm2^#r!!zmR zfBEtio&7kMPyKUa|GdBT>*M90^CJCBdipypit(8v_RpRSOMA+cDGpF3&_3hppYnj` zhue$r-?6*>o4C|;_RQt0=}n2F)fy{fc<-LPkr8=I(4c8R4#bGN$}5kP)zf~ zwEvZ zVwA24ZvQ4ObsbOsX`7_?e;x;@jM6=&wEtB`{n(WsKK!>NYX0Z;ooSiphhcvYCi!2v z(!2lZ)2BN?nbO=W{xjtP%@4!8r^NnEJ?eTkO7V}eJd;yD?}ar#^y`1dj2RA4rbz$K zohvjy4EmlD`#1Hd>)9y9e;)h4d&~%Oewg-OXWWn3|IC>)9iU8UZr&*KKM(oB_mm1f zKP3OFR@E7M)V^);pL;xa_i4Y&g`OY!^*?LYEC(o4T3V$4`^^E`u2A=s*uSYqUC%}- z{ymK6-Eq&`(lsI9^FzP>D=I1+piGhepTFw`&kxC6cb_w$ebm*hHuk7}+u}ceKDmE; zDf2Zy^y`22?AZ=bCQ#0_v}}_3e*vx+^qE0-K0kE(H*u-!*eH$t(>5D7ihnQt+iP9F z^F#LU!9DeP@n3+x?A3YK`g~8x%l&1){wpgh9iU8+{vX_Y!OJs8!dabcX?c4V5f3rG@ z|Npri{|B%Tehg^bNnaCM)tWWl{m+{>&jHE=${G5MnLY!g`v5|8VnEMj)AzrSBNLap zj*ZgTKkql)2DKwZAqF0u!&_&6_vPQUy?bA>d^@hi5(|6&{P|ab5)v7Mcj5htxKE^e z>ho`dABg|N`hODco4^gpfyCv&hj3oEV8MdE;1W<$#O>@%2yrz8&-eZuhC>s;a6U3l}b|1((1L zpoCb&;6L#A3RqlSU0uTNE&ZZ({LD>XtT%!);CJAC@DHJ=V(@qP`VBY@8o&df(=oeO zN?qsWo>+0Omjt}twSB#QlaH@7eLS~#y-#{wsZ@y~DC}Fw=X + + ico/64_plugin.ico + ico/answers.ico + ico/bag.ico + ico/Board_Games_red.ico + ico/Calcbot.ico + ico/certificate.ico + ico/chat.ico + ico/clock.ico + ico/close.ico + ico/cloud_download.ico + ico/cloud_upload.ico + ico/cnvcs.ico + ico/contacts.ico + ico/controls.ico + ico/Diamond_jewelry.ico + ico/FAQ.ico + ico/GameCenter.ico + ico/gamepad_game.ico + ico/Gem_Diamond_jewelry.ico + ico/hand.ico + ico/hanger.ico + ico/history.ico + ico/intelligentwindow.ico + ico/key.ico + ico/lock.ico + ico/Market_Analysis.ico + ico/music.ico + ico/mytracks.ico + ico/netlog.ico + ico/penciledit.ico + ico/Play_Music.ico + ico/questions.ico + ico/repair.ico + ico/ringtones.ico + ico/security.ico + ico/settings.ico + ico/stop.ico + ico/Trophy.ico + ico/users.ico + ico/wifi.ico + ico/xbox.ico + + diff --git a/intelligentwindowclient_zh_CN.ts b/intelligentwindowclient_zh_CN.ts new file mode 100644 index 0000000..ab3e619 --- /dev/null +++ b/intelligentwindowclient_zh_CN.ts @@ -0,0 +1,3 @@ + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..863101f --- /dev/null +++ b/main.cpp @@ -0,0 +1,38 @@ +/****************************** + * Author : YangRongBao + * Date : 2021.4 +******************************/ + +#include "cstring.h" +#include "cmainwindow.h" +#include "cloginwindow.h" + +#include +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication intelligentWindowClient(argc, argv); + QTextCodec *codec = QTextCodec::codecForName("UTF-8"); //此格式支持中文 + QTextCodec::setCodecForLocale(codec); //设置文件格式 + + CLoginWindow loginWindow; + loginWindow.show(); + + CMainWindow *mainWindow = nullptr; + + QObject::connect(&loginWindow, &CLoginWindow::login, [&](QString account) + { + mainWindow = new CMainWindow(account); + loginWindow.hide(); + mainWindow->show(); + QObject::connect(mainWindow, &CMainWindow::logout, [&](){ + mainWindow->hide(); + loginWindow.show(); + delete mainWindow; + }); + }); + + return intelligentWindowClient.exec(); +}