Fix settings dialog for mac.

- Fixes adding/removing accounts with separator in the toolbar -
accounts were not added in the right order and removing was not
including the separator.
- Fixes button sizes in the activities list - the buttons were too small
for the text.

Signed-off-by: Camila San <hello@camila.codes>
This commit is contained in:
Camila San 2018-07-07 17:16:03 +02:00 committed by Roeland Jago Douma
parent 11484d5588
commit f0ca5dbded
No known key found for this signature in database
GPG key ID: F941078878347C0C
4 changed files with 80 additions and 79 deletions

View file

@ -122,79 +122,62 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
timeBox.setHeight(actionTextBox.height());
timeBox.setBottom(timeBox.top() + fm.height());
// buttons
QStyleOptionButton primaryButton;
// buttons - default values
int rightMargin = margin;
int leftMargin = margin * offset;
int top = option.rect.top() + margin;
int buttonSize = option.rect.height()/2;
int right = option.rect.right() - rightMargin;
int left = right - buttonSize;
QStyleOptionButton secondaryButton;
secondaryButton.rect = option.rect;
secondaryButton.features |= QStyleOptionButton::Flat;
secondaryButton.state |= QStyle::State_None;
secondaryButton.rect.setLeft(left);
secondaryButton.rect.setRight(right);
secondaryButton.rect.setTop(top + margin);
secondaryButton.rect.setHeight(iconSize);
QStyleOptionButton primaryButton;
primaryButton.rect = option.rect;
primaryButton.features |= QStyleOptionButton::DefaultButton;
primaryButton.state |= QStyle::State_Raised;
primaryButton.rect.setTop(top);
primaryButton.rect.setHeight(buttonSize);
right = secondaryButton.rect.left() - rightMargin;
left = secondaryButton.rect.left() - leftMargin;
primaryButton.rect.setRight(right);
if(activityType == Activity::Type::NotificationType){
int rightMargin = margin;
int leftMargin = margin * offset;
int top = option.rect.top() + margin - offset;
int buttonSize = option.rect.height()/2.5;
// Secondary will be 'Dismiss' or '...' multiple options button
secondaryButton.rect = option.rect;
secondaryButton.icon = QIcon(QLatin1String(":/client/resources/dialog-close.png"));
if(customList.size() > 1)
secondaryButton.icon = QIcon(QLatin1String(":/client/resources/more.png"));
int right = option.rect.right() - rightMargin;
int left = right - buttonSize;
secondaryButton.iconSize = QSize(buttonSize, buttonSize);
secondaryButton.rect.setLeft(left);
secondaryButton.rect.setRight(right);
secondaryButton.rect.setTop(top);
secondaryButton.rect.setHeight(_buttonHeight);
secondaryButton.features |= QStyleOptionButton::Flat;
secondaryButton.state |= QStyle::State_Raised;
secondaryButton.icon = QIcon(QLatin1String(":/client/resources/more.svg"));
secondaryButton.iconSize = QSize(iconSize, iconSize);
// Primary button will be 'More Information'
primaryButton.rect = option.rect;
primaryButton.text = tr("More information");
right = secondaryButton.rect.left() - rightMargin;
left = secondaryButton.rect.left() - leftMargin;
primaryButton.rect.setLeft(left - fm.width(primaryButton.text));
primaryButton.rect.setRight(right);
primaryButton.rect.setTop(top);
primaryButton.rect.setHeight(_buttonHeight);
primaryButton.features |= QStyleOptionButton::DefaultButton;
primaryButton.state |= QStyle::State_Raised;
primaryButton.rect.setLeft(left - margin * 2 - fm.width(primaryButton.text));
// save info to be able to filter mouse clicks
_buttonHeight = buttonSize;
_spaceBetweenButtons = leftMargin;
_primaryButtonWidth = primaryButton.rect.size().width();
_secondaryButtonWidth = secondaryButton.rect.size().width();
} else if(activityType == Activity::Type::ErrorType){
int rightMargin = margin;
int leftMargin = margin * offset;
int top = option.rect.top() + margin - offset;
int buttonSize = option.rect.height()/2.5;
// Secondary will be 'open file manager' with the folder icon
secondaryButton.rect = option.rect;
secondaryButton.icon = QIcon(QLatin1String(":/client/resources/folder-grey.png"));
int right = option.rect.right() - rightMargin;
int left = right - buttonSize;
secondaryButton.iconSize = QSize(buttonSize, buttonSize);
secondaryButton.rect.setLeft(left);
secondaryButton.rect.setRight(right);
secondaryButton.rect.setTop(top);
secondaryButton.rect.setHeight(_buttonHeight);
secondaryButton.features |= QStyleOptionButton::Flat;
secondaryButton.state |= QStyle::State_Raised;
secondaryButton.iconSize = QSize(iconSize, iconSize);
// Primary button will be 'open browser'
primaryButton.rect = option.rect;
primaryButton.text = tr("Open Browser");
right = secondaryButton.rect.left() - rightMargin;
left = secondaryButton.rect.left() - leftMargin;
primaryButton.rect.setLeft(left - fm.width(primaryButton.text));
primaryButton.rect.setRight(right);
primaryButton.rect.setTop(top);
primaryButton.rect.setHeight(_buttonHeight);
primaryButton.features |= QStyleOptionButton::DefaultButton;
primaryButton.state |= QStyle::State_Raised;
primaryButton.rect.setLeft(left - margin * 2 - fm.width(primaryButton.text));
// save info to be able to filter mouse clicks
_buttonHeight = buttonSize;

View file

@ -100,7 +100,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
_actionBefore = new QAction;
_toolBar->addAction(_actionBefore);
// Adds space
// Adds space between users + activities and general + network actions
QWidget* spacer = new QWidget();
spacer->setMinimumWidth(10);
spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
@ -217,6 +217,8 @@ void SettingsDialog::accountAdded(AccountState *s)
bool brandingSingleAccount = !Theme::instance()->multiAccount();
_activitySettings[s] = new ActivitySettings(s, this);
// if this is not the first account, then before we continue to add more accounts we add a separator
if(AccountManager::instance()->accounts().first().data() != s &&
AccountManager::instance()->accounts().size() >= 1){
_actionGroupWidgets.insert(_toolBar->insertSeparator(_actionBefore), _activitySettings[s]);
@ -330,6 +332,7 @@ void SettingsDialog::accountRemoved(AccountState *s)
if(_activitySettings.contains(s)){
_activitySettings[s]->slotRemoveAccount();
_activitySettings[s]->hide();
// get the settings widget and the separator
foreach(QAction *action, _actionGroupWidgets.keys(_activitySettings[s])){
_actionGroupWidgets.remove(action);

View file

@ -26,7 +26,6 @@
#include "configfile.h"
#include "progressdispatcher.h"
#include "owncloudgui.h"
#include "protocolwidget.h"
#include "activitywidget.h"
#include "accountmanager.h"
@ -72,7 +71,6 @@ SettingsDialogMac::SettingsDialogMac(ownCloudGui *gui, QWidget *parent)
// dialog from minimize is broken in MacPreferencesWindow
setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint | Qt::WindowMaximizeButtonHint);
// Emulate dialog behavior: Escape means close
QAction *closeDialogAction = new QAction(this);
closeDialogAction->setShortcut(QKeySequence(Qt::Key_Escape));
@ -93,20 +91,19 @@ SettingsDialogMac::SettingsDialogMac(ownCloudGui *gui, QWidget *parent)
setWindowTitle(tr("%1").arg(Theme::instance()->appNameGUI()));
QIcon activityIcon(QLatin1String(":/client/resources/activity.png"));
_activitySettings = new ActivitySettings;
addPreferencesPanel(activityIcon, tr("Activity"), _activitySettings);
connect(_activitySettings, SIGNAL(guiLog(QString, QString)), _gui,
SLOT(slotShowOptionalTrayMessage(QString, QString)));
connect(AccountManager::instance(), &AccountManager::accountAdded,
this, &SettingsDialogMac::accountAdded);
connect(AccountManager::instance(), &AccountManager::accountRemoved,
this, &SettingsDialogMac::accountRemoved);
_actionsIdx = -1;
foreach (auto ai, AccountManager::instance()->accounts()) {
accountAdded(ai.data());
}
//_actionBefore = new QAction;
//addAction(_actionBefore);
QIcon generalIcon = MacStandardIcon::icon(MacStandardIcon::PreferencesGeneral);
GeneralSettings *generalSettings = new GeneralSettings;
addPreferencesPanel(generalIcon, tr("General"), generalSettings);
@ -122,7 +119,6 @@ SettingsDialogMac::SettingsDialogMac(ownCloudGui *gui, QWidget *parent)
ConfigFile cfg;
cfg.restoreGeometry(this);
_activitySettings->setNotificationRefreshInterval(cfg.notificationRefreshInterval());
}
void SettingsDialogMac::closeEvent(QCloseEvent *event)
@ -138,26 +134,17 @@ void SettingsDialogMac::showActivityPage()
setCurrentPanelIndex(preferencePanelCount() - 1 - 2);
}
void SettingsDialogMac::showIssuesList(const QString &folderAlias)
{
// Count backwards (0-based) from the last panel (multiple accounts can be on the left)
setCurrentPanelIndex(preferencePanelCount() - 1 - 2);
_activitySettings->slotShowIssuesTab(folderAlias);
}
void SettingsDialogMac::accountAdded(AccountState *s)
{
QIcon accountIcon = MacStandardIcon::icon(MacStandardIcon::UserAccounts);
auto accountSettings = new AccountSettings(s, this);
QString displayName = Theme::instance()->multiAccount() ? SettingsDialogCommon::shortDisplayNameForSettings(s->account().data(), 0) : tr("Account");
insertPreferencesPanel(0, accountIcon, displayName, accountSettings);
// this adds the panel - nothing to add here just to fix the order
insertPreferencesPanel(++_actionsIdx, accountIcon, displayName, accountSettings);
connect(accountSettings, &AccountSettings::folderChanged, _gui, &ownCloudGui::slotFoldersChanged);
connect(accountSettings, &AccountSettings::openFolderAlias, _gui, &ownCloudGui::slotFolderOpenAction);
connect(accountSettings, &AccountSettings::showIssuesList, this, &SettingsDialogMac::showIssuesList);
connect(s->account().data(), &Account::accountChangedAvatar, this, &SettingsDialogMac::slotAccountAvatarChanged);
connect(s->account().data(), &Account::accountChangedDisplayName, this, &SettingsDialogMac::slotAccountDisplayNameChanged);
@ -165,6 +152,23 @@ void SettingsDialogMac::accountAdded(AccountState *s)
// Refresh immediatly when getting online
connect(s, &AccountState::isConnectedChanged, this, &SettingsDialogMac::slotRefreshActivityAccountStateSender);
// Add activity panel
QIcon activityIcon(QLatin1String(":/client/resources/activity.png"));
_activitySettings[s] = new ActivitySettings(s, this);
insertPreferencesPanel(++_actionsIdx, activityIcon, tr("Activity"), _activitySettings[s]);
connect(_activitySettings[s], SIGNAL(guiLog(QString, QString)), _gui,
SLOT(slotShowOptionalTrayMessage(QString, QString)));
// if this is not the first account, add separator 2 positions before int the toolbar
if(AccountManager::instance()->accounts().first().data() != s &&
AccountManager::instance()->accounts().size() >= 1){
_separators[s] = insertSeparator(_actionsIdx - 1);
++_actionsIdx; //we have one more item in the toolbar
}
ConfigFile cfg;
_activitySettings[s]->setNotificationRefreshInterval(cfg.notificationRefreshInterval());
slotRefreshActivity(s);
}
@ -174,10 +178,18 @@ void SettingsDialogMac::accountRemoved(AccountState *s)
foreach (auto p, list) {
if (p->accountsState() == s) {
removePreferencesPanel(p);
// remove settings panel
if(_activitySettings.contains(s))
removePreferencesPanel(_activitySettings[s]);
// remove separator if there is any
if(_separators.contains(s)){
removeSeparator(_separators[s]);
_separators.remove(s);
}
}
}
_activitySettings->slotRemoveAccount(s);
}
void SettingsDialogMac::slotRefreshActivityAccountStateSender()
@ -188,7 +200,7 @@ void SettingsDialogMac::slotRefreshActivityAccountStateSender()
void SettingsDialogMac::slotRefreshActivity(AccountState *accountState)
{
if (accountState) {
_activitySettings->slotRefresh(accountState);
_activitySettings[accountState]->slotRefresh();
}
}
@ -226,3 +238,4 @@ void SettingsDialogMac::slotAccountDisplayNameChanged()
}
}

View file

@ -26,7 +26,6 @@ class QListWidgetItem;
namespace OCC {
class AccountSettings;
class ProtocolWidget;
class Application;
class FolderMan;
class ownCloudGui;
@ -47,7 +46,6 @@ public:
public slots:
void showActivityPage();
void showIssuesList(const QString &folderAlias);
void slotRefreshActivity(AccountState *accountState);
void slotRefreshActivityAccountStateSender();
@ -60,8 +58,11 @@ private slots:
private:
void closeEvent(QCloseEvent *event);
ProtocolWidget *_protocolWidget;
ActivitySettings *_activitySettings;
QAction *_actionBefore;
int _actionsIdx;
QMap<AccountState *, QAction *> _separators;
QMap<AccountState *, ActivitySettings *> _activitySettings;
ownCloudGui *_gui;
int _protocolIdx;
@ -69,3 +70,4 @@ private:
}
#endif // SETTINGSDIALOGMAC_H
;