-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "mainwindow.h" | ||
|
||
#include <QApplication> | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
QApplication a(argc, argv); | ||
MainWindow w; | ||
w.show(); | ||
return a.exec(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef MAINWINDOW_H | ||
#define MAINWINDOW_H | ||
|
||
#include <QMainWindow> | ||
#include <Windows.h> | ||
#include <QSettings> | ||
#include <QRegularExpression> | ||
#include <QPixmap> | ||
#include <QClipboard> | ||
#include <QDesktopServices> | ||
|
||
|
||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>MainWindow</class> | ||
<widget class="QMainWindow" name="MainWindow"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>218</width> | ||
<height>310</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>WasfurnBild v0.0.1</string> | ||
</property> | ||
<widget class="QWidget" name="centralwidget"> | ||
<layout class="QGridLayout" name="gridLayout"> | ||
<item row="0" column="0"> | ||
<widget class="QLineEdit" name="lineEdit"/> | ||
</item> | ||
<item row="1" column="0"> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QPushButton" name="pushButton"> | ||
<property name="toolTip"> | ||
<string>Liest den Pfad des aktuellen Desktop-Hintergrundbildes aus der Registry.</string> | ||
</property> | ||
<property name="text"> | ||
<string>Pfad auslesen</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_2"> | ||
<property name="enabled"> | ||
<bool>false</bool> | ||
</property> | ||
<property name="toolTip"> | ||
<string>Kopiert den Pfad in die Zwischenablage.</string> | ||
</property> | ||
<property name="text"> | ||
<string>Pfad kopieren</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="labelImage"> | ||
<property name="sizePolicy"> | ||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
<horstretch>0</horstretch> | ||
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="minimumSize"> | ||
<size> | ||
<width>200</width> | ||
<height>200</height> | ||
</size> | ||
</property> | ||
<property name="toolTip"> | ||
<string>Zeigt Desktop-Hintergrundbild, sobald Pfad ausgelesen wurde.</string> | ||
</property> | ||
<property name="styleSheet"> | ||
<string notr="true">background-color: rgb(204, 204, 204);</string> | ||
</property> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="0"> | ||
<layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_3"> | ||
<property name="enabled"> | ||
<bool>false</bool> | ||
</property> | ||
<property name="toolTip"> | ||
<string>Öffnet das Bild im System-Bildbetrachter.</string> | ||
</property> | ||
<property name="text"> | ||
<string>Bild öffnen</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="pushButton_4"> | ||
<property name="toolTip"> | ||
<string>Schließt das Programm.</string> | ||
</property> | ||
<property name="text"> | ||
<string>Beenden</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |