修复导航栏问题

master
Mike Solar 2023-08-03 16:16:02 +08:00
parent 6fa68053bb
commit 4220083ac3
9 changed files with 1393 additions and 1325 deletions

Binary file not shown.

View File

@ -1,86 +1,87 @@
// //
// Created by HW on 2023/07/26. // Created by HW on 2023/07/26.
// //
#define TEXT_SIZE 7 #define TEXT_SIZE 7
#include "MyButton.h" #include "MyButton.h"
MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) { MyButton::MyButton(ButtonStruct &buttonStruct,int width,int height,QList<MyButton *> *buttons,QWidget *parent) : QPushButton(parent) {
this->buttons=buttons; this->buttons=buttons;
this->width2=width; this->width2=width;
this->height2=height; this->height2=height;
this->text=buttonStruct.text; this->text=buttonStruct.text;
this->url = buttonStruct.url; this->url = buttonStruct.url;
this->logo=buttonStruct.image; this->logo=buttonStruct.image;
this->logo_cover = buttonStruct.image_cover; this->logo_cover = buttonStruct.image_cover;
QString style = "background-color:"; this->background_color = buttonStruct.background_color;
style += buttonStruct.background_color; QString style = "background-color:";
style += ";border:none;"; style += buttonStruct.background_color;
this->setStyleSheet(style); style += ";border:none;";
this->text_color = buttonStruct.text_color; this->setStyleSheet(style);
this->text_cover_color = buttonStruct.text_cover_color; this->text_color = buttonStruct.text_color;
this->checked = false; this->text_cover_color = buttonStruct.text_cover_color;
} this->checked = false;
}
MyButton::~MyButton() {
} MyButton::~MyButton() {
}
void MyButton::paintEvent(QPaintEvent *e) {
QPushButton::paintEvent(e); void MyButton::paintEvent(QPaintEvent *e) {
QPainter painter(this); QPushButton::paintEvent(e);
painter.setRenderHint(QPainter::Antialiasing); QPainter painter(this);
int logo_width=width()/3; painter.setRenderHint(QPainter::Antialiasing);
int logo_x=width()/3; int logo_width=width()/3;
int logo_y=(height()-logo_width)/3; int logo_x=width()/3;
setContentsMargins(0,0,0,0); int logo_y=(height()-logo_width)/3;
QFont ft; setContentsMargins(0,0,0,0);
ft.setPixelSize(TEXT_SIZE); QFont ft;
//别问我为啥乘3我也不知道 ft.setPixelSize(TEXT_SIZE);
int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2; //别问我为啥乘3我也不知道
int text_y=(logo_width+logo_y+10); int text_x=(width()-TEXT_SIZE*text.length()*scale*3)/2;
QRectF logo_rect(logo_x, logo_y, logo_width, logo_width); int text_y=(logo_width+logo_y+10);
QRectF text_rect(text_x,text_y, TEXT_SIZE*text.length()*scale*3,TEXT_SIZE*scale*3); QRectF logo_rect(logo_x, logo_y, logo_width, logo_width);
QRectF text_rect(text_x,text_y, TEXT_SIZE*text.length()*scale*3,TEXT_SIZE*scale*3);
if(checked){
painter.setPen(text_cover_color); if(checked){
painter.drawImage(logo_rect, *logo_cover); painter.setPen(text_cover_color);
painter.drawText(text_rect, Qt::AlignCenter, text); painter.drawImage(logo_rect, *logo_cover);
} painter.drawText(text_rect, Qt::AlignCenter, text);
else { }
painter.setPen(text_color); else {
painter.drawImage(logo_rect, *logo); painter.setPen(text_color);
painter.drawText(text_rect, Qt::AlignCenter, text); painter.drawImage(logo_rect, *logo);
} painter.drawText(text_rect, Qt::AlignCenter, text);
}
}
QSize MyButton::sizeHint() const { }
return QSize(width2,height2); QSize MyButton::sizeHint() const {
} return QSize(width2,height2);
}
void MyButton::enterEvent(QEvent *event) {
QWidget::enterEvent(event); void MyButton::enterEvent(QEvent *event) {
checked = true; QWidget::enterEvent(event);
update(); checked = true;
} update();
}
void MyButton::leaveEvent(QEvent *event) {
QWidget::leaveEvent(event); void MyButton::leaveEvent(QEvent *event) {
checked = false; QWidget::leaveEvent(event);
update(); checked = false;
} update();
}
void MyButton::mousePressEvent(QMouseEvent *event) {
QPushButton::mousePressEvent(event); void MyButton::mousePressEvent(QMouseEvent *event) {
} QPushButton::mousePressEvent(event);
}
void MyButton::mouseReleaseEvent(QMouseEvent *event) {
QPushButton::mouseReleaseEvent(event); void MyButton::mouseReleaseEvent(QMouseEvent *event) {
for(auto button:*buttons){ QPushButton::mouseReleaseEvent(event);
button->setChecked(false); for(auto button:*buttons){
button->update(); button->setChecked(false);
} button->update();
if(checked) }
checked=false; if(checked)
else checked=false;
checked=true; else
emit clicked1(text, url); checked=true;
} emit clicked1(text, url);
}

View File

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

View File

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

View File

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

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>79c86fb12b36dfa33d1a537c9af100b4c7928a9c</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>79c86fb12b36dfa33d1a537c9af100b4c7928a9c</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<QtLastBackgroundBuild>2023-08-01T03:05:45.8140795Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2023-08-03T08:03:42.8435391Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<QtLastBackgroundBuild>2023-08-01T03:05:46.4588999Z</QtLastBackgroundBuild> <QtLastBackgroundBuild>2023-08-03T08:03:43.2818738Z</QtLastBackgroundBuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -1,228 +1,261 @@
// //
// Created by HW on 2023/07/26. // 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 // You may need to build the project (run Qt uic code generator) to get "ui_NavBar.h" resolved
#include "navbar.h" #include "navbar.h"
#include "ui_NavBar.h" #include "ui_NavBar.h"
#include "config.h" #include "config.h"
#include <QTimer> #include <QTimer>
#include <QtSvg/QtSvg> #include <QtSvg/QtSvg>
#include <QPixmap> #include <QPixmap>
#include "mainwindowlayout.h" #include "mainwindowlayout.h"
#include "globalvariables.h" #include "globalvariables.h"
#ifdef _DEBUG #ifdef _DEBUG
#pragma comment(lib, "Qt5Svgd.lib") #pragma comment(lib, "Qt5Svgd.lib")
#else #else
#pragma comment(lib, "Qt5Svg.lib") #pragma comment(lib, "Qt5Svg.lib")
#endif #endif
QString url_param; QString url_param;
NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) : void ConvertImageToTransparent(QImage &img)
QWidget(parent), ui(new Ui::NavBar) { {
ui->setupUi(this); img = img.convertToFormat(QImage::Format_ARGB32);
//this->setAttribute(Qt::WA_DeleteOnClose); union myrgb
buffer = new QByteArray; {
/*QString style = "background-color:"; uint rgba;
style += configResponse->basic.backgroud_color.toUpper(); uchar rgba_bits[4];
style += ";"; };
setStyleSheet(style);*/ myrgb* mybits = (myrgb*)img.bits();
//setStyleSheet("margin:0"); int len = img.width()*img.height();
setContentsMargins(0, 0, 0, 0); while (len--> 0)
if (configResponse->succeed&&configResponse->menus.empty()!=true) { {
getLogoFromInternet(configResponse); mybits->rgba_bits[3] = (mybits->rgba == 0xFFFFFFFF) ? 0 : 255;
} mybits++;
else { }
getLogoFromLocal(); }
}
layout2 = new QHBoxLayout; NavBar::NavBar(ConfigResponse *configResponse, MainScreen *mainScreen,QWidget *parent) :
layout_right = new QHBoxLayout; QWidget(parent), ui(new Ui::NavBar) {
layout_left = new QHBoxLayout; ui->setupUi(this);
logo_label = new QLabel(this); //this->setAttribute(Qt::WA_DeleteOnClose);
//*logo = logo->scaled(this->width() / (5 / scale), this->height()); buffer = new QByteArray;
logo_label->setScaledContents(true); /*QString style = "background-color:";
logo_label->setPixmap(QPixmap::fromImage(*logo)); style += configResponse->basic.backgroud_color.toUpper();
logo_label->setMaximumHeight(parent->height() / 8); style += ";";
layout_left->addWidget(logo_label); setStyleSheet(style);*/
layout_left->setAlignment(Qt::AlignCenter); //setStyleSheet("margin:0");
for (auto buttonStruct : buttonStructs) { setContentsMargins(0, 0, 0, 0);
MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this); if (configResponse->succeed&&configResponse->menus.empty()!=true) {
myButton->setMaximumHeight(parent->height() / 8); getLogoFromInternet(configResponse);
layout_right->addWidget(myButton); }
//myButton->show(); else {
connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton); getLogoFromLocal();
buttons << myButton; }
} layout2 = new QHBoxLayout;
layout_right->setAlignment(Qt::AlignLeft); layout_right = new QHBoxLayout;
if (!buttonStructs.empty()) { layout_left = new QHBoxLayout;
connect(this, &NavBar::firstUrl, mainScreen, &MainScreen::firstUrl); logo_label = new QLabel(this);
emit firstUrl(buttonStructs[0].url); //*logo = logo->scaled(this->width() / (5 / scale), this->height());
} logo_label->setScaledContents(true);
layout2->addLayout(layout_left, 1); logo_label->setPixmap(QPixmap::fromImage(*logo));
layout2->addLayout(layout_right, 4); logo_label->setMaximumHeight(parent->height() / 8);
layout_right->setMargin(0); layout_left->addWidget(logo_label);
layout2->setMargin(0); layout_left->setAlignment(Qt::AlignCenter);
//layout2->setAlignment(Qt::AlignJustify); for (auto buttonStruct : buttonStructs) {
this->setLayout(layout2); MyButton *myButton = new MyButton(buttonStruct, height(), height(), &buttons,this);
logo_label->show(); myButton->setMaximumHeight(parent->height() / 8);
} layout_right->addWidget(myButton);
//myButton->show();
NavBar::~NavBar() { connect(myButton, &MyButton::clicked1, mainWindowLayout, &MainWindowLayout::clickButton);
for (auto buttonStruct : buttonStructs) { buttons << myButton;
delete buttonStruct.image; }
delete buttonStruct.image_cover; layout_right->setAlignment(Qt::AlignLeft);
} if (!buttonStructs.empty()) {
for(auto button : buttons){ connect(this, &NavBar::firstUrl, mainScreen, &MainScreen::firstUrl);
layout_right->removeWidget(button); emit firstUrl(buttonStructs[0].url);
delete button; }
} layout2->addLayout(layout_left, 1);
layout2->removeWidget(logo_label); layout2->addLayout(layout_right, 4);
delete logo_label; layout_right->setMargin(0);
delete logo; layout2->setMargin(0);
//delete layout_left; //layout2->setAlignment(Qt::AlignJustify);
delete layout_right; this->setLayout(layout2);
delete layout2; logo_label->show();
delete ui; }
}
NavBar::~NavBar() {
void NavBar::paintEvent(QPaintEvent *event) { for (auto buttonStruct : buttonStructs) {
QWidget::paintEvent(event); delete buttonStruct.image;
delete buttonStruct.image_cover;
QPainter painter(this); }
painter.setRenderHint(QPainter::Antialiasing); for(auto button : buttons){
layout_right->removeWidget(button);
QRectF rect(0, 0, this->width(), this->height()); delete button;
painter.fillRect(rect, qColor); }
layout2->removeWidget(logo_label);
} delete logo_label;
void NavBar::resizeEvent(QResizeEvent *event) { delete logo;
QWidget::resizeEvent(event); //delete layout_left;
for(auto button:buttons){ delete layout_right;
button->setMaximumSize(event->size().height(), event->size().height()); delete layout2;
button->update(); delete ui;
} }
logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
} void NavBar::paintEvent(QPaintEvent *event) {
void NavBar::getLogoFromInternet(ConfigResponse *configResponse) { QWidget::paintEvent(event);
qColor.setNamedColor(configResponse->basic.backgroud_color);
QPainter painter(this);
QUrl url_logo(configResponse->basic.logo_url); painter.setRenderHint(QPainter::Antialiasing);
QNetworkRequest *request_logo = new QNetworkRequest(url_logo);
manager = new QNetworkAccessManager; QRectF rect(0, 0, this->width(), this->height());
reply = manager->get(*request_logo); painter.fillRect(rect, qColor);
QTimer timer;
timer.setInterval(5000); }
connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit); void NavBar::resizeEvent(QResizeEvent *event) {
connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload); QWidget::resizeEvent(event);
eventLoop.exec(); for(auto button:buttons){
timer.stop(); button->setMaximumSize(event->size().height(), event->size().height());
buffer = new QByteArray; button->update();
delete request_logo; }
if (downloadSuccess == true) { logo_label->setMaximumSize(event->size().width() / 5, event->size().height());
*buffer = reply->readAll(); }
logo = new QImage(); void NavBar::getLogoFromInternet(ConfigResponse *configResponse) {
logo->loadFromData(*buffer); qColor.setNamedColor(configResponse->basic.backgroud_color);
buffer->clear();
for (auto button : configResponse->menus) { QUrl url_logo(configResponse->basic.logo_url);
QUrl url_image(button.img); QNetworkRequest *request_logo = new QNetworkRequest(url_logo);
QNetworkRequest *request_image = new QNetworkRequest(url_image); manager = new QNetworkAccessManager;
reply = manager->get(*request_image); reply = manager->get(*request_logo);
QTimer timer; QTimer timer;
timer.setInterval(5000); timer.setInterval(5000);
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); connect(reply, &QNetworkReply::finished, &eventLoop,&QEventLoop::quit);
connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload); connect(&timer, &QTimer::timeout,this, &NavBar::cancelDownload);
eventLoop.exec(); eventLoop.exec();
timer.stop(); timer.stop();
if (!downloadSuccess) { buffer = new QByteArray;
break; delete request_logo;
} reply->close();
*buffer = reply->readAll(); if (downloadSuccess == true) {
QSvgRenderer *render_image = new QSvgRenderer(*buffer); *buffer = reply->readAll();
QImage *image = new QImage(200, 200, QImage::Format_ARGB32); logo = new QImage();
QPainter painter_image(image); logo->loadFromData(*buffer);
render_image->render(&painter_image); buffer->clear();
for (auto button : configResponse->menus) {
QUrl url_image_cover(button.img_cover); QUrl url_image(button.img);
QNetworkRequest *request_image_cover = new QNetworkRequest(url_image_cover); QNetworkRequest *request_image = new QNetworkRequest(url_image);
reply = manager->get(*request_image_cover); reply = manager->get(*request_image);
timer.setInterval(5000); QTimer timer;
connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); timer.setInterval(5000);
connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload); connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
if (!downloadSuccess) { connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload);
break; eventLoop.exec();
} timer.stop();
*buffer = reply->readAll(); if (!downloadSuccess) {
QSvgRenderer *render_image_cover = new QSvgRenderer(*buffer); break;
QImage *image_cover = new QImage(200, 200, QImage::Format_ARGB32); }
QPainter painter_image_cover(image_cover); *buffer = reply->readAll();
render_image_cover->render(&painter_image_cover);
ButtonStruct buttonStruct; QSvgRenderer *render_image = new QSvgRenderer(*buffer);
buttonStruct.image = image;
buttonStruct.image_cover = image_cover; QImage *image = new QImage(200, 200, QImage::Format_ARGB32);
buttonStruct.text = button.title; QPainter painter_image(image);
buttonStruct.url = button.url; painter_image.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
buttonStruct.background_color = configResponse->basic.backgroud_color; painter_image.fillRect(rect(), Qt::transparent); // 填充透明色
buttonStruct.text_color.setNamedColor(configResponse->basic.title_color); painter_image.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
buttonStruct.text_cover_color.setNamedColor(configResponse->basic.title_cover_color); render_image->render(&painter_image);
buttonStructs << buttonStruct; buffer->clear();
delete request_image; reply->close();
delete render_image;
delete request_image_cover; QUrl url_image_cover(button.img_cover);
delete render_image_cover; QNetworkRequest *request_image_cover = new QNetworkRequest(url_image_cover);
} reply = manager->get(*request_image_cover);
} timer.setInterval(5000);
delete manager; connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
manager = nullptr; connect(&timer, &QTimer::timeout, this, &NavBar::cancelDownload);
if (!downloadSuccess) {
} break;
void NavBar::storeToBuffer() { }
buffer = new QByteArray; eventLoop.exec();
*buffer = reply->readAll();
} qDebug() << *buffer;
void NavBar::cancelDownload() { QSvgRenderer *render_image_cover = new QSvgRenderer(*buffer);
disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); QImage *image_cover = new QImage(200, 200, QImage::Format_ARGB32);
eventLoop.quit(); QPainter painter_image_cover(image_cover);
reply->abort(); painter_image_cover.setCompositionMode(QPainter::CompositionMode_Clear); // 清除画布
downloadSuccess = false; painter_image_cover.fillRect(rect(), Qt::transparent); // 填充透明色
} painter_image_cover.setCompositionMode(QPainter::CompositionMode_SourceOver); // 恢复默认值
render_image_cover->render(&painter_image_cover);
void NavBar::getLogoFromLocal() { buffer->clear();
QString dir = QApplication::applicationDirPath(); reply->close();
QFile file(dir + DEFAULT_FILE);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { ButtonStruct buttonStruct;
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件")); buttonStruct.image = image;
exit(1); buttonStruct.image_cover = image_cover;
} buttonStruct.text = button.title;
buffer->clear(); buttonStruct.url = button.url;
*buffer = file.readAll(); buttonStruct.background_color = configResponse->basic.backgroud_color;
file.close(); buttonStruct.text_color.setNamedColor(configResponse->basic.title_color);
QJsonDocument *qJsonDocument = new QJsonDocument; buttonStruct.text_cover_color.setNamedColor(configResponse->basic.title_cover_color);
*qJsonDocument = QJsonDocument::fromJson(*buffer); buttonStructs << buttonStruct;
QJsonObject *obj_root = new QJsonObject; delete request_image;
if (qJsonDocument->isObject()) { delete render_image;
*obj_root = qJsonDocument->object(); delete request_image_cover;
delete qJsonDocument; delete render_image_cover;
QString logo_path = obj_root->value("basic").toObject().value("logo").toString(); }
logo = new QImage(logo_path); }
QString color= obj_root->value("basic").toObject().value("backgroud_color").toString(); delete manager;
qColor.setNamedColor(color); manager = nullptr;
QJsonArray *array = new QJsonArray;
*array = obj_root->value("menu").toArray(); }
for (auto obj : *array) { void NavBar::storeToBuffer() {
ButtonStruct buttonStruct; buffer = new QByteArray;
buttonStruct.text = obj.toObject().value("title").toString();
buttonStruct.url = QString(BASE_URL)+obj.toObject().value("url").toString(); }
buttonStruct.image = new QImage(obj.toObject().value("img").toString()); void NavBar::cancelDownload() {
buttonStruct.image_cover = new QImage(obj.toObject().value("img_cover").toString()); disconnect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit);
buttonStructs << buttonStruct; eventLoop.quit();
} reply->abort();
delete array; downloadSuccess = false;
} }
else {
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏")); void NavBar::getLogoFromLocal() {
delete obj_root; QString dir = QApplication::applicationDirPath();
exit(1); QFile file(dir + DEFAULT_FILE);
} if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
delete obj_root; QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("无法打开配置文件"));
exit(1);
}
buffer->clear();
*buffer = file.readAll();
file.close();
QJsonDocument *qJsonDocument = new QJsonDocument;
*qJsonDocument = QJsonDocument::fromJson(*buffer);
QJsonObject *obj_root = new QJsonObject;
if (qJsonDocument->isObject()) {
*obj_root = qJsonDocument->object();
delete qJsonDocument;
QString logo_path = obj_root->value("basic").toObject().value("logo").toString();
logo = new QImage(logo_path);
QString color= obj_root->value("basic").toObject().value("backgroud_color").toString();
qColor.setNamedColor(color);
QJsonArray *array = new QJsonArray;
*array = obj_root->value("menu").toArray();
for (auto obj : *array) {
ButtonStruct buttonStruct;
buttonStruct.text = obj.toObject().value("title").toString();
buttonStruct.url = QString(BASE_URL)+obj.toObject().value("url").toString();
buttonStruct.image = new QImage(obj.toObject().value("img").toString());
buttonStruct.image_cover = new QImage(obj.toObject().value("img_cover").toString());
buttonStructs << buttonStruct;
}
delete array;
}
else {
QMessageBox::warning(nullptr, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("配置文件损坏"));
delete obj_root;
exit(1);
}
delete obj_root;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,113 +1,116 @@
// //
// Created by HW on 2023/07/27. // Created by HW on 2023/07/27.
// //
#ifndef OFFICEASSISTANT_NETIO_H #ifndef OFFICEASSISTANT_NETIO_H
#define OFFICEASSISTANT_NETIO_H #define OFFICEASSISTANT_NETIO_H
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QMessageBox> #include <QMessageBox>
#include <cstring> #include <cstring>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <Windows.h> #include <Windows.h>
#include <QtNetwork/QtNetwork> #include <QtNetwork/QtNetwork>
typedef struct { typedef struct {
QString img; QString img;
QString img_cover; QString img_cover;
QString title; QString title;
QString func; QString func;
QString url; QString url;
} Menu; } Menu;
typedef struct { typedef struct {
bool succeed; bool succeed;
struct { struct {
QString logo_url; QString logo_url;
QString device_id; QString device_id;
QString dev_id; QString dev_id;
QString token; QString token;
QString backgroud_color; QString backgroud_color;
QString title_color; QString title_color;
QString title_cover_color; QString title_cover_color;
}basic; }basic;
QList<Menu> menus; QList<Menu> menus;
}ConfigResponse; }ConfigResponse;
class RequestBodyBase:public QObject{ class RequestBodyBase:public QObject{
Q_OBJECT; Q_OBJECT;
public: public:
RequestBodyBase(); RequestBodyBase();
virtual void sendRequest(); virtual void sendRequest();
protected: protected:
QString product; QString product;
QString parter_id; QString parter_id;
QString os; QString os;
QString os_version; QString os_version;
QString device_id; QString device_id;
QString request_id; QString request_id;
QString version; QString version;
QString release; QString release;
QString sign; QString sign;
QJsonDocument qJsonDocument; QJsonDocument qJsonDocument;
QNetworkReply *reply; QNetworkReply *reply;
QEventLoop eventLoop; QEventLoop eventLoop;
QTimer *timer; QTimer *timer;
protected slots: protected slots:
void cancelDownload(); void cancelDownload();
}; };
class ConfigRequest:public RequestBodyBase{ class ConfigRequest:public RequestBodyBase{
public: public:
ConfigRequest():RequestBodyBase(){} ConfigRequest():RequestBodyBase(){}
void sendRequest(ConfigResponse * configResponse); void sendRequest(ConfigResponse * configResponse);
}; };
class OpRequest:public RequestBodyBase{ class OpRequest:public RequestBodyBase{
public: public:
OpRequest(QString Op,QString OpValue):RequestBodyBase(),op(Op),op_value(OpValue){ OpRequest(QString Op,QString OpValue):RequestBodyBase(),op(Op),op_value(OpValue){
QJsonObject obj_root=qJsonDocument.object(); QJsonObject obj_root=qJsonDocument.object();
QJsonValue value=op; QJsonValue value=op;
obj_root.insert("op",op); obj_root.insert("op",op);
value=op_value; value=op_value;
obj_root.insert("op_value",op_value); obj_root.insert("op_value",op_value);
qJsonDocument.setObject(obj_root); qJsonDocument.setObject(obj_root);
} }
QString getOpValue(){ QString getOpValue(){
return op_value; return op_value;
} }
QString getOp(){ QString getOp(){
return op; return op;
} }
void setOpValue(QString op_value){ void setOpValue(QString op_value){
this->op_value=op_value; this->op_value=op_value;
} }
void setOp(QString op){ void setOp(QString op){
this->op=op; this->op=op;
} }
void sendRequest(); void sendRequest();
protected: protected:
QString op; QString op;
QString op_value; QString op_value;
}; };
class DeviceRequest:RequestBodyBase{ class DeviceRequest:RequestBodyBase{
DeviceRequest(); DeviceRequest();
}; };
class OpenMulitiWechat:public RequestBodyBase{ class OpenMulitiWechat:public RequestBodyBase{
public: public:
OpenMulitiWechat(): RequestBodyBase(){} OpenMulitiWechat(): RequestBodyBase(){}
}; };
inline QString getMachineGUID() { inline QString getMachineGUID() {
HKEY hKey; HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography",
0, KEY_READ | KEY_WOW64_64KEY, &hKey); 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
DWORD dwType1 = REG_SZ; DWORD dwType1 = REG_SZ;
DWORD dwLen = MAX_PATH; DWORD dwLen = MAX_PATH;
WCHAR buf[100]; WCHAR buf[100];
RegQueryValueExA(hKey, "MachineGuid", 0, &dwType1, (LPBYTE)buf, &dwLen); RegQueryValueExA(hKey, "MachineGuid", 0, &dwType1, (LPBYTE)buf, &dwLen);
QString guid = QString::fromWCharArray(buf); QString guid = QString::fromWCharArray(buf);
return guid; return guid;
} }
#endif //OFFICEASSISTANT_NETIO_H class SoftwareRequest :public RequestBodyBase {
};
#endif //OFFICEASSISTANT_NETIO_H