5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "progresswidget.h"
22 #include "ui_progresswidget.h"
28 ProgressWidget::ProgressWidget(QWidget
*parent
):
30 ui(new Ui::ProgressWidget
)
37 QFont
newFont(ui
->textEdit
->font());
38 newFont
.setFamily("Courier");
40 newFont
.setPointSize(13);
41 ui
->textEdit
->setAttribute(Qt::WA_MacNormalSize
);
42 #elif defined WIN32 || !defined __GNUC__
43 newFont
.setPointSize(9);
45 ui
->textEdit
->setFont(newFont
);
48 ProgressWidget::~ProgressWidget()
53 void ProgressWidget::stop()
58 void ProgressWidget::forceOpen()
64 void ProgressWidget::setInfo(const QString
&text
)
67 ui
->info
->setText(text
);
70 void ProgressWidget::setMaximum(int value
)
72 ui
->progressBar
->setMaximum(value
);
75 int ProgressWidget::maximum()
77 return ui
->progressBar
->maximum();
80 void ProgressWidget::setValue(int value
)
82 ui
->progressBar
->setValue(value
);
85 void ProgressWidget::addText(const QString
&text
, const bool richText
)
87 ui
->checkBox
->setVisible(true);
88 ui
->checkBox
->setChecked(g
.outputDisplayDetails());
90 QTextCursor
cursor(ui
->textEdit
->textCursor());
92 // is the scrollbar at the end?
93 bool atEnd
= (ui
->textEdit
->verticalScrollBar()->value() == ui
->textEdit
->verticalScrollBar()->maximum());
95 cursor
.movePosition(QTextCursor::End
, QTextCursor::MoveAnchor
, 1);
97 cursor
.insertHtml(text
);
99 cursor
.insertText(text
);
102 ui
->textEdit
->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum
);
106 void ProgressWidget::addHtml(const QString
& text
)
111 void ProgressWidget::addMessage(const QString
& text
, const int & type
)
116 color
= "dimgrey"; // not important messages, may be filtered out
118 case QtWarningMsg
: // use warning level as emphasis
121 case QtCriticalMsg
: // use critical as a warning
124 case QtFatalMsg
: // fatal for hard errors
127 case QtInfoMsg
: // default plain text
131 if (color
.isEmpty()) {
132 if (text
.contains(QRegExp("<[^>]+>"))) // detect html (rouhgly)
133 addHtml(text
% "<br>");
135 addText(text
% "\n", false);
138 addHtml(QString("<font color=%1>").arg(color
) % text
% "</font><br>");
141 QString
ProgressWidget::getText()
143 return ui
->textEdit
->toPlainText();
146 bool ProgressWidget::isEmpty() const
148 return ui
->textEdit
->toPlainText().isEmpty();
151 void ProgressWidget::setProgressColor(const QColor
&color
)
153 ui
->progressBar
->setStyleSheet(QString("QProgressBar {text-align: center;} QProgressBar::chunk { background-color: %1; text-align:center;}:").arg(color
.name()));
156 #define HLINE_SEPARATOR "================================================================================="
158 void ProgressWidget::addSeparator()
160 addText("\n" HLINE_SEPARATOR
"\n");
163 void ProgressWidget::on_checkBox_toggled(bool checked
)
165 g
.outputDisplayDetails(checked
);
166 ui
->textEdit
->setVisible(checked
);
167 QTimer::singleShot(0, this, SLOT(shrink()));
170 void ProgressWidget::lock(bool lock
)
175 void ProgressWidget::shrink()
177 emit
detailsToggled();