mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 01:37:53 -06:00
Experiment with own ComboCtrl for preset_choice.
This commit is contained in:
parent
6053c8f54d
commit
e4b767e840
5 changed files with 118 additions and 2 deletions
|
@ -173,8 +173,7 @@ namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
|
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
|
||||||
{
|
{
|
||||||
// on_kill_focus(e);
|
e.Skip();// on_kill_focus(e);
|
||||||
e.Skip();
|
|
||||||
temp->GetToolTip()->Enable(true);
|
temp->GetToolTip()->Enable(true);
|
||||||
}), temp->GetId());
|
}), temp->GetId());
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <wx/filedlg.h>
|
#include <wx/filedlg.h>
|
||||||
|
|
||||||
#include <boost/algorithm/string/predicate.hpp>
|
#include <boost/algorithm/string/predicate.hpp>
|
||||||
|
#include "wxExtensions.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -38,6 +39,50 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle)
|
||||||
// preset chooser
|
// preset chooser
|
||||||
m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY);
|
m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY);
|
||||||
|
|
||||||
|
m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L("Presets"), wxDefaultPosition, wxSize(270, -1), wxCB_READONLY);
|
||||||
|
wxDataViewTreeCtrlComboPopup* popup = new wxDataViewTreeCtrlComboPopup;
|
||||||
|
if (popup != nullptr)
|
||||||
|
{
|
||||||
|
// FIXME If the following line is removed, the combo box popup list will not react to mouse clicks.
|
||||||
|
// On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10.
|
||||||
|
// comboCtrl->UseAltPopupWindow();
|
||||||
|
// comboCtrl->EnablePopupAnimation(false);
|
||||||
|
m_cc_presets_choice->SetPopupControl(popup);
|
||||||
|
popup->SetStringValue(from_u8("Text1"));
|
||||||
|
|
||||||
|
popup->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, popup](wxCommandEvent& evt)
|
||||||
|
{
|
||||||
|
auto selected = popup->GetItemText(popup->GetSelection());
|
||||||
|
if (selected != _(L("System presets")) && selected != _(L("Default presets")))
|
||||||
|
m_cc_presets_choice->SetText(selected);
|
||||||
|
// popup->OnDataViewTreeCtrlSelection(evt);
|
||||||
|
});
|
||||||
|
popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
||||||
|
popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); });
|
||||||
|
|
||||||
|
auto icons = new wxImageList(16, 16, true, 1);
|
||||||
|
popup->SetImageList(icons);
|
||||||
|
icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG));
|
||||||
|
icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG));
|
||||||
|
|
||||||
|
Freeze();
|
||||||
|
|
||||||
|
// get label of the currently selected item
|
||||||
|
auto selected = popup->GetItemText(popup->GetSelection());
|
||||||
|
auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets")));
|
||||||
|
auto tree_node1 = popup->AppendItem(root_sys, _("Sys1"), 0);
|
||||||
|
auto tree_node2 = popup->AppendContainer(root_sys, _("Sys2"), 0);
|
||||||
|
auto tree_node2_1 = popup->AppendItem(tree_node2, _("Sys2_1"), 0);
|
||||||
|
|
||||||
|
auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets")));
|
||||||
|
auto tree_node01 = popup->AppendContainer(root_def, _("Def1"), 0);
|
||||||
|
auto tree_node02 = popup->AppendContainer(root_def, _("Def2"), 0);
|
||||||
|
auto tree_node02_1 = popup->AppendItem(tree_node02, _("Def2_1"), 0);
|
||||||
|
|
||||||
|
Thaw();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
|
@ -82,6 +127,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle)
|
||||||
m_hsizer->AddSpacer(64);
|
m_hsizer->AddSpacer(64);
|
||||||
m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
|
m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
|
m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
m_hsizer->AddSpacer(64);
|
||||||
|
m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
|
||||||
|
|
||||||
//Horizontal sizer to hold the tree and the selected page.
|
//Horizontal sizer to hold the tree and the selected page.
|
||||||
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
|
m_hsizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <wx/treectrl.h>
|
#include <wx/treectrl.h>
|
||||||
#include <wx/imaglist.h>
|
#include <wx/imaglist.h>
|
||||||
#include <wx/statbox.h>
|
#include <wx/statbox.h>
|
||||||
|
#include <wx/dataview.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -95,6 +96,7 @@ protected:
|
||||||
wxButton* m_compatible_printers_btn;
|
wxButton* m_compatible_printers_btn;
|
||||||
wxButton* m_undo_btn;
|
wxButton* m_undo_btn;
|
||||||
wxButton* m_undo_to_sys_btn;
|
wxButton* m_undo_to_sys_btn;
|
||||||
|
wxComboCtrl* m_cc_presets_choice;
|
||||||
|
|
||||||
int m_icon_count;
|
int m_icon_count;
|
||||||
std::map<std::string, size_t> m_icon_index; // Map from an icon file name to its index
|
std::map<std::string, size_t> m_icon_index; // Map from an icon file name to its index
|
||||||
|
|
|
@ -109,3 +109,47 @@ void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt)
|
||||||
ProcessEvent(event);
|
ProcessEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// *** wxDataViewTreeCtrlComboPopup ***
|
||||||
|
|
||||||
|
const unsigned int wxDataViewTreeCtrlComboPopup::DefaultWidth = 270;
|
||||||
|
const unsigned int wxDataViewTreeCtrlComboPopup::DefaultHeight = 200;
|
||||||
|
const unsigned int wxDataViewTreeCtrlComboPopup::DefaultItemHeight = 22;
|
||||||
|
|
||||||
|
bool wxDataViewTreeCtrlComboPopup::Create(wxWindow* parent)
|
||||||
|
{
|
||||||
|
return wxDataViewTreeCtrl::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0), wxSize(270, -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight)
|
||||||
|
{
|
||||||
|
// matches owner wxComboCtrl's width
|
||||||
|
// and sets height dinamically in dependence of contained items count
|
||||||
|
return wxSize(DefaultWidth, DefaultHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewTreeCtrlComboPopup::OnKeyEvent(wxKeyEvent& evt)
|
||||||
|
{
|
||||||
|
// filters out all the keys which are not working properly
|
||||||
|
if (evt.GetKeyCode() == WXK_UP)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (evt.GetKeyCode() == WXK_DOWN)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
evt.Skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& evt)
|
||||||
|
{
|
||||||
|
wxComboCtrl* cmb = GetComboCtrl();
|
||||||
|
auto selected = GetItemText(GetSelection());
|
||||||
|
cmb->SetText(selected);
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <wx/checklst.h>
|
#include <wx/checklst.h>
|
||||||
#include <wx/combo.h>
|
#include <wx/combo.h>
|
||||||
|
#include <wx/dataview.h>
|
||||||
|
|
||||||
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup
|
||||||
{
|
{
|
||||||
|
@ -25,4 +26,27 @@ public:
|
||||||
void OnListBoxSelection(wxCommandEvent& evt);
|
void OnListBoxSelection(wxCommandEvent& evt);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// *** wxDataViewTreeCtrlComboBox ***
|
||||||
|
|
||||||
|
class wxDataViewTreeCtrlComboPopup: public wxDataViewTreeCtrl, public wxComboPopup
|
||||||
|
{
|
||||||
|
static const unsigned int DefaultWidth;
|
||||||
|
static const unsigned int DefaultHeight;
|
||||||
|
static const unsigned int DefaultItemHeight;
|
||||||
|
|
||||||
|
wxString m_text;
|
||||||
|
int m_cnt_open_items=2;
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool Create(wxWindow* parent);
|
||||||
|
virtual wxWindow* GetControl() { return this; }
|
||||||
|
virtual void SetStringValue(const wxString& value) { m_text = value; }
|
||||||
|
virtual wxString GetStringValue() const { return m_text; }
|
||||||
|
virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight);
|
||||||
|
|
||||||
|
virtual void OnKeyEvent(wxKeyEvent& evt);
|
||||||
|
void OnDataViewTreeCtrlSelection(wxCommandEvent& evt);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // slic3r_GUI_wxExtensions_hpp_
|
#endif // slic3r_GUI_wxExtensions_hpp_
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue