add settings page

Does nothing yet
This commit is contained in:
Jussi Kuokkanen 2023-09-11 21:35:38 +03:00
parent bbc2e21a51
commit 6ac81e1f13
7 changed files with 129 additions and 5 deletions

View File

@ -13,7 +13,8 @@ moc_files = qt5.preprocess(moc_headers: ['MainWindow.hpp',
'data/DynamicReadableProxy.hpp', 'data/DynamicReadableProxy.hpp',
'widgets/AbstractAssignableEditor.hpp', 'widgets/AbstractAssignableEditor.hpp',
'widgets/DragChartView.hpp', 'widgets/DragChartView.hpp',
'widgets/FunctionEditor.hpp'], 'widgets/FunctionEditor.hpp',
'widgets/Settings.hpp'],
qresources : ['resources/resources.qrc'], qresources : ['resources/resources.qrc'],
dependencies: qt5_dep) dependencies: qt5_dep)
@ -29,6 +30,7 @@ sources = ['main.cpp',
'widgets/DragChartView.cpp', 'widgets/DragChartView.cpp',
'widgets/EnumEditor.cpp', 'widgets/EnumEditor.cpp',
'widgets/FlagEditor.cpp', 'widgets/FlagEditor.cpp',
'widgets/Settings.cpp',
'MainWindow.cpp', 'MainWindow.cpp',
'Utils.cpp'] 'Utils.cpp']

View File

@ -1,5 +1,6 @@
<RCC> <RCC>
<qresource prefix="/"> <qresource prefix="/">
<file>ruler.svg</file> <file>ruler.svg</file>
<file>settings.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="1.88 1.88 11.22 11.22"><g clip-rule="evenodd" fill="#151515" fill-rule="evenodd"><path d="m10 7.50001c0 1.38072-1.11928 2.49999-2.49999 2.49999s-2.5-1.11927-2.5-2.49999c0-1.38071 1.11929-2.5 2.5-2.5s2.49999 1.11929 2.49999 2.5zm-.99999 0c0 .82843-.67157 1.5-1.5 1.5-.82842 0-1.5-.67157-1.5-1.5 0-.82842.67158-1.5 1.5-1.5.82843 0 1.5.67158 1.5 1.5z"/><path d="m8.92908 3.05724c-.34403-1.52302-2.5141-1.52302-2.85813 0-.07078.31333-.43034.46227-.70195.29076-1.3202-.83367-2.85467.7008-2.021 2.021.17151.27161.02257.63117-.29076.70195-1.52302.34403-1.52302 2.5141 0 2.85813.31333.07077.46227.43034.29076.70195-.83367 1.32017.7008 2.85467 2.021 2.02097.27161-.1715.63117-.0225.70195.2908.34403 1.523 2.5141 1.523 2.85813 0 .07077-.3133.43034-.4623.70195-.2908 1.32017.8337 2.85467-.7008 2.02097-2.02097-.1715-.27161-.0225-.63118.2908-.70195 1.523-.34403 1.523-2.5141 0-2.85813-.3133-.07078-.4623-.43034-.2908-.70195.8337-1.3202-.7008-2.85467-2.02097-2.021-.27161.17151-.63118.02257-.70195-.29076zm-1.8827.22034c.1092-.48347.79806-.48347.90727 0 .22296.98707 1.35568 1.45625 2.21135.91595.419-.26464.9061.22246.6415.64154-.5403.85562-.0711 1.98834.916 2.21131.4834.1092.4834.79806 0 .90727-.9871.22296-1.4563 1.35568-.916 2.21135.2646.419-.2225.9061-.6415.6415-.85567-.5403-1.98839-.0711-2.21135.916-.10921.4834-.79807.4834-.90727 0-.22297-.9871-1.35569-1.4563-2.21131-.916-.41908.2646-.90618-.2225-.64154-.6415.5403-.85567.07112-1.98839-.91595-2.21135-.48347-.10921-.48347-.79807 0-.90727.98707-.22297 1.45625-1.35569.91595-2.21131-.26464-.41908.22246-.90618.64154-.64154.85562.5403 1.98834.07112 2.21131-.91595z"/></g></svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -2,8 +2,12 @@
#include "AssignableItemData.hpp" #include "AssignableItemData.hpp"
#include "qnamespace.h" #include "qnamespace.h"
#include <Globals.hpp>
#include <patterns.hpp> #include <patterns.hpp>
#include <QStackedWidget>
#include <QToolButton>
#include <QVariant> #include <QVariant>
#include <Settings.hpp>
using namespace mpark::patterns; using namespace mpark::patterns;
using namespace TuxClocker::Device; using namespace TuxClocker::Device;
@ -41,10 +45,29 @@ DeviceBrowser::DeviceBrowser(DeviceModel &model, QWidget *parent)
m_flagEditor->flagsChanged.connect([=](auto flags) { m_proxyModel->setFlags(flags); }); m_flagEditor->flagsChanged.connect([=](auto flags) { m_proxyModel->setFlags(flags); });
m_layout->addWidget(m_flagLabel, 0, 0); m_settings = nullptr;
m_layout->addWidget(m_flagEditor, 0, 1);
m_layout->addWidget(m_treeView, 1, 0, 1, 2); auto icon = QIcon{":/settings.svg"};
m_layout->addWidget(m_apply, 2, 0, 1, 2); auto toolButton = new QToolButton{this};
toolButton->setIcon(icon);
connect(toolButton, &QToolButton::released, [=] {
if (!m_settings) {
m_settings = new Settings{this};
Globals::g_mainStack->addWidget(m_settings);
connect(m_settings, &Settings::cancelled,
[=] { Globals::g_mainStack->setCurrentWidget(this); });
}
Globals::g_mainStack->setCurrentWidget(m_settings);
});
m_layout->addWidget(toolButton, 0, 0);
m_layout->addWidget(m_flagLabel, 0, 1, 1, 1, Qt::AlignRight);
m_layout->addWidget(m_flagEditor, 0, 2);
m_layout->addWidget(m_treeView, 1, 0, 1, 3);
m_layout->addWidget(m_apply, 2, 0, 1, 3);
setLayout(m_layout); setLayout(m_layout);
} }

View File

@ -11,6 +11,8 @@
#include <QPushButton> #include <QPushButton>
#include <QWidget> #include <QWidget>
class Settings;
// Class for viewing/editing the main tuxclocker tree // Class for viewing/editing the main tuxclocker tree
class DeviceBrowser : public QWidget { class DeviceBrowser : public QWidget {
public: public:
@ -23,4 +25,5 @@ private:
QLabel *m_flagLabel; QLabel *m_flagLabel;
QPushButton *m_apply; QPushButton *m_apply;
QGridLayout *m_layout; QGridLayout *m_layout;
Settings *m_settings;
}; };

View File

@ -0,0 +1,68 @@
#include "Settings.hpp"
#include <QCheckBox>
#include <QGridLayout>
#include <QLabel>
#include <QListWidget>
#include <QPushButton>
Settings::Settings(QWidget *parent) : QWidget(parent) {
auto layout = new QGridLayout{this};
auto label = new QLabel{this};
// Bigger and bolder text
QFont biggerPoint{};
biggerPoint.setBold(true);
biggerPoint.setPointSize(biggerPoint.pointSize() + 4);
label->setTextFormat(Qt::RichText);
label->setFont(biggerPoint);
label->setText("Settings");
auto autoLoadCheck = new QCheckBox{"Apply profile settings automatically", this};
auto profileCheck = new QCheckBox{"Use profile", this};
// TODO: add delegate to make deleting a little nicer
auto profileView = new QListWidget{this};
auto triggers = QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed;
profileView->setEditTriggers(triggers);
profileView->setEnabled(false);
auto addButton = new QPushButton{"Add profile"};
addButton->setEnabled(false);
auto removeButton = new QPushButton{"Remove selected"};
connect(addButton, &QPushButton::released, [=] {
auto item = new QListWidgetItem{"Unnamed"};
item->setFlags(item->flags() | Qt::ItemIsEditable);
profileView->addItem(item);
});
connect(removeButton, &QPushButton::released,
[=] { profileView->model()->removeRow(profileView->currentRow()); });
connect(profileCheck, &QCheckBox::stateChanged, [=](auto state) {
bool enable = (state == Qt::Unchecked) ? false : true;
addButton->setEnabled(enable);
profileView->setEnabled(enable);
});
auto cancelButton = new QPushButton{"Cancel", this};
connect(cancelButton, &QPushButton::released, this, &Settings::cancelled);
auto saveButton = new QPushButton{"Save", this};
layout->addWidget(label, 0, 0, 1, 1, Qt::AlignLeft | Qt::AlignTop);
layout->addWidget(autoLoadCheck, 1, 0, 1, 1, Qt::AlignLeft);
layout->addWidget(profileCheck, 2, 0, 1, 1, Qt::AlignLeft);
layout->addWidget(profileView, 2, 1, 1, 2);
layout->addWidget(addButton, 3, 1);
layout->addWidget(removeButton, 3, 2);
layout->addWidget(cancelButton, 4, 0, 1, 1, Qt::AlignBottom);
layout->addWidget(saveButton, 4, 1, 1, 2, Qt::AlignBottom);
this->setLayout(layout);
}

View File

@ -0,0 +1,26 @@
#pragma once
#include <optional>
#include <QVariant>
#include <QWidget>
// TODO: duplicate definition
struct AssignableSetting {
QString assignablePath;
QVariant value;
};
struct SettingsData {
bool autoApplyProfile;
std::optional<QString> currentProfile;
QVector<AssignableSetting> assignableSettings;
};
class Settings : public QWidget {
public:
explicit Settings(QWidget *parent = nullptr);
signals:
void cancelled();
private:
Q_OBJECT
};