diff options
author | Daniel Molkentin <danimo@owncloud.com> | 2015-08-11 22:45:27 +0300 |
---|---|---|
committer | Daniel Molkentin <danimo@owncloud.com> | 2015-08-11 22:45:27 +0300 |
commit | a9acb185a0b364b72c5ed985c2707390afd11d36 (patch) | |
tree | 053d15cde51874222d23a175fb945c7d2367b01a | |
parent | 3267c15affe4572472ac13e9290e2ce65679749d (diff) |
SettingsDialog: Fixup default action setting
This broke silently when switching from pure actions to widgets
-rw-r--r-- | src/gui/settingsdialog.cpp | 44 | ||||
-rw-r--r-- | src/gui/settingsdialog.h | 5 |
2 files changed, 31 insertions, 18 deletions
diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index f8a0fe8c6..30f0c8735 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -37,20 +37,13 @@ #include <QVBoxLayout> #include <QPixmap> #include <QImage> +#include <QWidgetAction> 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:checked { background: %3; color: %4; }"; - - void addActionToToolBar(QAction *action, QToolBar *tb) { - QToolButton* btn = new QToolButton; - btn->setDefaultAction(action); - btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); - tb->addWidget(btn); - } } namespace OCC { @@ -58,10 +51,21 @@ namespace OCC { // // Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp ! // +void SettingsDialog::setDefaultAction() +{ + Q_FOREACH(QAction *action, _toolBar->actions()) { + if (QWidgetAction *wa = qobject_cast<QWidgetAction*>(action)) { + if (QToolButton *qtb = qobject_cast<QToolButton*>(wa->defaultWidget())) { + qtb->setChecked(true); + break; + } + } + } +} + SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : QDialog(parent) , _ui(new Ui::SettingsDialog), _gui(gui) - { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); _ui->setupUi(this); @@ -89,19 +93,19 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : // all buttons must have the same size in order to keep a good layout _protocolAction = createColorAwareAction(QLatin1String(":/client/resources/activity.png"), tr("Activity")); _actionGroup->addAction(_protocolAction); - addActionToToolBar(_protocolAction, _toolBar); + addActionToToolBar(_protocolAction); ProtocolWidget *protocolWidget = new ProtocolWidget; _ui->stack->addWidget(protocolWidget); QAction *generalAction = createColorAwareAction(QLatin1String(":/client/resources/settings.png"), tr("General")); _actionGroup->addAction(generalAction); - addActionToToolBar(generalAction, _toolBar); + addActionToToolBar(generalAction); GeneralSettings *generalSettings = new GeneralSettings; _ui->stack->addWidget(generalSettings); QAction *networkAction = createColorAwareAction(QLatin1String(":/client/resources/network.png"), tr("Network")); _actionGroup->addAction(networkAction); - addActionToToolBar(networkAction, _toolBar); + addActionToToolBar(networkAction); NetworkSettings *networkSettings = new NetworkSettings; _ui->stack->addWidget(networkSettings); @@ -119,8 +123,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) : accountAdded(ai.data()); } - // default to Account - _toolBar->actions().at(0)->trigger(); + setDefaultAction(); QPushButton *closeButton = _ui->buttonBox->button(QDialogButtonBox::Close); connect(closeButton, SIGNAL(clicked()), SLOT(accept())); @@ -195,7 +198,7 @@ void SettingsDialog::accountAdded(AccountState *s) accountButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); QAction* toolbarAction = _toolBar->insertWidget(_toolBar->actions().at(0), accountButton); - _toolbarActions.insert(accountAction, toolbarAction); + _toolbarAccountActions.insert(accountAction, toolbarAction); auto accountSettings = new AccountSettings(s, this); _ui->stack->insertWidget(0 , accountSettings); @@ -217,8 +220,8 @@ void SettingsDialog::accountRemoved(AccountState *s) continue; } if (as->accountsState() == s) { - _toolBar->removeAction(_toolbarActions.value(it.key())); - _toolbarActions.remove(it.key()); + _toolBar->removeAction(_toolbarAccountActions.value(it.key())); + _toolbarAccountActions.remove(it.key()); delete it.key(); delete it.value(); @@ -272,5 +275,12 @@ QAction *SettingsDialog::createColorAwareAction(const QString &iconPath, const Q return action; } +void SettingsDialog::addActionToToolBar(QAction *action) { + QToolButton* btn = new QToolButton; + btn->setDefaultAction(action); + btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); + btn->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); + _toolBar->addWidget(btn); +} } // namespace OCC diff --git a/src/gui/settingsdialog.h b/src/gui/settingsdialog.h index dbd4ff23e..9eafd82ab 100644 --- a/src/gui/settingsdialog.h +++ b/src/gui/settingsdialog.h @@ -50,6 +50,7 @@ public: void addAccount(const QString &title, QWidget *widget); + void setDefaultAction(); public slots: void showActivityPage(); void slotSwitchPage(QAction *action); @@ -67,6 +68,7 @@ private: void customizeStyle(); QIcon createColorAwareIcon(const QString &name); QAction *createColorAwareAction(const QString &iconName, const QString &fileName); + void addActionToToolBar(QAction *action); Ui::SettingsDialog * const _ui; QActionGroup* _actionGroup; @@ -75,8 +77,9 @@ private: QToolBar* _toolBar; // Maps the actions from the action group to the toolbar actions - QHash<QAction*, QAction*> _toolbarActions; + QHash<QAction*, QAction*> _toolbarAccountActions; + QAction * _seperatorAction; QAction * _protocolAction; ownCloudGui *_gui; }; |