OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::DialogButtons Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Widgets/DialogButtons.hpp>

Inheritance diagram for Slic3r::GUI::DialogButtons:
Collaboration diagram for Slic3r::GUI::DialogButtons:

Public Member Functions

 DialogButtons (wxWindow *parent, std::vector< wxString > non_translated_labels, const wxString &primary_btn_label="", const int left_aligned_buttons_count=0)
wxBoxSizer * GetSizer () const
Button * GetButtonFromID (wxStandardID id)
Button * GetButtonFromLabel (wxString label)
Button * GetButtonFromIndex (int index)
Button * GetOK ()
Button * GetYES ()
Button * GetAPPLY ()
Button * GetCONFIRM ()
Button * GetNO ()
Button * GetCANCEL ()
Button * GetRETURN ()
Button * GetNEXT ()
Button * GetFIRST ()
Button * GetLAST ()
void SetPrimaryButton (wxString label)
void SetAlertButton (wxString label)
void SetLeftAlignedButtonsCount (int left_aligned_buttons_count)
void UpdateButtons ()
 ~DialogButtons ()

Private Member Functions

Button * PickFromList (std::set< wxStandardID > ID_list)
int FromDIP (int d)
void on_dpi_changed (wxDPIChangedEvent &event)
void on_keydown (wxKeyEvent &event)

Private Attributes

wxWindow * m_parent
wxBoxSizer * m_sizer
std::vector< Button * > m_buttons
wxString m_primary
wxString m_alert
int m_left_aligned_buttons_count
const std::map< wxString, wxStandardID > m_standardIDs
std::set< wxStandardID > m_primaryIDs
std::set< wxStandardID > m_alertIDs

Detailed Description

Constructor & Destructor Documentation

◆ DialogButtons()

Slic3r::GUI::DialogButtons::DialogButtons ( wxWindow * parent,
std::vector< wxString > non_translated_labels,
const wxString & primary_btn_label = "",
const int left_aligned_buttons_count = 0 )
20 : wxPanel(parent, wxID_ANY)
21{
22 m_parent = parent;
23 m_sizer = new wxBoxSizer(wxHORIZONTAL);
24 m_primary = primary_btn_translated_label;
25 m_alert = wxEmptyString;
26 m_left_aligned_buttons_count = left_aligned_buttons_count;
27 SetBackgroundColour(StateColor::darkModeColorFor(wxColour("#FFFFFF")));
28
29 // Add all to array
30 for (wxString label : non_translated_labels) {
31 Button* btn = new Button(this, _L(label));
32 wxString l = label;
33 l.LowerCase();
34 auto f = m_standardIDs.find(l);
35 if (f != m_standardIDs.end())
36 btn->SetId(f->second);
37 m_buttons.push_back(btn);
38 }
39
40 m_parent->Bind(wxEVT_DPI_CHANGED, &DialogButtons::on_dpi_changed, this);
41
42 SetSizer(m_sizer);
43
45}
#define _L(s)
Definition OBJ.cpp:34
wxBoxSizer * m_sizer
Definition DialogButtons.hpp:56
wxString m_primary
Definition DialogButtons.hpp:58
const std::map< wxString, wxStandardID > m_standardIDs
Definition DialogButtons.hpp:63
void on_dpi_changed(wxDPIChangedEvent &event)
Definition DialogButtons.cpp:51
wxString m_alert
Definition DialogButtons.hpp:59
std::vector< Button * > m_buttons
Definition DialogButtons.hpp:57
wxWindow * m_parent
Definition DialogButtons.hpp:55
void UpdateButtons()
Definition DialogButtons.cpp:141
int m_left_aligned_buttons_count
Definition DialogButtons.hpp:60
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124

References _L, StateColor::darkModeColorFor(), Slic3r::f(), m_alert, m_buttons, m_left_aligned_buttons_count, m_parent, m_primary, m_sizer, m_standardIDs, on_dpi_changed(), and UpdateButtons().

Here is the call graph for this function:

◆ ~DialogButtons()

Slic3r::GUI::DialogButtons::~DialogButtons ( )
47 {
48 m_parent->Unbind(wxEVT_DPI_CHANGED, &DialogButtons::on_dpi_changed, this);
49}

References m_parent, and on_dpi_changed().

Here is the call graph for this function:

Member Function Documentation

◆ FromDIP()

int Slic3r::GUI::DialogButtons::FromDIP ( int d)
private
171 {
172 return m_parent->FromDIP(d);
173}

References m_parent.

Referenced by UpdateButtons().

Here is the caller graph for this function:

◆ GetAPPLY()

Button * Slic3r::GUI::DialogButtons::GetAPPLY ( )
91{return GetButtonFromID(wxID_APPLY) ;}
Button * GetButtonFromID(wxStandardID id)
Definition DialogButtons.cpp:56

References GetButtonFromID().

Here is the call graph for this function:

◆ GetButtonFromID()

Button * Slic3r::GUI::DialogButtons::GetButtonFromID ( wxStandardID id)
56 {
57 for (Button* btn : m_buttons)
58 if (btn->GetId() == id)
59 return btn;
60 return nullptr;
61}

References m_buttons.

Referenced by GetAPPLY(), GetCANCEL(), GetCONFIRM(), GetNEXT(), GetNO(), GetOK(), GetRETURN(), GetYES(), and PickFromList().

Here is the caller graph for this function:

◆ GetButtonFromIndex()

Button * Slic3r::GUI::DialogButtons::GetButtonFromIndex ( int index)
70 {
71 if(index >= 0 && index < m_buttons.size())
72 return m_buttons[index];
73 else
74 return nullptr;
75}

References m_buttons.

Referenced by Slic3r::GUI::NetworkPluginRestartDialog::NetworkPluginRestartDialog(), Slic3r::GUI::NetworkPluginDownloadDialog::create_missing_plugin_ui(), Slic3r::GUI::NetworkPluginDownloadDialog::create_update_available_ui(), GetFIRST(), and GetLAST().

Here is the caller graph for this function:

◆ GetButtonFromLabel()

Button * Slic3r::GUI::DialogButtons::GetButtonFromLabel ( wxString label)
63 {
64 for (Button* btn : m_buttons)
65 if (btn->GetLabel() == translated_label)
66 return btn;
67 return nullptr;
68}

References m_buttons.

Referenced by SetAlertButton(), and SetPrimaryButton().

Here is the caller graph for this function:

◆ GetCANCEL()

Button * Slic3r::GUI::DialogButtons::GetCANCEL ( )
94{return GetButtonFromID(wxID_CANCEL) ;}

References GetButtonFromID().

Referenced by Slic3r::GUI::CrealityDiscoveryDialog::CrealityDiscoveryDialog(), Slic3r::GUI::OAuthDialog::OAuthDialog(), Slic3r::GUI::anonymous_namespace{SceneBenchmark.cpp}::SceneBenchmarkDialog::SceneBenchmarkDialog(), Slic3r::GUI::DiffPresetDialog::create_buttons(), and Slic3r::GUI::CreateFilamentPresetDialog::create_dialog_buttons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetCONFIRM()

Button * Slic3r::GUI::DialogButtons::GetCONFIRM ( )
92{return GetButtonFromID(wxID_APPLY) ;}

References GetButtonFromID().

Here is the call graph for this function:

◆ GetFIRST()

Button * Slic3r::GUI::DialogButtons::GetFIRST ( )
97{return GetButtonFromIndex(0) ;}
Button * GetButtonFromIndex(int index)
Definition DialogButtons.cpp:70

References GetButtonFromIndex().

Referenced by Slic3r::GUI::ShortcutCaptureDialog::ShortcutCaptureDialog(), and Slic3r::GUI::EditFilamentPresetDialog::create_dialog_buttons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLAST()

Button * Slic3r::GUI::DialogButtons::GetLAST ( )
98{return GetButtonFromIndex(m_buttons.size() - 1);}

References GetButtonFromIndex(), and m_buttons.

Here is the call graph for this function:

◆ GetNEXT()

Button * Slic3r::GUI::DialogButtons::GetNEXT ( )
96{return GetButtonFromID(wxID_FORWARD) ;}

References GetButtonFromID().

Here is the call graph for this function:

◆ GetNO()

Button * Slic3r::GUI::DialogButtons::GetNO ( )
93{return GetButtonFromID(wxID_NO) ;}

References GetButtonFromID().

Here is the call graph for this function:

◆ GetOK()

Button * Slic3r::GUI::DialogButtons::GetOK ( )
89{return GetButtonFromID(wxID_OK) ;}

References GetButtonFromID().

Referenced by Slic3r::GUI::Cornering_Test_Dlg::Cornering_Test_Dlg(), Slic3r::GUI::CrealityDiscoveryDialog::CrealityDiscoveryDialog(), Slic3r::GUI::CreatePresetSuccessfulDialog::CreatePresetSuccessfulDialog(), Slic3r::GUI::EditCalibrationHistoryDialog::EditCalibrationHistoryDialog(), Slic3r::GUI::FlowRateCalibrationDialog::FlowRateCalibrationDialog(), Slic3r::GUI::Input_Shaping_Damp_Test_Dlg::Input_Shaping_Damp_Test_Dlg(), Slic3r::GUI::Input_Shaping_Freq_Test_Dlg::Input_Shaping_Freq_Test_Dlg(), Slic3r::GUI::MaxVolumetricSpeed_Test_Dlg::MaxVolumetricSpeed_Test_Dlg(), Slic3r::GUI::MultiChoiceDialog::MultiChoiceDialog(), Slic3r::GUI::NewCalibrationHistoryDialog::NewCalibrationHistoryDialog(), Slic3r::GUI::PA_Calibration_Dlg::PA_Calibration_Dlg(), Slic3r::GUI::PlateNameEditDialog::PlateNameEditDialog(), Slic3r::GUI::PlateSettingsDialog::PlateSettingsDialog(), Slic3r::GUI::ProjectDropDialog::ProjectDropDialog(), Slic3r::GUI::PublishSettingsDialog::PublishSettingsDialog(), Slic3r::GUI::PurgeModeDialog::PurgeModeDialog(), Slic3r::GUI::RecenterDialog::RecenterDialog(), Slic3r::GUI::Retraction_Test_Dlg::Retraction_Test_Dlg(), Slic3r::GUI::SingleChoiceDialog::SingleChoiceDialog(), StepMeshDialog::StepMeshDialog(), Slic3r::GUI::Temp_Calibration_Dlg::Temp_Calibration_Dlg(), Slic3r::GUI::VFA_Test_Dlg::VFA_Test_Dlg(), Slic3r::GUI::SavePresetDialog::build(), Slic3r::GUI::PluginPickerDialog::build_capability_ui(), Slic3r::GUI::PluginPickerDialog::build_ui(), Slic3r::GUI::DiffPresetDialog::create_buttons(), Slic3r::GUI::CreateFilamentPresetDialog::create_dialog_buttons(), Slic3r::GUI::CreatePresetForPrinterDialog::create_dialog_buttons(), Slic3r::GUI::ExportConfigsDialog::create_dialog_buttons(), and Slic3r::GUI::CreatePrinterPresetDialog::create_page1_dialog_buttons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetRETURN()

Button * Slic3r::GUI::DialogButtons::GetRETURN ( )
95{return GetButtonFromID(wxID_BACKWARD);} // gets Return button

References GetButtonFromID().

Referenced by Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSizer()

wxBoxSizer * Slic3r::GUI::DialogButtons::GetSizer ( ) const
inline
25{ return m_sizer; }

References m_sizer.

◆ GetYES()

Button * Slic3r::GUI::DialogButtons::GetYES ( )
90{return GetButtonFromID(wxID_YES) ;}

References GetButtonFromID().

Here is the call graph for this function:

◆ on_dpi_changed()

void Slic3r::GUI::DialogButtons::on_dpi_changed ( wxDPIChangedEvent & event)
private
51 {
53 event.Skip();
54}

References UpdateButtons().

Referenced by DialogButtons(), and ~DialogButtons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_keydown()

void Slic3r::GUI::DialogButtons::on_keydown ( wxKeyEvent & event)
private
186 {
187 wxObject* current = e.GetEventObject();
188 int key = e.GetKeyCode();
189 int cnt = m_buttons.size();
190 if(cnt > 1){
191 int i = -1;
192 for (Button* btn : m_buttons){
193 i++;
194 if(btn->HasFocus())
195 break;
196 }
197 // possible issue if button hidden
198 if (key == WXK_LEFT) {m_buttons[i - 1 < 0 ? (cnt - 1) : i - 1]->SetFocus();}
199 else if (key == WXK_RIGHT) {m_buttons[i + 1 > (cnt - 1) ? 0 : i + 1]->SetFocus();}
200 }
201 e.Skip();
202}

References m_buttons.

Referenced by UpdateButtons().

Here is the caller graph for this function:

◆ PickFromList()

Button * Slic3r::GUI::DialogButtons::PickFromList ( std::set< wxStandardID > ID_list)
private
77 {
78 // Picks first button from given list
79 Button* b;
80 for (auto itr : ID_list) {
81 b = GetButtonFromID(itr);
82 if (b != nullptr)
83 return b;
84 }
85 return nullptr;
86}

References GetButtonFromID().

Referenced by SetAlertButton(), and SetPrimaryButton().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetAlertButton()

void Slic3r::GUI::DialogButtons::SetAlertButton ( wxString label)
123 {
124 // use _L("Create") translated text for custom buttons
125 // use non existing button name to disable alert styled button
126 if(m_buttons.size() == 1)
127 return;
128 Button* btn;
129 if(translated_label.IsEmpty()){ // prefer standard alert buttons if label empty
131 }else
132 btn = GetButtonFromLabel(translated_label);
133
134 if(btn == nullptr) return;
135
136 m_alert = translated_label;
137
139}
@ Alert
Definition Button.hpp:26
@ Choice
Definition Button.hpp:33
void SetStyle(const ButtonStyle style, const ButtonType type)
Definition Button.cpp:200
std::set< wxStandardID > m_alertIDs
Definition DialogButtons.hpp:110
Button * GetButtonFromLabel(wxString label)
Definition DialogButtons.cpp:63
Button * PickFromList(std::set< wxStandardID > ID_list)
Definition DialogButtons.cpp:77

References Alert, Choice, GetButtonFromLabel(), m_alert, m_alertIDs, m_buttons, PickFromList(), and Button::SetStyle().

Referenced by UpdateButtons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetLeftAlignedButtonsCount()

void Slic3r::GUI::DialogButtons::SetLeftAlignedButtonsCount ( int left_aligned_buttons_count)
175 {
176 m_left_aligned_buttons_count = left_aligned_buttons_count;
178}

References m_left_aligned_buttons_count, and UpdateButtons().

Here is the call graph for this function:

◆ SetPrimaryButton()

void Slic3r::GUI::DialogButtons::SetPrimaryButton ( wxString label)
100 {
101 // use _L("Create") translated text for custom buttons
102 // use non existing button name to disable primary styled button
103 Button* btn;
104 if(translated_label.IsEmpty()){ // prefer standard primary buttons if label empty
105 if(m_buttons.size() == 1)
106 btn = m_buttons.front();
107 else
109 }else
110 btn = GetButtonFromLabel(translated_label);
111
112 if(btn == nullptr) return;
113
114 m_primary = translated_label;
115
116 // apply focus only if there is no focused element exist. this prevents stealing focus from input boxes
117 if(m_parent->FindFocus() == nullptr)
118 btn->SetFocus();
119
121}
@ Confirm
Definition Button.hpp:25
std::set< wxStandardID > m_primaryIDs
Definition DialogButtons.hpp:102

References Choice, Confirm, GetButtonFromLabel(), m_buttons, m_parent, m_primary, m_primaryIDs, PickFromList(), and Button::SetStyle().

Referenced by UpdateButtons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateButtons()

void Slic3r::GUI::DialogButtons::UpdateButtons ( )
141 {
142 m_sizer->Clear();
143 SetBackgroundColour(StateColor::darkModeColorFor(wxColour("#FFFFFF")));
144
145 // Apply standard style to all
146 for (Button* btn : m_buttons) {
148 btn->Bind(wxEVT_KEY_DOWN, &DialogButtons::on_keydown, this);
149 }
150
151 int btn_gap = FromDIP(ButtonProps::ChoiceButtonGap());
152
154 m_sizer->AddSpacer(btn_gap);
155
156 for (int i = 0; i < m_buttons.size(); i++) {
158 m_sizer->AddStretchSpacer();
159
160 auto margin_to = (i >= m_left_aligned_buttons_count ? wxRIGHT : wxLEFT);
161 m_sizer->Add(m_buttons[i], 0, margin_to | wxTOP | wxBOTTOM | wxALIGN_CENTER_VERTICAL, btn_gap);
162 }
163
166
167 Layout();
168 Fit();
169}
@ Regular
Definition Button.hpp:24
static int ChoiceButtonGap()
Definition Button.hpp:19
int FromDIP(int d)
Definition DialogButtons.cpp:171
void SetPrimaryButton(wxString label)
Definition DialogButtons.cpp:100
void on_keydown(wxKeyEvent &event)
Definition DialogButtons.cpp:186
void SetAlertButton(wxString label)
Definition DialogButtons.cpp:123

References Choice, ButtonProps::ChoiceButtonGap(), StateColor::darkModeColorFor(), FromDIP(), m_alert, m_buttons, m_left_aligned_buttons_count, m_primary, m_sizer, on_keydown(), Regular, SetAlertButton(), and SetPrimaryButton().

Referenced by DialogButtons(), on_dpi_changed(), and SetLeftAlignedButtonsCount().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_alert

wxString Slic3r::GUI::DialogButtons::m_alert
private

◆ m_alertIDs

std::set<wxStandardID> Slic3r::GUI::DialogButtons::m_alertIDs
private
Initial value:
{
wxID_REMOVE,
wxID_DELETE,
wxID_ABORT,
wxID_STOP,
wxID_RESET,
wxID_CLEAR,
wxID_EXIT
}
110 {
111 wxID_REMOVE,
112 wxID_DELETE,
113 wxID_ABORT,
114 wxID_STOP,
115 wxID_RESET,
116 wxID_CLEAR,
117 wxID_EXIT
118 };

Referenced by SetAlertButton().

◆ m_buttons

◆ m_left_aligned_buttons_count

int Slic3r::GUI::DialogButtons::m_left_aligned_buttons_count
private

◆ m_parent

wxWindow* Slic3r::GUI::DialogButtons::m_parent
private

◆ m_primary

wxString Slic3r::GUI::DialogButtons::m_primary
private

◆ m_primaryIDs

std::set<wxStandardID> Slic3r::GUI::DialogButtons::m_primaryIDs
private
Initial value:
{
wxID_OK,
wxID_YES,
wxID_APPLY,
wxID_SAVE,
wxID_PRINT
}
102 {
103 wxID_OK,
104 wxID_YES,
105 wxID_APPLY,
106 wxID_SAVE,
107 wxID_PRINT
108 };

Referenced by SetPrimaryButton().

◆ m_sizer

wxBoxSizer* Slic3r::GUI::DialogButtons::m_sizer
private

◆ m_standardIDs

const std::map<wxString, wxStandardID> Slic3r::GUI::DialogButtons::m_standardIDs
private
63 {
64 // Choice
65 {"ok" , wxID_OK},
66 {"yes" , wxID_YES},
67 {"apply" , wxID_APPLY},
68 {"confirm" , wxID_APPLY}, // no id for confirm, reusing wxID_APPLY
69 {"no" , wxID_NO},
70 {"cancel" , wxID_CANCEL},
71 // Action
72 {"open" , wxID_PRINT},
73 {"open" , wxID_OPEN},
74 {"add" , wxID_ADD},
75 {"copy" , wxID_COPY},
76 {"new" , wxID_NEW},
77 {"save" , wxID_SAVE},
78 {"save as" , wxID_SAVEAS},
79 {"refresh" , wxID_REFRESH},
80 {"retry" , wxID_RETRY},
81 {"ignore" , wxID_IGNORE},
82 {"help" , wxID_HELP},
83 {"clone" , wxID_DUPLICATE},
84 {"duplicate" , wxID_DUPLICATE},
85 {"select all" , wxID_SELECTALL},
86 {"replace" , wxID_REPLACE},
87 {"replace all", wxID_REPLACE_ALL},
88 // Navigation
89 {"return" , wxID_BACKWARD}, // use return instead back. back mostly used as side of object in translations
90 {"next" , wxID_FORWARD},
91 // Alert / Negative
92 {"remove" , wxID_REMOVE},
93 {"delete" , wxID_DELETE},
94 {"abort" , wxID_ABORT},
95 {"stop" , wxID_STOP},
96 {"reset" , wxID_RESET},
97 {"clear" , wxID_CLEAR},
98 {"exit" , wxID_EXIT},
99 {"quit" , wxID_EXIT}
100 };

Referenced by DialogButtons().


The documentation for this class was generated from the following files: