mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
parent
01dcccbd71
commit
9b6ebe8bfb
6
changelog/unreleased/7744
Normal file
6
changelog/unreleased/7744
Normal file
@ -0,0 +1,6 @@
|
||||
Resize the buttons in the settings view dynamically
|
||||
|
||||
Since Qt 5.12 the button text gets elided automatically
|
||||
if the button text would exceed the button width.
|
||||
|
||||
https://github.com/owncloud/client/issues/7744
|
||||
@ -52,13 +52,12 @@ const QString TOOLBAR_CSS()
|
||||
"QToolBar QToolButton:checked { background: %3; color: %4; }");
|
||||
}
|
||||
|
||||
const float buttonSizeRatio = 1.618f; // golden ratio
|
||||
const float BUTTONSIZERATIO = 1.618f; // golden ratio
|
||||
|
||||
|
||||
/** display name with two lines that is displayed in the settings
|
||||
* If width is bigger than 0, the string will be ellided so it does not exceed that width
|
||||
*/
|
||||
QString shortDisplayNameForSettings(OCC::Account *account, int width)
|
||||
QString shortDisplayNameForSettings(OCC::Account *account)
|
||||
{
|
||||
QString user = account->davDisplayName();
|
||||
if (user.isEmpty()) {
|
||||
@ -70,12 +69,6 @@ QString shortDisplayNameForSettings(OCC::Account *account, int width)
|
||||
host.append(QLatin1Char(':'));
|
||||
host.append(QString::number(port));
|
||||
}
|
||||
if (width > 0) {
|
||||
QFont f;
|
||||
QFontMetrics fm(f);
|
||||
host = fm.elidedText(host, Qt::ElideMiddle, width);
|
||||
user = fm.elidedText(user, Qt::ElideRight, width);
|
||||
}
|
||||
return QStringLiteral("%1\n%2").arg(user, host);
|
||||
}
|
||||
}
|
||||
@ -134,7 +127,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
|
||||
_ui->stack->addWidget(networkSettings);
|
||||
|
||||
QWidget *spacer = new QWidget();
|
||||
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
|
||||
_toolBar->addWidget(spacer);
|
||||
|
||||
QAction *quitAction = createColorAwareAction(QLatin1String(":/client/resources/quit.png"), tr("Quit %1").arg(qApp->applicationName()));
|
||||
@ -248,8 +241,6 @@ void SettingsDialog::showIssuesList(const QString &folderAlias)
|
||||
|
||||
void SettingsDialog::accountAdded(AccountState *s)
|
||||
{
|
||||
auto height = _toolBar->sizeHint().height();
|
||||
|
||||
bool brandingSingleAccount = !Theme::instance()->multiAccount();
|
||||
|
||||
QAction *accountAction;
|
||||
@ -265,7 +256,7 @@ void SettingsDialog::accountAdded(AccountState *s)
|
||||
|
||||
if (!brandingSingleAccount) {
|
||||
accountAction->setToolTip(s->account()->displayName());
|
||||
accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio));
|
||||
accountAction->setIconText(shortDisplayNameForSettings(s->account().data()));
|
||||
}
|
||||
_toolBar->insertAction(_toolBar->actions().at(0), accountAction);
|
||||
auto accountSettings = new AccountSettings(s, this);
|
||||
@ -310,8 +301,7 @@ void SettingsDialog::slotAccountDisplayNameChanged()
|
||||
if (action) {
|
||||
QString displayName = account->displayName();
|
||||
action->setText(displayName);
|
||||
auto height = _toolBar->sizeHint().height();
|
||||
action->setIconText(shortDisplayNameForSettings(account, height * buttonSizeRatio));
|
||||
action->setIconText(shortDisplayNameForSettings(account));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,12 +390,12 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
QToolButton *btn = new QToolButton(parent);
|
||||
QToolButton *btn = new QToolButton(toolbar);
|
||||
btn->setDefaultAction(this);
|
||||
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
// btn->setMinimumWidth(qMax<int>(parent->sizeHint().height() * buttonSizeRatio,
|
||||
// btn->sizeHint().width()));
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::MinimumExpanding);
|
||||
// icon size is fixed, we can't use the toolbars actual size hint as it might not be defined yet
|
||||
btn->setMinimumWidth(toolbar->iconSize().height() * BUTTONSIZERATIO);
|
||||
return btn;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user