mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 03:07:55 -06:00
ENH: [STUDIO-2446] support select media files by group of month/year
Change-Id: I10d26e34405a13daa477be011e7353d79232b4b3
This commit is contained in:
parent
2573d3c112
commit
ef1e4a132d
4 changed files with 156 additions and 70 deletions
|
@ -5,6 +5,7 @@
|
|||
#include "I18N.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
|
||||
#include <wx/dcgraph.h>
|
||||
|
||||
|
@ -127,11 +128,12 @@ void Slic3r::GUI::ImageGrid::Rescale()
|
|||
|
||||
void Slic3r::GUI::ImageGrid::Select(size_t index)
|
||||
{
|
||||
if (m_selecting) {
|
||||
m_file_sys->ToggleSelect(index);
|
||||
Refresh();
|
||||
return;
|
||||
}
|
||||
if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
|
||||
if (m_selecting) {
|
||||
m_file_sys->ToggleSelect(index);
|
||||
Refresh();
|
||||
}
|
||||
return;
|
||||
}
|
||||
index = m_file_sys->EnterSubGroup(index);
|
||||
|
@ -145,6 +147,13 @@ void Slic3r::GUI::ImageGrid::Select(size_t index)
|
|||
void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
|
||||
{
|
||||
if (action == 0) {
|
||||
if (m_file_sys->GetSelectCount() > 1) {
|
||||
MessageDialog dlg(this,
|
||||
wxString::Format(_L("You are going to delete %u files. Are you sure to continue?"), m_file_sys->GetSelectCount()),
|
||||
_L("Delete files"), wxYES_NO | wxICON_WARNING);
|
||||
if (dlg.ShowModal() != wxID_YES)
|
||||
return;
|
||||
}
|
||||
m_file_sys->DeleteFiles(index);
|
||||
} else if (action == 1) {
|
||||
if (index != -1) {
|
||||
|
@ -152,7 +161,9 @@ void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
|
|||
if (file.IsDownload() && file.progress >= -1) {
|
||||
if (file.progress >= 100) {
|
||||
if (!m_file_sys->DownloadCheckFile(index)) {
|
||||
wxMessageBox(wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)), _L("Error"), wxOK);
|
||||
MessageDialog(this,
|
||||
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
|
||||
_L("Error"), wxOK).ShowModal();
|
||||
Refresh();
|
||||
return;
|
||||
}
|
||||
|
@ -176,7 +187,9 @@ void Slic3r::GUI::ImageGrid::DoAction(size_t index, int action)
|
|||
if (file.IsDownload() && file.progress >= -1) {
|
||||
if (file.progress >= 100) {
|
||||
if (!m_file_sys->DownloadCheckFile(index)) {
|
||||
wxMessageBox(wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)), _L("Error"), wxOK);
|
||||
MessageDialog(this,
|
||||
wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
|
||||
_L("Error"), wxOK).ShowModal();
|
||||
Refresh();
|
||||
return;
|
||||
}
|
||||
|
@ -465,6 +478,8 @@ wxBitmap Slic3r::GUI::ImageGrid::createCircleBitmap(wxSize size, int borderWidth
|
|||
return bmp;
|
||||
}
|
||||
|
||||
static constexpr wchar_t const *TIME_FORMATS[] = {_T("%Y-%m-%d"), _T("%Y-%m"), _T("%Y")};
|
||||
|
||||
/*
|
||||
* Here we do the actual rendering. I put it in a separate
|
||||
* method so that it can work no matter what type of DC
|
||||
|
@ -495,7 +510,6 @@ void ImageGrid::render(wxDC& dc)
|
|||
// Draw line spacing at top
|
||||
if (off.y > 0)
|
||||
dc.DrawRectangle({0, 0, size.x, off.y});
|
||||
constexpr wchar_t const * formats[] = {_T("%Y-%m-%d"), _T("%Y-%m"), _T("%Y")};
|
||||
size_t start = index;
|
||||
size_t end = index;
|
||||
size_t hit_image = m_selecting ? size_t(-1) : m_hit_type == HIT_ITEM ? m_hit_item : m_hit_type == HIT_ACTION ? m_hit_item / 4 :size_t(-1);
|
||||
|
@ -506,65 +520,7 @@ void ImageGrid::render(wxDC& dc)
|
|||
wxPoint pt{off.x, off.y};
|
||||
end = (index + m_col_count) < m_file_sys->GetCount() ? index + m_col_count : m_file_sys->GetCount();
|
||||
while (index < end) {
|
||||
auto & file = m_file_sys->GetFile(index);
|
||||
// Draw thumbnail
|
||||
if (file.thumbnail.IsOk()) {
|
||||
float hs = (float) m_image_size.GetWidth() / file.thumbnail.GetWidth();
|
||||
float vs = (float) m_image_size.GetHeight() / file.thumbnail.GetHeight();
|
||||
dc.SetUserScale(hs, vs);
|
||||
dc.DrawBitmap(file.thumbnail, {(int) (pt.x / hs), (int) (pt.y / vs)});
|
||||
dc.SetUserScale(1, 1);
|
||||
if (m_file_sys->GetGroupMode() != PrinterFileSystem::G_NONE) {
|
||||
dc.DrawBitmap(m_mask, pt);
|
||||
}
|
||||
}
|
||||
bool show_download_state_always = true;
|
||||
// Draw checked icon
|
||||
if (m_selecting && !show_download_state_always)
|
||||
dc.DrawBitmap(file.IsSelect() ? m_checked_icon.bmp() : m_unchecked_icon.bmp(),
|
||||
pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
|
||||
// can't handle alpha
|
||||
// dc.GradientFillLinear({pt.x, pt.y, m_image_size.GetWidth(), 60}, wxColour(0x6F, 0x6F, 0x6F, 0x99), wxColour(0x6F, 0x6F, 0x6F, 0), wxBOTTOM);
|
||||
else if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
|
||||
wxString nonHoverText;
|
||||
wxString secondAction = _L("Download");
|
||||
wxString thirdAction;
|
||||
int states = 0;
|
||||
// Draw download progress
|
||||
if (file.IsDownload()) {
|
||||
if (file.progress == -1) {
|
||||
secondAction = _L("Cancel");
|
||||
nonHoverText = _L("Download waiting...");
|
||||
} else if (file.progress < 0) {
|
||||
secondAction = _L("Retry");
|
||||
nonHoverText = _L("Download failed");
|
||||
states = StateColor::Checked;
|
||||
} else if (file.progress >= 100) {
|
||||
secondAction = _L("Play");
|
||||
thirdAction = _L("Open Folder");
|
||||
nonHoverText = _L("Download finished");
|
||||
} else {
|
||||
secondAction = _L("Cancel");
|
||||
nonHoverText = wxString::Format(_L("Downloading %d%%..."), file.progress);
|
||||
thirdAction = wxString::Format(L"%d%%...", file.progress);
|
||||
}
|
||||
}
|
||||
// Draw buttons on hovered item
|
||||
wxRect rect{pt.x, pt.y + m_image_size.y - m_buttons_background.GetHeight(), m_image_size.GetWidth(), m_buttons_background.GetHeight()};
|
||||
if (hit_image == index) {
|
||||
renderButtons(dc, {_L("Delete"), (wxChar const *) secondAction, thirdAction.IsEmpty() ? nullptr : (wxChar const *) thirdAction, nullptr}, rect,
|
||||
m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states);
|
||||
} else if (!nonHoverText.IsEmpty()) {
|
||||
renderButtons(dc, {(wxChar const *) nonHoverText, nullptr}, rect, -1, states);
|
||||
}
|
||||
if (m_selecting && show_download_state_always)
|
||||
dc.DrawBitmap(file.IsSelect() ? m_checked_icon.bmp() : m_unchecked_icon.bmp(),
|
||||
pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
|
||||
} else {
|
||||
dc.SetTextForeground(*wxWHITE); // time text color
|
||||
auto date = wxDateTime((time_t) file.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
|
||||
dc.DrawText(date, pt + wxPoint{24, 16});
|
||||
}
|
||||
renderContent(dc, pt, index, hit_image == index);
|
||||
// Draw colume spacing at right
|
||||
dc.DrawRectangle({pt.x + m_image_size.GetWidth(), pt.y, m_cell_size.GetWidth() - m_image_size.GetWidth(), m_image_size.GetHeight()});
|
||||
++index;
|
||||
|
@ -583,8 +539,8 @@ void ImageGrid::render(wxDC& dc)
|
|||
dc.DrawRectangle({off.x, 0}, m_mask.GetSize());
|
||||
auto & file1 = m_file_sys->GetFile(start);
|
||||
auto & file2 = m_file_sys->GetFile(end - 1);
|
||||
auto date1 = wxDateTime((time_t) file1.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
|
||||
auto date2 = wxDateTime((time_t) file2.time).Format(_L(formats[m_file_sys->GetGroupMode()]));
|
||||
auto date1 = wxDateTime((time_t) file1.time).Format(_L(TIME_FORMATS[m_file_sys->GetGroupMode()]));
|
||||
auto date2 = wxDateTime((time_t) file2.time).Format(_L(TIME_FORMATS[m_file_sys->GetGroupMode()]));
|
||||
dc.SetFont(Label::Head_16);
|
||||
dc.SetTextForeground(StateColor::darkModeColorFor("#262E30"));
|
||||
dc.DrawText(date1 + " - " + date2, wxPoint{off.x, 2});
|
||||
|
@ -605,6 +561,68 @@ void ImageGrid::render(wxDC& dc)
|
|||
}
|
||||
}
|
||||
|
||||
void Slic3r::GUI::ImageGrid::renderContent(wxDC &dc, wxPoint const &pt, int index, bool hit)
|
||||
{
|
||||
bool selected = false;
|
||||
auto &file = m_file_sys->GetFile(index, selected);
|
||||
// Draw thumbnail
|
||||
if (file.thumbnail.IsOk()) {
|
||||
float hs = (float) m_image_size.GetWidth() / file.thumbnail.GetWidth();
|
||||
float vs = (float) m_image_size.GetHeight() / file.thumbnail.GetHeight();
|
||||
dc.SetUserScale(hs, vs);
|
||||
dc.DrawBitmap(file.thumbnail, {(int) (pt.x / hs), (int) (pt.y / vs)});
|
||||
dc.SetUserScale(1, 1);
|
||||
if (m_file_sys->GetGroupMode() != PrinterFileSystem::G_NONE) {
|
||||
dc.DrawBitmap(m_mask, pt);
|
||||
}
|
||||
}
|
||||
bool show_download_state_always = true;
|
||||
// Draw checked icon
|
||||
if (m_selecting && !show_download_state_always)
|
||||
dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
|
||||
// can't handle alpha
|
||||
// dc.GradientFillLinear({pt.x, pt.y, m_border_size.GetWidth(), 60}, wxColour(0x6F, 0x6F, 0x6F, 0x99), wxColour(0x6F, 0x6F, 0x6F, 0), wxBOTTOM);
|
||||
else if (m_file_sys->GetGroupMode() == PrinterFileSystem::G_NONE) {
|
||||
wxString nonHoverText;
|
||||
wxString secondAction = _L("Download");
|
||||
wxString thirdAction;
|
||||
int states = 0;
|
||||
// Draw download progress
|
||||
if (file.IsDownload()) {
|
||||
if (file.progress == -1) {
|
||||
secondAction = _L("Cancel");
|
||||
nonHoverText = _L("Download waiting...");
|
||||
} else if (file.progress < 0) {
|
||||
secondAction = _L("Retry");
|
||||
nonHoverText = _L("Download failed");
|
||||
states = StateColor::Checked;
|
||||
} else if (file.progress >= 100) {
|
||||
secondAction = _L("Play");
|
||||
thirdAction = _L("Open Folder");
|
||||
nonHoverText = _L("Download finished");
|
||||
} else {
|
||||
secondAction = _L("Cancel");
|
||||
nonHoverText = wxString::Format(_L("Downloading %d%%..."), file.progress);
|
||||
thirdAction = wxString::Format(L"%d%%...", file.progress);
|
||||
}
|
||||
}
|
||||
// Draw buttons on hovered item
|
||||
wxRect rect{pt.x, pt.y + m_image_size.GetHeight() - m_buttons_background.GetHeight(), m_image_size.GetWidth(), m_buttons_background.GetHeight()};
|
||||
if (hit) {
|
||||
renderButtons(dc, {_L("Delete"), (wxChar const *) secondAction, thirdAction.IsEmpty() ? nullptr : (wxChar const *) thirdAction, nullptr}, rect,
|
||||
m_hit_type == HIT_ACTION ? m_hit_item & 3 : -1, states);
|
||||
} else if (!nonHoverText.IsEmpty()) {
|
||||
renderButtons(dc, {(wxChar const *) nonHoverText, nullptr}, rect, -1, states);
|
||||
}
|
||||
} else {
|
||||
dc.SetTextForeground(*wxWHITE); // time text color
|
||||
auto date = wxDateTime((time_t) file.time).Format(_L(TIME_FORMATS[m_file_sys->GetGroupMode()]));
|
||||
dc.DrawText(date, pt + wxPoint{24, 16});
|
||||
}
|
||||
if (m_selecting && show_download_state_always)
|
||||
dc.DrawBitmap(selected ? m_checked_icon.bmp() : m_unchecked_icon.bmp(), pt + wxPoint{10, m_image_size.GetHeight() - m_checked_icon.GetBmpHeight() - 10});
|
||||
}
|
||||
|
||||
void Slic3r::GUI::ImageGrid::renderButtons(wxDC &dc, wxStringList const &texts, wxRect const &rect2, size_t hit, int states)
|
||||
{
|
||||
// Draw background
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue