diff --git a/src/Qt/UIWindow.cpp b/src/Qt/UIWindow.cpp index 2ecfe5d..499249a 100644 --- a/src/Qt/UIWindow.cpp +++ b/src/Qt/UIWindow.cpp @@ -1,9 +1,11 @@ #include "UIWindow.h" #include "Qt/SingleInstanceManager.h" +#include #include "Qt/WallpaperButton.h" #include #include #include +#include #include #include #include @@ -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 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 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 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::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 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(widget); if (!button) continue; + button->setEnabled(true); + std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()]; QString currentStyle = button->styleSheet(); QString newStyle = currentStyle; diff --git a/src/Qt/UIWindow.h b/src/Qt/UIWindow.h index 57a242a..8a966c3 100644 --- a/src/Qt/UIWindow.h +++ b/src/Qt/UIWindow.h @@ -30,7 +30,6 @@ #include #include #include -#include #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; diff --git a/src/Qt/WallpaperSettingsWidget.cpp b/src/Qt/WallpaperSettingsWidget.cpp index c68317e..cea8040 100644 --- a/src/Qt/WallpaperSettingsWidget.cpp +++ b/src/Qt/WallpaperSettingsWidget.cpp @@ -1,21 +1,56 @@ #include "WallpaperSettingsWidget.h" #include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include #include #include #include +#include +#include +#include +#include +#include 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(opt.widget)) { + if (std::holds_alternative(opt.defaultValue)) { + cb->setChecked(std::get(opt.defaultValue)); + } + continue; + } + if (auto* slider = dynamic_cast(opt.widget)) { + if (std::holds_alternative(opt.defaultValue)) { + slider->setValue(std::get(opt.defaultValue)); + } + continue; + } + if (auto* lineEdit = dynamic_cast(opt.widget)) { + if (std::holds_alternative(opt.defaultValue)) { + lineEdit->setText(QString::fromStdString(std::to_string(std::get(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(opt.widget)) { + if (cb->isChecked()) { + flags.append(opt.flag + " "); + if (opt.flagHasValue) flags.append("true "); + } + continue; + } + if (auto* slider = dynamic_cast(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(opt.widget)) { + std::string value = lineEdit->text().toStdString(); + flags.append(opt.flag + " "); + if (opt.flagHasValue) flags.append(value + " "); + continue; + } + } + emit applySettings(flags); } diff --git a/src/Qt/WallpaperSettingsWidget.h b/src/Qt/WallpaperSettingsWidget.h index 0edfaba..8571692 100644 --- a/src/Qt/WallpaperSettingsWidget.h +++ b/src/Qt/WallpaperSettingsWidget.h @@ -1,23 +1,68 @@ #pragma once #include +#include +#include #include +#include #include +#include #include +#include +#include +#include + +class UIWindow; struct Preview { QLabel* image; QLabel* title; }; +struct Option { + QWidget* widget; + QString labelName; + std::string optionName; + std::string flag; + bool flagHasValue; + + std::variant 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