mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-17 03:37:54 -06:00
UnsavedChangesDialog improvements:
* support markup text and colored icons for cells + Extended BitmapTextRenderer for using of markup text
This commit is contained in:
parent
3cf2914a9e
commit
1674d2af29
7 changed files with 664 additions and 102 deletions
|
@ -31,11 +31,17 @@ WX_DEFINE_ARRAY_PTR(ModelNode*, ModelNodePtrArray);
|
|||
|
||||
class ModelNode
|
||||
{
|
||||
wxWindow* m_parent_win{ nullptr };
|
||||
|
||||
ModelNode* m_parent;
|
||||
ModelNodePtrArray m_children;
|
||||
wxBitmap m_empty_bmp;
|
||||
Preset::Type m_preset_type {Preset::TYPE_INVALID};
|
||||
|
||||
// saved values for colors if they exist
|
||||
wxString m_old_color;
|
||||
wxString m_new_color;
|
||||
|
||||
// TODO/FIXME:
|
||||
// the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
|
||||
// needs to know in advance if a node is or _will be_ a container.
|
||||
|
@ -47,23 +53,29 @@ class ModelNode
|
|||
// would be added to the control)
|
||||
bool m_container {true};
|
||||
|
||||
wxBitmap get_bitmap(const wxString& color);
|
||||
|
||||
public:
|
||||
|
||||
bool m_toggle {true};
|
||||
wxBitmap m_type_icon;
|
||||
wxBitmap m_group_icon;
|
||||
wxBitmap m_icon;
|
||||
wxBitmap m_old_color_bmp;
|
||||
wxBitmap m_new_color_bmp;
|
||||
wxString m_text;
|
||||
wxString m_old_value;
|
||||
wxString m_new_value;
|
||||
|
||||
// preset(root) node
|
||||
ModelNode(const wxString& text, Preset::Type preset_type);
|
||||
ModelNode(Preset::Type preset_type, const wxString& text);
|
||||
|
||||
// group node
|
||||
// category node
|
||||
ModelNode(ModelNode* parent, const wxString& text, const std::string& icon_name);
|
||||
|
||||
// group node
|
||||
ModelNode(ModelNode* parent, const wxString& text, bool is_option);
|
||||
ModelNode(ModelNode* parent, const wxString& text);
|
||||
|
||||
// option node
|
||||
ModelNode(ModelNode* parent, const wxString& text, const wxString& old_value, const wxString& new_value);
|
||||
|
||||
~ModelNode() {
|
||||
// free all our children nodes
|
||||
|
@ -75,15 +87,21 @@ public:
|
|||
}
|
||||
|
||||
bool IsContainer() const { return m_container; }
|
||||
bool IsToggle() const { return m_toggle; }
|
||||
bool IsToggled() const { return m_toggle; }
|
||||
void Toggle(bool toggle = true) { m_toggle = toggle; }
|
||||
bool IsRoot() const { return m_parent == nullptr; }
|
||||
Preset::Type type() const { return m_preset_type; }
|
||||
const wxString& text() const { return m_text; }
|
||||
|
||||
ModelNode* GetParent() { return m_parent; }
|
||||
ModelNodePtrArray& GetChildren() { return m_children; }
|
||||
ModelNode* GetNthChild(unsigned int n) { return m_children.Item(n); }
|
||||
unsigned int GetChildCount() const { return m_children.GetCount(); }
|
||||
|
||||
void Insert(ModelNode* child, unsigned int n) { m_children.Insert(child, n); }
|
||||
void Append(ModelNode* child) { m_children.Add(child); }
|
||||
void Insert(ModelNode* child, unsigned int n) { m_children.Insert(child, n); }
|
||||
void Append(ModelNode* child) { m_children.Add(child); }
|
||||
|
||||
void UpdateEnabling();
|
||||
};
|
||||
|
||||
|
||||
|
@ -93,15 +111,31 @@ public:
|
|||
|
||||
class UnsavedChangesModel : public wxDataViewModel
|
||||
{
|
||||
ModelNode* m_root;
|
||||
ScalableBitmap m_icon[5];
|
||||
wxWindow* m_parent_win {nullptr};
|
||||
std::vector<ModelNode*> m_preset_nodes;
|
||||
|
||||
wxDataViewCtrl* m_ctrl{ nullptr };
|
||||
|
||||
ModelNode *AddOption(ModelNode *group_node,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString new_value);
|
||||
ModelNode *AddOptionWithGroup(ModelNode *category_node,
|
||||
wxString group_name,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString new_value);
|
||||
ModelNode *AddOptionWithGroupAndCategory(ModelNode *preset_node,
|
||||
wxString category_name,
|
||||
wxString group_name,
|
||||
wxString option_name,
|
||||
wxString old_value,
|
||||
wxString new_value);
|
||||
|
||||
public:
|
||||
enum {
|
||||
colToggle,
|
||||
colTypeIcon,
|
||||
colGroupIcon,
|
||||
colMarkedText,
|
||||
colIconText,
|
||||
colOldValue,
|
||||
colNewValue,
|
||||
colMax
|
||||
|
@ -110,18 +144,28 @@ public:
|
|||
UnsavedChangesModel(wxWindow* parent);
|
||||
~UnsavedChangesModel();
|
||||
|
||||
virtual unsigned int GetColumnCount() const override { return colMax; }
|
||||
virtual wxString GetColumnType(unsigned int col) const override;
|
||||
void SetAssociatedControl(wxDataViewCtrl* ctrl) { m_ctrl = ctrl; }
|
||||
|
||||
virtual wxDataViewItem GetParent(const wxDataViewItem& item) const override;
|
||||
virtual unsigned int GetChildren(const wxDataViewItem& parent, wxDataViewItemArray& array) const override;
|
||||
wxDataViewItem AddPreset(Preset::Type type, wxString preset_name);
|
||||
wxDataViewItem AddOption(Preset::Type type, wxString category_name, wxString group_name, wxString option_name,
|
||||
wxString old_value, wxString new_value);
|
||||
|
||||
virtual void GetValue(wxVariant& variant, const wxDataViewItem& item, unsigned int col) const override;
|
||||
virtual bool SetValue(const wxVariant& variant, const wxDataViewItem& item, unsigned int col) override;
|
||||
void UpdateItemEnabling(wxDataViewItem item);
|
||||
|
||||
virtual bool IsEnabled(const wxDataViewItem& item, unsigned int col) const override;
|
||||
virtual bool IsContainer(const wxDataViewItem& item) const override;
|
||||
unsigned int GetColumnCount() const override { return colMax; }
|
||||
wxString GetColumnType(unsigned int col) const override;
|
||||
|
||||
wxDataViewItem GetParent(const wxDataViewItem& item) const override;
|
||||
unsigned int GetChildren(const wxDataViewItem& parent, wxDataViewItemArray& array) const override;
|
||||
|
||||
void GetValue(wxVariant& variant, const wxDataViewItem& item, unsigned int col) const override;
|
||||
bool SetValue(const wxVariant& variant, const wxDataViewItem& item, unsigned int col) override;
|
||||
|
||||
bool IsEnabled(const wxDataViewItem& item, unsigned int col) const override;
|
||||
bool IsContainer(const wxDataViewItem& item) const override;
|
||||
// Is the container just a header or an item with all columns
|
||||
// In our case it is an item with all columns
|
||||
bool HasContainerColumns(const wxDataViewItem& WXUNUSED(item)) const override { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -130,14 +174,30 @@ public:
|
|||
//------------------------------------------
|
||||
class UnsavedChangesDialog : public DPIDialog
|
||||
{
|
||||
wxDataViewCtrl* changes_tree{ nullptr };
|
||||
UnsavedChangesModel* changes_tree_model{ nullptr };
|
||||
wxDataViewCtrl* m_tree { nullptr };
|
||||
UnsavedChangesModel* m_tree_model { nullptr };
|
||||
|
||||
int m_save_btn_id { wxID_ANY };
|
||||
int m_move_btn_id { wxID_ANY };
|
||||
int m_continue_btn_id { wxID_ANY };
|
||||
|
||||
enum class Action {
|
||||
Save,
|
||||
Move,
|
||||
Continue
|
||||
} m_action;
|
||||
|
||||
public:
|
||||
UnsavedChangesDialog(Preset::Type type);
|
||||
~UnsavedChangesDialog() {}
|
||||
|
||||
void ProcessSelection(wxDataViewItem selection);
|
||||
void update(Preset::Type type);
|
||||
void item_value_changed(wxDataViewEvent &event);
|
||||
void close(Action action);
|
||||
|
||||
bool save_preset() const { return m_action == Action::Save; }
|
||||
bool move_preset() const { return m_action == Action::Move; }
|
||||
bool just_continue() const { return m_action == Action::Continue; }
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue