Skip to content

Commit 46c50f8

Browse files
committed
fix e2ee buttons
1 parent d5afb8e commit 46c50f8

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

src/gui/nmcgui/nmcaccountsettings.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <QHBoxLayout>
2525
#include <QIcon>
2626
#include <QLabel>
27+
#include <QLayout>
2728
#include <QProgressBar>
2829
#include <QPushButton>
2930
#include <QSizePolicy>
@@ -162,6 +163,21 @@ void setupTransparentLayout(QLayout *layout, int spacing = 0)
162163
layout->setContentsMargins(0, 0, 0, 0);
163164
layout->setSpacing(spacing);
164165
}
166+
167+
bool layoutContainsPushButton(QLayout *layout)
168+
{
169+
if (!layout) {
170+
return false;
171+
}
172+
173+
for (int i = 0; i < layout->count(); ++i) {
174+
if (qobject_cast<QPushButton *>(layout->itemAt(i)->widget())) {
175+
return true;
176+
}
177+
}
178+
179+
return false;
180+
}
165181
}
166182

167183
NMCAccountSettings::NMCAccountSettings(AccountState *accountState, QWidget *parent)
@@ -246,26 +262,33 @@ void NMCAccountSettings::setLayout()
246262
setupContentLabel(getUi()->encryptionMessageLabel);
247263
setupTransparentWidget(getUi()->encryptionMessageLabel);
248264

249-
clearLayout(e2eeButtonContainerLayout);
265+
auto *sourceLayout = getUi()->encryptionMessageButtonsLayout;
266+
const bool hasNewSourceButtons = layoutContainsPushButton(sourceLayout);
267+
268+
if (hasNewSourceButtons) {
269+
clearLayout(e2eeButtonContainerLayout);
250270

251-
if (auto *sourceLayout = getUi()->encryptionMessageButtonsLayout) {
252271
while (auto *item = sourceLayout->takeAt(0)) {
253272
if (auto *button = qobject_cast<QPushButton *>(item->widget())) {
254273
styleSecondaryButton(button);
255274
e2eeButtonContainerLayout->addWidget(button, 0, Qt::AlignRight);
256275
}
257276
delete item;
258277
}
259-
}
260278

261-
e2eeButtonContainerLayout->addStretch();
279+
e2eeButtonContainerLayout->addStretch();
280+
} else {
281+
for (int i = 0; i < e2eeButtonContainerLayout->count(); ++i) {
282+
if (auto *button = qobject_cast<QPushButton *>(e2eeButtonContainerLayout->itemAt(i)->widget())) {
283+
styleSecondaryButton(button);
284+
}
285+
}
286+
}
262287

263288
getUi()->encryptionMessage->updateGeometry();
264-
getUi()->encryptionMessage->adjustSize();
265289

266290
if (auto *panel = getUi()->encryptionMessage->parentWidget()) {
267291
panel->updateGeometry();
268-
panel->adjustSize();
269292
}
270293

271294
updateGeometry();

0 commit comments

Comments
 (0)