第一阶段初稿+修复部分内容

master
Mike Solar 2023-07-31 19:06:37 +08:00
parent e3c650dbfd
commit 57aea93735
38 changed files with 659 additions and 103 deletions

3
.gitignore vendored
View File

@ -14,4 +14,5 @@ OfficeAssistant_msvc.sdf
startcalc/Debug/
startcalc/Release/
wxdk/Debug/
wxdk/Release/
wxdk/Release/
officeassistant-cppcheck-build-dir/

Binary file not shown.

View File

@ -23,7 +23,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
@ -101,6 +101,9 @@
<ClInclude Include="config.h" />
<ClInclude Include="globalvariables.h" />
<QtMoc Include="qminiblink.h" />
<QtMoc Include="settingsscreen.h" />
<QtMoc Include="switchbutton.h" />
<QtMoc Include="mythread.h" />
<ClInclude Include="wke.h" />
<QtMoc Include="mainwindowlayout.h" />
<QtMoc Include="mainwindow.h" />
@ -115,9 +118,12 @@
<ClCompile Include="mainwindow.cpp" />
<ClCompile Include="mainwindowlayout.cpp" />
<ClCompile Include="MyButton.cpp" />
<ClCompile Include="mythread.cpp" />
<ClCompile Include="navbar.cpp" />
<ClCompile Include="netio.cpp" />
<ClCompile Include="qminiblink.cpp" />
<ClCompile Include="settingsscreen.cpp" />
<ClCompile Include="switchbutton.cpp" />
</ItemGroup>
<ItemGroup>
<QtUic Include="mainscreen.ui" />
@ -125,6 +131,9 @@
<QtUic Include="mainwindowlayout.ui" />
<QtUic Include="navbar.ui" />
<QtUic Include="qminiblink.ui" />
<QtUic Include="qtwidgetsclass.ui" />
<QtUic Include="settingsscreen.ui" />
<QtUic Include="switchbutton.ui" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">

View File

@ -17,7 +17,7 @@
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
<Extensions>ui</Extensions>
</Filter>
<Filter Include="Translation Files">
<Filter Include="Source Files\Translation Files">
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
<Extensions>ts</Extensions>
</Filter>
@ -63,6 +63,15 @@
<QtMoc Include="qminiblink.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="settingsscreen.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="switchbutton.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="mythread.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@ -89,6 +98,15 @@
<ClCompile Include="qminiblink.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="settingsscreen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="switchbutton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mythread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtUic Include="navbar.ui">
@ -103,6 +121,15 @@
<QtUic Include="mainwindowlayout.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="settingsscreen.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="qtwidgetsclass.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="switchbutton.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="qminiblink.ui">
<Filter>Form Files</Filter>
</QtUic>

View File

@ -5,9 +5,9 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<QtLastBackgroundBuild>2023-07-30T09:15:49.0117730Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-07-30T18:20:21.4819233Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<QtLastBackgroundBuild>2023-07-30T09:15:57.3451755Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-07-30T18:20:22.3001457Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -9,4 +9,7 @@
#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 ADD_AUTOSTART 1
#define ADD_SHORTCUT 2
#endif //OFFICEASSISTANT_CONFIG_H

View File

@ -10,65 +10,93 @@
#include <QPixmap>
#include <exception>
#include <QResizeEvent>
#include "globalvariables.h"
#include "settingsscreen.h"
#include "mythread.h"
MainScreen::MainScreen(QWidget *parent) :
QWidget(parent), ui(new Ui::MainScreen) {
ui->setupUi(this);
broswer = new QWidget(this);
setContentsMargins(0, 0, 0, 0);
button = new QPushButton(this);
button->setHidden(true);
button->setStyleSheet("border-style:none;padding:10px;border-radius:5px;background-color:#FFFFFF");
//Plus Math icon by Icons8
QString dir = QApplication::applicationDirPath();
icon = new QIcon(dir + "/images/add.png");
icon = new QIcon(dir + QString::fromLocal8Bit("/images/add.png"));
button->setIcon(*icon);
layout = new QHBoxLayout;
layout->addWidget(broswer,4);
QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
button->setSizePolicy(sizePolicy);
miniblink = new QMiniBlink(this);
settingScreen = new SettingsScreen;
settingScreen->setHidden(true);
layout->addWidget(button, 1);
layout->addWidget(miniblink, 4);
layout->addWidget(settingScreen);
this->setLayout(layout);
//QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
//broswer->setSizePolicy(sizePolicy);
miniblink = new QMiniBlink(broswer,this);
layout->setMargin(0);
//miniblink->setAttribute(Qt::WA_DeleteOnClose);
miniblink->show();
//miniblink->setSizePolicy(sizePolicy);
thread = new QThread;
miniblink->moveToThread(thread);
connect(thread, &QThread::started, miniblink, &QMiniBlink::init);
connect(thread, &QThread::finished, thread, &QThread::deleteLater);
connect(this, &MainScreen::destroy, miniblink, &QMiniBlink::destroy);
//thread = new MyThread(this,&miniblink);
//thread->start();
//miniblink->moveToThread(thread);
connect(this, &MainScreen::ondestroy, miniblink, &QMiniBlink::ondestroy);
connect(button, &QPushButton::pressed, this, &MainScreen::startWeChat);
connect(this, &MainScreen::started, miniblink, &QMiniBlink::init);
//connect(miniblink, SIGNAL(finish()), miniblink, SLOT(deleteLater()));
//connect(miniblink, SIGNAL(destroyed()), thread, SLOT(quit()));
//connect(thread, &QThread::finished, thread, &QThread::deleteLater);
while(miniblink==nullptr){}
connect(this, &MainScreen::changeUrl, miniblink, &QMiniBlink::switchUrl);
thread->start();
emit started();
}
MainScreen::~MainScreen() {
emit ondestroy();
layout->removeWidget(miniblink);
layout->removeWidget(settingScreen);
layout->removeWidget(button);
button->setIcon(QIcon(nullptr));
delete miniblink;
delete settingScreen;
delete button;
delete icon;
delete layout;
delete ui;
}
void MainScreen::firstUrl(QString url)
{
emit changeUrl(url);
}
void MainScreen::clickButton1(QString text, QString url) {
if (text == QString::fromLocal8Bit("΢ÐŶ࿪")) {
button->setHidden(false);
connect(button, &QPushButton::click, this, &MainScreen::startWeChat);
if (button->layout() == nullptr) {
layout->insertWidget(1, button);
}
if (broswer->layout() == nullptr) {
layout->addWidget(broswer, 4);
}
miniblink->setHidden(false);
settingScreen->setHidden(true);
emit changeUrl(url);
}
else if (text == QString::fromLocal8Bit("Èí¼þÉèÖÃ")){
miniblink->setHidden(true);
button->setHidden(true);
settingScreen->setHidden(false);
}
else {
if (button->layout() != nullptr) {
layout->removeWidget(button);
button->setHidden(true);
}
button->setHidden(true);
miniblink->setHidden(false);
settingScreen->setHidden(true);
emit changeUrl(url);
}
}
void MainScreen::startWeChat() {
QString path = QApplication::applicationDirPath();
QString exe = path + "/wxdk.exe";
ShellExecute(GetDesktopWindow(), L"open", exe.toStdWString().c_str(), L"", path.toStdWString().c_str(), SW_SHOW);
ShellExecute(GetDesktopWindow(), L"open", exe.toStdWString().c_str(), L"79c86fb12b36dfa33d1a537c9af100b4c7928a9c", path.toStdWString().c_str(), SW_SHOW);
}
//void MainScreen::resizeEvent(QResizeEvent *event) {
// QWidget::resizeEvent(event);

View File

@ -11,7 +11,8 @@
#include <QPushButton>
#include "wke.h"
#include "qminiblink.h"
#include "settingsscreen.h"
class MyThread;
QT_BEGIN_NAMESPACE
namespace Ui { class MainScreen; }
QT_END_NAMESPACE
@ -19,13 +20,16 @@ QT_END_NAMESPACE
class MainScreen : public QWidget {
Q_OBJECT
signals:
void destroy();
void started();
void ondestroy();
void changeUrl(QString url);
void initMiniBlink();
public:
explicit MainScreen(QWidget *parent = nullptr);
~MainScreen() override;
public slots:
void clickButton1(QString text, QString url);
void firstUrl(QString url);
protected:
//void resizeEvent(QResizeEvent *event) override;
private:
@ -36,11 +40,12 @@ private:
QIcon *icon;
QWidget *broswer;
static bool isInited();
QThread *thread;
MyThread *thread;
QMiniBlink *miniblink;
SettingsScreen *settingScreen;
private slots:
void startWeChat();
};

View File

@ -17,18 +17,13 @@ MainWindow::MainWindow(QWidget *parent) :
//delete desktopWidget;
mainWindowLayout=new MainWindowLayout(this);
setCentralWidget(mainWindowLayout);
if(deskRect.width()*scale>1920){
resize(1600,1080);
//this->setMaximumWidth(1600);
}else{
resize(800, 540);
//this->setMaximumWidth(800);
}
setWindowState(Qt::WindowMaximized);
}
MainWindow::~MainWindow() {
this->setCentralWidget(nullptr);
delete mainWindowLayout;
delete ui;
}

View File

@ -13,23 +13,29 @@ MainWindowLayout::MainWindowLayout(QWidget *parent) :
layout=new QVBoxLayout(this);
mainWindowLayout = this;
ConfigRequest *configRequest = new ConfigRequest;
ConfigResponse *configResponse = new ConfigResponse;
configResponse = new ConfigResponse;
configRequest->sendRequest(configResponse);
navBar=new NavBar(configResponse,this);
mainScreen=new MainScreen();
mainScreen = new MainScreen(this);
navBar=new NavBar(configResponse,mainScreen,this);
navBar->setAttribute(Qt::WA_DeleteOnClose);
delete configRequest;
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
//navBar->setSizePolicy(sizePolicy);
layout->setMargin(0);
layout->addWidget(navBar,1);
layout->addWidget(mainScreen,7);
setLayout(layout);
connect(this, &MainWindowLayout::clickButton1, mainScreen, &MainScreen::clickButton1);
connect(this,&MainWindowLayout::clickButton1,mainScreen,&MainScreen::clickButton1);
}
MainWindowLayout::~MainWindowLayout() {
delete configResponse;
layout->removeWidget(mainScreen);
layout->removeWidget(navBar);
delete mainScreen;
//delete[] list[0];
delete navBar;
//delete layout;
delete layout;
delete ui;
}

View File

@ -37,6 +37,7 @@ private:
NavBar *navBar;
ButtonStruct *buttons;
MainScreen *mainScreen;
ConfigResponse *configResponse;
};

View File

@ -0,0 +1,25 @@
#include "mythread.h"
#include "qminiblink.h"
#include "mainscreen.h"
MyThread::MyThread(MainScreen * mainScreen, QMiniBlink *(*miniblink),QObject *parent)
: QThread(parent)
{
this->mainScreen = mainScreen;
this->miniblink = miniblink;
}
MyThread::~MyThread()
{
}
void MyThread::run() {
*miniblink = new QMiniBlink(mainScreen);
(*miniblink)->init();
}
void MyThread::onstop() {
(*miniblink)->ondestroy();
delete miniblink;
}

View File

@ -0,0 +1,19 @@
#pragma once
class MainScreen;
#include <QThread>
#include "qminiblink.h"
class MyThread : public QThread
{
Q_OBJECT
public:
MyThread(MainScreen * mainScreen,QMiniBlink **miniblink,QObject *parent=nullptr);
MainScreen *mainScreen;
QMiniBlink *(*miniblink);
~MyThread();
protected:
void run() override;
public slots:
void onstop();
};

View File

@ -14,11 +14,12 @@
#ifdef _DEBUG
#pragma comment(lib, "Qt5Svgd.lib")
#else
#pragma comment(lib, "QtSvg.lib")
#pragma comment(lib, "Qt5Svg.lib")
#endif
NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) :
NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this);
this->setAttribute(Qt::WA_DeleteOnClose);
buffer = new QByteArray;
if (configResponse->succeed&&configResponse->menus.empty()!=true) {
getLogoFromInternet(configResponse);
@ -37,6 +38,10 @@ NavBar::NavBar(ConfigResponse *configResponse,QWidget *parent) :
x += height();
buttons << myButton;
}
if (!buttonStructs.empty()) {
connect(this, &NavBar::firstUrl, mainScreen, &MainScreen::firstUrl);
emit firstUrl(buttonStructs[0].url);
}
}
NavBar::~NavBar() {
@ -76,7 +81,7 @@ void NavBar::resizeEvent(QResizeEvent *event) {
}
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
qColor.setNamedColor(configResponse->basic.backgroud_color);
QUrl url_logo(QString(BASE_URL) + configResponse->basic.logo_url);
QUrl url_logo(configResponse->basic.logo_url);
QNetworkRequest *request_logo = new QNetworkRequest(url_logo);
manager = new QNetworkAccessManager;
reply = manager->get(*request_logo);
@ -84,24 +89,27 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
timer.setInterval(5000);
connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit);
connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload);
eventLoop.exec();
timer.stop();
buffer = new QByteArray;
delete request_logo;
if (downloadSuccess == true) {
*buffer = reply->readAll();
QSvgRenderer *render_logo = new QSvgRenderer(*buffer);
logo = new QImage(200, 200, QImage::Format_ARGB32);
logo = new QImage(400, 200, QImage::Format_ARGB32);
QPainter painter_logo(logo);
render_logo->render(&painter_logo);
buffer->clear();
for (auto button : configResponse->menus) {
QUrl url_image(QString(BASE_URL) + button.img);
QUrl url_image(button.img);
QNetworkRequest *request_image = new QNetworkRequest(url_image);
reply = manager->get(*request_image);
QTimer timer;
timer.setInterval(5000);
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload);
eventLoop.exec();
timer.stop();
if (!downloadSuccess) {
break;
}
@ -111,7 +119,7 @@ void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
QPainter painter_image(image);
render_image->render(&painter_image);
QUrl url_image_cover(QString(BASE_URL) + button.img_cover);
QUrl url_image_cover(button.img_cover);
QNetworkRequest *request_image_cover = new QNetworkRequest(url_image_cover);
reply = manager->get(*request_image_cover);
timer.setInterval(5000);

View File

@ -15,6 +15,7 @@
#include <QResizeEvent>
#include "buttonstruct.h"
#include <QtNetwork/QtNetwork>
#include "mainscreen.h"
#include "mainwindowlayout.h"
@ -24,9 +25,10 @@ QT_END_NAMESPACE
class NavBar : public QWidget {
Q_OBJECT
signals:
void firstUrl(QString url);
public:
NavBar(ConfigResponse *configResponse,QWidget *parent = nullptr);
NavBar(ConfigResponse *configResponse,MainScreen *mainScreen,QWidget *parent = nullptr);
~NavBar() override;
protected:
@ -38,6 +40,8 @@ protected:
private:
Ui::NavBar *ui;
QColor qColor;
QColor text_color;
QColor text_cover_color;
QList<MyButton *> buttons;
QList<ButtonStruct> buttonStructs;
QByteArray *buffer;
@ -50,6 +54,7 @@ private:
bool downloadSuccess=true;
void getLogoFromInternet(ConfigResponse *configResponse);
void getLogoFromLocal();
MainScreen *mainScreen;
private slots:
void storeToBuffer();
void cancelDownload();

View File

@ -30,17 +30,7 @@
#endif
#pragma comment(lib,"comsuppw.lib")
//读取注册表获取MachineUUID
inline QString getMachineGUID(){
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
0,KEY_READ | KEY_WOW64_64KEY, &hKey);
DWORD dwType1 = REG_SZ;
DWORD dwLen = MAX_PATH;
WCHAR buf[100];
RegQueryValueExA(hKey, "MachineGuid" ,0 ,&dwType1, (LPBYTE)buf, &dwLen);
QString guid=QString::fromWCharArray(buf);
return guid;
}
RequestBodyBase::RequestBodyBase(){
wchar_t unix_time[65]={0};
@ -182,7 +172,6 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
timer->stop();
//delete httpMgr;
QJsonDocument result;
configResponse=new ConfigResponse;
configResponse->succeed = false;
//memset(configResponse,0,sizeof(*configResponse));
auto error = reply->error();
@ -203,8 +192,16 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
if(result.isObject()){
QJsonObject obj_root=result.object();
QJsonArray array;
array = obj_root.value("menu").toArray();
array = obj_root.value("data").toObject().value("menu").toArray();
QJsonObject obj_basic = obj_root.value("basic").toObject();
configResponse->basic.logo_url = obj_basic.value("logo_url").toString();
configResponse->basic.device_id = obj_basic.value("device_id").toString();
configResponse->basic.dev_id = obj_basic.value("dev_id").toString();
configResponse->basic.token = obj_basic.value("token").toString();
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();
@ -217,6 +214,7 @@ void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
configResponse->menus << menu;
i++;
}
configResponse->succeed = true;
}else{
//数据不完整
configResponse->succeed=false;

View File

@ -98,6 +98,16 @@ class OpenMulitiWechat:public RequestBodyBase{
public:
OpenMulitiWechat(): RequestBodyBase(){}
};
inline QString getMachineGUID() {
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
0, KEY_READ | KEY_WOW64_64KEY, &hKey);
DWORD dwType1 = REG_SZ;
DWORD dwLen = MAX_PATH;
WCHAR buf[100];
RegQueryValueExA(hKey, "MachineGuid", 0, &dwType1, (LPBYTE)buf, &dwLen);
QString guid = QString::fromWCharArray(buf);
return guid;
}
#endif //OFFICEASSISTANT_NETIO_H

View File

@ -1,27 +1,43 @@
#include "qminiblink.h"
#include <QThread>
#include <QDebug>
#pragma comment (lib,"Comctl32.lib")
QMiniBlink::QMiniBlink(QWidget *broswer,QWidget *parent)
QMiniBlink::QMiniBlink(QWidget *parent)
: QWidget(parent){
this->broswer = broswer;
this->parent = parent;
wkeView = nullptr;
//QSizePolicy sizePolicy(QSizePolicy::Policy::Expanding, QSizePolicy::QSizePolicy::Expanding);
//setSizePolicy(sizePolicy);
}
void QMiniBlink::init() {
ui.setupUi(this);
wkeInit();
wkeView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)this->winId(), 0, 0, this->width(), this->height());
wkeSetNavigationToNewWindowEnable(wkeView, false);
wkeShowWindow(wkeView, TRUE);
SetParent(wkeGetWindowHandle(wkeView), (HWND)this->winId());
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
wkeRunMessageLoop();
}
QMiniBlink::~QMiniBlink(){}
void QMiniBlink::destroy() {
wkeDestroyWebView(wkeView);
}
RECT rect;
GetWindowRect((HWND)this->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);
wkeSetNavigationToNewWindowEnable(this->wkeView, false);
wkeShowWindow(this->wkeView, TRUE);
SetParent(wkeGetWindowHandle(this->wkeView), (HWND)this->winId());
wkeMoveWindow(this->wkeView, 0, 0, rect.right - rect.left, rect.bottom - rect.top);
//while(this->firstUrl.isEmpty()){}
//wkeLoadURL(this->wkeView, this->firstUrl.toStdString().c_str());
SetWindowSubclass((HWND)this->winId(), subClassProc, 0, (DWORD_PTR)this);
//wkeRunMessageLoop();
}
QMiniBlink::~QMiniBlink(){
qDebug() << "Destroyed";
}
void QMiniBlink::ondestroy() {
if (this->wkeView != nullptr) {
wkeDestroyWebView(wkeView);
qDebug() << "Destroyed";
}
wkeShutdown();
}
void QMiniBlink::switchUrl(QString url) {
wkeLoadURL(wkeView, url.toStdString().c_str());
}

View File

@ -11,16 +11,20 @@ class QMiniBlink : public QWidget
Q_OBJECT
public:
QMiniBlink(QWidget *broswer,QWidget *parent = Q_NULLPTR);
QMiniBlink(QWidget *parent = nullptr);
~QMiniBlink();
void init();
void destroy();
void autojustWebViewSize();
QString firstUrl;
public slots:
void ondestroy();
void switchUrl(QString url);
private:
Ui::QMiniBlink ui;
wkeWebView wkeView;
QWidget *broswer;
QWidget *parent;
int w;
int h;
static LRESULT CALLBACK subClassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
};

View File

@ -1,23 +1,20 @@
<UI version="4.0" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QMiniBlink</class>
<widget class="QWidget" name="QMiniBlink" >
<property name="objectName" >
<string notr="true">QMiniBlink</string>
</property>
<property name="geometry" >
<widget class="QWidget" name="QMiniBlink">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<x>0</x>
<y>0</y>
<width>1142</width>
<height>806</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>QMiniBlink</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</UI>
</ui>

View File

@ -0,0 +1,23 @@
<UI version="4.0" >
<class>QtWidgetsClass</class>
<widget class="QWidget" name="QtWidgetsClass" >
<property name="objectName" >
<string notr="true">QtWidgetsClass</string>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>QtWidgetsClass</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</UI>

View File

@ -0,0 +1,56 @@
#include "settingsscreen.h"
#include "config.h"
#include <QCryptographicHash>
#include "netio.h"
SettingsScreen::SettingsScreen(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
autoStart = new SwitchButton(ADD_AUTOSTART,this);
addDesktopLink = new QPushButton(this);
addDesktopLink->setText(QString::fromLocal8Bit("创建桌面快捷方式"));
connect(addDesktopLink, &QPushButton::pressed, this, &SettingsScreen::createShortCut);
layout = new QHBoxLayout(this);
left = new QVBoxLayout(this);
addDesktopLink_label = new QLabel(QString::fromLocal8Bit("添加桌面快捷方式"),this);
autoStart_label = new QLabel(QString::fromLocal8Bit("开机启动"),this);
autoStart->setMaximumSize(100, 50);
autoStart->setMinimumSize(50, 25);
left->addWidget(autoStart_label);
left->addWidget(autoStart);
left->addWidget(addDesktopLink_label);
left->addWidget(addDesktopLink);
left->setAlignment(Qt::AlignCenter);
left->setMargin(0);
layout->addLayout(left);
information = new QLabel;
QString device_id = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex();
QString inf_str = QString::fromLocal8Bit("硬件ID:\n");
inf_str += device_id;
information->setText(inf_str);
layout->addWidget(information);
}
void SettingsScreen::createShortCut() {
QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
deskTopPath = deskTopPath + QString::fromLocal8Bit("/办公助手.lnk");
QString srcFile = QApplication::applicationFilePath();
QFile::link(srcFile, deskTopPath);
}
SettingsScreen::~SettingsScreen()
{
left->removeWidget(autoStart);
left->removeWidget(addDesktopLink);
left->removeWidget(addDesktopLink_label);
left->removeWidget(autoStart_label);
delete autoStart;
delete addDesktopLink;
delete addDesktopLink_label;
delete autoStart_label;
layout->removeItem(left);
delete left;
layout->removeWidget(information);
delete information;
delete layout;
}

View File

@ -0,0 +1,31 @@
#pragma once
#include <QWidget>
#include <QHBoxLayout>
#include <QVboxLayout>
#include <QPushButton>
#include <QLabel>
#include "ui_settingsscreen.h"
#include "switchbutton.h"
class SettingsScreen : public QWidget
{
Q_OBJECT
public:
SettingsScreen(QWidget *parent = Q_NULLPTR);
~SettingsScreen();
private:
Ui::SettingsScreen ui;
QLabel *autoStart_label;
QLabel *addDesktopLink_label;
QPushButton *addDesktopLink;
SwitchButton *autoStart;
QHBoxLayout *layout;
QVBoxLayout *left;
QLabel *information;
private slots:
void createShortCut();
};

View File

@ -0,0 +1,23 @@
<UI version="4.0" >
<class>SettingsScreen</class>
<widget class="QWidget" name="SettingsScreen" >
<property name="objectName" >
<string notr="true">SettingsScreen</string>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>SettingsScreen</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</UI>

View File

@ -0,0 +1,188 @@
#include "switchbutton.h"
#include "config.h"
#include <Windows.h>
#include <QMessageBox>
#include <QFile>
SwitchButton::SwitchButton(int action,QWidget *parent=nullptr)
: QWidget(parent)
{
ui.setupUi(this);
checked = false;
this->action = action;
//开、闭时背景颜色
bgColorOff = QColor(225, 225, 225);
bgColorOn = QColor(250, 250, 250);
//开、闭时滑块颜色
sliderColorOff = QColor(100, 100, 100);
sliderColorOn = QColor(100, 184, 255);
space = 2; //背景间隔
rectRadius = 5;
step = width() / 50; //步长
//起始、目标位置
startX = 0;
endX = 0;
timer = new QTimer(this);
timer->setInterval(10);
connect(timer, &QTimer::timeout, this, &SwitchButton::updateValue);
}
void SwitchButton::updateValue()
{
if (checked) {
if (startX < endX) {
startX = startX + step;
}
else {
startX = endX;
timer->stop();
}
}
else {
if (startX > endX) {
startX = startX - step;
}
else {
startX = endX;
timer->stop();
}
}
update();
}
void SwitchButton::mousePressEvent(QMouseEvent *event)
{
QWidget::mousePressEvent(event);
checked = !checked;
if (action == ADD_AUTOSTART) {
if (checked == true) {
HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项失败"));
return;
}
QString app = QApplication::applicationFilePath();
lRet = RegSetValueEx(hKey, L"SelfRun", 0, REG_SZ, (BYTE*)app.toStdWString().c_str(), app.length());
if (lRet == ERROR_SUCCESS)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("创建开机启动项成功"));
}
RegCloseKey(hKey);
}
else {
HKEY hRoot = HKEY_CURRENT_USER;
wchar_t *szSubKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hKey;
DWORD dwDisposition = REG_OPENED_EXISTING_KEY; // 如果不存在不创建
LONG lRet = RegCreateKeyEx(hRoot, szSubKey, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition);
if (lRet != ERROR_SUCCESS) {
QMessageBox::critical(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项失败"));
return;
}
QString app = QApplication::applicationFilePath();
lRet = RegDeleteValue(hKey, L"SelfRun");
if (lRet == ERROR_SUCCESS)
{
QMessageBox::information(this, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("移除开机启动项成功"));
}
RegCloseKey(hKey);
}
}
//每次移动的步长为宽度的 50分之一
step = width() / 50;
//状态切换改变后自动计算终点坐标
if (checked)
{
endX = width() - width() / 2;
}
else
{
endX = 0;
}
timer->start();
}
void SwitchButton::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
//每次移动的步长为宽度的 50分之一
step = width() / 50;
//尺寸大小改变后自动设置起点坐标为终点
if (checked)
{
startX = width() - width() / 2;
}
else
{
startX = 0;
}
update();
}
void SwitchButton::paintEvent(QPaintEvent *event)
{
QWidget::paintEvent(event);
//绘制准备工作,启用反锯齿
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
//绘制背景
drawBg(&painter);
//绘制滑块
drawSlider(&painter);
}
void SwitchButton::drawBg(QPainter *painter)
{
painter->save();
painter->setPen(Qt::NoPen);
if (!checked)
{
painter->setBrush(bgColorOff);
}
else
{
painter->setBrush(bgColorOn);
}
painter->drawRoundedRect(rect(), rectRadius, rectRadius);
painter->restore();
}
void SwitchButton::drawSlider(QPainter *painter)
{
painter->save();
painter->setPen(Qt::NoPen);
if (!checked) {
painter->setBrush(sliderColorOff);
}
else {
painter->setBrush(sliderColorOn);
}
int sliderWidth = width() / 2 - space * 2;
int sliderHeight = height() - space * 2;
QRect sliderRect(startX + space, space, sliderWidth, sliderHeight);
painter->drawRoundedRect(sliderRect, rectRadius, rectRadius);
painter->restore();
}
SwitchButton::~SwitchButton()
{
}

View File

@ -0,0 +1,41 @@
#pragma once
#include <QWidget>
#include <QPainter>
#include <QTimer>
#include "ui_switchbutton.h"
class SwitchButton : public QWidget
{
Q_OBJECT
public:
SwitchButton(int action, QWidget * parent);
~SwitchButton();
private:
int action;
Ui::SwitchButton ui;
bool checked;
QColor bgColorOff;
QColor bgColorOn;
QColor sliderColorOff;
QColor sliderColorOn;
int space;
int rectRadius;
int step;
int startX;
int endX;
QTimer *timer;
void updateValue();
void drawBg(QPainter * painter);
void drawSlider(QPainter * painter);
protected:
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void mousePressEvent(QMouseEvent *);
};

View File

@ -0,0 +1,23 @@
<UI version="4.0" >
<class>SwitchButton</class>
<widget class="QWidget" name="SwitchButton" >
<property name="objectName" >
<string notr="true">SwitchButton</string>
</property>
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>SwitchButton</string>
</property>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</UI>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

14
officeassistant.cppcheck Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>officeassistant-cppcheck-build-dir</builddir>
<importproject>OfficeAssistant_msvc.sln</importproject>
<analyze-all-vs-configs>true</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>true</check-unused-templates>
<max-ctu-depth>2</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<vs-configurations>
<config>Debug</config>
<config>Release</config>
</vs-configurations>
</project>

View File

@ -34,7 +34,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>

View File

@ -34,7 +34,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>