mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-23 19:02:10 +00:00
Hyperlink class (#9947)
### FIXES • 3mf file version check dialog opens bambu releases page instead Orca ### CODE COMPARISON <img width="112" height="36" alt="Screenshot-20251128125737" src="https://github.com/user-attachments/assets/73718a18-8159-43d5-bb80-0eb90d59a8f6" /> **wxHyperlinkCtrl** • System decides what colors to use. so blue color is visible even with colors set • No need to use SetCursor() ``` auto wiki_url = "https://github.com/OrcaSlicer/OrcaSlicer/wiki/Built-in-placeholders-variables"; wxHyperlinkCtrl* wiki = new wxHyperlinkCtrl(this, wxID_ANY, _L("Wiki Guide"), wiki_url); wiki->SetToolTip(wiki_url); // required to showing navigation point to user wiki->SetFont(Label::Body_14); // not works properly wiki->SetVisitedColour(wxColour("#009687")); // not works properly wiki->SetHoverColour( wxColour("#26A69A")); // not works properly wiki->SetNormalColour( wxColour("#009687")); // not works properly ``` <img width="132" height="39" alt="Screenshot-20251128125847" src="https://github.com/user-attachments/assets/f6818dc0-5078-498a-bf09-1fd36e81ebe5" /> **wxStaticText** • Works reliably on colors and fonts • All event has to defined manually ``` wxStaticText* wiki = new wxStaticText(this, wxID_ANY, _L("Wiki Guide")); auto wiki_url = "https://github.com/OrcaSlicer/OrcaSlicer/wiki/Built-in-placeholders-variables"; wiki->SetToolTip(wiki_url); // required to showing navigation point to user wiki->SetForegroundColour(wxColour("#009687")); wiki->SetCursor(wxCURSOR_HAND); wxFont font = Label::Body_14; font.SetUnderlined(true); wiki->SetFont(font); wiki->Bind(wxEVT_LEFT_DOWN ,[this, wiki_url](wxMouseEvent e) {wxLaunchDefaultBrowser(wiki_url);}); wiki->Bind(wxEVT_ENTER_WINDOW,[this, wiki ](wxMouseEvent e) {SetForegroundColour(wxColour("#26A69A"));}); wiki->Bind(wxEVT_LEAVE_WINDOW,[this, wiki ](wxMouseEvent e) {SetForegroundColour(wxColour("#009687"));}); ``` <img width="132" height="39" alt="Screenshot-20251128125847" src="https://github.com/user-attachments/assets/f6818dc0-5078-498a-bf09-1fd36e81ebe5" /> **HyperLink** • Fully automated and single line solution • Colors can be controllable from one place • Works reliably on colors and fonts • Reduces duplicate code ``` HyperLink* wiki = new HyperLink(this, _L("Wiki Guide"), "https://github.com/OrcaSlicer/OrcaSlicer/wiki/Built-in-placeholders-variables"); wiki->SetFont(Label::Body_14) // OPTIONAL default is Label::Body_14; ``` ### CHANGES • Unifies all hyperlinks with same style and makes them controllable from one place • Replaces all wxHyperlink with simple custom class. Problem with wxHyperlink it mostly rendered as blue even color set • Reduces duplicate code • Adds wiki links for calibration dialogs • Probably will add "Wiki Guide" to more dialogs overtime <img width="349" height="238" alt="Screenshot-20251127212007" src="https://github.com/user-attachments/assets/69da2732-ea35-44de-8ebc-97a01f86328f" /> <img width="355" height="459" alt="Screenshot-20251127212021" src="https://github.com/user-attachments/assets/c0df40f8-c15d-47fa-b31a-cf8d8b337472" /> <img width="442" height="382" alt="Screenshot-20251127212046" src="https://github.com/user-attachments/assets/5d94242b-6364-4b0a-8b2f-a1f482199bd1" /> <img width="225" height="241" alt="Screenshot-20250824171339" src="https://github.com/user-attachments/assets/39ca6af3-6f8a-42ee-bf1d-c13d0f54bb63" /> <img width="442" height="639" alt="Screenshot-20251127212403" src="https://github.com/user-attachments/assets/c1c580f8-3e1b-42f0-aa8e-bac41c2ff76b" /> <img width="476" height="286" alt="Screenshot-20251127212515" src="https://github.com/user-attachments/assets/28b130ce-c7c0-4ada-9842-ff7154c00c21" /> <img width="1460" height="245" alt="Screenshot-20251127212541" src="https://github.com/user-attachments/assets/3fca2649-9cd3-4aea-9153-b2f508fdfefe" /> <img width="401" height="291" alt="Screenshot-20251127213243" src="https://github.com/user-attachments/assets/82b4ec1f-6074-4018-9efa-a1b6b819ae28" />
This commit is contained in:
49
src/slic3r/GUI/Widgets/HyperLink.cpp
Normal file
49
src/slic3r/GUI/Widgets/HyperLink.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include "HyperLink.hpp"
|
||||
#include "Label.hpp"
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
HyperLink::HyperLink(wxWindow* parent, const wxString& label, const wxString& url, long style)
|
||||
: wxStaticText(parent, wxID_ANY, label)
|
||||
, m_url(url)
|
||||
, m_normalColor(wxColour("#009687")) // used slightly different color otherwise automatically uses ColorForDark that not visible enough
|
||||
, m_hoverColor(wxColour("#26A69A"))
|
||||
{
|
||||
SetForegroundColour(m_normalColor);
|
||||
HyperLink::SetFont(Label::Head_14);
|
||||
SetCursor(wxCursor(wxCURSOR_HAND));
|
||||
|
||||
if (!m_url.IsEmpty())
|
||||
SetToolTip(m_url);
|
||||
|
||||
Bind(wxEVT_LEFT_DOWN, ([this](wxMouseEvent& e) {
|
||||
if (!m_url.IsEmpty())
|
||||
wxLaunchDefaultBrowser(m_url);
|
||||
}));
|
||||
|
||||
Bind(wxEVT_ENTER_WINDOW, ([this](wxMouseEvent& e) {
|
||||
SetForegroundColour(m_hoverColor);
|
||||
Refresh();
|
||||
}));
|
||||
Bind(wxEVT_LEAVE_WINDOW, ([this](wxMouseEvent& e) {
|
||||
SetForegroundColour(m_normalColor);
|
||||
Refresh();
|
||||
}));
|
||||
}
|
||||
|
||||
bool HyperLink::SetFont(const wxFont& font)
|
||||
{ // ensure it stays underlined
|
||||
wxFont f = font;
|
||||
f.SetUnderlined(true);
|
||||
return wxStaticText::SetFont(f);
|
||||
}
|
||||
|
||||
void HyperLink::SetURL(const wxString& url)
|
||||
{
|
||||
m_url = url;
|
||||
SetToolTip(m_url);
|
||||
}
|
||||
|
||||
wxString HyperLink::GetURL() const { return m_url; }
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
26
src/slic3r/GUI/Widgets/HyperLink.hpp
Normal file
26
src/slic3r/GUI/Widgets/HyperLink.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef slic3r_GUI_HyperLink_hpp_
|
||||
#define slic3r_GUI_HyperLink_hpp_
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/window.h>
|
||||
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
class HyperLink : public wxStaticText
|
||||
{
|
||||
public:
|
||||
HyperLink(wxWindow* parent, const wxString& label = wxEmptyString, const wxString& url = wxEmptyString, const long style = 0);
|
||||
|
||||
void SetURL(const wxString& url);
|
||||
wxString GetURL() const;
|
||||
|
||||
bool SetFont(const wxFont& font);
|
||||
|
||||
private:
|
||||
wxString m_url;
|
||||
wxColour m_normalColor;
|
||||
wxColour m_hoverColor;
|
||||
};
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
#endif // !slic3r_GUI_HyperLink_hpp_
|
||||
@@ -274,8 +274,8 @@ SideTools::SideTools(wxWindow *parent, wxWindowID id, const wxPoint &pos, const
|
||||
wxBoxSizer* connection_sizer_V = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer* connection_sizer_H = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
m_hyperlink = new wxHyperlinkCtrl(m_connection_info, wxID_ANY, _L("Failed to connect to the server"), wxT("https://wiki.bambulab.com/en/software/bambu-studio/failed-to-connect-printer"), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
m_hyperlink->SetBackgroundColour(wxColour(255, 111, 0));
|
||||
// ORCA standardized HyperLink
|
||||
m_hyperlink = new HyperLink(m_connection_info, _L("Failed to connect to the server"), wxT("https://wiki.bambulab.com/en/software/bambu-studio/failed-to-connect-printer"));
|
||||
|
||||
m_more_err_open = ScalableBitmap(this, "monitir_err_open", 16);
|
||||
m_more_err_close = ScalableBitmap(this, "monitir_err_close", 16);
|
||||
@@ -328,13 +328,10 @@ SideTools::SideTools(wxWindow *parent, wxWindowID id, const wxPoint &pos, const
|
||||
wxBoxSizer* sizer_error_desc = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer* sizer_extra_info = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
m_link_network_state = new wxHyperlinkCtrl(m_side_error_panel, wxID_ANY,_L("Check the status of current system services"),"",wxDefaultPosition,wxDefaultSize, wxHL_ALIGN_CENTRE |wxST_ELLIPSIZE_END);
|
||||
m_link_network_state->SetMinSize(wxSize(FromDIP(220), -1));
|
||||
// ORCA standardized HyperLink
|
||||
m_link_network_state = new HyperLink(m_side_error_panel, _L("Check the status of current system services"), wxGetApp().link_to_network_check(), wxST_ELLIPSIZE_END);
|
||||
m_link_network_state->SetMaxSize(wxSize(FromDIP(220), -1));
|
||||
m_link_network_state->SetFont(::Label::Body_12);
|
||||
m_link_network_state->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {wxGetApp().link_to_network_check(); });
|
||||
m_link_network_state->Bind(wxEVT_ENTER_WINDOW, [this](auto& e) {m_link_network_state->SetCursor(wxCURSOR_HAND); });
|
||||
m_link_network_state->Bind(wxEVT_LEAVE_WINDOW, [this](auto& e) {m_link_network_state->SetCursor(wxCURSOR_ARROW); });
|
||||
|
||||
auto st_title_error_code = new wxStaticText(m_side_error_panel, wxID_ANY, _L("code"), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
auto st_title_error_code_doc = new wxStaticText(m_side_error_panel, wxID_ANY, ": ");
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <wx/dcgraph.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/dcclient.h>
|
||||
#include <wx/hyperlink.h>
|
||||
#include "Button.hpp"
|
||||
#include "Label.hpp"
|
||||
#include "HyperLink.hpp" // ORCA
|
||||
#include "../GUI/Tabbook.hpp"
|
||||
#include "../DeviceManager.hpp"
|
||||
#include "../wxExtensions.hpp"
|
||||
@@ -99,13 +99,13 @@ public:
|
||||
private:
|
||||
SideToolsPanel* m_side_tools{ nullptr };
|
||||
Tabbook* m_tabpanel{ nullptr };
|
||||
wxHyperlinkCtrl* m_link_network_state{ nullptr };
|
||||
HyperLink* m_link_network_state{ nullptr }; // ORCA
|
||||
Label* m_st_txt_error_code{ nullptr };
|
||||
Label* m_st_txt_error_desc{ nullptr };
|
||||
Label* m_st_txt_extra_info{ nullptr };
|
||||
wxWindow* m_side_error_panel{ nullptr };
|
||||
Button* m_connection_info{ nullptr };
|
||||
wxHyperlinkCtrl* m_hyperlink{ nullptr };
|
||||
HyperLink* m_hyperlink{ nullptr }; // ORCA
|
||||
ScalableButton* m_more_button{ nullptr };
|
||||
ScalableBitmap m_more_err_open;
|
||||
ScalableBitmap m_more_err_close;
|
||||
|
||||
Reference in New Issue
Block a user