[Pkg-owncloud-commits] [owncloud-client] 24/218: Account Settings: rework the toolbar

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 17 14:30:34 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 1a0d0c0a313d4cc0c380d8aceadcef90685c1bfe
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Sun Aug 30 15:20:35 2015 +0200

    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
---
 src/gui/accountstate.cpp   | 26 ++++++++++----------------
 src/gui/accountstate.h     |  6 ++++--
 src/gui/settingsdialog.cpp | 16 ++++++----------
 src/gui/settingsdialog.h   |  1 -
 4 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 9256693..7631412 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -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;
 }
 
 
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index d5412aa..f56364e 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -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);
diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp
index a87e3b5..d798bd8 100644
--- a/src/gui/settingsdialog.cpp
+++ b/src/gui/settingsdialog.cpp
@@ -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
diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h
index f6a2198..3b8e0c6 100644
--- a/src/gui/settingsdialog.h
+++ b/src/gui/settingsdialog.h
@@ -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;
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list