Skip to content

Commit 38bfcc9

Browse files
committed
Turn settings menu into a dialog window
Closes quotient-im#553.
1 parent 05c1819 commit 38bfcc9

File tree

6 files changed

+450
-111
lines changed

6 files changed

+450
-111
lines changed

CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ set(quaternion_SRCS
142142
client/activitydetector.cpp
143143
client/dialog.cpp
144144
client/logindialog.cpp
145+
client/settingsdialog.cpp
145146
client/networkconfigdialog.cpp
146147
client/roomdialogs.cpp
147148
client/mainwindow.cpp
@@ -163,6 +164,10 @@ set(quaternion_QRC
163164
client/resources.qrc
164165
)
165166

167+
set(quaternion_UI
168+
client/settingsgeneralpage.ui
169+
)
170+
166171
# quaternion_en.ts is updated explicitly by building trbase target,
167172
# while all other translation files are created and updated externally at
168173
# Lokalise.co
@@ -178,6 +183,8 @@ set(quaternion_TS
178183
)
179184
QT5_ADD_TRANSLATION(quaternion_QM ${quaternion_TS})
180185

186+
qt5_wrap_ui(quaternion_UI_OUT ${quaternion_UI})
187+
181188
QT5_ADD_RESOURCES(quaternion_QRC_SRC ${quaternion_QRC})
182189
set_property(SOURCE qrc_resources.cpp PROPERTY SKIP_AUTOMOC ON)
183190

@@ -206,7 +213,7 @@ endif(APPLE)
206213

207214
# Windows, this is a GUI executable; OSX, make a bundle
208215
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
209-
${quaternion_SRCS} ${quaternion_QRC_SRC} ${quaternion_QM}
216+
${quaternion_SRCS} ${quaternion_UI_OUT} ${quaternion_QRC_SRC} ${quaternion_QM}
210217
${quaternion_WINRC} ${${PROJECT_NAME}_MAC_ICON})
211218

212219
target_link_libraries(${PROJECT_NAME}

client/mainwindow.cpp

+29-110
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "userlistdock.h"
2424
#include "chatroomwidget.h"
2525
#include "logindialog.h"
26+
#include "settingsdialog.h"
2627
#include "networkconfigdialog.h"
2728
#include "roomdialogs.h"
2829
#include "systemtrayicon.h"
@@ -168,6 +169,24 @@ void MainWindow::createMenu()
168169
{
169170
using QMatrixClient::Settings;
170171

172+
// Application menu
173+
auto applicationMenu = menuBar()->addMenu(tr("A&pplication"));
174+
applicationMenu->addAction(QIcon::fromTheme("preferences"), tr("&Preferences..."),
175+
this, [=]{ showSettingsWindow(); } );
176+
177+
applicationMenu->addAction(QIcon::fromTheme("preferences-system-network"),
178+
tr("Configure &network proxy..."), [this]
179+
{
180+
static QPointer<NetworkConfigDialog> dlg;
181+
summon(dlg, this);
182+
});
183+
184+
// Augment poor Windows users with a handy Ctrl-Q shortcut.
185+
static const auto quitShortcut = QSysInfo::productType() == "windows"
186+
? QKeySequence(Qt::CTRL + Qt::Key_Q) : QKeySequence::Quit;
187+
applicationMenu->addAction(QIcon::fromTheme("application-exit"),
188+
tr("&Quit"), qApp, &QApplication::quit, quitShortcut);
189+
171190
// Connection menu
172191
connectionMenu = menuBar()->addMenu(tr("&Accounts"));
173192

@@ -178,12 +197,6 @@ void MainWindow::createMenu()
178197
// Account submenus will be added in this place - see addConnection()
179198
accountListGrowthPoint = connectionMenu->addSeparator();
180199

181-
// Augment poor Windows users with a handy Ctrl-Q shortcut.
182-
static const auto quitShortcut = QSysInfo::productType() == "windows"
183-
? QKeySequence(Qt::CTRL + Qt::Key_Q) : QKeySequence::Quit;
184-
connectionMenu->addAction(QIcon::fromTheme("application-exit"),
185-
tr("&Quit"), qApp, &QApplication::quit, quitShortcut);
186-
187200
// View menu
188201
auto viewMenu = menuBar()->addMenu(tr("&View"));
189202

@@ -318,114 +331,10 @@ void MainWindow::createMenu()
318331
tr("&Close current room"), [this] { selectRoom(nullptr); },
319332
QKeySequence::Close);
320333

321-
// Settings menu
322-
auto settingsMenu = menuBar()->addMenu(tr("&Settings"));
323-
324334
// Help menu
325335
auto helpMenu = menuBar()->addMenu(tr("&Help"));
326336
helpMenu->addAction(QIcon::fromTheme("help-about"), tr("&About"),
327337
[=]{ showAboutWindow(); });
328-
329-
{
330-
auto notifGroup = new QActionGroup(this);
331-
connect(notifGroup, &QActionGroup::triggered, this,
332-
[] (QAction* notifAction)
333-
{
334-
notifAction->setChecked(true);
335-
Settings().setValue("UI/notifications",
336-
notifAction->data().toString());
337-
});
338-
339-
auto noNotif = notifGroup->addAction(tr("&Highlight only"));
340-
noNotif->setData(QStringLiteral("none"));
341-
noNotif->setStatusTip(tr("Notifications are entirely suppressed"));
342-
auto gentleNotif = notifGroup->addAction(tr("&Non-intrusive"));
343-
gentleNotif->setData(QStringLiteral("non-intrusive"));
344-
gentleNotif->setStatusTip(
345-
tr("Show notifications but do not activate the window"));
346-
auto fullNotif = notifGroup->addAction(tr("&Full"));
347-
fullNotif->setData(QStringLiteral("intrusive"));
348-
fullNotif->setStatusTip(
349-
tr("Show notifications and activate the window"));
350-
351-
auto notifMenu = settingsMenu->addMenu(
352-
QIcon::fromTheme("preferences-desktop-notification"),
353-
tr("Notifications"));
354-
for (auto a: {noNotif, gentleNotif, fullNotif})
355-
{
356-
a->setCheckable(true);
357-
notifMenu->addAction(a);
358-
}
359-
360-
const auto curSetting = Settings().value("UI/notifications",
361-
fullNotif->data().toString());
362-
if (curSetting == noNotif->data().toString())
363-
noNotif->setChecked(true);
364-
else if (curSetting == gentleNotif->data().toString())
365-
gentleNotif->setChecked(true);
366-
else
367-
fullNotif->setChecked(true);
368-
}
369-
{
370-
auto layoutGroup = new QActionGroup(this);
371-
connect(layoutGroup, &QActionGroup::triggered, this,
372-
[this] (QAction* action)
373-
{
374-
action->setChecked(true);
375-
Settings().setValue("UI/timeline_style", action->data().toString());
376-
chatRoomWidget->setRoom(nullptr);
377-
chatRoomWidget->setRoom(currentRoom);
378-
});
379-
380-
auto defaultLayout = layoutGroup->addAction(tr("Default"));
381-
defaultLayout->setStatusTip(
382-
tr("The layout with author labels above blocks of messages"));
383-
auto xchatLayout = layoutGroup->addAction("XChat");
384-
xchatLayout->setData(QStringLiteral("xchat"));
385-
xchatLayout->setStatusTip(
386-
tr("The layout with author labels to the left from each message"));
387-
388-
auto layoutMenu = settingsMenu->addMenu(QIcon::fromTheme("table"),
389-
tr("Timeline layout"));
390-
for (auto a: {defaultLayout, xchatLayout})
391-
{
392-
a->setCheckable(true);
393-
layoutMenu->addAction(a);
394-
}
395-
396-
const auto curSetting = Settings().value("UI/timeline_style",
397-
defaultLayout->data().toString());
398-
if (curSetting == xchatLayout->data().toString())
399-
xchatLayout->setChecked(true);
400-
else
401-
defaultLayout->setChecked(true);
402-
}
403-
addTimelineOptionCheckbox(
404-
settingsMenu,
405-
tr("Use shuttle scrollbar (requires restart)"),
406-
tr("Control scroll velocity instead of position with the timeline scrollbar"),
407-
QStringLiteral("use_shuttle_dial"), true
408-
);
409-
addTimelineOptionCheckbox(
410-
settingsMenu,
411-
tr("Load full-size images at once"),
412-
tr("Automatically download a full-size image instead of a thumbnail"),
413-
QStringLiteral("autoload_images"), true
414-
);
415-
addTimelineOptionCheckbox(
416-
settingsMenu,
417-
tr("Close to tray"),
418-
tr("Make close button [X] minimize to tray instead of closing main window"),
419-
QStringLiteral("close_to_tray"), false
420-
);
421-
422-
settingsMenu->addSeparator();
423-
settingsMenu->addAction(QIcon::fromTheme("preferences-system-network"),
424-
tr("Configure &network proxy..."), [this]
425-
{
426-
static QPointer<NetworkConfigDialog> dlg;
427-
summon(dlg, this);
428-
});
429338
}
430339

431340
void MainWindow::loadSettings()
@@ -888,6 +797,16 @@ void MainWindow::processLogin(LoginDialog& dialog)
888797
addConnection(connection, deviceName);
889798
}
890799

800+
void MainWindow::showSettingsWindow()
801+
{
802+
SettingsDialog settingsDialog(this);
803+
connect(&settingsDialog, &SettingsDialog::timelineChanged, this, [=]() {
804+
chatRoomWidget->setRoom(nullptr);
805+
chatRoomWidget->setRoom(currentRoom);
806+
});
807+
settingsDialog.exec();
808+
}
809+
891810
void MainWindow::showAboutWindow()
892811
{
893812
Dialog aboutDialog(tr("About Quaternion"), QDialogButtonBox::Close,

client/mainwindow.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class MainWindow: public QMainWindow
9191
void showLoginWindow(const QString& statusMessage = {});
9292
void showLoginWindow(const QString& statusMessage,
9393
QMatrixClient::AccountSettings& reloginAccount);
94+
void showSettingsWindow();
9495
void showAboutWindow();
9596
void logout(Connection* c);
9697

client/settingsdialog.cpp

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**************************************************************************
2+
* *
3+
* Copyright (C) 2019 Roland Pallai <[email protected]> *
4+
* *
5+
* This program is free software; you can redistribute it and/or *
6+
* modify it under the terms of the GNU General Public License *
7+
* as published by the Free Software Foundation; either version 3 *
8+
* of the License, or (at your option) any later version. *
9+
* *
10+
* This program is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the GNU General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
* *
18+
**************************************************************************/
19+
20+
#include "settingsdialog.h"
21+
#include "mainwindow.h"
22+
#include <settings.h>
23+
24+
#include <QTabWidget>
25+
#include <QVBoxLayout>
26+
#include <QDialog>
27+
28+
using QMatrixClient::SettingsGroup;
29+
30+
SettingsDialog::SettingsDialog(MainWindow *parent) : QDialog(parent) {
31+
setWindowTitle(tr("Settings"));
32+
33+
QVBoxLayout *layout = new QVBoxLayout(this);
34+
stack = new QTabWidget(this);
35+
stack->setTabBarAutoHide(true);
36+
layout->addWidget(stack);
37+
stack->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
38+
39+
auto generalPage = new GeneralPage(this);
40+
connect(generalPage, &GeneralPage::timelineChanged, this, [this] {
41+
emit timelineChanged();
42+
});
43+
addPage(generalPage, tr("&General"));
44+
}
45+
46+
SettingsDialog::~SettingsDialog() = default;
47+
48+
void SettingsDialog::addPage(ConfigurationWidgetInterface *page, const QString &title)
49+
{
50+
stack->addTab(page->asWidget(), title);
51+
pages << page;
52+
}
53+
54+
//
55+
// GeneralPage
56+
//
57+
GeneralPage::GeneralPage(SettingsDialog *parent):
58+
QScrollArea(parent), Ui_GeneralPage(), m_parent(parent)
59+
{
60+
Ui_GeneralPage::setupUi(this);
61+
62+
// closeToTray
63+
closeToTray->setChecked(SettingsGroup("UI").value("close_to_tray", false).toBool());
64+
connect(closeToTray, &QAbstractButton::toggled, this, [=](bool checked) {
65+
SettingsGroup("UI").setValue("close_to_tray", checked);
66+
});
67+
68+
// timeline_layout
69+
const auto curTimelineStyle = SettingsGroup("UI").value("timeline_style", "default");
70+
timeline_layout->addItem(tr("Default"), QVariant(QStringLiteral("default")));
71+
timeline_layout->addItem(tr("XChat"), QVariant(QStringLiteral("xchat")));
72+
if (curTimelineStyle == "xchat")
73+
timeline_layout->setCurrentText(tr("XChat"));
74+
75+
connect(timeline_layout, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
76+
auto new_layout = timeline_layout->itemData(index).toString();
77+
SettingsGroup("UI").setValue("timeline_style", new_layout);
78+
emit timelineChanged();
79+
});
80+
81+
// useShuttleScrollbar
82+
useShuttleScrollbar->setChecked(SettingsGroup("UI").value("use_shuttle_dial", true).toBool());
83+
connect(useShuttleScrollbar, &QAbstractButton::toggled, this, [=](bool checked) {
84+
SettingsGroup("UI").setValue("use_shuttle_dial", checked);
85+
// needs restart instead
86+
//emit timelineChanged();
87+
});
88+
89+
// loadFullSizeImages
90+
loadFullSizeImages->setChecked(SettingsGroup("UI").value("autoload_images", true).toBool());
91+
connect(loadFullSizeImages, &QAbstractButton::toggled, this, [=](bool checked) {
92+
SettingsGroup("UI").setValue("autoload_images", checked);
93+
emit timelineChanged();
94+
});
95+
96+
// *Notif
97+
const auto curNotifications = SettingsGroup("UI").value("notifications", "intrusive");
98+
if (curNotifications == "intrusive") {
99+
fullNotif->setChecked(true);
100+
} else if (curNotifications == "non-intrusive") {
101+
gentleNotif->setChecked(true);
102+
} else if (curNotifications == "none") {
103+
noNotif->setChecked(true);
104+
}
105+
106+
connect(noNotif, &QAbstractButton::clicked, this, [=]() {
107+
SettingsGroup("UI").setValue("notifications", "none");
108+
});
109+
connect(gentleNotif, &QAbstractButton::clicked, this, [=]() {
110+
SettingsGroup("UI").setValue("notifications", "non-intrusive");
111+
});
112+
connect(fullNotif, &QAbstractButton::clicked, this, [=]() {
113+
SettingsGroup("UI").setValue("notifications", "intrusive");
114+
});
115+
116+
groupBox->setMinimumWidth(groupBox->sizeHint().width());
117+
verticalFrame_3->setMinimumWidth(verticalFrame_3->sizeHint().width());
118+
scrollAreaWidgetContents->resize(scrollAreaWidgetContents->sizeHint());
119+
}
120+
121+
QWidget *GeneralPage::asWidget()
122+
{
123+
return this;
124+
}

0 commit comments

Comments
 (0)