From 993c4d422efbc13b9d0c77ee6e97bef358af1661 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Fri, 13 Jan 2023 09:04:00 +0800 Subject: [PATCH] FIX: sync code of PhysicalPrintDialog Change-Id: I362c2485fed351b3533359be57a6e0b618d0fffa Signed-off-by: Stone Li --- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 92 +++++++++++++++--------- src/slic3r/GUI/PhysicalPrinterDialog.hpp | 6 +- 2 files changed, 62 insertions(+), 36 deletions(-) diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index 20c8e5a13..5304955bc 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -36,14 +36,14 @@ namespace Slic3r { namespace GUI { -#define BORDER_W 10 +#define BORDER_W FromDIP(10) //------------------------------------------ // PhysicalPrinterDialog //------------------------------------------ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent) : - DPIDialog(parent, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) + DPIDialog(parent, wxID_ANY, _L("Physical Printer"), wxDefaultPosition, wxSize(45 * wxGetApp().em_unit(), -1), wxDEFAULT_DIALOG_STYLE) { SetFont(wxGetApp().normal_font()); SetBackgroundColour(*wxWHITE); @@ -61,18 +61,17 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent) : label_top->SetFont(::Label::Body_13); label_top->SetForegroundColour(wxColour(38,46,48)); - m_input_area = new RoundedRectangle(this, wxColor(172, 172, 172), wxDefaultPosition, wxSize(-1,-1), 3, 1); + m_input_area = new RoundedRectangle(this, wxColour(172, 172, 172), wxDefaultPosition, wxSize(-1, -1), 3, 1); m_input_area->SetMinSize(wxSize(FromDIP(360), FromDIP(32))); wxBoxSizer *input_sizer_h = new wxBoxSizer(wxHORIZONTAL); - wxBoxSizer *input_sizer_v = new wxBoxSizer(wxVERTICAL); + wxBoxSizer *input_sizer_v = new wxBoxSizer(wxVERTICAL); - m_input_ctrl = new wxTextCtrl(m_input_area, -1, from_u8(preset_name), wxDefaultPosition, wxSize(wxSize(FromDIP(360), FromDIP(32)).x, -1), 0 | wxBORDER_NONE); - m_input_ctrl->SetBackgroundColour(wxColour(255, 255, 255)); + m_input_ctrl = new wxTextCtrl(m_input_area, -1, from_u8(preset_name), wxDefaultPosition, wxSize(FromDIP(360), -1), 0 | wxBORDER_NONE); + m_input_ctrl->SetBackgroundColour(*wxWHITE); m_input_ctrl->Bind(wxEVT_TEXT, [this](wxCommandEvent &) { update(); }); - - input_sizer_v->Add(m_input_ctrl, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, 12); + input_sizer_v->Add(m_input_ctrl, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, BORDER_W); input_sizer_h->Add(input_sizer_v, 0, wxALIGN_CENTER, 0); m_input_area->SetSizer(input_sizer_h); @@ -90,20 +89,45 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent) : m_optgroup = new ConfigOptionsGroup(this, _L("Print Host upload"), m_config); build_printhost_settings(m_optgroup); - wxStdDialogButtonSizer* btns = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL); - btnOK = static_cast(this->FindWindowById(wxID_OK, this)); - wxGetApp().UpdateDarkUI(btnOK); - btnOK->Bind(wxEVT_BUTTON, &PhysicalPrinterDialog::OnOK, this); + auto button_sizer = new wxBoxSizer(wxHORIZONTAL); - wxGetApp().UpdateDarkUI(static_cast(this->FindWindowById(wxID_CANCEL, this))); - (static_cast(this->FindWindowById(wxID_CANCEL, this)))->Hide(); + StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), + std::pair(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); - wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL); + StateColor btn_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), + std::pair(*wxWHITE, StateColor::Normal)); + + m_button_ok = new Button(this, _L("OK")); + m_button_ok->SetBackgroundColor(btn_bg_green); + m_button_ok->SetBorderColor(*wxWHITE); + m_button_ok->SetTextColor(*wxWHITE); + m_button_ok->SetFont(Label::Body_12); + m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetCornerRadius(FromDIP(12)); + + m_button_ok->Bind(wxEVT_LEFT_DOWN, &PhysicalPrinterDialog::OnOK, this); + + m_button_cancel = new Button(this, _L("Cancel")); + m_button_cancel->SetBackgroundColor(btn_bg_white); + m_button_cancel->SetBorderColor(wxColour(38, 46, 48)); + m_button_cancel->SetFont(Label::Body_12); + m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_cancel->SetCornerRadius(FromDIP(12)); + + m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](auto &e) { this->EndModal(wxID_NO);}); + + button_sizer->AddStretchSpacer(); + button_sizer->Add(m_button_ok, 0, wxALL, FromDIP(5)); + button_sizer->Add(m_button_cancel, 0, wxALL, FromDIP(5)); + + wxBoxSizer *topSizer = new wxBoxSizer(wxVERTICAL); // topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(input_sizer , 0, wxEXPAND | wxALL, BORDER_W); - topSizer->Add(m_optgroup->sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); - topSizer->Add(btns , 0, wxEXPAND | wxALL, BORDER_W); + topSizer->Add(input_sizer, 0, wxEXPAND | wxALL, BORDER_W); + topSizer->Add(m_optgroup->sizer, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W); + topSizer->Add(button_sizer, 0, wxEXPAND | wxALL, BORDER_W); Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {this->EndModal(wxID_NO);}); @@ -209,7 +233,7 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr const auto ca_file_hint = _u8L("HTTPS CA file is optional. It is only needed if you use HTTPS with a self-signed certificate."); - if (Http::ca_file_supported()) { + /*if (Http::ca_file_supported()) { option = m_optgroup->get_option("printhost_cafile"); option.opt.width = Field::def_width_wider(); Line cafile_line = m_optgroup->create_single_option_line(option); @@ -231,14 +255,14 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr cafile_line.append_widget(printhost_cafile_browse); //m_optgroup->append_line(cafile_line); - /*Line cafile_hint{ "", "" }; - cafile_hint.full_width = 1; - cafile_hint.widget = [ca_file_hint](wxWindow* parent) { - auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint); - auto sizer = new wxBoxSizer(wxHORIZONTAL); - sizer->Add(txt); - return sizer; - };*/ + //Line cafile_hint{ "", "" }; + //cafile_hint.full_width = 1; + //cafile_hint.widget = [ca_file_hint](wxWindow* parent) { + // auto txt = new wxStaticText(parent, wxID_ANY, ca_file_hint); + // auto sizer = new wxBoxSizer(wxHORIZONTAL); + // sizer->Add(txt); + // return sizer; + //}; //m_optgroup->append_line(cafile_hint); } else { @@ -259,7 +283,7 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr // return sizer; //}; //m_optgroup->append_line(line); - } + }*/ for (const std::string& opt_key : std::vector{ "printhost_user", "printhost_password" }) { option = m_optgroup->get_option(opt_key); @@ -386,12 +410,12 @@ void PhysicalPrinterDialog::update_preset_input() { m_valid_label->Show(!info_line.IsEmpty()); if (m_valid_type == NoValid) { - if (btnOK) - btnOK->Disable(); + if (m_button_ok) + m_button_ok->Disable(); } else { - if (btnOK) - btnOK->Enable(); + if (m_button_ok) + m_button_ok->Enable(); } } @@ -516,10 +540,10 @@ void PhysicalPrinterDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } -void PhysicalPrinterDialog::OnOK(wxEvent& event) +void PhysicalPrinterDialog::OnOK(wxMouseEvent& event) { wxGetApp().get_tab(Preset::TYPE_PRINTER)->save_preset("", false, false, true, m_preset_name ); - event.Skip(); + this->EndModal(wxID_YES); } }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.hpp b/src/slic3r/GUI/PhysicalPrinterDialog.hpp index ee88e34f7..3e6706de6 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.hpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.hpp @@ -8,6 +8,7 @@ #include "libslic3r/Preset.hpp" #include "GUI_Utils.hpp" #include "Widgets/RoundedRectangle.hpp" +#include "Widgets/Button.hpp" class wxString; class wxTextCtrl; @@ -38,10 +39,11 @@ class PhysicalPrinterDialog : public DPIDialog RoundedRectangle* m_input_area {nullptr}; wxStaticText* m_valid_label {nullptr}; wxTextCtrl* m_input_ctrl {nullptr}; - wxButton* btnOK {nullptr}; + Button* m_button_ok {nullptr}; + Button* m_button_cancel {nullptr}; void build_printhost_settings(ConfigOptionsGroup* optgroup); - void OnOK(wxEvent& event); + void OnOK(wxMouseEvent& event); public: PhysicalPrinterDialog(wxWindow* parent);