summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2014-11-09 00:59:22 +0100
committerPetr Mrázek <peterix@gmail.com>2014-11-09 00:59:22 +0100
commit587fedce84207dd772a6f2dec5d53ceeb2bbf18a (patch)
treea7393323d54d52e76e7ecfe1f7edde37899cfcce
parentfa42a27525b0af912b67d70e6a76684806aee7ad (diff)
downloadMultiMC-587fedce84207dd772a6f2dec5d53ceeb2bbf18a.tar
MultiMC-587fedce84207dd772a6f2dec5d53ceeb2bbf18a.tar.gz
MultiMC-587fedce84207dd772a6f2dec5d53ceeb2bbf18a.tar.lz
MultiMC-587fedce84207dd772a6f2dec5d53ceeb2bbf18a.tar.xz
MultiMC-587fedce84207dd772a6f2dec5d53ceeb2bbf18a.zip
Implement search and logging pause in minecraft log
Fixes #47
-rw-r--r--gui/pages/LogPage.cpp85
-rw-r--r--gui/pages/LogPage.h9
-rw-r--r--gui/pages/LogPage.ui25
3 files changed, 92 insertions, 27 deletions
diff --git a/gui/pages/LogPage.cpp b/gui/pages/LogPage.cpp
index 7fbf5929..636d2695 100644
--- a/gui/pages/LogPage.cpp
+++ b/gui/pages/LogPage.cpp
@@ -3,6 +3,7 @@
#include <QIcon>
#include <QScrollBar>
+#include <QShortcut>
#include "logic/MinecraftProcess.h"
#include "gui/GuiUtil.h"
@@ -13,7 +14,15 @@ LogPage::LogPage(MinecraftProcess *proc, QWidget *parent)
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
connect(m_process, SIGNAL(log(QString, MessageLevel::Enum)), this,
- SLOT(write(QString, MessageLevel::Enum)));
+ SLOT(write(QString, MessageLevel::Enum)));
+
+ 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()));
}
LogPage::~LogPage()
@@ -46,7 +55,59 @@ void LogPage::on_btnClear_clicked()
ui->text->clear();
}
-void LogPage::writeColor(QString text, const char *color, const char * background)
+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);
+ }
+}
+
+void LogPage::writeColor(QString text, const char *color, const char *background)
{
// append a paragraph
QString newtext;
@@ -66,10 +127,21 @@ void LogPage::writeColor(QString text, const char *color, const char * backgroun
void LogPage::write(QString data, MessageLevel::Enum mode)
{
+ 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();
+
QScrollBar *bar = ui->text->verticalScrollBar();
int max_bar = bar->maximum();
int val_bar = bar->value();
- if(isVisible())
+ if (isVisible())
{
if (m_scroll_active)
{
@@ -86,9 +158,7 @@ void LogPage::write(QString data, MessageLevel::Enum mode)
QStringList filtered;
for (QString &paragraph : paragraphs)
{
- // Quick hack for
- if(paragraph.contains("Detected an attempt by a mod null to perform game activity during mod construction"))
- continue;
+ //TODO: implement filtering here.
filtered.append(paragraph.trimmed());
}
QListIterator<QString> iter(filtered);
@@ -114,7 +184,7 @@ void LogPage::write(QString data, MessageLevel::Enum mode)
else
while (iter.hasNext())
writeColor(iter.next(), 0, 0);
- if(isVisible())
+ if (isVisible())
{
if (m_scroll_active)
{
@@ -122,4 +192,5 @@ void LogPage::write(QString data, MessageLevel::Enum mode)
}
m_last_scroll_value = bar->value();
}
+ ui->text->setCursor(savedCursor);
}
diff --git a/gui/pages/LogPage.h b/gui/pages/LogPage.h
index dcc6bbf7..3c86724e 100644
--- a/gui/pages/LogPage.h
+++ b/gui/pages/LogPage.h
@@ -64,7 +64,6 @@ private:
* \n are ignored. a real \n is always appended.
*/
void writeColor(QString text, const char *color, const char *background);
-
private slots:
/**
* @brief write a string
@@ -77,10 +76,18 @@ private slots:
void on_btnCopy_clicked();
void on_btnClear_clicked();
+ void on_trackLogCheckbox_clicked(bool checked);
+
+ void on_findButton_clicked();
+ void findActivated();
+ void findNextActivated();
+ void findPreviousActivated();
+
private:
Ui::LogPage *ui;
MinecraftProcess *m_process;
int m_last_scroll_value = 0;
bool m_scroll_active = true;
int m_saved_offset = 0;
+ bool m_write_active = true;
};
diff --git a/gui/pages/LogPage.ui b/gui/pages/LogPage.ui
index b87a7522..089bc906 100644
--- a/gui/pages/LogPage.ui
+++ b/gui/pages/LogPage.ui
@@ -38,28 +38,15 @@
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label">
- <property name="enabled">
- <bool>false</bool>
- </property>
<property name="text">
<string>Search:</string>
</property>
</widget>
</item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="lineEdit">
- <property name="enabled">
- <bool>false</bool>
- </property>
- </widget>
- </item>
<item row="2" column="2">
- <widget class="QPushButton" name="pushButton">
- <property name="enabled">
- <bool>false</bool>
- </property>
+ <widget class="QPushButton" name="findButton">
<property name="text">
- <string>Find next</string>
+ <string>Find</string>
</property>
</widget>
</item>
@@ -85,10 +72,7 @@
<item row="0" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QCheckBox" name="checkBox">
- <property name="enabled">
- <bool>false</bool>
- </property>
+ <widget class="QCheckBox" name="trackLogCheckbox">
<property name="text">
<string>Keep updating</string>
</property>
@@ -142,6 +126,9 @@
</item>
</layout>
</item>
+ <item row="2" column="1">
+ <widget class="QLineEdit" name="searchBar"/>
+ </item>
</layout>
</widget>
</widget>