mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Added seperat WallpaperSettingsWidget Class
This commit is contained in:
parent
07ff793a19
commit
ed372e3d88
3
.clangd
Normal file
3
.clangd
Normal file
@ -0,0 +1,3 @@
|
||||
CompileFlags:
|
||||
Remove: [-mono-direct-extern-access]
|
||||
Add: [-std=c++20]
|
@ -263,6 +263,8 @@ add_executable(
|
||||
src/Qt/SingleInstanceManager.cpp
|
||||
src/Qt/WallpaperButton.h
|
||||
src/Qt/WallpaperButton.cpp
|
||||
src/Qt/WallpaperSettingsWidget.h
|
||||
src/Qt/WallpaperSettingsWidget.cpp
|
||||
|
||||
src/External/MimeTypes/MimeTypes.cpp
|
||||
src/External/MimeTypes/MimeTypes.h
|
||||
|
@ -3,10 +3,7 @@
|
||||
#include "Qt/WallpaperButton.h"
|
||||
#include <QtConcurrent/qtconcurrentrun.h>
|
||||
#include <X11/X.h>
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#include <qapplication.h>
|
||||
@ -35,6 +32,7 @@
|
||||
#include <vector>
|
||||
#include <QToolButton>
|
||||
#include <QGroupBox>
|
||||
#include "Qt/WallpaperSettingsWidget.h"
|
||||
#include "WallpaperButton.h"
|
||||
|
||||
#define PICTURE_SIZE 128
|
||||
@ -46,6 +44,8 @@ UIWindow::UIWindow(QWidget* parent, QApplication* qapp, SingleInstanceManager* i
|
||||
this->wallpaperEngine = new QProcess(this);
|
||||
this->instanceGuard = ig;
|
||||
this->buttonLayout = new QGridLayout(this);
|
||||
|
||||
this->wallpaperSettingsWidget = nullptr;
|
||||
}
|
||||
|
||||
void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
||||
@ -77,10 +77,10 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
||||
|
||||
startNewWallpaperEngine();
|
||||
|
||||
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() {
|
||||
QObject::connect(wallpaperEngine, &QProcess::started, button, [this, button]() {
|
||||
button->setEnabled(true);
|
||||
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) {
|
||||
updateSelectedButton();
|
||||
updateConfigLayout();
|
||||
this->wallpaperSettingsWidget->update(this->selectedWallpapers[this->screenSelector->currentText().toStdString()]);
|
||||
});
|
||||
|
||||
auto* screenSelectorLayout = new QVBoxLayout();
|
||||
@ -154,19 +154,10 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
||||
leftWidget->setLayout(leftLayout);
|
||||
|
||||
// right side
|
||||
auto* rightWidget = new QWidget(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);
|
||||
this->wallpaperSettingsWidget = new WallpaperSettingsWidget(splitWidget);
|
||||
|
||||
splitLayout->addWidget(leftWidget, 2);
|
||||
splitLayout->addWidget(rightWidget, 1);
|
||||
splitLayout->addWidget(this->wallpaperSettingsWidget, 1);
|
||||
|
||||
mainlayout->addWidget(splitWidget);
|
||||
mainlayout->addWidget(extraFlagsInput);
|
||||
@ -236,43 +227,6 @@ void UIWindow::startNewWallpaperEngine() {
|
||||
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() {
|
||||
for (int i = 0; i < this->buttonLayout->rowCount(); i++) {
|
||||
for (int j = 0; j < this->buttonLayout->columnCount(); j++) {
|
||||
|
@ -29,9 +29,9 @@
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <bits/stdc++.h>
|
||||
#include <QVBoxLayout>
|
||||
#include <iostream>
|
||||
#include "Qt/WallpaperSettingsWidget.h"
|
||||
|
||||
class UIWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
@ -47,8 +47,7 @@ class UIWindow : public QWidget {
|
||||
QComboBox* screenSelector;
|
||||
QLineEdit* extraFlagsInput;
|
||||
QGridLayout* buttonLayout;
|
||||
QLabel* previewImageLabel;
|
||||
QLabel* previewTitleLabel;
|
||||
WallpaperSettingsWidget* wallpaperSettingsWidget;
|
||||
|
||||
// Important Fields
|
||||
std::map<std::string, std::string> selectedWallpapers;
|
||||
@ -57,7 +56,6 @@ class UIWindow : public QWidget {
|
||||
|
||||
void startNewWallpaperEngine();
|
||||
void updateSelectedButton();
|
||||
void updateConfigLayout();
|
||||
static std::vector<std::string> split(const std::string &str, char r);
|
||||
|
||||
protected:
|
||||
|
56
src/Qt/WallpaperSettingsWidget.cpp
Normal file
56
src/Qt/WallpaperSettingsWidget.cpp
Normal 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));
|
||||
}
|
23
src/Qt/WallpaperSettingsWidget.h
Normal file
23
src/Qt/WallpaperSettingsWidget.h
Normal 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:
|
||||
};
|
Loading…
Reference in New Issue
Block a user