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

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

Inheritance diagram for Slic3r::GUI::MarkdownTip:
Collaboration diagram for Slic3r::GUI::MarkdownTip:

Static Public Member Functions

static bool ShowTip (std::string const &tip, std::string const &tooltip, wxPoint pos)
static void ExitTip ()
static void Reload ()
static void Recreate (wxWindow *parent)
static wxWindow * AttachTo (wxWindow *parent)
static wxWindow * DetachFrom (wxWindow *parent)

Private Member Functions

 MarkdownTip ()
 ~MarkdownTip ()
void LoadStyle ()
bool ShowTip (wxPoint pos, std::string const &tip, std::string const &tooltip)
std::string LoadTip (std::string const &tip, std::string const &tooltip)
void RunScript (std::string const &script)
wxWebView * CreateTipView (wxWindow *parent)
void OnLoaded (wxWebViewEvent &event)
void OnTitleChanged (wxWebViewEvent &event)
void OnError (wxWebViewEvent &event)
void OnTimer (wxTimerEvent &event)

Static Private Member Functions

static MarkdownTip * markdownTip (bool create=true)

Private Attributes

wxWebView * _tipView = nullptr
std::string _lastTip
std::string _pendingScript = " "
std::string _language
wxPoint _requestPos
double _lastHeight = 0
wxTimer * _timer = nullptr
bool _hide = false
bool _data_dir = false

Detailed Description

Constructor & Destructor Documentation

◆ MarkdownTip()

Slic3r::GUI::MarkdownTip::MarkdownTip ( )
private
87 : wxPopupTransientWindow(wxGetApp().mainframe, wxBORDER_NONE)
88{
89 wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);
90
91 _tipView = CreateTipView(this);
92 topsizer->Add(_tipView, wxSizerFlags().Expand().Proportion(1));
93
94 SetSizer(topsizer);
95 SetSize({400, 300});
96
97 LoadStyle();
98
99 _timer = new wxTimer;
100 _timer->Bind(wxEVT_TIMER, &MarkdownTip::OnTimer, this);
101}
wxWebView * CreateTipView(wxWindow *parent)
Definition MarkdownTip.cpp:240
void LoadStyle()
Definition MarkdownTip.cpp:105
void OnTimer(wxTimerEvent &event)
Definition MarkdownTip.cpp:285
wxTimer * _timer
Definition MarkdownTip.hpp:67
wxWebView * _tipView
Definition MarkdownTip.hpp:61

References _timer, _tipView, CreateTipView(), LoadStyle(), and OnTimer().

Referenced by AttachTo(), DetachFrom(), and markdownTip().

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

◆ ~MarkdownTip()

Slic3r::GUI::MarkdownTip::~MarkdownTip ( )
private
103{ delete _timer; }

References _timer.

Member Function Documentation

◆ AttachTo()

wxWindow * Slic3r::GUI::MarkdownTip::AttachTo ( wxWindow * parent)
static
339{
340 MarkdownTip& tip = *markdownTip();
341 tip._tipView = tip.CreateTipView(parent);
342 tip._pendingScript = " ";
343 return tip._tipView;
344}
MarkdownTip()
Definition MarkdownTip.cpp:86
static MarkdownTip * markdownTip(bool create=true)
Definition MarkdownTip.cpp:302

References MarkdownTip(), _pendingScript, _tipView, CreateTipView(), and markdownTip().

Here is the call graph for this function:

◆ CreateTipView()

wxWebView * Slic3r::GUI::MarkdownTip::CreateTipView ( wxWindow * parent)
private
241{
242 wxWebView *tipView = WebView::CreateWebView(parent, "");
243 Bind(wxEVT_WEBVIEW_LOADED, &MarkdownTip::OnLoaded, this);
244 Bind(wxEVT_WEBVIEW_TITLE_CHANGED, &MarkdownTip::OnTitleChanged, this);
245 Bind(wxEVT_WEBVIEW_ERROR, &MarkdownTip::OnError, this);
246 return tipView;
247}
void OnTitleChanged(wxWebViewEvent &event)
Definition MarkdownTip.cpp:253
void OnLoaded(wxWebViewEvent &event)
Definition MarkdownTip.cpp:249
void OnError(wxWebViewEvent &event)
Definition MarkdownTip.cpp:281
static wxWebView * CreateWebView(wxWindow *parent, wxString const &url)
Definition WebView.cpp:313

References WebView::CreateWebView(), OnError(), OnLoaded(), and OnTitleChanged().

Referenced by MarkdownTip(), and AttachTo().

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

◆ DetachFrom()

wxWindow * Slic3r::GUI::MarkdownTip::DetachFrom ( wxWindow * parent)
static
347{
348 MarkdownTip& tip = *markdownTip();
349 if (tip._tipView->GetParent() == parent) {
350 tip.Destroy();
351 }
352 return NULL;
353}

References MarkdownTip(), _tipView, and markdownTip().

Here is the call graph for this function:

◆ ExitTip()

void Slic3r::GUI::MarkdownTip::ExitTip ( )
static
319{
320 //if (auto tip = markdownTip(false))
321 // tip->Destroy();
322}

◆ LoadStyle()

void Slic3r::GUI::MarkdownTip::LoadStyle ( )
private
106{
107 _language = GUI::into_u8(GUI::wxGetApp().current_language_code());
108 fs::path ph(data_dir());
109 ph /= "resources/tooltip/common/styled.html";
110 _data_dir = true;
111 if (!fs::exists(ph)) {
112 ph = resources_dir();
113 ph /= "tooltip/styled.html";
114 _data_dir = false;
115 }
116 _tipView->LoadURL(file_url_from_path(ph));
117 _lastTip.clear();
118}
std::string _language
Definition MarkdownTip.hpp:64
bool _data_dir
Definition MarkdownTip.hpp:69
std::string _lastTip
Definition MarkdownTip.hpp:62
wxString file_url_from_path(const boost::filesystem::path &path)
Definition GUI.cpp:569
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
const std::string & data_dir()
Definition utils.cpp:365
const std::string & resources_dir()
Definition utils.cpp:296

References _data_dir, _language, _lastTip, _tipView, Slic3r::data_dir(), Slic3r::GUI::file_url_from_path(), Slic3r::GUI::into_u8(), and Slic3r::resources_dir().

Referenced by MarkdownTip().

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

◆ LoadTip()

std::string Slic3r::GUI::MarkdownTip::LoadTip ( std::string const & tip,
std::string const & tooltip )
private
173{
174 fs::path ph;
175 wxString file;
176 wxFile f;
177 if (_data_dir) {
178 if (!_language.empty()) {
179 ph = data_dir();
180 ph /= "resources/tooltip/" + _language + "/" + tip + ".md";
181 file = from_u8(ph.string());
182 if (wxFile::Exists(file) && f.Open(file)) {
183 std::string content(f.Length(), 0);
184 f.Read(&content[0], content.size());
185 return content;
186 }
187 }
188 ph = data_dir();
189 ph /= "resources/tooltip/common/" + tip + ".md";
190 file = from_u8(ph.string());
191 if (wxFile::Exists(file) && f.Open(file)) {
192 std::string content(f.Length(), 0);
193 f.Read(&content[0], content.size());
194 return content;
195 }
196 }
197 /*
198 file = var("tooltips.zip");
199 if (wxFile::Exists(file) && f.Open(file)) {
200 wxFileInputStream fs(f);
201 wxZipInputStream zip(fs);
202 file = tip + ".md";
203 while (auto e = zip.GetNextEntry()) {
204 if (e->GetName() == file) {
205 if (zip.OpenEntry(*e)) {
206 std::string content(f.Length(), 0);
207 zip.Read(&content[0], content.size());
208 return content;
209 }
210 break;
211 }
212 }
213 }
214 */
215 ph = resources_dir();
216 ph /= "tooltip/" + _language + "/" + tip + ".md";
217 file = from_u8(ph.string());
218 if (wxFile::Exists(file) && f.Open(file)) {
219 std::string content(f.Length(), 0);
220 f.Read(&content[0], content.size());
221 return content;
222 }
223 ph = resources_dir();
224 ph /= "tooltip/" + tip + ".md";
225 file = from_u8(ph.string());
226 if (wxFile::Exists(file) && f.Open(file)) {
227 std::string content(f.Length(), 0);
228 f.Read(&content[0], content.size());
229 return content;
230 }
231 if (!tooltip.empty()) return "#### " + _utf8(tip) + "\n" + tooltip;
232 return (_tipView->GetParent() == this && tip.empty()) ? "" : LoadTip("", "");
233}
std::string LoadTip(std::string const &tip, std::string const &tooltip)
Definition MarkdownTip.cpp:172
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
static double f(double x, double z_sin, double z_cos, bool vertical, bool flip)
Definition FillGyroid.cpp:124
#define _utf8(s)
Definition I18N.hpp:10

References _data_dir, _language, _tipView, _utf8, Slic3r::data_dir(), Slic3r::f(), Slic3r::GUI::from_u8(), LoadTip(), and Slic3r::resources_dir().

Referenced by LoadTip(), and ShowTip().

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

◆ markdownTip()

MarkdownTip * Slic3r::GUI::MarkdownTip::markdownTip ( bool create = true)
staticprivate
303{
304 static MarkdownTip * markdownTip = nullptr;
305 if (markdownTip == nullptr && create)
307 return markdownTip;
308}

References MarkdownTip(), and markdownTip().

Referenced by AttachTo(), DetachFrom(), markdownTip(), Recreate(), Reload(), and ShowTip().

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

◆ OnError()

void Slic3r::GUI::MarkdownTip::OnError ( wxWebViewEvent & event)
private
282{
283}

Referenced by CreateTipView().

Here is the caller graph for this function:

◆ OnLoaded()

void Slic3r::GUI::MarkdownTip::OnLoaded ( wxWebViewEvent & event)
private
250{
251}

Referenced by CreateTipView().

Here is the caller graph for this function:

◆ OnTimer()

void Slic3r::GUI::MarkdownTip::OnTimer ( wxTimerEvent & event)
private
286{
287 if (_hide) {
288 wxPoint pos = ScreenToClient(wxGetMousePosition());
289 if (GetClientRect().Contains(pos)) {
290 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::OnTimer: restart hide timer...";
291 _timer->StartOnce();
292 return;
293 }
294 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::OnTimer: hide.";
295 this->Hide();
296 } else {
297 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::OnTimer: show.";
298 this->Show();
299 }
300}
bool _hide
Definition MarkdownTip.hpp:68
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References _hide, and _timer.

Referenced by MarkdownTip().

Here is the caller graph for this function:

◆ OnTitleChanged()

void Slic3r::GUI::MarkdownTip::OnTitleChanged ( wxWebViewEvent & event)
private
254{
255 if (!_pendingScript.empty()) {
257 _pendingScript.clear();
258 return;
259 }
260#ifdef __linux__
261 wxString str = "0";
262#else
263 wxString str = event.GetString();
264#endif
265 double height = 0;
266 if (str.ToDouble(&height)) {
267 if (height > _lastHeight - 10 && height < _lastHeight + 10)
268 return;
270 height *= 1.25; height += 50;
271 wxSize size = wxDisplay(this).GetClientArea().GetSize();
272 if (height > size.y)
273 height = size.y;
274 wxPoint pos = _requestPos;
275 if (pos.y + height > size.y)
276 pos.y = size.y - height;
277 this->SetSize({ 400, (int)height });
278 this->SetPosition(pos);
279 }
280}
void RunScript(std::string const &script)
Definition MarkdownTip.cpp:235
wxPoint _requestPos
Definition MarkdownTip.hpp:65
std::string _pendingScript
Definition MarkdownTip.hpp:63
double _lastHeight
Definition MarkdownTip.hpp:66
coord_t height(const BoundingBox &box)
Definition Arrange.cpp:1185

References _lastHeight, _pendingScript, _requestPos, and RunScript().

Referenced by CreateTipView().

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

◆ Recreate()

void Slic3r::GUI::MarkdownTip::Recreate ( wxWindow * parent)
static
331{
332 if (auto tip = markdownTip(false)) {
333 tip->Reparent(parent);
334 tip->LoadStyle(); // switch language
335 }
336}

References markdownTip().

Here is the call graph for this function:

◆ Reload()

void Slic3r::GUI::MarkdownTip::Reload ( )
static
325{
326 if (auto tip = markdownTip(false))
327 tip->LoadStyle();
328}

References markdownTip().

Referenced by Slic3r::PresetUpdater::priv::sync_tooltip().

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

◆ RunScript()

void Slic3r::GUI::MarkdownTip::RunScript ( std::string const & script)
private
236{
238}
static bool RunScript(wxWebView *webView, wxString const &msg)
Definition WebView.cpp:491

References _tipView, and WebView::RunScript().

Referenced by OnTitleChanged(), and ShowTip().

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

◆ ShowTip() [1/2]

bool Slic3r::GUI::MarkdownTip::ShowTip ( std::string const & tip,
std::string const & tooltip,
wxPoint pos )
static
311{
312#ifdef NDEBUG
313 return false;
314#endif
315 return markdownTip()->ShowTip(pos, tip, tooltip);
316}
static bool ShowTip(std::string const &tip, std::string const &tooltip, wxPoint pos)
Definition MarkdownTip.cpp:310

References markdownTip(), and ShowTip().

Referenced by Slic3r::GUI::OG_CustomCtrl::OnLeaveWin(), Slic3r::GUI::OG_CustomCtrl::OnMotion(), and ShowTip().

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

◆ ShowTip() [2/2]

bool Slic3r::GUI::MarkdownTip::ShowTip ( wxPoint pos,
std::string const & tip,
std::string const & tooltip )
private
121{
122 if (tip.empty()) {
123 if (_tipView->GetParent() != this)
124 return false;
125 if (pos.x) {
126 _hide = true;
127 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::ShowTip: hide soon on empty tip.";
128 this->Hide();
129 }
130 else if (!_hide) {
131 _hide = true;
132 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::ShowTip: start hide timer (300)...";
133 _timer->StartOnce(300);
134 }
135 return false;
136 }
137 bool tipChanged = _lastTip != tip;
138 if (tipChanged) {
139 auto content = LoadTip(tip, tooltip);
140 if (content.empty()) {
141 _hide = true;
142 this->Hide();
143 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::ShowTip: hide soon on empty content.";
144 return false;
145 }
146 auto script = "window.showMarkdown('" + url_encode(content) + "', true);";
147 if (!_pendingScript.empty()) {
148 _pendingScript = script;
149 }
150 else {
151 RunScript(script);
152 }
153 _lastTip = tip;
154 if (_tipView->GetParent() == this)
155 this->Hide();
156 }
157 if (_tipView->GetParent() == this) {
158 wxSize size = wxDisplay(this).GetClientArea().GetSize();
160 if (pos.y + this->GetSize().y > size.y)
161 pos.y = size.y - this->GetSize().y;
162 this->SetPosition(pos);
163 if (tipChanged || _hide) {
164 _hide = false;
165 BOOST_LOG_TRIVIAL(info) << "MarkdownTip::ShowTip: start show timer (500)...";
166 _timer->StartOnce(500);
167 }
168 }
169 return true;
170}
static std::string url_encode(const std::string &value)
Definition MarkdownTip.cpp:33

References _hide, _lastTip, _pendingScript, _requestPos, _timer, _tipView, LoadTip(), RunScript(), and Slic3r::GUI::url_encode().

Here is the call graph for this function:

Member Data Documentation

◆ _data_dir

bool Slic3r::GUI::MarkdownTip::_data_dir = false
private

Referenced by LoadStyle(), and LoadTip().

◆ _hide

bool Slic3r::GUI::MarkdownTip::_hide = false
private

Referenced by OnTimer(), and ShowTip().

◆ _language

std::string Slic3r::GUI::MarkdownTip::_language
private

Referenced by LoadStyle(), and LoadTip().

◆ _lastHeight

double Slic3r::GUI::MarkdownTip::_lastHeight = 0
private

Referenced by OnTitleChanged().

◆ _lastTip

std::string Slic3r::GUI::MarkdownTip::_lastTip
private

Referenced by LoadStyle(), and ShowTip().

◆ _pendingScript

std::string Slic3r::GUI::MarkdownTip::_pendingScript = " "
private

Referenced by AttachTo(), OnTitleChanged(), and ShowTip().

◆ _requestPos

wxPoint Slic3r::GUI::MarkdownTip::_requestPos
private

Referenced by OnTitleChanged(), and ShowTip().

◆ _timer

wxTimer* Slic3r::GUI::MarkdownTip::_timer = nullptr
private

◆ _tipView

wxWebView* Slic3r::GUI::MarkdownTip::_tipView = nullptr
private

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