commit 25daaecbc03daf49d8d442bdd76bc0aa99dc296b Author: Mike Solar Date: Wed Jul 26 19:48:14 2023 +0800 第一次提交 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0970347 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +cmake-build-debug/ +cmake-build-release/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b3a59a4 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.25) +project(officeassistant) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.6.3/5.6.3/mingw49_32") +add_definitions(-DOFFICEASSISTANT_NO_CONSOLE) +find_package(Qt5 COMPONENTS + Core + Gui + Widgets + REQUIRED) + +add_executable(officeassistant main.cpp mainwindow.cpp mainwindow.h mainwindow.ui mainwindowlayout.cpp mainwindowlayout.h mainwindowlayout.ui navbar.cpp navbar.h navbar.ui MyButton.cpp MyButton.h buttonstruct.h) +target_link_libraries(officeassistant + Qt5::Core + Qt5::Gui + Qt5::Widgets + ) +if (WIN32 AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) + set(DEBUG_SUFFIX) + if (MSVC AND CMAKE_BUILD_TYPE MATCHES "Debug") + set(DEBUG_SUFFIX "d") + endif () + set(QT_INSTALL_PATH "${CMAKE_PREFIX_PATH}") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + if (NOT EXISTS "${QT_INSTALL_PATH}/bin") + set(QT_INSTALL_PATH "${QT_INSTALL_PATH}/..") + endif () + endif () + if (EXISTS "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory + "$/plugins/platforms/") + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/plugins/platforms/qwindows${DEBUG_SUFFIX}.dll" + "$/plugins/platforms/") + endif () + foreach (QT_LIB Core Gui Widgets) + add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${QT_INSTALL_PATH}/bin/Qt5${QT_LIB}${DEBUG_SUFFIX}.dll" + "$") + endforeach (QT_LIB) +endif () diff --git a/MyButton.cpp b/MyButton.cpp new file mode 100644 index 0000000..73b49ea --- /dev/null +++ b/MyButton.cpp @@ -0,0 +1,34 @@ +// +// Created by HW on 2023/07/26. +// + +#include "MyButton.h" +MyButton::MyButton(QString logo,QString text,int width,int height,QWidget *parent) : QPushButton(parent) { + this->width2=width; + this->height2=height; + this->text=text; + this->logo=new QImage; + this->logo->load(logo); + this->setStyleSheet("background-color:#333332;"); +} + +MyButton::~MyButton() { + delete logo; +} + +void MyButton::paintEvent(QPaintEvent *e) { + QPushButton::paintEvent(e); + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + int logo_width=width()/2; + int logo_x=width()/4; + QFont ft; + ft.setPixelSize(7); + int text_x=0; + int text_y=(logo_width+logo_x); + QRectF logo_rect(logo_x, logo_x, logo_width, logo_width); + QRectF text_rect(text_x,text_y,7*text.length(),7); + painter.setPen(QColor("#FFFFFF")); + painter.drawImage(logo_rect, *logo); + painter.drawText(text_rect, Qt::AlignCenter, text); +} diff --git a/MyButton.h b/MyButton.h new file mode 100644 index 0000000..fe83337 --- /dev/null +++ b/MyButton.h @@ -0,0 +1,39 @@ +// +// Created by HW on 2023/07/26. +// + +#ifndef OFFICEASSISTANT_MYBUTTON_H +#define OFFICEASSISTANT_MYBUTTON_H + +#include +#include +#include +#include +#include + +class MyButton: public QPushButton{ +public: + MyButton(QString logo,QString text,int width,int height,QWidget *parent=nullptr); + ~MyButton() override; + QString getText(){ + return text; + } + QSize sizeHint() const override { + return QSize(width2/2,height2/2); + } + +protected: + void paintEvent(QPaintEvent *e) override; +private: + QImage *logo; + QLabel *logo_label; + QLabel *text_label; + QVBoxLayout *layout; + QPixmap* logo_pixmap; + QString text; + int width2; + int height2; +}; + + +#endif //OFFICEASSISTANT_MYBUTTON_H diff --git a/buttonstruct.h b/buttonstruct.h new file mode 100644 index 0000000..9f22c0f --- /dev/null +++ b/buttonstruct.h @@ -0,0 +1,13 @@ +// +// Created by HW on 2023/07/26. +// + +#ifndef OFFICEASSISTANT_BUTTONSTRUCT_H +#define OFFICEASSISTANT_BUTTONSTRUCT_H +#include +typedef struct taButtonStruct{ + int index; + QString logo; + QString text; +}ButtonStruct; +#endif //OFFICEASSISTANT_BUTTONSTRUCT_H diff --git a/images/address.png b/images/address.png new file mode 100644 index 0000000..875b34a Binary files /dev/null and b/images/address.png differ diff --git a/images/close-small.png b/images/close-small.png new file mode 100644 index 0000000..c8c864d Binary files /dev/null and b/images/close-small.png differ diff --git a/images/close.png b/images/close.png new file mode 100644 index 0000000..dcc9b40 Binary files /dev/null and b/images/close.png differ diff --git a/images/home.png b/images/home.png new file mode 100644 index 0000000..4b774e2 Binary files /dev/null and b/images/home.png differ diff --git a/images/maxsize.png b/images/maxsize.png new file mode 100644 index 0000000..d2539ed Binary files /dev/null and b/images/maxsize.png differ diff --git a/images/minsize.png b/images/minsize.png new file mode 100644 index 0000000..f08070f Binary files /dev/null and b/images/minsize.png differ diff --git a/images/money.png b/images/money.png new file mode 100644 index 0000000..93c1567 Binary files /dev/null and b/images/money.png differ diff --git a/images/personalcenter.png b/images/personalcenter.png new file mode 100644 index 0000000..e37d1c7 Binary files /dev/null and b/images/personalcenter.png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..7ba5a95 --- /dev/null +++ b/main.cpp @@ -0,0 +1,12 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..7431a92 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,31 @@ +// +// 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(); + if(deskRect.width()>=1920){ + resize(1920,1080); + }else if(deskRect.width()>=1333&&deskRect.width()<=1920) { + resize(800, 540); + } + delete desktopWidget; + mainWindowLayout=new MainWindowLayout(this); + setCentralWidget(mainWindowLayout); +} + +MainWindow::~MainWindow() { + delete mainWindowLayout; + delete layout; + delete ui; +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..2e0eef1 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,30 @@ +// +// Created by HW on 2023/07/26. +// + +#ifndef UNTITLED_MAINWINDOW_H +#define UNTITLED_MAINWINDOW_H + +#include +#include +#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 diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..0c3025c --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,34 @@ + + + + + + MainWindow + + + + 0 + 0 + 400 + 300 + + + + MainWindow + + + + + + 0 + 0 + 400 + 17 + + + + + + + + \ No newline at end of file diff --git a/mainwindowlayout.cpp b/mainwindowlayout.cpp new file mode 100644 index 0000000..5e92b2f --- /dev/null +++ b/mainwindowlayout.cpp @@ -0,0 +1,44 @@ +// +// 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]; + } + navBar=new NavBar(list,this); + layout->addWidget(navBar,1); + layout->addStretch(4); + layout->setMargin(0); + setLayout(layout); +} + +MainWindowLayout::~MainWindowLayout() { + + delete[] list[0]; + delete navBar; + delete layout; + delete ui; +} diff --git a/mainwindowlayout.h b/mainwindowlayout.h new file mode 100644 index 0000000..a2f584a --- /dev/null +++ b/mainwindowlayout.h @@ -0,0 +1,35 @@ + +// +// Created by HW on 2023/07/26. +// + +#ifndef OFFICEASSISTANT_MAINWINDOWLAYOUT_H +#define OFFICEASSISTANT_MAINWINDOWLAYOUT_H + +#include +#include +#include "navbar.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; + +private: + Ui::MainWindowLayout *ui; + QVBoxLayout *layout; + QList list; + NavBar *navBar; + ButtonStruct *buttons; +}; + + +#endif //OFFICEASSISTANT_MAINWINDOWLAYOUT_H diff --git a/mainwindowlayout.ui b/mainwindowlayout.ui new file mode 100644 index 0000000..704794c --- /dev/null +++ b/mainwindowlayout.ui @@ -0,0 +1,19 @@ + + + MainWindowLayout + + + + 0 + 0 + 400 + 300 + + + + MainWindowLagout + + + + + diff --git a/navbar.cpp b/navbar.cpp new file mode 100644 index 0000000..c8ac2cd --- /dev/null +++ b/navbar.cpp @@ -0,0 +1,47 @@ +// +// 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 &buttonNames,QWidget *parent) : + QWidget(parent), ui(new Ui::NavBar) { + ui->setupUi(this); + layout=new QHBoxLayout(); + layout->setMargin(0); + this->setMinimumHeight(48); + this->setMaximumHeight(150); + for(auto buttonName : buttonNames){ + MyButton *button=new MyButton(buttonName->logo,buttonName->text,height(),height()); + //QSizePolicy sizePolicy(QSizePolicy::Policy::Maximum, QSizePolicy::QSizePolicy::Maximum); + //button->setSizePolicy(sizePolicy); + layout->addWidget(button); + buttons<setAlignment(Qt::AlignHCenter); + + 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")); +} diff --git a/navbar.h b/navbar.h new file mode 100644 index 0000000..0dc8ef8 --- /dev/null +++ b/navbar.h @@ -0,0 +1,34 @@ +// +// Created by HW on 2023/07/26. +// + +#ifndef OFFICEASSISTANT_NAVBAR_H +#define OFFICEASSISTANT_NAVBAR_H + +#include +#include +#include +#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 &buttonNames,QWidget *parent = nullptr); + + ~NavBar() override; +protected: + void paintEvent(QPaintEvent *event); +private: + Ui::NavBar *ui; + QHBoxLayout *layout; + QList buttons; +}; + + +#endif //OFFICEASSISTANT_NAVBAR_H diff --git a/navbar.ui b/navbar.ui new file mode 100644 index 0000000..f072f6b --- /dev/null +++ b/navbar.ui @@ -0,0 +1,22 @@ + + + + + + NavBar + + + + 0 + 0 + 400 + 300 + + + + NavBar + + + + + \ No newline at end of file