Added basic settings

This commit is contained in:
delia 2025-08-26 03:01:56 +02:00
parent edae0178c8
commit f078765987
4 changed files with 203 additions and 25 deletions

View File

@ -1,9 +1,11 @@
#include "UIWindow.h"
#include "Qt/SingleInstanceManager.h"
#include <QListView>
#include "Qt/WallpaperButton.h"
#include <QtConcurrent/qtconcurrentrun.h>
#include <X11/X.h>
#include <cstddef>
#include <iostream>
#include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp>
#include <qapplication.h>
@ -40,7 +42,6 @@
UIWindow::UIWindow(QWidget* parent, QApplication* qapp, SingleInstanceManager* ig) {
this->qapp = qapp;
this->screenSelector = new QComboBox(this);
this->extraFlagsInput = new QLineEdit(this);
this->wallpaperEngine = new QProcess(this);
this->instanceGuard = ig;
this->buttonLayout = new QGridLayout(this);
@ -50,16 +51,18 @@ UIWindow::UIWindow(QWidget* parent, QApplication* qapp, SingleInstanceManager* i
void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
this->setWindowTitle("Wallpapers :3");
this->setStyleSheet(R"(
QWidget {
background-color: #2B2A33;
color: white;
}
)");
this->setAttribute(Qt::WA_StyledBackground, true);
// palette
auto* pal = new QPalette();
pal->setColor(QPalette::Window, QColor(0x2B, 0x2A, 0x33, 0xFF));
this->setAutoFillBackground(true);
this->setPalette(*pal);
auto* scrollArea = new QScrollArea(this);
scrollArea->setWidgetResizable(true);
scrollArea->setPalette(*pal);
auto* container = new QWidget();
@ -73,22 +76,20 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
button->setEnabled(false);
this->selectedWallpapers[this->screenSelector->currentText().toStdString()] = clickedPath.toStdString();
this->extraFlags[this->screenSelector->currentText().toStdString()] = split(this->extraFlagsInput->text().toStdString(), ' ');
startNewWallpaperEngine();
QObject::connect(wallpaperEngine, &QProcess::started, button, [this, button]() {
button->setEnabled(true);
updateSelectedButton();
this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
});
updateSelectedButton();
this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
});
int row = i / cols;
int col = i % cols;
buttonLayout->addWidget(button, row, col);
}
QObject::connect(wallpaperEngine, &QProcess::started, this, [this]() {
updateSelectedButton();
});
QObject::connect(this->qapp, &QCoreApplication::aboutToQuit, this, [this]() {
wallpaperEngine->terminate();
wallpaperEngine->waitForFinished(3000);
@ -114,20 +115,24 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
this->screenSelector->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->screenSelector->setFixedHeight(48);
auto font = screenSelector->font();
font.setPointSize(18);
this->screenSelector->setFont(font);
this->screenSelector->setView(new QListView());
this->screenSelector->view()->setStyleSheet(
"QListView { background-color:#2B2A33; selection-background-color:#4488FF; color:white; }"
"QListView::item:hover { background-color:#4488FF; }"
);
this->screenSelector->setStyleSheet(
"font-size: 24px;"
);
this->screenSelector->setPalette(*pal);
QObject::connect(this->screenSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
updateSelectedButton();
this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
});
auto* screenSelectorLayout = new QVBoxLayout();
auto* screenSelectorLayout = new QVBoxLayout(this);
auto* label = new QLabel("Screen Selector:");
label->setFont(font);
screenSelectorLayout->addWidget(label);
screenSelectorLayout->addWidget(screenSelector);
@ -155,12 +160,16 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
// right side
this->wallpaperSettingsWidget = new WallpaperSettingsWidget(splitWidget);
connect(this->wallpaperSettingsWidget, &WallpaperSettingsWidget::applySettings, this, [this](const std::string& flags) {
this->extraFlags[this->screenSelector->currentText().toStdString()] = split(flags, ' ');
startNewWallpaperEngine();
});
splitLayout->addWidget(leftWidget, 2);
splitLayout->addWidget(this->wallpaperSettingsWidget, 1);
mainlayout->addWidget(splitWidget);
mainlayout->addWidget(extraFlagsInput);
this->setLayout(mainlayout);
// update Buttons
@ -239,6 +248,8 @@ void UIWindow::updateSelectedButton() {
auto* button = dynamic_cast<WallpaperButton*>(widget);
if (!button) continue;
button->setEnabled(true);
std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()];
QString currentStyle = button->styleSheet();
QString newStyle = currentStyle;

View File

@ -30,7 +30,6 @@
#include <string>
#include <vector>
#include <QVBoxLayout>
#include <iostream>
#include "Qt/WallpaperSettingsWidget.h"
class UIWindow : public QWidget {
@ -45,7 +44,6 @@ class UIWindow : public QWidget {
QApplication* qapp;
SingleInstanceManager* instanceGuard;
QComboBox* screenSelector;
QLineEdit* extraFlagsInput;
QGridLayout* buttonLayout;
WallpaperSettingsWidget* wallpaperSettingsWidget;

View File

@ -1,21 +1,56 @@
#include "WallpaperSettingsWidget.h"
#include <fstream>
#include <nlohmann/json_fwd.hpp>
#include <qchar.h>
#include <qcheckbox.h>
#include <qformlayout.h>
#include <qgroupbox.h>
#include <qlineedit.h>
#include <qmovie.h>
#include <qnamespace.h>
#include <qobjectdefs.h>
#include <qpushbutton.h>
#include <qslider.h>
#include <qwidget.h>
#include <string>
#include <nlohmann/json.hpp>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <variant>
#include <iostream>
WallpaperSettingsWidget::WallpaperSettingsWidget(QWidget* parent)
: QWidget(parent) {
layout->setSpacing(5);
preview.title = new QLabel("...", this);
preview.title->setAlignment(Qt::AlignTop);
preview.title->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
preview.image = new QLabel(this);
preview.image->setFixedSize(256, 256);
preview.image->setAlignment(Qt::AlignCenter);
auto* settingsBox = new QGroupBox("Settings:", this);
settingsBox->setStyleSheet(
"font-size: 16px; "
"color: white; "
"background: transparent; "
);
this->settingsLayout = new QFormLayout(settingsBox);
settingsBox->setAlignment(Qt::AlignTop);
settingsBox->setLayout(this->settingsLayout);
auto* applyButton = new QPushButton("Apply", this);
connect(applyButton, &QPushButton::clicked, this, [applyButton, this]() {
this->apply();
});
layout->addWidget(preview.image);
layout->addWidget(preview.title);
layout->addWidget(settingsBox);
layout->addWidget(applyButton);
setLayout(layout);
}
@ -23,6 +58,8 @@ WallpaperSettingsWidget::WallpaperSettingsWidget(QWidget* parent)
void WallpaperSettingsWidget::update(const std::string& selected) {
if (selected.empty()) return;
this->currentWallpaperPath = selected;
std::ifstream file(selected + "/project.json");
nlohmann::json wallpaperJSON = nlohmann::json::parse(file);
@ -53,4 +90,91 @@ void WallpaperSettingsWidget::update(const std::string& selected) {
preview.image->setPixmap(pixmap);
// edit Title
preview.title->setText(QString::fromStdString(title));
updateSettings(selected, wallpaperJSON);
}
QCheckBox* createStyledCheckBox(const QString& style) {
auto* cb = new QCheckBox();
cb->setStyleSheet(style);
return cb;
}
void WallpaperSettingsWidget::updateSettings(const std::string& wallpaperPath, const nlohmann::json& wallpaper) {
clearSettings();
// TODO: add individual settings depending on wallpaper
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Mute Audio:", "mute_audio", "--silent", false, false});
this->currentOptions.push_back({new QSlider(Qt::Horizontal), "Volume:", "volume", "--volume", true, 50});
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Disable Automute:", "disable_automute", "--noautomute", false, false});
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Disable Audio Reaction:", "disable_audio_reaction", "--no-audio-processing", false, false});
this->currentOptions.push_back({new QLineEdit(), "FPS:", "fps", "--fps", true, 30});
this->currentOptions.push_back({new QComboBox(), "Scaling:", "scaling", "--scaling", true});
this->currentOptions.push_back({new QComboBox(), "Clamping:", "clamping", "--clamping", true});
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Disable Mouse:", "diable_mouse", "--disable-mouse", false, false});
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Disable Parallax", "disable_parallax", "--disable-parallax", false, true});
this->currentOptions.push_back({createStyledCheckBox(this->checkboxStyleSheet), "Disable Fullscreen Pause:", "disable_fullscreen_pause", "--no-fullscreen-pause", true, false});
for (const Option& opt : this->currentOptions) {
this->settingsLayout->addRow(opt.labelName, opt.widget);
if (auto* cb = dynamic_cast<QCheckBox*>(opt.widget)) {
if (std::holds_alternative<bool>(opt.defaultValue)) {
cb->setChecked(std::get<bool>(opt.defaultValue));
}
continue;
}
if (auto* slider = dynamic_cast<QSlider*>(opt.widget)) {
if (std::holds_alternative<int>(opt.defaultValue)) {
slider->setValue(std::get<int>(opt.defaultValue));
}
continue;
}
if (auto* lineEdit = dynamic_cast<QLineEdit*>(opt.widget)) {
if (std::holds_alternative<int>(opt.defaultValue)) {
lineEdit->setText(QString::fromStdString(std::to_string(std::get<int>(opt.defaultValue))));
}
continue;
}
}
}
void WallpaperSettingsWidget::clearSettings() {
QLayoutItem* item;
while ((this->settingsLayout->count() != 0) && (item = this->settingsLayout->takeAt(0)) != nullptr) {
if (item->widget()) {
delete item->widget();
}
delete item;
}
this->currentOptions.clear();
}
void WallpaperSettingsWidget::apply() {
if (currentWallpaperPath.empty()) return;
std::string flags;
for (const Option& opt : this->currentOptions) {
if (auto* cb = dynamic_cast<QCheckBox*>(opt.widget)) {
if (cb->isChecked()) {
flags.append(opt.flag + " ");
if (opt.flagHasValue) flags.append("true ");
}
continue;
}
if (auto* slider = dynamic_cast<QSlider*>(opt.widget)) {
int value = slider->value();
flags.append(opt.flag + " ");
if (opt.flagHasValue) flags.append(std::to_string(value) + " ");
continue;
}
if (auto* lineEdit = dynamic_cast<QLineEdit*>(opt.widget)) {
std::string value = lineEdit->text().toStdString();
flags.append(opt.flag + " ");
if (opt.flagHasValue) flags.append(value + " ");
continue;
}
}
emit applySettings(flags);
}

View File

@ -1,23 +1,68 @@
#pragma once
#include <QWidget>
#include <QString>
#include <nlohmann/json.hpp>
#include <qboxlayout.h>
#include <qchar.h>
#include <qlabel.h>
#include <qobjectdefs.h>
#include <qwidget.h>
#include <QFormLayout>
#include <variant>
#include <vector>
class UIWindow;
struct Preview {
QLabel* image;
QLabel* title;
};
struct Option {
QWidget* widget;
QString labelName;
std::string optionName;
std::string flag;
bool flagHasValue;
std::variant<bool, int, float, QString> defaultValue;
};
class WallpaperSettingsWidget : public QWidget {
Q_OBJECT
public:
explicit WallpaperSettingsWidget(QWidget* parent = nullptr);
void update(const std::string& currentWallpaperPath);
private:
QVBoxLayout* layout = new QVBoxLayout(this);
QFormLayout* settingsLayout = nullptr;
Preview preview = {nullptr, nullptr};
std::vector<Option> currentOptions;
std::string currentWallpaperPath;
void updateSettings(const std::string& wallpaperPath, const nlohmann::json& wallpaper);
void clearSettings();
void apply();
QString checkboxStyleSheet =
"QCheckBox {"
" color: white;"
"}"
"QCheckBox::indicator {"
" width: 16px;"
" height: 16px;"
" background-color: white;"
" border: 1px solid gray;"
"}"
"QCheckBox::indicator:checked {"
" background-color: #4CAF50;"
"}";
signals:
void applySettings(const std::string& flags);
protected:
};