Calendar work done
This commit is contained in:
parent
eacaa1a460
commit
3ea364b22f
|
@ -3,7 +3,7 @@
|
|||
enum {DESCRIPTION, DATE, DEBIT, CREDIT, CATEGORY, ACCOUNT, DELETE, CHECKED, NUMBER_COLS_OPS};
|
||||
enum {ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_INIT, ACCOUNT_CUR, ACCOUNT_FINAL, NUMBER_COLS_ACCOUNTS};
|
||||
enum {CUR_CREDIT, CUR_DEBIT, TOTAL_CREDIT, TOTAL_DEBIT, REMAINS, STATS_ROW, CATS_STATS};
|
||||
enum {CALENDAR_TREE_ID=10, OPS_GRID_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID};
|
||||
enum {CALENDAR_TREE_ID, OPS_GRID_ID, CALENDAR_ID, ACCOUNTS_GRID_ID, MENU_GENERATE_ID, MENU_DELETE_ID};
|
||||
|
||||
static wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), _(""), _("")};
|
||||
|
||||
|
@ -16,11 +16,13 @@ EVT_TREE_KEY_DOWN(CALENDAR_TREE_ID, AccountPanel::OnTreeChange)
|
|||
EVT_MENU(MENU_GENERATE_ID, AccountPanel::OnMenuGenerate)
|
||||
EVT_MENU(MENU_DELETE_ID, AccountPanel::OnMenuDelete)
|
||||
EVT_SHOW(AccountPanel::OnShow)
|
||||
EVT_CALENDAR_SEL_CHANGED(CALENDAR_ID, AccountPanel::OnCalendarChange)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)), _curMonth(-1), _curYear(-1), _kiss(kiss), _wxUI(parent), _tree(this, CALENDAR_TREE_ID, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT)
|
||||
{
|
||||
wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer *hbox2 = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);
|
||||
wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
|
||||
wxChartPanel* chart ;
|
||||
|
@ -47,6 +49,12 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|||
ColorScheme* colorScheme = new ColorScheme(categoryColors, WXSIZEOF(categoryColors));
|
||||
|
||||
_pie = new PiePlot();
|
||||
_calendar = new wxCalendarCtrl(this, CALENDAR_ID, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize,
|
||||
wxCAL_MONDAY_FIRST | wxCAL_NO_MONTH_CHANGE | wxCAL_SEQUENTIAL_MONTH_SELECTION);
|
||||
_calendar->EnableMonthChange(false);
|
||||
_calendar->EnableYearChange(false);
|
||||
_calendar->EnableHolidayDisplay(false);
|
||||
_calendar->Enable(false);
|
||||
|
||||
_accounts = new wxString[user->GetAccountsNumber()];
|
||||
for (i=0,
|
||||
|
@ -122,7 +130,9 @@ AccountPanel::AccountPanel(KissCount* kiss, wxUI *parent) : wxPanel(&(*parent)),
|
|||
chart->SetMinSize(// chart->GetSize()
|
||||
wxSize(200,250));
|
||||
hbox->Add(&_tree, 0);
|
||||
vbox2->Add(_accountsGrid, 0);
|
||||
hbox2->Add(_accountsGrid, 0);
|
||||
hbox2->Add(_calendar, 0);
|
||||
vbox2->Add(hbox2, 0);
|
||||
vbox2->Add(-1, 10);
|
||||
vbox2->Add(_grid, 0);
|
||||
hbox->Add(vbox2, 0);
|
||||
|
@ -313,6 +323,7 @@ void AccountPanel::ShowMonth(int month, int year)
|
|||
_curYear = year;
|
||||
_curMonth = month;
|
||||
_wxUI->SetTitle(user->_name + _(" - ") + months[month] + _(" ") + wxString::Format(wxT("%d"), year));
|
||||
_calendar->Enable(true);
|
||||
|
||||
if (_grid->GetNumberRows() > 1)
|
||||
_grid->DeleteRows(1, _grid->GetNumberRows()-1);
|
||||
|
@ -343,6 +354,19 @@ void AccountPanel::ShowMonth(int month, int year)
|
|||
|
||||
UpdateStats();
|
||||
|
||||
_calendar->EnableMonthChange(true);
|
||||
_calendar->EnableYearChange(true);
|
||||
if (curDate.GetMonth() == month && curDate.GetYear() == year)
|
||||
_calendar->SetDate(curDate) ;
|
||||
else if (curDate.GetMonth() > month || curDate.GetYear() > year)
|
||||
_calendar->SetDate(curDate.GetLastMonthDay((wxDateTime::Month)month, year));
|
||||
else if (curDate.GetMonth() < month || curDate.GetYear() < year)
|
||||
_calendar->SetDate(wxDateTime(1, (wxDateTime::Month)month, year));
|
||||
|
||||
_calendar->EnableMonthChange(false);
|
||||
_calendar->EnableYearChange(false);
|
||||
_calendar->SetSize(_calendar->GetMinSize());
|
||||
|
||||
Fit();
|
||||
SetMinSize(GetSize());
|
||||
}
|
||||
|
@ -374,7 +398,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
|
|||
|
||||
if (op)
|
||||
{
|
||||
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day+1, op->month, op->year));
|
||||
_grid->SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
||||
_grid->SetCellValue(line, DESCRIPTION, op->description);
|
||||
_grid->SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
||||
if (op->amount < 0)
|
||||
|
@ -404,7 +428,7 @@ void AccountPanel::InsertOperation(User* user, operation* op, int line, bool fix
|
|||
}
|
||||
else
|
||||
{
|
||||
_grid->SetCellEditor(line, DATE, new CalendarEditor(1, _curMonth, _curYear));
|
||||
_grid->SetCellEditor(line, DATE, new CalendarEditor(0, _curMonth, _curYear));
|
||||
if (fix)
|
||||
SET_ROW_COLOR(line, OWN_YELLOW)
|
||||
else
|
||||
|
@ -483,13 +507,17 @@ void AccountPanel::UpdateStats()
|
|||
User* user = _kiss->GetUser();
|
||||
std::vector<operation>::iterator it;
|
||||
double curCredit, curDebit, totalCredit, totalDebit, remains, value;
|
||||
wxDateTime curDate;
|
||||
wxDateTime date;
|
||||
std::map<wxString, double> curAccountAmount, finalAccountAmount;
|
||||
std::map<wxString, double>::iterator doubleIt;
|
||||
std::map<wxString, int>::iterator intIt;
|
||||
std::vector<Account>::iterator accountIt;
|
||||
unsigned int day, month, year ;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
date = _calendar->GetDate();
|
||||
day = date.GetDay()-1;
|
||||
month = date.GetMonth();
|
||||
year = date.GetYear();
|
||||
|
||||
curCredit = curDebit = totalCredit = totalDebit = 0.0;
|
||||
|
||||
|
@ -506,7 +534,7 @@ void AccountPanel::UpdateStats()
|
|||
{
|
||||
if (it->amount > 0)
|
||||
{
|
||||
if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year)
|
||||
if (day >= it->day && month >= it->month && year >= it->year)
|
||||
{
|
||||
curCredit += it->amount;
|
||||
curAccountAmount[it->account] += it->amount;
|
||||
|
@ -517,7 +545,7 @@ void AccountPanel::UpdateStats()
|
|||
else
|
||||
{
|
||||
_categoriesValues[_categoriesIndexes[user->GetCategoryName(it->category)]] += -it->amount ;
|
||||
if (curDate.GetDay() >= it->day && curDate.GetMonth() >= (int)it->month && curDate.GetYear() >= (int)it->year)
|
||||
if (day >= it->day && month >= it->month && year >= it->year)
|
||||
{
|
||||
curDebit += -it->amount;
|
||||
curAccountAmount[it->account] += it->amount;
|
||||
|
@ -672,6 +700,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
|||
}
|
||||
|
||||
new_op.id = cur_op.id;
|
||||
new_op.fix_cost = true;
|
||||
if (cur_op.day != new_op.day)
|
||||
{
|
||||
need_insertion = true;
|
||||
|
@ -708,6 +737,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
|||
row--;
|
||||
cur_op = (*_curOperations)[row] ;
|
||||
new_op.id = cur_op.id;
|
||||
new_op.fix_cost = false;
|
||||
|
||||
if (col == DELETE)
|
||||
{
|
||||
|
@ -755,15 +785,7 @@ void AccountPanel::OnOperationModified(wxGridEvent& event)
|
|||
if ((*_curOperations)[i].fix_cost && !fix_op) continue;
|
||||
if (!(*_curOperations)[i].fix_cost && fix_op) break;
|
||||
if ((*_curOperations)[i].day > new_op.day)
|
||||
{
|
||||
if (i)
|
||||
{
|
||||
// First Operation
|
||||
if ((*_curOperations)[i-1].fix_cost && !fix_op) break;
|
||||
i--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
_curOperations->insert(_curOperations->begin()+i ,new_op);
|
||||
|
@ -1040,3 +1062,8 @@ void AccountPanel::OnShow(wxShowEvent& event)
|
|||
else
|
||||
_wxUI->SetTitle(_kiss->GetUser()->_name);
|
||||
}
|
||||
|
||||
void AccountPanel::OnCalendarChange(wxCalendarEvent& event)
|
||||
{
|
||||
UpdateStats();
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
void OnMenuGenerate(wxCommandEvent& event);
|
||||
void OnMenuDelete(wxCommandEvent& event);
|
||||
void OnShow(wxShowEvent& event);
|
||||
void OnCalendarChange(wxCalendarEvent& event);
|
||||
|
||||
int _curMonth, _curYear;
|
||||
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
KissCount* _kiss;
|
||||
wxUI* _wxUI;
|
||||
wxTreeCtrl _tree;
|
||||
wxCalendarCtrl* _calendar;
|
||||
GridAccount* _grid;
|
||||
wxGrid *_statsGrid, *_accountsGrid;
|
||||
PiePlot* _pie;
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
#include "CalendarEditor.h"
|
||||
|
||||
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL)
|
||||
CalendarEditor::CalendarEditor(int day, int month, int year) : _day(day), _month(month), _year(year), _parent(NULL), _days(NULL), _editor(NULL)
|
||||
{
|
||||
_calendar = new wxCalendarCtrl();
|
||||
wxDateTime date;
|
||||
int i;
|
||||
|
||||
_maxDay = date.GetLastMonthDay ((wxDateTime::Month) month, year).GetDay()+1;
|
||||
|
||||
_days = new wxString[_maxDay];
|
||||
|
||||
for (i=0; i<_maxDay; i++)
|
||||
_days[i] = wxString::Format(_("%d"), i+1) ;
|
||||
|
||||
_editor = new wxChoice();
|
||||
}
|
||||
|
||||
CalendarEditor::~CalendarEditor()
|
||||
{
|
||||
if (_calendar) delete _calendar;
|
||||
delete _editor;
|
||||
delete[] _days;
|
||||
}
|
||||
|
||||
void CalendarEditor::BeginEdit(int row, int col, wxGrid *grid)
|
||||
|
@ -28,15 +39,9 @@ wxGridCellEditor* CalendarEditor::Clone() const
|
|||
void CalendarEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *evtHandler)
|
||||
{
|
||||
_parent = parent;
|
||||
_calendar->Create(_parent, id, wxDateTime(_day, _month, _year));
|
||||
_calendar->EnableHolidayDisplay(false);
|
||||
_calendar->EnableMonthChange(false);
|
||||
_calendar->EnableYearChange(false);
|
||||
// (void (wxObject::*)(wxEvent&))
|
||||
_calendar->Connect((int)id, (int)wxEVT_CALENDAR_SEL_CHANGED, wxCommandEventHandler(CalendarEditor::OnCalendarChange), NULL, this);
|
||||
//evtHandler->Connect((int)id, (int)wxEVT_CALENDAR_DOUBLECLICKED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange);
|
||||
//_calendar->Connect(wxEVT_CALENDAR_SEL_CHANGED, (void (wxObject::*)(wxEvent&))&CalendarEditor::OnCalendarChange);
|
||||
//wxGridCellEditor::Create(parent, id, evtHandler);
|
||||
_editor->Create(parent, id, wxDefaultPosition, wxDefaultSize, _maxDay, _days);
|
||||
_editor->Select(_day);
|
||||
_editor->Connect((int)id, (int)wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(CalendarEditor::OnDateChanged), NULL, this);
|
||||
}
|
||||
|
||||
bool CalendarEditor::EndEdit (int row, int col, wxGrid *grid)
|
||||
|
@ -58,32 +63,30 @@ wxString CalendarEditor::GetValue() const
|
|||
|
||||
void CalendarEditor::Reset()
|
||||
{
|
||||
_calendar->SetDate(wxDateTime(_day, _month, _year));
|
||||
_editor->Select(_day);
|
||||
}
|
||||
|
||||
void CalendarEditor::Show (bool show, wxGridCellAttr *attr)
|
||||
{
|
||||
_calendar->SetDate(wxDateTime(_day, _month, _year));
|
||||
_calendar->Show(show);
|
||||
_editor->Show(show);
|
||||
}
|
||||
|
||||
void CalendarEditor::SetSize (const wxRect &rect)
|
||||
{
|
||||
wxSize size = _calendar->GetMinSize();
|
||||
_calendar->SetSize(wxRect(rect.x, rect.y, size.GetWidth(), size.GetHeight()));
|
||||
}
|
||||
|
||||
void CalendarEditor::OnCalendarChange(wxCommandEvent& event)
|
||||
{
|
||||
_day = _calendar->GetDate().GetDay();
|
||||
//_calendar->Show(false);
|
||||
_editor->SetSize(rect);
|
||||
}
|
||||
|
||||
void CalendarEditor::StartingClick()
|
||||
{
|
||||
Show(true, NULL);
|
||||
}
|
||||
|
||||
bool CalendarEditor::IsAcceptedKey(wxKeyEvent &event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void CalendarEditor::OnDateChanged(wxCommandEvent& event)
|
||||
{
|
||||
_day = _editor->GetSelection()+1;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@
|
|||
#include <wx/calctrl.h>
|
||||
#include <wx/datetime.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/choice.h>
|
||||
|
||||
class CalendarEditor : public wxGridCellEditor, public wxEvtHandler
|
||||
class CalendarEditor : public wxGridCellChoiceEditor, public wxEvtHandler
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -23,7 +24,8 @@ public:
|
|||
void Reset();
|
||||
void Show(bool show, wxGridCellAttr *attr=NULL);
|
||||
void SetSize (const wxRect &rect);
|
||||
void OnCalendarChange(wxCommandEvent& event);
|
||||
/* void OnCalendarChange(wxCommandEvent& event); */
|
||||
void OnDateChanged(wxCommandEvent& event);
|
||||
void StartingClick();
|
||||
bool IsAcceptedKey(wxKeyEvent &event);
|
||||
|
||||
|
@ -32,7 +34,9 @@ private:
|
|||
int _month;
|
||||
int _year;
|
||||
wxWindow *_parent;
|
||||
wxCalendarCtrl *_calendar;
|
||||
wxString* _days;
|
||||
int _maxDay;
|
||||
wxChoice* _editor;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,19 +13,19 @@ wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxS
|
|||
{
|
||||
_hbox = new wxBoxSizer(wxVERTICAL);
|
||||
ButtonPanel* buttons = new ButtonPanel(_kiss, this);
|
||||
wxMenu *menuFile = new wxMenu;
|
||||
// wxMenu *menuFile = new wxMenu;
|
||||
|
||||
menuFile->Append( ID_About, _("&About...") );
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append( ID_Quit, _("E&xit") );
|
||||
// menuFile->Append( ID_About, _("&About...") );
|
||||
// menuFile->AppendSeparator();
|
||||
// menuFile->Append( ID_Quit, _("E&xit") );
|
||||
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
menuBar->Append( menuFile, _("&File") );
|
||||
// wxMenuBar *menuBar = new wxMenuBar;
|
||||
// menuBar->Append( menuFile, _("&File") );
|
||||
|
||||
SetMenuBar( menuBar );
|
||||
// SetMenuBar( menuBar );
|
||||
|
||||
CreateStatusBar();
|
||||
SetStatusText( _("Welcome to wxWidgets!") );
|
||||
// CreateStatusBar();
|
||||
// SetStatusText( _("Welcome to wxWidgets!") );
|
||||
|
||||
SetSizer(_hbox);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user