Skip to content

add insert table button #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/OneMarkdown.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "OneMarkdown.h"
#include "./ui_OneMarkdown.h"
//#include "OneMarkdown.h"
#include "OneMarkdown.h"
auto parser = std::make_shared<maddy::Parser>();

// std::string html_head = readFileIntoString("index.html");
Expand Down Expand Up @@ -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|<table");
}
4 changes: 4 additions & 0 deletions src/OneMarkdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common.h"
#include <QPropertyAnimation>
#include <QMessageBox>
#include "table.h"
#pragma execution_character_set("utf-8")
QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/OneMarkdown.ui
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ QToolButton:hover {
<property name="title">
<string>表格</string>
</property>
<addaction name="action_173"/>
<addaction name="action_insert_table"/>
<addaction name="separator"/>
<addaction name="action_175"/>
<addaction name="action_176"/>
Expand Down Expand Up @@ -1952,7 +1952,7 @@ QToolButton:hover {
<string>Ctrl+H</string>
</property>
</action>
<action name="action_173">
<action name="action_insert_table">
<property name="text">
<string>插入表格</string>
</property>
Expand Down
28 changes: 28 additions & 0 deletions src/table.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "table.h"
#include "ui_table.h"
#include "table.h"
/*#include <iostream>
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();
}

28 changes: 28 additions & 0 deletions src/table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef TABLE_H
#define TABLE_H

#include <QWidget>

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
122 changes: 122 additions & 0 deletions src/table.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>table</class>
<widget class="QWidget" name="table">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>131</height>
</rect>
</property>
<property name="windowTitle">
<string>插入表格</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="column">
<property name="text">
<string>列</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="row_lineEdit">
<property name="text">
<string>3</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="row">
<property name="text">
<string>行</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="column_lineEdit">
<property name="text">
<string>4</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="cancel_Button">
<property name="text">
<string>取消</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="certify_Button">
<property name="text">
<string>确定</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>