Enable panels mechanism
This commit is contained in:
@@ -19,8 +19,8 @@
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
/*#include "AccountPanel.hpp"
|
||||
#include "PreferencesPanel.hpp"
|
||||
#include "AccountPanel.hpp"
|
||||
/*#include "PreferencesPanel.hpp"
|
||||
#include "UsersDialog.hpp"
|
||||
#include "GenerateDialog.hpp"
|
||||
#include "SearchPanel.hpp"
|
||||
@@ -53,12 +53,14 @@ QColor wxUI::categoryColors[MAX_CATEGORY] = {QColor(0x00, 0x45, 0x86),
|
||||
QColor(0x00, 0x84, 0xD1)};
|
||||
|
||||
wxUI::wxUI(KissCount* kiss, const QString& title)
|
||||
: QFrame(0), _kiss(kiss),
|
||||
: QFrame(0), _kiss(kiss), _signalMapper(this),
|
||||
_curPanel(0), _locale(0), _needReload(false)
|
||||
{
|
||||
QPushButton* button;
|
||||
|
||||
setWindowTitle(title);
|
||||
|
||||
connect(&_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnButtonClicked(int)));
|
||||
|
||||
_vbox = new QVBoxLayout;
|
||||
_buttonsBox = new QHBoxLayout;
|
||||
@@ -87,10 +89,10 @@ wxUI::wxUI(KissCount* kiss, const QString& title)
|
||||
|
||||
wxUI::~wxUI()
|
||||
{
|
||||
//int i;
|
||||
int i;
|
||||
|
||||
// for (i=0; i<(int)_panels.size(); i++)
|
||||
// Disconnect(i, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxUI::OnButtonClicked), _panels[i], this);
|
||||
for (i=0; i<(int)_panels.size(); i++)
|
||||
_buttons[i]->disconnect(&_signalMapper, SLOT(map()));
|
||||
|
||||
if (_locale) delete _locale;
|
||||
}
|
||||
@@ -148,22 +150,25 @@ bool wxUI::SetLanguage(QString 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;
|
||||
// _panels.clear();
|
||||
KissPanel* panel;
|
||||
QPushButton* button;
|
||||
_panels.clear();
|
||||
int id=0;
|
||||
|
||||
// ADD_PANEL(AccountPanel, 0);
|
||||
ADD_PANEL(AccountPanel);
|
||||
// ADD_PANEL(StatsPanel, 1);
|
||||
// ADD_PANEL(SearchPanel, 2);
|
||||
// ADD_PANEL(PreferencesPanel, 3);
|
||||
@@ -173,29 +178,29 @@ void wxUI::InitPanels()
|
||||
|
||||
void wxUI::LoadPanels()
|
||||
{
|
||||
// std::vector<KissPanel*>::iterator it;
|
||||
// KissPanel* temp;
|
||||
// int i;
|
||||
std::vector<KissPanel*>::iterator it;
|
||||
KissPanel* temp;
|
||||
int i;
|
||||
|
||||
// if (_curPanel)
|
||||
// {
|
||||
// _vbox->Detach(_curPanel);
|
||||
// _curPanel = 0;
|
||||
// }
|
||||
if (_curPanel)
|
||||
{
|
||||
_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());
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// InitPanels();
|
||||
if (_panels.size())
|
||||
{
|
||||
for (i=0; i<(int)_panels.size(); i++)
|
||||
{
|
||||
temp = _panels[i]->CreatePanel();
|
||||
_buttons[i]->disconnect(&_signalMapper, SLOT(map()));
|
||||
_panels[i] = temp;
|
||||
connect(_buttons[i], SIGNAL(clicked()), &_signalMapper, SLOT(map()));
|
||||
_buttons[i]->setToolTip(temp->GetToolTip());
|
||||
}
|
||||
}
|
||||
else
|
||||
InitPanels();
|
||||
}
|
||||
|
||||
void wxUI::LoadUser()
|
||||
@@ -213,39 +218,38 @@ void wxUI::LoadUser()
|
||||
|
||||
void wxUI::ShowPanel(KissPanel* panel)
|
||||
{
|
||||
// wxShowEvent event;
|
||||
// int i;
|
||||
// User* user = _kiss->GetUser();
|
||||
int i;
|
||||
User* user = _kiss->GetUser();
|
||||
|
||||
// if (!panel) return;
|
||||
if (!panel) return;
|
||||
|
||||
// if (_curPanel)
|
||||
// {
|
||||
// _vbox->Detach(_curPanel);
|
||||
// _curPanel->Hide();
|
||||
// }
|
||||
if (_curPanel)
|
||||
{
|
||||
_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];
|
||||
// }
|
||||
// else
|
||||
// _curPanel = panel;
|
||||
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();
|
||||
_curPanel->OnShow();
|
||||
_vbox->addWidget(_curPanel);
|
||||
_curPanel->show();
|
||||
layout();
|
||||
}
|
||||
|
||||
void wxUI::OnButtonClicked()
|
||||
void wxUI::OnButtonClicked(int id)
|
||||
{
|
||||
// ShowPanel(_panels[event.GetId()]);
|
||||
ShowPanel(_panels[id]);
|
||||
}
|
||||
|
||||
void wxUI::OnButtonChangeUser()
|
||||
@@ -272,27 +276,30 @@ void wxUI::OnButtonQuit()
|
||||
|
||||
void wxUI::GenerateMonth(int month, int year)
|
||||
{
|
||||
// ((AccountPanel*)_panels[0])->GenerateMonth(month, year);
|
||||
(dynamic_cast<AccountPanel*>(_panels[0]))->GenerateMonth(month, year);
|
||||
}
|
||||
|
||||
void wxUI::KillMe()
|
||||
{
|
||||
// std::vector<KissPanel*>::iterator it;
|
||||
std::vector<KissPanel*>::iterator it;
|
||||
|
||||
// if (_curPanel)
|
||||
// {
|
||||
// _vbox->Detach(_curPanel);
|
||||
// _curPanel = 0;
|
||||
// }
|
||||
if (_curPanel)
|
||||
{
|
||||
_vbox->removeWidget(_curPanel);
|
||||
_curPanel = 0;
|
||||
}
|
||||
|
||||
// for (it=_panels.begin(); it!= _panels.end(); it++)
|
||||
// {
|
||||
// if (*it) delete *it;
|
||||
// _buttonsBox->Remove(0);
|
||||
// _buttons.erase(_buttons.begin());
|
||||
// }
|
||||
for (it=_panels.begin(); it!= _panels.end(); it++)
|
||||
{
|
||||
if (*it)
|
||||
{
|
||||
_buttonsBox->removeWidget(*it);
|
||||
delete *it;
|
||||
}
|
||||
_buttons.erase(_buttons.begin());
|
||||
}
|
||||
|
||||
// _panels.clear();
|
||||
_panels.clear();
|
||||
}
|
||||
|
||||
void wxUI::NeedReload()
|
||||
|
||||
Reference in New Issue
Block a user