mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
added side pannel
This commit is contained in:
parent
34db844694
commit
fe9b59e491
@ -261,6 +261,8 @@ add_executable(
|
|||||||
src/Qt/UIWindow.cpp
|
src/Qt/UIWindow.cpp
|
||||||
src/Qt/SingleInstanceManager.h
|
src/Qt/SingleInstanceManager.h
|
||||||
src/Qt/SingleInstanceManager.cpp
|
src/Qt/SingleInstanceManager.cpp
|
||||||
|
src/Qt/WallpaperButton.h
|
||||||
|
src/Qt/WallpaperButton.cpp
|
||||||
|
|
||||||
src/External/MimeTypes/MimeTypes.cpp
|
src/External/MimeTypes/MimeTypes.cpp
|
||||||
src/External/MimeTypes/MimeTypes.h
|
src/External/MimeTypes/MimeTypes.h
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
#include "UIWindow.h"
|
#include "UIWindow.h"
|
||||||
#include "Qt/SingleInstanceManager.h"
|
#include "Qt/SingleInstanceManager.h"
|
||||||
|
#include "Qt/WallpaperButton.h"
|
||||||
#include <QtConcurrent/qtconcurrentrun.h>
|
#include <QtConcurrent/qtconcurrentrun.h>
|
||||||
|
#include <X11/X.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <nlohmann/json_fwd.hpp>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
|
#include <QHBoxLayout>
|
||||||
#include <qcombobox.h>
|
#include <qcombobox.h>
|
||||||
#include <qcursor.h>
|
#include <qcursor.h>
|
||||||
|
#include <qdebug.h>
|
||||||
#include <qevent.h>
|
#include <qevent.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
#include <qgroupbox.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
#include <qlayout.h>
|
#include <qlayout.h>
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
@ -23,6 +33,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QGroupBox>
|
||||||
|
#include "WallpaperButton.h"
|
||||||
|
|
||||||
#define PICTURE_SIZE 128
|
#define PICTURE_SIZE 128
|
||||||
|
|
||||||
@ -53,26 +66,7 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
|||||||
int cols = 6;
|
int cols = 6;
|
||||||
|
|
||||||
for (size_t i = 0; i < wallpaperPaths.size(); i++) {
|
for (size_t i = 0; i < wallpaperPaths.size(); i++) {
|
||||||
QPixmap pixmap(QString::fromStdString(wallpaperPaths[i] + "/preview.jpg"));
|
auto* button = new WallpaperButton(this, wallpaperPaths[i]);
|
||||||
auto* button = new QPushButton();
|
|
||||||
|
|
||||||
if (pixmap.isNull()) {
|
|
||||||
pixmap = QPixmap(PICTURE_SIZE, PICTURE_SIZE);
|
|
||||||
pixmap.fill(Qt::black);
|
|
||||||
|
|
||||||
auto* movie = new QMovie(QString::fromStdString(wallpaperPaths[i] + "/preview.gif"));
|
|
||||||
if (movie->isValid()) {
|
|
||||||
movie->jumpToFrame(0);
|
|
||||||
pixmap = movie->currentPixmap().scaled(PICTURE_SIZE, PICTURE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
||||||
}
|
|
||||||
delete movie;
|
|
||||||
} else pixmap = pixmap.scaled(PICTURE_SIZE, PICTURE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
||||||
|
|
||||||
button->setIcon(pixmap);
|
|
||||||
button->setIconSize(QSize(PICTURE_SIZE, PICTURE_SIZE));
|
|
||||||
button->setFixedSize(PICTURE_SIZE*1.5, PICTURE_SIZE*1.5);
|
|
||||||
button->setProperty("path", QString::fromStdString(wallpaperPaths[i]));
|
|
||||||
|
|
||||||
|
|
||||||
QAbstractButton::connect(button, &QPushButton::clicked, [button, this]() {
|
QAbstractButton::connect(button, &QPushButton::clicked, [button, this]() {
|
||||||
QString clickedPath = button->property("path").toString();
|
QString clickedPath = button->property("path").toString();
|
||||||
@ -86,8 +80,8 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
|||||||
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() {
|
QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() {
|
||||||
button->setEnabled(true);
|
button->setEnabled(true);
|
||||||
updateSelectedButton();
|
updateSelectedButton();
|
||||||
|
updateConfigLayout();
|
||||||
});
|
});
|
||||||
// qapp.exit();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
int row = i / cols;
|
int row = i / cols;
|
||||||
@ -128,6 +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();
|
||||||
});
|
});
|
||||||
|
|
||||||
auto* screenSelectorLayout = new QVBoxLayout();
|
auto* screenSelectorLayout = new QVBoxLayout();
|
||||||
@ -139,12 +134,41 @@ void UIWindow::setupUIWindow(std::vector<std::string> wallpaperPaths) {
|
|||||||
auto* screenSelectContainer = new QWidget();
|
auto* screenSelectContainer = new QWidget();
|
||||||
screenSelectContainer->setLayout(screenSelectorLayout);
|
screenSelectContainer->setLayout(screenSelectorLayout);
|
||||||
|
|
||||||
// Flags Inputfield
|
// Main Layout
|
||||||
//
|
|
||||||
|
|
||||||
auto* mainlayout = new QVBoxLayout(this);
|
auto* mainlayout = new QVBoxLayout(this);
|
||||||
mainlayout->addWidget(screenSelectContainer);
|
mainlayout->addWidget(screenSelectContainer);
|
||||||
mainlayout->addWidget(scrollArea);
|
|
||||||
|
auto* splitWidget = new QGroupBox("Wallpaper Selection", this);
|
||||||
|
splitWidget->setStyleSheet(
|
||||||
|
"font-size: 26px; "
|
||||||
|
"color: white; "
|
||||||
|
"background: transparent; "
|
||||||
|
);
|
||||||
|
auto* splitLayout = new QHBoxLayout(splitWidget);
|
||||||
|
splitWidget->setLayout(splitLayout);
|
||||||
|
|
||||||
|
// left side
|
||||||
|
auto* leftWidget = new QWidget(splitWidget);
|
||||||
|
auto* leftLayout = new QVBoxLayout(leftWidget);
|
||||||
|
leftLayout->addWidget(scrollArea);
|
||||||
|
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);
|
||||||
|
|
||||||
|
splitLayout->addWidget(leftWidget, 2);
|
||||||
|
splitLayout->addWidget(rightWidget, 1);
|
||||||
|
|
||||||
|
mainlayout->addWidget(splitWidget);
|
||||||
mainlayout->addWidget(extraFlagsInput);
|
mainlayout->addWidget(extraFlagsInput);
|
||||||
this->setLayout(mainlayout);
|
this->setLayout(mainlayout);
|
||||||
|
|
||||||
@ -212,6 +236,43 @@ 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++) {
|
||||||
@ -221,14 +282,18 @@ void UIWindow::updateSelectedButton() {
|
|||||||
auto* widget = item->widget();
|
auto* widget = item->widget();
|
||||||
if (!widget) continue;
|
if (!widget) continue;
|
||||||
|
|
||||||
auto* button = dynamic_cast<QPushButton*>(widget);
|
auto* button = dynamic_cast<WallpaperButton*>(widget);
|
||||||
if (!button) continue;
|
if (!button) continue;
|
||||||
|
|
||||||
std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()];
|
std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()];
|
||||||
|
QString currentStyle = button->styleSheet();
|
||||||
|
QString newStyle = currentStyle;
|
||||||
if (button->property("path").toString().toStdString() == selected) {
|
if (button->property("path").toString().toStdString() == selected) {
|
||||||
button->setStyleSheet("background-color: #4488ff; color white; border: 2px solid #0055cc");
|
newStyle = newStyle.replace(QRegularExpression("background-color:[^;]+;"), "background-color: #4488ff; ");
|
||||||
|
button->setStyleSheet(newStyle);
|
||||||
} else {
|
} else {
|
||||||
button->setStyleSheet("background-color: #4A4D51; color white; border: 2px solid #3B3A43");
|
newStyle = newStyle.replace(QRegularExpression("background-color:[^;]+;"), "background-color: #4A4D51; ");
|
||||||
|
button->setStyleSheet(newStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
#include "Qt/SingleInstanceManager.h"
|
#include "Qt/SingleInstanceManager.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <qapplication.h>
|
#include <qapplication.h>
|
||||||
|
#include <qboxlayout.h>
|
||||||
#include <qcombobox.h>
|
#include <qcombobox.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qgridlayout.h>
|
#include <qgridlayout.h>
|
||||||
|
#include <qlabel.h>
|
||||||
#include <qlineedit.h>
|
#include <qlineedit.h>
|
||||||
#include <qobjectdefs.h>
|
#include <qobjectdefs.h>
|
||||||
#include <qprocess.h>
|
#include <qprocess.h>
|
||||||
@ -28,6 +30,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <bits/stdc++.h>
|
#include <bits/stdc++.h>
|
||||||
|
#include <QVBoxLayout>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class UIWindow : public QWidget {
|
class UIWindow : public QWidget {
|
||||||
@ -44,6 +47,8 @@ class UIWindow : public QWidget {
|
|||||||
QComboBox* screenSelector;
|
QComboBox* screenSelector;
|
||||||
QLineEdit* extraFlagsInput;
|
QLineEdit* extraFlagsInput;
|
||||||
QGridLayout* buttonLayout;
|
QGridLayout* buttonLayout;
|
||||||
|
QLabel* previewImageLabel;
|
||||||
|
QLabel* previewTitleLabel;
|
||||||
|
|
||||||
// Important Fields
|
// Important Fields
|
||||||
std::map<std::string, std::string> selectedWallpapers;
|
std::map<std::string, std::string> selectedWallpapers;
|
||||||
@ -52,6 +57,7 @@ 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:
|
||||||
|
@ -1,9 +1,65 @@
|
|||||||
#include "WallpaperButton.h"
|
#include "WallpaperButton.h"
|
||||||
#include "Qt/UIWindow.h"
|
#include "Qt/UIWindow.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <nlohmann/json_fwd.hpp>
|
||||||
|
#include <qevent.h>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
#include <qpushbutton.h>
|
||||||
#include <qwidget.h>
|
#include <qwidget.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
WallpaperButton::WallpaperButton(UIWindow* window, std::string& path, QWidget* parent) {
|
WallpaperButton::WallpaperButton(UIWindow* window, std::string& path, QWidget* parent) {
|
||||||
this->mainWindow = window;
|
this->mainWindow = window;
|
||||||
this->wallpaperPath = path;
|
this->wallpaperPath = path;
|
||||||
|
|
||||||
|
std::ifstream file(path + "/project.json");
|
||||||
|
nlohmann::json wallpaperJSON = nlohmann::json::parse(file);
|
||||||
|
|
||||||
|
std::string title = wallpaperJSON.at("title");
|
||||||
|
if (title.size() > 15) {
|
||||||
|
title = title.substr(0, 14) + "..";
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap pixmap(QString::fromStdString(path + "/preview.jpg"));
|
||||||
|
|
||||||
|
|
||||||
|
if (pixmap.isNull()) {
|
||||||
|
pixmap = QPixmap(PICTURE_SIZE, PICTURE_SIZE);
|
||||||
|
pixmap.fill(Qt::black);
|
||||||
|
|
||||||
|
auto* movie = new QMovie(QString::fromStdString(path + "/preview.gif"));
|
||||||
|
if (movie->isValid()) {
|
||||||
|
movie->jumpToFrame(0);
|
||||||
|
pixmap = movie->currentPixmap().scaled(PICTURE_SIZE, PICTURE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
|
delete movie;
|
||||||
|
} else pixmap = pixmap.scaled(PICTURE_SIZE, PICTURE_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
|
||||||
|
|
||||||
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||||
|
setMinimumSize(100, 100);
|
||||||
|
setIcon(QIcon(pixmap));
|
||||||
|
setText(QString::fromStdString(title));
|
||||||
|
setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextUnderIcon);
|
||||||
|
setIconSize(size() * 0.8);
|
||||||
|
setProperty("path", QString::fromStdString(path));
|
||||||
|
|
||||||
|
setStyleSheet(
|
||||||
|
"QToolButton {"
|
||||||
|
"background-color: #2B2A33; "
|
||||||
|
"color: white; "
|
||||||
|
"font-size: 15px;"
|
||||||
|
"border: 1px solid #FFFFFF; "
|
||||||
|
"border-radius: 5px; "
|
||||||
|
"} "
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WallpaperButton::resizeEvent(QResizeEvent* event) {
|
||||||
|
QToolButton::resizeEvent(event);
|
||||||
|
int size = std::min(event->size().width(), event->size().height()) * 0.8f;
|
||||||
|
setIconSize(QSize(size, size));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <qcoreevent.h>
|
#include <qcoreevent.h>
|
||||||
|
#include <qevent.h>
|
||||||
#include <qobjectdefs.h>
|
#include <qobjectdefs.h>
|
||||||
#include <qpushbutton.h>
|
#include <qtoolbutton.h>
|
||||||
#include <qwidget.h>
|
#include <qwidget.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "UIWindow.h"
|
#include "UIWindow.h"
|
||||||
|
|
||||||
class WallpaperButton : public QPushButton {
|
#define PICTURE_SIZE 128
|
||||||
|
|
||||||
|
class WallpaperButton : public QToolButton {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WallpaperButton(UIWindow* mainWindow, std::string& wallpaperPath, QWidget* parent = nullptr);
|
explicit WallpaperButton(UIWindow* mainWindow, std::string& wallpaperPath, QWidget* parent = nullptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QMouseEvent* event) override;
|
// void mousePressEvent(QMouseEvent* event) override;
|
||||||
void enterEvent(QEvent* event) override;
|
// void enterEvent(QEvent* event) override;
|
||||||
void leaveEvent(QEvent* event) override;
|
// void leaveEvent(QEvent* event) override;
|
||||||
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UIWindow* mainWindow;
|
UIWindow* mainWindow;
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
|
#include <qstandardpaths.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -45,6 +46,8 @@ void initLogging ()
|
|||||||
int main (int argc, char* argv[]) {
|
int main (int argc, char* argv[]) {
|
||||||
initLogging ();
|
initLogging ();
|
||||||
|
|
||||||
|
std::cout << QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() << "\n";
|
||||||
|
|
||||||
|
|
||||||
if (argc <= 1) {
|
if (argc <= 1) {
|
||||||
QApplication qapp(argc, argv);
|
QApplication qapp(argc, argv);
|
||||||
|
Loading…
Reference in New Issue
Block a user