mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 01:26:10 +08:00
Set downloaded avatar to scalable button
This commit is contained in:
parent
c129340712
commit
2031fb5133
@ -904,10 +904,10 @@ void MainFrame::set_monitor_tab_url(const wxString& url)
|
|||||||
m_monitor_webview->load_default_url();
|
m_monitor_webview->load_default_url();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slic3r::GUI::MainFrame::refresh_auth_menu()
|
void Slic3r::GUI::MainFrame::refresh_auth_menu(bool avatar/* = false */)
|
||||||
{
|
{
|
||||||
// Update User name in TopBar
|
// Update User name in TopBar
|
||||||
dynamic_cast<TopBar*>(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAuthMenu();
|
dynamic_cast<TopBar*>(m_tabpanel)->GetTopBarItemsCtrl()->UpdateAuthMenu(avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainFrame::add_created_tab(Tab* panel, const std::string& bmp_name /*= ""*/)
|
void MainFrame::add_created_tab(Tab* panel, const std::string& bmp_name /*= ""*/)
|
||||||
|
@ -223,7 +223,7 @@ public:
|
|||||||
void set_monitor_tab_url(const wxString& url);
|
void set_monitor_tab_url(const wxString& url);
|
||||||
bool get_monitor_tab_added() const { return m_monitor_webview_added; }
|
bool get_monitor_tab_added() const { return m_monitor_webview_added; }
|
||||||
|
|
||||||
void refresh_auth_menu();
|
void refresh_auth_menu(bool avatar = false);
|
||||||
|
|
||||||
PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; }
|
PrintHostQueueDialog* printhost_queue_dlg() { return m_printhost_queue_dlg; }
|
||||||
|
|
||||||
|
@ -889,7 +889,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID);
|
this->notification_manager->close_notification_of_type(NotificationType::PrusaAuthUserID);
|
||||||
this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
|
this->notification_manager->push_notification(NotificationType::PrusaAuthUserID, NotificationManager::NotificationLevel::ImportantNotificationLevel, text);
|
||||||
this->main_frame->disable_connect_tab();
|
this->main_frame->disable_connect_tab();
|
||||||
this->main_frame->refresh_auth_menu();
|
this->main_frame->refresh_auth_menu(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
this->q->Bind(EVT_PA_ID_USER_SUCCESS, [this](PrusaAuthSuccessEvent& evt) {
|
this->q->Bind(EVT_PA_ID_USER_SUCCESS, [this](PrusaAuthSuccessEvent& evt) {
|
||||||
@ -953,6 +953,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
|
|||||||
file = fopen(png_path.string().c_str(), "wb");
|
file = fopen(png_path.string().c_str(), "wb");
|
||||||
fwrite(evt.data.c_str(), 1, evt.data.size(), file);
|
fwrite(evt.data.c_str(), 1, evt.data.size(), file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
this->main_frame->refresh_auth_menu(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
wxGetApp().other_instance_message_handler()->init(this->q);
|
wxGetApp().other_instance_message_handler()->init(this->q);
|
||||||
|
@ -185,7 +185,7 @@ void TopBarItemsCtrl::CreateAuthMenu()
|
|||||||
}, get_bmp_bundle("login", 16));
|
}, get_bmp_bundle("login", 16));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopBarItemsCtrl::UpdateAuthMenu()
|
void TopBarItemsCtrl::UpdateAuthMenu(bool avatar/* = false*/)
|
||||||
{
|
{
|
||||||
auto user_account = wxGetApp().plater()->get_user_account();
|
auto user_account = wxGetApp().plater()->get_user_account();
|
||||||
if (m_login_menu_item) {
|
if (m_login_menu_item) {
|
||||||
@ -198,8 +198,19 @@ void TopBarItemsCtrl::UpdateAuthMenu()
|
|||||||
m_user_menu_item->SetItemLabel(user_name);
|
m_user_menu_item->SetItemLabel(user_name);
|
||||||
|
|
||||||
m_auth_btn->SetLabel(user_name);
|
m_auth_btn->SetLabel(user_name);
|
||||||
m_auth_btn->SetBitmapMargins(0, 0);
|
if (avatar) {
|
||||||
// m_auth_btn->SetBitmap_("icon_name");
|
if (user_account->is_logged()) {
|
||||||
|
boost::filesystem::path path = boost::filesystem::path(boost::filesystem::path(Slic3r::data_dir()) / "cache" / "avatar.png");
|
||||||
|
ScalableBitmap new_logo(this, path, m_auth_btn->GetBitmapSize());
|
||||||
|
if (new_logo.IsOk())
|
||||||
|
m_auth_btn->SetBitmap_(new_logo);
|
||||||
|
else
|
||||||
|
m_auth_btn->SetBitmap_("user");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_auth_btn->SetBitmap_("user");
|
||||||
|
}
|
||||||
|
}
|
||||||
m_auth_btn->Refresh();
|
m_auth_btn->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
void AppendMenuSeparaorItem();
|
void AppendMenuSeparaorItem();
|
||||||
void ApplyWorkspacesMenu();
|
void ApplyWorkspacesMenu();
|
||||||
void CreateAuthMenu();
|
void CreateAuthMenu();
|
||||||
void UpdateAuthMenu();
|
void UpdateAuthMenu(bool avatar = false);
|
||||||
void CreateSearch();
|
void CreateSearch();
|
||||||
|
|
||||||
wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); }
|
wxWindow* GetSearchCtrl() { return m_search->GetTextCtrl(); }
|
||||||
|
@ -830,6 +830,22 @@ ScalableBitmap(parent, icon_name, icon_size.x, icon_size.y, grayscale)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScalableBitmap::ScalableBitmap(wxWindow* parent, boost::filesystem::path& icon_path, const wxSize icon_size)
|
||||||
|
:m_parent(parent), m_bmp_width(icon_size.x), m_bmp_height(icon_size.y)
|
||||||
|
{
|
||||||
|
wxString path = Slic3r::GUI::from_u8(icon_path.string());
|
||||||
|
wxBitmap bitmap;
|
||||||
|
const std::string ext = icon_path.extension().string();
|
||||||
|
if (ext == ".png") {
|
||||||
|
bitmap.LoadFile(path, wxBITMAP_TYPE_PNG);
|
||||||
|
wxBitmap::Rescale(bitmap, icon_size);
|
||||||
|
m_bmp = wxBitmapBundle(bitmap);
|
||||||
|
}
|
||||||
|
else if (ext == ".svg") {
|
||||||
|
m_bmp = wxBitmapBundle::FromSVGFile(path, icon_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScalableBitmap::sys_color_changed()
|
void ScalableBitmap::sys_color_changed()
|
||||||
{
|
{
|
||||||
m_bmp = *get_bmp_bundle(m_icon_name, m_bmp_width, m_bmp_height);
|
m_bmp = *get_bmp_bundle(m_icon_name, m_bmp_width, m_bmp_height);
|
||||||
@ -925,12 +941,20 @@ int ScalableButton::GetBitmapHeight()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxSize ScalableButton::GetBitmapSize()
|
||||||
|
{
|
||||||
|
#ifdef __APPLE__
|
||||||
|
return wxSize(GetBitmap().GetScaledWidth(), GetBitmap().GetScaledHeight());
|
||||||
|
#else
|
||||||
|
return wxSize(GetBitmap().GetWidth(), GetBitmap().GetHeight());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void ScalableButton::sys_color_changed()
|
void ScalableButton::sys_color_changed()
|
||||||
{
|
{
|
||||||
|
Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border);
|
||||||
if (m_current_icon_name.empty())
|
if (m_current_icon_name.empty())
|
||||||
return;
|
return;
|
||||||
Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border);
|
|
||||||
|
|
||||||
wxBitmapBundle bmp = *get_bmp_bundle(m_current_icon_name, m_bmp_width, m_bmp_height);
|
wxBitmapBundle bmp = *get_bmp_bundle(m_current_icon_name, m_bmp_width, m_bmp_height);
|
||||||
SetBitmap(bmp);
|
SetBitmap(bmp);
|
||||||
SetBitmapCurrent(bmp);
|
SetBitmapCurrent(bmp);
|
||||||
|
@ -167,6 +167,10 @@ public:
|
|||||||
const wxSize icon_size,
|
const wxSize icon_size,
|
||||||
const bool grayscale = false);
|
const bool grayscale = false);
|
||||||
|
|
||||||
|
ScalableBitmap( wxWindow *parent,
|
||||||
|
boost::filesystem::path& icon_path,
|
||||||
|
const wxSize icon_size);
|
||||||
|
|
||||||
~ScalableBitmap() {}
|
~ScalableBitmap() {}
|
||||||
|
|
||||||
void sys_color_changed();
|
void sys_color_changed();
|
||||||
@ -181,6 +185,7 @@ public:
|
|||||||
wxSize GetSize() const { return get_preferred_size(m_bmp, m_parent); }
|
wxSize GetSize() const { return get_preferred_size(m_bmp, m_parent); }
|
||||||
int GetWidth() const { return GetSize().GetWidth(); }
|
int GetWidth() const { return GetSize().GetWidth(); }
|
||||||
int GetHeight() const { return GetSize().GetHeight(); }
|
int GetHeight() const { return GetSize().GetHeight(); }
|
||||||
|
bool IsOk() const { return m_bmp.IsOk(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxWindow* m_parent{ nullptr };
|
wxWindow* m_parent{ nullptr };
|
||||||
@ -263,6 +268,7 @@ public:
|
|||||||
bool SetBitmap_(const std::string& bmp_name);
|
bool SetBitmap_(const std::string& bmp_name);
|
||||||
void SetBitmapDisabled_(const ScalableBitmap &bmp);
|
void SetBitmapDisabled_(const ScalableBitmap &bmp);
|
||||||
int GetBitmapHeight();
|
int GetBitmapHeight();
|
||||||
|
wxSize GetBitmapSize();
|
||||||
|
|
||||||
virtual void sys_color_changed();
|
virtual void sys_color_changed();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user