2014-06-30 01:02:57 +01:00
|
|
|
#include "LogPage.h"
|
|
|
|
#include "ui_LogPage.h"
|
2014-07-12 16:58:23 +01:00
|
|
|
|
2014-11-09 18:48:35 +00:00
|
|
|
#include "MultiMC.h"
|
|
|
|
|
2014-07-12 16:58:23 +01:00
|
|
|
#include <QIcon>
|
2014-06-30 01:02:57 +01:00
|
|
|
#include <QScrollBar>
|
2014-11-08 23:59:22 +00:00
|
|
|
#include <QShortcut>
|
2014-06-30 01:02:57 +01:00
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
#include "logic/BaseProcess.h"
|
2014-07-12 16:58:23 +01:00
|
|
|
#include "gui/GuiUtil.h"
|
|
|
|
|
2015-01-27 21:31:07 +00:00
|
|
|
LogPage::LogPage(BaseProcess *proc, QWidget *parent)
|
2014-06-30 01:02:57 +01:00
|
|
|
: QWidget(parent), ui(new Ui::LogPage), m_process(proc)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-07-20 23:10:13 +01:00
|
|
|
ui->tabWidget->tabBar()->hide();
|
2014-06-30 01:02:57 +01:00
|
|
|
connect(m_process, SIGNAL(log(QString, MessageLevel::Enum)), this,
|
2014-11-08 23:59:22 +00:00
|
|
|
SLOT(write(QString, MessageLevel::Enum)));
|
|
|
|
|
2014-11-09 13:53:08 +00:00
|
|
|
// create the format and set its font
|
|
|
|
defaultFormat = new QTextCharFormat(ui->text->currentCharFormat());
|
2014-11-09 18:48:35 +00:00
|
|
|
QString fontFamily = MMC->settings()->get("ConsoleFont").toString();
|
2014-11-10 23:50:17 +00:00
|
|
|
bool conversionOk = false;
|
|
|
|
int fontSize = MMC->settings()->get("ConsoleFontSize").toInt(&conversionOk);
|
|
|
|
if(!conversionOk)
|
|
|
|
{
|
|
|
|
fontSize = 11;
|
|
|
|
}
|
|
|
|
defaultFormat->setFont(QFont(fontFamily, fontSize));
|
2014-11-09 13:53:08 +00:00
|
|
|
|
2014-11-08 23:59:22 +00:00
|
|
|
auto findShortcut = new QShortcut(QKeySequence(QKeySequence::Find), this);
|
|
|
|
connect(findShortcut, SIGNAL(activated()), SLOT(findActivated()));
|
|
|
|
auto findNextShortcut = new QShortcut(QKeySequence(QKeySequence::FindNext), this);
|
|
|
|
connect(findNextShortcut, SIGNAL(activated()), SLOT(findNextActivated()));
|
|
|
|
connect(ui->searchBar, SIGNAL(returnPressed()), SLOT(on_findButton_clicked()));
|
|
|
|
auto findPreviousShortcut = new QShortcut(QKeySequence(QKeySequence::FindPrevious), this);
|
|
|
|
connect(findPreviousShortcut, SIGNAL(activated()), SLOT(findPreviousActivated()));
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LogPage::~LogPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
2014-11-09 13:53:08 +00:00
|
|
|
delete defaultFormat;
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool LogPage::apply()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-12 16:58:23 +01:00
|
|
|
bool LogPage::shouldDisplay() const
|
2014-06-30 01:02:57 +01:00
|
|
|
{
|
|
|
|
return m_process->instance()->isRunning();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_btnPaste_clicked()
|
|
|
|
{
|
2014-07-12 16:58:23 +01:00
|
|
|
GuiUtil::uploadPaste(ui->text->toPlainText(), this);
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|
|
|
|
|
2014-07-11 00:50:36 +01:00
|
|
|
void LogPage::on_btnCopy_clicked()
|
|
|
|
{
|
2014-07-12 16:58:23 +01:00
|
|
|
GuiUtil::setClipboardText(ui->text->toPlainText());
|
2014-07-11 00:50:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_btnClear_clicked()
|
|
|
|
{
|
|
|
|
ui->text->clear();
|
|
|
|
}
|
|
|
|
|
2014-11-08 23:59:22 +00:00
|
|
|
void LogPage::on_trackLogCheckbox_clicked(bool checked)
|
|
|
|
{
|
|
|
|
m_write_active = checked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::on_findButton_clicked()
|
|
|
|
{
|
|
|
|
auto modifiers = QApplication::keyboardModifiers();
|
|
|
|
if (modifiers & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
findPreviousActivated();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
findNextActivated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findActivated()
|
|
|
|
{
|
|
|
|
// focus the search bar if it doesn't have focus
|
|
|
|
if (!ui->searchBar->hasFocus())
|
|
|
|
{
|
|
|
|
auto searchForCursor = ui->text->textCursor();
|
|
|
|
auto searchForString = searchForCursor.selectedText();
|
|
|
|
if (searchForString.size())
|
|
|
|
{
|
|
|
|
ui->searchBar->setText(searchForString);
|
|
|
|
}
|
|
|
|
ui->searchBar->setFocus();
|
|
|
|
ui->searchBar->selectAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findNextActivated()
|
|
|
|
{
|
|
|
|
auto toSearch = ui->searchBar->text();
|
|
|
|
if (toSearch.size())
|
|
|
|
{
|
|
|
|
ui->text->find(toSearch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogPage::findPreviousActivated()
|
|
|
|
{
|
|
|
|
auto toSearch = ui->searchBar->text();
|
|
|
|
if (toSearch.size())
|
|
|
|
{
|
|
|
|
ui->text->find(toSearch, QTextDocument::FindBackward);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-30 01:02:57 +01:00
|
|
|
void LogPage::write(QString data, MessageLevel::Enum mode)
|
|
|
|
{
|
2014-11-08 23:59:22 +00:00
|
|
|
if (!m_write_active)
|
|
|
|
{
|
|
|
|
if (mode != MessageLevel::PrePost && mode != MessageLevel::MultiMC)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save the cursor so it can be restored.
|
|
|
|
auto savedCursor = ui->text->cursor();
|
|
|
|
|
2014-06-30 01:02:57 +01:00
|
|
|
QScrollBar *bar = ui->text->verticalScrollBar();
|
|
|
|
int max_bar = bar->maximum();
|
|
|
|
int val_bar = bar->value();
|
2014-11-08 23:59:22 +00:00
|
|
|
if (isVisible())
|
2014-06-30 01:02:57 +01:00
|
|
|
{
|
|
|
|
if (m_scroll_active)
|
|
|
|
{
|
|
|
|
m_scroll_active = (max_bar - val_bar) <= 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_scroll_active = val_bar == max_bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data.endsWith('\n'))
|
|
|
|
data = data.left(data.length() - 1);
|
|
|
|
QStringList paragraphs = data.split('\n');
|
|
|
|
QStringList filtered;
|
|
|
|
for (QString ¶graph : paragraphs)
|
|
|
|
{
|
2014-11-08 23:59:22 +00:00
|
|
|
//TODO: implement filtering here.
|
2014-11-09 13:53:08 +00:00
|
|
|
filtered.append(paragraph);
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|
|
|
|
QListIterator<QString> iter(filtered);
|
2014-11-09 13:53:08 +00:00
|
|
|
QTextCharFormat format(*defaultFormat);
|
|
|
|
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case MessageLevel::MultiMC:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("blue"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageLevel::Debug:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("green"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageLevel::Warning:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("orange"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageLevel::Error:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("red"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MessageLevel::Fatal:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("red"));
|
|
|
|
format.setBackground(QColor("black"));
|
2014-11-10 04:10:58 +00:00
|
|
|
break;
|
2014-11-09 13:53:08 +00:00
|
|
|
}
|
|
|
|
case MessageLevel::PrePost:
|
|
|
|
{
|
|
|
|
format.setForeground(QColor("grey"));
|
2014-11-10 04:10:58 +00:00
|
|
|
break;
|
2014-11-09 13:53:08 +00:00
|
|
|
}
|
|
|
|
case MessageLevel::Info:
|
|
|
|
case MessageLevel::Message:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// do nothing, keep original
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (iter.hasNext())
|
|
|
|
{
|
|
|
|
// append a paragraph/line
|
|
|
|
auto workCursor = ui->text->textCursor();
|
|
|
|
workCursor.movePosition(QTextCursor::End);
|
|
|
|
workCursor.insertText(iter.next(), format);
|
|
|
|
workCursor.insertBlock();
|
|
|
|
}
|
|
|
|
|
2014-11-08 23:59:22 +00:00
|
|
|
if (isVisible())
|
2014-06-30 01:02:57 +01:00
|
|
|
{
|
|
|
|
if (m_scroll_active)
|
|
|
|
{
|
|
|
|
bar->setValue(bar->maximum());
|
|
|
|
}
|
|
|
|
m_last_scroll_value = bar->value();
|
|
|
|
}
|
2014-11-08 23:59:22 +00:00
|
|
|
ui->text->setCursor(savedCursor);
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|