@@ -1216,8 +1216,54 @@ void MainWindow::on_actionInterpret_As_triggered()
1216
1216
}
1217
1217
}
1218
1218
1219
+ void MainWindow::on_actionConvert_to_UTF_8_triggered ()
1220
+ {
1221
+ Document* activeDocument = qobject_cast<Document*>(ui->documentsTab ->currentWidget ());
1222
+ QString text = activeDocument->getEditorContent ();
1223
+ QByteArray utf8Data = text.toUtf8 ();
1224
+ QString utf8Text = QString::fromUtf8 (utf8Data);
1225
+ activeDocument->editor ()->setPlainText (utf8Text);
1226
+ }
1227
+
1228
+ void MainWindow::on_actionConvert_to_UTF_8_without_BOM_triggered ()
1229
+ {
1230
+ Document* activeDocument = qobject_cast<Document*>(ui->documentsTab ->currentWidget ());
1231
+ QString text = activeDocument->getEditorContent ();
1232
+ QByteArray utf8Data = text.toUtf8 ();
1233
+ // Remove the BOM if it exists
1234
+ if (utf8Data.startsWith (" \xEF\xBB\xBF " )) {
1235
+ utf8Data.remove (0 , 3 );
1236
+ }
1237
+ QString utf8Text = QString::fromUtf8 (utf8Data);
1238
+ activeDocument->editor ()->setPlainText (utf8Text);
1239
+ }
1219
1240
1220
1241
1242
+ void MainWindow::on_actionConvert_to_UTF_16BE_UCS_2_Big_Endian_triggered ()
1243
+ {
1244
+ Document* activeDocument = qobject_cast<Document*>(ui->documentsTab ->currentWidget ());
1245
+ QString text = activeDocument->getEditorContent ();
1246
+ QByteArray utf16BEData;
1247
+ QTextStream stream (&utf16BEData, QIODevice::WriteOnly);
1248
+ stream.setEncoding (QStringConverter::Encoding::Utf16BE); // Set encoding to UTF-16BE
1249
+ stream << text;
1250
+ stream.flush ();
1251
+ QString utf16BEText = QString::fromUtf16 (reinterpret_cast <const char16_t *>(utf16BEData.constData ()), utf16BEData.size () / 2 );
1252
+ activeDocument->editor ()->setPlainText (utf16BEText);
1253
+ }
1254
+
1255
+ void MainWindow::on_actionConvert_to_UTF_16LE_UCS_2_Little_Endian_triggered ()
1256
+ {
1257
+ Document* activeDocument = qobject_cast<Document*>(ui->documentsTab ->currentWidget ());
1258
+ QString text = activeDocument->getEditorContent ();
1259
+ QByteArray utf16LEData;
1260
+ QTextStream stream (&utf16LEData, QIODevice::WriteOnly);
1261
+ stream.setEncoding (QStringConverter::Encoding::Utf16LE); // Set encoding to UTF-16LE
1262
+ stream << text;
1263
+ stream.flush ();
1264
+ QString utf16LEText = QString::fromUtf16 (reinterpret_cast <const char16_t *>(utf16LEData.constData ()), utf16LEData.size () / 2 );
1265
+ activeDocument->editor ()->setPlainText (utf16LEText);
1266
+ }
1221
1267
1222
1268
1223
1269
@@ -1490,4 +1536,3 @@ void MainWindow::on_actionAbout_Qt_triggered()
1490
1536
QMessageBox::aboutQt (this , tr (" About Qt" ));
1491
1537
}
1492
1538
1493
-
0 commit comments