第一阶段只差兼容性问题了

master
Mike Solar 2023-08-01 23:51:40 +08:00
parent 9b53ef9764
commit 6a695e8a03
20 changed files with 167 additions and 54 deletions

View File

@ -1,4 +1,3 @@
<RCC>
<qresource prefix="OfficeAssistant_msvc">
</qresource>
<qresource prefix="/OfficeAssistant_msvc"/>
</RCC>

View File

@ -102,6 +102,7 @@
<ClInclude Include="globalvariables.h" />
<QtMoc Include="qminiblink.h" />
<QtMoc Include="mysettingsdialog.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="wke.h" />
<QtMoc Include="mainwindowlayout.h" />
<QtMoc Include="mainwindow.h" />
@ -129,6 +130,12 @@
<QtUic Include="navbar.ui" />
<QtUic Include="qminiblink.ui" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="logo.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="icon\wechat.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />

View File

@ -40,6 +40,9 @@
<ClInclude Include="wke.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtMoc Include="navbar.h">
@ -116,4 +119,14 @@
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="logo.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<Image Include="icon\wechat.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>

View File

@ -4,13 +4,18 @@
#ifndef OFFICEASSISTANT_CONFIG_H
#define OFFICEASSISTANT_CONFIG_H
#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config"
#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op"
#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device"
#define BASE_URL "http://softapi.s103.y01.cn/"
#define DEFAULT_FILE "/config/default_navbar.kmd"
#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0"
#define CONFIG_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/config" //获取导航栏信息的地址
#define OP_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/op" //上传是否设置开机启动、是否建立桌面快捷方式的地址
#define DEVICE_URL "http://softapi.s103.y01.cn/addons/Kmdsoft/Index/device" //上传设备信息的地址
#define BASE_URL "http://softapi.s103.y01.cn/" //域名
#define DEFAULT_FILE "/config/default_navbar.kmd" //默认导航栏文件位置
#define KEY "3b046cfe4a2a3e62141a4840f2006210a3224e3615312bef6e19f4983921abe0" //Key
#define NAME "办公助手" //中文名
#define LOGO_TITLEBAR "/icon/logo_navbar.png" //标题栏图标
#define ENG_NAME "OfficeAssistant" //英文名
#define LENG_NAME L"OfficeAssistant" //英文名(宽字符)
#define ADD_AUTOSTART 1
#define ADD_SHORTCUT 2
#define VERSION "1.0.0" //软件版本
#define RELEASE "20230801" //Release
#endif //OFFICEASSISTANT_CONFIG_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

Binary file not shown.

View File

@ -24,12 +24,17 @@ MainScreen::MainScreen(QWidget *parent) :
button = new QPushButton(widget);
layout_left->addStretch(4);
layout_left->addWidget(button,1);
layout_left->setAlignment(Qt::AlignCenter);
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
button->setMinimumSize(100,50);
button->setMaximumSize(200,100);
widget->setLayout(layout_left);
widget->setHidden(true);
button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#09bb07");
button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#09bb07;color:white;font-family:SimHei");
//Plus Math icon by Icons8
QString dir = QApplication::applicationDirPath();
button->setText(QString::fromLocal8Bit("´ò¿ªÎ¢ÐÅ"));
//button->setStyleSheet("text-color:white");
layout = new QHBoxLayout;
miniblink = new QMiniBlink(this);
layout->addWidget(widget, 1);

View File

@ -6,23 +6,27 @@
#include "mainwindow.h"
#include "ui_MainWindow.h"
#include "config.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskRect = desktopWidget->availableGeometry();
//delete desktopWidget;
resize(deskRect.width()*0.8, deskRect.height()*0.8);
setWindowState(Qt::WindowMaximized);
mainWindowLayout=new MainWindowLayout(this);
setCentralWidget(mainWindowLayout);
setWindowState(Qt::WindowMaximized);
setWindowTitle(QString::fromLocal8Bit(NAME));
QString path = QApplication::applicationDirPath();
path += LOGO_TITLEBAR;
icon = new QIcon(path);
setWindowIcon(*icon);
}
MainWindow::~MainWindow() {
delete icon;
this->setCentralWidget(nullptr);
delete mainWindowLayout;
delete ui;

View File

@ -8,6 +8,8 @@
#include <QMainWindow>
#include <QVBoxLayout>
#include "mainwindowlayout.h"
#include <QIcon>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
@ -22,6 +24,7 @@ public:
private:
Ui::MainWindow *ui;
QIcon *icon;
QVBoxLayout *layout;
MainWindowLayout *mainWindowLayout;
};

View File

@ -11,6 +11,7 @@
MainWindowLayout::MainWindowLayout(QWidget *parent) :
QWidget(parent), ui(new Ui::MainWindowLayout) {
ui->setupUi(this);
setContentsMargins(0, 0, 0, 0);
layout=new QVBoxLayout(this);
mainWindowLayout = this;
ConfigRequest *configRequest = new ConfigRequest;
@ -18,13 +19,17 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
configRequest->sendRequest(configResponse);
mainScreen = new MainScreen(this);
navBar=new NavBar(configResponse,mainScreen,this);
navBar->setAttribute(Qt::WA_DeleteOnClose);
navBar->setMinimumHeight(0);
navBar->setMaximumHeight(this->height() / 8);
mainScreen->setMinimumHeight(0);
//navBar->setAttribute(Qt::WA_DeleteOnClose);
delete configRequest;
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
//navBar->setSizePolicy(sizePolicy);
layout->setMargin(0);
//layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(navBar,1);
layout->addWidget(mainScreen,7);
layout->setMargin(0);
setLayout(layout);
connect(this,&MainWindowLayout::clickButton1,mainScreen,&MainScreen::clickButton1);
}
@ -42,7 +47,7 @@ MainWindowLayout::~MainWindowLayout() {
void MainWindowLayout::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
navBar->resize(navBar->width(),height()/8);
navBar->setMaximumHeight(event->size().height()/8);
//layout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
}

View File

@ -2,11 +2,13 @@
#include <Windows.h>
#include <QClipBoard>
#include "netio.h"
#include "config.h"
#include "globalvariables.h"
MySettingsDialog::MySettingsDialog(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
setWindowFlags(Qt::WindowCloseButtonHint);
this->setFixedSize(width(), height());
HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
@ -19,10 +21,10 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
}
QString app = QApplication::applicationFilePath();
app.replace("/", "\\");
DWORD size=128;
wchar_t reg[128];
lRet = RegGetValue(hRoot, szSubKey, L"OfficeAssistant", RRF_RT_ANY, nullptr, reg, &size);
if (wcscmp(reg,app.toStdWString().c_str())==0) {
DWORD size=128+sizeof(wchar_t);
char reg[128] = { 0 };
lRet = RegQueryValueEx(hKey, L"OfficeAssistant", NULL, NULL,(LPBYTE)reg, &size);
if (lRet==0) {
ui.autostart->setChecked(true);
}
copyButton = ui.copy;
@ -31,6 +33,7 @@ MySettingsDialog::MySettingsDialog(QWidget *parent)
connect(ui.addshortcut, &QPushButton::clicked, this, &MySettingsDialog::createShortcut);
connect(ui.law_button, &QPushButton::clicked, this, &MySettingsDialog::law);
ui.code->setText(QString(QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex()));
ui.version->setText(QString(VERSION) + "-" + QString(RELEASE));
}
MySettingsDialog::~MySettingsDialog()
@ -53,7 +56,7 @@ void MySettingsDialog::autoStart(int state)
QString app = QApplication::applicationFilePath();
app.replace("/", "\\");
qDebug() << app.toStdWString().c_str();
lRet = RegSetValueEx(hKey, L"OfficeAssistant", 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
lRet = RegSetValueEx(hKey, LENG_NAME, 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length()*sizeof(wchar_t));
if (lRet == ERROR_SUCCESS)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
@ -72,7 +75,7 @@ void MySettingsDialog::autoStart(int state)
return;
}
QString app = QApplication::applicationFilePath();
lRet = RegDeleteValue(hKey, L"OfficeAssistant");
lRet = RegDeleteValue(hKey, LENG_NAME);
if (lRet == ERROR_SUCCESS)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功。"));
@ -95,7 +98,9 @@ void MySettingsDialog::copyToCLipboard() {
}
void MySettingsDialog::createShortcut() {
QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
deskTopPath = deskTopPath + QString::fromLocal8Bit("/°ì¹«ÖúÊÖ.lnk");
deskTopPath = deskTopPath + QString::fromLocal8Bit("/");
deskTopPath = deskTopPath + QString::fromLocal8Bit(NAME);
deskTopPath = deskTopPath + QString::fromLocal8Bit(".lnk");
QString srcFile = QApplication::applicationFilePath();
bool succeed=QFile::link(srcFile, deskTopPath);
if (succeed) {

View File

@ -26,12 +26,51 @@
<property name="geometry">
<rect>
<x>70</x>
<y>70</y>
<y>40</y>
<width>581</width>
<height>381</height>
<height>461</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>版本信息</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>108</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>版本号</string>
</property>
</widget>
<widget class="QLabel" name="version">
<property name="geometry">
<rect>
<x>130</x>
<y>50</y>
<width>261</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="hardware">
<property name="sizePolicy">
@ -151,6 +190,8 @@
</item>
</layout>
</widget>
<zorder>gridLayoutWidget</zorder>
<zorder>hardware</zorder>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>

View File

@ -9,6 +9,7 @@
#include "config.h"
#include <QTimer>
#include <QtSvg/QtSvg>
#include <QPixmap>
#include "mainwindowlayout.h"
#include "globalvariables.h"
#ifdef _DEBUG
@ -20,30 +21,50 @@ QString url_param;
NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this);
this->setAttribute(Qt::WA_DeleteOnClose);
//this->setAttribute(Qt::WA_DeleteOnClose);
buffer = new QByteArray;
/*QString style = "background-color:";
style += configResponse->basic.backgroud_color.toUpper();
style += ";";
setStyleSheet(style);*/
//setStyleSheet("margin:0");
setContentsMargins(0, 0, 0, 0);
if (configResponse->succeed&&configResponse->menus.empty()!=true) {
getLogoFromInternet(configResponse);
}
else {
getLogoFromLocal();
}
this->setLayout(nullptr);
int n = buttonStructs.length();
int x = (width() - height()*n) / 2;
layout2 = new QHBoxLayout;
layout_right = new QHBoxLayout;
layout_left = new QHBoxLayout;
logo_label = new QLabel(this);
//*logo = logo->scaled(this->width() / (5 / scale), this->height());
logo_label->setScaledContents(true);
logo_label->setPixmap(QPixmap::fromImage(*logo));
logo_label->setMaximumHeight(parent->height() / 8);
layout_left->addWidget(logo_label);
layout_left->setAlignment(Qt::AlignCenter);
for (auto buttonStruct : buttonStructs) {
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this);
myButton->setGeometry(x, 0, height(), height());
myButton->show();
myButton->setMaximumHeight(parent->height() / 8);
layout_right->addWidget(myButton);
//myButton->show();
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
x += height();
buttons << myButton;
}
layout_right->setAlignment(Qt::AlignLeft);
if (!buttonStructs.empty()) {
connect(this, &NavBar::firstUrl, mainScreen, &MainScreen::firstUrl);
emit firstUrl(buttonStructs[0].url);
}
layout2->addLayout(layout_left, 1);
layout2->addLayout(layout_right, 4);
layout_right->setMargin(0);
layout2->setMargin(0);
//layout2->setAlignment(Qt::AlignJustify);
this->setLayout(layout2);
logo_label->show();
}
NavBar::~NavBar() {
@ -52,8 +73,15 @@ NavBar::~NavBar() {
delete buttonStruct.image_cover;
}
for(auto button : buttons){
layout_right->removeWidget(button);
delete button;
}
layout2->removeWidget(logo_label);
delete logo_label;
delete logo;
//delete layout_left;
delete layout_right;
delete layout2;
delete ui;
}
@ -66,20 +94,14 @@ void NavBar::paintEvent(QPaintEvent *event) {
QRectF rect(0, 0, this->width(), this->height());
painter.fillRect(rect, qColor);
QRectF rect2(0, 0, this->width()/5, this->height());
painter.drawImage(rect2, *logo);
}
void NavBar::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
int n = buttonStructs.length();
int x = (width() - height()*n) / 2;
for(auto button:buttons){
button->setSize(event->size().height(),event->size().height(),event->size().height(),event->size().height());
button->setGeometry(x, 0, event->size().height(), event->size().height());
x += event->size().height();
button->setMaximumSize(event->size().height(), event->size().height());
button->update();
}
logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
}
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
qColor.setNamedColor(configResponse->basic.backgroud_color);
@ -98,10 +120,8 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
delete request_logo;
if (downloadSuccess == true) {
*buffer = reply->readAll();
QSvgRenderer *render_logo = new QSvgRenderer(*buffer);
logo = new QImage(400, 200, QImage::Format_ARGB32);
QPainter painter_logo(logo);
render_logo->render(&painter_logo);
logo = new QImage();
logo->loadFromData(*buffer);
buffer->clear();
for (auto button : configResponse->menus) {
QUrl url_image(button.img);

View File

@ -16,6 +16,7 @@
#include "buttonstruct.h"
#include <QtNetwork/QtNetwork>
#include "mainscreen.h"
#include <QImage>
#include "mainwindowlayout.h"
@ -49,10 +50,14 @@ private:
QNetworkReply *reply;
QEventLoop eventLoop;
QImage *logo;
QLabel *logo_label;
bool downloadSuccess=true;
void getLogoFromInternet(ConfigResponse *configResponse);
void getLogoFromLocal();
MainScreen *mainScreen;
QHBoxLayout *layout_left;
QHBoxLayout *layout_right;
QHBoxLayout *layout2;
private slots:
void storeToBuffer();
void cancelDownload();

View File

@ -65,11 +65,6 @@ RequestBodyBase::RequestBodyBase(){
exit(1);
}
parter_id=obj_root.value("parter_id").toString();
if(obj_root.value("release")==QJsonValue::Undefined){
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
exit(1);
}
release=obj_root.value("release").toString();
}else{
//处理错误
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
@ -107,6 +102,8 @@ RequestBodyBase::RequestBodyBase(){
default:
os_version="Unknown";
}
this->release = RELEASE;
this->version = VERSION;
//读取MachineGUID并取MD5作为device_id
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
device_id = hash.toHex();
@ -114,6 +111,10 @@ RequestBodyBase::RequestBodyBase(){
QJsonValue value = device_id;
QJsonObject obj_root = qJsonDocument.object();
obj_root.insert("device_id", value);
QJsonValue version_json = this->version;
obj_root.insert("version", version_json);
QJsonValue release_json = this->release;
obj_root.insert("release", release_json);
qJsonDocument.setObject(obj_root);
QJsonValue os_json(this->os);
QJsonValue os_version_json(this->os_version);

View File

@ -15,7 +15,7 @@ void QMiniBlink::init() {
ui.setupUi(this);
wkeInit();
RECT rect;
GetWindowRect((HWND)this->winId(), &rect);
GetWindowRect((HWND)parent->winId(), &rect);
resize(rect.right - rect.left, rect.bottom - rect.top);
this->wkeView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, rect.right - rect.left, rect.bottom - rect.top);

Binary file not shown.

BIN
icon/logo_navbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
icon/wechat.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB