[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 "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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
@@ -41,10 +41,10 @@
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QLabel" name="info">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@@ -54,7 +54,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<item alignment="Qt::AlignTop">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
|
||||
<property name="spacing">
|
||||
@@ -75,7 +75,7 @@
|
||||
<item>
|
||||
<widget class="QProgressBar" name="progressBar">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@@ -107,17 +107,11 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>350</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Courier</family>
|
||||
@@ -145,19 +139,6 @@ p, li { white-space: pre-wrap; }
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
||||
Reference in New Issue
Block a user