Loading editor/qml/HtmlEditorField.qml +57 −4 Original line number Diff line number Diff line Loading @@ -142,10 +142,20 @@ ColumnLayout { } CheckBox { id: tableHeaderCheck; text: qsTr("Include header row"); checked: true } RowLayout { spacing: 6 Label { text: qsTr("Border:") } ComboBox { id: tableBorderCombo implicitWidth: 150 model: ["1px solid #ccc", "1px solid #000", "2px solid #000", "1px dashed #ccc", "1px dotted #999", "none"] } } Button { text: qsTr("Insert Table") onClicked: { insertTable(tableRowsSpin.value, tableColsSpin.value, tableHeaderCheck.checked) insertTable(tableRowsSpin.value, tableColsSpin.value, tableHeaderCheck.checked, tableBorderCombo.currentText) tablePopup.close() } } Loading @@ -166,6 +176,20 @@ ColumnLayout { text: qsTr("Remove Table") onClicked: { tableRemove(); tablePopup.close() } } RowLayout { spacing: 6 Label { text: qsTr("Set Border:") } ComboBox { id: tableBorderModCombo implicitWidth: 150 model: ["1px solid #ccc", "1px solid #000", "2px solid #000", "1px dashed #ccc", "1px dotted #999", "none"] } Button { text: qsTr("Apply") onClicked: { tableSetBorder(tableBorderModCombo.currentText); tablePopup.close() } } } } } } Loading Loading @@ -487,13 +511,15 @@ ColumnLayout { root.textChangedByUser(root.rawMode ? newHtml : stripQtArtifacts(newHtml)) } function insertTable(rows, cols, hasHeader) { function insertTable(rows, cols, hasHeader, borderStyle) { var border = borderStyle || "1px solid #ccc" var cellBorder = border === "none" ? "border:none;" : "border:" + border + ";" var html = "<table style=\"border-collapse:collapse; width:100%;\">" var startRow = 0 if (hasHeader) { html += "<thead><tr>" for (var c = 0; c < cols; c++) html += "<th style=\"border:1px solid #ccc; padding:8px;\">Header " + (c + 1) + "</th>" html += "<th style=\"" + cellBorder + " padding:8px;\">Header " + (c + 1) + "</th>" html += "</tr></thead>" startRow = 0 } Loading @@ -501,7 +527,7 @@ ColumnLayout { for (var r = 0; r < rows; r++) { html += "<tr>" for (var c2 = 0; c2 < cols; c2++) html += "<td style=\"border:1px solid #ccc; padding:8px;\">-</td>" html += "<td style=\"" + cellBorder + " padding:8px;\">-</td>" html += "</tr>" } html += "</tbody></table>" Loading Loading @@ -646,4 +672,31 @@ ColumnLayout { _switching = false root.textChangedByUser(newHtml) } function tableSetBorder(borderStyle) { var html = root.rawMode ? editorArea.text : stripQtArtifacts(editorArea.text) if (html.indexOf("<table") < 0) return var newBorder = borderStyle === "none" ? "border:none" : "border:" + borderStyle // Replace border in all <td> and <th> style attributes var newHtml = html.replace(/(<t[dh]\s[^>]*style\s*=\s*")([^"]*)(">)/gi, function(match, pre, style, post) { var updated = style.replace(/border\s*:[^;"]*/gi, newBorder) if (updated === style) { // No existing border found, prepend it updated = newBorder + "; " + style } return pre + updated + post }) _switching = true if (root.rawMode) { editorArea.text = newHtml } else { editorArea.textFormat = TextEdit.RichText editorArea.text = newHtml } _switching = false root.textChangedByUser(newHtml) } } Loading
editor/qml/HtmlEditorField.qml +57 −4 Original line number Diff line number Diff line Loading @@ -142,10 +142,20 @@ ColumnLayout { } CheckBox { id: tableHeaderCheck; text: qsTr("Include header row"); checked: true } RowLayout { spacing: 6 Label { text: qsTr("Border:") } ComboBox { id: tableBorderCombo implicitWidth: 150 model: ["1px solid #ccc", "1px solid #000", "2px solid #000", "1px dashed #ccc", "1px dotted #999", "none"] } } Button { text: qsTr("Insert Table") onClicked: { insertTable(tableRowsSpin.value, tableColsSpin.value, tableHeaderCheck.checked) insertTable(tableRowsSpin.value, tableColsSpin.value, tableHeaderCheck.checked, tableBorderCombo.currentText) tablePopup.close() } } Loading @@ -166,6 +176,20 @@ ColumnLayout { text: qsTr("Remove Table") onClicked: { tableRemove(); tablePopup.close() } } RowLayout { spacing: 6 Label { text: qsTr("Set Border:") } ComboBox { id: tableBorderModCombo implicitWidth: 150 model: ["1px solid #ccc", "1px solid #000", "2px solid #000", "1px dashed #ccc", "1px dotted #999", "none"] } Button { text: qsTr("Apply") onClicked: { tableSetBorder(tableBorderModCombo.currentText); tablePopup.close() } } } } } } Loading Loading @@ -487,13 +511,15 @@ ColumnLayout { root.textChangedByUser(root.rawMode ? newHtml : stripQtArtifacts(newHtml)) } function insertTable(rows, cols, hasHeader) { function insertTable(rows, cols, hasHeader, borderStyle) { var border = borderStyle || "1px solid #ccc" var cellBorder = border === "none" ? "border:none;" : "border:" + border + ";" var html = "<table style=\"border-collapse:collapse; width:100%;\">" var startRow = 0 if (hasHeader) { html += "<thead><tr>" for (var c = 0; c < cols; c++) html += "<th style=\"border:1px solid #ccc; padding:8px;\">Header " + (c + 1) + "</th>" html += "<th style=\"" + cellBorder + " padding:8px;\">Header " + (c + 1) + "</th>" html += "</tr></thead>" startRow = 0 } Loading @@ -501,7 +527,7 @@ ColumnLayout { for (var r = 0; r < rows; r++) { html += "<tr>" for (var c2 = 0; c2 < cols; c2++) html += "<td style=\"border:1px solid #ccc; padding:8px;\">-</td>" html += "<td style=\"" + cellBorder + " padding:8px;\">-</td>" html += "</tr>" } html += "</tbody></table>" Loading Loading @@ -646,4 +672,31 @@ ColumnLayout { _switching = false root.textChangedByUser(newHtml) } function tableSetBorder(borderStyle) { var html = root.rawMode ? editorArea.text : stripQtArtifacts(editorArea.text) if (html.indexOf("<table") < 0) return var newBorder = borderStyle === "none" ? "border:none" : "border:" + borderStyle // Replace border in all <td> and <th> style attributes var newHtml = html.replace(/(<t[dh]\s[^>]*style\s*=\s*")([^"]*)(">)/gi, function(match, pre, style, post) { var updated = style.replace(/border\s*:[^;"]*/gi, newBorder) if (updated === style) { // No existing border found, prepend it updated = newBorder + "; " + style } return pre + updated + post }) _switching = true if (root.rawMode) { editorArea.text = newHtml } else { editorArea.textFormat = TextEdit.RichText editorArea.text = newHtml } _switching = false root.textChangedByUser(newHtml) } }