mirror of
https://git.mirrors.martin98.com/https://github.com/bambulab/BambuStudio.git
synced 2025-08-05 18:10:39 +08:00
ENH: update the print options layout
jira: [STUDIO-11972] Change-Id: Idb15ad586d6c517f6f65ea940719d3c99230ab60
This commit is contained in:
parent
f97931d191
commit
5727210713
@ -1,4 +1,16 @@
|
||||
<svg width="56" height="22" viewBox="0 0 56 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<rect x="0.5" y="0.5" width="55" height="21" rx="3.5" fill="white"/>
|
||||
<rect x="0.5" y="0.5" width="55" height="21" rx="3.5" stroke="#00AE42"/>
|
||||
<svg width="44" height="22" viewBox="0 0 44 22" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<g clip-path="url(#clip0_2172_1443)">
|
||||
<mask id="mask0_2172_1443" style="mask-type:luminance" maskUnits="userSpaceOnUse" x="0" y="0" width="44" height="22">
|
||||
<path d="M44 0H0V22H44V0Z" fill="white"/>
|
||||
</mask>
|
||||
<g mask="url(#mask0_2172_1443)">
|
||||
<path d="M40.8572 0.5H3.14286C1.62408 0.5 0.39286 2.067 0.39286 4V18C0.39286 19.933 1.62408 21.5 3.14286 21.5H40.8572C42.376 21.5 43.6072 19.933 43.6072 18V4C43.6072 2.067 42.376 0.5 40.8572 0.5Z" fill="white"/>
|
||||
<path d="M40.8572 0.5H3.14286C1.62408 0.5 0.39286 2.067 0.39286 4V18C0.39286 19.933 1.62408 21.5 3.14286 21.5H40.8572C42.376 21.5 43.6072 19.933 43.6072 18V4C43.6072 2.067 42.376 0.5 40.8572 0.5Z" stroke="#00AE42"/>
|
||||
</g>
|
||||
</g>
|
||||
<defs>
|
||||
<clipPath id="clip0_2172_1443">
|
||||
<rect width="44" height="22" fill="white"/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 245 B After Width: | Height: | Size: 883 B |
@ -4561,8 +4561,6 @@ SelectMachineDialog::~SelectMachineDialog()
|
||||
|
||||
m_printoption_title = new Label(this, title);
|
||||
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->SetFont(Label::Body_13);
|
||||
@ -4574,6 +4572,8 @@ SelectMachineDialog::~SelectMachineDialog()
|
||||
SetSizer(sizer);
|
||||
Layout();
|
||||
Fit();
|
||||
|
||||
update_tooltip(tips);
|
||||
}
|
||||
|
||||
void PrintOption::OnPaint(wxPaintEvent &event)
|
||||
@ -4642,6 +4642,7 @@ void PrintOption::update_options(std::vector<POItem> ops, 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()
|
||||
@ -4662,68 +4663,152 @@ int PrintOption::getValueInt()
|
||||
}
|
||||
}
|
||||
|
||||
PrintOptionItem::PrintOptionItem(wxWindow *parent, std::vector<POItem> ops, std::string param)
|
||||
: ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(parent->FromDIP(70), parent->FromDIP(24)), 0, nullptr, wxCB_READONLY)
|
||||
#define PRINT_OPT_WIDTH FromDIP(44)
|
||||
PrintOptionItem::PrintOptionItem(wxWindow* parent, std::vector<POItem> ops, std::string param)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
|
||||
{
|
||||
Bind(wxEVT_COMBOBOX, &PrintOptionItem::on_combobox_changed, this);
|
||||
#ifdef __WINDOWS__
|
||||
SetDoubleBuffered(true);
|
||||
#endif //__WINDOWS__
|
||||
|
||||
m_ops = ops;
|
||||
m_param = param;
|
||||
update_options(ops);
|
||||
SetBackgroundColour(PRINT_OPT_ITEM_BG_GRAY);
|
||||
|
||||
Bind(wxEVT_PAINT, &PrintOptionItem::OnPaint, this);
|
||||
auto width = ops.size() * PRINT_OPT_WIDTH + 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);
|
||||
}
|
||||
|
||||
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::OnPaint(wxPaintEvent& event)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
doRender(dc);
|
||||
}
|
||||
|
||||
void PrintOptionItem::on_combobox_changed(wxCommandEvent &evt) {
|
||||
const auto &new_key = get_key(evt.GetString());
|
||||
setValue(new_key);
|
||||
}
|
||||
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 });
|
||||
|
||||
wxString PrintOptionItem::get_display_str(const std::string &key) const {
|
||||
for (const auto &entry : m_ops) {
|
||||
if (entry.key == key) { return entry.value; }
|
||||
{
|
||||
wxGCDC dc2(memdc);
|
||||
doRender(dc2);
|
||||
}
|
||||
|
||||
return wxEmptyString;
|
||||
memdc.SelectObject(wxNullBitmap);
|
||||
dc.DrawBitmap(bmp, 0, 0);
|
||||
#else
|
||||
doRender(dc);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string PrintOptionItem::get_key(const wxString &display_val) const {
|
||||
for (const auto &entry : m_ops) {
|
||||
if (entry.value == display_val) { return entry.key; }
|
||||
void PrintOptionItem::on_left_down(wxMouseEvent& evt)
|
||||
{
|
||||
if (!m_enable)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return std::string();
|
||||
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;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
wxCommandEvent event(EVT_SWITCH_PRINT_OPTION);
|
||||
event.SetString(selected_key);
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void PrintOptionItem::setValue(std::string value) {
|
||||
if (selected_key != value) {
|
||||
selected_key = value;
|
||||
ComboBox::SetStringSelection(get_display_str(value));
|
||||
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));
|
||||
|
||||
if (!m_param.empty()) {
|
||||
AppConfig *config = wxGetApp().app_config;
|
||||
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");
|
||||
}
|
||||
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 * PRINT_OPT_WIDTH + FromDIP(4);
|
||||
dc.DrawBitmap(m_selected_bk.bmp(), selected_left, (size.y - m_selected_bk.GetBmpHeight()) / 2);
|
||||
|
||||
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 + (PRINT_OPT_WIDTH - 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 + (PRINT_OPT_WIDTH - text_size.x) / 2;
|
||||
auto text_top = (size.y - text_size.y) / 2;
|
||||
dc.DrawText(text_value, wxPoint(text_left, text_top));
|
||||
}
|
||||
|
||||
wxCommandEvent event(EVT_SWITCH_PRINT_OPTION);
|
||||
event.SetString(selected_key);
|
||||
event.SetEventObject(GetParent());
|
||||
wxPostEvent(GetParent(), event);
|
||||
left += PRINT_OPT_WIDTH;
|
||||
}
|
||||
}
|
||||
|
||||
void PrintOptionItem::setValue(std::string value)
|
||||
{
|
||||
if (selected_key != value) {
|
||||
selected_key = value;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,32 +134,51 @@ struct POItem
|
||||
bool operator==(const POItem &other) const { return key == other.key && value == other.value; }
|
||||
};
|
||||
|
||||
class PrintOptionItem : public ComboBox
|
||||
class PrintOptionItem : public wxPanel
|
||||
{
|
||||
std::vector<POItem> m_ops;
|
||||
std::string selected_key;
|
||||
std::string m_param;
|
||||
|
||||
public:
|
||||
PrintOptionItem(wxWindow *parent, std::vector<POItem> ops, std::string param = "");
|
||||
PrintOptionItem(wxWindow* parent, std::vector<POItem> ops, std::string param = "");
|
||||
~PrintOptionItem() {};
|
||||
|
||||
public:
|
||||
bool Enable(bool enable) override { return ComboBox::Enable(enable); }
|
||||
|
||||
void setValue(std::string value);
|
||||
std::string getValue() const { return selected_key; }
|
||||
void update_options(std::vector<POItem> ops) {
|
||||
if (m_ops != 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);
|
||||
void enable(bool able) {
|
||||
if (m_enable != able)
|
||||
{
|
||||
m_enable = able;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
bool CanBeFocused() const override { return false; }
|
||||
void msw_rescale() { m_selected_bk.msw_rescale(); Refresh(); };
|
||||
|
||||
private:
|
||||
void on_combobox_changed(wxCommandEvent &evt);
|
||||
void OnPaint(wxPaintEvent& event);
|
||||
void render(wxDC& dc);
|
||||
void on_left_down(wxMouseEvent& evt);
|
||||
void doRender(wxDC& dc);
|
||||
|
||||
wxString get_display_str(const std::string& key) const;
|
||||
std::string get_key(const wxString &display_val) const;
|
||||
private:
|
||||
ScalableBitmap m_selected_bk;
|
||||
std::vector<POItem> m_ops;
|
||||
std::string selected_key;
|
||||
std::string m_param;
|
||||
|
||||
bool m_enable = true;
|
||||
};
|
||||
|
||||
class PrintOption : public wxPanel
|
||||
@ -175,7 +194,7 @@ public:
|
||||
~PrintOption(){};
|
||||
|
||||
public:
|
||||
void enable(bool en) { m_printoption_item->Enable(en); }
|
||||
void enable(bool en) { m_printoption_item->enable(en); }
|
||||
|
||||
void setValue(std::string value);
|
||||
std::string getValue();
|
||||
|
Loading…
x
Reference in New Issue
Block a user