Set checkboxes centered in PreferencesPanel
This commit is contained in:
parent
47fffc71b1
commit
2e70586e97
|
@ -298,6 +298,34 @@ void PreferencesPanel::InitAccounts(User* user)
|
|||
AddAccount(curLine, account);
|
||||
}
|
||||
|
||||
void PreferencesPanel::InsertCenteredWidget(QTableWidget* table, int line, int column,
|
||||
QWidget* widget, int margins)
|
||||
{
|
||||
QVBoxLayout* layout = new QVBoxLayout;
|
||||
layout->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
layout->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
layout->setContentsMargins(margins, margins, margins, margins);
|
||||
layout->addWidget(widget);
|
||||
|
||||
QWidget* fakeWidget = new QWidget;
|
||||
fakeWidget->setLayout(layout);
|
||||
table->setCellWidget(line, column, fakeWidget);
|
||||
}
|
||||
|
||||
QWidget* PreferencesPanel::GetCenteredWidget(QTableWidget* table, int line, int column)
|
||||
{
|
||||
QWidget* fakeWidget= table->cellWidget(line, column);
|
||||
|
||||
if (!fakeWidget) return 0;
|
||||
|
||||
QLayout* layout = fakeWidget->layout();
|
||||
QLayoutItem* layoutItem = layout->itemAt(0);
|
||||
|
||||
if (!layoutItem) return 0;
|
||||
|
||||
return layoutItem->widget();
|
||||
}
|
||||
|
||||
#define SET_READ_ONLY(row, line) _accountsGrid->item(row, line)->setFlags(_accountsGrid->item(row, line)->flags() & ~Qt::ItemIsEditable);
|
||||
|
||||
void PreferencesPanel::AddAccount(int line, Account ac)
|
||||
|
@ -314,31 +342,31 @@ void PreferencesPanel::AddAccount(int line, Account ac)
|
|||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState((ac._default) ? Qt::Checked : Qt::Unchecked);
|
||||
_accountsGrid->setCellWidget(line, ACCOUNT_DEFAULT, checkBox);
|
||||
InsertCenteredWidget(_accountsGrid, line, ACCOUNT_DEFAULT, checkBox);
|
||||
_defaultSignalMapper.setMapping(checkBox, ac.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_defaultSignalMapper, SLOT(map()));
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState((ac._virtual) ? Qt::Checked : Qt::Unchecked);
|
||||
_accountsGrid->setCellWidget(line, ACCOUNT_VIRTUAL, checkBox);
|
||||
InsertCenteredWidget(_accountsGrid, line, ACCOUNT_VIRTUAL, checkBox);
|
||||
_virtualSignalMapper.setMapping(checkBox, ac.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_virtualSignalMapper, SLOT(map()));
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState((ac.blocked) ? Qt::Checked : Qt::Unchecked);
|
||||
_accountsGrid->setCellWidget(line, ACCOUNT_BLOCKED, checkBox);
|
||||
InsertCenteredWidget(_accountsGrid, line, ACCOUNT_BLOCKED, checkBox);
|
||||
_blockedSignalMapper.setMapping(checkBox, ac.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_blockedSignalMapper, SLOT(map()));
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
_accountsGrid->setCellWidget(line, ACCOUNT_DELETE, checkBox);
|
||||
InsertCenteredWidget(_accountsGrid, line, ACCOUNT_DELETE, checkBox);
|
||||
_deleteAccountSignalMapper.setMapping(checkBox, ac.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_deleteAccountSignalMapper, SLOT(map()));
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState((ac.hidden) ? Qt::Checked : Qt::Unchecked);
|
||||
_accountsGrid->setCellWidget(line, ACCOUNT_HIDDEN, checkBox);
|
||||
InsertCenteredWidget(_accountsGrid, line, ACCOUNT_HIDDEN, checkBox);
|
||||
_hiddenAccountSignalMapper.setMapping(checkBox, ac.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_hiddenAccountSignalMapper, SLOT(map()));
|
||||
|
||||
|
@ -465,7 +493,7 @@ void PreferencesPanel::AddCategory(int line, Category cat)
|
|||
{
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
_categoriesGrid->setCellWidget(line, CATEGORY_DELETE, checkBox);
|
||||
InsertCenteredWidget(_categoriesGrid, line, CATEGORY_DELETE, checkBox);
|
||||
_deleteCategorySignalMapper.setMapping(checkBox, cat.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_deleteCategorySignalMapper, SLOT(map()));
|
||||
}
|
||||
|
@ -563,7 +591,7 @@ void PreferencesPanel::AddTag(int line, Tag tag)
|
|||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
_tagsGrid->setCellWidget(line, TAG_DELETE, checkBox);
|
||||
InsertCenteredWidget(_tagsGrid, line, TAG_DELETE, checkBox);
|
||||
_deleteTagSignalMapper.setMapping(checkBox, tag.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_deleteTagSignalMapper, SLOT(map()));
|
||||
|
||||
|
@ -658,7 +686,7 @@ void PreferencesPanel::OnAccountDefaultClicked(int id)
|
|||
{
|
||||
account._default = false;
|
||||
_kiss->UpdateAccount(account);
|
||||
checkBox = qobject_cast<QCheckBox*>(_accountsGrid->cellWidget(i, ACCOUNT_DEFAULT));
|
||||
checkBox = qobject_cast<QCheckBox*>(GetCenteredWidget(_accountsGrid, i, ACCOUNT_DEFAULT));
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
break;
|
||||
}
|
||||
|
@ -778,9 +806,9 @@ void PreferencesPanel::OnAccountDeleteClicked(int id)
|
|||
user->_accounts[0]._default = true;
|
||||
user->_accounts[0].hidden = false;
|
||||
_kiss->UpdateAccount(user->_accounts[0]);
|
||||
checkBox = qobject_cast<QCheckBox*> (_accountsGrid->cellWidget(0, ACCOUNT_DEFAULT));
|
||||
checkBox = qobject_cast<QCheckBox*> (GetCenteredWidget(_accountsGrid, 0, ACCOUNT_DEFAULT));
|
||||
checkBox->setCheckState(Qt::Checked);
|
||||
checkBox = qobject_cast<QCheckBox*> (_accountsGrid->cellWidget(0, ACCOUNT_HIDDEN));
|
||||
checkBox = qobject_cast<QCheckBox*> (GetCenteredWidget(_accountsGrid, 0, ACCOUNT_HIDDEN));
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
|
||||
|
|
|
@ -86,6 +86,10 @@ private:
|
|||
void InitLanguage(User* user);
|
||||
void InitOperationOrder(User* user);
|
||||
|
||||
void InsertCenteredWidget(QTableWidget* table, int line, int column,
|
||||
QWidget* widget, int margins=3);
|
||||
QWidget* GetCenteredWidget(QTableWidget* table, int line, int column);
|
||||
|
||||
void AddAccount(int line, Account ac);
|
||||
void AddCategory(int line, Category cat);
|
||||
void AddTag(int line, Tag tag);
|
||||
|
|
Loading…
Reference in New Issue
Block a user