Add account limit color & value to PreferencesPanel

This commit is contained in:
Grégory Soutadé 2017-10-29 18:21:53 +01:00 committed by Grégory Soutadé
parent fe302d2ef5
commit 47fffc71b1
8 changed files with 147 additions and 25 deletions

View File

@ -417,7 +417,31 @@ void KissCount::KillMe()
void KissCount::SetLanguage(QString language) void KissCount::SetLanguage(QString language)
{ {
_user->SetLanguage(language); _user->SetLanguage(language);
_db->UpdatePreference(_user, "language"); }
QString KissCount::GetLanguage(void)
{
return _user->GetLanguage();
}
void KissCount::SetAccountLimitValue(int limit)
{
_user->SetAccountLimitValue(limit);
}
void KissCount::SetAccountLimitColor(QColor& color)
{
_user->SetAccountLimitColor(color);
}
int KissCount::GetAccountLimitValue(void)
{
return _user->GetAccountLimitValue();
}
QColor KissCount::GetAccountLimitColor(void)
{
return _user->GetAccountLimitColor();
} }
/* /*

View File

@ -103,6 +103,11 @@ public:
void KillMe(); void KillMe();
void SetLanguage(QString language); void SetLanguage(QString language);
QString GetLanguage(void);
void SetAccountLimitValue(int limit);
void SetAccountLimitColor(QColor& color);
int GetAccountLimitValue(void);
QColor GetAccountLimitColor(void);
void SetOperationOrder(const QString& order); void SetOperationOrder(const QString& order);
const QString& GetOperationOrder(); const QString& GetOperationOrder();

View File

@ -259,8 +259,6 @@ User* Database::LoadUser(const QString& name)
user->_name = set.value("name").toString(); user->_name = set.value("name").toString();
user->_password = "" ; // Security reasons set.value("password").toString(); user->_password = "" ; // Security reasons set.value("password").toString();
user->_preferences["operation_order"] = "ASC" ;
query.clear(); query.clear();
req = QString("SELECT * FROM account WHERE user='%1' ORDER BY default_account DESC, hidden, blocked, virtual, name ASC").arg(user->_id); req = QString("SELECT * FROM account WHERE user='%1' ORDER BY default_account DESC, hidden, blocked, virtual, name ASC").arg(user->_id);

View File

@ -20,12 +20,19 @@
#include <algorithm> #include <algorithm>
#include <QString> #include <QString>
#include <QColor>
#include <view/view.hpp> #include <view/view.hpp>
#include "User.hpp" #include "User.hpp"
User::User(Database* db) : _db(db) User::User(Database* db) : _db(db)
{} {
_preferences["operation_order"] = "ASC" ;
_preferences["account_limit_value"] = "200";
_preferences["account_limit_color_r"] = "240";
_preferences["account_limit_color_g"] = "195";
_preferences["account_limit_color_b"] = "0";
}
User::~User() User::~User()
{ {
@ -315,16 +322,38 @@ QString User::GetLanguage()
void User::SetLanguage(QString language) void User::SetLanguage(QString language)
{ {
_preferences["language"] = language; _preferences["language"] = language;
_db->UpdatePreference(this, "language");
} }
int User::GetDefaultCurrency() void User::SetAccountLimitValue(int limit)
{ {
return _preferences["defaultCurrency"].toInt(); _preferences["account_limit_value"] = QString::number(limit);
_db->UpdatePreference(this, "account_limit_value");
} }
void User::SetDefaultCurrency(int currency) void User::SetAccountLimitColor(QColor& color)
{ {
_preferences["defaultCurrency"] = QString(currency); _preferences["account_limit_color_r"] = QString::number(color.red());
_preferences["account_limit_color_g"] = QString::number(color.green());
_preferences["account_limit_color_b"] = QString::number(color.blue());
_db->UpdatePreference(this, "account_limit_color_r");
_db->UpdatePreference(this, "account_limit_color_g");
_db->UpdatePreference(this, "account_limit_color_b");
}
int User::GetAccountLimitValue(void)
{
return _preferences["account_limit_value"].toInt();
}
QColor User::GetAccountLimitColor(void)
{
int r = _preferences["account_limit_color_r"].toInt();
int g = _preferences["account_limit_color_g"].toInt();
int b = _preferences["account_limit_color_b"].toInt();
return QColor(r,g,b);
} }
void User::LinkOrUnlinkOperation(Operation& op) void User::LinkOrUnlinkOperation(Operation& op)

View File

@ -89,9 +89,10 @@ public:
QString GetLanguage(); QString GetLanguage();
void SetLanguage(QString language); void SetLanguage(QString language);
int GetDefaultCurrency(); void SetAccountLimitValue(int limit);
void SetDefaultCurrency(int currency); void SetAccountLimitColor(QColor& color);
int GetAccountLimitValue(void);
QColor GetAccountLimitColor(void);
void LinkOrUnlinkOperation(Operation& op); void LinkOrUnlinkOperation(Operation& op);

View File

@ -691,9 +691,9 @@ void AccountPanel::UpdateStats()
textFormat.setForeground(brush); textFormat.setForeground(brush);
} }
} }
else if (minimalValue <= 200*100) else if (minimalValue <= user->GetAccountLimitValue()*100)
{ {
brush.setColor(QColor(240,195,0)); brush.setColor(user->GetAccountLimitColor());
textFormat.setBackground(brush); textFormat.setBackground(brush);
} }
else else

View File

@ -43,11 +43,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
QHBoxLayout *hbox2 = new QHBoxLayout; QHBoxLayout *hbox2 = new QHBoxLayout;
QHBoxLayout *hbox3 = new QHBoxLayout; QHBoxLayout *hbox3 = new QHBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout; QHBoxLayout *hbox = new QHBoxLayout;
QGroupBox* staticUser, *staticAccount, *staticCategories, *staticTags, *staticLanguage, *staticOperationOrder, *staticSharedWith; QGroupBox* staticUser, *staticAccount, *staticCategories, *staticTags, *staticLanguage, *staticOperationOrder, *staticAccountLimit, *staticSharedWith;
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
QGridLayout *gridBagSizer; QGridLayout *gridBagSizer;
QLabel* label; QLabel* label;
QPushButton* buttonChangeName, *buttonChangePassword, *killMe; QPushButton* buttonChangeName, *buttonChangePassword, *killMe, *buttonAccountLimitColor;
QVBoxLayout * staticBoxSizer; QVBoxLayout * staticBoxSizer;
std::list<QString> users; std::list<QString> users;
std::list<QString>::iterator it; std::list<QString>::iterator it;
@ -63,6 +63,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
staticTags = new QGroupBox(_("Tags")); staticTags = new QGroupBox(_("Tags"));
staticLanguage = new QGroupBox(_("Language")); staticLanguage = new QGroupBox(_("Language"));
staticOperationOrder = new QGroupBox(_("Operation order")); staticOperationOrder = new QGroupBox(_("Operation order"));
staticAccountLimit = new QGroupBox(_("Account limit"));
staticSharedWith = new QGroupBox(_("Shared with")); staticSharedWith = new QGroupBox(_("Shared with"));
// User // User
@ -139,7 +140,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
_sharedWith->setEnabled(false); _sharedWith->setEnabled(false);
connect(_sharedWith, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(OnSharedChange(QListWidgetItem *))); connect(_sharedWith, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(OnSharedChanged(QListWidgetItem *)));
staticBoxSizer->addWidget(_sharedWith); staticBoxSizer->addWidget(_sharedWith);
@ -187,7 +188,37 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
hbox3->addWidget(staticOperationOrder); hbox3->addWidget(staticOperationOrder);
connect(_operationOrder, SIGNAL(currentIndexChanged(int)), this, SLOT(OnOperationOrderChange(int))); connect(_operationOrder, SIGNAL(currentIndexChanged(int)), this, SLOT(OnOperationOrderChanged(int)));
// Account Limit
{
QHBoxLayout *hbox = new QHBoxLayout;
QPalette palette;
staticBoxSizer = new QVBoxLayout ();
staticAccountLimit->setLayout(staticBoxSizer);
_accountLimit = new QSpinBox();
_accountLimit->setMinimum(1);
_accountLimit->setMaximum(10000);
_accountLimit->setValue(user->GetAccountLimitValue());
palette = _accountLimit->palette();
palette.setColor(QPalette::Base, user->GetAccountLimitColor());
_accountLimit->setPalette(palette);
hbox->addWidget(_accountLimit);
buttonAccountLimitColor = new QPushButton("...");
hbox->addWidget(buttonAccountLimitColor);
staticBoxSizer->addLayout(hbox);
hbox3->addWidget(staticAccountLimit);
connect(_accountLimit, SIGNAL(valueChanged(int)), this, SLOT(OnAccountLimitChanged(int)));
connect(buttonAccountLimitColor, SIGNAL(clicked(void)), this, SLOT(OnAccountLimitColorClicked(void)));
}
// Language // Language
staticBoxSizer = new QVBoxLayout (); staticBoxSizer = new QVBoxLayout ();
@ -196,7 +227,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu
_language = new QListWidget(); _language = new QListWidget();
//_language->SetWindowStyle(wxCB_READONLY); //_language->SetWindowStyle(wxCB_READONLY);
connect(_language, SIGNAL(currentRowChanged(int)), this, SLOT(OnLanguageChange(int))); connect(_language, SIGNAL(currentRowChanged(int)), this, SLOT(OnLanguageChanged(int)));
staticBoxSizer->addWidget(_language); staticBoxSizer->addWidget(_language);
@ -1138,7 +1169,7 @@ void PreferencesPanel::OnAccountCellChanged(int row, int col, int previousRow, i
_sharedWith->setEnabled(own); _sharedWith->setEnabled(own);
} }
void PreferencesPanel::OnSharedChange(QListWidgetItem *item) void PreferencesPanel::OnSharedChanged(QListWidgetItem *item)
{ {
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
@ -1380,7 +1411,7 @@ void PreferencesPanel::OnChangePassword()
g.exec(); g.exec();
} }
void PreferencesPanel::OnOperationOrderChange(int index) void PreferencesPanel::OnOperationOrderChanged(int index)
{ {
if (index == 0) if (index == 0)
_kiss->SetOperationOrder("ASC"); _kiss->SetOperationOrder("ASC");
@ -1390,7 +1421,7 @@ void PreferencesPanel::OnOperationOrderChange(int index)
_wxUI->NeedReload(); _wxUI->NeedReload();
} }
void PreferencesPanel::OnLanguageChange(int index) void PreferencesPanel::OnLanguageChanged(int index)
{ {
if (_inModification) return; if (_inModification) return;
@ -1415,7 +1446,7 @@ void PreferencesPanel::OnShow()
} }
void PreferencesPanel::OnKillMe() void PreferencesPanel::OnKillMe()
{ {
User* user = _kiss->GetUser(); User* user = _kiss->GetUser();
if (QMessageBox::question(0, "KissCount", _("Are you sure want to delete profil of ")+user->_name+_(" ?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::No) if (QMessageBox::question(0, "KissCount", _("Are you sure want to delete profil of ")+user->_name+_(" ?"), QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
@ -1425,3 +1456,33 @@ void PreferencesPanel::OnKillMe()
_kiss->KillMe(); _kiss->KillMe();
} }
void PreferencesPanel::OnAccountLimitChanged(int val)
{
_kiss->SetAccountLimitValue(val);
_wxUI->NeedReload();
}
void PreferencesPanel::OnAccountLimitColorClicked(void)
{
QColor color;
User* user = _kiss->GetUser();
QPalette palette;
_inModification = true ;
color = QColorDialog::getColor(user->GetAccountLimitColor());
if (color.isValid())
{
_kiss->SetAccountLimitColor(color);
QPalette palette = _accountLimit->palette();
palette.setColor(QPalette::Base, user->GetAccountLimitColor());
_accountLimit->setPalette(palette);
_wxUI->NeedReload();
}
_inModification = false ;
}

View File

@ -24,6 +24,7 @@
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QTableWidget> #include <QTableWidget>
#include <QComboBox> #include <QComboBox>
#include <QSpinBox>
#include "SupportedLanguages.hpp" #include "SupportedLanguages.hpp"
#include "view.hpp" #include "view.hpp"
#include <model/model.hpp> #include <model/model.hpp>
@ -54,14 +55,16 @@ private slots:
void OnFontClicked(int id); void OnFontClicked(int id);
void OnAccountModified(int row, int col); void OnAccountModified(int row, int col);
void OnAccountCellChanged(int row, int col, int, int); void OnAccountCellChanged(int row, int col, int, int);
void OnSharedChange(QListWidgetItem *item); void OnSharedChanged(QListWidgetItem *item);
void OnCategoryModified(int row, int col); void OnCategoryModified(int row, int col);
void OnTagModified(int row, int col); void OnTagModified(int row, int col);
void OnChangeName(); void OnChangeName();
void OnChangePassword(); void OnChangePassword();
void OnOperationOrderChange(int index); void OnOperationOrderChanged(int index);
void OnLanguageChange(int); void OnLanguageChanged(int);
void OnKillMe(); void OnKillMe();
void OnAccountLimitChanged(int val);
void OnAccountLimitColorClicked(void);
private: private:
QTableWidget* _accountsGrid; QTableWidget* _accountsGrid;
@ -70,6 +73,7 @@ private:
QLineEdit* _name; QLineEdit* _name;
QListWidget* _language; QListWidget* _language;
QComboBox* _operationOrder; QComboBox* _operationOrder;
QSpinBox* _accountLimit;
QListWidget* _sharedWith; QListWidget* _sharedWith;
int _curAccountRow; int _curAccountRow;
std::map<QString, QString> _sharedOwners; std::map<QString, QString> _sharedOwners;