* Create a grid directory for grid's components
* Fix a bug inside ShowPanels * Add fast comboboxes editing inside grids
This commit is contained in:
223
src/view/grid/GridAccount.cpp
Normal file
223
src/view/grid/GridAccount.cpp
Normal file
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
Copyright 2010 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
KissCount is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
KissCount is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "GridAccount.h"
|
||||
|
||||
#define SET_ROW_COLOR(row, color) for(int i=0; i<NUMBER_COLS_OPS; i++) \
|
||||
{ \
|
||||
SetCellBackgroundColour(row, i, color); \
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(GridAccount, wxGrid)
|
||||
EVT_GRID_CELL_LEFT_CLICK(GridAccount::OnCellLeftClick )
|
||||
END_EVENT_TABLE()
|
||||
|
||||
GridAccount::GridAccount(KissCount* kiss, wxWindow *parent, wxWindowID id) : wxGrid(parent, id),
|
||||
_fixCosts(0), _week1(0), _week2(0), _week3(0), _week4(0), _kiss(kiss)
|
||||
{
|
||||
wxBitmap deleteBitmap(wxT(DELETE_ICON));
|
||||
wxBitmap checkedBitmap(wxT(CHECKED_ICON));
|
||||
DEFAULT_FONT(font);
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
std::vector<Account>::iterator accountIt;
|
||||
std::vector<Category>::iterator categoryIt;
|
||||
|
||||
CreateGrid(1, NUMBER_COLS_OPS);
|
||||
SetColLabelSize(0);
|
||||
SetRowLabelSize(0);
|
||||
|
||||
SetColSize (0, GetColSize(0)*3);
|
||||
SetDefaultCellFont(font);
|
||||
|
||||
font.SetWeight(wxFONTWEIGHT_BOLD);
|
||||
wxString colsName[] = {_("Description"), _("Date"), _("Debit"), _("Credit"), _("Category"), _("Account"), wxT(""), wxT("")};
|
||||
for(i=0; i<NUMBER_COLS_OPS; i++)
|
||||
{
|
||||
SetCellValue(0, i, colsName[i]);
|
||||
SetCellBackgroundColour(0, i, OWN_CYAN);
|
||||
SetCellFont(0, i, font);
|
||||
SetReadOnly(0, i, true);
|
||||
SetCellAlignment(0, i, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
}
|
||||
SetCellRenderer(0, DELETE, new wxGridCellBitmapRenderer(deleteBitmap));
|
||||
SetCellRenderer(0, CHECKED, new wxGridCellBitmapRenderer(checkedBitmap));
|
||||
|
||||
_accounts = new wxString[user->GetAccountsNumber()];
|
||||
for (i=0,
|
||||
accountIt = user->_accounts.begin();
|
||||
accountIt != user->_accounts.end();
|
||||
accountIt++, i++)
|
||||
_accounts[i] = accountIt->name;
|
||||
|
||||
_categories = new wxString[user->GetCategoriesNumber()] ;
|
||||
for(i=0, categoryIt = user->_categories.begin();
|
||||
categoryIt != user->_categories.end();
|
||||
categoryIt++, i++)
|
||||
{
|
||||
_categories[i] = categoryIt->name ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
GridAccount::~GridAccount()
|
||||
{
|
||||
delete[] _categories;
|
||||
delete[] _accounts;
|
||||
}
|
||||
|
||||
wxPen GridAccount::GetColGridLinePen (int col)
|
||||
{return wxPen(*wxBLACK, 1, wxSOLID);}
|
||||
|
||||
wxPen GridAccount::GetRowGridLinePen (int row) {
|
||||
if (row == 0 || row == _fixCosts ||
|
||||
row == _week1 ||
|
||||
row == _week2 ||
|
||||
row == _week3 ||
|
||||
row == _week4)
|
||||
return wxPen(*wxBLACK, 1, wxSOLID);
|
||||
|
||||
return GetCellBackgroundColour(row, 0);
|
||||
}
|
||||
|
||||
void GridAccount::SetWeek(int week, int line) {
|
||||
switch (week) {
|
||||
case 1: _week1 = line; break;
|
||||
case 2: _week2 = line; break;
|
||||
case 3: _week3 = line; break;
|
||||
case 4: _week4 = line; break;
|
||||
}
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperation(User* user, Operation* op, int line, bool fix, int curMonth, int curYear)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
int r, g, b;
|
||||
wxColour color;
|
||||
wxDateTime curDate;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
if (!op && !user->_accounts.size()) return;
|
||||
|
||||
InsertRows(line, 1);
|
||||
|
||||
SetCellEditor(line, DEBIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
||||
SetCellEditor(line, CREDIT, new wxGridCellFloatEditor(wxID_ANY, 2));
|
||||
wxGridCellChoiceEditor* accountEditor = new wxGridCellChoiceEditor(user->GetAccountsNumber(), _accounts, false);
|
||||
SetCellEditor(line, ACCOUNT, accountEditor);
|
||||
wxGridCellChoiceEditor* categoryEditor = new wxGridCellChoiceEditor(user->GetCategoriesNumber()-1, _categories+1, false);
|
||||
SetCellEditor(line, CATEGORY, categoryEditor);
|
||||
|
||||
if (fix)
|
||||
{
|
||||
SetCellValue(line, CATEGORY, _("Fix"));
|
||||
SetReadOnly(line, CATEGORY);
|
||||
}
|
||||
|
||||
if (op)
|
||||
{
|
||||
SetCellEditor(line, DATE, new CalendarEditor(op->day, op->month, op->year));
|
||||
SetCellValue(line, DESCRIPTION, op->description);
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), op->day+1, op->month+1, op->year));
|
||||
if (op->amount < 0)
|
||||
SetCellValue(line, DEBIT, wxString::Format(wxT("%.2lf"), -op->amount));
|
||||
else
|
||||
SetCellValue(line, CREDIT, wxString::Format(wxT("%.2lf"), op->amount));
|
||||
SetCellValue(line, ACCOUNT, user->GetAccountName(op->account));
|
||||
if (!fix)
|
||||
SetCellValue(line, CATEGORY, user->GetCategoryName(op->category));
|
||||
SetCellRenderer(line, DELETE, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, DELETE, new wxGridCellFastBoolEditor ());
|
||||
SetCellRenderer(line, CHECKED, new wxGridCellBoolRenderer ());
|
||||
SetCellEditor(line, CHECKED, new wxGridCellFastBoolEditor ());
|
||||
|
||||
color = user->GetCategory(op->category).color;
|
||||
|
||||
if (op->checked)
|
||||
{
|
||||
r = ((color.Red()*1.5) >= 0xFF) ? 0xFF : color.Red()*1.5 ;
|
||||
g = ((color.Green()*1.5) >= 0xFF) ? 0xFF : color.Green()*1.5 ;
|
||||
b = ((color.Blue()*1.5) >= 0xFF) ? 0xFF : color.Blue()*1.5 ;
|
||||
color.Set(r, g, b, color.Alpha());
|
||||
SetCellValue(line, CHECKED, wxT("1"));
|
||||
}
|
||||
|
||||
SET_ROW_COLOR(line, color);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
if (!fix &&
|
||||
curDate.GetMonth() == curMonth &&
|
||||
curDate.GetYear() == curYear)
|
||||
{
|
||||
SetCellValue(line, DATE, wxString::Format(wxT("%02d/%02d/%d"), curDate.GetDay(), curMonth+1, curYear));
|
||||
SetCellEditor(line, DATE, new CalendarEditor(curDate.GetDay()-1, curMonth, curYear));
|
||||
}
|
||||
else
|
||||
SetCellEditor(line, DATE, new CalendarEditor(0, curMonth, curYear));
|
||||
|
||||
if (fix)
|
||||
SET_ROW_COLOR(line, OWN_YELLOW)
|
||||
else
|
||||
SET_ROW_COLOR(line, OWN_GREEN);
|
||||
|
||||
SetReadOnly(line, CHECKED, true);
|
||||
SetReadOnly(line, DELETE, true);
|
||||
}
|
||||
|
||||
SetCellAlignment(line, DEBIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, CREDIT, wxALIGN_RIGHT, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
SetCellAlignment(line, CHECKED, wxALIGN_CENTRE, wxALIGN_CENTRE);
|
||||
|
||||
Layout();
|
||||
SetMinSize(GetMinSize());
|
||||
}
|
||||
|
||||
// From http://nomadsync.cvs.sourceforge.net/nomadsync/nomadsync/src/
|
||||
void GridAccount::OnCellLeftClick(wxGridEvent& evt)
|
||||
{
|
||||
if (evt.GetCol() != DELETE && evt.GetCol() != CHECKED) { evt.Skip() ; return;}
|
||||
|
||||
// This forces the cell to go into edit mode directly
|
||||
//m_waitForSlowClick = TRUE;
|
||||
SetGridCursor(evt.GetRow(), evt.GetCol());
|
||||
// Store the click co-ordinates in the editor if possible
|
||||
// if an editor has created a ClientData area, we presume it's
|
||||
// a wxPoint and we store the click co-ordinates
|
||||
wxGridCellEditor* pEditor = GetCellEditor(evt.GetRow(), evt.GetCol());
|
||||
wxPoint* pClickPoint = (wxPoint*)pEditor->GetClientData();
|
||||
if (pClickPoint)
|
||||
{
|
||||
*pClickPoint = ClientToScreen(evt.GetPosition());
|
||||
#ifndef __WINDOWS__
|
||||
EnableCellEditControl(true);
|
||||
#endif
|
||||
}
|
||||
// hack to prevent selection from being lost when click combobox
|
||||
if (evt.GetCol() == 0 && IsInSelection(evt.GetRow(), evt.GetCol()))
|
||||
{
|
||||
//m_selTemp = m_selection;
|
||||
m_selection = NULL;
|
||||
}
|
||||
pEditor->DecRef();
|
||||
evt.Skip();
|
||||
}
|
||||
Reference in New Issue
Block a user