diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c2ba41932de7a652ebb357ecc380906f1077297 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,70 @@ +cmake_minimum_required(VERSION 3.5) + +project(stickers-renomator-2000 VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(stickers-renomator-2000 + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET stickers-renomator-2000 APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(stickers-renomator-2000 SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(stickers-renomator-2000 + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(stickers-renomator-2000 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. +# If you are developing for iOS or macOS you should consider setting an +# explicit, fixed bundle identifier manually though. +if(${QT_VERSION} VERSION_LESS 6.1.0) + set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.stickers-renomator-2000) +endif() +set_target_properties(stickers-renomator-2000 PROPERTIES + ${BUNDLE_ID_OPTION} + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +include(GNUInstallDirs) +install(TARGETS stickers-renomator-2000 + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(stickers-renomator-2000) +endif() diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fdcfb96120c0d71954aa68c9f6fe2791e2775f6 --- /dev/null +++ b/main.cpp @@ -0,0 +1,13 @@ +#include "mainwindow.h" + +#include <QApplication> +#include <QFile> +#include <QTextStream> + +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 0000000000000000000000000000000000000000..f7c0db68929bc1fcbfdfe3cce49ff90c57dd7a7e --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,129 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" + +#include <QFileDialog> +#include <QDir> +#include <QFile> +#include <QPixmap> +#include <QKeyEvent> + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::StickersRenomator2000) +{ + ui->setupUi(this); + MainWindow::setWindowTitle("Stickers Renomator 2000"); + ui->label_2->setScaledContents(false); + connect(ui->lineEdit, SIGNAL(returnPressed()),this,SLOT(on_pushButton_clicked())); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::on_actionOpen_Folder_triggered() +{ + this->imageFolder = QFileDialog::getExistingDirectory(this); + processImages(); +} + +void MainWindow::processImages() +{ + QDir directory(this->imageFolder); + this->imageList = directory.entryList(QStringList() << "*.png" << "*.PNG",QDir::Files); + this->currentImageIndex = 0; + this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; + ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); + this->currentImage = QPixmap(this->currentImagePath); + setImage(); +} + +void MainWindow::setImage() +{ + int w = this->ui->label_2->width(); + int h = this->ui->label_2->height(); + this->ui->label_2->setPixmap(this->currentImage.scaled(w,h, Qt::KeepAspectRatio, Qt::SmoothTransformation)); +} + +void MainWindow::resizeEvent(QResizeEvent* event) +{ + QMainWindow::resizeEvent(event); + if(!this->currentImage.isNull()){ + setImage(); + } +} + +void MainWindow::keyPressEvent(QKeyEvent *event) +{ + QMainWindow::keyPressEvent(event); + switch(event->key()){ + case Qt::Key_Right: + MainWindow::on_next_clicked(); + break; + case Qt::Key_Left: + MainWindow::on_prev_clicked(); + break; + case Qt::Key_Delete: + MainWindow::on_deleteButton_clicked(); + break; + } +} + +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + ui->lineEdit->clearFocus(); +} + +void MainWindow::on_pushButton_clicked() +{ + QString newName = ui->lineEdit->text(); + QFile::rename(this->currentImagePath, this->imageFolder+"/"+newName+".png"); + ui->lineEdit->setText(""); + this->imageList[this->currentImageIndex] = newName+".png"; + this->currentImageIndex++; + if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0; + this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; + ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); + this->currentImage = QPixmap(this->currentImagePath); + setImage(); +} + + +void MainWindow::on_deleteButton_clicked() +{ + if(!QDir(this->imageFolder+"/deletedStickers").exists()){ + QDir().mkdir(this->imageFolder+"/deletedStickers"); + } + QFile::rename(this->currentImagePath, this->imageFolder+"/deletedStickers/"+this->imageList[this->currentImageIndex]); + this->imageList.removeAt(this->currentImageIndex); + this->currentImageIndex++; + if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0; + this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; + ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); + this->currentImage = QPixmap(this->currentImagePath); + setImage(); +} + + +void MainWindow::on_prev_clicked() +{ + this->currentImageIndex--; + if(this->currentImageIndex<0) this->currentImageIndex = this->imageList.size()-1; + this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; + ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); + this->currentImage = QPixmap(this->currentImagePath); + setImage(); +} + + +void MainWindow::on_next_clicked() +{ + this->currentImageIndex++; + if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0; + this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; + ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); + this->currentImage = QPixmap(this->currentImagePath); + setImage(); +} + diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000000000000000000000000000000000000..1eba77a58dcbe9cfee291e3bd08b03b011714f29 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,46 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> + +QT_BEGIN_NAMESPACE +namespace Ui { +class StickersRenomator2000; +} +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private slots: + void on_actionOpen_Folder_triggered(); + + + void on_pushButton_clicked(); + + void on_deleteButton_clicked(); + + void on_prev_clicked(); + + void on_next_clicked(); + +private: + Ui::StickersRenomator2000 *ui; + QString imageFolder; + QStringList imageList; + int currentImageIndex; + QString currentImagePath; + QPixmap currentImage; + void resizeEvent(QResizeEvent *event) override; + void keyPressEvent(QKeyEvent *event) override; + void mousePressEvent ( QMouseEvent * event ) override; + + void processImages(); + void setImage(); +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000000000000000000000000000000000000..fc9e102289dd7f46993700a0e65686aac68dd492 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,585 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>StickersRenomator2000</class> + <widget class="QMainWindow" name="StickersRenomator2000"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>822</width> + <height>617</height> + </rect> + </property> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Light"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>75</red> + <green>75</green> + <blue>87</blue> + </color> + </brush> + </colorrole> + <colorrole role="Midlight"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>62</red> + <green>62</green> + <blue>72</blue> + </color> + </brush> + </colorrole> + <colorrole role="Dark"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="Mid"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>33</red> + <green>33</green> + <blue>39</blue> + </color> + </brush> + </colorrole> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="BrightText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Shadow"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="AlternateBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>220</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="PlaceholderText"> + <brush brushstyle="SolidPattern"> + <color alpha="127"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Light"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>75</red> + <green>75</green> + <blue>87</blue> + </color> + </brush> + </colorrole> + <colorrole role="Midlight"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>62</red> + <green>62</green> + <blue>72</blue> + </color> + </brush> + </colorrole> + <colorrole role="Dark"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="Mid"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>33</red> + <green>33</green> + <blue>39</blue> + </color> + </brush> + </colorrole> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="BrightText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Shadow"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="AlternateBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>220</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="PlaceholderText"> + <brush brushstyle="SolidPattern"> + <color alpha="127"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="Button"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Light"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>75</red> + <green>75</green> + <blue>87</blue> + </color> + </brush> + </colorrole> + <colorrole role="Midlight"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>62</red> + <green>62</green> + <blue>72</blue> + </color> + </brush> + </colorrole> + <colorrole role="Dark"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="Mid"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>33</red> + <green>33</green> + <blue>39</blue> + </color> + </brush> + </colorrole> + <colorrole role="Text"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="BrightText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="ButtonText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="Shadow"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="AlternateBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>50</red> + <green>50</green> + <blue>58</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipBase"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>220</blue> + </color> + </brush> + </colorrole> + <colorrole role="ToolTipText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>0</red> + <green>0</green> + <blue>0</blue> + </color> + </brush> + </colorrole> + <colorrole role="PlaceholderText"> + <brush brushstyle="SolidPattern"> + <color alpha="127"> + <red>25</red> + <green>25</green> + <blue>29</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="1"> + <widget class="QFrame" name="frame"> + <property name="minimumSize"> + <size> + <width>200</width> + <height>200</height> + </size> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>TextLabel</string> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0" colspan="3" alignment="Qt::AlignHCenter|Qt::AlignVCenter"> + <widget class="QFrame" name="frame_2"> + <property name="minimumSize"> + <size> + <width>400</width> + <height>150</height> + </size> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Raised</enum> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="1" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Nouveau nom</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QLineEdit" name="lineEdit"/> + </item> + <item row="2" column="1"> + <widget class="QToolButton" name="deleteButton"> + <property name="text"> + <string comment="Supprimer">X</string> + </property> + <property name="icon"> + <iconset theme="dialog-error"/> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Enregistrer et suivant</string> + </property> + <property name="autoDefault"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Nom actuel: </string> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QToolButton" name="prev"> + <property name="text"> + <string>prev</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QToolButton" name="next"> + <property name="text"> + <string>next</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>822</width> + <height>22</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionOpen_Folder"/> + </widget> + <addaction name="menuFile"/> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <action name="actionOpen_Folder"> + <property name="text"> + <string>Open Folder</string> + </property> + </action> + </widget> + <resources/> + <connections/> +</ui>