Work on wxUI and UsersDialog

This commit is contained in:
Grégory Soutadé 2011-09-04 11:21:30 +02:00
parent e6ff989bfa
commit f6e0f92ad7
7 changed files with 224 additions and 49 deletions

View File

@ -28,21 +28,18 @@
std::vector<ImportEngine*> * KissCount::_importEngines;
std::vector<ExportEngine*> * KissCount::_exportEngines;
KissCount::KissCount(const char* bdd_filename) : QApplication(0, 0), _user(0)
KissCount::KissCount(int argc, char** argv) : QApplication(argc, argv), _user(0)
{
//wxRect rect = wxDisplay().GetGeometry();
_wxUI = new wxUI(this, "KissCount");
//_wxUI->SetLanguage(wxLocale::GetSystemLanguage());
_wxUI->show();
// _wxUI->Centre();
// _wxUI->Disable();
_wxUI->showMaximized();
_wxUI->setDisabled(true);
try
{
_db = new Database(bdd_filename, this);
_db = new Database((argc == 2) ? argv[1] : 0, this);
}
catch (std::string s)
{
@ -51,7 +48,7 @@ KissCount::KissCount(const char* bdd_filename) : QApplication(0, 0), _user(0)
}
_wxUI->ChangeUser();
//_wxUI->enable();
_wxUI->setDisabled(false);
}
KissCount::~KissCount()

View File

@ -54,7 +54,7 @@ class ExportEngine;
class KissCount : public QApplication
{
public:
KissCount(const char* bdd_filename);
KissCount(int argc, char** argv);
~KissCount();
std::list<QString> GetUsers();

View File

@ -21,14 +21,11 @@
#include <controller/KissCount.hpp>
int main(int argc, const char *argv[])
int main(int argc, char *argv[])
{
try
{
if (argc == 2)
return KissCount(argv[1]).exec();
else
return KissCount(0).exec();
return KissCount(argc, argv).exec();
}
catch (std::string s)
{

128
src/view/UsersDialog.cpp Normal file
View File

@ -0,0 +1,128 @@
/*
Copyright 2010-2011 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 <list>
#include <algorithm>
#include <functional>
#include <QLabel>
#include <QGridLayout>
#include <QPushButton>
#include <QInputDialog>
#include <QMessageBox>
#include "UsersDialog.hpp"
UsersDialog::UsersDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog), _kiss(kiss), _wxUI(parent)
{
QGridLayout* gridLayout;
setWindowTitle(_("Users"));
setModal(true);
gridLayout = new QGridLayout(this);
gridLayout->addWidget(new QLabel(_("User "), this), 0, 0);
_users = new QComboBox(this);
gridLayout->addWidget(_users, 0, 1);
gridLayout->addWidget(new QLabel(_("Password "), this), 1, 0);
_password = new QLineEdit(this);
_password->setEchoMode(QLineEdit::Password);
gridLayout->addWidget(_password, 1, 1);
QPushButton* ok = new QPushButton(_("OK"), this);
QPushButton* cancel = new QPushButton(_("Cancel"), this);
QPushButton* newUser = new QPushButton(_("New User"), this);
gridLayout->addWidget(ok, 3, 1);
gridLayout->addWidget(cancel, 3, 2);
gridLayout->addWidget(newUser, 3, 3);
connect(ok, SIGNAL(clicked()), this, SLOT(OnOK()));
connect(cancel, SIGNAL(clicked()), this, SLOT(OnCancel()));
connect(newUser, SIGNAL(clicked()), this, SLOT(OnNewUser()));
std::list<QString> users_list = _kiss->GetUsers();
for(std::list<QString>::iterator i = users_list.begin(); i != users_list.end(); i++)
{
_users->addItem(*i);
}
_users->setFocus();
if (users_list.size() == 0)
OnNewUser();
else
show();
}
void UsersDialog::OnEnter()
{
OnOK();
}
void UsersDialog::OnOK()
{
QString curUser = _users->currentText();
// No users in database
if (!curUser.size())
return;
if (!_kiss->IsValidUser(curUser, _password->text()))
{
QMessageBox::critical(0, _("Error"), _("Invalid password"));
_password->clear();
_password->setFocus();
}
else
{
_kiss->LoadUser(curUser);
close();
}
}
void UsersDialog::OnCancel()
{
close();
}
void UsersDialog::OnNewUser()
{
QString name;
bool ok;
name = QInputDialog::getText (0, _("New User"), "", QLineEdit::Normal, "", &ok);
if (!ok)
return;
if (!name.size()) return;
if (_kiss->UserExists(name))
{
QMessageBox::critical(0, _("Error"), _("User ") + name + _(" already exists"));
return;
}
_kiss->NewUser(name);
_kiss->LoadUser(name);
close();
}

48
src/view/UsersDialog.hpp Normal file
View File

@ -0,0 +1,48 @@
/*
Copyright 2010-2011 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/>.
*/
#ifndef USERSDIALOG_H
#define USERSDIALOG_H
#include <QDialog>
#include <QComboBox>
#include <QLineEdit>
#include "wxUI.hpp"
class UsersDialog : public QDialog
{
Q_OBJECT;
public:
UsersDialog(KissCount* kiss, wxUI *parent);
private slots:
void OnEnter();
void OnOK();
void OnCancel();
void OnNewUser();
private:
KissCount* _kiss;
wxUI* _wxUI;
QComboBox* _users;
QLineEdit* _password;
};
#endif

View File

@ -34,6 +34,7 @@
#include "grid/wxGridCellButtonEditor.hpp"
*/
#include "wxUI.hpp"
#include "view.hpp"
#include "UsersDialog.hpp"
@ -55,31 +56,33 @@ wxUI::wxUI(KissCount* kiss, const QString& title)
: QFrame(0), _kiss(kiss),
_curPanel(0), _locale(0), _needReload(false)
{
QPushButton* button;
setWindowTitle(title);
// _vbox = new wxBoxSizer(wxVERTICAL);
// _buttonsBox = new wxBoxSizer(wxHORIZONTAL);
// // ButtonPanel* buttons = new ButtonPanel(_kiss, this);
// // wxMenu *menuFile = new wxMenu;
_vbox = new QVBoxLayout;
_buttonsBox = new QHBoxLayout;
// // menuFile->Append( ID_About, wxT("&About...") );
// // menuFile->AppendSeparator();
// // menuFile->Append( ID_Quit, wxT("E&xit") );
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);
// // wxMenuBar *menuBar = new wxMenuBar;
// // menuBar->Append( menuFile, wxT("&File") );
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);
// // SetMenuBar( menuBar );
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);
// // 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)));
// SetSizer(_vbox);
// _vbox->Add(_buttonsBox, 0, wxGROW);
_vbox->addLayout(_buttonsBox);
setLayout(_vbox);
}
wxUI::~wxUI()
@ -129,18 +132,18 @@ bool wxUI::SetLanguage(QString language)
// 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") ;
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") ;
return res;
}
@ -258,12 +261,12 @@ void wxUI::ChangeUser()
void wxUI::OnButtonAbout()
{
QMessageBox::information(this, "KissCount " APP_VERSION, _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé"));
QMessageBox::information(0, "KissCount " APP_VERSION, _("Personal accounting software\n\nhttp://indefero.soutade.fr/p/kisscount/\n\nLicenced under GNU GPL v3\n\nCopyright (C) 2010-2011 Grégory Soutadé"));
}
void wxUI::OnButtonQuit()
{
if (QMessageBox::question(this, "KissCount", _("Quit KissCount ?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
if (QMessageBox::question(0, "KissCount", _("Quit KissCount ?"), QMessageBox::Yes|QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
close();
}

View File

@ -24,6 +24,7 @@ class ImportEngine;
#include <QFrame>
#include <QLocale>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QScrollArea>
#include <QPushButton>
@ -33,7 +34,7 @@ class ImportEngine;
#include <qtranslator.h>
#include <qtextcodec.h>
#define _(s) QObject::tr(s)
#define _(s) QObject::trUtf8(s)
class KissCount;
class KissPanel;
@ -77,7 +78,8 @@ private slots:
private:
KissCount *_kiss;
QVBoxLayout *_vbox, *_buttonsBox;
QVBoxLayout *_vbox;
QHBoxLayout *_buttonsBox;
KissPanel *_curPanel;
std::vector<KissPanel*> _panels;
std::vector<QPushButton*> _buttons;