From b6ef31f7b97ec52093c9537e02c578348a03076c Mon Sep 17 00:00:00 2001 From: "tao.jin" Date: Tue, 20 Dec 2022 13:13:48 +0800 Subject: [PATCH] ENH: refine physical printer dialog Change-Id: I34d122f83addab3db2952a6a2b91b59921d2a981 --- src/slic3r/GUI/BonjourDialog.cpp | 40 ++++++++- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 92 +++++++++++++-------- src/slic3r/GUI/PhysicalPrinterDialog.hpp | 6 +- src/slic3r/GUI/Widgets/RoundedRectangle.cpp | 11 +-- 4 files changed, 104 insertions(+), 45 deletions(-) diff --git a/src/slic3r/GUI/BonjourDialog.cpp b/src/slic3r/GUI/BonjourDialog.cpp index 516b1ab4a..123f45677 100644 --- a/src/slic3r/GUI/BonjourDialog.cpp +++ b/src/slic3r/GUI/BonjourDialog.cpp @@ -16,6 +16,7 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/Utils/Bonjour.hpp" +#include "Widgets/Button.hpp" namespace Slic3r { @@ -60,6 +61,8 @@ BonjourDialog::BonjourDialog(wxWindow *parent, Slic3r::PrinterTechnology tech) , timer_state(0) , tech(tech) { + SetBackgroundColour(*wxWHITE); + const int em = GUI::wxGetApp().em_unit(); list->SetMinSize(wxSize(80 * em, 30 * em)); @@ -78,10 +81,39 @@ BonjourDialog::BonjourDialog(wxWindow *parent, Slic3r::PrinterTechnology tech) vsizer->Add(list, 1, wxEXPAND | wxALL, em); - wxBoxSizer *button_sizer = new wxBoxSizer(wxHORIZONTAL); - button_sizer->Add(new wxButton(this, wxID_OK, "OK"), 0, wxALL, em); - button_sizer->Add(new wxButton(this, wxID_CANCEL, "Cancel"), 0, wxALL, em); - // ^ Note: The Ok/Cancel labels are translated by wxWidgets + + auto button_sizer = new wxBoxSizer(wxHORIZONTAL); + + StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), + std::pair(wxColour(0, 174, 66), StateColor::Normal)); + + 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)); + + auto 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, [this](auto &e) { this->EndModal(wxID_OK); }); + + auto 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_CANCEL); }); + + button_sizer->AddStretchSpacer(); + button_sizer->Add(m_button_ok, 0, wxALL, FromDIP(5)); + button_sizer->Add(m_button_cancel, 0, wxALL, FromDIP(5)); vsizer->Add(button_sizer, 0, wxALIGN_CENTER); SetSizerAndFit(vsizer); diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index b92613670..e13030eb7 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); @@ -389,12 +413,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(); } } @@ -518,10 +542,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); diff --git a/src/slic3r/GUI/Widgets/RoundedRectangle.cpp b/src/slic3r/GUI/Widgets/RoundedRectangle.cpp index a78020f86..a3c7c139a 100644 --- a/src/slic3r/GUI/Widgets/RoundedRectangle.cpp +++ b/src/slic3r/GUI/Widgets/RoundedRectangle.cpp @@ -6,9 +6,9 @@ BEGIN_EVENT_TABLE(RoundedRectangle, wxPanel) EVT_PAINT(RoundedRectangle::OnPaint) END_EVENT_TABLE() - RoundedRectangle::RoundedRectangle(wxWindow *parent, wxColour col, wxPoint pos, wxSize size, double radius, int type) - : wxWindow(parent, wxID_ANY, pos, size, wxBORDER_NONE) -{ + RoundedRectangle::RoundedRectangle(wxWindow *parent, wxColour col, wxPoint pos, wxSize size, double radius, int type) + : wxWindow(parent, wxID_ANY, pos, size, wxBORDER_NONE) +{ SetBackgroundColour(wxColour(255,255,255)); m_type = type; m_color = col; @@ -26,9 +26,10 @@ void RoundedRectangle::OnPaint(wxPaintEvent &evt) } //draw RoundedRectangle only board - if (m_type == 1) { + if (m_type == 1) { wxPaintDC dc(this); - dc.SetPen(m_color); + dc.SetPen(m_color); + dc.SetBrush(wxBrush(*wxTRANSPARENT_BRUSH)); dc.DrawRoundedRectangle(0, 0, GetSize().GetWidth(), GetSize().GetHeight(), m_radius); } } \ No newline at end of file