Skip to content

Commit

Permalink
Turn settings menu into a dialog window
Browse files Browse the repository at this point in the history
Closes #553.
  • Loading branch information
rpallai committed Jul 1, 2019
1 parent 05c1819 commit edf3db8
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 111 deletions.
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(quaternion_SRCS
client/activitydetector.cpp
client/dialog.cpp
client/logindialog.cpp
client/settingsdialog.cpp
client/networkconfigdialog.cpp
client/roomdialogs.cpp
client/mainwindow.cpp
Expand All @@ -163,6 +164,10 @@ set(quaternion_QRC
client/resources.qrc
)

set(quaternion_UI
client/settingsgeneralpage.ui
)

# quaternion_en.ts is updated explicitly by building trbase target,
# while all other translation files are created and updated externally at
# Lokalise.co
Expand All @@ -178,6 +183,8 @@ set(quaternion_TS
)
QT5_ADD_TRANSLATION(quaternion_QM ${quaternion_TS})

qt5_wrap_ui(quaternion_UI_OUT ${quaternion_UI})

QT5_ADD_RESOURCES(quaternion_QRC_SRC ${quaternion_QRC})
set_property(SOURCE qrc_resources.cpp PROPERTY SKIP_AUTOMOC ON)

Expand Down Expand Up @@ -206,7 +213,7 @@ endif(APPLE)

# Windows, this is a GUI executable; OSX, make a bundle
add_executable(${PROJECT_NAME} WIN32 MACOSX_BUNDLE
${quaternion_SRCS} ${quaternion_QRC_SRC} ${quaternion_QM}
${quaternion_SRCS} ${quaternion_UI_OUT} ${quaternion_QRC_SRC} ${quaternion_QM}
${quaternion_WINRC} ${${PROJECT_NAME}_MAC_ICON})

target_link_libraries(${PROJECT_NAME}
Expand Down
139 changes: 29 additions & 110 deletions client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "userlistdock.h"
#include "chatroomwidget.h"
#include "logindialog.h"
#include "settingsdialog.h"
#include "networkconfigdialog.h"
#include "roomdialogs.h"
#include "systemtrayicon.h"
Expand Down Expand Up @@ -168,6 +169,24 @@ void MainWindow::createMenu()
{
using QMatrixClient::Settings;

// Application menu
auto applicationMenu = menuBar()->addMenu(tr("A&pplication"));
applicationMenu->addAction(QIcon::fromTheme("preferences"), tr("&Preferences..."),
this, [=]{ showSettingsWindow(); } );

applicationMenu->addAction(QIcon::fromTheme("preferences-system-network"),
tr("Configure &network proxy..."), [this]
{
static QPointer<NetworkConfigDialog> dlg;
summon(dlg, this);
});

// Augment poor Windows users with a handy Ctrl-Q shortcut.
static const auto quitShortcut = QSysInfo::productType() == "windows"
? QKeySequence(Qt::CTRL + Qt::Key_Q) : QKeySequence::Quit;
applicationMenu->addAction(QIcon::fromTheme("application-exit"),
tr("&Quit"), qApp, &QApplication::quit, quitShortcut);

// Connection menu
connectionMenu = menuBar()->addMenu(tr("&Accounts"));

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

// Augment poor Windows users with a handy Ctrl-Q shortcut.
static const auto quitShortcut = QSysInfo::productType() == "windows"
? QKeySequence(Qt::CTRL + Qt::Key_Q) : QKeySequence::Quit;
connectionMenu->addAction(QIcon::fromTheme("application-exit"),
tr("&Quit"), qApp, &QApplication::quit, quitShortcut);

// View menu
auto viewMenu = menuBar()->addMenu(tr("&View"));

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

// Settings menu
auto settingsMenu = menuBar()->addMenu(tr("&Settings"));

// Help menu
auto helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(QIcon::fromTheme("help-about"), tr("&About"),
[=]{ showAboutWindow(); });

{
auto notifGroup = new QActionGroup(this);
connect(notifGroup, &QActionGroup::triggered, this,
[] (QAction* notifAction)
{
notifAction->setChecked(true);
Settings().setValue("UI/notifications",
notifAction->data().toString());
});

auto noNotif = notifGroup->addAction(tr("&Highlight only"));
noNotif->setData(QStringLiteral("none"));
noNotif->setStatusTip(tr("Notifications are entirely suppressed"));
auto gentleNotif = notifGroup->addAction(tr("&Non-intrusive"));
gentleNotif->setData(QStringLiteral("non-intrusive"));
gentleNotif->setStatusTip(
tr("Show notifications but do not activate the window"));
auto fullNotif = notifGroup->addAction(tr("&Full"));
fullNotif->setData(QStringLiteral("intrusive"));
fullNotif->setStatusTip(
tr("Show notifications and activate the window"));

auto notifMenu = settingsMenu->addMenu(
QIcon::fromTheme("preferences-desktop-notification"),
tr("Notifications"));
for (auto a: {noNotif, gentleNotif, fullNotif})
{
a->setCheckable(true);
notifMenu->addAction(a);
}

const auto curSetting = Settings().value("UI/notifications",
fullNotif->data().toString());
if (curSetting == noNotif->data().toString())
noNotif->setChecked(true);
else if (curSetting == gentleNotif->data().toString())
gentleNotif->setChecked(true);
else
fullNotif->setChecked(true);
}
{
auto layoutGroup = new QActionGroup(this);
connect(layoutGroup, &QActionGroup::triggered, this,
[this] (QAction* action)
{
action->setChecked(true);
Settings().setValue("UI/timeline_style", action->data().toString());
chatRoomWidget->setRoom(nullptr);
chatRoomWidget->setRoom(currentRoom);
});

auto defaultLayout = layoutGroup->addAction(tr("Default"));
defaultLayout->setStatusTip(
tr("The layout with author labels above blocks of messages"));
auto xchatLayout = layoutGroup->addAction("XChat");
xchatLayout->setData(QStringLiteral("xchat"));
xchatLayout->setStatusTip(
tr("The layout with author labels to the left from each message"));

auto layoutMenu = settingsMenu->addMenu(QIcon::fromTheme("table"),
tr("Timeline layout"));
for (auto a: {defaultLayout, xchatLayout})
{
a->setCheckable(true);
layoutMenu->addAction(a);
}

const auto curSetting = Settings().value("UI/timeline_style",
defaultLayout->data().toString());
if (curSetting == xchatLayout->data().toString())
xchatLayout->setChecked(true);
else
defaultLayout->setChecked(true);
}
addTimelineOptionCheckbox(
settingsMenu,
tr("Use shuttle scrollbar (requires restart)"),
tr("Control scroll velocity instead of position with the timeline scrollbar"),
QStringLiteral("use_shuttle_dial"), true
);
addTimelineOptionCheckbox(
settingsMenu,
tr("Load full-size images at once"),
tr("Automatically download a full-size image instead of a thumbnail"),
QStringLiteral("autoload_images"), true
);
addTimelineOptionCheckbox(
settingsMenu,
tr("Close to tray"),
tr("Make close button [X] minimize to tray instead of closing main window"),
QStringLiteral("close_to_tray"), false
);

settingsMenu->addSeparator();
settingsMenu->addAction(QIcon::fromTheme("preferences-system-network"),
tr("Configure &network proxy..."), [this]
{
static QPointer<NetworkConfigDialog> dlg;
summon(dlg, this);
});
}

void MainWindow::loadSettings()
Expand Down Expand Up @@ -888,6 +797,16 @@ void MainWindow::processLogin(LoginDialog& dialog)
addConnection(connection, deviceName);
}

void MainWindow::showSettingsWindow()
{
SettingsDialog settingsDialog(this);
connect(&settingsDialog, &SettingsDialog::timelineChanged, this, [=]() {
chatRoomWidget->setRoom(nullptr);
chatRoomWidget->setRoom(currentRoom);
});
settingsDialog.exec();
}

void MainWindow::showAboutWindow()
{
Dialog aboutDialog(tr("About Quaternion"), QDialogButtonBox::Close,
Expand Down
1 change: 1 addition & 0 deletions client/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class MainWindow: public QMainWindow
void showLoginWindow(const QString& statusMessage = {});
void showLoginWindow(const QString& statusMessage,
QMatrixClient::AccountSettings& reloginAccount);
void showSettingsWindow();
void showAboutWindow();
void logout(Connection* c);

Expand Down
120 changes: 120 additions & 0 deletions client/settingsdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**************************************************************************
* *
* Copyright (C) 2019 Roland Pallai <[email protected]> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 3 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
**************************************************************************/

#include "settingsdialog.h"
#include "mainwindow.h"
#include <settings.h>

#include <QTabWidget>
#include <QVBoxLayout>
#include <QDialog>

using QMatrixClient::SettingsGroup;

SettingsDialog::SettingsDialog(MainWindow *parent) : QDialog(parent) {
setWindowTitle(tr("Settings"));

QVBoxLayout *layout = new QVBoxLayout(this);
stack = new QTabWidget(this);
stack->setTabBarAutoHide(true);
layout->addWidget(stack);
stack->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);

auto generalPage = new GeneralPage(this);
connect(generalPage, &GeneralPage::timelineChanged, this, [this] {
emit timelineChanged();
});
addPage(generalPage, tr("&General"));
}

SettingsDialog::~SettingsDialog() = default;

void SettingsDialog::addPage(ConfigurationWidgetInterface *page, const QString &title)
{
stack->addTab(page->asWidget(), title);
pages << page;
}

//
// GeneralPage
//
GeneralPage::GeneralPage(SettingsDialog *parent):
QWidget(parent), Ui_GeneralPage(), m_parent(parent)
{
Ui_GeneralPage::setupUi(this);

// closeToTray
closeToTray->setChecked(SettingsGroup("UI").value("close_to_tray", false).toBool());
connect(closeToTray, &QAbstractButton::toggled, this, [=](bool checked) {
SettingsGroup("UI").setValue("close_to_tray", checked);
});

// timeline_layout
const auto curTimelineStyle = SettingsGroup("UI").value("timeline_style", "default");
timeline_layout->addItem(tr("Default"), QVariant(QStringLiteral("default")));
timeline_layout->addItem(tr("XChat"), QVariant(QStringLiteral("xchat")));
if (curTimelineStyle == "xchat")
timeline_layout->setCurrentText(tr("XChat"));

connect(timeline_layout, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this](int index) {
auto new_layout = timeline_layout->itemData(index).toString();
SettingsGroup("UI").setValue("timeline_style", new_layout);
emit timelineChanged();
});

// useShuttleScrollbar
useShuttleScrollbar->setChecked(SettingsGroup("UI").value("use_shuttle_dial", true).toBool());
connect(useShuttleScrollbar, &QAbstractButton::toggled, this, [=](bool checked) {
SettingsGroup("UI").setValue("use_shuttle_dial", checked);
// needs restart instead
//emit timelineChanged();
});

// loadFullSizeImages
loadFullSizeImages->setChecked(SettingsGroup("UI").value("autoload_images", true).toBool());
connect(loadFullSizeImages, &QAbstractButton::toggled, this, [=](bool checked) {
SettingsGroup("UI").setValue("autoload_images", checked);
emit timelineChanged();
});

// *Notif
const auto curNotifications = SettingsGroup("UI").value("notifications", "intrusive");
if (curNotifications == "intrusive") {
fullNotif->setChecked(true);
} else if (curNotifications == "non-intrusive") {
gentleNotif->setChecked(true);
} else if (curNotifications == "none") {
noNotif->setChecked(true);
}

connect(noNotif, &QAbstractButton::clicked, this, [=]() {
SettingsGroup("UI").setValue("notifications", "none");
});
connect(gentleNotif, &QAbstractButton::clicked, this, [=]() {
SettingsGroup("UI").setValue("notifications", "non-intrusive");
});
connect(fullNotif, &QAbstractButton::clicked, this, [=]() {
SettingsGroup("UI").setValue("notifications", "intrusive");
});
}

QWidget *GeneralPage::asWidget()
{
return this;
}
Loading

0 comments on commit edf3db8

Please sign in to comment.