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:
Olivier Goffart 2015-08-30 15:20:35 +02:00
Родитель ce769cb1ef
Коммит 1a0d0c0a31
4 изменённых файлов: 20 добавлений и 29 удалений

Просмотреть файл

@ -18,6 +18,7 @@
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include <qfontmetrics.h>
namespace OCC { namespace OCC {
@ -252,24 +253,17 @@ std::unique_ptr<QSettings> AccountState::settings()
return s; return s;
} }
QString AccountState::shortDisplayNameForSettings() const QString AccountState::shortDisplayNameForSettings(int width) const
{ {
QString userWithoutMailHost = account()->credentials()->user(); QString user = account()->credentials()->user();
if (userWithoutMailHost.contains('@')) { QString host = account()->url().host();
userWithoutMailHost = userWithoutMailHost.left(userWithoutMailHost.lastIndexOf('@')); 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(); return user + QLatin1String("\n") + 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;
} }

Просмотреть файл

@ -89,8 +89,10 @@ public:
/** Returns a new settings object for this account, already in the right groups. */ /** Returns a new settings object for this account, already in the right groups. */
std::unique_ptr<QSettings> settings(); std::unique_ptr<QSettings> settings();
/** display name with two lines that is displayed in the settings */ /** display name with two lines that is displayed in the settings
QString shortDisplayNameForSettings() const; * 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: private:
void setState(State state); void setState(State state);

Просмотреть файл

@ -42,7 +42,7 @@
namespace { namespace {
const char TOOLBAR_CSS[] = const char TOOLBAR_CSS[] =
"QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } " "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; }"; "QToolBar QToolButton:checked { background: %3; color: %4; }";
} }
@ -69,12 +69,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept())); connect(closeWindowAction, SIGNAL(triggered()), SLOT(accept()));
addAction(closeWindowAction); addAction(closeWindowAction);
setObjectName("Settings"); // required as group for saveGeometry call setObjectName("Settings"); // required as group for saveGeometry call
setWindowTitle(Theme::instance()->appNameGUI()); 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 = new QActionGroup(this);
_actionGroup->setExclusive(true); _actionGroup->setExclusive(true);
@ -191,14 +188,16 @@ void SettingsDialog::showActivityPage()
void SettingsDialog::accountAdded(AccountState *s) void SettingsDialog::accountAdded(AccountState *s)
{ {
auto height = _toolBar->sizeHint().height();
auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"),
s->shortDisplayNameForSettings()); s->shortDisplayNameForSettings(height * 1.618)); // Golden ratio
accountAction->setToolTip(s->account()->displayName()); accountAction->setToolTip(s->account()->displayName());
QToolButton* accountButton = new QToolButton; QToolButton* accountButton = new QToolButton;
accountButton->setDefaultAction(accountAction);
accountButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); accountButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
accountButton->setDefaultAction(accountAction);
accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
accountButton->setMinimumWidth(height * 1.3);
QAction* toolbarAction = _toolBar->insertWidget(_toolBar->actions().at(0), accountButton); QAction* toolbarAction = _toolBar->insertWidget(_toolBar->actions().at(0), accountButton);
_toolbarAccountActions.insert(accountAction, toolbarAction); _toolbarAccountActions.insert(accountAction, toolbarAction);
@ -211,8 +210,6 @@ void SettingsDialog::accountAdded(AccountState *s)
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged())); connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged()));
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)), connect( accountSettings, SIGNAL(openFolderAlias(const QString&)),
_gui, SLOT(slotFolderOpenAction(QString))); _gui, SLOT(slotFolderOpenAction(QString)));
_seperatorAction->setVisible(!_toolbarAccountActions.isEmpty());
} }
void SettingsDialog::accountRemoved(AccountState *s) void SettingsDialog::accountRemoved(AccountState *s)
@ -232,8 +229,6 @@ void SettingsDialog::accountRemoved(AccountState *s)
break; break;
} }
} }
_seperatorAction->setVisible(!_toolbarAccountActions.isEmpty());
} }
void SettingsDialog::customizeStyle() void SettingsDialog::customizeStyle()
@ -284,6 +279,7 @@ void SettingsDialog::addActionToToolBar(QAction *action) {
btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
_toolBar->addWidget(btn); _toolBar->addWidget(btn);
btn->setMinimumWidth(_toolBar->sizeHint().height() * 1.3);
} }
} // namespace OCC } // namespace OCC

Просмотреть файл

@ -79,7 +79,6 @@ private:
// Maps the actions from the action group to the toolbar actions // Maps the actions from the action group to the toolbar actions
QHash<QAction*, QAction*> _toolbarAccountActions; QHash<QAction*, QAction*> _toolbarAccountActions;
QAction * _seperatorAction;
QAction * _protocolAction; QAction * _protocolAction;
ownCloudGui *_gui; ownCloudGui *_gui;
}; };