Added seperat WallpaperSettingsWidget Class

This commit is contained in:
delia 2025-08-23 17:52:22 +02:00
parent 07ff793a19
commit ed372e3d88
6 changed files with 95 additions and 59 deletions

3
.clangd Normal file
View File

@ -0,0 +1,3 @@
CompileFlags:
Remove: [-mono-direct-extern-access]
Add: [-std=c++20]

View File

@ -263,6 +263,8 @@ add_executable(
src/Qt/SingleInstanceManager.cpp src/Qt/SingleInstanceManager.cpp
src/Qt/WallpaperButton.h src/Qt/WallpaperButton.h
src/Qt/WallpaperButton.cpp src/Qt/WallpaperButton.cpp
src/Qt/WallpaperSettingsWidget.h
src/Qt/WallpaperSettingsWidget.cpp
src/External/MimeTypes/MimeTypes.cpp src/External/MimeTypes/MimeTypes.cpp
src/External/MimeTypes/MimeTypes.h src/External/MimeTypes/MimeTypes.h

View File

@ -3,10 +3,7 @@
#include "Qt/WallpaperButton.h" #include "Qt/WallpaperButton.h"
#include <QtConcurrent/qtconcurrentrun.h> #include <QtConcurrent/qtconcurrentrun.h>
#include <X11/X.h> #include <X11/X.h>
#include <algorithm>
#include <cstddef> #include <cstddef>
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <nlohmann/json_fwd.hpp> #include <nlohmann/json_fwd.hpp>
#include <qapplication.h> #include <qapplication.h>
@ -35,6 +32,7 @@
#include <vector> #include <vector>
#include <QToolButton> #include <QToolButton>
#include <QGroupBox> #include <QGroupBox>
#include "Qt/WallpaperSettingsWidget.h"
#include "WallpaperButton.h" #include "WallpaperButton.h"
#define PICTURE_SIZE 128 #define PICTURE_SIZE 128
@ -46,6 +44,8 @@ UIWindow::UIWindow(QWidget* parent, QApplication* qapp, SingleInstanceManager* i
this->wallpaperEngine = new QProcess(this); this->wallpaperEngine = new QProcess(this);
this->instanceGuard = ig; this->instanceGuard = ig;
this->buttonLayout = new QGridLayout(this); this->buttonLayout = new QGridLayout(this);
this->wallpaperSettingsWidget = nullptr;
} }
void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) { void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
@ -77,10 +77,10 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
startNewWallpaperEngine(); startNewWallpaperEngine();
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() { QObject::connect(wallpaperEngine, &QProcess::started, button, [this, button]() {
button->setEnabled(true); button->setEnabled(true);
updateSelectedButton(); updateSelectedButton();
updateConfigLayout(); this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
}); });
}); });
@ -122,7 +122,7 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
QObject::connect(this->screenSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) { QObject::connect(this->screenSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {
updateSelectedButton(); updateSelectedButton();
updateConfigLayout(); this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
}); });
auto* screenSelectorLayout = new QVBoxLayout(); auto* screenSelectorLayout = new QVBoxLayout();
@ -154,19 +154,10 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
leftWidget->setLayout(leftLayout); leftWidget->setLayout(leftLayout);
// right side // right side
auto* rightWidget = new QWidget(splitWidget); this->wallpaperSettingsWidget = new WallpaperSettingsWidget(splitWidget);
auto* rightLayout = new QVBoxLayout(rightWidget);
this->previewTitleLabel = new QLabel("...", rightWidget);
this->previewTitleLabel->setAlignment(Qt::AlignTop);
this->previewImageLabel = new QLabel(rightWidget);
this->previewImageLabel->setFixedSize(256, 256);
this->previewImageLabel->setAlignment(Qt::AlignCenter);
rightLayout->addWidget(previewImageLabel);
rightLayout->addWidget(previewTitleLabel);
rightWidget->setLayout(rightLayout);
splitLayout->addWidget(leftWidget, 2); splitLayout->addWidget(leftWidget, 2);
splitLayout->addWidget(rightWidget, 1); splitLayout->addWidget(this->wallpaperSettingsWidget, 1);
mainlayout->addWidget(splitWidget); mainlayout->addWidget(splitWidget);
mainlayout->addWidget(extraFlagsInput); mainlayout->addWidget(extraFlagsInput);
@ -236,43 +227,6 @@ void UIWindow::startNewWallpaperEngine() {
wallpaperEngine->start(QCoreApplication::applicationFilePath(), args); wallpaperEngine->start(QCoreApplication::applicationFilePath(), args);
} }
void UIWindow::updateConfigLayout() {
std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()];
if (selected.empty()) return;
std::ifstream file(selected + "/project.json");
nlohmann::json wallpaperJSON = nlohmann::json::parse(file);
if (wallpaperJSON.empty()) {
return;
}
std::string title = wallpaperJSON.at("title");
if (title.size() > 25) {
title = title.substr(0, 24) + "..";
}
QPixmap pixmap(QString::fromStdString(selected + "/preview.jpg"));
if (pixmap.isNull()) {
pixmap = QPixmap(256, 256);
pixmap.fill(Qt::black);
auto* movie = new QMovie(QString::fromStdString(selected + "/preview.gif"));
if (movie->isValid()) {
movie->jumpToFrame(0);
pixmap = movie->currentPixmap().scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
delete movie;
} else pixmap = pixmap.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// edit previewLabel
this->previewImageLabel->setPixmap(pixmap);
// edit Title
this->previewTitleLabel->setText(QString::fromStdString(title));
}
void UIWindow::updateSelectedButton() { void UIWindow::updateSelectedButton() {
for (int i = 0; i < this->buttonLayout->rowCount(); i++) { for (int i = 0; i < this->buttonLayout->rowCount(); i++) {
for (int j = 0; j < this->buttonLayout->columnCount(); j++) { for (int j = 0; j < this->buttonLayout->columnCount(); j++) {

View File

@ -29,9 +29,9 @@
#include <QtConcurrent/QtConcurrent> #include <QtConcurrent/QtConcurrent>
#include <string> #include <string>
#include <vector> #include <vector>
#include <bits/stdc++.h>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <iostream> #include <iostream>
#include "Qt/WallpaperSettingsWidget.h"
class UIWindow : public QWidget { class UIWindow : public QWidget {
Q_OBJECT Q_OBJECT
@ -47,8 +47,7 @@ class UIWindow : public QWidget {
QComboBox* screenSelector; QComboBox* screenSelector;
QLineEdit* extraFlagsInput; QLineEdit* extraFlagsInput;
QGridLayout* buttonLayout; QGridLayout* buttonLayout;
QLabel* previewImageLabel; WallpaperSettingsWidget* wallpaperSettingsWidget;
QLabel* previewTitleLabel;
// Important Fields // Important Fields
std::map<std::string, std::string> selectedWallpapers; std::map<std::string, std::string> selectedWallpapers;
@ -57,7 +56,6 @@ class UIWindow : public QWidget {
void startNewWallpaperEngine(); void startNewWallpaperEngine();
void updateSelectedButton(); void updateSelectedButton();
void updateConfigLayout();
static std::vector<std::string> split(const std::string &str, char r); static std::vector<std::string> split(const std::string &str, char r);
protected: protected:

View File

@ -0,0 +1,56 @@
#include "WallpaperSettingsWidget.h"
#include <fstream>
#include <qmovie.h>
#include <qwidget.h>
#include <string>
#include <nlohmann/json.hpp>
WallpaperSettingsWidget::WallpaperSettingsWidget(QWidget* parent)
: QWidget(parent) {
preview.title = new QLabel("...", this);
preview.title->setAlignment(Qt::AlignTop);
preview.image = new QLabel(this);
preview.image->setFixedSize(256, 256);
preview.image->setAlignment(Qt::AlignCenter);
layout->addWidget(preview.image);
layout->addWidget(preview.title);
setLayout(layout);
}
void WallpaperSettingsWidget::update(const std::string& selected) {
if (selected.empty()) return;
std::ifstream file(selected + "/project.json");
nlohmann::json wallpaperJSON = nlohmann::json::parse(file);
if (wallpaperJSON.empty()) {
return;
}
std::string title = wallpaperJSON.at("title");
if (title.size() > 25) {
title = title.substr(0, 24) + "..";
}
QPixmap pixmap(QString::fromStdString(selected + "/preview.jpg"));
if (pixmap.isNull()) {
pixmap = QPixmap(256, 256);
pixmap.fill(Qt::black);
auto* movie = new QMovie(QString::fromStdString(selected + "/preview.gif"));
if (movie->isValid()) {
movie->jumpToFrame(0);
pixmap = movie->currentPixmap().scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
delete movie;
} else pixmap = pixmap.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// edit previewLabel
preview.image->setPixmap(pixmap);
// edit Title
preview.title->setText(QString::fromStdString(title));
}

View File

@ -0,0 +1,23 @@
#pragma once
#include <QWidget>
#include <qboxlayout.h>
#include <qlabel.h>
#include <qwidget.h>
struct Preview {
QLabel* image;
QLabel* title;
};
class WallpaperSettingsWidget : public QWidget {
public:
explicit WallpaperSettingsWidget(QWidget* parent = nullptr);
void update(const std::string& currentWallpaperPath);
private:
QVBoxLayout* layout = new QVBoxLayout(this);
Preview preview = {nullptr, nullptr};
protected:
};