mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
GTK specific: Use the wxDataViewIconTextRenderer instead of the DataViewBitmapRenderer for "Old/NewValue" columns too.
+ update ofthe enabling for the "Save/Move" buttons
This commit is contained in:
parent
8b74ae4568
commit
f87ca111e1
2 changed files with 106 additions and 30 deletions
|
@ -42,14 +42,14 @@ static std::string orange = "#ed6b21";
|
||||||
|
|
||||||
static void color_string(wxString& str, const std::string& color)
|
static void color_string(wxString& str, const std::string& color)
|
||||||
{
|
{
|
||||||
#if defined(SUPPORTS_MARKUP) && /*!defined(__APPLE__)*/defined(wxHAS_GENERIC_DATAVIEWCTRL)
|
#if defined(SUPPORTS_MARKUP) && !defined(__APPLE__)
|
||||||
str = from_u8((boost::format("<span color=\"%1%\">%2%</span>") % color % into_u8(str)).str());
|
str = from_u8((boost::format("<span color=\"%1%\">%2%</span>") % color % into_u8(str)).str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void make_string_bold(wxString& str)
|
static void make_string_bold(wxString& str)
|
||||||
{
|
{
|
||||||
#if defined(SUPPORTS_MARKUP) && !defined(__APPLE__)//defined(wxHAS_GENERIC_DATAVIEWCTRL)
|
#if defined(SUPPORTS_MARKUP) && !defined(__APPLE__)
|
||||||
str = from_u8((boost::format("<b>%1%</b>") % into_u8(str)).str());
|
str = from_u8((boost::format("<b>%1%</b>") % into_u8(str)).str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,11 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text) :
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
wxIcon ModelNode::get_bitmap(const wxString& color);
|
||||||
|
#else
|
||||||
wxBitmap ModelNode::get_bitmap(const wxString& color)
|
wxBitmap ModelNode::get_bitmap(const wxString& color)
|
||||||
|
#endif // __linux__
|
||||||
{
|
{
|
||||||
/* It's supposed that standard size of an icon is 48px*16px for 100% scaled display.
|
/* It's supposed that standard size of an icon is 48px*16px for 100% scaled display.
|
||||||
* So set sizes for solid_colored icons used for filament preset
|
* So set sizes for solid_colored icons used for filament preset
|
||||||
|
@ -100,7 +104,16 @@ wxBitmap ModelNode::get_bitmap(const wxString& color)
|
||||||
unsigned char rgb[3];
|
unsigned char rgb[3];
|
||||||
BitmapCache::parse_color(into_u8(color), rgb);
|
BitmapCache::parse_color(into_u8(color), rgb);
|
||||||
// there is no need to scale created solid bitmap
|
// there is no need to scale created solid bitmap
|
||||||
return bmp_cache.mksolid(icon_width, icon_height, rgb, true);
|
wxBitmap bmp = bmp_cache.mksolid(icon_width, icon_height, rgb, true);
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
wxIcon icon;
|
||||||
|
icon.CopyFromBitmap(create_scaled_bitmap(icon_name));
|
||||||
|
return icon;
|
||||||
|
#else
|
||||||
|
return bmp;
|
||||||
|
#endif // __linux__
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// option node
|
// option node
|
||||||
|
@ -297,6 +310,13 @@ void UnsavedChangesModel::UpdateItemEnabling(wxDataViewItem item)
|
||||||
update_parents(node);
|
update_parents(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UnsavedChangesModel::IsEnabledItem(const wxDataViewItem& item)
|
||||||
|
{
|
||||||
|
assert(item.IsOk());
|
||||||
|
ModelNode* node = (ModelNode*)item.GetID();
|
||||||
|
return node->IsToggled();
|
||||||
|
}
|
||||||
|
|
||||||
void UnsavedChangesModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsigned int col) const
|
void UnsavedChangesModel::GetValue(wxVariant& variant, const wxDataViewItem& item, unsigned int col) const
|
||||||
{
|
{
|
||||||
assert(item.IsOk());
|
assert(item.IsOk());
|
||||||
|
@ -307,12 +327,19 @@ void UnsavedChangesModel::GetValue(wxVariant& variant, const wxDataViewItem& ite
|
||||||
case colToggle:
|
case colToggle:
|
||||||
variant = node->m_toggle;
|
variant = node->m_toggle;
|
||||||
break;
|
break;
|
||||||
case colIconText:
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
case colIconText:
|
||||||
variant << wxDataViewIconText(node->m_text, node->m_icon);
|
variant << wxDataViewIconText(node->m_text, node->m_icon);
|
||||||
|
break;
|
||||||
|
case colOldValue:
|
||||||
|
variant << wxDataViewIconText(node->m_old_value, node->m_old_color_bmp);
|
||||||
|
break;
|
||||||
|
case colNewValue:
|
||||||
|
variant << wxDataViewIconText(node->m_new_value, node->m_new_color_bmp);
|
||||||
|
break;
|
||||||
#else
|
#else
|
||||||
|
case colIconText:
|
||||||
variant << DataViewBitmapText(node->m_text, node->m_icon);
|
variant << DataViewBitmapText(node->m_text, node->m_icon);
|
||||||
#endif //__linux__
|
|
||||||
break;
|
break;
|
||||||
case colOldValue:
|
case colOldValue:
|
||||||
variant << DataViewBitmapText(node->m_old_value, node->m_old_color_bmp);
|
variant << DataViewBitmapText(node->m_old_value, node->m_old_color_bmp);
|
||||||
|
@ -320,6 +347,7 @@ void UnsavedChangesModel::GetValue(wxVariant& variant, const wxDataViewItem& ite
|
||||||
case colNewValue:
|
case colNewValue:
|
||||||
variant << DataViewBitmapText(node->m_new_value, node->m_new_color_bmp);
|
variant << DataViewBitmapText(node->m_new_value, node->m_new_color_bmp);
|
||||||
break;
|
break;
|
||||||
|
#endif //__linux__
|
||||||
|
|
||||||
default:
|
default:
|
||||||
wxLogError("UnsavedChangesModel::GetValue: wrong column %d", col);
|
wxLogError("UnsavedChangesModel::GetValue: wrong column %d", col);
|
||||||
|
@ -333,23 +361,35 @@ bool UnsavedChangesModel::SetValue(const wxVariant& variant, const wxDataViewIte
|
||||||
ModelNode* node = (ModelNode*)item.GetID();
|
ModelNode* node = (ModelNode*)item.GetID();
|
||||||
switch (col)
|
switch (col)
|
||||||
{
|
{
|
||||||
case colIconText: {
|
|
||||||
#ifdef __linux__
|
|
||||||
wxDataViewIconText data;
|
|
||||||
#else
|
|
||||||
DataViewBitmapText data;
|
|
||||||
#endif //__linux__
|
|
||||||
data << variant;
|
|
||||||
node->m_text = data.GetText();
|
|
||||||
#ifdef __linux__
|
|
||||||
node->m_icon = data.GetIcon();
|
|
||||||
#else
|
|
||||||
node->m_icon = data.GetBitmap();
|
|
||||||
#endif //__linux__
|
|
||||||
return true; }
|
|
||||||
case colToggle:
|
case colToggle:
|
||||||
node->m_toggle = variant.GetBool();
|
node->m_toggle = variant.GetBool();
|
||||||
return true;
|
return true;
|
||||||
|
#ifdef __linux__
|
||||||
|
case colIconText: {
|
||||||
|
wxDataViewIconText data;
|
||||||
|
data << variant;
|
||||||
|
node->m_icon = data.GetIcon();
|
||||||
|
node->m_text = data.GetText();
|
||||||
|
return true; }
|
||||||
|
case colOldValue: {
|
||||||
|
wxDataViewIconText data;
|
||||||
|
data << variant;
|
||||||
|
node->m_old_color_bmp = data.GetIcon();
|
||||||
|
node->m_old_value = data.GetText();
|
||||||
|
return true; }
|
||||||
|
case colNewValue: {
|
||||||
|
wxDataViewIconText data;
|
||||||
|
data << variant;
|
||||||
|
node->m_new_color_bmp = data.GetIcon();
|
||||||
|
node->m_new_value = data.GetText();
|
||||||
|
return true; }
|
||||||
|
#else
|
||||||
|
case colIconText: {
|
||||||
|
DataViewBitmapText data;
|
||||||
|
data << variant;
|
||||||
|
node->m_icon = data.GetBitmap();
|
||||||
|
node->m_text = data.GetText();
|
||||||
|
return true; }
|
||||||
case colOldValue: {
|
case colOldValue: {
|
||||||
DataViewBitmapText data;
|
DataViewBitmapText data;
|
||||||
data << variant;
|
data << variant;
|
||||||
|
@ -362,6 +402,7 @@ bool UnsavedChangesModel::SetValue(const wxVariant& variant, const wxDataViewIte
|
||||||
node->m_new_color_bmp = data.GetBitmap();
|
node->m_new_color_bmp = data.GetBitmap();
|
||||||
node->m_new_value = data.GetText();
|
node->m_new_value = data.GetText();
|
||||||
return true; }
|
return true; }
|
||||||
|
#endif //__linux__
|
||||||
default:
|
default:
|
||||||
wxLogError("UnsavedChangesModel::SetValue: wrong column");
|
wxLogError("UnsavedChangesModel::SetValue: wrong column");
|
||||||
}
|
}
|
||||||
|
@ -458,7 +499,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type)
|
||||||
m_tree->AssociateModel(m_tree_model);
|
m_tree->AssociateModel(m_tree_model);
|
||||||
m_tree_model->SetAssociatedControl(m_tree);
|
m_tree_model->SetAssociatedControl(m_tree);
|
||||||
|
|
||||||
m_tree->AppendToggleColumn(L"\u2714", UnsavedChangesModel::colToggle, wxDATAVIEW_CELL_ACTIVATABLE/*, 6 * em*/);//2610,11,12 //2714
|
m_tree->AppendToggleColumn(L"\u2714", UnsavedChangesModel::colToggle, wxDATAVIEW_CELL_ACTIVATABLE, 6 * em);//2610,11,12 //2714
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
wxDataViewIconTextRenderer* rd = new wxDataViewIconTextRenderer();
|
wxDataViewIconTextRenderer* rd = new wxDataViewIconTextRenderer();
|
||||||
|
@ -473,7 +514,7 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type)
|
||||||
m_tree->AppendColumn(new wxDataViewColumn("Old value", new BitmapTextRenderer(true), UnsavedChangesModel::colOldValue, 20 * em, wxALIGN_TOP));
|
m_tree->AppendColumn(new wxDataViewColumn("Old value", new BitmapTextRenderer(true), UnsavedChangesModel::colOldValue, 20 * em, wxALIGN_TOP));
|
||||||
m_tree->AppendColumn(new wxDataViewColumn("New value", new BitmapTextRenderer(true), UnsavedChangesModel::colNewValue, 20 * em, wxALIGN_TOP));
|
m_tree->AppendColumn(new wxDataViewColumn("New value", new BitmapTextRenderer(true), UnsavedChangesModel::colNewValue, 20 * em, wxALIGN_TOP));
|
||||||
|
|
||||||
m_tree->SetExpanderColumn(icon_text_clmn);
|
// m_tree->SetExpanderColumn(icon_text_clmn);
|
||||||
|
|
||||||
m_tree->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &UnsavedChangesDialog::item_value_changed, this);
|
m_tree->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &UnsavedChangesDialog::item_value_changed, this);
|
||||||
|
|
||||||
|
@ -486,14 +527,18 @@ UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type)
|
||||||
|
|
||||||
wxString label= from_u8((boost::format(_u8L("Save selected to preset:%1%"))% ("\"" + presets->get_selected_preset().name + "\"")).str());
|
wxString label= from_u8((boost::format(_u8L("Save selected to preset:%1%"))% ("\"" + presets->get_selected_preset().name + "\"")).str());
|
||||||
auto save_btn = new wxButton(this, m_save_btn_id = NewControlId(), label);
|
auto save_btn = new wxButton(this, m_save_btn_id = NewControlId(), label);
|
||||||
save_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Save); });
|
|
||||||
buttons->Insert(0, save_btn, 0, wxLEFT, 5);
|
buttons->Insert(0, save_btn, 0, wxLEFT, 5);
|
||||||
|
|
||||||
|
save_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Save); });
|
||||||
|
save_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_empty_selection); });
|
||||||
|
|
||||||
label = from_u8((boost::format(_u8L("Move selected to preset:%1%"))% ("\"NewSelectedPreset\"")).str());
|
label = from_u8((boost::format(_u8L("Move selected to preset:%1%"))% ("\"NewSelectedPreset\"")).str());
|
||||||
auto move_btn = new wxButton(this, m_move_btn_id = NewControlId(), label);
|
auto move_btn = new wxButton(this, m_move_btn_id = NewControlId(), label);
|
||||||
move_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Move); });
|
|
||||||
buttons->Insert(1, move_btn, 0, wxLEFT, 5);
|
buttons->Insert(1, move_btn, 0, wxLEFT, 5);
|
||||||
|
|
||||||
|
move_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Move); });
|
||||||
|
move_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_empty_selection); });
|
||||||
|
|
||||||
auto continue_btn = new wxButton(this, m_continue_btn_id = NewControlId(), _L("Continue without changes"));
|
auto continue_btn = new wxButton(this, m_continue_btn_id = NewControlId(), _L("Continue without changes"));
|
||||||
continue_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Continue); });
|
continue_btn->Bind(wxEVT_BUTTON, [this](wxEvent&) { close(Action::Continue); });
|
||||||
buttons->Insert(2, continue_btn, 0, wxLEFT, 5);
|
buttons->Insert(2, continue_btn, 0, wxLEFT, 5);
|
||||||
|
@ -519,6 +564,9 @@ void UnsavedChangesDialog::item_value_changed(wxDataViewEvent& event)
|
||||||
|
|
||||||
m_tree_model->UpdateItemEnabling(item);
|
m_tree_model->UpdateItemEnabling(item);
|
||||||
m_tree->Refresh();
|
m_tree->Refresh();
|
||||||
|
|
||||||
|
// update an enabling of the "save/move" buttons
|
||||||
|
m_empty_selection = get_selected_options().empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnsavedChangesDialog::close(Action action)
|
void UnsavedChangesDialog::close(Action action)
|
||||||
|
@ -670,12 +718,24 @@ void UnsavedChangesDialog::update(Preset::Type type)
|
||||||
for (const std::string& opt_key : presets->current_dirty_options()) {
|
for (const std::string& opt_key : presets->current_dirty_options()) {
|
||||||
const Search::Option& option = searcher.get_option(opt_key);
|
const Search::Option& option = searcher.get_option(opt_key);
|
||||||
|
|
||||||
m_tree_model->AddOption(type, option.category_local, option.group_local, option.label_local,
|
m_items_map.emplace(m_tree_model->AddOption(type, option.category_local, option.group_local, option.label_local,
|
||||||
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config));
|
get_string_value(opt_key, old_config), get_string_value(opt_key, new_config)), opt_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<std::string> UnsavedChangesDialog::get_selected_options()
|
||||||
|
{
|
||||||
|
std::vector<std::string> ret;
|
||||||
|
|
||||||
|
for (auto item : m_items_map) {
|
||||||
|
if (m_tree_model->IsEnabledItem(item.first))
|
||||||
|
ret.emplace_back(item.second);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void UnsavedChangesDialog::on_dpi_changed(const wxRect& suggested_rect)
|
void UnsavedChangesDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||||
{
|
{
|
||||||
const int& em = em_unit();
|
const int& em = em_unit();
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
#define slic3r_UnsavedChangesDialog_hpp_
|
#define slic3r_UnsavedChangesDialog_hpp_
|
||||||
|
|
||||||
#include <wx/dataview.h>
|
#include <wx/dataview.h>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "GUI_Utils.hpp"
|
#include "GUI_Utils.hpp"
|
||||||
#include "wxExtensions.hpp"
|
#include "wxExtensions.hpp"
|
||||||
|
@ -48,18 +50,24 @@ class ModelNode
|
||||||
// would be added to the control)
|
// would be added to the control)
|
||||||
bool m_container {true};
|
bool m_container {true};
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
wxIcon get_bitmap(const wxString& color);
|
||||||
|
#else
|
||||||
wxBitmap get_bitmap(const wxString& color);
|
wxBitmap get_bitmap(const wxString& color);
|
||||||
|
#endif //__linux__
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool m_toggle {true};
|
bool m_toggle {true};
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
wxIcon m_icon;
|
wxIcon m_icon;
|
||||||
|
wxIcon m_old_color_bmp;
|
||||||
|
wxIcon m_new_color_bmp;
|
||||||
#else
|
#else
|
||||||
wxBitmap m_icon;
|
wxBitmap m_icon;
|
||||||
#endif //__linux__
|
|
||||||
wxBitmap m_old_color_bmp;
|
wxBitmap m_old_color_bmp;
|
||||||
wxBitmap m_new_color_bmp;
|
wxBitmap m_new_color_bmp;
|
||||||
|
#endif //__linux__
|
||||||
wxString m_text;
|
wxString m_text;
|
||||||
wxString m_old_value;
|
wxString m_old_value;
|
||||||
wxString m_new_value;
|
wxString m_new_value;
|
||||||
|
@ -150,6 +158,7 @@ public:
|
||||||
wxString old_value, wxString new_value);
|
wxString old_value, wxString new_value);
|
||||||
|
|
||||||
void UpdateItemEnabling(wxDataViewItem item);
|
void UpdateItemEnabling(wxDataViewItem item);
|
||||||
|
bool IsEnabledItem(const wxDataViewItem& item);
|
||||||
|
|
||||||
unsigned int GetColumnCount() const override { return colMax; }
|
unsigned int GetColumnCount() const override { return colMax; }
|
||||||
wxString GetColumnType(unsigned int col) const override;
|
wxString GetColumnType(unsigned int col) const override;
|
||||||
|
@ -176,15 +185,20 @@ class UnsavedChangesDialog : public DPIDialog
|
||||||
wxDataViewCtrl* m_tree { nullptr };
|
wxDataViewCtrl* m_tree { nullptr };
|
||||||
UnsavedChangesModel* m_tree_model { nullptr };
|
UnsavedChangesModel* m_tree_model { nullptr };
|
||||||
|
|
||||||
|
bool m_empty_selection { false };
|
||||||
int m_save_btn_id { wxID_ANY };
|
int m_save_btn_id { wxID_ANY };
|
||||||
int m_move_btn_id { wxID_ANY };
|
int m_move_btn_id { wxID_ANY };
|
||||||
int m_continue_btn_id { wxID_ANY };
|
int m_continue_btn_id { wxID_ANY };
|
||||||
|
|
||||||
enum class Action {
|
enum class Action {
|
||||||
|
Undef,
|
||||||
Save,
|
Save,
|
||||||
Move,
|
Move,
|
||||||
Continue
|
Continue
|
||||||
} m_action;
|
} m_action {Action::Undef};
|
||||||
|
|
||||||
|
|
||||||
|
std::map<wxDataViewItem, std::string> m_items_map;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UnsavedChangesDialog(Preset::Type type);
|
UnsavedChangesDialog(Preset::Type type);
|
||||||
|
@ -198,6 +212,8 @@ public:
|
||||||
bool move_preset() const { return m_action == Action::Move; }
|
bool move_preset() const { return m_action == Action::Move; }
|
||||||
bool just_continue() const { return m_action == Action::Continue; }
|
bool just_continue() const { return m_action == Action::Continue; }
|
||||||
|
|
||||||
|
std::vector<std::string> get_selected_options();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||||
void on_sys_color_changed() override;
|
void on_sys_color_changed() override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue