diff --git a/CMakeLists.txt b/CMakeLists.txt index fe2d2bd..723c299 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,6 +261,8 @@ add_executable( src/Qt/UIWindow.cpp src/Qt/SingleInstanceManager.h src/Qt/SingleInstanceManager.cpp + src/Qt/WallpaperButton.h + src/Qt/WallpaperButton.cpp src/External/MimeTypes/MimeTypes.cpp src/External/MimeTypes/MimeTypes.h diff --git a/src/Qt/UIWindow.cpp b/src/Qt/UIWindow.cpp index 51d3b3c..e091ae1 100644 --- a/src/Qt/UIWindow.cpp +++ b/src/Qt/UIWindow.cpp @@ -1,13 +1,23 @@ #include "UIWindow.h" #include "Qt/SingleInstanceManager.h" +#include "Qt/WallpaperButton.h" #include +#include +#include #include +#include +#include +#include +#include #include #include +#include #include #include +#include #include #include +#include #include #include #include @@ -23,6 +33,9 @@ #include #include #include +#include +#include +#include "WallpaperButton.h" #define PICTURE_SIZE 128 @@ -53,26 +66,7 @@ void UIWindow::setupUIWindow(std::vector wallpaperPaths) { int cols = 6; for (size_t i = 0; i < wallpaperPaths.size(); i++) { - QPixmap pixmap(QString::fromStdString(wallpaperPaths[i] + "/preview.jpg")); - 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])); - + auto* button = new WallpaperButton(this, wallpaperPaths[i]); QAbstractButton::connect(button, &QPushButton::clicked, [button, this]() { QString clickedPath = button->property("path").toString(); @@ -86,8 +80,8 @@ void UIWindow::setupUIWindow(std::vector wallpaperPaths) { QObject::connect(wallpaperEngine, &QProcess::started, button, [=]() { button->setEnabled(true); updateSelectedButton(); + updateConfigLayout(); }); - // qapp.exit(); }); int row = i / cols; @@ -128,6 +122,7 @@ void UIWindow::setupUIWindow(std::vector wallpaperPaths) { QObject::connect(this->screenSelector, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) { updateSelectedButton(); + updateConfigLayout(); }); auto* screenSelectorLayout = new QVBoxLayout(); @@ -139,12 +134,41 @@ void UIWindow::setupUIWindow(std::vector wallpaperPaths) { auto* screenSelectContainer = new QWidget(); screenSelectContainer->setLayout(screenSelectorLayout); - // Flags Inputfield - // - + // Main Layout auto* mainlayout = new QVBoxLayout(this); 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); this->setLayout(mainlayout); @@ -212,6 +236,43 @@ 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++) { @@ -221,14 +282,18 @@ void UIWindow::updateSelectedButton() { auto* widget = item->widget(); if (!widget) continue; - auto* button = dynamic_cast(widget); + auto* button = dynamic_cast(widget); if (!button) continue; std::string selected = this->selectedWallpapers[this->screenSelector->currentText().toStdString()]; + QString currentStyle = button->styleSheet(); + QString newStyle = currentStyle; 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 { - button->setStyleSheet("background-color: #4A4D51; color white; border: 2px solid #3B3A43"); + newStyle = newStyle.replace(QRegularExpression("background-color:[^;]+;"), "background-color: #4A4D51; "); + button->setStyleSheet(newStyle); } } } diff --git a/src/Qt/UIWindow.h b/src/Qt/UIWindow.h index 7c4c9c0..8bd9ced 100644 --- a/src/Qt/UIWindow.h +++ b/src/Qt/UIWindow.h @@ -3,9 +3,11 @@ #include "Qt/SingleInstanceManager.h" #include #include +#include #include #include #include +#include #include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include class UIWindow : public QWidget { @@ -44,6 +47,8 @@ class UIWindow : public QWidget { QComboBox* screenSelector; QLineEdit* extraFlagsInput; QGridLayout* buttonLayout; + QLabel* previewImageLabel; + QLabel* previewTitleLabel; // Important Fields std::map selectedWallpapers; @@ -52,6 +57,7 @@ class UIWindow : public QWidget { void startNewWallpaperEngine(); void updateSelectedButton(); + void updateConfigLayout(); static std::vector split(const std::string &str, char r); protected: diff --git a/src/Qt/WallpaperButton.cpp b/src/Qt/WallpaperButton.cpp index 48e6dbf..44426d4 100644 --- a/src/Qt/WallpaperButton.cpp +++ b/src/Qt/WallpaperButton.cpp @@ -1,9 +1,65 @@ #include "WallpaperButton.h" #include "Qt/UIWindow.h" +#include +#include +#include +#include +#include +#include +#include #include #include WallpaperButton::WallpaperButton(UIWindow* window, std::string& path, QWidget* parent) { this->mainWindow = window; 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)); + } diff --git a/src/Qt/WallpaperButton.h b/src/Qt/WallpaperButton.h index e4ce222..b12412e 100644 --- a/src/Qt/WallpaperButton.h +++ b/src/Qt/WallpaperButton.h @@ -1,22 +1,26 @@ #pragma once #include +#include #include -#include +#include #include #include #include "UIWindow.h" -class WallpaperButton : public QPushButton { +#define PICTURE_SIZE 128 + +class WallpaperButton : public QToolButton { Q_OBJECT public: explicit WallpaperButton(UIWindow* mainWindow, std::string& wallpaperPath, QWidget* parent = nullptr); protected: - void mousePressEvent(QMouseEvent* event) override; - void enterEvent(QEvent* event) override; - void leaveEvent(QEvent* event) override; + // void mousePressEvent(QMouseEvent* event) override; + // void enterEvent(QEvent* event) override; + // void leaveEvent(QEvent* event) override; + void resizeEvent(QResizeEvent* event) override; private: UIWindow* mainWindow; diff --git a/src/main.cpp b/src/main.cpp index 397daf7..29f48ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,8 @@ void initLogging () int main (int argc, char* argv[]) { initLogging (); + std::cout << QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toStdString() << "\n"; + if (argc <= 1) { QApplication qapp(argc, argv);