diff --git a/CMakeLists.txt b/CMakeLists.txt index 36cfc69..57f605a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) include_directories(3rd) +include_directories(src) set(PROJECT_SOURCES main.cpp MainWidget.cpp @@ -40,6 +41,7 @@ set(PROJECT_SOURCES resource/ico.rc src/attribute_edit.ui src/attribute_edit.h src/attribute_edit.cpp flatgray.qrc src/data_edit.h src/data_edit.cpp src/data_edit.ui + src/QCustomQLineEdit.h src/QCustomQLineEdit.cpp ) if (MSVC) diff --git a/MainWidget.cpp b/MainWidget.cpp index 4418d1f..ebb896f 100644 --- a/MainWidget.cpp +++ b/MainWidget.cpp @@ -961,11 +961,16 @@ bool MainWidget::format_xml() if (xml_path.empty()) { return false; } - if (!xml_.handle_save(xml_path)) { - CUtil::msg(this, u8"格式化失败"); + + if (!CUtil::affirm(this, u8"确认", u8"重排版内容将会覆盖源文件,请确认是否需要备份,继续?")) { return false; } - CUtil::msg(this, u8"格式化结束"); + + if (!xml_.handle_save(xml_path)) { + CUtil::msg(this, u8"重排版内容失败"); + return false; + } + CUtil::msg(this, u8"重排版内容结束"); return true; } diff --git a/MainWidget.ui b/MainWidget.ui index 03fae1c..e9a62e6 100644 --- a/MainWidget.ui +++ b/MainWidget.ui @@ -6,7 +6,7 @@ 0 0 - 1056 + 1102 682 @@ -35,7 +35,7 @@ - + @@ -57,7 +57,7 @@ - + 重排版 @@ -87,7 +87,7 @@ - Qt::Orientation::Vertical + Qt::Vertical @@ -142,7 +142,7 @@ - Qt::Orientation::Vertical + Qt::Vertical @@ -227,9 +227,6 @@ - - Qt::Orientation::Horizontal - 40 @@ -247,9 +244,6 @@ - - Qt::Orientation::Horizontal - 40 @@ -329,6 +323,13 @@ + + + QCustomQLineEdit + QLineEdit +
QCustomQLineEdit.h
+
+
btnSelectFile edStatus diff --git a/src/QCustomQLineEdit.cpp b/src/QCustomQLineEdit.cpp new file mode 100644 index 0000000..7b4cab4 --- /dev/null +++ b/src/QCustomQLineEdit.cpp @@ -0,0 +1,36 @@ +#include "QCustomQLineEdit.h" + +QCustomQLineEdit::QCustomQLineEdit(QWidget* parent) : QLineEdit(parent) +{ + setAcceptDrops(true); +} + +void QCustomQLineEdit::dragEnterEvent(QDragEnterEvent* event) +{ + if (event->mimeData()->hasUrls()) { + event->acceptProposedAction(); + } + QLineEdit::dragEnterEvent(event); +} + +void QCustomQLineEdit::dragMoveEvent(QDragMoveEvent* event) +{ +} + +void QCustomQLineEdit::dropEvent(QDropEvent* event) +{ + const QMimeData* mimeData = event->mimeData(); + if (mimeData->hasUrls()) { + QList urls = mimeData->urls(); + if (urls.size() > 0) { + QString file_name = urls.at(0).toLocalFile(); + setText(file_name); + event->accept(); + } + } + QLineEdit::dropEvent(event); +} + +QCustomQLineEdit::~QCustomQLineEdit() +{ +} diff --git a/src/QCustomQLineEdit.h b/src/QCustomQLineEdit.h new file mode 100644 index 0000000..b1bef6f --- /dev/null +++ b/src/QCustomQLineEdit.h @@ -0,0 +1,27 @@ +#ifndef QCUSTOMQLINE +#define QCUSTOMQLINE + +#include + +#include +#include +#include + +class QCustomQLineEdit : public QLineEdit +{ + Q_OBJECT + +public: + QCustomQLineEdit(QWidget* parent = nullptr); + ~QCustomQLineEdit() override; + +protected: + // 拖动文件到窗口 触发 + void dragEnterEvent(QDragEnterEvent* event); + // 拖动文件到窗口移动文件 触发 + void dragMoveEvent(QDragMoveEvent* event); + // 拖动文件到窗口释放文件触发 + void dropEvent(QDropEvent* event); +}; + +#endif \ No newline at end of file