Improve GUI by removing some blank spaces around grids and center widgets
This commit is contained in:
@@ -348,6 +348,33 @@ void GridAccount::InsertOperationWithWeek(User* user, Operation& op, int line, b
|
||||
ComputeWeeks();
|
||||
}
|
||||
|
||||
void GridAccount::InsertCenteredWidget(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);
|
||||
setCellWidget(line, column, fakeWidget);
|
||||
}
|
||||
|
||||
QWidget* GridAccount::GetCenteredWidget(int line, int column)
|
||||
{
|
||||
QWidget* fakeWidget= cellWidget(line, column);
|
||||
|
||||
if (!fakeWidget) return 0;
|
||||
|
||||
QLayout* layout = fakeWidget->layout();
|
||||
QLayoutItem* layoutItem = layout->itemAt(0);
|
||||
|
||||
if (!layoutItem) return 0;
|
||||
|
||||
return layoutItem->widget();
|
||||
}
|
||||
|
||||
void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix, int month, int year)
|
||||
{
|
||||
std::vector<Operation>::iterator it;
|
||||
@@ -414,13 +441,13 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState(Qt::Unchecked);
|
||||
setCellWidget(line, OP_DELETE, checkBox);
|
||||
_deleteSignalMapper.setMapping(checkBox, op.id);
|
||||
InsertCenteredWidget(line, OP_DELETE, checkBox);
|
||||
_deleteSignalMapper.setMapping(checkBox, op.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_deleteSignalMapper, SLOT(map()));
|
||||
|
||||
checkBox = new QCheckBox();
|
||||
checkBox->setCheckState((op.checked) ? Qt::Checked : Qt::Unchecked);
|
||||
setCellWidget(line, CHECKED, checkBox);
|
||||
InsertCenteredWidget(line, CHECKED, checkBox);
|
||||
_checkSignalMapper.setMapping(checkBox, op.id);
|
||||
connect(checkBox, SIGNAL(stateChanged(int)), &_checkSignalMapper, SLOT(map()));
|
||||
|
||||
@@ -496,8 +523,6 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||
this->item(line, OP_DATE)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
this->item(line, DEBIT)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||
this->item(line, CREDIT)->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
|
||||
this->item(line, OP_DELETE)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
this->item(line, CHECKED)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
|
||||
|
||||
if (op.id && op.meta)
|
||||
{
|
||||
@@ -507,7 +532,7 @@ void GridAccount::InsertOperation(User* user, Operation& op, int line, bool fix,
|
||||
connect(button, SIGNAL(clicked()), &_treeSignalMapper, SLOT(map()));
|
||||
|
||||
button->setMaximumSize(QSize(height, height));
|
||||
setCellWidget(line, TREE, button);
|
||||
InsertCenteredWidget(line, TREE, button);
|
||||
|
||||
SET_READ_ONLY(this->item(line, OP_DATE));
|
||||
SET_READ_ONLY(this->item(line, CREDIT));
|
||||
@@ -558,14 +583,14 @@ void GridAccount::DeleteOperation(const Operation& op) throw (OperationNotFound)
|
||||
|
||||
void GridAccount::RemoveRow(const Operation& op, int line, bool deleteOp)
|
||||
{
|
||||
QPushButton* button = qobject_cast<QPushButton*> (cellWidget(line, TREE));
|
||||
QPushButton* button = qobject_cast<QPushButton*> (GetCenteredWidget(line, TREE));
|
||||
|
||||
if (button)
|
||||
button->disconnect(&_treeSignalMapper, SLOT(map()));
|
||||
QCheckBox* checkBox = qobject_cast<QCheckBox*> (cellWidget(line, CHECKED));
|
||||
QCheckBox* checkBox = qobject_cast<QCheckBox*> (GetCenteredWidget(line, CHECKED));
|
||||
if (checkBox)
|
||||
checkBox->disconnect(&_checkSignalMapper, SLOT(map()));
|
||||
checkBox = qobject_cast<QCheckBox*> (cellWidget(line, OP_DELETE));
|
||||
checkBox = qobject_cast<QCheckBox*> (GetCenteredWidget(line, OP_DELETE));
|
||||
if (checkBox)
|
||||
checkBox->disconnect(&_deleteSignalMapper, SLOT(map()));
|
||||
removeRow(line);
|
||||
@@ -666,7 +691,7 @@ void GridAccount::CheckOperation(Operation& op, int line, bool check, bool force
|
||||
op.checked = check;
|
||||
UpdateOperation(op);
|
||||
|
||||
QCheckBox* checkBox = qobject_cast<QCheckBox*>(cellWidget(line, CHECKED));
|
||||
QCheckBox* checkBox = qobject_cast<QCheckBox*>(GetCenteredWidget(line, CHECKED));
|
||||
if (checkBox)
|
||||
checkBox->setCheckState(check ? Qt::Checked : Qt::Unchecked);
|
||||
}
|
||||
@@ -688,7 +713,7 @@ int GridAccount::RemoveMeta(Operation op, int line, bool removeRoot, bool delete
|
||||
std::vector<Operation*>::iterator it, it2;
|
||||
int i, deletedOperations = 0;
|
||||
Operation op2;
|
||||
QPushButton* button = qobject_cast<QPushButton*> (cellWidget(line, TREE));
|
||||
QPushButton* button = qobject_cast<QPushButton*> (GetCenteredWidget(line, TREE));
|
||||
|
||||
for(i=0; i<(int)op.childs.size(); i++)
|
||||
{
|
||||
@@ -761,7 +786,7 @@ bool GridAccount::IsMetaOpened(int id)
|
||||
{
|
||||
int row = GetDisplayedRow(id);
|
||||
|
||||
QPushButton* button = qobject_cast<QPushButton*> (cellWidget(row, TREE));
|
||||
QPushButton* button = qobject_cast<QPushButton*> (GetCenteredWidget(row, TREE));
|
||||
|
||||
return (button->text() == QString("-"));
|
||||
}
|
||||
|
||||
@@ -106,5 +106,8 @@ private:
|
||||
Operation& GetOperation(int id) throw(OperationNotFound);
|
||||
void UpdateOperation(Operation& op);
|
||||
int GetDisplayedRow(int id) throw (OperationNotFound);
|
||||
|
||||
void InsertCenteredWidget(int line, int column, QWidget* widget, int margins=3);
|
||||
QWidget* GetCenteredWidget(int line, int column);
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user