feat(cpn): improve flashing messages (#6588)
This commit is contained in:
@@ -97,7 +97,7 @@ void ProgressWidget::setValue(int value)
|
||||
ui->progressBar->setValue(value);
|
||||
}
|
||||
|
||||
void ProgressWidget::addText(const QString &text, const bool richText)
|
||||
void ProgressWidget::addText(const QString &text, const bool richText, const bool updateLast)
|
||||
{
|
||||
if (!m_hasDetails) {
|
||||
m_hasDetails = true;
|
||||
@@ -105,6 +105,21 @@ void ProgressWidget::addText(const QString &text, const bool richText)
|
||||
toggleDetails();
|
||||
}
|
||||
|
||||
// TODO handle rich text
|
||||
if (!richText && updateLast) {
|
||||
// delete last message
|
||||
ui->textEdit->setFocus();
|
||||
QTextCursor cursor = ui->textEdit->textCursor();
|
||||
if (cursor.position() > 0) {
|
||||
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
||||
cursor.deletePreviousChar(); // remove \n otherwise next instruction does nothing
|
||||
cursor.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor);
|
||||
cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
|
||||
cursor.removeSelectedText();
|
||||
ui->textEdit->setTextCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
QTextCursor cursor(ui->textEdit->textCursor());
|
||||
|
||||
// is the scrollbar at the end?
|
||||
@@ -121,12 +136,12 @@ void ProgressWidget::addText(const QString &text, const bool richText)
|
||||
}
|
||||
}
|
||||
|
||||
void ProgressWidget::addHtml(const QString & text)
|
||||
void ProgressWidget::addHtml(const QString & text, const bool updateLast)
|
||||
{
|
||||
addText(text, true);
|
||||
addText(text, true, updateLast);
|
||||
}
|
||||
|
||||
void ProgressWidget::addMessage(const QString & text, const int & type, bool richText)
|
||||
void ProgressWidget::addMessage(const QString & text, const int & type, const bool richText, const bool updateLast)
|
||||
{
|
||||
QString color;
|
||||
switch (type) {
|
||||
@@ -146,14 +161,15 @@ void ProgressWidget::addMessage(const QString & text, const int & type, bool ric
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (color.isEmpty()) {
|
||||
if (richText)
|
||||
addHtml(text % "<br>");
|
||||
addHtml(text % "<br>", updateLast);
|
||||
else
|
||||
addText(text % "\n");
|
||||
addText(text % "\n", false, updateLast);
|
||||
}
|
||||
else {
|
||||
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>");
|
||||
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>", updateLast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,3 +234,14 @@ void ProgressWidget::refresh()
|
||||
ui->progressBar->update();
|
||||
ui->textEdit->update();
|
||||
}
|
||||
|
||||
void ProgressWidget::updateInfoAndMessages(const QString & text, const int & type, const bool richText)
|
||||
{
|
||||
setInfo(text);
|
||||
addMessage(text, type, richText);
|
||||
}
|
||||
|
||||
void ProgressWidget::updateLastMessage(const QString & text, const int & type, const bool richText)
|
||||
{
|
||||
addMessage(text, type, richText, true);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTextCursor>
|
||||
|
||||
namespace Ui {
|
||||
class ProgressWidget;
|
||||
@@ -41,9 +42,9 @@ class ProgressWidget : public QWidget
|
||||
|
||||
public slots:
|
||||
void lock(bool lock);
|
||||
void addText(const QString &text, const bool richText = false);
|
||||
void addHtml(const QString &text);
|
||||
void addMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false);
|
||||
void addText(const QString &text, const bool richText = false, const bool updateLast = false);
|
||||
void addHtml(const QString &text, const bool updateLast = false);
|
||||
void addMessage(const QString & text, const int & type = QtInfoMsg, const bool richText = false, const bool updateLast = false);
|
||||
void setInfo(const QString &text);
|
||||
void setMaximum(int value);
|
||||
void setValue(int value);
|
||||
@@ -54,6 +55,8 @@ class ProgressWidget : public QWidget
|
||||
void clearDetails() const;
|
||||
void forceKeepOpen(bool value);
|
||||
void refresh();
|
||||
void updateInfoAndMessages(const QString & text, const int & type = QtInfoMsg, const bool richText = false);
|
||||
void updateLastMessage(const QString & text, const int & type = QtInfoMsg, const bool richText = false);
|
||||
|
||||
signals:
|
||||
void detailsToggled();
|
||||
|
||||
Reference in New Issue
Block a user