From 93f39004dcb57766426cdc86296be21f5b4100dc Mon Sep 17 00:00:00 2001 From: taynpg Date: Tue, 6 Aug 2024 00:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 13 ++++++++++--- MainEntry.cpp | 35 +++++++++++++++++++++++++++++++++++ MainEntry.h | 29 +++++++++++++++++++++++++++++ MainUi.cpp | 30 ------------------------------ MainUi.h | 20 -------------------- MainWidget.cpp | 25 +++++++++++++++++++++++++ MainWidget.h | 28 ++++++++++++++++++++++++++++ main.cpp | 2 +- 8 files changed, 128 insertions(+), 54 deletions(-) create mode 100644 MainEntry.cpp create mode 100644 MainEntry.h delete mode 100644 MainUi.cpp delete mode 100644 MainUi.h create mode 100644 MainWidget.cpp create mode 100644 MainWidget.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 226fdea..6794679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,10 +3,15 @@ project(LinuxPack) set(CMAKE_CXX_STANDARD 17) -set(CMAKE_PREFIX_PATH "/home/taynpg/mlib/wxwidget") +set(CMAKE_PREFIX_PATH + "/home/taynpg/mlib/wxwidget" + "D:/Code/wxWidgets-install" +) + if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() + if (MSVC) add_compile_options(/source-charset:utf-8) add_compile_options(/EHsc) @@ -17,7 +22,9 @@ find_package(wxWidgets REQUIRED COMPONENTS core base) include(${wxWidgets_USE_FILE}) add_executable(LinuxPack main.cpp - MainUi.h - MainUi.cpp) + MainEntry.h + MainEntry.cpp + MainWidget.cpp + MainWidget.h) target_link_libraries(LinuxPack PRIVATE ${wxWidgets_LIBRARIES}) set_target_properties(LinuxPack PROPERTIES WIN32_EXECUTABLE TRUE) diff --git a/MainEntry.cpp b/MainEntry.cpp new file mode 100644 index 0000000..b0b865a --- /dev/null +++ b/MainEntry.cpp @@ -0,0 +1,35 @@ +#include "MainEntry.h" + +bool CLinuxPack::OnInit() +{ + auto* frame = new CMainFrame(wxT("Linux二进制打包")); + frame->Show(true); + return true; +} + +CMainEntry::CMainEntry(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) + : CMainWidget(parent, id, pos, size, style, name) +{ + +} + + CMainFrame::CMainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) +{ + entry_ = new CMainEntry(this, wxID_ANY); +} + +void CMainFrame::selectBinaryFile(wxCommandEvent& event) +{ + // btnSelectBinary->Bind(wxEVT_BUTTON, &CMainFrame::selectBinaryFile, this); + wxFileDialog openFileDialog( + this, _("Open file"), "", "", + "Text files (*.txt)|*.txt|PDF files (*.pdf)|*.pdf|All files (*.*)|*.*", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + + if (openFileDialog.ShowModal() == wxID_CANCEL) + return; + + wxString filePath = openFileDialog.GetPath(); + //text_ctrl_->SetValue(filePath); +} + diff --git a/MainEntry.h b/MainEntry.h new file mode 100644 index 0000000..aade995 --- /dev/null +++ b/MainEntry.h @@ -0,0 +1,29 @@ +#ifndef MAIN_ENTRY +#define MAIN_ENTRY + +#include "MainWidget.h" + +class CLinuxPack : public wxApp +{ +public: + bool OnInit() override; +}; + +class CMainEntry : public CMainWidget +{ +public: + explicit CMainEntry(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(649, 422), + long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString); + +}; + +class CMainFrame : public wxFrame +{ +private: + CMainEntry* entry_{}; +public: + explicit CMainFrame(const wxString& title); + void selectBinaryFile(wxCommandEvent& event); +}; + +#endif \ No newline at end of file diff --git a/MainUi.cpp b/MainUi.cpp deleted file mode 100644 index 0c0286d..0000000 --- a/MainUi.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "MainUi.h" - -bool CLinuxPack::OnInit() -{ - auto* frame = new CMainFrame(wxT("Linux二进制打包工具")); - frame->Show(true); - return true; -} - -void CMainFrame::OnQuit(wxCommandEvent& event) -{ - Close(); -} - -CMainFrame::CMainFrame(const wxString& title) : wxFrame(nullptr, wxID_ANY, title) -{ - auto* button = new wxButton(this, wxID_OK, wxT("OK"), wxPoint(100, 100)); - - wxSize screenSize = wxGetDisplaySize(); - wxSize initSize(screenSize.GetWidth() / 2, screenSize.GetHeight() / 2); - - SetSize(initSize); - - // 计算窗口的位置,使其居中 - int x = (screenSize.GetWidth() - initSize.GetWidth()) / 2; - int y = (screenSize.GetHeight() - initSize.GetHeight()) / 2; - - // 设置窗口的位置 - SetPosition(wxPoint(x, y)); -} diff --git a/MainUi.h b/MainUi.h deleted file mode 100644 index bea3201..0000000 --- a/MainUi.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef MAIN_UI -#define MAIN_UI - -#include -#define USE_DYNAMIC_CONNECT - -class CLinuxPack : public wxApp -{ -public: - bool OnInit() override; -}; - -class CMainFrame : public wxFrame -{ -public: - explicit CMainFrame(const wxString& title); - void OnQuit(wxCommandEvent& event); -}; - -#endif \ No newline at end of file diff --git a/MainWidget.cpp b/MainWidget.cpp new file mode 100644 index 0000000..18da8a7 --- /dev/null +++ b/MainWidget.cpp @@ -0,0 +1,25 @@ +// +// Created by sinxm on 24-8-5. +// + +#include "MainWidget.h" + +CMainWidget::CMainWidget(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) + : wxPanel(parent, id, pos, size, style, name) +{ + InitUi(); +} + +void CMainWidget::InitUi() +{ + ui_basic_box_ = new wxStaticBox(this, wxID_ANY, _("基本信息")); + ui_box_sizer_ = new wxStaticBoxSizer(ui_basic_box_, wxVERTICAL); + label_select_ = new wxStaticText(ui_box_sizer_->GetStaticBox(), wxID_ANY, _("要打包的二进制文件"), wxDefaultPosition, wxDefaultSize, 0); + sizer_select_ = new wxBoxSizer(wxHORIZONTAL); + text_select_ctrl_ = new wxTextCtrl(ui_box_sizer_->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0); + sizer_select_->Add(text_select_ctrl_, 0, wxALL, 5); + btn_select_ = new wxButton(ui_box_sizer_->GetStaticBox(), wxID_ANY, _("选择"), wxDefaultPosition, wxDefaultSize, 0); + sizer_select_->Add(btn_select_, 0, wxALL, 5); + ui_box_sizer_->Add(sizer_select_, 1, wxEXPAND, 5); + SetSizer(ui_box_sizer_); +} \ No newline at end of file diff --git a/MainWidget.h b/MainWidget.h new file mode 100644 index 0000000..d8e1eba --- /dev/null +++ b/MainWidget.h @@ -0,0 +1,28 @@ +// +// Created by sinxm on 24-8-5. +// + +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include + +class CMainWidget : public wxPanel +{ +protected: + wxStaticBox* ui_basic_box_{}; + wxStaticBoxSizer* ui_box_sizer_{}; + wxStaticText* label_select_{}; + wxBoxSizer* sizer_select_{}; + wxTextCtrl* text_select_ctrl_{}; + wxButton* btn_select_{}; + +public: + explicit CMainWidget(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize(649, 422), + long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString); + +public: + void InitUi(); +}; + +#endif // MAINWIDGET_H diff --git a/main.cpp b/main.cpp index 8f174ce..897b673 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,5 @@ #include -#include "MainUi.h" +#include "MainEntry.h" IMPLEMENT_APP(CLinuxPack); DECLARE_APP(CLinuxPack); \ No newline at end of file