换完IDE了

This commit is contained in:
Mike Solar
2023-07-29 07:23:38 +08:00
parent c9db35e414
commit b9559e444b
38 changed files with 264 additions and 56 deletions

View File

@ -0,0 +1,72 @@
//
// Created by HW on 2023/07/26.
//
#define TEXT_SIZE 7
#include "MyButton.h"
MyButton::MyButton(QString logo,QString text,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) {
this->buttons=buttons;
this->width2=width;
this->height2=height;
this->text=text;
this->logo=new QImage;
this->logo->load(logo);
this->setStyleSheet("background-color:#333332;/*border:none;*/");
}
MyButton::~MyButton() {
delete logo;
}
void MyButton::paintEvent(QPaintEvent *e) {
QPushButton::paintEvent(e);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int logo_width=width()/3;
int logo_x=width()/3;
int logo_y=(height()-logo_width)/3;
setContentsMargins(0,0,0,0);
QFont ft;
ft.setPixelSize(TEXT_SIZE);
int text_x=(width()-TEXT_SIZE*text.length()*scale*2)/2;
int text_y=(logo_width+logo_y+10);
QRectF logo_rect(logo_x, logo_y, logo_width, logo_width);
QRectF text_rect(text_x,text_y, TEXT_SIZE*text.length()*scale*2,TEXT_SIZE*scale*2);
painter.setPen(QColor("#FFFFFF"));
painter.drawImage(logo_rect, *logo);
painter.drawText(text_rect, Qt::AlignCenter, text);
if(checked){
QRectF rect(0, this->height()-6, this->width(), 5);
painter.fillRect(rect, QColor("#FFFFFF"));
}
}
QSize MyButton::sizeHint() const {
return QSize(width2,height2);
}
void MyButton::enterEvent(QEvent *event) {
QWidget::enterEvent(event);
this->setStyleSheet("background-color:#646464;border:none;");
}
void MyButton::leaveEvent(QEvent *event) {
QWidget::leaveEvent(event);
this->setStyleSheet("background-color:#333332;border:none;");
}
void MyButton::mousePressEvent(QMouseEvent *event) {
QPushButton::mousePressEvent(event);
}
void MyButton::mouseReleaseEvent(QMouseEvent *event) {
QPushButton::mouseReleaseEvent(event);
for(auto button:*buttons){
button->setChecked(false);
button->update();
}
if(checked)
checked=false;
else
checked=true;
}

View File

@ -0,0 +1,63 @@
//
// Created by HW on 2023/07/26.
//
#ifndef OFFICEASSISTANT_MYBUTTON_H
#define OFFICEASSISTANT_MYBUTTON_H
#include <QPushButton>
#include <QPaintEvent>
#include <QtSvg/QtSvg>
#include <QtSvg/QSvgWidget>
#include <QtSvg/QSvgRenderer>
#include "globalvariables.h"
class MyButton: public QPushButton{
public:
MyButton(QString logo,QString text,int width,int height,QList<MyButton *> *buttons,QWidget *parent=nullptr);
~MyButton() override;
QString getText(){
return text;
}
QSize sizeHint() const override;
void setChecked(bool checked){
this->checked=checked;
}
QSize getLogicalSize() const {
if(scale>=1.25){
return QSize(width2,height2);
}
else{
return QSize(width2,height2);
};
}
void setSize(int width,int height,int logicalwidth,int logicalheight){
this->width2=width;
this->height2=height;
this->logicalwidth=logicalwidth;
this->logicalheight=logicalheight;
}
protected:
void paintEvent(QPaintEvent *e) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
QList<MyButton *> *buttons;
QImage *logo;
QLabel *logo_label;
QLabel *text_label;
QVBoxLayout *layout;
QPixmap* logo_pixmap;
QString text;
int width2;
int height2;
int logicalwidth;
int logicalheight;
bool checked=false;
};
#endif //OFFICEASSISTANT_MYBUTTON_H

View File

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

View File

@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{A49230DF-A869-4AA1-8ACA-3C7322530E46}</ProjectGuid>
<Keyword>QtVS_v304</Keyword>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140_xp</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="QtSettings">
<QtInstall>5.6.3_msvc2015</QtInstall>
<QtModules>core;gui;widgets;network</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="QtSettings">
<QtInstall>5.6.3_msvc2015</QtInstall>
<QtModules>core;gui;widgets</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
</Target>
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'">
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'">
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Win32'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
<ClCompile>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DebugInformationFormat>None</DebugInformationFormat>
<Optimization>MaxSpeed</Optimization>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<QtRcc Include="OfficeAssistant_msvc.qrc" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="buttonstruct.h" />
<ClInclude Include="config.h" />
<ClInclude Include="globalvariables.h" />
<QtMoc Include="mainwindowlayout.h" />
<QtMoc Include="mainwindow.h" />
<QtMoc Include="mainscreen.h" />
<ClInclude Include="MyButton.h" />
<ClInclude Include="netio.h" />
<QtMoc Include="navbar.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="mainscreen.cpp" />
<ClCompile Include="mainwindow.cpp" />
<ClCompile Include="mainwindowlayout.cpp" />
<ClCompile Include="MyButton.cpp" />
<ClCompile Include="navbar.cpp" />
<ClCompile Include="netio.cpp" />
</ItemGroup>
<ItemGroup>
<QtUic Include="mainscreen.ui" />
<QtUic Include="mainwindow.ui" />
<QtUic Include="mainwindowlayout.ui" />
<QtUic Include="navbar.ui" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
</ImportGroup>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Form Files">
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
<Extensions>ui</Extensions>
</Filter>
<Filter Include="Translation Files">
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
<Extensions>ts</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<QtRcc Include="OfficeAssistant_msvc.qrc">
<Filter>Resource Files</Filter>
</QtRcc>
</ItemGroup>
<ItemGroup>
<ClInclude Include="MyButton.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="netio.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="buttonstruct.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="globalvariables.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<QtMoc Include="navbar.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="mainscreen.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="mainwindow.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="mainwindowlayout.h">
<Filter>Header Files</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mainscreen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mainwindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="mainwindowlayout.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MyButton.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="navbar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="netio.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtUic Include="navbar.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="mainscreen.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="mainwindow.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="mainwindowlayout.ui">
<Filter>Form Files</Filter>
</QtUic>
</ItemGroup>
</Project>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<QtLastBackgroundBuild>2023-07-28T22:55:30.5913647Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<QtLastBackgroundBuild>2023-07-28T22:55:31.6946123Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,13 @@
//
// Created by HW on 2023/07/26.
//
#ifndef OFFICEASSISTANT_BUTTONSTRUCT_H
#define OFFICEASSISTANT_BUTTONSTRUCT_H
#include <QString>
typedef struct taButtonStruct{
int index;
QString logo;
QString text;
}ButtonStruct;
#endif //OFFICEASSISTANT_BUTTONSTRUCT_H

View File

@ -0,0 +1,10 @@
//
// Created by HW on 2023/07/27.
//
#ifndef OFFICEASSISTANT_CONFIG_H
#define OFFICEASSISTANT_CONFIG_H
#define CONFIG_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/config"
#define OP_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/op"
#define DEVICE_URL "http://softapi.1.y01.cn/addons/Kmdsoft/Index/device"
#endif //OFFICEASSISTANT_CONFIG_H

View File

@ -0,0 +1,8 @@
//
// Created by HW on 2023/07/27.
//
#ifndef OFFICEASSISTANT_GLOBALVARIABLES_H
#define OFFICEASSISTANT_GLOBALVARIABLES_H
extern double scale;
#endif //OFFICEASSISTANT_GLOBALVARIABLES_H

View File

@ -0,0 +1,15 @@
#include "mainwindow.h"
#include <QApplication>
#include <Windows.h>
double scale;
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
HDC hdc = GetDC(NULL);
scale = GetDeviceCaps(hdc, LOGPIXELSX)/96;
ReleaseDC(NULL,hdc);
MainWindow w;
w.show();
return a.exec();
}

View File

@ -0,0 +1,19 @@
//
// Created by HW on 2023/07/27.
//
// You may need to build the project (run Qt uic code generator) to get "ui_MainScreen.h" resolved
#include "mainscreen.h"
#include "ui_MainScreen.h"
MainScreen::MainScreen(QWidget *parent) :
QWidget(parent), ui(new Ui::MainScreen) {
ui->setupUi(this);
}
MainScreen::~MainScreen() {
delete ui;
}

View File

@ -0,0 +1,28 @@
//
// Created by HW on 2023/07/27.
//
#ifndef OFFICEASSISTANT_MAINSCREEN_H
#define OFFICEASSISTANT_MAINSCREEN_H
#include <QWidget>
QT_BEGIN_NAMESPACE
namespace Ui { class MainScreen; }
QT_END_NAMESPACE
class MainScreen : public QWidget {
Q_OBJECT
public:
explicit MainScreen(QWidget *parent = nullptr);
~MainScreen() override;
private:
Ui::MainScreen *ui;
};
#endif //OFFICEASSISTANT_MAINSCREEN_H

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>MainScreen</class>
<widget class="QWidget" name="MainScreen">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainScreen</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>

View File

@ -0,0 +1,34 @@
//
// Created by HW on 2023/07/26.
//
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindow.h" resolved
#include "mainwindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
QDesktopWidget* desktopWidget = QApplication::desktop();
QRect deskRect = desktopWidget->availableGeometry();
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);
}
}
MainWindow::~MainWindow() {
delete mainWindowLayout;
delete ui;
}

View File

@ -0,0 +1,30 @@
//
// Created by HW on 2023/07/26.
//
#ifndef UNTITLED_MAINWINDOW_H
#define UNTITLED_MAINWINDOW_H
#include <QMainWindow>
#include <QVBoxLayout>
#include "mainwindowlayout.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;
private:
Ui::MainWindow *ui;
QVBoxLayout *layout;
MainWindowLayout *mainWindowLayout;
};
#endif //UNTITLED_MAINWINDOW_H

View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>17</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<pixmapfunction/>
<connections/>
</ui>

View File

@ -0,0 +1,63 @@
//
// Created by HW on 2023/07/26.
//
// You may need to build the project (run Qt uic code generator) to get "ui_MainWindowLagout.h" resolved
#include "mainwindowlayout.h"
#include "ui_MainWindowLayout.h"
MainWindowLayout::MainWindowLayout(QWidget *parent) :
QWidget(parent), ui(new Ui::MainWindowLayout) {
ui->setupUi(this);
layout=new QVBoxLayout(this);
buttons=new ButtonStruct[4];
buttons[0].text="主页";
buttons[0].logo=".\\images\\home.png";
buttons[0].index=0;
buttons[1].text="我的网址";
buttons[1].logo=".\\images\\address.png";
buttons[1].index=1;
buttons[2].text="我的资产";
buttons[2].logo=".\\images\\money.png";
buttons[2].index=2;
buttons[3].text="个人中心";
buttons[3].logo=".\\images\\personalcenter.png";
buttons[3].index=3;
for(auto i=0;i<4;i++) {
list << &buttons[i];
}
this->setLayout(nullptr);
navBar=new NavBar(list,this);
mainScreen=new MainScreen();
//QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
//navBar->setSizePolicy(sizePolicy);
layout->setMargin(0);
layout->addWidget(navBar,1);
layout->addWidget(mainScreen,4);
setLayout(layout);
}
MainWindowLayout::~MainWindowLayout() {
delete[] list[0];
delete navBar;
//delete layout;
delete ui;
}
void MainWindowLayout::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
navBar->resize(navBar->width(),height()/5);
//layout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
}
/*void MainWindowLayout::paintEvent(QPaintEvent *event) {
QWidget::paintEvent(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QRectF rect(0, 0, this->width(), this->height()/5);
painter.fillRect(rect, QColor("#333332"));
}*/

View File

@ -0,0 +1,40 @@
//
// Created by HW on 2023/07/26.
//
#ifndef OFFICEASSISTANT_MAINWINDOWLAYOUT_H
#define OFFICEASSISTANT_MAINWINDOWLAYOUT_H
#include <QWidget>
#include <QVBoxLayout>
#include "navbar.h"
#include "mainscreen.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindowLayout; }
QT_END_NAMESPACE
class MainWindowLayout : public QWidget {
Q_OBJECT
public:
explicit MainWindowLayout(QWidget *parent = nullptr);
~MainWindowLayout() override;
protected:
void resizeEvent(QResizeEvent *event) override;
//void paintEvent(QPaintEvent *event) override;
private:
Ui::MainWindowLayout *ui;
QVBoxLayout *layout;
QList<ButtonStruct *> list;
NavBar *navBar;
ButtonStruct *buttons;
MainScreen *mainScreen;
};
#endif //OFFICEASSISTANT_MAINWINDOWLAYOUT_H

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindowLayout</class>
<widget class="QWidget" name="MainWindowLayout">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindowLagout</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

1176
OfficeAssistant_msvc/mb.h Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -0,0 +1,57 @@
//
// Created by HW on 2023/07/26.
//
// You may need to build the project (run Qt uic code generator) to get "ui_NavBar.h" resolved
#include "navbar.h"
#include "ui_NavBar.h"
NavBar::NavBar(QList<ButtonStruct *> &buttonNames,QWidget *parent) :
QWidget(parent), ui(new Ui::NavBar) {
ui->setupUi(this);
layout=new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);
this->setMinimumHeight(48);
this->setMaximumHeight(200);
for(auto buttonName : buttonNames){
MyButton *button=new MyButton(buttonName->logo,buttonName->text,height(),height(),&buttons);
QSizePolicy sizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::QSizePolicy::Fixed);
button->setSizePolicy(sizePolicy);
layout->addWidget(button);
buttons<<button;
}
layout->setAlignment(Qt::AlignHCenter);
layout->setSpacing(0);
this->setLayout(layout);
}
NavBar::~NavBar() {
for(auto button : buttons){
delete button;
}
delete layout;
delete ui;
}
void NavBar::paintEvent(QPaintEvent *event) {
QWidget::paintEvent(event);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QRectF rect(0, 0, this->width(), this->height());
painter.fillRect(rect, QColor("#333332"));
}
void NavBar::resizeEvent(QResizeEvent *event) {
QWidget::resizeEvent(event);
for(auto button:buttons){
button->setSize(event->size().height(),event->size().height(),event->size().height(),event->size().height());
button->resize(event->size().height(),event->size().height());
button->update();
}
}

View File

@ -0,0 +1,40 @@
//
// Created by HW on 2023/07/26.
//
#ifndef OFFICEASSISTANT_NAVBAR_H
#define OFFICEASSISTANT_NAVBAR_H
#include <QWidget>
#include <QList>
#include <map>
#include "MyButton.h"
#include "buttonstruct.h"
QT_BEGIN_NAMESPACE
namespace Ui { class NavBar; }
QT_END_NAMESPACE
class NavBar : public QWidget {
Q_OBJECT
public:
NavBar(QList<ButtonStruct *> &buttonNames,QWidget *parent = nullptr);
~NavBar() override;
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
Ui::NavBar *ui;
QHBoxLayout *layout;
QList<MyButton *> buttons;
int width2;
int height2;
};
#endif //OFFICEASSISTANT_NAVBAR_H

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>NavBar</class>
<widget class="QWidget" name="NavBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>NavBar</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>

View File

@ -0,0 +1,531 @@
//
// Created by HW on 2023/07/27.
//
#include <QProcess>
#include <QScreen>
#include <QCryptographicHash>
#include "netio.h"
#include "config.h"
#include <cstdlib>
#include <ctime>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkRequest>
#include <QEventLoop>
#include <QtNetwork/QNetworkReply>
#include <QTimer>
#include <cstring>
#include <QJsonArray>
#include <QSysInfo>
#include <QStorageInfo>
#include <comutil.h>
#include <wbemidl.h>
#include <iostream>
#include <QGuiApplication>
#include <wbemidl.h>
#include <ctime>
#pragma comment(lib, "wbemuuid.lib")
#pragma comment(lib, "Qt5Networkd.lib")
#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};
wsprintf(unix_time,L"%ld",std::time(0));
QString request_id=QString::fromWCharArray(unix_time);
//打开配置文件
QFile *infFile=new QFile(".\\config\\information.cfg");
if(!infFile->open(QIODevice::ReadOnly|QIODevice::Text)){
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
delete infFile;
exit(1);
}
//读取配置文件
QByteArray bytes;
bytes=infFile->readAll();
infFile->close();
delete infFile;
//转化位json
qJsonDocument=QJsonDocument::fromJson(bytes);
if(qJsonDocument.isObject()){
//读取数据,写入对应字段
QJsonObject obj_root=qJsonDocument.object();
if(obj_root.value("product")==QJsonValue::Undefined){
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
product=obj_root.value("product").toString();
if(obj_root.value("partner_id")==QJsonValue::Undefined){
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
partner_id=obj_root.value("partner_id").toString();
if(obj_root.value("release")==QJsonValue::Undefined){
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
release=obj_root.value("release").toString();
if(obj_root.value("version")==QJsonValue::Undefined){
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
version=obj_root.value("version").toString();
if(obj_root.value("device_id")==QJsonValue::Undefined){
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
device_id=obj_root.value("device_id").toString();
}else{
//处理错误
QMessageBox::warning(nullptr,"错误","配置文件损坏");
exit(1);
}
//获取操作系统版本
os="Windows";
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize=sizeof(os);
GetVersionEx((OSVERSIONINFO *)&os);
switch(os.dwMajorVersion){//主版本号
case 5: //不兼容Windows 2000因此5.x一定是Windows XP
os_version="Windows XP";
break;
case 6:
switch(os.dwMinorVersion){ //次版本号
case 0:
os_version="Windows Vista or Windows Server 2008";
break;
case 1:
os_version="Windows 7 or Windows Server 2008 R2";
break;
case 2:
os_version="Windows 8 or Windows Server 2012";
break;
case 3:
os_version="Windows 8.1 or Windows Server 2012 R2";
break;
default:
os_version="Unknown";
}
case 10: //这几个系统都是10.0
os_version="Windows 10, Windows 11, Windows Server 2016 or Windows Server 2019";
break;
default:
os_version="Unknown";
}
//如果device_id是空值
if(device_id.isEmpty()){
//读取MachineGUID并取MD5作为device_id
QByteArray hash = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5);
device_id=hash.toHex();
infFile=new QFile(".\\config\\information.cfg");
if(!infFile->open(QIODevice::WriteOnly|QIODevice::Text)){
//处理错误
QMessageBox::warning(nullptr,"错误","无法覆写配置文件");
infFile->close();
delete infFile;
exit(1);
}
//加入json序列
QJsonValue value=device_id;
QJsonObject obj_root;
obj_root.insert("device_id",value);
qJsonDocument.setObject(obj_root);
//写入配置文件
infFile->write(qJsonDocument.toJson());
//关闭文件;
infFile->close();
delete infFile;
}
QJsonValue requestId_json=QJsonValue(request_id);
QJsonObject obj_root;
//插入request_id
obj_root.insert("request_id",requestId_json);
qJsonDocument.setObject(obj_root);
}
void ConfigRequest::sendRequest(ConfigResponse *configResponse) {
QTimer *timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
/* QFile *file=new QFile(".\\config\\config.cfg");
if(!file->open(QIODevice::ReadOnly|QIODevice::Text)){
QMessageBox::warning(nullptr,"错误","无法打开配置文件");
file->close();
delete file;
exit(1);
}*/
QNetworkRequest requestInfo;
//HTTP请求
//请求头
requestInfo.setUrl(QUrl(CONFIG_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止
QEventLoop eventLoop;
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
timer->start(5000);
//启动循环
eventLoop.exec();
delete httpMgr;
QJsonDocument result;
configResponse=new ConfigResponse;
memset(configResponse,0,sizeof(*configResponse));
//如果没有错误
if(reply->error() == QNetworkReply::NoError) {
result = QJsonDocument::fromJson(reply->readAll());
}else{
//如果有错误
configResponse->succeed=false;
delete reply;
delete timer;
return;
}
//如果数据完整
if(result.isObject()){
QJsonObject obj_root=result.object();
QJsonArray array;
array = obj_root.value("menu").toArray();
configResponse->menu=new Menu[array.count()];
auto i=0;
for(auto value:array){
QJsonObject object=value.toObject();
configResponse->menu[i].img=object.value("img").toString();
configResponse->menu[i].img_cover=object.value("img_cover").toString();
configResponse->menu[i].title=object.value("title").toString();
configResponse->menu[i].func=object.value("func").toString();
configResponse->menu[i].url=object.value("url").toString();
i++;
}
}else{
//数据不完整
configResponse->succeed=false;
delete reply;
delete timer;
return;
}
}
void RequestBodyBase::sendRequest() {
QTimer *timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo;
//HTTP请求
//请求头
requestInfo.setUrl(QUrl(OP_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止
QEventLoop eventLoop;
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
timer->start(5000);
//启动循环
eventLoop.exec();
delete timer;
delete httpMgr;
delete reply;
}
DeviceRequest::DeviceRequest() : RequestBodyBase() {
//CPU
QString cpu = QSysInfo::currentCpuArchitecture();
//内存大小
MEMORYSTATUSEX status;
status.dwLength = sizeof(status);
GlobalMemoryStatusEx(&status);
int ram = status.ullTotalPhys / 1024 / 1024;
//硬盘大小
QStorageInfo storage = QStorageInfo::root();
int disk = storage.bytesTotal() / static_cast<qulonglong>(1024 * 1024 * 1024);
//显卡型号
QStringList gpus;
BOOL success;
DWORD deviceIndex = 0;
DISPLAY_DEVICE displayDevice;
displayDevice.cb = sizeof(displayDevice);
while (EnumDisplayDevices(NULL, deviceIndex, &displayDevice, 0)) {
WCHAR valueName[128];
DWORD valueSize;
DWORD valueType;
BYTE valueData[MAX_PATH];
HKEY hKey;
WCHAR keyName[128];
wsprintf(keyName, L"SYSTEM\\CurrentControlSet\\Control\\Video\\%s\\HardwareInformation",
displayDevice.DeviceID);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
valueSize = sizeof(valueData);
wsprintf(valueName, L"HardwareInformation.AdapterString");
if (RegQueryValueEx(hKey, valueName, NULL, &valueType, valueData, &valueSize) == ERROR_SUCCESS) {
Q_ASSERT(valueType == REG_SZ);
QString adapterString = QString::fromWCharArray((wchar_t *) valueData, valueSize / sizeof(wchar_t) - 1);
gpus.append(adapterString);
}
RegCloseKey(hKey);
}
deviceIndex++;
displayDevice.cb = sizeof(displayDevice);
}
//主板型号
QString motherboard = QSysInfo::prettyProductName();
//WMI获取网卡型号
HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr)) {
std::cerr << "Failed to initialize COM library." << std::endl;
return;
}
QStringList netCards;
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL
);
if (FAILED(hr)) {
std::cerr << "Failed to initialize security." << std::endl;
CoUninitialize();
return;
}
IWbemLocator* pLoc = NULL;
hr = CoCreateInstance(
CLSID_WbemLocator,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator,
(LPVOID*)&pLoc
);
if (FAILED(hr)) {
std::cerr << "Failed to create IWbemLocator object." << std::endl;
CoUninitialize();
return;
}
IWbemServices* pSvc = NULL;
hr = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"),
NULL,
NULL,
0,
NULL,
0,
0,
&pSvc
);
if (FAILED(hr)) {
std::cerr << "Failed to connect to WMI service." << std::endl;
pLoc->Release();
CoUninitialize();
return;
}
hr = CoSetProxyBlanket(
pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
if (FAILED(hr)) {
std::cerr << "Failed to set security blanket." << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
IEnumWbemClassObject* pEnumerator = NULL;
hr = pSvc->ExecQuery(
_bstr_t("WQL"),
_bstr_t("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE AND NetConnectionStatus = 3"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator
);
if (FAILED(hr)) {
std::cerr << "Failed to execute WQL query for Win32_NetworkAdapter." << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
IWbemClassObject* pClassObj = NULL;
ULONG uReturn = 0;
while (pEnumerator) {
hr = pEnumerator->Next(WBEM_INFINITE, 1, &pClassObj, &uReturn);
if (uReturn == 0) {
break;
}
VARIANT vtProp;
hr = pClassObj->Get(L"Caption", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
QString str=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
netCards.append(str);
}
pClassObj->Release();
}
//WMI获取声卡型号
hr = pSvc->ExecQuery(
_bstr_t("WQL"),
_bstr_t("SELECT * FROM Win32_SoundDevice"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator
);
if (FAILED(hr)) {
std::cerr << "Failed to execute WQL query for Win32_SoundDevice." << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
QStringList audioCards;
while (pEnumerator) {
hr = pEnumerator->Next(WBEM_INFINITE, 1, &pClassObj, &uReturn);
if (uReturn == 0) {
break;
}
VARIANT vtProp;
hr = pClassObj->Get(L"Name", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr)) {
QString str=QString::fromWCharArray(vtProp.bstrVal);
VariantClear(&vtProp);
audioCards.append(str);
}
pClassObj->Release();
}
hr = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_PhysicalMemory"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator
);
if (FAILED(hr))
{
std::cout << "Query failed. Error code: " << hr << std::endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return;
}
QStringList RAMModel;
while (pEnumerator)
{
hr = pEnumerator->Next(WBEM_INFINITE, 1, &pClassObj, &uReturn);
if (uReturn == 0)
{
break;
}
VARIANT vtProp;
hr = pClassObj->Get(L"Manufacturer", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr))
{
std::wcout << "Manufacturer: " << vtProp.bstrVal << std::endl;
VariantClear(&vtProp);
}
hr = pClassObj->Get(L"PartNumber", 0, &vtProp, 0, 0);
if (SUCCEEDED(hr))
{
RAMModel.append(QString::fromWCharArray(vtProp.bstrVal));
VariantClear(&vtProp);
}
pClassObj->Release();
}
pSvc->Release();
pLoc->Release();
CoUninitialize();
DISPLAY_DEVICE d = { sizeof(DISPLAY_DEVICE) };
::EnumDisplayDevices(NULL, 0, &d, 0);
QString monitor=QString::fromWCharArray(d.DeviceString, wcslen(d.DeviceString));
//发送
//构造JSON
QJsonDocument *device=new QJsonDocument;
QJsonObject *object=new QJsonObject;
object->insert("CPU",QJsonValue(cpu));
object->insert("RAM",QJsonValue(ram));
object->insert("Hard_Disk",QJsonValue(disk));
QJsonArray *gpu_array=new QJsonArray;
for(auto gpu:gpus) {
gpu_array->append(gpu);
}
object->insert("GPU",*gpu_array);
delete gpu_array;
object->insert("Mother_Board",motherboard);
QJsonArray *RAMModel_json=new QJsonArray;
for(auto RAM:RAMModel){
RAMModel_json->append(RAM);
}
object->insert("Net_Card",*RAMModel_json);
delete RAMModel_json;
QJsonArray *netCards_json=new QJsonArray;
for(auto netCard:netCards){
netCards_json->append(netCard);
}
object->insert("Net_Card",*netCards_json);
delete netCards_json;
QJsonArray *audioCards_json=new QJsonArray;
for(auto audioCard:audioCards){
audioCards_json->append(audioCard);
}
object->insert("Audio_Card",*audioCards_json);
delete audioCards_json;
object->insert("Monitor",monitor);
device->setObject(*object);
delete object;
QJsonObject obj_root=qJsonDocument.object();
obj_root.insert("data",QString(device->toJson()));
delete device;
qJsonDocument.setObject(obj_root);
QTimer *timer = new QTimer(this);
QNetworkAccessManager *httpMgr = new QNetworkAccessManager();
QNetworkRequest requestInfo;
//HTTP请求
//请求头
requestInfo.setUrl(QUrl(DEVICE_URL));
requestInfo.setHeader(QNetworkRequest::ContentTypeHeader,QVariant("application/json"));
//保存响应的变量
QNetworkReply *reply = httpMgr->post(requestInfo,qJsonDocument.toJson());
//开启一个循环,直到超时或者获取到数据为止
QEventLoop eventLoop;
connect(reply,&QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
//设置定时器防止超时
connect(timer,&QTimer::timeout,&eventLoop,&QEventLoop::quit);
timer->start(5000);
//启动循环
eventLoop.exec();
delete httpMgr;
}

View File

@ -0,0 +1,96 @@
//
// Created by HW on 2023/07/27.
//
#ifndef OFFICEASSISTANT_NETIO_H
#define OFFICEASSISTANT_NETIO_H
#include <QString>
#include <QFile>
#include <QMessageBox>
#include <cstring>
#include <QJsonDocument>
#include <QJsonObject>
#include <Windows.h>
typedef struct {
QString img;
QString img_cover;
QString title;
QString func;
QString url;
} Menu;
typedef struct {
bool succeed;
struct {
QString logo_url;
QString device_id;
QString dev_id;
QString token;
QString backgroud_color;
QString title_color;
QString title_cover_color;
}basic;
Menu *menu;
}ConfigResponse;
class RequestBodyBase:public QObject{
public:
RequestBodyBase();
virtual void sendRequest();
protected:
QString product;
QString partner_id;
QString os;
QString os_version;
QString device_id;
QString request_id;
QString version;
QString release;
QString sign;
QJsonDocument qJsonDocument;
};
class ConfigRequest:public RequestBodyBase{
public:
ConfigRequest():RequestBodyBase(){}
void sendRequest(ConfigResponse * configResponse);
};
class OpRequest:public RequestBodyBase{
public:
OpRequest(QString Op,QString OpValue):RequestBodyBase(),op(Op),op_value(OpValue){
QJsonObject obj_root=qJsonDocument.object();
QJsonValue value=op;
obj_root.insert("op",op);
value=op_value;
obj_root.insert("op_value",op_value);
qJsonDocument.setObject(obj_root);
}
QString getOpValue(){
return op_value;
}
QString getOp(){
return op;
}
void setOpValue(QString op_value){
this->op_value=op_value;
}
void setOp(QString op){
this->op=op;
}
void sendRequest();
protected:
QString op;
QString op_value;
};
class DeviceRequest:RequestBodyBase{
DeviceRequest();
};
class OpenMulitiWechat:public RequestBodyBase{
public:
OpenMulitiWechat(): RequestBodyBase(){}
};
#endif //OFFICEASSISTANT_NETIO_H