ENH: update send print dialog options GUI style
jira: [STUDIO-11444] Change-Id: I16f6e93edf09dc84786a0f7e6a14c9d0734542b8
This commit is contained in:
parent
64e7c5ac46
commit
6e9f2ecb5b
|
@ -618,7 +618,7 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater)
|
|||
|
||||
option_use_ams->setValue("on");
|
||||
|
||||
m_sizer_options = new wxGridSizer(0, 2, FromDIP(5), FromDIP(40));
|
||||
m_sizer_options = new wxGridSizer(0, 2, FromDIP(5), FromDIP(28));
|
||||
m_sizer_options->Add(option_timelapse, 0, wxEXPAND);
|
||||
m_sizer_options->Add(option_use_ams, 0, wxEXPAND);
|
||||
m_sizer_options->Add(option_auto_bed_level, 0, wxEXPAND);
|
||||
|
@ -4833,26 +4833,26 @@ std::string SelectMachineDialog::get_print_status_info(PrintDialogStatus status)
|
|||
#endif //__WINDOWS__
|
||||
Bind(wxEVT_PAINT, &PrintOption::OnPaint, this);
|
||||
|
||||
SetMinSize(wxSize(-1, FromDIP(60)));
|
||||
SetMaxSize(wxSize(-1, FromDIP(60)));
|
||||
SetMinSize(wxSize(-1, FromDIP(28)));
|
||||
SetMaxSize(wxSize(-1, FromDIP(28)));
|
||||
|
||||
m_ops = ops;
|
||||
m_param = param;
|
||||
|
||||
SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
|
||||
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
m_printoption_title = new Label(this, title);
|
||||
m_printoption_title->SetFont(Label::Body_13);
|
||||
m_printoption_title->SetFont(Label::Head_13);
|
||||
//m_printoption_title->SetBackgroundColour(0xF8F8F8);
|
||||
m_printoption_title->SetToolTip(tips);
|
||||
|
||||
m_printoption_item = new PrintOptionItem(this, m_ops, param);
|
||||
m_printoption_item->SetToolTip(tips);
|
||||
m_printoption_item->SetFont(Label::Body_13);
|
||||
|
||||
sizer->Add(m_printoption_title, 0, wxALIGN_LEFT, 0);
|
||||
sizer->AddSpacer(FromDIP(5));
|
||||
sizer->Add(m_printoption_item, 0, wxALIGN_LEFT, 0);
|
||||
sizer->Add(m_printoption_title, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 0);
|
||||
sizer->AddStretchSpacer();
|
||||
sizer->Add(m_printoption_item, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 0);
|
||||
|
||||
SetSizer(sizer);
|
||||
Layout();
|
||||
|
@ -4913,16 +4913,18 @@ bool PrintOption::contain_opt(const std::string &opt) const
|
|||
|
||||
void PrintOption::update_options(std::vector<POItem> ops, const wxString &tips)
|
||||
{
|
||||
if (m_ops != ops)
|
||||
{
|
||||
m_ops = ops;
|
||||
m_printoption_item->update_options(ops);
|
||||
}
|
||||
|
||||
if (m_printoption_title->GetToolTipText() != tips) { m_printoption_title->SetToolTip(tips); }
|
||||
if (m_printoption_item->GetToolTipText() != tips) { m_printoption_item->SetToolTip(tips); }
|
||||
}
|
||||
|
||||
void PrintOption::update_tooltip(const wxString &tips) {
|
||||
void PrintOption::update_tooltip(const wxString &tips)
|
||||
{
|
||||
if (m_printoption_title->GetToolTipText() != tips) { m_printoption_title->SetToolTip(tips); }
|
||||
if (m_printoption_item->GetToolTipText() != tips) { m_printoption_item->SetToolTip(tips); }
|
||||
}
|
||||
|
||||
std::string PrintOption::getValue()
|
||||
|
@ -4944,77 +4946,57 @@ int PrintOption::getValueInt()
|
|||
}
|
||||
|
||||
PrintOptionItem::PrintOptionItem(wxWindow *parent, std::vector<POItem> ops, std::string param)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
: ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(parent->FromDIP(70), parent->FromDIP(24)), 0, nullptr, wxCB_READONLY)
|
||||
{
|
||||
#ifdef __WINDOWS__
|
||||
SetDoubleBuffered(true);
|
||||
#endif //__WINDOWS__
|
||||
|
||||
m_ops = ops;
|
||||
Bind(wxEVT_COMBOBOX, &PrintOptionItem::on_combobox_changed, this);
|
||||
m_param = param;
|
||||
SetBackgroundColour(PRINT_OPT_ITEM_BG_GRAY);
|
||||
|
||||
Bind(wxEVT_PAINT, &PrintOptionItem::OnPaint, this);
|
||||
auto width = ops.size() * FromDIP(56) + FromDIP(8);
|
||||
auto height = FromDIP(22) + FromDIP(8);
|
||||
SetMinSize(wxSize(width, height));
|
||||
SetMaxSize(wxSize(width, height));
|
||||
Bind(wxEVT_ENTER_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_HAND); });
|
||||
Bind(wxEVT_LEAVE_WINDOW, [this](auto &e) { SetCursor(wxCURSOR_ARROW); });
|
||||
Bind(wxEVT_LEFT_DOWN, &PrintOptionItem::on_left_down, this);
|
||||
|
||||
m_selected_bk = ScalableBitmap(this, "print_options_bg", 22);
|
||||
update_options(ops);
|
||||
}
|
||||
|
||||
void PrintOptionItem::OnPaint(wxPaintEvent &event)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
doRender(dc);
|
||||
void PrintOptionItem::update_options(std::vector<POItem> ops) {
|
||||
if (m_ops != ops) {
|
||||
m_ops = ops;
|
||||
|
||||
ComboBox::Clear();
|
||||
selected_key.clear();
|
||||
for (const auto &entry : m_ops) { Append(entry.value); }
|
||||
|
||||
Layout();
|
||||
Fit();
|
||||
}
|
||||
}
|
||||
|
||||
void PrintOptionItem::render(wxDC &dc)
|
||||
{
|
||||
#ifdef __WXMSW__
|
||||
wxSize size = GetSize();
|
||||
wxMemoryDC memdc;
|
||||
wxBitmap bmp(size.x, size.y);
|
||||
memdc.SelectObject(bmp);
|
||||
memdc.Blit({0, 0}, size, &dc, {0, 0});
|
||||
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
void PrintOptionItem::on_combobox_changed(wxCommandEvent &evt) {
|
||||
const auto &new_key = get_key(evt.GetString());
|
||||
setValue(new_key);
|
||||
}
|
||||
|
||||
void PrintOptionItem::on_left_down(wxMouseEvent &evt)
|
||||
{
|
||||
if (!m_enabled) { return;}
|
||||
|
||||
auto pos = ClientToScreen(evt.GetPosition());
|
||||
auto rect = ClientToScreen(wxPoint(0, 0));
|
||||
auto select_size = GetSize().x / m_ops.size();
|
||||
|
||||
int i = 0;
|
||||
for (const auto& entry : m_ops) {
|
||||
auto left_edge = rect.x + i * select_size;
|
||||
auto right_edge = rect.x + (i + 1) * select_size;
|
||||
|
||||
if (pos.x > left_edge && pos.x < right_edge) {
|
||||
selected_key = entry.key;
|
||||
wxString PrintOptionItem::get_display_str(const std::string &key) const {
|
||||
for (const auto &entry : m_ops) {
|
||||
if (entry.key == key) { return entry.value; }
|
||||
}
|
||||
i++;
|
||||
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
std::string PrintOptionItem::get_key(const wxString &display_val) const {
|
||||
for (const auto &entry : m_ops) {
|
||||
if (entry.value == display_val) { return entry.key; }
|
||||
}
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void PrintOptionItem::setValue(std::string value) {
|
||||
if (selected_key != value) {
|
||||
selected_key = value;
|
||||
ComboBox::SetStringSelection(get_display_str(value));
|
||||
|
||||
if (!m_param.empty()) {
|
||||
AppConfig *config = wxGetApp().app_config;
|
||||
if (selected_key == "on") {
|
||||
if (selected_key == "auto") {
|
||||
config->set_str("print", m_param, "2");
|
||||
} else if (selected_key == "on") {
|
||||
config->set_str("print", m_param, "1");
|
||||
} else if (selected_key == "off") {
|
||||
config->set_str("print", m_param, "0");
|
||||
|
@ -5025,78 +5007,7 @@ void PrintOptionItem::on_left_down(wxMouseEvent &evt)
|
|||
event.SetString(selected_key);
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void PrintOptionItem::doRender(wxDC &dc)
|
||||
{
|
||||
auto size = GetSize();
|
||||
dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
|
||||
dc.SetBrush(GetBackgroundColour());
|
||||
dc.DrawRoundedRectangle(0, 0, size.x, size.y, FromDIP(5));
|
||||
|
||||
auto left = FromDIP(4);
|
||||
|
||||
int selected = 0;
|
||||
for (const auto &entry : m_ops) {
|
||||
if (entry.key == selected_key) {
|
||||
break;
|
||||
}
|
||||
selected++;
|
||||
}
|
||||
|
||||
/*selected*/
|
||||
auto selected_left = selected * FromDIP(56) + FromDIP(4);
|
||||
dc.DrawBitmap(m_selected_bk.bmp(), selected_left, FromDIP(4));
|
||||
|
||||
for (auto it = m_ops.begin(); it != m_ops.end(); ++it) {
|
||||
auto text_key = it->key;
|
||||
auto text_value = it->value;
|
||||
|
||||
if (text_key == selected_key) {
|
||||
|
||||
const wxColour& clr = wxGetApp().dark_mode() ? StateColor::darkModeColorFor("#00AE42") : "#00AE42";
|
||||
dc.SetPen(wxPen(clr));
|
||||
dc.SetTextForeground(clr);
|
||||
|
||||
dc.SetFont(::Label::Head_13);
|
||||
auto text_size = dc.GetTextExtent(text_value);
|
||||
auto text_left = left + (FromDIP(56) - text_size.x) / 2;
|
||||
auto text_top = (size.y - text_size.y) / 2;
|
||||
dc.DrawText(text_value, wxPoint(text_left, text_top));
|
||||
}
|
||||
else {
|
||||
const wxColour& clr = wxGetApp().dark_mode() ? StateColor::darkModeColorFor(*wxBLACK) : *wxBLACK;
|
||||
dc.SetPen(wxPen(clr));
|
||||
dc.SetTextForeground(clr);
|
||||
|
||||
dc.SetFont(::Label::Body_13);
|
||||
auto text_size = dc.GetTextExtent(text_value);
|
||||
auto text_left = left + (FromDIP(56) - text_size.x) / 2;
|
||||
auto text_top = (size.y - text_size.y) / 2;
|
||||
dc.DrawText(text_value, wxPoint(text_left, text_top));
|
||||
}
|
||||
|
||||
left += FromDIP(56);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintOptionItem::setValue(std::string value)
|
||||
{
|
||||
if (selected_key != value) {
|
||||
selected_key = value;
|
||||
wxCommandEvent event(EVT_SWITCH_PRINT_OPTION);
|
||||
event.SetString(selected_key);
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
std::string PrintOptionItem::getValue()
|
||||
{
|
||||
return selected_key;
|
||||
}
|
||||
|
||||
SendModeSwitchButton::SendModeSwitchButton(wxWindow *parent, wxString mode, bool sel)
|
||||
|
|
|
@ -207,44 +207,38 @@ static int get_brightness_value(wxImage image) {
|
|||
struct POItem
|
||||
{
|
||||
std::string key;
|
||||
wxString value;
|
||||
wxString value; // the display value
|
||||
|
||||
public:
|
||||
bool operator==(const POItem &other) const { return key == other.key && value == other.value; }
|
||||
};
|
||||
|
||||
class PrintOptionItem : public wxPanel
|
||||
class PrintOptionItem : public ComboBox
|
||||
{
|
||||
ScalableBitmap m_selected_bk;
|
||||
std::vector<POItem> m_ops;
|
||||
std::string selected_key;
|
||||
std::string m_param;
|
||||
|
||||
bool m_enabled = true;
|
||||
|
||||
public:
|
||||
PrintOptionItem(wxWindow *parent, std::vector<POItem> ops, std::string param = "");
|
||||
~PrintOptionItem(){};
|
||||
~PrintOptionItem() {};
|
||||
|
||||
public:
|
||||
bool Enable(bool enable) override { m_enabled = enable; return m_enabled;}
|
||||
bool Enable(bool enable) override { return ComboBox::Enable(enable); }
|
||||
|
||||
void setValue(std::string value);
|
||||
std::string getValue();
|
||||
std::string getValue() const { return selected_key; }
|
||||
|
||||
void msw_rescale() { m_selected_bk.msw_rescale(); Refresh();};
|
||||
void update_options(std::vector<POItem> ops){
|
||||
m_ops = ops;
|
||||
selected_key = "";
|
||||
auto width = ops.size() * FromDIP(56) + FromDIP(8);
|
||||
auto height = FromDIP(22) + FromDIP(8);
|
||||
SetMinSize(wxSize(width, height));
|
||||
SetMaxSize(wxSize(width, height));
|
||||
Refresh();
|
||||
};
|
||||
void msw_rescale() { ComboBox::Rescale();};
|
||||
void update_options(std::vector<POItem> ops);
|
||||
|
||||
bool CanBeFocused() const override { return false; }
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void render(wxDC &dc);
|
||||
void on_left_down(wxMouseEvent &evt);
|
||||
void doRender(wxDC &dc);
|
||||
void on_combobox_changed(wxCommandEvent &evt);
|
||||
|
||||
wxString get_display_str(const std::string& key) const;
|
||||
std::string get_key(const wxString &display_val) const;
|
||||
};
|
||||
|
||||
class PrintOption : public wxPanel
|
||||
|
@ -270,11 +264,13 @@ public:
|
|||
|
||||
bool contain_opt(const std::string& opt_str) const;
|
||||
void update_options(std::vector<POItem> ops, const wxString &tips);
|
||||
|
||||
void update_tooltip(const wxString &tips);
|
||||
|
||||
void msw_rescale() { m_printoption_item->msw_rescale(); };
|
||||
|
||||
// override funcs
|
||||
bool CanBeFocused() const override { return false; }
|
||||
|
||||
private:
|
||||
void OnPaint(wxPaintEvent &event);
|
||||
void render(wxDC &dc);
|
||||
|
|
Loading…
Reference in New Issue