Skip to content

Commit 8b88159

Browse files
committed
v0.0.101
1 parent 6b0e912 commit 8b88159

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
============
44

5+
## 0.0.101
6+
7+
- Implemented:
8+
- Encoding Menu -> convert to UTF-8, convert to UTF-8 without BOM, convert to UTF-16BE (UCS-2 big endian), UTF-16LE (UCS-2 little endian)
9+
510
## 0.0.100
611

712
- Implemented:

src/mainwindow.cpp

+46-1
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,54 @@ void MainWindow::on_actionInterpret_As_triggered()
12161216
}
12171217
}
12181218

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+
}
12191240

12201241

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+
}
12211267

12221268

12231269

@@ -1490,4 +1536,3 @@ void MainWindow::on_actionAbout_Qt_triggered()
14901536
QMessageBox::aboutQt(this, tr("About Qt"));
14911537
}
14921538

1493-

src/mainwindow.h

+8
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ private slots:
198198

199199
void on_actionInterpret_As_triggered();
200200

201+
void on_actionConvert_to_UTF_8_triggered();
202+
203+
void on_actionConvert_to_UTF_8_without_BOM_triggered();
204+
205+
void on_actionConvert_to_UTF_16BE_UCS_2_Big_Endian_triggered();
206+
207+
void on_actionConvert_to_UTF_16LE_UCS_2_Little_Endian_triggered();
208+
201209
private:
202210
Ui::MainWindow* ui;
203211
FileOperations* fileOperations;

src/mainwindow.ui

-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@
225225
<addaction name="actionInterpret_as_16_LE"/>
226226
<addaction name="actionInterpret_As"/>
227227
<addaction name="separator"/>
228-
<addaction name="action_Reload_file_interpreted_as"/>
229228
<addaction name="actionConvert_to_UTF_8"/>
230229
<addaction name="actionConvert_to_UTF_8_without_BOM"/>
231230
<addaction name="actionConvert_to_UTF_16BE_UCS_2_Big_Endian"/>

0 commit comments

Comments
 (0)