Skip to content

Commit

Permalink
Move text color selection from ButtonsDescription to Preferences dial…
Browse files Browse the repository at this point in the history
…og (related to #5489)
  • Loading branch information
YuSanka committed Dec 30, 2020
1 parent 0331bce commit 6effa30
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
17 changes: 15 additions & 2 deletions src/slic3r/GUI/GUI_App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,12 @@ void GUI_App::update_label_colours_from_appconfig()
}
}

void GUI_App::update_label_colours()
{
for (Tab* tab : tabs_list)
tab->update_label_colours();
}

void GUI_App::init_fonts()
{
m_small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
Expand Down Expand Up @@ -1057,15 +1063,21 @@ void GUI_App::update_fonts(const MainFrame *main_frame)
m_code_font.SetPointSize(m_normal_font.GetPointSize());
}

void GUI_App::set_label_clr_modified(const wxColour& clr) {
void GUI_App::set_label_clr_modified(const wxColour& clr)
{
if (m_color_label_modified == clr)
return;
m_color_label_modified = clr;
auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue());
std::string str = clr_str.ToStdString();
app_config->set("label_clr_modified", str);
app_config->save();
}

void GUI_App::set_label_clr_sys(const wxColour& clr) {
void GUI_App::set_label_clr_sys(const wxColour& clr)
{
if (m_color_label_sys == clr)
return;
m_color_label_sys = clr;
auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue());
std::string str = clr_str.ToStdString();
Expand Down Expand Up @@ -1220,6 +1232,7 @@ void fatal_error(wxWindow* parent)
// Update the UI based on the current preferences.
void GUI_App::update_ui_from_settings(bool apply_free_camera_correction)
{
update_label_colours();
mainframe->update_ui_from_settings(apply_free_camera_correction);
}

Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GUI_App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class GUI_App : public wxApp
static bool dark_mode();
void init_label_colours();
void update_label_colours_from_appconfig();
void update_label_colours();
void init_fonts();
void update_fonts(const MainFrame *main_frame = nullptr);
void set_label_clr_modified(const wxColour& clr);
Expand Down
41 changes: 41 additions & 0 deletions src/slic3r/GUI/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void PreferencesDialog::build()
m_icon_size_sizer->ShowItems(app_config->get("use_custom_toolbar_size") == "1");

create_settings_mode_widget();
create_settings_text_color_widget();
}

#if ENABLE_ENVIRONMENT_MAP
Expand Down Expand Up @@ -379,6 +380,10 @@ void PreferencesDialog::accept()
app_config->set(it->first, it->second);

app_config->save();

wxGetApp().set_label_clr_sys(m_sys_colour->GetColour());
wxGetApp().set_label_clr_modified(m_mod_colour->GetColour());

EndModal(wxID_OK);

if (m_settings_layout_changed)
Expand Down Expand Up @@ -498,6 +503,42 @@ void PreferencesDialog::create_settings_mode_widget()
m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND);
}

void PreferencesDialog::create_settings_text_color_widget()
{
wxWindow* parent = m_optgroup_gui->parent();

wxStaticBox* stb = new wxStaticBox(parent, wxID_ANY, _L("Text color Settings"));
if (!wxOSX) stb->SetBackgroundStyle(wxBG_STYLE_PAINT);

wxSizer* sizer = new wxStaticBoxSizer(stb, wxVERTICAL);
wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(2, 10, 20);
sizer->Add(grid_sizer, 0, wxEXPAND);

auto sys_label = new wxStaticText(parent, wxID_ANY, _L("Value is the same as the system value"));
sys_label->SetForegroundColour(wxGetApp().get_label_clr_sys());
m_sys_colour = new wxColourPickerCtrl(parent, wxID_ANY, wxGetApp().get_label_clr_sys());
m_sys_colour->Bind(wxEVT_COLOURPICKER_CHANGED, [this, sys_label](wxCommandEvent&) {
sys_label->SetForegroundColour(m_sys_colour->GetColour());
sys_label->Refresh();
});

grid_sizer->Add(m_sys_colour, -1, wxALIGN_CENTRE_VERTICAL);
grid_sizer->Add(sys_label, -1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);

auto mod_label = new wxStaticText(parent, wxID_ANY, _L("Value was changed and is not equal to the system value or the last saved preset"));
mod_label->SetForegroundColour(wxGetApp().get_label_clr_modified());
m_mod_colour = new wxColourPickerCtrl(parent, wxID_ANY, wxGetApp().get_label_clr_modified());
m_mod_colour->Bind(wxEVT_COLOURPICKER_CHANGED, [this, mod_label](wxCommandEvent&) {
mod_label->SetForegroundColour(m_mod_colour->GetColour());
mod_label->Refresh();
});

grid_sizer->Add(m_mod_colour, -1, wxALIGN_CENTRE_VERTICAL);
grid_sizer->Add(mod_label, -1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);

m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND | wxTOP, em_unit());
}


} // GUI
} // Slic3r
4 changes: 4 additions & 0 deletions src/slic3r/GUI/Preferences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <map>

class wxRadioBox;
class wxColourPickerCtrl;

namespace Slic3r {
namespace GUI {
Expand All @@ -25,6 +26,8 @@ class PreferencesDialog : public DPIDialog
#endif // ENABLE_ENVIRONMENT_MAP
wxSizer* m_icon_size_sizer;
wxRadioBox* m_layout_mode_box;
wxColourPickerCtrl* m_sys_colour {nullptr};
wxColourPickerCtrl* m_mod_colour {nullptr};
bool isOSX {false};
bool m_settings_layout_changed {false};
bool m_seq_top_layer_only_changed{ false };
Expand All @@ -43,6 +46,7 @@ class PreferencesDialog : public DPIDialog
void layout();
void create_icon_size_slider();
void create_settings_mode_widget();
void create_settings_text_color_widget();
};

} // GUI
Expand Down
28 changes: 13 additions & 15 deletions src/slic3r/GUI/Tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,11 @@ void Tab::create_preset_tab()

m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); }));
m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); }));
m_question_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent)
{
m_question_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) {
ButtonsDescription dlg(this, m_icon_descriptions);
if (dlg.ShowModal() == wxID_OK) {
// Colors for ui "decoration"
for (Tab *tab : wxGetApp().tabs_list) {
tab->m_sys_label_clr = wxGetApp().get_label_clr_sys();
tab->m_modified_label_clr = wxGetApp().get_label_clr_modified();
tab->update_labels_colour();
}
}
}));
if (dlg.ShowModal() == wxID_OK)
wxGetApp().update_label_colours();
});
m_search_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent) { wxGetApp().plater()->search(false); });

// Colors for ui "decoration"
Expand Down Expand Up @@ -482,8 +475,13 @@ void Tab::OnActivate()
Refresh();
}

void Tab::update_labels_colour()
void Tab::update_label_colours()
{
if (m_sys_label_clr == wxGetApp().get_label_clr_sys() && m_modified_label_clr == wxGetApp().get_label_clr_modified())
return;
m_sys_label_clr = wxGetApp().get_label_clr_sys();
m_modified_label_clr = wxGetApp().get_label_clr_modified();

//update options "decoration"
for (const auto opt : m_options_list)
{
Expand Down Expand Up @@ -529,6 +527,8 @@ void Tab::update_labels_colour()
}
cur_item = m_treectrl->GetNextVisible(cur_item);
}

decorate();
}

void Tab::decorate()
Expand Down Expand Up @@ -992,9 +992,7 @@ void Tab::sys_color_changed()
m_treectrl->AssignImageList(m_icons);

// Colors for ui "decoration"
m_sys_label_clr = wxGetApp().get_label_clr_sys();
m_modified_label_clr = wxGetApp().get_label_clr_modified();
update_labels_colour();
update_label_colours();

// update options_groups
if (m_active_page)
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class Tab: public wxPanel
void toggle_show_hide_incompatible();
void update_show_hide_incompatible_button();
void update_ui_from_settings();
void update_labels_colour();
void update_label_colours();
void decorate();
void update_changed_ui();
void get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page);
Expand Down

0 comments on commit 6effa30

Please sign in to comment.