优化选中文本分行插入td、tr、p、h1~h6的工具
This commit is contained in:
parent
0d384780f9
commit
7fc3e7551a
|
@ -21,6 +21,7 @@
|
|||
#include <QMdiSubWindow>
|
||||
#include <QDateTime>
|
||||
#include <QTextBlock>
|
||||
#include <QComboBox>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
@ -28,12 +29,19 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
settings(QCoreApplication::organizationName(), QCoreApplication::applicationName())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
move((QApplication::desktop()->width() - width())/2, (QApplication::desktop()->height() - height())/2);
|
||||
|
||||
QComboBox *comboBox = new QComboBox;
|
||||
QStringList SL;
|
||||
SL << "h1" << "h2" << "h3" << "h4" << "h5" << "h6";
|
||||
comboBox->addItems(SL);
|
||||
connect(comboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(comboBoxHChanged(QString)));
|
||||
ui->mainToolBar->addWidget(comboBox);
|
||||
|
||||
lineEdit_command = new QLineEdit;
|
||||
lineEdit_command->setFixedWidth(300);
|
||||
lineEdit_command->setPlaceholderText("命令");
|
||||
ui->mainToolBar->addWidget(lineEdit_command);
|
||||
|
||||
ui->textBrowser->hide();
|
||||
|
||||
LS1 = new QLabel("欢迎使用海天鹰编辑器!");
|
||||
|
@ -113,7 +121,7 @@ void MainWindow::on_action_about_triggered()
|
|||
|
||||
void MainWindow::on_action_changelog_triggered()
|
||||
{
|
||||
QString s = "1.10\n2019-06\nHTML排版,增加选中文本前后插入<td>、<tr>、<p>的工具。\n\n1.9\n2019-04\n便签右键菜单增加打开文件路径。\n换行自动缩进。\n快捷键 Ctrl+/ 注释、取消注释选中行。\n保存窗口大小,保存字体设置,设置是否显示输出窗口。\n\n1.8\n2018-11\n使用系统主题图标代替Qt内置图标。\n\n1.7\n2018-10\n支持拖放打开多个文件。\n增加打开文件log。\n打开方式文件路径兼容深度文管和其他文管。\n\n1.6\n2018-09\n标签右键增加只读菜单。\n优化括号补全。\n\n1.5\n2018-08\n增加行号\n增加java文件编译命令\n\n1.4\n2018-07\n设置QTextEdit的Tab跳过的空格数为4个空格\n\n1.3\n2018-06\n增加调试窗口。\n\n1.2\n2018-05\n增加c、cpp的OpenGL编译命令。\n2018-05\n解决右键打开方式无法打开文件问题。\n增加运行python。\n2018-04\n增加打印功能。\n\n1.1\n2017-10\n增加获取文本编码(使用 file --mime-encoding 命令返回),但是没有解决乱码问题。\n排版实验。\n用文本框代替消息框显示更新日志。\n2017-07\n增加拖放打开文件。\n2017-06\n增加语法高亮。\n提取打开文件的相对路径,使Markdown预览能够载入相对路径图片。\n\n1.0\n2017-03\n支持命令行打开文件和打开方式打开文件。\n查找窗口填入选中文本。\n2017-02\n根据文件扩展名选择语法高亮方案。\nJS语法高亮实验成功!\nHTML语法高亮实验成功!\n增加设置字体。\n设置状态栏左右边距。\n2017-01\n实现全部替换。\n设置循环查找。\n增加查找替换窗体和功能。\n根据文件扩展名决定是否使用默认程序打开,如htm。\n优化保存、另存为和文本修动标题标记逻辑。\n增加撤销,重做,子窗标题文本改动标识。\n增加子窗体类,实现Ctrl+滚轮缩放和保存打开文件的路径。\n增加使用默认程序预览文件。\n把上一个打开或保存的路径设置为打开或保存对话框的默认路径和文件名。\n增加放大、缩小。\n增加文本光标变化信号,光标所在行列显示在状态栏第二栏。\n状态栏分为2栏\n修复没有子窗口时预览引起的崩溃。\n增加预览功能。\n保存成功。\n修改字体颜色,背景色成功。\n新建文件成功,打开文件载入成功。\n选用QMdiArea作为主控件,增加窗口标签、平铺、层叠菜单。 \n制作主要菜单。";
|
||||
QString s = "1.10\n2019-08\nHTML排版,增加选中文本分行插入td、tr、p、h1~h6的工具。\n\n1.9\n2019-04\n便签右键菜单增加打开文件路径。\n换行自动缩进。\n快捷键 Ctrl+/ 注释、取消注释选中行。\n保存窗口大小,保存字体设置,设置是否显示输出窗口。\n\n1.8\n2018-11\n使用系统主题图标代替Qt内置图标。\n\n1.7\n2018-10\n支持拖放打开多个文件。\n增加打开文件log。\n打开方式文件路径兼容深度文管和其他文管。\n\n1.6\n2018-09\n标签右键增加只读菜单。\n优化括号补全。\n\n1.5\n2018-08\n增加行号\n增加java文件编译命令\n\n1.4\n2018-07\n设置QTextEdit的Tab跳过的空格数为4个空格\n\n1.3\n2018-06\n增加调试窗口。\n\n1.2\n2018-05\n增加c、cpp的OpenGL编译命令。\n2018-05\n解决右键打开方式无法打开文件问题。\n增加运行python。\n2018-04\n增加打印功能。\n\n1.1\n2017-10\n增加获取文本编码(使用 file --mime-encoding 命令返回),但是没有解决乱码问题。\n排版实验。\n用文本框代替消息框显示更新日志。\n2017-07\n增加拖放打开文件。\n2017-06\n增加语法高亮。\n提取打开文件的相对路径,使Markdown预览能够载入相对路径图片。\n\n1.0\n2017-03\n支持命令行打开文件和打开方式打开文件。\n查找窗口填入选中文本。\n2017-02\n根据文件扩展名选择语法高亮方案。\nJS语法高亮实验成功!\nHTML语法高亮实验成功!\n增加设置字体。\n设置状态栏左右边距。\n2017-01\n实现全部替换。\n设置循环查找。\n增加查找替换窗体和功能。\n根据文件扩展名决定是否使用默认程序打开,如htm。\n优化保存、另存为和文本修动标题标记逻辑。\n增加撤销,重做,子窗标题文本改动标识。\n增加子窗体类,实现Ctrl+滚轮缩放和保存打开文件的路径。\n增加使用默认程序预览文件。\n把上一个打开或保存的路径设置为打开或保存对话框的默认路径和文件名。\n增加放大、缩小。\n增加文本光标变化信号,光标所在行列显示在状态栏第二栏。\n状态栏分为2栏\n修复没有子窗口时预览引起的崩溃。\n增加预览功能。\n保存成功。\n修改字体颜色,背景色成功。\n新建文件成功,打开文件载入成功。\n选用QMdiArea作为主控件,增加窗口标签、平铺、层叠菜单。 \n制作主要菜单。";
|
||||
QDialog *dialog = new QDialog;
|
||||
dialog->setWindowTitle("更新历史");
|
||||
dialog->setFixedSize(400, 300);
|
||||
|
@ -723,12 +731,12 @@ void MainWindow::anchorClick(QUrl url)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_td_triggered()
|
||||
void MainWindow::on_action_h1_triggered()
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
if(window != 0){
|
||||
MdiChild *child = (MdiChild*)(window->widget());
|
||||
child->insertTD();
|
||||
child->insertH1();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -741,6 +749,15 @@ void MainWindow::on_action_tr_triggered()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_td_triggered()
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
if(window != 0){
|
||||
MdiChild *child = (MdiChild*)(window->widget());
|
||||
child->insertTD();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_p_triggered()
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
|
@ -748,4 +765,13 @@ void MainWindow::on_action_p_triggered()
|
|||
MdiChild *child = (MdiChild*)(window->widget());
|
||||
child->insertP();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::comboBoxHChanged(QString s)
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
if(window != 0){
|
||||
MdiChild *child = (MdiChild*)(window->widget());
|
||||
child->insertH(s);
|
||||
}
|
||||
}
|
|
@ -61,8 +61,9 @@ private slots:
|
|||
void on_action_find_triggered();
|
||||
void on_action_indent_triggered();
|
||||
void on_action_font_triggered();
|
||||
void on_action_td_triggered();
|
||||
void on_action_h1_triggered();
|
||||
void on_action_tr_triggered();
|
||||
void on_action_td_triggered();
|
||||
void on_action_p_triggered();
|
||||
void find();
|
||||
void replace();
|
||||
|
@ -74,6 +75,8 @@ private slots:
|
|||
void printOutput();
|
||||
void printError();
|
||||
void anchorClick(QUrl url);
|
||||
void comboBoxHChanged(QString s);
|
||||
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
#endif // MAINWINDOW_H
|
|
@ -146,8 +146,8 @@
|
|||
</attribute>
|
||||
<addaction name="action_font"/>
|
||||
<addaction name="action_run"/>
|
||||
<addaction name="action_td"/>
|
||||
<addaction name="action_tr"/>
|
||||
<addaction name="action_td"/>
|
||||
<addaction name="action_p"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
|
@ -450,7 +450,7 @@
|
|||
</action>
|
||||
<action name="action_td">
|
||||
<property name="text">
|
||||
<string><td></string>
|
||||
<string>td</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ctrl+Shift+D</string>
|
||||
|
@ -461,7 +461,7 @@
|
|||
</action>
|
||||
<action name="action_tr">
|
||||
<property name="text">
|
||||
<string><tr></string>
|
||||
<string>tr</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ctrl+Shift+R</string>
|
||||
|
@ -472,7 +472,7 @@
|
|||
</action>
|
||||
<action name="action_p">
|
||||
<property name="text">
|
||||
<string><p></string>
|
||||
<string>p</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ctrl+Alt+P</string>
|
||||
|
@ -484,6 +484,11 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_h1">
|
||||
<property name="text">
|
||||
<string>h1</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
68
mdichild.cpp
68
mdichild.cpp
|
@ -228,23 +228,77 @@ void MdiChild::setReadOnlyA(bool b)
|
|||
setReadOnly(b);
|
||||
}
|
||||
|
||||
void MdiChild::insertTD()
|
||||
void MdiChild::insertH1()
|
||||
{
|
||||
QString s = textCursor().selectedText();
|
||||
s = "<td>" + s + "</td>";
|
||||
QString s = textCursor().selection().toPlainText(); //可以显示换行符
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for(int i=0; i<SL.length(); i++){
|
||||
if(SL.at(i) != ""){
|
||||
s += "<h1>" + SL.at(i) + "</h1>";
|
||||
if(i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertH(QString h)
|
||||
{
|
||||
QString s = textCursor().selection().toPlainText(); //可以显示换行符
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for(int i=0; i<SL.length(); i++){
|
||||
if(SL.at(i) != ""){
|
||||
s += "<" + h +">" + SL.at(i) + "</" + h + ">";
|
||||
if(i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertTR()
|
||||
{
|
||||
QString s = textCursor().selectedText();
|
||||
s = "<tr>" + s + "</tr>";
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for(int i=0; i<SL.length(); i++){
|
||||
if(SL.at(i) != ""){
|
||||
s += "<tr>" + SL.at(i) + "</tr>";
|
||||
if(i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertTD()
|
||||
{
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for(int i=0; i<SL.length(); i++){
|
||||
if(SL.at(i) != ""){
|
||||
s += "<td>" + SL.at(i) + "</td>";
|
||||
if(i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertP()
|
||||
{
|
||||
QString s = textCursor().selectedText();
|
||||
s = "<p>" + s + "</p>";
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for(int i=0; i<SL.length(); i++){
|
||||
if(SL.at(i) != ""){
|
||||
s += "<p>" + SL.at(i) + "</p>";
|
||||
if(i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
|
@ -16,8 +16,10 @@ public:
|
|||
QString path, scodec;
|
||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||
int lineNumberAreaWidth();
|
||||
void insertTD();
|
||||
void insertH1();
|
||||
void insertH(QString h);
|
||||
void insertTR();
|
||||
void insertTD();
|
||||
void insertP();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue