#include "GeneralStatusPage.h" #include "ui_GeneralStatusPage.h" #include "QStringList" #include CGeneralStatusPage::CGeneralStatusPage(QWidget *parent) : QWidget(parent), ui(new Ui::CGeneralStatusPage) { ui->setupUi(this); connect(ui->mClearGenMsgTxtBtn,&QPushButton::clicked,this,&CGeneralStatusPage::ClearGenMsgAreaBtnPressed); } CGeneralStatusPage::~CGeneralStatusPage() { delete ui; } int CGeneralStatusPage::SetGeneralMsgText(QStringList Txt) { Q_UNUSED(Txt) /*if you're populating the text box programatically, is to use textEdit->setTextColor(QColor&).You can create the QColor object yourself, or use one of the predefined colours in the Qt namespace (Qt::black, Qt::red, etc). It will apply the specified colour to any text you add, until it is called again with a different one.*/ return RET_OK; } int CGeneralStatusPage::AddGeneralMsgBoxLineEntry(QString LineTxt) { //Limit the number of lines in the MsgBox to avoid overruns... if(mGenMsgListBoxTextLines.size() >= GENERAL_MESSAGES_MAX_LOG_LINES) { mGenMsgListBoxTextLines.removeFirst(); mGenMsgListBoxTextLines.append(LineTxt); ui->mGenMsgTextEdit->clear(); for(int i = 0; i < mGenMsgListBoxTextLines.size(); i++) { AddColoredLineToGenMsgBox(mGenMsgListBoxTextLines[i]); } } else { mGenMsgListBoxTextLines.append(LineTxt); AddColoredLineToGenMsgBox(LineTxt); } ui->mGenMsgTextEdit->verticalScrollBar()->setValue(ui->mGenMsgTextEdit->verticalScrollBar()->maximum()); return RET_OK; } int CGeneralStatusPage::AddColoredLineToGenMsgBox(QString Line) { if(Line.isEmpty()) { return RET_GENERAL_ERROR; } if(Line.at(0) == QChar('%')) { if(Line.at(1) == QChar('E')) //The line is describing an error... write it red { ui->mGenMsgTextEdit->setTextColor(Qt::red); } else if(Line.at(1) == QChar('W')) //The line is describing a warning... write it yellow { ui->mGenMsgTextEdit->setTextColor(Qt::blue); } else if(Line.at(1) == QChar('S')) //The line is describing a warning... write it yellow { ui->mGenMsgTextEdit->setTextColor(Qt::darkGreen); } else { qDebug("GeneralStatusPage: Logic error in general message box line encoding... you should check into that"); return RET_GENERAL_ERROR; } Line.remove(0,2); } ui->mGenMsgTextEdit->insertPlainText(Line); ui->mGenMsgTextEdit->setTextColor(Qt::black); return RET_OK; } void CGeneralStatusPage::ClearGenMsgAreaBtnPressed() { mGenMsgListBoxTextLines.clear(); ui->mGenMsgTextEdit->clear(); }