#include <QDebug>
#include <QSettings>
+#include <qfontmetrics.h>
namespace OCC {
return s;
}
-QString AccountState::shortDisplayNameForSettings() const
+QString AccountState::shortDisplayNameForSettings(int width) const
{
- QString userWithoutMailHost = account()->credentials()->user();
- if (userWithoutMailHost.contains('@')) {
- userWithoutMailHost = userWithoutMailHost.left(userWithoutMailHost.lastIndexOf('@'));
+ QString user = account()->credentials()->user();
+ QString host = account()->url().host();
+ if (width > 0) {
+ QFont f;
+ QFontMetrics fm(f);
+ host = fm.elidedText(host, Qt::ElideRight, width);
+ user = fm.elidedText(user, Qt::ElideRight, width);
}
- QString hostWithoutTld = account()->url().host();
- if (hostWithoutTld.contains('.') && !hostWithoutTld.at(0).isDigit()) {
- hostWithoutTld = hostWithoutTld.left(hostWithoutTld.lastIndexOf('.'));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("www."), QLatin1String(""));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("cloud."), QLatin1String(""));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("sync."), QLatin1String(""));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("drive."), QLatin1String(""));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("share."), QLatin1String(""));
- hostWithoutTld = hostWithoutTld.replace(QLatin1String("web."), QLatin1String(""));
- }
-
- return userWithoutMailHost + QLatin1String("\n") + hostWithoutTld;
+ return user + QLatin1String("\n") + host;
}
/** Returns a new settings object for this account, already in the right groups. */
std::unique_ptr<QSettings> settings();
- /** display name with two lines that is displayed in the settings */
- QString shortDisplayNameForSettings() const;
+ /** 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(int width = 0) const;
private:
void setState(State state);
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: 0; } "
+ "QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 5px; } "
"QToolBar QToolButton:checked { background: %3; color: %4; }";
}
connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept()));
addAction(closeWindowAction);
-
setObjectName("Settings"); // required as group for saveGeometry call
setWindowTitle(Theme::instance()->appNameGUI());
- // Add a spacer so config buttons are right aligned and account buttons will be left aligned
- _seperatorAction = _toolBar->addSeparator();
_actionGroup = new QActionGroup(this);
_actionGroup->setExclusive(true);
void SettingsDialog::accountAdded(AccountState *s)
{
+ auto height = _toolBar->sizeHint().height();
auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
- s->shortDisplayNameForSettings());
+ s->shortDisplayNameForSettings(height * 1.618)); // Golden ratio
accountAction->setToolTip(s->account()->displayName());
QToolButton* accountButton = new QToolButton;
- accountButton->setDefaultAction(accountAction);
accountButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
+ accountButton->setDefaultAction(accountAction);
accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+ accountButton->setMinimumWidth(height * 1.3);
QAction* toolbarAction = _toolBar->insertWidget(_toolBar->actions().at(0), accountButton);
_toolbarAccountActions.insert(accountAction, toolbarAction);
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged()));
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)),
_gui, SLOT(slotFolderOpenAction(QString)));
-
- _seperatorAction->setVisible(!_toolbarAccountActions.isEmpty());
}
void SettingsDialog::accountRemoved(AccountState *s)
break;
}
}
-
- _seperatorAction->setVisible(!_toolbarAccountActions.isEmpty());
}
void SettingsDialog::customizeStyle()
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
_toolBar->addWidget(btn);
+ btn->setMinimumWidth(_toolBar->sizeHint().height() * 1.3);
}
} // namespace OCC