Browse Source

20220620 v1.0.1 新增功能

master
tianzhendong 2 years ago
parent
commit
b2c41d2df1
  1. 5
      README.md
  2. 22
      src/Rename.cpp
  3. 10
      src/Rename.h
  4. 52
      src/widget.cpp
  5. 8
      src/widget.h
  6. 19
      src/widget.ui
  7. BIN
      windeploy/FileRename.exe

5
README.md

@ -44,4 +44,9 @@ deploy目录下为生成的程序,可以直接使用
![](./assets/img_1.png)
## 更改日志
### 20220620 v1.0.1
- [x] 新增打开文件目录功能(右下角listwidget支持)
- [x] 新增删除文件功能(右下角listwidget支持)

22
src/Rename.cpp

@ -3,6 +3,7 @@
//
#include <QDateTime>
#include "Rename.h"
#include <QProcess>
Rename::Rename(QObject *) {
@ -121,3 +122,24 @@ void Rename::comboxStateChangedSlot(const QString & text) {
qDebug()<< renameMethodFlag;
}
void Rename::getTextSlot(const QString &text) {
qDebug()<<"widget当前的text为:"<< text;
currentText = text;
}
void Rename::openDirSlot() {
QFileInfo fileInfo(currentText);
QString filePath = fileInfo.absolutePath();
qDebug()<<"filePath"<<filePath;
QString path = filePath.replace("/", "\\");
qDebug()<<"path"<<path;
QProcess::startDetached("explorer " + path);
}
void Rename::delActionTriggeredSlot() {
QFile file(currentText);
qDebug()<<"即将删除:"<<currentText;
emit delActionFeedbackSignal(file.remove());
qDebug()<<"删除成功";
}

10
src/Rename.h

@ -23,9 +23,10 @@ signals:
void oldFileNameSignal(const QString &);
void newFileNameSignal(const QString &);
void process(const int &, const int &);
void singleFileSignal(const QString &);
void delActionFeedbackSignal(bool delFlag);
public slots:
@ -34,6 +35,10 @@ public slots:
void checkBoxChangedSlot(int );
void comboxStateChangedSlot(const QString &);
void openDirSlot();
void delActionTriggeredSlot();
void getTextSlot(const QString &text);
private:
void renameFile(const QString &filePath, const QString &strReplaced, const QString &strNew);
QStringList getFiles(const QString &);
@ -43,6 +48,9 @@ private:
QString renameMethodFlag = "替换";
QStringList dirFiles = QStringList();
QString currentText = "";
};

52
src/widget.cpp

@ -67,6 +67,24 @@ Widget::Widget(QWidget *parent)
connect(ui->btnConfirm, SIGNAL(clicked()),
this, SLOT(btnConfirmClickedSlot()));
ui->listWidget_2->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->listWidget_2, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(on_listWidget_customContextMenuRequested(const QPoint &)));
delAction = new QAction();
delAction->setText("删除文件");
openAction = new QAction();
openAction->setText("打开文件目录");
connect(delAction, SIGNAL(triggered(bool)),
renameFile, SLOT(delActionTriggeredSlot()));
connect(ui->listWidget_2, SIGNAL(currentTextChanged(const QString &)),
renameFile, SLOT(getTextSlot(const QString &)));
connect(openAction, SIGNAL(triggered(bool)),
renameFile, SLOT(openDirSlot()));
connect(renameFile, SIGNAL(delActionFeedbackSignal(bool)),
this, SLOT(delActionFeedbackSlot(bool)));
}
Widget::~Widget()
@ -74,6 +92,8 @@ Widget::~Widget()
renameFile->deleteLater();
myThread->exit();
myThread->wait(10 * 1000);
openAction->deleteLater();
delAction->deleteLater();
delete ui;
}
@ -194,6 +214,38 @@ void Widget::btnConfirmClickedSlot() {
confirmFlag = true;
}
void Widget::on_listWidget_customContextMenuRequested(const QPoint &pos)
{
// ui->listWidget_2->currentTextChanged()
QMenu *menu = new QMenu(this);
// menu->addAction(ui->actionAdd);
// menu->addAction(ui->actionClear);
// menu->addAction(ui->actionDelete);
// menu->addAction(ui->actionInsert);
menu->addAction(this->openAction);
menu->addAction(this->delAction);
// menu->addSeparator();
// menu->addAction(ui->actionInit);
// menu->addSeparator();
// menu->addAction(ui->actionSelAll);
// menu->addAction(ui->actionSelInv);
// menu->addAction(ui->actionSelNone);
// menu->addAction(ui->actionSelPopMenu);
menu->exec(QCursor::pos());
delete menu;
}
void Widget::delActionFeedbackSlot(bool flag) {
if(flag){
qDebug()<<"remove item";
QListWidgetItem * item = ui->listWidget_2->currentItem();
qDebug()<<item;
ui->listWidget_2->removeItemWidget(item);
delete item;
}
}

8
src/widget.h

@ -15,6 +15,7 @@
#include <QDebug>
#include <QThread>
#include <QFileDialog>
#include <QMenu>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
@ -45,6 +46,8 @@ public slots:
void oldFileNameSlot(const QString & oldName);
void newFileNameSlot(const QString & newName);
void delActionFeedbackSlot(bool flag);
private slots:
void btnMaxClickedSlot();
void btnMinClickedSlot();
@ -53,6 +56,8 @@ private slots:
void selectDirClickedSlot();
void btnConfirmClickedSlot();
void on_listWidget_customContextMenuRequested(const QPoint &pos);
private:
Ui::Widget *ui;
Rename * renameFile;
@ -61,6 +66,9 @@ private:
QPoint mousePosInWindow = QPoint();
bool confirmFlag = false;
QAction *delAction;
QAction *openAction;
};

19
src/widget.ui

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>950</width>
<height>668</height>
</rect>
</property>
<property name="windowTitle">
@ -508,10 +508,21 @@ QPushButton:pressed
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QListWidget" name="listWidget"/>
<widget class="QListWidget" name="listWidget">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListWidget" name="listWidget_2"/>
<widget class="QListWidget" name="listWidget_2">
<property name="enabled">
<bool>true</bool>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</widget>
</item>
</layout>
</item>

BIN
windeploy/FileRename.exe

Binary file not shown.
Loading…
Cancel
Save