Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsupermerill <merill@free.fr>2021-10-30 04:31:33 +0300
committersupermerill <merill@free.fr>2021-11-06 23:19:00 +0300
commit037847f80007943e3017bb09a6ab68cfba57b008 (patch)
tree069f9017136b6405e44a406fcc2825ec0cbba3e2 /src
parent43aeffd114fcfd5d97f2d499a94af1a77f2ec980 (diff)
Update to richtooltip:
* on windows, won't be as annoying, stealing the focus. * Fixing color & activation for ubuntu. * Also don't activate it by default on MACOS. May need more work for this os. supermerill/SuperSlicer#1720
Diffstat (limited to 'src')
-rw-r--r--src/libslic3r/AppConfig.cpp8
-rw-r--r--src/slic3r/GUI/Field.cpp54
-rw-r--r--src/slic3r/GUI/Field.hpp7
-rw-r--r--src/slic3r/GUI/Preferences.cpp2
4 files changed, 56 insertions, 15 deletions
diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp
index d8b00510b..9be3b5eae 100644
--- a/src/libslic3r/AppConfig.cpp
+++ b/src/libslic3r/AppConfig.cpp
@@ -200,11 +200,11 @@ void AppConfig::set_defaults()
if (get("use_rich_tooltip").empty())
set("use_rich_tooltip",
-#if __APPLE__
- "1"
-#else
+//#if __APPLE__
+ //"1"
+//#else
"0"
-#endif
+//#endif
);
}
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp
index 8cdb0a8a9..793652f26 100644
--- a/src/slic3r/GUI/Field.cpp
+++ b/src/slic3r/GUI/Field.cpp
@@ -206,8 +206,7 @@ wxString Field::get_tooltip_text(const wxString& default_string)
if (tooltip.length() > 0)
tooltip_text = tooltip + "\n" + _(L("default value")) + "\t: " +
- (boost::iends_with(opt_id, "_gcode") ? "\n" : "") + default_string +
- (boost::iends_with(opt_id, "_gcode") ? "" : "\n") +
+ (boost::iends_with(opt_id, "_gcode") ? "\n" : "") + default_string + "\n" +
_(L("parameter name")) + "\t: " + opt_id;
return tooltip_text;
@@ -218,6 +217,8 @@ wxString Field::get_rich_tooltip_text(const wxString& default_string)
wxString tooltip_text("");
wxString tooltip = _(m_opt.tooltip);
update_Slic3r_string(tooltip);
+ std::wstring wtooltip = tooltip.ToStdWstring();
+ std::wstring wtooltip_text;
std::string opt_id = m_opt_id;
auto hash_pos = opt_id.find("#");
@@ -226,8 +227,20 @@ wxString Field::get_rich_tooltip_text(const wxString& default_string)
opt_id += "]";
}
+ //add "\n" to long tooltip lines
+ int length = 0;
+ for (int i = 0; i < wtooltip.size(); i++) {
+ if (length >= 80 && wtooltip[i] == u' ')
+ wtooltip_text.push_back(u'\n');
+ else
+ wtooltip_text.push_back(wtooltip[i]);
+ length++;
+ if (wtooltip_text.back() == u'\n')
+ length = 0;
+ }
+
if (tooltip.length() > 0)
- tooltip_text = tooltip + "\n" + _(L("default value")) + ": " +
+ tooltip_text = wtooltip_text + "\n" + _(L("default value")) + ": " +
(boost::iends_with(opt_id, "_gcode") ? "\n" : "") + default_string;
return tooltip_text;
@@ -252,7 +265,11 @@ void Field::set_tooltip(const wxString& default_string, wxWindow* window) {
if (get_app_config()->get("use_rich_tooltip") == "1") {
this->m_rich_tooltip_timer.m_value = default_string;
window->Bind(wxEVT_ENTER_WINDOW, [this, window](wxMouseEvent& event) {
- if (wxGetActiveWindow() && !this->m_rich_tooltip_timer.IsRunning()) {
+ if (!this->m_rich_tooltip_timer.IsRunning()
+#ifdef __WXMSW__
+ && wxGetActiveWindow() //don't activate if the currrent app is not the focus. (deactivated for linux as it check the field instead)
+#endif /* __WXMSW__ */
+ ) {
this->m_rich_tooltip_timer.m_current_window = window;
this->m_rich_tooltip_timer.m_is_rich_tooltip_ready = true;
this->m_rich_tooltip_timer.StartOnce(500);
@@ -263,16 +280,22 @@ void Field::set_tooltip(const wxString& default_string, wxWindow* window) {
wxWindowList tipWindow = this->getWindow()->GetChildren();
if (tipWindow.size() > 0) {
wxWindow* tooltipWindow = tipWindow.GetLast()->GetData();
- if (tooltipWindow && tooltipWindow == this->m_rich_tooltip_timer.m_current_rich_tooltip)
+ if (tooltipWindow && tooltipWindow == this->m_rich_tooltip_timer.m_current_rich_tooltip) {
tooltipWindow->Hide();// DismissAndNotify();
+ }
}
});
- }else
+ } else
window->SetToolTip(get_tooltip_text(default_string));
}
void RichTooltipTimer::Notify() {
- if (wxGetActiveWindow() && this->m_is_rich_tooltip_ready && m_current_window) {
+ if (this->m_is_rich_tooltip_ready && m_current_window && !m_current_window->HasFocus()
+#ifdef __WXMSW__
+ && wxGetActiveWindow() //don't activate if the currrent app is not the focus. (deactivated for linux as it check the field instead)
+#endif /* __WXMSW__ */
+ ) {
+ this->m_previous_focus = wxGetActiveWindow()->FindFocus();
this->m_current_rich_tooltip = nullptr;
wxRichToolTip richTooltip(
m_field->get_rich_tooltip_title(this->m_value),
@@ -281,6 +304,23 @@ void RichTooltipTimer::Notify() {
richTooltip.ShowFor(m_current_window);
wxWindowList tipWindow = m_current_window->GetChildren();
this->m_current_rich_tooltip = tipWindow.GetLast()->GetData();
+ this->m_current_rich_tooltip->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BACKGROUND));
+ this->m_current_rich_tooltip->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
+ this->m_current_rich_tooltip->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& event) {
+ this->m_is_rich_tooltip_ready = false;
+ wxWindowList tipWindow = m_current_window->GetChildren();
+ if (tipWindow.size() > 0) {
+ wxWindow* tooltipWindow = tipWindow.GetLast()->GetData();
+ if (tooltipWindow && tooltipWindow == this->m_current_rich_tooltip) {
+ tooltipWindow->Hide();// DismissAndNotify();
+ }
+ }
+ });
+ this->m_current_rich_tooltip->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& event) {
+ CallAfter([this]() {
+ if (this->m_previous_focus) this->m_previous_focus->SetFocus();
+ });
+ });
}
}
diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp
index b963dd62c..3c361f94b 100644
--- a/src/slic3r/GUI/Field.hpp
+++ b/src/slic3r/GUI/Field.hpp
@@ -45,10 +45,11 @@ class RichTooltipTimer : public wxTimer
Field* m_field;
public:
bool m_is_rich_tooltip_ready = false;
- wxWindow* m_current_rich_tooltip = nullptr;
+ wxWindow* m_current_rich_tooltip = nullptr;
+ wxWindow* m_previous_focus = nullptr;
wxString m_value;
- wxWindow* m_window2 = nullptr; //for point
- wxWindow* m_current_window = nullptr; //for point
+ wxWindow* m_window2 = nullptr; //for point
+ wxWindow* m_current_window = nullptr; //for point
RichTooltipTimer(Field* field) : m_field(field) {};
void Notify() override;
diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp
index 49654a3b8..a48961ee1 100644
--- a/src/slic3r/GUI/Preferences.cpp
+++ b/src/slic3r/GUI/Preferences.cpp
@@ -484,7 +484,7 @@ void PreferencesDialog::build()
def.label = L("Use custom tooltip");
def.type = coBool;
def.tooltip = L("On some OS like MacOS or some Linux, tooltips can't stay on for a long time. This setting replaces native tooltips with custom dialogs to improve readability (only for settings)."
- "\nNote that for the number controls, you need to hover the arrows to get the custom tooltip.");
+ "\nNote that for the number controls, you need to hover the arrows to get the custom tooltip. Also, it keeps the focus but will give it back when it closes. It won't show up if you are editing the field.");
def.set_default_value(new ConfigOptionBool{ app_config->has("use_rich_tooltip") ? app_config->get("use_rich_tooltip") == "1" :
#if __APPLE__
true