From fb0c147fbbafd94f2bd27ef303b1aeed8be3d5ca Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Wed, 27 Nov 2019 12:01:44 +0100 Subject: [PATCH] Cleanup --- src/gui/application.cpp | 1 - src/gui/settingsdialog.cpp | 47 ++++++++++++++++++++++++-------- src/gui/settingsdialogcommon.cpp | 28 ------------------- 3 files changed, 36 insertions(+), 40 deletions(-) delete mode 100644 src/gui/settingsdialogcommon.cpp diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 8946ade30e..ff373a0fc2 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -188,7 +188,6 @@ Application::Application(int &argc, char **argv) setOrganizationDomain(QLatin1String(APPLICATION_REV_DOMAIN)); setApplicationName(_theme->appName()); setWindowIcon(_theme->applicationIcon()); - setAttribute(Qt::AA_UseHighDpiPixmaps, true); if (!ConfigFile().exists()) { // Migrate from version <= 2.4 diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 1b8023d077..1b47ce9846 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -43,20 +43,45 @@ #include namespace { -const char TOOLBAR_CSS[] = - "QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } " - "QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 5px; } " - "QToolBar QToolBarExtension { padding:0; } " - "QToolBar QToolButton:checked { background: %3; color: %4; }"; +const QString TOOLBAR_CSS() +{ + return QStringLiteral("QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } " + "QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 5px; } " + "QToolBar QToolBarExtension { padding:0; } " + "QToolBar QToolButton:checked { background: %3; color: %4; }"); +} -static const float buttonSizeRatio = 1.618; // 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 user = account->davDisplayName(); + if (user.isEmpty()) { + user = account->credentials()->user(); + } + QString host = account->url().host(); + int port = account->url().port(); + if (port > 0 && port != 80 && port != 443) { + 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); +} } namespace OCC { -#include "settingsdialogcommon.cpp" - SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : QDialog(parent) , _ui(new Ui::SettingsDialog) @@ -223,7 +248,7 @@ void SettingsDialog::accountAdded(AccountState *s) if (!brandingSingleAccount) { accountAction->setToolTip(s->account()->displayName()); - accountAction->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio)); + accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), height * buttonSizeRatio)); } _toolBar->insertAction(_toolBar->actions().at(0), accountAction); auto accountSettings = new AccountSettings(s, this); @@ -269,7 +294,7 @@ void SettingsDialog::slotAccountDisplayNameChanged() QString displayName = account->displayName(); action->setText(displayName); auto height = _toolBar->sizeHint().height(); - action->setIconText(SettingsDialogCommon::shortDisplayNameForSettings(account, height * buttonSizeRatio)); + action->setIconText(shortDisplayNameForSettings(account, height * buttonSizeRatio)); } } } @@ -314,7 +339,7 @@ void SettingsDialog::customizeStyle() QString highlightTextColor(palette().highlightedText().color().name()); QString dark(palette().dark().color().name()); QString background(palette().base().color().name()); - _toolBar->setStyleSheet(QString::fromLatin1(TOOLBAR_CSS).arg(background, dark, highlightColor, highlightTextColor)); + _toolBar->setStyleSheet(TOOLBAR_CSS().arg(background, dark, highlightColor, highlightTextColor)); Q_FOREACH (QAction *a, _actionGroup->actions()) { QIcon icon = createColorAwareIcon(a->property("iconPath").toString()); diff --git a/src/gui/settingsdialogcommon.cpp b/src/gui/settingsdialogcommon.cpp deleted file mode 100644 index de6f820c86..0000000000 --- a/src/gui/settingsdialogcommon.cpp +++ /dev/null @@ -1,28 +0,0 @@ -namespace SettingsDialogCommon -{ - -/** 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(Account* account, int width) -{ - QString user = account->davDisplayName(); - if (user.isEmpty()) { - user = account->credentials()->user(); - } - QString host = account->url().host(); - int port = account->url().port(); - if (port > 0 && port != 80 && port != 443) { - 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 user + QLatin1String("\n") + host; -} - -} \ No newline at end of file