qt: Resize main toolbar depending on visible buttons / font attributes

This commit is contained in:
xdustinface 2020-09-26 16:59:20 +02:00
parent 3a8d9a4026
commit c0447b0bc6
2 changed files with 29 additions and 0 deletions

View File

@ -924,6 +924,9 @@ void BitcoinGUI::optionsClicked()
OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
connect(&dlg, &OptionsDialog::appearanceChanged, [=]() {
updateWidth();
});
dlg.exec();
updatePrivateSendVisibility();
@ -1171,6 +1174,26 @@ void BitcoinGUI::updatePrivateSendVisibility()
privateSendCoinsMenuAction->setVisible(fEnabled);
showPrivateSendHelpAction->setVisible(fEnabled);
updateToolBarShortcuts();
updateWidth();
}
void BitcoinGUI::updateWidth()
{
int nWidthWidestButton{0};
int nButtonsVisible{0};
for (QAbstractButton* button : tabGroup->buttons()) {
if (!button->isEnabled()) {
continue;
}
QFontMetrics fm(button->font());
nWidthWidestButton = std::max<int>(nWidthWidestButton, fm.width(button->text()));
++nButtonsVisible;
}
// Add 30 per button as padding and use minimum 980 which is the minimum required to show all tab's contents
// Use nButtonsVisible + 1 <- for the dash logo
int nWidth = std::max<int>(980, (nWidthWidestButton + 30) * (nButtonsVisible + 1));
setMinimumWidth(nWidth);
setMaximumWidth(nWidth);
}
void BitcoinGUI::updateToolBarShortcuts()
@ -1490,6 +1513,10 @@ void BitcoinGUI::showEvent(QShowEvent *event)
openRepairAction->setEnabled(true);
aboutAction->setEnabled(true);
optionsAction->setEnabled(true);
if (!event->spontaneous()) {
updateWidth();
}
}
#ifdef ENABLE_WALLET

View File

@ -331,6 +331,8 @@ private Q_SLOTS:
void showModalOverlay();
void updatePrivateSendVisibility();
void updateWidth();
};
class UnitDisplayStatusBarControl : public QLabel