Fix doc path
[opentx.git] / companion / src / progresswidget.cpp
blob240fa02d51611adfb573c4667374f06ee0c4ea5b
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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"
23 #include "appdata.h"
24 #include <QDebug>
25 #include <QTimer>
26 #include <QScrollBar>
28 ProgressWidget::ProgressWidget(QWidget *parent):
29 QWidget(parent),
30 ui(new Ui::ProgressWidget)
32 ui->setupUi(this);
33 ui->info->hide();
34 ui->checkBox->hide();
35 ui->textEdit->hide();
37 QFont newFont(ui->textEdit->font());
38 newFont.setFamily("Courier");
39 #ifdef __APPLE__
40 newFont.setPointSize(13);
41 ui->textEdit->setAttribute(Qt::WA_MacNormalSize);
42 #elif defined WIN32 || !defined __GNUC__
43 newFont.setPointSize(9);
44 #endif
45 ui->textEdit->setFont(newFont);
48 ProgressWidget::~ProgressWidget()
50 delete ui;
53 void ProgressWidget::stop()
55 emit stopped();
58 void ProgressWidget::forceOpen()
60 ui->checkBox->hide();
61 ui->textEdit->show();
64 void ProgressWidget::setInfo(const QString &text)
66 ui->info->show();
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);
96 if (richText)
97 cursor.insertHtml(text);
98 else
99 cursor.insertText(text);
101 if (atEnd) {
102 ui->textEdit->verticalScrollBar()->triggerAction(QAbstractSlider::SliderToMaximum);
106 void ProgressWidget::addHtml(const QString & text)
108 addText(text, true);
111 void ProgressWidget::addMessage(const QString & text, const int & type)
113 QString color;
114 switch (type) {
115 case QtDebugMsg:
116 color = "dimgrey"; // not important messages, may be filtered out
117 break;
118 case QtWarningMsg: // use warning level as emphasis
119 color = "darkblue";
120 break;
121 case QtCriticalMsg: // use critical as a warning
122 color = "#ff7900";
123 break;
124 case QtFatalMsg: // fatal for hard errors
125 color = "red";
126 break;
127 case QtInfoMsg: // default plain text
128 default:
129 break;
131 if (color.isEmpty()) {
132 if (text.contains(QRegExp("<[^>]+>"))) // detect html (rouhgly)
133 addHtml(text % "<br>");
134 else
135 addText(text % "\n", false);
137 else
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)
172 emit locked(lock);
175 void ProgressWidget::shrink()
177 emit detailsToggled();