From 9ee232cead8605b399045bc23c302f9c23a6d1a2 Mon Sep 17 00:00:00 2001 From: Mike Solar Date: Mon, 21 Aug 2023 15:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=85=BC=E5=AE=B9=E6=80=A7?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OfficeAssistant_msvc/addapp.cpp | 63 +++++++++++++------ OfficeAssistant_msvc/applicationmanager.cpp | 4 +- OfficeAssistant_msvc/applicationmanager.h | 2 +- .../applicationmanagerpage.cpp | 24 ++++--- OfficeAssistant_msvc/globalvariables.h | 2 + OfficeAssistant_msvc/minibutton.cpp | 11 +--- OfficeAssistant_msvc/navbar.cpp | 7 ++- OfficeAssistant_msvc/netio.cpp | 21 ++++--- OfficeAssistant_msvc/sqlitehelper.cpp | 31 +++++++-- 9 files changed, 110 insertions(+), 55 deletions(-) diff --git a/OfficeAssistant_msvc/addapp.cpp b/OfficeAssistant_msvc/addapp.cpp index cf641c2..4e7906c 100644 --- a/OfficeAssistant_msvc/addapp.cpp +++ b/OfficeAssistant_msvc/addapp.cpp @@ -23,33 +23,37 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) setWindowFlags(Qt::WindowCloseButtonHint); form = new QFormLayout; name = new QLineEdit; - form->addRow(QString::fromLocal8Bit("名称"), name); - - if (isEdit) + if(isEdit) { - sqlite_helper.get_a_software(row->orig_name, &record); - name_label = new QLabel(orig_name_str); - form->addRow(QString::fromLocal8Bit("全名"), name_label); - record = *row;//最初为啥这么写我也忘了 - if (!record.orig_name.isEmpty()) - { - name_label->setText(record.orig_name); - } - orig_name_str = record.orig_name; + record=*row;//最初为啥这么写我也忘了 } - else - { - orig_name = new QLineEdit; - form->addRow(QString::fromLocal8Bit("全名"), orig_name); - } - + if (record.orig_name.isEmpty()) { path = new QPushButton(QString::fromLocal8Bit("浏览")); connect(path, &QPushButton::clicked, this, &AddApp::broswer_exe); form->addRow(QString::fromLocal8Bit("路径"), path); + if (isEdit) + { + sqlite_helper.get_a_software(row->orig_name, &record); + name_label = new QLabel(orig_name_str); + form->addRow(QString::fromLocal8Bit("全名"), name_label); + if (!record.orig_name.isEmpty()) + { + name_label->setText(record.orig_name); + } + orig_name_str = record.orig_name; + } + else + { + orig_name = new QLineEdit; + form->addRow(QString::fromLocal8Bit("全名"), orig_name); + } + form->addRow(QString::fromLocal8Bit("名称"), name); + sort = new QLineEdit; sort->setValidator(new QIntValidator(10, 100)); + sort->setText("50"); form->addRow(QString::fromLocal8Bit("排序"), sort); QList categrories; layout_inner = new QVBoxLayout; @@ -83,6 +87,24 @@ AddApp::AddApp(bool isEdit, Record2 *row , QWidget* parent) { form->addRow(QString::fromLocal8Bit("路径"), path); } + if (isEdit) + { + sqlite_helper.get_a_software(row->orig_name, &record); + name_label = new QLabel(orig_name_str); + form->addRow(QString::fromLocal8Bit("全名"), name_label); + if (!record.orig_name.isEmpty()) + { + name_label->setText(record.orig_name); + } + orig_name_str = record.orig_name; + } + else + { + orig_name = new QLineEdit; + form->addRow(QString::fromLocal8Bit("全名"), orig_name); + } + form->addRow(QString::fromLocal8Bit("名称"), name); + sort = new QLineEdit; sort->setText(QString::number(record.sort)); sort->setValidator(new QIntValidator(10, 100)); @@ -145,7 +167,10 @@ void AddApp::broswer_exe(){ } fs::path file(path_str.toStdWString()); path->setText(QString::fromStdWString(file.filename().c_str())); - + if(!isEdit) + { + orig_name->setText(QString::fromStdWString(file.filename().c_str())); + } } void AddApp::submit() { diff --git a/OfficeAssistant_msvc/applicationmanager.cpp b/OfficeAssistant_msvc/applicationmanager.cpp index 37851e0..d25f9f7 100644 --- a/OfficeAssistant_msvc/applicationmanager.cpp +++ b/OfficeAssistant_msvc/applicationmanager.cpp @@ -126,7 +126,7 @@ void ApplicationManager::onclick1(QString op, QString func, QString path, QStrin QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("插入失败,全名是否重名")); } - emit refresh(); + emit refresh_tab(); } } else if (func == "app_update") @@ -237,7 +237,7 @@ void ApplicationManager::onclick2(QString orig_name, QString op) { QMessageBox::critical(this, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("编辑失败")); } - emit refresh(); + emit refresh_tab(); } } diff --git a/OfficeAssistant_msvc/applicationmanager.h b/OfficeAssistant_msvc/applicationmanager.h index 4e6acdf..63010d2 100644 --- a/OfficeAssistant_msvc/applicationmanager.h +++ b/OfficeAssistant_msvc/applicationmanager.h @@ -57,6 +57,7 @@ signals: void refresh(); void refresh_tab(); public: + QList buttons; ApplicationManager(QWidget *parent = nullptr); ~ApplicationManager(); QWidget* parent; @@ -69,7 +70,6 @@ private: QHBoxLayout* layout_top; QHBoxLayout* layout_bottom; QMiniBlink* miniblink; - QList buttons; QList softwares; QList button_structs; ApplicationManagerPage* application_manager_page_all; diff --git a/OfficeAssistant_msvc/applicationmanagerpage.cpp b/OfficeAssistant_msvc/applicationmanagerpage.cpp index 0b1bd57..f4f9755 100644 --- a/OfficeAssistant_msvc/applicationmanagerpage.cpp +++ b/OfficeAssistant_msvc/applicationmanagerpage.cpp @@ -86,6 +86,10 @@ void ApplicationManagerPage::onclicked(int state) //刷新页面 void ApplicationManagerPage::refresh() { + for(auto button:application_manager->buttons) + { + button->update(); + } int rowcount = table->rowCount(); for(auto i : connections) { @@ -141,13 +145,18 @@ void ApplicationManagerPage::refresh() } table->setCellWidget(i, 0, record2.icon); - record2.settings = new MiniButton(software.orig_name, "settings"); - record2.settings->setText(QString::fromLocal8Bit("设置")); - record2.settings->setMaximumSize(60, 40); - QMetaObject::Connection connect1=connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2); - connections << connect1; - QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); - connections << connect2; + + if(!software.locked) + { + record2.settings = new MiniButton(software.orig_name, "settings"); + record2.settings->setText(QString::fromLocal8Bit("设置")); + record2.settings->setMaximumSize(60, 40); + QMetaObject::Connection connect1 = connect(record2.settings, &MiniButton::clicked, record2.settings, &MiniButton::onclick2); + connections << connect1; + QMetaObject::Connection connect2 = connect(record2.settings, &MiniButton::click2, application_manager, &ApplicationManager::onclick2); + connections << connect2; + table->setCellWidget(i, 7, record2.settings); + } record2.open = new MiniButton(software.orig_name, "open"); record2.open->setText(QString::fromLocal8Bit("打开")); record2.open->setMaximumSize(60, 40); @@ -203,7 +212,6 @@ void ApplicationManagerPage::refresh() table->setItem(i, 6, check_box_item); table->setCellWidget(i, 6, record2.check_box); check_box_item->setTextAlignment(Qt::AlignCenter); - table->setCellWidget(i, 7, record2.settings); table->setCellWidget(i, 8, record2.open); rows.insert(software.orig_name, record2); table->resizeColumnToContents(0); diff --git a/OfficeAssistant_msvc/globalvariables.h b/OfficeAssistant_msvc/globalvariables.h index 9488a5a..a07280c 100644 --- a/OfficeAssistant_msvc/globalvariables.h +++ b/OfficeAssistant_msvc/globalvariables.h @@ -13,5 +13,7 @@ extern MainWindowLayout *mainWindowLayout; extern QString url_param; extern bool autostart; extern bool agree; +extern QString background_color; +extern QString text_color; extern ApplicationManager *application_manager; #endif //OFFICEASSISTANT_GLOBALVARIABLES_H diff --git a/OfficeAssistant_msvc/minibutton.cpp b/OfficeAssistant_msvc/minibutton.cpp index 3825143..2407459 100644 --- a/OfficeAssistant_msvc/minibutton.cpp +++ b/OfficeAssistant_msvc/minibutton.cpp @@ -6,7 +6,6 @@ MiniButton::MiniButton(QString orig_name, QString op, QWidget* parent) { this->orig_name = orig_name; - q_color.setNamedColor(DEFAULT_BACKGROUND_COLOR); this->op = op; connect(this, &MiniButton::click, this, &MiniButton::onclick2); @@ -15,11 +14,6 @@ MiniButton::MiniButton(ButtonStruct button_struct, QWidget *parent) : QPushButton(parent) { ui.setupUi(this); - q_color.setNamedColor(DEFAULT_COVER_COLOR); - QString style_sheet = "MiniButton:{background-color:"; - style_sheet += DEFAULT_TEXT_COLOR; - style_sheet += ";}"; - setStyleSheet(style_sheet); connect(this, &MiniButton::click, this, &MiniButton::onclick1); this->button_struct = button_struct; } @@ -33,14 +27,15 @@ void MiniButton::paintEvent(QPaintEvent* event) setContentsMargins(0, 0, 0, 0); QRect rect(0, 0, this->width(), this->height()); QPainter painter(this); - + q_color.setNamedColor(background_color); + painter.fillRect(rect, q_color); int text_x = (width() - TEXT_SIZE * text().length() * scale * 3) / 2; int text_y = (height()- TEXT_SIZE * scale * 3)/2; QFont ft; ft.setPixelSize(TEXT_SIZE); QRectF text_rect(text_x, text_y, TEXT_SIZE * text().length() * scale * 3, TEXT_SIZE * scale * 3); - painter.setPen(DEFAULT_TEXT_COLOR); + painter.setPen(text_color); painter.drawText(text_rect, Qt::AlignCenter, text()); } diff --git a/OfficeAssistant_msvc/navbar.cpp b/OfficeAssistant_msvc/navbar.cpp index af0fa3f..e15c1a1 100644 --- a/OfficeAssistant_msvc/navbar.cpp +++ b/OfficeAssistant_msvc/navbar.cpp @@ -155,8 +155,8 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { timer.stop(); buffer = new QByteArray; delete request_logo; - reply->close(); - if (downloadSuccess == true) { + + if (downloadSuccess == true&& reply->error() == QNetworkReply::NoError) { *buffer = reply->readAll(); QFile logo(QApplication::applicationDirPath() + DEFAULT_LOGO); if (logo.open(QIODevice::WriteOnly)) { @@ -164,10 +164,11 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { logo.close(); } buffer->clear(); + reply->close(); + } delete manager; manager = nullptr; - } void NavBar::storeToBuffer() { buffer = new QByteArray; diff --git a/OfficeAssistant_msvc/netio.cpp b/OfficeAssistant_msvc/netio.cpp index 07a14cf..e67f540 100644 --- a/OfficeAssistant_msvc/netio.cpp +++ b/OfficeAssistant_msvc/netio.cpp @@ -31,6 +31,8 @@ #pragma comment(lib, "Qt5Network.lib") #endif #pragma comment(lib,"comsuppw.lib") +QString background_color; +QString text_color; //读取注册表获取MachineUUID bool IsWin11AndLater() { @@ -187,12 +189,9 @@ RequestBodyBase::RequestBodyBase(){ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { timer = new QTimer(this); - if(agree) - { - QJsonObject obj_root = qJsonDocument.object(); - obj_root.insert("autostart", autostart); - qJsonDocument.setObject(obj_root); - } + QJsonObject obj_root = qJsonDocument.object(); + obj_root.insert("autostart", autostart); + qJsonDocument.setObject(obj_root); QNetworkAccessManager *httpMgr = new QNetworkAccessManager(); QNetworkRequest requestInfo; @@ -238,8 +237,13 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { array = obj_root.value("data").toObject().value("menu").toArray(); QJsonObject obj_data = obj_root.value("data").toObject(); - QString basic_str= obj_data.value("basic").toString(); - QJsonObject obj_basic=QJsonDocument::fromJson(basic_str.toUtf8()).object(); + if(!obj_data.value("basic").isObject()) + { + configResponse->succeed=false; + delete timer; + return; + } + QJsonObject obj_basic=obj_data.value("basic").toObject(); configResponse->basic.logo_url = obj_basic.value("logo").toString(); configResponse->basic.device_id = obj_basic.value("device_id").toString(); configResponse->basic.dev_id = obj_basic.value("dev_id").toString(); @@ -247,6 +251,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) { configResponse->basic.backgroud_color = obj_basic.value("backgroud_color").toString(); configResponse->basic.title_color = obj_basic.value("title_color").toString(); configResponse->basic.title_cover_color = obj_basic.value("title_cover_color").toString(); + auto i=0; for(auto value:array){ QJsonObject object=value.toObject(); diff --git a/OfficeAssistant_msvc/sqlitehelper.cpp b/OfficeAssistant_msvc/sqlitehelper.cpp index b19c342..9a12eb4 100644 --- a/OfficeAssistant_msvc/sqlitehelper.cpp +++ b/OfficeAssistant_msvc/sqlitehelper.cpp @@ -673,6 +673,7 @@ bool SQLiteHelper::update_software() } else { + public_programs_list[key].img.replace(QApplication::applicationDirPath(), ""); sql = "insert into kmd_menu (sort,app_id,locked,type,category_id,name,orig_name,version,dev,create_time,use_time,op,func,path,url,status,is_navbar,is_elite) values " "(:sort,:app_id,:locked,:type,:category_id,:name,:orig_name,:version,:dev,:create_time,:use_time,:op,:func,:path,:url,:status,:is_navbar,:is_elite); "; query.prepare(sql); @@ -760,13 +761,13 @@ bool SQLiteHelper::get_software(QList* button_structs, ConfigRespo QSqlQuery query(db); QString sql = "select * from kmd_menu where is_navbar=1 order by sort,orig_name asc ;"; - QString background_color; QString title_color; QString title_cover_color; QList