Skip to content

Commit 0d5b318

Browse files
authored
Make StrftimeChooserWidget button layout creation independent if number of buttons is even or not. (flameshot-org#4033)
1 parent 89679f5 commit 0d5b318

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/config/strftimechooserwidget.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,33 @@
99
StrftimeChooserWidget::StrftimeChooserWidget(QWidget* parent)
1010
: QWidget(parent)
1111
{
12+
const quint8 MAXCOLUMNS = 2;
1213
auto* layout = new QGridLayout(this);
13-
auto k = m_buttonData.keys();
14-
int middle = k.length() / 2;
15-
// add the buttons in 2 columns (they need to be even)
16-
for (int i = 0; i < 2; i++) {
17-
for (int j = 0; j < middle; j++) {
18-
QString key = k.last();
19-
k.pop_back();
20-
QString variable = m_buttonData.value(key);
21-
auto* button = new QPushButton(this);
22-
button->setText(tr(key.toStdString().data()));
23-
button->setToolTip(variable);
24-
button->setSizePolicy(QSizePolicy::Expanding,
25-
QSizePolicy::Expanding);
26-
button->setMinimumHeight(25);
27-
layout->addWidget(button, j, i);
28-
connect(button, &QPushButton::clicked, this, [variable, this]() {
29-
emit variableEmitted(variable);
30-
});
14+
quint8 row = 0;
15+
quint8 col = 0;
16+
QMapIterator<QString, QString> iterator(m_buttonData);
17+
18+
while (iterator.hasNext()) {
19+
iterator.next();
20+
21+
QString variable = iterator.value();
22+
auto* button = new QPushButton(this);
23+
button->setText(tr(iterator.key().toStdString().data()));
24+
button->setToolTip(variable);
25+
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
26+
button->setMinimumHeight(25);
27+
layout->addWidget(button, row, col);
28+
connect(button, &QPushButton::clicked, this, [variable, this]() {
29+
emit variableEmitted(variable);
30+
});
31+
32+
col++;
33+
if (col >= MAXCOLUMNS) {
34+
row++;
35+
col = 0;
3136
}
3237
}
38+
3339
setLayout(layout);
3440
}
3541

0 commit comments

Comments
 (0)