diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index 4e122da..dab6117 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -417,7 +417,31 @@ void KissCount::KillMe() void KissCount::SetLanguage(QString 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(); } /* diff --git a/src/controller/KissCount.hpp b/src/controller/KissCount.hpp index 24a9c3c..d30f92a 100644 --- a/src/controller/KissCount.hpp +++ b/src/controller/KissCount.hpp @@ -103,6 +103,11 @@ public: void KillMe(); 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); const QString& GetOperationOrder(); diff --git a/src/model/Database.cpp b/src/model/Database.cpp index c1feba4..fa86f6a 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -259,8 +259,6 @@ User* Database::LoadUser(const QString& name) user->_name = set.value("name").toString(); user->_password = "" ; // Security reasons set.value("password").toString(); - user->_preferences["operation_order"] = "ASC" ; - query.clear(); req = QString("SELECT * FROM account WHERE user='%1' ORDER BY default_account DESC, hidden, blocked, virtual, name ASC").arg(user->_id); diff --git a/src/model/User.cpp b/src/model/User.cpp index f1a7982..8f896ef 100644 --- a/src/model/User.cpp +++ b/src/model/User.cpp @@ -20,12 +20,19 @@ #include #include +#include #include #include "User.hpp" 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() { @@ -315,16 +322,38 @@ QString User::GetLanguage() void User::SetLanguage(QString 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) diff --git a/src/model/User.hpp b/src/model/User.hpp index d6abf3d..5b995b2 100644 --- a/src/model/User.hpp +++ b/src/model/User.hpp @@ -89,9 +89,10 @@ public: QString GetLanguage(); void SetLanguage(QString language); - int GetDefaultCurrency(); - void SetDefaultCurrency(int currency); - + void SetAccountLimitValue(int limit); + void SetAccountLimitColor(QColor& color); + int GetAccountLimitValue(void); + QColor GetAccountLimitColor(void); void LinkOrUnlinkOperation(Operation& op); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index f277264..f6f82b0 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -691,9 +691,9 @@ void AccountPanel::UpdateStats() 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); } else diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index 9a2353f..552e0f7 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -43,11 +43,11 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu QHBoxLayout *hbox2 = new QHBoxLayout; QHBoxLayout *hbox3 = 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(); QGridLayout *gridBagSizer; QLabel* label; - QPushButton* buttonChangeName, *buttonChangePassword, *killMe; + QPushButton* buttonChangeName, *buttonChangePassword, *killMe, *buttonAccountLimitColor; QVBoxLayout * staticBoxSizer; std::list users; std::list::iterator it; @@ -63,6 +63,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu staticTags = new QGroupBox(_("Tags")); staticLanguage = new QGroupBox(_("Language")); staticOperationOrder = new QGroupBox(_("Operation order")); + staticAccountLimit = new QGroupBox(_("Account limit")); staticSharedWith = new QGroupBox(_("Shared with")); // User @@ -139,7 +140,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu _sharedWith->setEnabled(false); - connect(_sharedWith, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(OnSharedChange(QListWidgetItem *))); + connect(_sharedWith, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(OnSharedChanged(QListWidgetItem *))); staticBoxSizer->addWidget(_sharedWith); @@ -187,7 +188,37 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu 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 staticBoxSizer = new QVBoxLayout (); @@ -196,7 +227,7 @@ PreferencesPanel::PreferencesPanel(KissCount* kiss, wxUI *parent, bool lowResolu _language = new QListWidget(); //_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); @@ -1138,7 +1169,7 @@ void PreferencesPanel::OnAccountCellChanged(int row, int col, int previousRow, i _sharedWith->setEnabled(own); } -void PreferencesPanel::OnSharedChange(QListWidgetItem *item) +void PreferencesPanel::OnSharedChanged(QListWidgetItem *item) { User* user = _kiss->GetUser(); @@ -1380,7 +1411,7 @@ void PreferencesPanel::OnChangePassword() g.exec(); } -void PreferencesPanel::OnOperationOrderChange(int index) +void PreferencesPanel::OnOperationOrderChanged(int index) { if (index == 0) _kiss->SetOperationOrder("ASC"); @@ -1390,7 +1421,7 @@ void PreferencesPanel::OnOperationOrderChange(int index) _wxUI->NeedReload(); } -void PreferencesPanel::OnLanguageChange(int index) +void PreferencesPanel::OnLanguageChanged(int index) { if (_inModification) return; @@ -1415,7 +1446,7 @@ void PreferencesPanel::OnShow() } void PreferencesPanel::OnKillMe() -{ +{ 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) @@ -1425,3 +1456,33 @@ void PreferencesPanel::OnKillMe() _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 ; +} diff --git a/src/view/PreferencesPanel.hpp b/src/view/PreferencesPanel.hpp index 6d138d6..09cda4c 100644 --- a/src/view/PreferencesPanel.hpp +++ b/src/view/PreferencesPanel.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "SupportedLanguages.hpp" #include "view.hpp" #include @@ -54,14 +55,16 @@ private slots: void OnFontClicked(int id); void OnAccountModified(int row, int col); void OnAccountCellChanged(int row, int col, int, int); - void OnSharedChange(QListWidgetItem *item); + void OnSharedChanged(QListWidgetItem *item); void OnCategoryModified(int row, int col); void OnTagModified(int row, int col); void OnChangeName(); void OnChangePassword(); - void OnOperationOrderChange(int index); - void OnLanguageChange(int); + void OnOperationOrderChanged(int index); + void OnLanguageChanged(int); void OnKillMe(); + void OnAccountLimitChanged(int val); + void OnAccountLimitColorClicked(void); private: QTableWidget* _accountsGrid; @@ -70,6 +73,7 @@ private: QLineEdit* _name; QListWidget* _language; QComboBox* _operationOrder; + QSpinBox* _accountLimit; QListWidget* _sharedWith; int _curAccountRow; std::map _sharedOwners;