增加去除链接
This commit is contained in:
parent
2642030230
commit
e464d9f23d
|
@ -780,6 +780,15 @@ void MainWindow::on_action_a_triggered()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_action_img_triggered()
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
if(window != 0){
|
||||
MdiChild *child = (MdiChild*)(window->widget());
|
||||
child->insertImg(lineEdit_command->text());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::comboBoxHChanged(QString s)
|
||||
{
|
||||
QMdiSubWindow *window = ui->mdiArea->currentSubWindow();
|
||||
|
|
|
@ -66,6 +66,7 @@ private slots:
|
|||
void on_action_p_triggered();
|
||||
void on_action_div_triggered();
|
||||
void on_action_a_triggered();
|
||||
void on_action_img_triggered();
|
||||
void find();
|
||||
void replace();
|
||||
void replaceAll();
|
||||
|
|
|
@ -151,6 +151,7 @@
|
|||
<addaction name="action_p"/>
|
||||
<addaction name="action_div"/>
|
||||
<addaction name="action_a"/>
|
||||
<addaction name="action_img"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="action_new">
|
||||
|
@ -511,6 +512,17 @@
|
|||
<string>Ctrl+Shift+A</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="action_img">
|
||||
<property name="text">
|
||||
<string>img</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Ctrl+Shift+I</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+Shift+I</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
49
mdichild.cpp
49
mdichild.cpp
|
@ -80,8 +80,7 @@ bool MdiChild::loadFile(QString filename)
|
|||
bool MdiChild::save()
|
||||
{
|
||||
QFile file(path);
|
||||
if(file.open(QFile::WriteOnly))
|
||||
{
|
||||
if (file.open(QFile::WriteOnly)) {
|
||||
QTextStream ts(&file);
|
||||
QString s = toPlainText();
|
||||
ts << s;
|
||||
|
@ -90,7 +89,7 @@ bool MdiChild::save()
|
|||
setWindowTitle(QFileInfo(path).fileName() + "[*]");
|
||||
setWindowModified(false);
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
QMessageBox::warning(this,"错误", QString(" %1:\n%2").arg(path).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
@ -299,14 +298,14 @@ void MdiChild::insertP()
|
|||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertDIV(QString s1)
|
||||
void MdiChild::insertDIV(QString se)
|
||||
{
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for (int i=0; i<SL.length(); i++) {
|
||||
if (SL.at(i) != "") {
|
||||
s += "<div" + s1 + ">" + SL.at(i) + "</div>";
|
||||
s += "<div" + se + ">" + SL.at(i) + "</div>";
|
||||
if (i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
|
@ -314,18 +313,38 @@ void MdiChild::insertDIV(QString s1)
|
|||
textCursor().insertText(s);
|
||||
}
|
||||
|
||||
void MdiChild::insertA(QString s1)
|
||||
void MdiChild::insertA(QString se)
|
||||
{
|
||||
//正则去链接("/<a[^>]*>(.*?)<\/a>/is", "$1")
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for (int i=0; i<SL.length(); i++) {
|
||||
if (SL.at(i) != "") {
|
||||
s += "<a " + s1 + ">" + SL.at(i) + "</a>";
|
||||
if (i < SL.length()-1)
|
||||
s += "\n";
|
||||
|
||||
if(s.contains("<a>") || s.contains("</a>")){
|
||||
//正则去链接
|
||||
s.replace(QRegularExpression("<a(.*?)>(.*)</a>"), "\\2");
|
||||
textCursor().insertText(s);
|
||||
} else {
|
||||
QStringList SL = s.split("\n");
|
||||
s = "";
|
||||
for (int i=0; i<SL.length(); i++) {
|
||||
if (SL.at(i) != "") {
|
||||
s += "<a " + se + ">" + SL.at(i) + "</a>";
|
||||
if (i < SL.length()-1)
|
||||
s += "\n";
|
||||
}
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
}
|
||||
|
||||
void MdiChild::insertImg(QString se)
|
||||
{
|
||||
QString s = textCursor().selection().toPlainText();
|
||||
|
||||
if(s.contains("<img")){
|
||||
//正则去img除src以外属性,失败
|
||||
s.replace(QRegularExpression("<img(.*?)src=([^\\s]*?)>"), "<img src=\\2");
|
||||
textCursor().insertText(s);
|
||||
} else {
|
||||
s = "<img src=\"" + se + "\">";
|
||||
textCursor().insertText(s);
|
||||
}
|
||||
textCursor().insertText(s);
|
||||
}
|
|
@ -20,8 +20,9 @@ public:
|
|||
void insertTR();
|
||||
void insertTD();
|
||||
void insertP();
|
||||
void insertDIV(QString s1);
|
||||
void insertA(QString s1);
|
||||
void insertDIV(QString se);
|
||||
void insertA(QString se);
|
||||
void insertImg(QString se);
|
||||
|
||||
private:
|
||||
QSettings settings;
|
||||
|
|
Loading…
Reference in New Issue