[Companion][ProgressWidget] Improve handling of showing/hiding details text; Speed up addMessage(); Adjust layout size policies.

This commit is contained in:
Max Paperno
2018-06-30 10:24:09 -04:00
parent ff82a575f6
commit a236b4c59b
3 changed files with 72 additions and 57 deletions
+54 -26
View File
@@ -21,19 +21,27 @@
#include "progresswidget.h"
#include "ui_progresswidget.h"
#include "appdata.h"
#include <QApplication>
#include <QDebug>
#include <QTimer>
#include <QThread>
#include <QScrollBar>
ProgressWidget::ProgressWidget(QWidget *parent):
QWidget(parent),
ui(new Ui::ProgressWidget)
ProgressWidget::ProgressWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::ProgressWidget),
m_forceOpen(false),
m_hasDetails(false)
{
ui->setupUi(this);
ui->info->hide();
ui->checkBox->hide();
ui->textEdit->hide();
ui->checkBox->setChecked(g.outputDisplayDetails());
connect(ui->checkBox, &QCheckBox::toggled, this, &ProgressWidget::onShowDetailsToggled);
QFont newFont(ui->textEdit->font());
newFont.setFamily("Courier");
#ifdef __APPLE__
@@ -43,6 +51,7 @@ ui(new Ui::ProgressWidget)
newFont.setPointSize(9);
#endif
ui->textEdit->setFont(newFont);
}
ProgressWidget::~ProgressWidget()
@@ -55,10 +64,16 @@ void ProgressWidget::stop()
emit stopped();
}
void ProgressWidget::clearDetails() const
{
ui->textEdit->clear();
}
void ProgressWidget::forceOpen()
{
m_forceOpen = true;
ui->checkBox->hide();
ui->textEdit->show();
toggleDetails();
}
void ProgressWidget::setInfo(const QString &text)
@@ -84,8 +99,11 @@ void ProgressWidget::setValue(int value)
void ProgressWidget::addText(const QString &text, const bool richText)
{
ui->checkBox->setVisible(true);
ui->checkBox->setChecked(g.outputDisplayDetails());
if (!m_hasDetails) {
m_hasDetails = true;
if (!m_forceOpen)
toggleDetails();
}
QTextCursor cursor(ui->textEdit->textCursor());
@@ -108,7 +126,7 @@ void ProgressWidget::addHtml(const QString & text)
addText(text, true);
}
void ProgressWidget::addMessage(const QString & text, const int & type)
void ProgressWidget::addMessage(const QString & text, const int & type, bool richText)
{
QString color;
switch (type) {
@@ -129,23 +147,47 @@ void ProgressWidget::addMessage(const QString & text, const int & type)
break;
}
if (color.isEmpty()) {
if (text.contains(QRegExp("<[^>]+>"))) // detect html (rouhgly)
if (richText)
addHtml(text % "<br>");
else
addText(text % "\n", false);
addText(text % "\n");
}
else
else {
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>");
}
}
QString ProgressWidget::getText()
QString ProgressWidget::getText() const
{
return ui->textEdit->toPlainText();
}
bool ProgressWidget::isEmpty() const
{
return ui->textEdit->toPlainText().isEmpty();
return getText().isEmpty();
}
bool ProgressWidget::detailsVisible() const
{
return ui->textEdit->isVisible();
}
void ProgressWidget::onShowDetailsToggled(bool checked)
{
g.outputDisplayDetails(checked);
toggleDetails();
}
void ProgressWidget::toggleDetails()
{
bool showDetails = m_forceOpen || (m_hasDetails && g.outputDisplayDetails());
if (!m_forceOpen)
ui->checkBox->show();
if ((!showDetails && ui->textEdit->isVisible()) || (showDetails && !ui->textEdit->isVisible())) {
ui->textEdit->setMinimumHeight(showDetails ? 300 : 0);
ui->textEdit->setVisible(showDetails);
emit detailsToggled();
}
}
void ProgressWidget::setProgressColor(const QColor &color)
@@ -160,21 +202,7 @@ void ProgressWidget::addSeparator()
addText("\n" HLINE_SEPARATOR "\n");
}
void ProgressWidget::on_checkBox_toggled(bool checked)
{
g.outputDisplayDetails(checked);
ui->textEdit->setVisible(checked);
QTimer::singleShot(0, this, SLOT(shrink()));
}
void ProgressWidget::lock(bool lock)
{
emit locked(lock);
}
void ProgressWidget::shrink()
{
emit detailsToggled();
}