Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Dynamically elide actions #7750

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/7744
Original file line number Diff line number Diff line change
@@ -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
28 changes: 9 additions & 19 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -400,12 +390,12 @@ class ToolButtonAction : public QWidgetAction
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;
}
};
Expand Down