From 1a269ba7195282a6cd49bab6f2d225d4e12e2bb3 Mon Sep 17 00:00:00 2001 From: Alsweider <30653982+Alsweider@users.noreply.github.com> Date: Thu, 14 Dec 2023 04:40:38 +0100 Subject: [PATCH] v0.0.1 --- WasfurnBild.pro | 28 +++++++++++++ main.cpp | 11 +++++ mainwindow.cpp | 93 ++++++++++++++++++++++++++++++++++++++++++ mainwindow.h | 45 +++++++++++++++++++++ mainwindow.ui | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 282 insertions(+) create mode 100644 WasfurnBild.pro create mode 100644 main.cpp create mode 100644 mainwindow.cpp create mode 100644 mainwindow.h create mode 100644 mainwindow.ui diff --git a/WasfurnBild.pro b/WasfurnBild.pro new file mode 100644 index 0000000..d6a8cf4 --- /dev/null +++ b/WasfurnBild.pro @@ -0,0 +1,28 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++17 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + + + + diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..aff48df --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..3566673 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,93 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_pushButton_clicked() +{ + ui->lineEdit->setText(getDesktopBackgroundFileName()); + + //Wenn der Pfad im Feld ist, aktiviere Knöpfe zum Kopieren und Öffnen + if (ui->lineEdit->text() != ""){ + ui->pushButton_2->setEnabled(true); + ui->pushButton_3->setEnabled(true); + } + + //Bild laden + desktopBackground.load(getDesktopBackgroundFileName()); + desktopBackground = desktopBackground.scaled(200, 200, Qt::KeepAspectRatio); + + ui->labelImage->setPixmap(desktopBackground); +} + +QString MainWindow::getDesktopBackgroundFileName() { + qDebug() << "Funktion getDesktopBackgroundFileName() aufgerufen "; + + // Öffnen der Registry-Schlüssel + QSettings registrySettings("HKEY_CURRENT_USER\\Control Panel\\Desktop", QSettings::NativeFormat); + + //QString zur Aufnahme des neuen Pfades + QString wallpaperPath = ""; + + //Lesen des Werts TranscodedImageCache + wallpaperPath = registrySettings.value("TranscodedImageCache").toString(); + + //Entfernen möglicher Nullterminierungen + wallpaperPath.remove(QChar('\0')); + + //Bereinigen des Pfads von weiteren unerwünschten Zeichen + wallpaperPath = cleanUpPath(wallpaperPath); + + //Rückgabe des Pfads + qDebug() << "Pfad: " << wallpaperPath; + return wallpaperPath; +} + + +QString MainWindow::cleanUpPath(const QString &path) { + //Nur erlaubte Zeichen beibehalten (A-Z, a-z, 0-9, \, :, ., -) + QString allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜẞabcdefghijklmnopqrstuvwxyzäöüß0123456789\\:.-/_, "; + + QString cleanedPath; + for (const QChar &ch : path) { + if (allowedChars.contains(ch)) { + cleanedPath.append(ch); + } + } + + return cleanedPath; +} + +void MainWindow::on_pushButton_2_clicked() +{ + QClipboard *clipboard = QApplication::clipboard(); + clipboard->setText(ui->lineEdit->text()); +} + + +void MainWindow::on_pushButton_3_clicked() +{ + QString imagePath = getDesktopBackgroundFileName(); + + //Überprüfen, ob der Dateipfad nicht leer ist + if (!imagePath.isEmpty()) { + QDesktopServices::openUrl(QUrl::fromLocalFile(imagePath)); + } +} + +//Knopf zum Schließen des Programms +void MainWindow::on_pushButton_4_clicked() +{ + this->close(); +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..3f24122 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,45 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#include +#include + + + + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + QString getDesktopBackgroundFileName(); + QString cleanUpPath(const QString&); + +private slots: + void on_pushButton_clicked(); + + void on_pushButton_2_clicked(); + + void on_pushButton_3_clicked(); + + void on_pushButton_4_clicked(); + +private: + Ui::MainWindow *ui; + QPixmap desktopBackground; + +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..817f665 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,105 @@ + + + MainWindow + + + + 0 + 0 + 218 + 310 + + + + WasfurnBild v0.0.1 + + + + + + + + + + + + Liest den Pfad des aktuellen Desktop-Hintergrundbildes aus der Registry. + + + Pfad auslesen + + + + + + + false + + + Kopiert den Pfad in die Zwischenablage. + + + Pfad kopieren + + + + + + + + + + 0 + 0 + + + + + 200 + 200 + + + + Zeigt Desktop-Hintergrundbild, sobald Pfad ausgelesen wurde. + + + background-color: rgb(204, 204, 204); + + + + + + + + + + + + false + + + Öffnet das Bild im System-Bildbetrachter. + + + Bild öffnen + + + + + + + Schließt das Programm. + + + Beenden + + + + + + + + + + +