| 302 | } |
| 303 | |
| 304 | bool TextEditorPrivate::readFile(const QString &encode) |
| 305 | { |
| 306 | QFile file(fileName); |
| 307 | if (file.open(QIODevice::ReadOnly)) { |
| 308 | QByteArray fileContent = file.readAll(); |
| 309 | QString newEncode = encode; |
| 310 | if (newEncode.isEmpty()) |
| 311 | newEncode = DetectCode::getFileEncodingFormat(fileName, fileContent.left(1024 * 1024)); |
| 312 | |
| 313 | QByteArray outData; |
| 314 | DetectCode::changeFileEncodingFormat(fileContent, outData, newEncode, QString("UTF-8")); |
| 315 | if (outData.isEmpty()) { |
| 316 | outData = fileContent; |
| 317 | newEncode = "UTF-8"; |
| 318 | } |
| 319 | q->setText(outData); |
| 320 | file.close(); |
| 321 | documentEncode = newEncode; |
| 322 | q->setModified(false); |
| 323 | return true; |
| 324 | } |
| 325 | return false; |
| 326 | } |
| 327 | |
| 328 | int TextEditorPrivate::cursorPosition() const |
| 329 | { |