зеркало из https://github.com/nextcloud/desktop.git
Account Settings: rework the toolbar
Modifications ask by Jan: - Elide the label in the actions - Minimum sizes for the actions - No separatcions between the accounts Issue #3516
This commit is contained in:
Родитель
ce769cb1ef
Коммит
1a0d0c0a31
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <QSettings>
|
||||
#include <qfontmetrics.h>
|
||||
|
||||
namespace OCC {
|
||||
|
||||
|
@ -252,24 +253,17 @@ std::unique_ptr<QSettings> AccountState::settings()
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -89,8 +89,10 @@ public:
|
|||
/** 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);
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
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; }";
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
|
|||
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);
|
||||
|
||||
|
@ -191,14 +188,16 @@ void SettingsDialog::showActivityPage()
|
|||
|
||||
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);
|
||||
|
@ -211,8 +210,6 @@ void SettingsDialog::accountAdded(AccountState *s)
|
|||
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)
|
||||
|
@ -232,8 +229,6 @@ void SettingsDialog::accountRemoved(AccountState *s)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_seperatorAction->setVisible(!_toolbarAccountActions.isEmpty());
|
||||
}
|
||||
|
||||
void SettingsDialog::customizeStyle()
|
||||
|
@ -284,6 +279,7 @@ void SettingsDialog::addActionToToolBar(QAction *action) {
|
|||
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
|
||||
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
_toolBar->addWidget(btn);
|
||||
btn->setMinimumWidth(_toolBar->sizeHint().height() * 1.3);
|
||||
}
|
||||
|
||||
} // namespace OCC
|
||||
|
|
|
@ -79,7 +79,6 @@ private:
|
|||
// Maps the actions from the action group to the toolbar actions
|
||||
QHash<QAction*, QAction*> _toolbarAccountActions;
|
||||
|
||||
QAction * _seperatorAction;
|
||||
QAction * _protocolAction;
|
||||
ownCloudGui *_gui;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче