Skip to content

Commit 7c306ce

Browse files
committed
Merge #411 [stable-4.0] [master] 2003-Main_Settings_Dialog
2 parents 389a040 + e9e6827 commit 7c306ce

File tree

7 files changed

+210
-29
lines changed

7 files changed

+210
-29
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (C) by Eugen Fischer
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* for more details.
13+
*/
14+
15+
#include "nmcsettingsdialog.h"
16+
#include <QBoxLayout>
17+
#include <QLabel>
18+
#include <QToolBar>
19+
#include "settingsdialog.h"
20+
21+
namespace OCC {
22+
23+
NMCSettingsDialog::NMCSettingsDialog(ownCloudGui *gui, QWidget *parent)
24+
: SettingsDialog(gui, parent)
25+
{
26+
setLayout();
27+
28+
// The window has no background widget, use palette
29+
// QPalette palette;
30+
// palette.setColor(QPalette::Window, QColor("#F3f3f3"));
31+
// setPalette(palette);
32+
33+
setFixedSize(760,760);
34+
35+
getToolBar()->setFixedHeight(92); // 76px button height + 8 + 8 margin top and bottom
36+
getToolBar()->setContentsMargins(8, 0, 8, 0); // Left margin not accepted, Qt bug?
37+
}
38+
39+
void NMCSettingsDialog::slotAccountAvatarChanged()
40+
{
41+
//Intercept the base class slot, so the round avatar is not set. (dont pass to base class)
42+
//Fix Account button size, for ech new created account
43+
fixAccountButton();
44+
}
45+
46+
void OCC::NMCSettingsDialog::setLayout() const
47+
{
48+
//Fix network and general settings button size
49+
const auto actions = getToolBar()->actions();
50+
for(auto *action : actions)
51+
{
52+
if((action->text() == QCoreApplication::translate("OCC::SettingsDialog","General") || action->text() == QCoreApplication::tr("General")) ||
53+
(action->text() == QCoreApplication::translate("OCC::SettingsDialog","Network") || action->text() == QCoreApplication::tr("Network")) ||
54+
(action->text() == QCoreApplication::translate("OCC::SettingsDialog","Account") || action->text() == QCoreApplication::tr("Account")))
55+
{
56+
auto *widget = getToolBar()->widgetForAction(action);
57+
if(widget)
58+
{
59+
widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
60+
widget->setFixedSize(76, 76);
61+
}
62+
}
63+
}
64+
65+
//Fix initial account button size and stylesheet
66+
fixAccountButton();
67+
}
68+
69+
void NMCSettingsDialog::fixAccountButton() const
70+
{
71+
auto toolbar = getToolBar();
72+
73+
// Sicher prüfen, ob ein Spacer schon existiert
74+
auto *firstAction = toolbar->actions().at(0);
75+
auto *firstWidget = toolbar->widgetForAction(firstAction);
76+
if (!firstWidget || !firstWidget->objectName().startsWith("spacer_left")) {
77+
auto *spacer = new QWidget(toolbar);
78+
spacer->setFixedWidth(16);
79+
spacer->setObjectName("spacer_left");
80+
spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
81+
toolbar->insertWidget(firstAction, spacer);
82+
}
83+
84+
// Account-Button anpassen
85+
if (toolbar->actions().size() > 1) {
86+
auto action = toolbar->actions().at(1); // Index 1, da davor Spacer
87+
auto *widget = toolbar->widgetForAction(action);
88+
if(widget)
89+
{
90+
widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
91+
widget->setFixedSize(152, 76);
92+
}
93+
}
94+
}
95+
96+
} // namespace OCC

src/gui/nmcgui/nmcsettingsdialog.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) by Eugen Fischer
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but
10+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* for more details.
13+
*/
14+
15+
#ifndef MIRALL_SETTINGSDIALOGMAGENTA_H
16+
#define MIRALL_SETTINGSDIALOGMAGENTA_H
17+
18+
#include <settingsdialog.h>
19+
20+
namespace OCC {
21+
22+
/**
23+
* @brief The NMCSettingsDialog class
24+
*
25+
* This class represents the settings dialog specific to the Magenta theme.
26+
* It inherits from SettingsDialog and provides additional functionalities
27+
* or customizations related to the Magenta theme.
28+
*
29+
* @ingroup gui
30+
*/
31+
class NMCSettingsDialog : public SettingsDialog
32+
{
33+
Q_OBJECT
34+
35+
public:
36+
/**
37+
* @brief Constructor for NMCSettingsDialog
38+
*
39+
* @param gui Pointer to the ownCloudGui instance.
40+
* @param parent Pointer to the parent QWidget (default is nullptr).
41+
*/
42+
explicit NMCSettingsDialog(ownCloudGui *gui, QWidget *parent = nullptr);
43+
44+
/**
45+
* @brief Destructor for NMCSettingsDialog
46+
*/
47+
~NMCSettingsDialog() = default;
48+
49+
public slots:
50+
/**
51+
* @brief Slot for handling changes in the account avatar
52+
*/
53+
void slotAccountAvatarChanged();
54+
55+
// NMCGuiInterface interface
56+
protected:
57+
/**
58+
* @brief Sets the layout for the NMCSettingsDialog
59+
*/
60+
void setLayout() const;
61+
62+
private:
63+
/**
64+
* @brief Fixes the appearance of the account button
65+
*/
66+
void fixAccountButton() const;
67+
};
68+
69+
} // namespace OCC
70+
#endif // MIRALL_SETTINGSDIALOGMAGENTA_H

src/gui/owncloudgui.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "owncloudsetupwizard.h"
2222
#include "progressdispatcher.h"
2323
#include "settingsdialog.h"
24+
#include "nmcgui/nmcsettingsdialog.h"
2425
#include "theme.h"
2526
#include "wheelhandler.h"
2627
#include "syncconflictsmodel.h"
@@ -611,7 +612,7 @@ void ownCloudGui::slotShowGuiMessage(const QString &title, const QString &messag
611612
void ownCloudGui::slotShowSettings()
612613
{
613614
if (_settingsDialog.isNull()) {
614-
_settingsDialog = new SettingsDialog(this);
615+
_settingsDialog = new NMCSettingsDialog(this);
615616
_settingsDialog->setAttribute(Qt::WA_DeleteOnClose, true);
616617

617618
#ifdef Q_OS_MACOS

src/gui/settingsdialog.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "settingsdialog.h"
88
#include "ui_settingsdialog.h"
9+
#include "QtWidgets/qmainwindow.h"
910

1011
#include "folderman.h"
1112
#include "theme.h"
@@ -38,10 +39,13 @@
3839
namespace {
3940
const QString TOOLBAR_CSS()
4041
{
41-
return QStringLiteral("QToolBar { background: %1; margin: 0; padding: 0; border: none; border-bottom: 1px solid %2; spacing: 0; } "
42-
"QToolBar QToolButton { background: %1; border: none; border-bottom: 1px solid %2; margin: 0; padding: 5px; } "
43-
"QToolBar QToolBarExtension { padding:0; } "
44-
"QToolBar QToolButton:checked { background: %3; color: %4; }");
42+
return QStringLiteral(
43+
"QToolBar { background: %1; margin: 0; padding: 0; border: none; spacing: 0; } "
44+
"QToolBar QToolButton { background: %1; border: none; border-radius: 4px; margin: 0; padding: 6px; } "
45+
"QToolBar QToolBarExtension { padding: 0; } "
46+
"QToolBar QToolButton:hover { background: %2; } "
47+
"QToolBar QToolButton:checked { background: %3; }"
48+
);
4549
}
4650

4751
const float buttonSizeRatio = 1.618f; // golden ratio
@@ -65,7 +69,7 @@ QString shortDisplayNameForSettings(OCC::Account *account, int width)
6569
host = fm.elidedText(host, Qt::ElideMiddle, width);
6670
user = fm.elidedText(user, Qt::ElideRight, width);
6771
}
68-
return QStringLiteral("%1\n%2").arg(user, host);
72+
return QStringLiteral("%1").arg(user);
6973
}
7074
}
7175

@@ -118,6 +122,12 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent)
118122
auto *generalSettings = new NMCGeneralSettings;
119123
_ui->stack->addWidget(generalSettings);
120124

125+
// Adds space between general and network actions
126+
auto *spacer2 = new QWidget();
127+
spacer2->setFixedWidth(8);
128+
spacer2->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
129+
_toolBar->addWidget(spacer2);
130+
121131
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
122132
connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged);
123133

@@ -231,7 +241,7 @@ void SettingsDialog::accountAdded(AccountState *s)
231241
const auto accountAction = createColorAwareAction(QLatin1String(":/client/theme/account.svg"), actionText);
232242

233243
if (!brandingSingleAccount) {
234-
accountAction->setToolTip(s->account()->displayName());
244+
accountAction->setToolTip(shortDisplayNameForSettings(s->account().data(), static_cast<int>(height * buttonSizeRatio)));
235245
accountAction->setIconText(shortDisplayNameForSettings(s->account().data(), static_cast<int>(height * buttonSizeRatio)));
236246
}
237247

@@ -290,6 +300,7 @@ void SettingsDialog::slotAccountDisplayNameChanged()
290300
QString displayName = account->displayName();
291301
action->setText(displayName);
292302
auto height = _toolBar->sizeHint().height();
303+
action->setToolTip(shortDisplayNameForSettings(account, static_cast<int>(height * buttonSizeRatio)));
293304
action->setIconText(shortDisplayNameForSettings(account, static_cast<int>(height * buttonSizeRatio)));
294305
}
295306
}
@@ -330,20 +341,11 @@ void SettingsDialog::accountRemoved(AccountState *s)
330341

331342
void SettingsDialog::customizeStyle()
332343
{
333-
QString highlightColor(palette().highlight().color().name());
334-
QString highlightTextColor(palette().highlightedText().color().name());
335-
QString dark(palette().dark().color().name());
336344
QString background(palette().base().color().name());
337-
_toolBar->setStyleSheet(TOOLBAR_CSS().arg(background, dark, highlightColor, highlightTextColor));
338-
339-
const auto &allActions = _actionGroup->actions();
340-
for (const auto a : allActions) {
341-
QIcon icon = Theme::createColorAwareIcon(a->property("iconPath").toString(), palette());
342-
a->setIcon(icon);
343-
auto *btn = qobject_cast<QToolButton *>(_toolBar->widgetForAction(a));
344-
if (btn)
345-
btn->setIcon(icon);
346-
}
345+
QString highlightColor(palette().highlight().color().name());
346+
QString midlightColor(palette().mid().color().name());
347+
348+
_toolBar->setStyleSheet(TOOLBAR_CSS().arg(background, highlightColor, midlightColor));
347349
}
348350

349351
class ToolButtonAction : public QWidgetAction

src/gui/settingsdialog.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,16 @@ class SettingsDialog : public QDialog
4545

4646
QWidget* currentPage();
4747

48+
QToolBar *getToolBar() const
49+
{
50+
return _toolBar;
51+
}
52+
4853
public slots:
4954
void showFirstPage();
5055
void showIssuesList(OCC::AccountState *account);
5156
void slotSwitchPage(QAction *action);
52-
void slotAccountAvatarChanged();
57+
virtual void slotAccountAvatarChanged();
5358
void slotAccountDisplayNameChanged();
5459

5560
signals:
@@ -66,9 +71,10 @@ private slots:
6671
void accountAdded(OCC::AccountState *);
6772
void accountRemoved(OCC::AccountState *);
6873

69-
private:
74+
protected:
7075
void customizeStyle();
7176

77+
private:
7278
QAction *createColorAwareAction(const QString &iconName, const QString &fileName);
7379
QAction *createActionWithIcon(const QIcon &icon, const QString &text, const QString &iconPath = QString());
7480

theme/account.svg

Lines changed: 6 additions & 6 deletions
Loading

theme/network.svg

Lines changed: 7 additions & 1 deletion
Loading

0 commit comments

Comments
 (0)