Skip to content

Commit

Permalink
qt: Resize main toolbar depending on visible buttons / font attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
xdustinface committed Sep 28, 2020
1 parent 3a8d9a4 commit c0447b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,9 @@ void BitcoinGUI::optionsClicked()

OptionsDialog dlg(this, enableWallet);
dlg.setModel(clientModel->getOptionsModel());
connect(&dlg, &OptionsDialog::appearanceChanged, [=]() {
updateWidth();
});
dlg.exec();

updatePrivateSendVisibility();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ private Q_SLOTS:
void showModalOverlay();

void updatePrivateSendVisibility();

void updateWidth();
};

class UnitDisplayStatusBarControl : public QLabel
Expand Down

0 comments on commit c0447b0

Please sign in to comment.