Merge with dev
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2010-2011 Grégory Soutadé
|
||||
Copyright 2010-2012 Grégory Soutadé
|
||||
|
||||
This file is part of KissCount.
|
||||
|
||||
@@ -17,59 +17,70 @@
|
||||
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "wxUI.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
enum {BUTTON_CHANGE_USER_ID=-4, BUTTON_ABOUT_ID=-5, BUTTON_QUIT_ID=-6};
|
||||
#include "AccountPanel.hpp"
|
||||
#include "SearchPanel.hpp"
|
||||
#include "PreferencesPanel.hpp"
|
||||
#include "StatsPanel.hpp"
|
||||
#include "ImportPanel.hpp"
|
||||
#include "ExportPanel.hpp"
|
||||
|
||||
BEGIN_EVENT_TABLE(wxUI, wxFrame)
|
||||
EVT_BUTTON(BUTTON_CHANGE_USER_ID, wxUI::OnButtonChangeUser)
|
||||
EVT_BUTTON(BUTTON_ABOUT_ID, wxUI::OnButtonAbout)
|
||||
EVT_BUTTON(BUTTON_QUIT_ID, wxUI::OnButtonQuit)
|
||||
END_EVENT_TABLE()
|
||||
#include "wxUI.hpp"
|
||||
#include "view.hpp"
|
||||
|
||||
wxString months[12] ;
|
||||
wxColour categoryColors[MAX_CATEGORY] = {wxColour(0x00, 0x45, 0x86),
|
||||
wxColour(0xFF, 0x3E, 0x0E),
|
||||
wxColour(0xFF, 0xD3, 0x20),
|
||||
wxColour(0x58, 0x9D, 0x1B),
|
||||
wxColour(0x7E, 0x00, 0x21),
|
||||
wxColour(0x83, 0xCC, 0xFF),
|
||||
wxColour(0x31, 0x40, 0x04),
|
||||
wxColour(0xB0, 0xCF, 0x00),
|
||||
wxColour(0x4B, 0x1F, 0x6F),
|
||||
wxColour(0xFF, 0x93, 0x0E),
|
||||
wxColour(0xC5, 0x00, 0x0D),
|
||||
wxColour(0x00, 0x84, 0xD1)};
|
||||
#include "UsersDialog.hpp"
|
||||
|
||||
wxUI::wxUI(KissCount* kiss, const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
: wxFrame(NULL, -1, title, pos, size), _kiss(kiss),
|
||||
_curPanel(NULL), _locale(NULL), _needReload(false)
|
||||
QString wxUI::months[12] ;
|
||||
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), _language(SupportedLanguages::languages[SupportedLanguages::English].name),
|
||||
_kiss(kiss), _signalMapper(this), _curPanel(0), _locale(0),
|
||||
_needReload(false)
|
||||
{
|
||||
wxInitAllImageHandlers();
|
||||
QPushButton* button;
|
||||
|
||||
_vbox = new wxBoxSizer(wxVERTICAL);
|
||||
_buttonsBox = new wxBoxSizer(wxHORIZONTAL);
|
||||
// ButtonPanel* buttons = new ButtonPanel(_kiss, this);
|
||||
// wxMenu *menuFile = new wxMenu;
|
||||
SetLanguage("");
|
||||
|
||||
// menuFile->Append( ID_About, wxT("&About...") );
|
||||
// menuFile->AppendSeparator();
|
||||
// menuFile->Append( ID_Quit, wxT("E&xit") );
|
||||
setWindowTitle(title);
|
||||
|
||||
connect(&_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnButtonClicked(int)));
|
||||
|
||||
// wxMenuBar *menuBar = new wxMenuBar;
|
||||
// menuBar->Append( menuFile, wxT("&File") );
|
||||
_vbox = new QVBoxLayout;
|
||||
_buttonsBox = new QHBoxLayout;
|
||||
|
||||
// SetMenuBar( menuBar );
|
||||
button = new QPushButton(QIcon(CHANGE_USER_ICON), "", this);
|
||||
button->setFixedSize(128, 128);
|
||||
button->setIconSize(QSize(128, 128));
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(OnButtonChangeUser()));
|
||||
_buttonsBox->addWidget(button);
|
||||
|
||||
// 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)));
|
||||
button = new QPushButton(QIcon(ABOUT_ICON), "", this);
|
||||
button->setFixedSize(128, 128);
|
||||
button->setIconSize(QSize(128, 128));
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(OnButtonAbout()));
|
||||
_buttonsBox->addWidget(button);
|
||||
|
||||
SetSizer(_vbox);
|
||||
button = new QPushButton(QIcon(QUIT_ICON), "", this);
|
||||
button->setFixedSize(128, 128);
|
||||
button->setIconSize(QSize(128, 128));
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(OnButtonQuit()));
|
||||
_buttonsBox->addWidget(button);
|
||||
|
||||
_vbox->Add(_buttonsBox, 0, wxGROW);
|
||||
_vbox->addLayout(_buttonsBox);
|
||||
setLayout(_vbox);
|
||||
}
|
||||
|
||||
wxUI::~wxUI()
|
||||
@@ -77,47 +88,69 @@ wxUI::~wxUI()
|
||||
int i;
|
||||
|
||||
for (i=0; i<(int)_panels.size(); i++)
|
||||
Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
|
||||
_buttons[i]->disconnect(&_signalMapper, SLOT(map()));
|
||||
|
||||
if (_locale) delete _locale;
|
||||
}
|
||||
|
||||
bool wxUI::SetLanguage(long language)
|
||||
bool wxUI::SetLanguage(QString language)
|
||||
{
|
||||
bool res = true;
|
||||
int i;
|
||||
|
||||
if (_locale) delete _locale;
|
||||
_locale = NULL;
|
||||
|
||||
// load language if possible, fall back to english otherwise
|
||||
if(wxLocale::IsAvailable(language))
|
||||
if (_locale)
|
||||
{
|
||||
_locale = new wxLocale( language, wxLOCALE_CONV_ENCODING );
|
||||
|
||||
#ifdef __WXGTK__
|
||||
_locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
|
||||
#endif
|
||||
|
||||
_locale->AddCatalog(wxT("french"));
|
||||
_locale->AddCatalog(wxT("kisscount"));
|
||||
|
||||
_language = (wxLanguage) language;
|
||||
if (language == _language) return true;
|
||||
}
|
||||
|
||||
if (_locale == NULL || !_locale->IsOk())
|
||||
if (language == "")
|
||||
{
|
||||
if (_locale) delete _locale;
|
||||
_locale = new wxLocale();
|
||||
QLocale default_locale = QLocale::system();
|
||||
|
||||
#ifdef __WXGTK__
|
||||
_locale->AddCatalogLookupPathPrefix(wxT(LANG_ROOT));
|
||||
#endif
|
||||
|
||||
_locale->AddCatalog(wxT("kisscount"));
|
||||
|
||||
_language = wxLANGUAGE_ENGLISH;
|
||||
res = false;
|
||||
for(i=0; i<SupportedLanguages::NB_SUPPORTED_LANGUAGES; i++)
|
||||
{
|
||||
if (default_locale.language() == SupportedLanguages::languages[i].language)
|
||||
break;
|
||||
}
|
||||
if (i == SupportedLanguages::NB_SUPPORTED_LANGUAGES)
|
||||
i = SupportedLanguages::English;
|
||||
language = SupportedLanguages::languages[i].name;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i=0; i<SupportedLanguages::NB_SUPPORTED_LANGUAGES; i++)
|
||||
{
|
||||
if (language == SupportedLanguages::languages[i].name)
|
||||
break;
|
||||
}
|
||||
if (i == SupportedLanguages::NB_SUPPORTED_LANGUAGES)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_locale)
|
||||
{
|
||||
delete _locale;
|
||||
_kiss->removeTranslator(&_translator);
|
||||
}
|
||||
|
||||
if (i != SupportedLanguages::English)
|
||||
{
|
||||
if (!_translator.load(SupportedLanguages::languages[i].filename, RESSOURCES_ROOT "po"))
|
||||
{
|
||||
i = SupportedLanguages::English;
|
||||
_translator.load(SupportedLanguages::languages[i].filename, RESSOURCES_ROOT "po");
|
||||
_language = SupportedLanguages::languages[i].name;
|
||||
res = false;
|
||||
}
|
||||
|
||||
_kiss->installTranslator(&_translator);
|
||||
}
|
||||
|
||||
_language = SupportedLanguages::languages[i].language;
|
||||
_curLanguage = SupportedLanguages::languages[i];
|
||||
|
||||
_locale = new QLocale(SupportedLanguages::languages[i].language);
|
||||
QLocale::setDefault(*_locale);
|
||||
|
||||
months[0] = _("january");
|
||||
months[1] = _("february");
|
||||
@@ -135,27 +168,30 @@ bool wxUI::SetLanguage(long language)
|
||||
return res;
|
||||
}
|
||||
|
||||
#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);
|
||||
#define ADD_PANEL(panelName) \
|
||||
panel = new panelName(_kiss, this); \
|
||||
button = panel->GetButton(); \
|
||||
button->setToolTip(panel->GetToolTip()); \
|
||||
_buttonsBox->insertWidget(id, button); \
|
||||
_buttons.insert(_buttons.begin()+id, button); \
|
||||
_panels.push_back(panel); \
|
||||
_signalMapper.setMapping(button, id); \
|
||||
connect(button, SIGNAL(clicked()), &_signalMapper, SLOT(map())); \
|
||||
id++;
|
||||
|
||||
void wxUI::InitPanels()
|
||||
{
|
||||
KissPanel* panel;
|
||||
wxBitmapButton* button;
|
||||
QPushButton* button;
|
||||
_panels.clear();
|
||||
int id=0;
|
||||
|
||||
ADD_PANEL(AccountPanel, 0);
|
||||
ADD_PANEL(StatsPanel, 1);
|
||||
ADD_PANEL(SearchPanel, 2);
|
||||
ADD_PANEL(PreferencesPanel, 3);
|
||||
ADD_PANEL(ImportPanel, 4);
|
||||
ADD_PANEL(ExportPanel, 5);
|
||||
ADD_PANEL(AccountPanel);
|
||||
ADD_PANEL(StatsPanel);
|
||||
ADD_PANEL(SearchPanel);
|
||||
ADD_PANEL(PreferencesPanel);
|
||||
ADD_PANEL(ImportPanel);
|
||||
ADD_PANEL(ExportPanel);
|
||||
}
|
||||
|
||||
void wxUI::LoadPanels()
|
||||
@@ -166,31 +202,36 @@ void wxUI::LoadPanels()
|
||||
|
||||
if (_curPanel)
|
||||
{
|
||||
_vbox->Detach(_curPanel);
|
||||
_curPanel = NULL;
|
||||
_vbox->removeWidget(_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());
|
||||
}
|
||||
for (i=0; i<(int)_panels.size(); i++)
|
||||
{
|
||||
temp = _panels[i]->CreatePanel();
|
||||
_buttons[i]->disconnect(&_signalMapper, SLOT(map()));
|
||||
delete _panels[i];
|
||||
_panels[i] = temp;
|
||||
connect(_buttons[i], SIGNAL(clicked()), &_signalMapper, SLOT(map()));
|
||||
_buttons[i]->setToolTip(temp->GetToolTip());
|
||||
}
|
||||
}
|
||||
else
|
||||
InitPanels();
|
||||
InitPanels();
|
||||
}
|
||||
|
||||
void wxUI::LoadUser()
|
||||
{
|
||||
User* user = _kiss->GetUser();
|
||||
|
||||
if (user->_preferences[wxT("language")] != wxT(""))
|
||||
if (user->_preferences["language"].size())
|
||||
SetLanguage(user->GetLanguage());
|
||||
else
|
||||
SetLanguage(SupportedLanguages::languages[0].name);
|
||||
|
||||
LoadPanels();
|
||||
|
||||
LoadPanels();
|
||||
|
||||
@@ -200,7 +241,6 @@ void wxUI::LoadUser()
|
||||
|
||||
void wxUI::ShowPanel(KissPanel* panel)
|
||||
{
|
||||
wxShowEvent event;
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
|
||||
@@ -208,64 +248,71 @@ void wxUI::ShowPanel(KissPanel* panel)
|
||||
|
||||
if (_curPanel)
|
||||
{
|
||||
_vbox->Detach(_curPanel);
|
||||
_curPanel->Hide();
|
||||
_vbox->removeWidget(_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];
|
||||
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 = panel;
|
||||
|
||||
_curPanel->OnShow(event);
|
||||
_vbox->Add(_curPanel);
|
||||
_curPanel->Show();
|
||||
Layout();
|
||||
_curPanel->OnShow();
|
||||
_vbox->addWidget(_curPanel);
|
||||
_curPanel->show();
|
||||
layout();
|
||||
}
|
||||
|
||||
void wxUI::OnButtonClicked(wxCommandEvent& event)
|
||||
void wxUI::OnButtonClicked(int id)
|
||||
{
|
||||
ShowPanel(_panels[event.GetId()]);
|
||||
ShowPanel(_panels[id]);
|
||||
}
|
||||
|
||||
void wxUI::OnButtonChangeUser(wxCommandEvent& event)
|
||||
void wxUI::OnButtonChangeUser()
|
||||
{
|
||||
ChangeUser();
|
||||
}
|
||||
|
||||
void wxUI::ChangeUser()
|
||||
{
|
||||
UsersDialog u(_kiss, this);
|
||||
}
|
||||
|
||||
void wxUI::OnButtonAbout(wxCommandEvent& event)
|
||||
{
|
||||
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 );
|
||||
}
|
||||
|
||||
void wxUI::OnButtonQuit(wxCommandEvent& event)
|
||||
{
|
||||
wxMessageDialog dialog(this, _("Quit KissCount ?"), wxT("KissCount"), wxYES_NO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
try
|
||||
{
|
||||
return;
|
||||
UsersDialog u(_kiss, this);
|
||||
u.exec();
|
||||
}
|
||||
catch (UsersDialog::ExceptionNewUser e)
|
||||
{
|
||||
|
||||
Close(true);
|
||||
}
|
||||
}
|
||||
|
||||
void wxUI::OnButtonAbout()
|
||||
{
|
||||
QMessageBox::information(0, "KissCount " APP_VERSION, _("Personal accounting software") + "\n\nhttp://indefero.soutade.fr/p/kisscount/\n\n" + _("Licenced under GNU GPL v3") + "\n\nCopyright (C) 2010-2012 Grégory Soutadé");
|
||||
}
|
||||
|
||||
void wxUI::OnButtonQuit()
|
||||
{
|
||||
if (QMessageBox::question(0, "KissCount", _("Quit KissCount ?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
|
||||
close();
|
||||
}
|
||||
|
||||
void wxUI::GenerateMonth(int month, int year)
|
||||
{
|
||||
((AccountPanel*)_panels[0])->GenerateMonth(month, year);
|
||||
(dynamic_cast<AccountPanel*>(_panels[0]))->GenerateMonth(month, year);
|
||||
}
|
||||
|
||||
void wxUI::UpdateStats()
|
||||
{
|
||||
if (_curPanel == _panels[0])
|
||||
(dynamic_cast<AccountPanel*>(_panels[0]))->UpdateStats();
|
||||
}
|
||||
|
||||
void wxUI::KillMe()
|
||||
@@ -274,15 +321,19 @@ void wxUI::KillMe()
|
||||
|
||||
if (_curPanel)
|
||||
{
|
||||
_vbox->Detach(_curPanel);
|
||||
_curPanel = NULL;
|
||||
_vbox->removeWidget(_curPanel);
|
||||
_curPanel = 0;
|
||||
}
|
||||
|
||||
for (it=_panels.begin(); it!= _panels.end(); it++)
|
||||
{
|
||||
if (*it) delete *it;
|
||||
_buttonsBox->Remove(0);
|
||||
_buttons.erase(_buttons.begin());
|
||||
if (*it)
|
||||
{
|
||||
_buttonsBox->removeWidget(*_buttons.begin());
|
||||
delete *it;
|
||||
delete *_buttons.begin();
|
||||
}
|
||||
_buttons.erase(_buttons.begin());
|
||||
}
|
||||
|
||||
_panels.clear();
|
||||
@@ -292,3 +343,8 @@ void wxUI::NeedReload()
|
||||
{
|
||||
_needReload = true;
|
||||
}
|
||||
|
||||
QString wxUI::GetDateFormat()
|
||||
{
|
||||
return _curLanguage.dateFormat;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user