2010-07-10 16:34:30 +02:00
|
|
|
/*
|
2011-02-13 19:30:12 +01:00
|
|
|
Copyright 2010-2011 Grégory Soutadé
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
This file is part of KissCount.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
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.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
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.
|
2010-07-10 16:34:30 +02:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-10 16:34:30 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
/*#include "AccountPanel.hpp"
|
2011-08-20 14:02:47 +02:00
|
|
|
#include "PreferencesPanel.hpp"
|
|
|
|
#include "UsersDialog.hpp"
|
|
|
|
#include "GenerateDialog.hpp"
|
|
|
|
#include "SearchPanel.hpp"
|
|
|
|
#include "StatsPanel.hpp"
|
|
|
|
#include "ImportPanel.hpp"
|
|
|
|
#include "ExportPanel.hpp"
|
|
|
|
|
|
|
|
#include "grid/wxMyGrid.hpp"
|
|
|
|
#include "grid/wxGridCellFastBoolEditor.hpp"
|
|
|
|
#include "grid/wxGridCellButtonRenderer.hpp"
|
|
|
|
#include "grid/wxGridCellButtonEditor.hpp"
|
2011-08-25 17:45:41 +02:00
|
|
|
*/
|
2011-08-20 14:02:47 +02:00
|
|
|
#include "wxUI.hpp"
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2011-09-03 10:38:36 +02:00
|
|
|
#include "UsersDialog.hpp"
|
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
enum {BUTTON_CHANGE_USER_ID=-4, BUTTON_ABOUT_ID=-5, BUTTON_QUIT_ID=-6};
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
QString wxUI::months[12] ;
|
2011-08-25 17:45:41 +02:00
|
|
|
QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
|
|
|
|
QColor(0xFF, 0x3E, 0x0E),
|
|
|
|
QColor(0xFF, 0xD3, 0x20),
|
|
|
|
QColor(0x58, 0x9D, 0x1B),
|
|
|
|
QColor(0x7E, 0x00, 0x21),
|
|
|
|
QColor(0x83, 0xCC, 0xFF),
|
|
|
|
QColor(0x31, 0x40, 0x04),
|
|
|
|
QColor(0xB0, 0xCF, 0x00),
|
|
|
|
QColor(0x4B, 0x1F, 0x6F),
|
|
|
|
QColor(0xFF, 0x93, 0x0E),
|
|
|
|
QColor(0xC5, 0x00, 0x0D),
|
|
|
|
QColor(0x00, 0x84, 0xD1)};
|
|
|
|
|
|
|
|
wxUI::wxUI(KissCount* kiss, const QString& title)
|
|
|
|
: QFrame(0), _kiss(kiss),
|
2011-08-14 17:47:16 +02:00
|
|
|
_curPanel(0), _locale(0), _needReload(false)
|
2010-05-14 15:04:01 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
setWindowTitle(title);
|
2011-02-05 21:02:03 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _vbox = new wxBoxSizer(wxVERTICAL);
|
|
|
|
// _buttonsBox = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
// // ButtonPanel* buttons = new ButtonPanel(_kiss, this);
|
|
|
|
// // wxMenu *menuFile = new wxMenu;
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// // menuFile->Append( ID_About, wxT("&About...") );
|
|
|
|
// // menuFile->AppendSeparator();
|
|
|
|
// // menuFile->Append( ID_Quit, wxT("E&xit") );
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// // wxMenuBar *menuBar = new wxMenuBar;
|
|
|
|
// // menuBar->Append( menuFile, wxT("&File") );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// // SetMenuBar( menuBar );
|
2010-05-14 15:04:01 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// // CreateStatusBar();
|
|
|
|
// // SetStatusText( wxT("Welcome to wxWidgets!") );
|
|
|
|
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_CHANGE_USER_ID, wxBitmap(wxT(CHANGE_USER_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
|
|
|
|
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_ABOUT_ID, wxBitmap(wxT(ABOUT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
|
|
|
|
// _buttonsBox->Add(new wxBitmapButton(this, BUTTON_QUIT_ID, wxBitmap(wxT(QUIT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)));
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// SetSizer(_vbox);
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _vbox->Add(_buttonsBox, 0, wxGROW);
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
wxUI::~wxUI()
|
|
|
|
{
|
2011-09-03 10:38:36 +02:00
|
|
|
//int i;
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// for (i=0; i<(int)_panels.size(); i++)
|
|
|
|
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2010-08-26 21:28:15 +02:00
|
|
|
if (_locale) delete _locale;
|
2010-07-04 19:39:39 +02:00
|
|
|
}
|
|
|
|
|
2011-08-27 18:35:36 +02:00
|
|
|
bool wxUI::SetLanguage(QString language)
|
2010-07-04 19:39:39 +02:00
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
bool res = true;
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// if (_locale) delete _locale;
|
|
|
|
// _locale = 0;
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// // load language if possible, fall back to english otherwise
|
|
|
|
// if(wxLocale::IsAvailable(language))
|
|
|
|
// {
|
|
|
|
// _locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// #ifdef __WXGTK__
|
|
|
|
// _locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
|
|
|
|
// #endif
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _locale->AddCatalog(wxT("frenchpp"));
|
|
|
|
// _locale->AddCatalog(wxT("kisscount"));
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _language = (wxLanguage) language;
|
|
|
|
// }
|
2010-07-04 19:39:39 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// if (_locale == 0 || !_locale->IsOk())
|
|
|
|
// {
|
|
|
|
// if (_locale) delete _locale;
|
|
|
|
// _locale = new wxLocale();
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// #ifdef __WXGTK__
|
|
|
|
// _locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
|
|
|
|
// #endif
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _locale->AddCatalog(wxT("kisscount"));
|
2010-07-07 21:04:38 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// _language = wxLANGUAGE_ENGLISH;
|
|
|
|
// res = false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// months[0] = _("january");
|
|
|
|
// months[1] = _("february");
|
|
|
|
// months[2] = _("marchpp");
|
|
|
|
// months[3] = _("april");
|
|
|
|
// months[4] = _("may");
|
|
|
|
// months[5] = _("june");
|
|
|
|
// months[6] = _("july");
|
|
|
|
// months[7] = _("august");
|
|
|
|
// months[8] = _("september");
|
|
|
|
// months[9] = _("october");
|
|
|
|
// months[10] = _("november");
|
|
|
|
// months[11] = _("december") ;
|
2010-08-26 21:28:15 +02:00
|
|
|
|
|
|
|
return res;
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
#define ADD_PANEL(panelName, id) \
|
|
|
|
panel = new panelName(_kiss, this); \
|
|
|
|
button = panel->GetButton(id); \
|
|
|
|
button->SetToolTip(panel->GetToolTip()); \
|
|
|
|
_buttonsBox->Insert(id, button); \
|
|
|
|
_buttons.insert(_buttons.begin()+id, button); \
|
|
|
|
_panels.push_back(panel); \
|
|
|
|
Connect(id, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), panel, this);
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
void wxUI::InitPanels()
|
2010-07-14 11:15:48 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// KissPanel* panel;
|
|
|
|
// wxBitmapButton* button;
|
|
|
|
// _panels.clear();
|
|
|
|
|
|
|
|
// ADD_PANEL(AccountPanel, 0);
|
|
|
|
// ADD_PANEL(StatsPanel, 1);
|
|
|
|
// ADD_PANEL(SearchPanel, 2);
|
|
|
|
// ADD_PANEL(PreferencesPanel, 3);
|
|
|
|
// ADD_PANEL(ImportPanel, 4);
|
|
|
|
// ADD_PANEL(ExportPanel, 5);
|
2010-07-14 11:15:48 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
void wxUI::LoadPanels()
|
2010-08-17 18:59:19 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// std::vector<KissPanel*>::iterator it;
|
|
|
|
// KissPanel* temp;
|
|
|
|
// int i;
|
|
|
|
|
|
|
|
// if (_curPanel)
|
|
|
|
// {
|
|
|
|
// _vbox->Detach(_curPanel);
|
|
|
|
// _curPanel = 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (_panels.size())
|
|
|
|
// {
|
|
|
|
// for (i=0; i<(int)_panels.size(); i++)
|
|
|
|
// {
|
|
|
|
// temp = _panels[i]->CreatePanel();
|
|
|
|
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
|
|
|
|
// _panels[i] = temp;
|
|
|
|
// Connect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), temp, this);
|
|
|
|
// _buttons[i]->SetToolTip(temp->GetToolTip());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// InitPanels();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::LoadUser()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
User* user = _kiss->GetUser();
|
2010-05-17 18:03:21 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
if (user->_preferences["language"].size())
|
2010-12-20 19:28:24 +01:00
|
|
|
SetLanguage(user->GetLanguage());
|
2010-07-14 11:15:48 +02:00
|
|
|
|
2011-08-06 17:30:16 +02:00
|
|
|
LoadPanels();
|
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
if (_panels.size())
|
|
|
|
ShowPanel(_panels[0]);
|
2010-05-17 18:03:21 +02:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:28:24 +01:00
|
|
|
void wxUI::ShowPanel(KissPanel* panel)
|
2010-05-17 18:03:21 +02:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// wxShowEvent event;
|
|
|
|
// int i;
|
|
|
|
// User* user = _kiss->GetUser();
|
|
|
|
|
|
|
|
// if (!panel) return;
|
|
|
|
|
|
|
|
// if (_curPanel)
|
|
|
|
// {
|
|
|
|
// _vbox->Detach(_curPanel);
|
|
|
|
// _curPanel->Hide();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (_needReload)
|
|
|
|
// {
|
|
|
|
// user->InvalidateOperations();
|
|
|
|
// for(i=0; i<(int)_panels.size(); i++)
|
|
|
|
// if (_panels[i] == panel) break;
|
|
|
|
// LoadPanels();
|
|
|
|
// _needReload = false;
|
|
|
|
// _curPanel = _panels[i];
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// _curPanel = panel;
|
|
|
|
|
|
|
|
// _curPanel->OnShow(event);
|
|
|
|
// _vbox->Add(_curPanel);
|
|
|
|
// _curPanel->Show();
|
|
|
|
// Layout();
|
2010-05-14 15:04:01 +02:00
|
|
|
}
|
2010-06-23 19:32:42 +02:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void wxUI::OnButtonClicked(QEvent& event)
|
2010-12-20 19:28:24 +01:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// ShowPanel(_panels[event.GetId()]);
|
2010-12-20 19:28:24 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void wxUI::OnButtonChangeUser(QEvent& event)
|
2010-12-20 19:28:24 +01:00
|
|
|
{
|
|
|
|
ChangeUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::ChangeUser()
|
|
|
|
{
|
2011-09-03 10:38:36 +02:00
|
|
|
UsersDialog u(_kiss, this);
|
|
|
|
u.exec();
|
2010-12-20 19:28:24 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void wxUI::OnButtonAbout(QEvent& event)
|
2010-12-20 19:28:24 +01:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// wxMessageBox( _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé"),
|
|
|
|
// wxT("KissCount " APP_VERSION "\n\n"),
|
|
|
|
// wxOK | wxICON_INFORMATION, this );
|
2010-12-20 19:28:24 +01:00
|
|
|
}
|
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
void wxUI::OnButtonQuit(QEvent& event)
|
2010-12-20 19:28:24 +01:00
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// wxMessageDialog dialog(this, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO);
|
|
|
|
// if (dialog.ShowModal() == wxID_NO)
|
|
|
|
// {
|
|
|
|
// return;
|
|
|
|
// }
|
2010-12-20 19:28:24 +01:00
|
|
|
|
2011-08-25 17:45:41 +02:00
|
|
|
// Close(true);
|
2010-12-20 19:28:24 +01:00
|
|
|
}
|
|
|
|
|
2010-06-23 19:32:42 +02:00
|
|
|
void wxUI::GenerateMonth(int month, int year)
|
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// ((AccountPanel*)_panels[0])->GenerateMonth(month, year);
|
2010-06-23 19:32:42 +02:00
|
|
|
}
|
2010-06-27 21:39:49 +02:00
|
|
|
|
|
|
|
void wxUI::KillMe()
|
|
|
|
{
|
2011-08-25 17:45:41 +02:00
|
|
|
// std::vector<KissPanel*>::iterator it;
|
|
|
|
|
|
|
|
// if (_curPanel)
|
|
|
|
// {
|
|
|
|
// _vbox->Detach(_curPanel);
|
|
|
|
// _curPanel = 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (it=_panels.begin(); it!= _panels.end(); it++)
|
|
|
|
// {
|
|
|
|
// if (*it) delete *it;
|
|
|
|
// _buttonsBox->Remove(0);
|
|
|
|
// _buttons.erase(_buttons.begin());
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _panels.clear();
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wxUI::NeedReload()
|
|
|
|
{
|
2010-08-26 21:28:15 +02:00
|
|
|
_needReload = true;
|
2010-06-27 21:39:49 +02:00
|
|
|
}
|