diff --git a/src/OneMarkdown.cpp b/src/OneMarkdown.cpp index 2c741dd..b06b22e 100644 --- a/src/OneMarkdown.cpp +++ b/src/OneMarkdown.cpp @@ -1,6 +1,6 @@ #include "OneMarkdown.h" #include "./ui_OneMarkdown.h" -//#include "OneMarkdown.h" +#include "OneMarkdown.h" auto parser = std::make_shared(); // std::string html_head = readFileIntoString("index.html"); @@ -485,3 +485,34 @@ void OneMarkdown::on_action_58_triggered() } } + +void OneMarkdown::on_action_insert_table_triggered() +{ + table *t = new table(); + t -> show(); + disconnect(t, &table::textEntered, this, &OneMarkdown::table_TextEntered); // 断开之前的连接 + connect(t, &table::textEntered, this, &OneMarkdown::table_TextEntered); +} + +void OneMarkdown::table_TextEntered(const QString& text1, const QString& text2) +{ + QTextCursor cursor(ui->textEdit->textCursor()); // 获取当前文本编辑器的光标 + + // 获取当前行的文本 + cursor.movePosition(QTextCursor::StartOfLine); + QString lineText = cursor.block().text(); + + if(!lineText.isEmpty()) + { + cursor.movePosition(QTextCursor::EndOfLine); // 移动光标到当前行的结尾 + cursor.insertBlock(); // 在当前行的下一行插入一个空行 + cursor.insertBlock(); + ui->textEdit->setTextCursor(cursor); // 设置新的光标位置 + } + cursor.insertText("|table>\n"); + QString tableLine = QString("|").repeated(text2.toInt()) + QString("\n"); + for (int i = 0; i < text1.toInt(); i++) { + cursor.insertText(tableLine); + } + cursor.insertText("\n| #include +#include "table.h" #pragma execution_character_set("utf-8") QT_BEGIN_NAMESPACE @@ -90,6 +91,9 @@ private slots: void on_action_save_as_triggered(); + void on_action_insert_table_triggered(); + + void table_TextEntered(const QString& text1, const QString& text2); private: int WORD_NUM = 0; diff --git a/src/OneMarkdown.ui b/src/OneMarkdown.ui index 7ee7d8d..166b3d5 100644 --- a/src/OneMarkdown.ui +++ b/src/OneMarkdown.ui @@ -792,7 +792,7 @@ QToolButton:hover { 表格 - + @@ -1952,7 +1952,7 @@ QToolButton:hover { Ctrl+H - + 插入表格 diff --git a/src/table.cpp b/src/table.cpp new file mode 100644 index 0000000..1a3f8f8 --- /dev/null +++ b/src/table.cpp @@ -0,0 +1,28 @@ +#include "table.h" +#include "ui_table.h" +#include "table.h" +/*#include +using namespace std;*/ +table::table(QWidget *parent) : + QWidget(parent), + ui(new Ui::table) +{ + ui->setupUi(this); + connect(ui->cancel_Button,&QPushButton::clicked,this,&table::close); +// connect(ui->certify_Button,&QPushButton::clicked,this,&table::on_certify_Button_clicked); +} + +table::~table() +{ + delete ui; +} + +void table::on_certify_Button_clicked() +{ + QString col_text = ui->column_lineEdit->text(); + QString row_text = ui->row_lineEdit->text(); + + emit textEntered(col_text, row_text); + close(); +} + diff --git a/src/table.h b/src/table.h new file mode 100644 index 0000000..e7ed363 --- /dev/null +++ b/src/table.h @@ -0,0 +1,28 @@ +#ifndef TABLE_H +#define TABLE_H + +#include + +namespace Ui { +class table; +} + +class table : public QWidget +{ + Q_OBJECT + +public: + explicit table(QWidget *parent = nullptr); + ~table(); + +signals: + void textEntered(const QString& text1, const QString& text2); + +private slots: + void on_certify_Button_clicked(); + +private: + Ui::table *ui; +}; + +#endif // TABLE_H diff --git a/src/table.ui b/src/table.ui new file mode 100644 index 0000000..7a46d73 --- /dev/null +++ b/src/table.ui @@ -0,0 +1,122 @@ + + + table + + + + 0 + 0 + 400 + 131 + + + + 插入表格 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + + + 3 + + + + + + + + + + + + + + 4 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 取消 + + + + + + + 确定 + + + + + + + + + + + + + +