Skip to content
Extraits de code Groupes Projets
Valider 56de9a23 rédigé par Deurstann's avatar Deurstann
Parcourir les fichiers

Add default prefix in config and escape on name edit

parent c7d5514c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -38,6 +38,7 @@ else() ...@@ -38,6 +38,7 @@ else()
else() else()
add_executable(stickers-renomator-2000 add_executable(stickers-renomator-2000
${PROJECT_SOURCES} ${PROJECT_SOURCES}
lineEditEventFilter.h
) )
endif() endif()
endif() endif()
......
#ifndef LINEEDITEVENTFILTER_H
#define LINEEDITEVENTFILTER_H
#include <QObject>
#include <QLineEdit>
#include <QKeyEvent>
#include <QEvent>
class LineEditEventFilter : public QObject
{
public:
explicit LineEditEventFilter(QLineEdit *parent) : QObject(parent)
{}
bool eventFilter(QObject *obj, QEvent *e)
{
switch (e->type())
{
case QEvent::KeyPress:
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
if (keyEvent->key() == Qt::Key_Escape)
{
reinterpret_cast<QLineEdit *>(parent())->clearFocus();
}
break;
}
}
// standard event processing
return QObject::eventFilter(obj, e);
}
};
#endif // LINEEDITEVENTFILTER_H
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <QFile> #include <QFile>
#include <QPixmap> #include <QPixmap>
#include <QKeyEvent> #include <QKeyEvent>
#include "lineEditEventFilter.h"
MainWindow::MainWindow(QString dir, QWidget *parent) MainWindow::MainWindow(QString dir, QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
...@@ -15,7 +16,11 @@ MainWindow::MainWindow(QString dir, QWidget *parent) ...@@ -15,7 +16,11 @@ MainWindow::MainWindow(QString dir, QWidget *parent)
MainWindow::setWindowTitle("Stickers Renomator 2000"); MainWindow::setWindowTitle("Stickers Renomator 2000");
ui->label_2->setScaledContents(false); ui->label_2->setScaledContents(false);
connect(ui->lineEdit, SIGNAL(returnPressed()),this,SLOT(on_pushButton_clicked())); connect(ui->lineEdit, SIGNAL(returnPressed()),this,SLOT(on_pushButton_clicked()));
connect(ui->defautPrefixEdit, SIGNAL(textEdited(const QString)), this, SLOT(on_defaultPrefixEdit_textEdited()));
this->imageFolder = dir; this->imageFolder = dir;
auto lineEditEventFilter = new LineEditEventFilter(ui->lineEdit);
ui->lineEdit->installEventFilter(lineEditEventFilter);
ui->lineEdit->setFocus();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
...@@ -88,53 +93,67 @@ void MainWindow::mousePressEvent(QMouseEvent *event) ...@@ -88,53 +93,67 @@ void MainWindow::mousePressEvent(QMouseEvent *event)
void MainWindow::on_pushButton_clicked() void MainWindow::on_pushButton_clicked()
{ {
QString newName = ui->lineEdit->text(); if(this->imageFolder != ""){
QFile::rename(this->currentImagePath, this->imageFolder+"/"+newName+".png"); QString newName = ui->lineEdit->text();
ui->lineEdit->setText(""); QFile::rename(this->currentImagePath, this->imageFolder+"/"+newName+".png");
this->imageList[this->currentImageIndex] = newName+".png"; ui->lineEdit->setText(defaultPrefix);
this->currentImageIndex++; this->imageList[this->currentImageIndex] = newName+".png";
if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0; this->currentImageIndex++;
this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0;
ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex];
this->currentImage = QPixmap(this->currentImagePath); ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0));
setImage(); this->currentImage = QPixmap(this->currentImagePath);
setImage();
}
} }
void MainWindow::on_deleteButton_clicked() void MainWindow::on_deleteButton_clicked()
{ {
if(!QDir(this->imageFolder+"/deletedStickers").exists()){ if(this->imageFolder != ""){
if(!QDir(this->imageFolder+"/deletedStickers").exists()){
QDir().mkdir(this->imageFolder+"/deletedStickers"); 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();
} }
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() void MainWindow::on_prev_clicked()
{ {
this->currentImageIndex--; if(this->imageFolder != ""){
if(this->currentImageIndex<0) this->currentImageIndex = this->imageList.size()-1; this->currentImageIndex--;
this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; if(this->currentImageIndex<0) this->currentImageIndex = this->imageList.size()-1;
ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex];
this->currentImage = QPixmap(this->currentImagePath); ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0));
setImage(); this->currentImage = QPixmap(this->currentImagePath);
setImage();
}
} }
void MainWindow::on_next_clicked() void MainWindow::on_next_clicked()
{ {
this->currentImageIndex++; if(this->imageFolder != ""){
if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0; this->currentImageIndex++;
this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex]; if(this->currentImageIndex>=this->imageList.size()) this->currentImageIndex = 0;
ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0)); this->currentImagePath = this->imageFolder+"/"+this->imageList[this->currentImageIndex];
this->currentImage = QPixmap(this->currentImagePath); ui->label_3->setText("Nom actuel: "+this->imageList[this->currentImageIndex].split(".").at(0));
setImage(); this->currentImage = QPixmap(this->currentImagePath);
setImage();
}
}
void MainWindow::on_defaultPrefixEdit_textEdited()
{
defaultPrefix = ui->defautPrefixEdit->text();
ui->lineEdit->setText(defaultPrefix);
} }
...@@ -30,6 +30,8 @@ private slots: ...@@ -30,6 +30,8 @@ private slots:
void on_next_clicked(); void on_next_clicked();
void on_defaultPrefixEdit_textEdited();
private: private:
Ui::StickersRenomator2000 *ui; Ui::StickersRenomator2000 *ui;
QStringList imageList; QStringList imageList;
...@@ -37,6 +39,7 @@ private: ...@@ -37,6 +39,7 @@ private:
QString currentImagePath; QString currentImagePath;
QPixmap currentImage; QPixmap currentImage;
bool isFirstResize=true; bool isFirstResize=true;
QString defaultPrefix;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void keyPressEvent(QKeyEvent *event) override; void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent ( QMouseEvent * event ) override; void mousePressEvent ( QMouseEvent * event ) override;
......
...@@ -522,16 +522,6 @@ ...@@ -522,16 +522,6 @@
<item row="2" column="0"> <item row="2" column="0">
<widget class="QLineEdit" name="lineEdit"/> <widget class="QLineEdit" name="lineEdit"/>
</item> </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"> <item row="4" column="0">
<widget class="QPushButton" name="pushButton"> <widget class="QPushButton" name="pushButton">
<property name="text"> <property name="text">
...@@ -563,9 +553,72 @@ ...@@ -563,9 +553,72 @@
</property> </property>
</widget> </widget>
</item> </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>
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="QFrame" name="frame_3">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Config</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>111</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Default prefix:</string>
</property>
</widget>
<widget class="QLineEdit" name="defautPrefixEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>113</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter