Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/en_US/grm.html
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,13 @@ <h5>Generated report example:</h5><p>
<img class="shadow wide" alt="selection example output" src="../en_US/grm/ExampleOutputSelection.png"></td><br>


<!-- ====================== Section ====================== -->
<!-- Exporting report definition -->
<!-- ======================================================= -->

<h2>Customizing the report</h2>
<p>Within the context menu of an report, there are options to rename the report, to add a custom icon (see also <a href="../icon.html?lang=en_US">Custom account and navigator icons</a> for details)
and to assign the report to a new/different group.</p>

<!-- ====================== Section ====================== -->
<!-- Exporting report definition -->
Expand Down
Binary file added docs/en_US/settings/grm_selection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/en_US/settings/iconSelectionDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions docs/en_US/settings/icons.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ <h3>Directly adding a favicon</h3>
<img class="shadow" alt='Icon manager dialog' src='../../en_US/settings/fav_icon_from_account_dialog.png' height="600">
</div>

<h2>Adding a custom icon to a navigator section</h2>
<p>All configured custom icons are available in the navigator configuration dialog and can be selected during editing of the navigator entry
(see <a href="../../navigator.html?lang=en_US">Navigator configuration and custom account types - 2.4</a> for details):</p>

<h2>Adding a custom icon to a GRM report</h2>
<p>Within the GRM manager report tree, with a right click on a selected report, the context menu for the report has an <kbd><samp>Set icon </samp></kbd> option:</p>
<div>
<img class="shadow" alt='Icon selection dialog' src='../../en_US/settings/grm_selection.png' height="200">
</div>
<p> This opens an icon selection dialog, to assign an icon to an report:</p>
<div>
<img class="shadow" alt='Icon selection dialog' src='../../en_US/settings/iconSelectionDialog.png' height="400">
</div>
<p>An icon can be directly selected with a double click, or by marking it in the list and applying it with the <kbd><samp>OK</samp></kbd> button. The <kbd><samp>Default</samp></kbd> button
removes a custom icon from the report.</p>
<p>The icon is used in the GRM manager tree and the navigator tree.</p>


<h2>Notes</h2>
<ul>
<li>All icons are stored globally for the MMEX installation beside the global settings database in the sub directory "icons" and are available for all mmex databases on the PC.</li>
Expand Down
50 changes: 50 additions & 0 deletions src/app/mmFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,7 @@ bool mmFrame::openFile(const wxString& fileName, bool openingNew, const wxString
InfoModel::instance().saveBool("ISUSED", true);
db_lockInPlace = false;
mmNavigatorList::instance().LoadFromDB();
loadGrmIconMapping();
autoRepeatTransactionsTimer_.Start(REPEAT_FREQ_TRANS_DELAY_TIME, wxTIMER_ONE_SHOT);
}
else
Expand Down Expand Up @@ -2667,6 +2668,7 @@ void mmFrame::OnNew(wxCommandEvent& /*event*/)

SetDatabaseFile(fileName, true);
SettingModel::instance().saveString("LASTFILENAME", fileName);
loadGrmIconMapping();
}
//----------------------------------------------------------------------------

Expand Down Expand Up @@ -3306,6 +3308,7 @@ void mmFrame::OnGeneralReportManager(wxCommandEvent& WXUNUSED(event))
wxTreeItemId selectedItem = m_nav_tree_ctrl->GetSelection();
GeneralReportManager dlg(this, m_db.get(), selectedItem.IsOk() ? m_nav_tree_ctrl->GetItemText(selectedItem) : "");
dlg.ShowModal();
loadGrmIconMapping();
RefreshNavigationTree();
}
}
Expand Down Expand Up @@ -4605,6 +4608,8 @@ void mmFrame::DoUpdateGRMNavigation(wxTreeItemId& parent_item)
));
}

// Update icons:
applyGrmIconMapping(parent_item);
}

void mmFrame::DoUpdateFilterNavigation(wxTreeItemId& parent_item)
Expand Down Expand Up @@ -4665,3 +4670,48 @@ void mmFrame::mmDoHideReportsDialog()
}
DoRecreateNavTreeControl();
}

void mmFrame::loadGrmIconMapping()
{
m_grm_icons_map.clear();

rapidjson::Document doc;
const wxString& json = InfoModel::instance().getString("GRM_REPORT_IMAGE_STATUS", "");
doc.Parse(json.c_str());
if (!doc.IsObject())
return;

const int prefix_len = static_cast<int>(_t("Reports").Len()) + 1;

for (auto it = doc.MemberBegin(); it != doc.MemberEnd(); ++it) {
std::string p = it->name.GetString();
wxString path(p.substr(prefix_len).c_str(), wxConvUTF8);
wxString timg = wxString::FromUTF8(it->value.GetString());
m_grm_icons_map[path] = NavTreeIconImages::instance().getImgIndexFromStorageString(timg);
}
}

void mmFrame::applyGrmIconMapping(wxTreeItemId& parent_item)
{
for (auto const& x : m_grm_icons_map) {
wxLogDebug ("Apply icon '%d' to path '%s'", x.second, x.first);

std::vector<std::string> parts = GeneralReportManager::splitPath(x.first.ToStdString());
wxTreeItemId current = parent_item;
if (!parts.empty()) {
for (size_t i = 0; i < parts.size(); ++i) {
wxTreeItemId next = GeneralReportManager::findChild(m_nav_tree_ctrl, current, parts[i]);
if (!next.IsOk()) {
current = wxTreeItemId();
break;
}
current = next;
}
}

if (current.IsOk()) {
m_nav_tree_ctrl->SetItemImage(current, x.second);
m_nav_tree_ctrl->SetItemImage(current, x.second, wxTreeItemIcon_Selected);
}
}
}
4 changes: 3 additions & 1 deletion src/app/mmFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class mmFrame : public wxFrame

private:
static const std::vector<std::pair<mmNavigatorItem::TYPE_ID, wxString>> ACCOUNT_SECTION_TABLE;
//static wxArrayString account_section_all();

// -- state

Expand All @@ -207,6 +206,7 @@ class mmFrame : public wxFrame
private:
std::vector<WebsiteNews> websiteNewsArray_;
std::vector<TableBase*> m_all_models;
std::map<wxString, int> m_grm_icons_map;

// handles to SQLite Database
wxSharedPtr<wxSQLite3Database> m_db;
Expand Down Expand Up @@ -299,6 +299,8 @@ class mmFrame : public wxFrame
wxSizer* cleanupHomePanel(bool new_sizer = true);
void updateHomePagePanel(PanelBase* panel);
bool openFile(const wxString& fileName, bool openingNew, const wxString &password = "");
void loadGrmIconMapping();
void applyGrmIconMapping(wxTreeItemId& parent_item);
void InitializeModelTables();
bool createDataStore(const wxString& fileName, const wxString &passwd, bool openingNew);
void createMenu();
Expand Down
114 changes: 114 additions & 0 deletions src/dialog/IconManagerDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,117 @@ void IconManagerDialog::OnRightClick(wxMouseEvent& WXUNUSED(event), const wxStri

PopupMenu(&menu);
}


// =============== Icon Selection Dialog =============================
IconSelectionDialog::IconSelectionDialog(wxWindow* parent, wxVector<wxBitmapBundle>& images, int iconSize)
: wxDialog(parent, wxID_ANY, _t("Select icon"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
m_icons(images)
{
wxBoxSizer* dialogSizer = new wxBoxSizer(wxVERTICAL);

m_scrollWin = new wxScrolledWindow(this, wxID_ANY,
wxDefaultPosition, wxDefaultSize,
wxVSCROLL);
m_scrollWin->SetScrollRate(5, 5);
m_scrollWin->SetMinSize(wxSize(300, 200));

int cols = 6;
m_gridSizer = new wxGridSizer(cols, 5, 5);

for (size_t i = 0; i < m_icons.size(); ++i) {
wxBitmap bmp = m_icons[i].GetBitmap(wxSize(iconSize, iconSize));

wxStaticBitmap* iconCtrl = new wxStaticBitmap(
m_scrollWin, wxID_ANY, bmp,
wxDefaultPosition,
wxSize(iconSize + 10, iconSize + 10),
wxBORDER_SIMPLE
);

iconCtrl->SetBackgroundColour(*wxWHITE);
iconCtrl->SetClientData(reinterpret_cast<void*>(i));

iconCtrl->Bind(wxEVT_LEFT_DOWN, &IconSelectionDialog::OnIconClicked, this);
iconCtrl->Bind(wxEVT_LEFT_DCLICK, [this, i](wxMouseEvent&) {
m_selectedIndex = i;
EndModal(wxID_OK);
});
iconCtrl->Bind(wxEVT_ENTER_WINDOW, [](wxMouseEvent& e) {
auto w = static_cast<wxWindow*>(e.GetEventObject());
w->SetBackgroundColour(wxColour(220,220,220));
w->Refresh();
});

iconCtrl->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent& e) {
auto w = static_cast<wxWindow*>(e.GetEventObject());
if (reinterpret_cast<intptr_t>(w->GetClientData()) != m_selectedIndex)
w->SetBackgroundColour(*wxWHITE);
w->Refresh();
});

m_gridSizer->Add(iconCtrl, 0, wxALIGN_CENTER | wxALL, 2);
m_iconWidgets.push_back(iconCtrl);
}

m_scrollWin->SetSizer(m_gridSizer);
m_gridSizer->FitInside(m_scrollWin);

dialogSizer->Add(m_scrollWin, 1, wxEXPAND | wxALL, 5);

// bottom area
wxStaticLine* panelSeparatorLine = new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
dialogSizer->Add(panelSeparatorLine, 0, wxGROW | wxLEFT | wxRIGHT, 10);

// Buttons
wxBoxSizer* btnSizer = new wxBoxSizer(wxHORIZONTAL);
btnSizer->AddStretchSpacer(1);
btnSizer->Add(new wxButton(this, wxID_CANCEL), 0, wxALL | wxALIGN_CENTER, 10);

wxButton* rstBtn = new wxButton(this, wxID_RESET, "&Default");
rstBtn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
m_selectedIndex = -1;
EndModal(wxID_OK);
});
btnSizer->Add(rstBtn, 0, wxALL | wxALIGN_CENTER, 10);

btnSizer->Add(new wxButton(this, wxID_OK), 0, wxALL | wxALIGN_CENTER, 10);
btnSizer->AddStretchSpacer(1);

dialogSizer->Add(btnSizer, 0, wxEXPAND | wxALL, 5);

SetSizer(dialogSizer);

// Dialog window
SetMinSize(wxSize(400, 300));
SetSize(wxSize(400, 600));
Layout();
Centre();
}

void IconSelectionDialog::OnIconClicked(wxMouseEvent& event)
{
wxStaticBitmap* clicked = dynamic_cast<wxStaticBitmap*>(event.GetEventObject());
if (!clicked) return;

int index = reinterpret_cast<intptr_t>(clicked->GetClientData());
m_selectedIndex = index;

for (auto* icon : m_iconWidgets)
{
icon->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
icon->Refresh();
}

clicked->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
clicked->Refresh();

event.Skip();
}

int IconSelectionDialog::GetSelectedIndex() const
{
return m_selectedIndex;
}
23 changes: 23 additions & 0 deletions src/dialog/IconManagerDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,26 @@ class IconManagerDialog : public wxDialog

wxDECLARE_EVENT_TABLE();
};


class IconSelectionDialog : public wxDialog
{
public:
IconSelectionDialog(wxWindow* parent, wxVector<wxBitmapBundle>& images, int iconSize = 32);

int GetSelectedIndex() const;
//wxBitmapBundle GetSelectedIcon() const;

private:
void OnIconClicked(wxMouseEvent& event);

wxScrolledWindow* m_scrollWin;
wxGridSizer* m_gridSizer;

wxVector<wxBitmapBundle> m_icons;
int m_selectedIndex = wxNOT_FOUND;

std::vector<wxStaticBitmap*> m_iconWidgets;

//wxDECLARE_EVENT_TABLE();
};
12 changes: 0 additions & 12 deletions src/dialog/NavigatorEditDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,6 @@ void NavigatorEditDialog::CreateControls()

wxStaticText* iconLabel = new wxStaticText(uiBox, wxID_ANY, _t("Symbol") + ":");

/* wxImageList* imageList = new wxImageList(navIconSize, navIconSize);
for (const auto& bundle : navtree_images_list(navIconSize)) {
wxBitmap bitmap = bundle.GetBitmap(wxSize(navIconSize, navIconSize));
imageList->Add(bitmap);
}
wxImageList* imageList = NavTreeIconImages::instance().getImageList();*/

const auto navIconSize = PrefModel::instance().getNavigationIconSize();
m_cbIcon = new wxBitmapComboBox(uiBox, wxID_ANY, "",
wxPoint(navIconSize, navIconSize), wxDefaultSize,
Expand All @@ -122,11 +115,6 @@ void NavigatorEditDialog::CreateControls()
m_cbIcon->Append("", bitmap);
}

/*const int imageCount = imageList->GetImageCount();
for (int i = 0; i < imageCount; ++i) {
m_cbIcon->Append("", imageList->GetBitmap(i));
}*/

uiStyleSizer->Add(iconLabel, g_flagsH);
uiStyleSizer->Add(m_cbIcon, g_flagsH);

Expand Down
Loading
Loading