mirror of
https://github.com/fergalmoran/flameshot.git
synced 2025-12-22 09:51:06 +00:00
Make StrftimeChooserWidget button layout creation independent if number of buttons is even or not. (#4033)
This commit is contained in:
@@ -9,27 +9,33 @@
|
||||
StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
const quint8 MAXCOLUMNS = 2;
|
||||
auto* layout = new QGridLayout(this);
|
||||
auto k = m_buttonData.keys();
|
||||
int middle = k.length() / 2;
|
||||
// add the buttons in 2 columns (they need to be even)
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < middle; j++) {
|
||||
QString key = k.last();
|
||||
k.pop_back();
|
||||
QString variable = m_buttonData.value(key);
|
||||
quint8 row = 0;
|
||||
quint8 col = 0;
|
||||
QMapIterator<QString, QString> iterator(m_buttonData);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
|
||||
QString variable = iterator.value();
|
||||
auto* button = new QPushButton(this);
|
||||
button->setText(tr(key.toStdString().data()));
|
||||
button->setText(tr(iterator.key().toStdString().data()));
|
||||
button->setToolTip(variable);
|
||||
button->setSizePolicy(QSizePolicy::Expanding,
|
||||
QSizePolicy::Expanding);
|
||||
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
button->setMinimumHeight(25);
|
||||
layout->addWidget(button, j, i);
|
||||
layout->addWidget(button, row, col);
|
||||
connect(button, &QPushButton::clicked, this, [variable, this]() {
|
||||
emit variableEmitted(variable);
|
||||
});
|
||||
|
||||
col++;
|
||||
if (col >= MAXCOLUMNS) {
|
||||
row++;
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user