diff --git a/mainwindow.cpp b/mainwindow.cpp index 02fd3c9..02918c7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -161,9 +161,40 @@ void MainWindow::onAppendText(QString text, QString suffix) { } Utils::printLineEditInfo(editText.split('\n')); - ui->updateStatus->setPlainText(editText.trimmed()); - ui->updateStatus->setEnabled(true); + scrollDownTextEdit(); +} + +void MainWindow::onReplaceLast(QStringList newTextLines, QString suffix) { + int const s = newTextLines.size(); + if (s > 0) { + QString editText = ui->updateStatus->toPlainText(); + QStringList lines = editText.split('\n'); + QString newText; + if (lines.size() >= s) { + for (int i = 0; i < s; ++i) { + lines.removeLast(); + } + if (lines.size() > 0) { + newText = lines.join('\n'); + newText += '\n'; + } + QStringList newLines; + for (int i = 0; i < s; ++i) { + if (i == 0 && !suffix.isNull() && suffix.size() > 0 && suffix != "\n") { + newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10) + suffix); + } else { + newLines += Utils::rstrip(newTextLines.at(i).leftJustified(m_width-10)); + } + } + lines += newLines; + newText += newLines.join(' '); + } + + ui->updateStatus->setText(newText); + Utils::printLineEditInfo(lines); + scrollDownTextEdit(); + } } void MainWindow::onReplaceLast(QString text, QString suffix) { diff --git a/mainwindow.h b/mainwindow.h index c217a3a..5dcef5b 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -27,6 +27,7 @@ public: public slots: void onAppendText(QString, QString suffix = ""); + void onReplaceLast(QStringList, QString suffix = ""); void onReplaceLast(QString, QString suffix = ""); void onShowErrorMessage(QString, QString); void onStopStartTimer();