From ab1c88fc10589bded4cabd37598224f4855e86f7 Mon Sep 17 00:00:00 2001 From: daleclack Date: Tue, 26 Jul 2022 13:01:38 +0800 Subject: [PATCH] Adjust UI --- XeRelease_Gtkmm3/CMakeLists.txt | 1 + XeRelease_Gtkmm3/res/prefs.ui | 393 +++++++++++++++++-------------- XeRelease_Gtkmm3/res/style.css | 10 + XeRelease_Gtkmm3/src/MyDialog.cc | 131 ++++++----- XeRelease_Gtkmm3/src/MyDialog.hh | 41 ++-- XeRelease_Gtkmm3/src/MyWin.cc | 30 ++- XeRelease_Gtkmm3/src/MyWin.hh | 26 +- 7 files changed, 353 insertions(+), 279 deletions(-) create mode 100644 XeRelease_Gtkmm3/res/style.css diff --git a/XeRelease_Gtkmm3/CMakeLists.txt b/XeRelease_Gtkmm3/CMakeLists.txt index 0c44552..91c76ae 100644 --- a/XeRelease_Gtkmm3/CMakeLists.txt +++ b/XeRelease_Gtkmm3/CMakeLists.txt @@ -26,6 +26,7 @@ set(SOURCES src/main.cc src/MyWin.cc src/MyDialog.cc #Compile resources with GCR_CMake set(RESOURCE_LIST + style.css STRIPBLANKS menubar.xml STRIPBLANKS prefs.ui icons/16x16/actions/open-menu.png diff --git a/XeRelease_Gtkmm3/res/prefs.ui b/XeRelease_Gtkmm3/res/prefs.ui index fe1c5f9..3b81d36 100644 --- a/XeRelease_Gtkmm3/res/prefs.ui +++ b/XeRelease_Gtkmm3/res/prefs.ui @@ -2,7 +2,213 @@ - + + True + False + center + center + vertical + 10 + + + True + False + 5 + 5 + 5 + 5 + True + True + vertical + + + True + False + Release Configs: + + + False + True + 0 + + + + + + True + False + + + True + False + end + True + True + LongTerm: + + + 0 + 0 + + + + + True + False + end + True + True + Stable: + + + 0 + 1 + + + + + True + False + end + True + True + Development: + + + 0 + 2 + + + + + True + True + True + True + default_config + + + 1 + 0 + + + + + True + True + True + True + default_config + + + 1 + 1 + + + + + True + True + True + True + default_config + + + 1 + 2 + + + + + True + False + end + Path: + + + 0 + 3 + + + + + True + True + ./ + + + 1 + 3 + + + + + False + True + 1 + + + + + False + True + 0 + + + + + True + False + center + 5 + + + Custom Path + True + True + True + + + False + False + 0 + + + + + OK + True + True + True + + + False + False + 1 + + + + + Cancel + True + True + True + + + False + False + 2 + + + + + False + True + 1 + + + + False 10 dialog @@ -16,43 +222,13 @@ False end - - Custom Path - True - True - True - - - True - True - 0 - + - - OK - True - True - True - - - True - True - 1 - + - - Cancel - True - True - True - - - True - True - 2 - + @@ -62,156 +238,9 @@ - - True - False - 5 - 5 - 5 - 5 - True - True - vertical - - - True - False - Release Configs: - - - False - True - 0 - - - - - - True - False - - - True - False - end - True - True - LongTerm: - - - 0 - 0 - - - - - True - False - end - True - True - Stable: - - - 0 - 1 - - - - - True - False - end - True - True - Development: - - - 0 - 2 - - - - - True - True - True - True - default_config - - - 1 - 0 - - - - - True - True - True - True - default_config - - - 1 - 1 - - - - - True - True - True - True - default_config - - - 1 - 2 - - - - - True - False - end - Path: - - - 0 - 3 - - - - - True - True - ./ - - - 1 - 3 - - - - - False - True - 1 - - - - - False - True - 1 - + - - btn_ok - btn_cancel - diff --git a/XeRelease_Gtkmm3/res/style.css b/XeRelease_Gtkmm3/res/style.css new file mode 100644 index 0000000..015c6cc --- /dev/null +++ b/XeRelease_Gtkmm3/res/style.css @@ -0,0 +1,10 @@ +/* +您可以在这里输入任何 GTK+ 可识别的 CSS 规则。 +您可以点击上面的“暂停”按钮来暂时停用这个自定义 CSS。 + +变更会立即应用到全局,影响整个应用程序。 +*/ + +box{ + background-color:rgba(255,255,255,0.5); +} \ No newline at end of file diff --git a/XeRelease_Gtkmm3/src/MyDialog.cc b/XeRelease_Gtkmm3/src/MyDialog.cc index b502f48..c9f5582 100644 --- a/XeRelease_Gtkmm3/src/MyDialog.cc +++ b/XeRelease_Gtkmm3/src/MyDialog.cc @@ -1,17 +1,18 @@ #include "MyDialog.hh" -MyDialog::MyDialog(BaseObjectType *cobject, const Glib::RefPtr &ref_builder) - : Gtk::Dialog(cobject), +MyPrefs::MyPrefs(BaseObjectType *cobject, const Glib::RefPtr &ref_builder) + : Gtk::Box(cobject), ref_Glade(ref_builder) { - // Initalize - set_icon_name("XeRelease"); + // // Initalize + // set_icon_name("XeRelease"); // Get Widgets ref_builder->get_widget("entry_lts", entry_lts); ref_builder->get_widget("entry_stable", entry_stable); ref_builder->get_widget("entry_dev", entry_dev); ref_builder->get_widget("entry_path", entry_path); ref_builder->get_widget("btnpath", btnpath); + ref_builder->get_widget("btn_ok", btnok); // json_file.close(); @@ -29,41 +30,40 @@ MyDialog::MyDialog(BaseObjectType *cobject, const Glib::RefPtr &re // readCfgFile("xe_config","Release_Path_Win32",config_win32); // Connect Signal - btnpath->signal_clicked().connect(sigc::mem_fun(*this, &MyDialog::btnpath_clicked)); + btnpath->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnpath_clicked)); + btnok->signal_clicked().connect(sigc::mem_fun(*this, &MyPrefs::btnok_clicked)); } -void MyDialog::on_response(int response_id) +void MyPrefs::btnok_clicked() { // Save Configs to a file - if (response_id == Gtk::RESPONSE_OK) + Glib::ustring config; + std::fstream outfile; + + // Initalize Config for path + if (unix_file_system_detected()) + { + config_unix = entry_path->get_text(); + } + else { - Glib::ustring config; - std::fstream outfile; - // Initalize Config for path - if (unix_file_system_detected()) - { - config_unix = entry_path->get_text(); - } - else - { - - config_win32 = entry_path->get_text(); - } - // Open the config file - outfile.open("xe_config.json", std::ios_base::out); - /*OutPut contents to the file - Simple Contents of xe_config: - Longterm=x.x - Stable=x.x - Develop=x.x - Release_Path_Unix=/xxx/xxx - Release_Path_Win32=X:\xxx\xxx - */ - if (outfile.is_open()) - { - // Create json object - json out_data = json::parse(R"( + config_win32 = entry_path->get_text(); + } + // Open the config file + outfile.open("xe_config.json", std::ios_base::out); + /*OutPut contents to the file + Simple Contents of xe_config: + Longterm=x.x + Stable=x.x + Develop=x.x + Release_Path_Unix=/xxx/xxx + Release_Path_Win32=X:\xxx\xxx + */ + if (outfile.is_open()) + { + // Create json object + json out_data = json::parse(R"( { "Longterm":"", "Stable":"", @@ -73,31 +73,29 @@ void MyDialog::on_response(int response_id) } )"); - // Load config to json file - out_data["Longterm"] = entry_lts->get_text(); - out_data["Stable"] = entry_stable->get_text(); - out_data["Develop"] = entry_dev->get_text(); - out_data["Release_Path_Unix"] = config_unix; - out_data["Release_Path_Win32"] = config_win32; - outfile << out_data; - // outfile<<"This is the config file of Xe Release"<get_text(); - // outfile<<"Longterm="<get_text(); - // outfile<<"Stable="<get_text(); - // outfile<<"Develop="<get_text(); + out_data["Stable"] = entry_stable->get_text(); + out_data["Develop"] = entry_dev->get_text(); + out_data["Release_Path_Unix"] = config_unix; + out_data["Release_Path_Win32"] = config_win32; + outfile << out_data; + // outfile<<"This is the config file of Xe Release"<get_text(); + // outfile<<"Longterm="<get_text(); + // outfile<<"Stable="<get_text(); + // outfile<<"Develop="<get_widget_derived("prefs", dialog); - dialog->set_transient_for(parent); + MyPrefs *box = nullptr; + builder->get_widget_derived("prefs", box); - return dialog; + return box; } -void MyDialog::btnpath_clicked() +void MyPrefs::set_parent_win(Gtk::Window *parent){ + parent_win = parent; +} + +void MyPrefs::btnpath_clicked() { // Create a Dialog - dialog = Gtk::FileChooserNative::create("Select a folder", *this, + dialog = Gtk::FileChooserNative::create("Select a folder", *parent_win, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, "OK", "Cancel"); - dialog->signal_response().connect(sigc::mem_fun(*this, &MyDialog::dialog_response)); + dialog->signal_response().connect(sigc::mem_fun(*this, &MyPrefs::dialog_response)); dialog->show(); } -void MyDialog::dialog_response(int response_id) +void MyPrefs::dialog_response(int response_id) { if (response_id == Gtk::RESPONSE_ACCEPT) { diff --git a/XeRelease_Gtkmm3/src/MyDialog.hh b/XeRelease_Gtkmm3/src/MyDialog.hh index 8b3a4d9..f537fd4 100644 --- a/XeRelease_Gtkmm3/src/MyDialog.hh +++ b/XeRelease_Gtkmm3/src/MyDialog.hh @@ -6,43 +6,52 @@ using json = nlohmann::json; -class MyDialog : public Gtk::Dialog{ +class MyPrefs : public Gtk::Box +{ public: - MyDialog(BaseObjectType* cobject,const Glib::RefPtr& ref_builder); - static MyDialog * create(Gtk::Window& parent); + MyPrefs(BaseObjectType *cobject, const Glib::RefPtr &ref_builder); + static MyPrefs *create(); + void set_parent_win(Gtk::Window *parent); void init_json_data(json &data1); -protected: - void on_response(int response_id) override; + private: Glib::RefPtr ref_Glade; - //Child widgets - Gtk::Entry * entry_lts,* entry_stable,* entry_dev,* entry_path; - Gtk::Button * btnpath; + // Parent Window + Gtk::Window *parent_win; - //Strings to store path on Windows and Unix-Like systems - std::string config_win32,config_unix; + // Child widgets + Gtk::Entry *entry_lts, *entry_stable, *entry_dev, *entry_path; + Gtk::Button *btnpath, *btnok; - //Signal Handlers + // Strings to store path on Windows and Unix-Like systems + std::string config_win32, config_unix; + + // Signal Handlers Glib::RefPtr dialog; void btnpath_clicked(); void dialog_response(int response_id); + void btnok_clicked(); }; -class MsgBox : public Gtk::Dialog{ +class MsgBox : public Gtk::Dialog +{ public: MsgBox(Gtk::Window &parent); void Init(Glib::ustring msg); + protected: - //Signal Handler + // Signal Handler void on_response(int response_id) override; + private: - //Child Widgets + // Child Widgets Gtk::Image image; Gtk::Label msg_label; - Gtk::Box *vbox,hbox; + Gtk::Box *vbox, hbox; }; -static inline bool unix_file_system_detected(){ +static inline bool unix_file_system_detected() +{ #ifdef _WIN32 return false; #else diff --git a/XeRelease_Gtkmm3/src/MyWin.cc b/XeRelease_Gtkmm3/src/MyWin.cc index 86b3a42..e1cbc93 100644 --- a/XeRelease_Gtkmm3/src/MyWin.cc +++ b/XeRelease_Gtkmm3/src/MyWin.cc @@ -16,6 +16,7 @@ enum Releases MyWin::MyWin() : btn_box(Gtk::ORIENTATION_VERTICAL, 5), btn_ver("Xe-Ver"), + cfg_box(Gtk::ORIENTATION_HORIZONTAL, 5), msg_dialog(*this) { // Initalize window @@ -27,7 +28,7 @@ MyWin::MyWin() auto pixbuf = Gdk::Pixbuf::create_from_xpm_data(fly); auto sized = pixbuf->scale_simple(640, 360, Gdk::INTERP_BILINEAR); gtk_image_set_from_pixbuf(background.gobj(), sized->gobj()); - overlay.add(background); + back_overlay.add(background); // Get Local time time_t t; @@ -55,8 +56,27 @@ MyWin::MyWin() btn_ver.signal_clicked().connect(sigc::mem_fun(*this, &MyWin::main_releases)); // Show everything - add(stack1); + add(back_overlay); + back_overlay.add_overlay(stack1); stack1.add(overlay, "main_page", "WelCome"); + + //Add Config Page + prefs = MyPrefs::create(); + prefs->set_parent_win(this); + load_config(); + prefs->init_json_data(data); + cfg_box.pack_start(*prefs, Gtk::PACK_SHRINK); + cfg_box.set_opacity(0.7); + stack1.add(cfg_box, "config_page", "Config"); + + // Create Style for widgets + provider = Gtk::CssProvider::create(); + provider->load_from_resource("/org/gtk/daleclack/style.css"); + auto style1 = btn_box.get_style_context(); + style1->add_provider(provider, 1); + auto style2 = prefs->get_style_context(); + style2->add_provider(provider, 1); + switcher.set_stack(stack1); show_all_children(); @@ -135,10 +155,8 @@ void MyWin::background3() void MyWin::config_dialog() { load_config(); - auto dialog = MyDialog::create(*this); - dialog->init_json_data(data); - dialog->signal_hide().connect(sigc::bind(sigc::mem_fun(*this, &MyWin::on_window_hide), dialog)); - dialog->present(); + prefs->init_json_data(data); + stack1.set_visible_child(cfg_box); } void MyWin::load_config(){ diff --git a/XeRelease_Gtkmm3/src/MyWin.hh b/XeRelease_Gtkmm3/src/MyWin.hh index 9e3d8d3..9acbcea 100644 --- a/XeRelease_Gtkmm3/src/MyWin.hh +++ b/XeRelease_Gtkmm3/src/MyWin.hh @@ -9,34 +9,40 @@ public: MyWin(); private: - //Child Widgets + // Child Widgets Glib::RefPtr menu_builder; - //Main window + // Main window Gtk::Stack stack1; Gtk::StackSwitcher switcher; Gtk::Image background; - Gtk::Overlay overlay; - Gtk::Box btn_box; + Gtk::Overlay back_overlay, overlay; + Gtk::Box btn_box, cfg_box; Gtk::Label api_label; Gtk::ComboBoxText combo; Gtk::Button btn_ver; - //TitleBar and menu + // TitleBar and menu Gtk::HeaderBar header; Gtk::MenuButton menubtn; Gtk::PopoverMenu popover; void titlebar_init(); - //Dialogs + // Css Style + Glib::RefPtr provider; + + // Config Page + MyPrefs *prefs; + + // Dialogs MsgBox msg_dialog; - //Backgrounds + // Backgrounds void background1(); void background2(); void background3(); - //Version Configs + // Version Configs struct tm *local; char api_version[57]; json data; @@ -44,8 +50,8 @@ private: void load_config(); void config_dialog(); - //Signal Handlers - void on_window_hide(Gtk::Window* window); + // Signal Handlers + void on_window_hide(Gtk::Window *window); void about_dialog(); void main_releases(); }; \ No newline at end of file