diff --git a/companion/src/progresswidget.cpp b/companion/src/progresswidget.cpp index 240fa02d5..92f45e6f7 100644 --- a/companion/src/progresswidget.cpp +++ b/companion/src/progresswidget.cpp @@ -21,19 +21,27 @@ #include "progresswidget.h" #include "ui_progresswidget.h" #include "appdata.h" + +#include #include #include +#include #include -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 % "
"); else - addText(text % "\n", false); + addText(text % "\n"); } - else + else { addHtml(QString("").arg(color) % text % "
"); + } } -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(); -} - - diff --git a/companion/src/progresswidget.h b/companion/src/progresswidget.h index a9098a358..f50933033 100644 --- a/companion/src/progresswidget.h +++ b/companion/src/progresswidget.h @@ -38,20 +38,24 @@ class ProgressWidget : public QWidget public: explicit ProgressWidget(QWidget *parent); ~ProgressWidget(); + QString getText() const; + int maximum(); + bool isEmpty() const; + bool detailsVisible() const; + + 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); - QString getText(); + void addMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false); void setInfo(const QString &text); void setMaximum(int value); - int maximum(); void setValue(int value); void setProgressColor(const QColor &color); void addSeparator(); void forceOpen(); void stop(); - bool isEmpty() const; + void clearDetails() const; signals: void detailsToggled(); @@ -59,11 +63,13 @@ class ProgressWidget : public QWidget void stopped(); protected slots: - void on_checkBox_toggled(bool checked); - void shrink(); + void toggleDetails(); + void onShowDetailsToggled(bool checked); private: Ui::ProgressWidget *ui; + bool m_forceOpen; + bool m_hasDetails; }; #endif // _PROGRESSWIDGET_H_ diff --git a/companion/src/progresswidget.ui b/companion/src/progresswidget.ui index d53302226..8399257ae 100644 --- a/companion/src/progresswidget.ui +++ b/companion/src/progresswidget.ui @@ -25,7 +25,7 @@ 0 - + 6 @@ -41,10 +41,10 @@ 0 - + - + 0 0 @@ -54,7 +54,7 @@ - + @@ -75,7 +75,7 @@ - + 0 0 @@ -107,17 +107,11 @@ true - + 0 0 - - - 0 - 350 - - Courier @@ -145,19 +139,6 @@ p, li { white-space: pre-wrap; } - - - - Qt::Vertical - - - - 20 - 0 - - - -