[Companion][ProgressWidget] Improve handling of showing/hiding details text; Speed up addMessage(); Adjust layout size policies.
This commit is contained in:
@@ -21,19 +21,27 @@
|
|||||||
#include "progresswidget.h"
|
#include "progresswidget.h"
|
||||||
#include "ui_progresswidget.h"
|
#include "ui_progresswidget.h"
|
||||||
#include "appdata.h"
|
#include "appdata.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QThread>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
|
||||||
ProgressWidget::ProgressWidget(QWidget *parent):
|
ProgressWidget::ProgressWidget(QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
ui(new Ui::ProgressWidget)
|
ui(new Ui::ProgressWidget),
|
||||||
|
m_forceOpen(false),
|
||||||
|
m_hasDetails(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->info->hide();
|
ui->info->hide();
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
ui->textEdit->hide();
|
ui->textEdit->hide();
|
||||||
|
|
||||||
|
ui->checkBox->setChecked(g.outputDisplayDetails());
|
||||||
|
connect(ui->checkBox, &QCheckBox::toggled, this, &ProgressWidget::onShowDetailsToggled);
|
||||||
|
|
||||||
QFont newFont(ui->textEdit->font());
|
QFont newFont(ui->textEdit->font());
|
||||||
newFont.setFamily("Courier");
|
newFont.setFamily("Courier");
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
@@ -43,6 +51,7 @@ ui(new Ui::ProgressWidget)
|
|||||||
newFont.setPointSize(9);
|
newFont.setPointSize(9);
|
||||||
#endif
|
#endif
|
||||||
ui->textEdit->setFont(newFont);
|
ui->textEdit->setFont(newFont);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressWidget::~ProgressWidget()
|
ProgressWidget::~ProgressWidget()
|
||||||
@@ -55,10 +64,16 @@ void ProgressWidget::stop()
|
|||||||
emit stopped();
|
emit stopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProgressWidget::clearDetails() const
|
||||||
|
{
|
||||||
|
ui->textEdit->clear();
|
||||||
|
}
|
||||||
|
|
||||||
void ProgressWidget::forceOpen()
|
void ProgressWidget::forceOpen()
|
||||||
{
|
{
|
||||||
|
m_forceOpen = true;
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
ui->textEdit->show();
|
toggleDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressWidget::setInfo(const QString &text)
|
void ProgressWidget::setInfo(const QString &text)
|
||||||
@@ -84,8 +99,11 @@ void ProgressWidget::setValue(int value)
|
|||||||
|
|
||||||
void ProgressWidget::addText(const QString &text, const bool richText)
|
void ProgressWidget::addText(const QString &text, const bool richText)
|
||||||
{
|
{
|
||||||
ui->checkBox->setVisible(true);
|
if (!m_hasDetails) {
|
||||||
ui->checkBox->setChecked(g.outputDisplayDetails());
|
m_hasDetails = true;
|
||||||
|
if (!m_forceOpen)
|
||||||
|
toggleDetails();
|
||||||
|
}
|
||||||
|
|
||||||
QTextCursor cursor(ui->textEdit->textCursor());
|
QTextCursor cursor(ui->textEdit->textCursor());
|
||||||
|
|
||||||
@@ -108,7 +126,7 @@ void ProgressWidget::addHtml(const QString & text)
|
|||||||
addText(text, true);
|
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;
|
QString color;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -129,23 +147,47 @@ void ProgressWidget::addMessage(const QString & text, const int & type)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (color.isEmpty()) {
|
if (color.isEmpty()) {
|
||||||
if (text.contains(QRegExp("<[^>]+>"))) // detect html (rouhgly)
|
if (richText)
|
||||||
addHtml(text % "<br>");
|
addHtml(text % "<br>");
|
||||||
else
|
else
|
||||||
addText(text % "\n", false);
|
addText(text % "\n");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>");
|
addHtml(QString("<font color=%1>").arg(color) % text % "</font><br>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ProgressWidget::getText()
|
QString ProgressWidget::getText() const
|
||||||
{
|
{
|
||||||
return ui->textEdit->toPlainText();
|
return ui->textEdit->toPlainText();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProgressWidget::isEmpty() const
|
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)
|
void ProgressWidget::setProgressColor(const QColor &color)
|
||||||
@@ -160,21 +202,7 @@ void ProgressWidget::addSeparator()
|
|||||||
addText("\n" HLINE_SEPARATOR "\n");
|
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)
|
void ProgressWidget::lock(bool lock)
|
||||||
{
|
{
|
||||||
emit locked(lock);
|
emit locked(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressWidget::shrink()
|
|
||||||
{
|
|
||||||
emit detailsToggled();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,20 +38,24 @@ class ProgressWidget : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit ProgressWidget(QWidget *parent);
|
explicit ProgressWidget(QWidget *parent);
|
||||||
~ProgressWidget();
|
~ProgressWidget();
|
||||||
|
QString getText() const;
|
||||||
|
int maximum();
|
||||||
|
bool isEmpty() const;
|
||||||
|
bool detailsVisible() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
void lock(bool lock);
|
void lock(bool lock);
|
||||||
void addText(const QString &text, const bool richText = false);
|
void addText(const QString &text, const bool richText = false);
|
||||||
void addHtml(const QString &text);
|
void addHtml(const QString &text);
|
||||||
void addMessage(const QString & text, const int & type = QtInfoMsg);
|
void addMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false);
|
||||||
QString getText();
|
|
||||||
void setInfo(const QString &text);
|
void setInfo(const QString &text);
|
||||||
void setMaximum(int value);
|
void setMaximum(int value);
|
||||||
int maximum();
|
|
||||||
void setValue(int value);
|
void setValue(int value);
|
||||||
void setProgressColor(const QColor &color);
|
void setProgressColor(const QColor &color);
|
||||||
void addSeparator();
|
void addSeparator();
|
||||||
void forceOpen();
|
void forceOpen();
|
||||||
void stop();
|
void stop();
|
||||||
bool isEmpty() const;
|
void clearDetails() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void detailsToggled();
|
void detailsToggled();
|
||||||
@@ -59,11 +63,13 @@ class ProgressWidget : public QWidget
|
|||||||
void stopped();
|
void stopped();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_checkBox_toggled(bool checked);
|
void toggleDetails();
|
||||||
void shrink();
|
void onShowDetailsToggled(bool checked);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ProgressWidget *ui;
|
Ui::ProgressWidget *ui;
|
||||||
|
bool m_forceOpen;
|
||||||
|
bool m_hasDetails;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _PROGRESSWIDGET_H_
|
#endif // _PROGRESSWIDGET_H_
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
@@ -41,10 +41,10 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item alignment="Qt::AlignTop">
|
||||||
<widget class="QLabel" name="info">
|
<widget class="QLabel" name="info">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item alignment="Qt::AlignTop">
|
||||||
<widget class="QWidget" name="widget" native="true">
|
<widget class="QWidget" name="widget" native="true">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QProgressBar" name="progressBar">
|
<widget class="QProgressBar" name="progressBar">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@@ -107,17 +107,11 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>350</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="font">
|
<property name="font">
|
||||||
<font>
|
<font>
|
||||||
<family>Courier</family>
|
<family>Courier</family>
|
||||||
@@ -145,19 +139,6 @@ p, li { white-space: pre-wrap; }
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
Reference in New Issue
Block a user