Basic support for launcher log page

Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
Yihe Li 2025-06-03 04:41:48 +08:00
parent df90d0cb0d
commit c58cc3396a
No known key found for this signature in database
11 changed files with 631 additions and 91 deletions

View file

@ -63,6 +63,7 @@
#include "ui/pages/global/ExternalToolsPage.h" #include "ui/pages/global/ExternalToolsPage.h"
#include "ui/pages/global/JavaPage.h" #include "ui/pages/global/JavaPage.h"
#include "ui/pages/global/LanguagePage.h" #include "ui/pages/global/LanguagePage.h"
#include "ui/pages/global/LauncherLogPage.h"
#include "ui/pages/global/LauncherPage.h" #include "ui/pages/global/LauncherPage.h"
#include "ui/pages/global/MinecraftPage.h" #include "ui/pages/global/MinecraftPage.h"
#include "ui/pages/global/ProxyPage.h" #include "ui/pages/global/ProxyPage.h"
@ -244,8 +245,11 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext& context, const QSt
} }
QString out = qFormatLogMessage(type, context, msg); QString out = qFormatLogMessage(type, context, msg);
out += QChar::LineFeed; if (APPLICATION->logModel) {
APPLICATION->logModel->append(MessageLevel::getLevel(type), out);
}
out += QChar::LineFeed;
APPLICATION->logFile->write(out.toUtf8()); APPLICATION->logFile->write(out.toUtf8());
APPLICATION->logFile->flush(); APPLICATION->logFile->flush();
@ -538,6 +542,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
qInstallMessageHandler(appDebugOutput); qInstallMessageHandler(appDebugOutput);
qSetMessagePattern(defaultLogFormat); qSetMessagePattern(defaultLogFormat);
logModel.reset(new LogModel(this));
bool foundLoggingRules = false; bool foundLoggingRules = false;
auto logRulesFile = QStringLiteral("qtlogging.ini"); auto logRulesFile = QStringLiteral("qtlogging.ini");
@ -691,6 +697,17 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
m_settings->registerSetting("ConsoleMaxLines", 100000); m_settings->registerSetting("ConsoleMaxLines", 100000);
m_settings->registerSetting("ConsoleOverflowStop", true); m_settings->registerSetting("ConsoleOverflowStop", true);
auto lineSetting = settings()->getSetting("ConsoleMaxLines");
bool conversionOk = false;
int maxLines = lineSetting->get().toInt(&conversionOk);
if (!conversionOk) {
maxLines = lineSetting->defValue().toInt();
qWarning() << "ConsoleMaxLines has nonsensical value, defaulting to" << maxLines;
}
logModel->setMaxLines(maxLines);
logModel->setStopOnOverflow(settings()->get("ConsoleOverflowStop").toBool());
logModel->setOverflowMessage(tr("Cannot display this log since the log length surpassed %1 lines.").arg(maxLines));
// Folders // Folders
m_settings->registerSetting("InstanceDir", "instances"); m_settings->registerSetting("InstanceDir", "instances");
m_settings->registerSetting({ "CentralModsDir", "ModsDir" }, "mods"); m_settings->registerSetting({ "CentralModsDir", "ModsDir" }, "mods");
@ -895,6 +912,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
m_globalSettingsProvider->addPage<APIPage>(); m_globalSettingsProvider->addPage<APIPage>();
m_globalSettingsProvider->addPage<ExternalToolsPage>(); m_globalSettingsProvider->addPage<ExternalToolsPage>();
m_globalSettingsProvider->addPage<ProxyPage>(); m_globalSettingsProvider->addPage<ProxyPage>();
m_globalSettingsProvider->addPage<LauncherLogPage>();
} }
PixmapCache::setInstance(new PixmapCache(this)); PixmapCache::setInstance(new PixmapCache(this));

View file

@ -48,6 +48,7 @@
#include <BaseInstance.h> #include <BaseInstance.h>
#include "launch/LogModel.h"
#include "minecraft/launch/MinecraftTarget.h" #include "minecraft/launch/MinecraftTarget.h"
class LaunchController; class LaunchController;
@ -307,6 +308,7 @@ class Application : public QApplication {
QList<QUrl> m_urlsToImport; QList<QUrl> m_urlsToImport;
QString m_instanceIdToShowWindowOf; QString m_instanceIdToShowWindowOf;
std::unique_ptr<QFile> logFile; std::unique_ptr<QFile> logFile;
shared_qobject_ptr<LogModel> logModel;
public: public:
void addQSavePath(QString); void addQSavePath(QString);

View file

@ -959,6 +959,8 @@ SET(LAUNCHER_SOURCES
ui/pages/global/MinecraftPage.h ui/pages/global/MinecraftPage.h
ui/pages/global/LauncherPage.cpp ui/pages/global/LauncherPage.cpp
ui/pages/global/LauncherPage.h ui/pages/global/LauncherPage.h
ui/pages/global/LauncherLogPage.cpp
ui/pages/global/LauncherLogPage.h
ui/pages/global/AppearancePage.h ui/pages/global/AppearancePage.h
ui/pages/global/ProxyPage.cpp ui/pages/global/ProxyPage.cpp
ui/pages/global/ProxyPage.h ui/pages/global/ProxyPage.h
@ -1203,6 +1205,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/pages/global/AccountListPage.ui ui/pages/global/AccountListPage.ui
ui/pages/global/JavaPage.ui ui/pages/global/JavaPage.ui
ui/pages/global/LauncherPage.ui ui/pages/global/LauncherPage.ui
ui/pages/global/LauncherLogPage.ui
ui/pages/global/APIPage.ui ui/pages/global/APIPage.ui
ui/pages/global/ProxyPage.ui ui/pages/global/ProxyPage.ui
ui/pages/global/ExternalToolsPage.ui ui/pages/global/ExternalToolsPage.ui

View file

@ -25,6 +25,24 @@ MessageLevel::Enum MessageLevel::getLevel(const QString& levelName)
return MessageLevel::Unknown; return MessageLevel::Unknown;
} }
MessageLevel::Enum MessageLevel::getLevel(QtMsgType type)
{
switch (type) {
case QtDebugMsg:
return MessageLevel::Debug;
case QtInfoMsg:
return MessageLevel::Info;
case QtWarningMsg:
return MessageLevel::Warning;
case QtCriticalMsg:
return MessageLevel::Error;
case QtFatalMsg:
return MessageLevel::Fatal;
default:
return MessageLevel::Unknown;
}
}
MessageLevel::Enum MessageLevel::fromLine(QString& line) MessageLevel::Enum MessageLevel::fromLine(QString& line)
{ {
// Level prefix // Level prefix

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QString> #include <QString>
#include <QtLogging>
/** /**
* @brief the MessageLevel Enum * @brief the MessageLevel Enum
@ -21,6 +22,7 @@ enum Enum {
Fatal, /**< Fatal Errors */ Fatal, /**< Fatal Errors */
}; };
MessageLevel::Enum getLevel(const QString& levelName); MessageLevel::Enum getLevel(const QString& levelName);
MessageLevel::Enum getLevel(QtMsgType type);
/* Get message level from a line. Line is modified if it was successful. */ /* Get message level from a line. Line is modified if it was successful. */
MessageLevel::Enum fromLine(QString& line); MessageLevel::Enum fromLine(QString& line);

View file

@ -24,5 +24,5 @@ class ResourcePack : public DataPack {
/** Gets, respectively, the lower and upper versions supported by the set pack format. */ /** Gets, respectively, the lower and upper versions supported by the set pack format. */
[[nodiscard]] std::pair<Version, Version> compatibleVersions() const override; [[nodiscard]] std::pair<Version, Version> compatibleVersions() const override;
virtual QString directory() { return "/assets"; } QString directory() override { return "/assets"; }
}; };

View file

@ -0,0 +1,293 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
* Copyright (c) 2025 Yihe Li <winmikedows@hotmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "LauncherLogPage.h"
#include "ui_LauncherLogPage.h"
#include "Application.h"
#include <QIdentityProxyModel>
#include <QScrollBar>
#include <QShortcut>
#include "launch/LaunchTask.h"
#include "settings/Setting.h"
#include "ui/GuiUtil.h"
#include "ui/themes/ThemeManager.h"
#include <BuildConfig.h>
QVariant LogFormatProxyModel::data(const QModelIndex& index, int role) const
{
const LogColors& colors = APPLICATION->themeManager()->getLogColors();
switch (role) {
case Qt::FontRole:
return m_font;
case Qt::ForegroundRole: {
auto level = static_cast<MessageLevel::Enum>(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt());
QColor result = colors.foreground.value(level);
if (result.isValid())
return result;
break;
}
case Qt::BackgroundRole: {
auto level = static_cast<MessageLevel::Enum>(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt());
QColor result = colors.background.value(level);
if (result.isValid())
return result;
break;
}
}
return QIdentityProxyModel::data(index, role);
}
QModelIndex LogFormatProxyModel::find(const QModelIndex& start, const QString& value, bool reverse) const
{
QModelIndex parentIndex = parent(start);
auto compare = [this, start, parentIndex, value](int r) -> QModelIndex {
QModelIndex idx = index(r, start.column(), parentIndex);
if (!idx.isValid() || idx == start) {
return QModelIndex();
}
QVariant v = data(idx, Qt::DisplayRole);
QString t = v.toString();
if (t.contains(value, Qt::CaseInsensitive))
return idx;
return QModelIndex();
};
if (reverse) {
int from = start.row();
int to = 0;
for (int i = 0; i < 2; ++i) {
for (int r = from; (r >= to); --r) {
auto idx = compare(r);
if (idx.isValid())
return idx;
}
// prepare for the next iteration
from = rowCount() - 1;
to = start.row();
}
} else {
int from = start.row();
int to = rowCount(parentIndex);
for (int i = 0; i < 2; ++i) {
for (int r = from; (r < to); ++r) {
auto idx = compare(r);
if (idx.isValid())
return idx;
}
// prepare for the next iteration
from = 0;
to = start.row();
}
}
return QModelIndex();
}
LauncherLogPage::LauncherLogPage(QWidget* parent) : QWidget(parent), ui(new Ui::LauncherLogPage)
{
ui->setupUi(this);
ui->tabWidget->tabBar()->hide();
m_proxy = new LogFormatProxyModel(this);
// set up fonts in the log proxy
{
QString fontFamily = APPLICATION->settings()->get("ConsoleFont").toString();
bool conversionOk = false;
int fontSize = APPLICATION->settings()->get("ConsoleFontSize").toInt(&conversionOk);
if (!conversionOk) {
fontSize = 11;
}
m_proxy->setFont(QFont(fontFamily, fontSize));
}
ui->text->setModel(m_proxy);
m_proxy->setSourceModel(APPLICATION->logModel.get());
modelStateToUI();
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()));
}
LauncherLogPage::~LauncherLogPage()
{
delete ui;
}
void LauncherLogPage::modelStateToUI()
{
if (APPLICATION->logModel->wrapLines()) {
ui->text->setWordWrap(true);
ui->wrapCheckbox->setCheckState(Qt::Checked);
} else {
ui->text->setWordWrap(false);
ui->wrapCheckbox->setCheckState(Qt::Unchecked);
}
if (APPLICATION->logModel->colorLines()) {
ui->text->setColorLines(true);
ui->colorCheckbox->setCheckState(Qt::Checked);
} else {
ui->text->setColorLines(false);
ui->colorCheckbox->setCheckState(Qt::Unchecked);
}
if (APPLICATION->logModel->suspended()) {
ui->trackLogCheckbox->setCheckState(Qt::Unchecked);
} else {
ui->trackLogCheckbox->setCheckState(Qt::Checked);
}
}
void LauncherLogPage::UIToModelState()
{
if (!APPLICATION->logModel) {
return;
}
APPLICATION->logModel->setLineWrap(ui->wrapCheckbox->checkState() == Qt::Checked);
APPLICATION->logModel->setColorLines(ui->colorCheckbox->checkState() == Qt::Checked);
APPLICATION->logModel->suspend(ui->trackLogCheckbox->checkState() != Qt::Checked);
}
void LauncherLogPage::on_btnPaste_clicked()
{
if (!APPLICATION->logModel)
return;
// FIXME: turn this into a proper task and move the upload logic out of GuiUtil!
APPLICATION->logModel->append(MessageLevel::Launcher,
QString("Log upload triggered at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date)));
auto url = GuiUtil::uploadPaste(tr("Launcher Log"), APPLICATION->logModel->toPlainText(), this);
if (!url.has_value()) {
APPLICATION->logModel->append(MessageLevel::Error, QString("Log upload canceled"));
} else if (url->isNull()) {
APPLICATION->logModel->append(MessageLevel::Error, QString("Log upload failed!"));
} else {
APPLICATION->logModel->append(MessageLevel::Launcher, QString("Log uploaded to: %1").arg(url.value()));
}
}
void LauncherLogPage::on_btnCopy_clicked()
{
if (!APPLICATION->logModel)
return;
APPLICATION->logModel->append(MessageLevel::Launcher,
QString("Clipboard copy at: %1").arg(QDateTime::currentDateTime().toString(Qt::RFC2822Date)));
GuiUtil::setClipboardText(APPLICATION->logModel->toPlainText());
}
void LauncherLogPage::on_btnClear_clicked()
{
if (!APPLICATION->logModel)
return;
APPLICATION->logModel->clear();
m_container->refreshContainer();
}
void LauncherLogPage::on_btnBottom_clicked()
{
ui->text->scrollToBottom();
}
void LauncherLogPage::on_trackLogCheckbox_clicked(bool checked)
{
if (!APPLICATION->logModel)
return;
APPLICATION->logModel->suspend(!checked);
}
void LauncherLogPage::on_wrapCheckbox_clicked(bool checked)
{
ui->text->setWordWrap(checked);
if (!APPLICATION->logModel)
return;
APPLICATION->logModel->setLineWrap(checked);
}
void LauncherLogPage::on_colorCheckbox_clicked(bool checked)
{
ui->text->setColorLines(checked);
if (!APPLICATION->logModel)
return;
APPLICATION->logModel->setColorLines(checked);
}
void LauncherLogPage::on_findButton_clicked()
{
auto modifiers = QApplication::keyboardModifiers();
bool reverse = modifiers & Qt::ShiftModifier;
ui->text->findNext(ui->searchBar->text(), reverse);
}
void LauncherLogPage::findNextActivated()
{
ui->text->findNext(ui->searchBar->text(), false);
}
void LauncherLogPage::findPreviousActivated()
{
ui->text->findNext(ui->searchBar->text(), true);
}
void LauncherLogPage::findActivated()
{
// focus the search bar if it doesn't have focus
if (!ui->searchBar->hasFocus()) {
ui->searchBar->setFocus();
ui->searchBar->selectAll();
}
}
void LauncherLogPage::retranslate()
{
ui->retranslateUi(this);
}

View file

@ -0,0 +1,99 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (c) 2025 Yihe Li <winmikedows@hotmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <QIdentityProxyModel>
#include <QWidget>
#include <Application.h>
#include "BaseInstance.h"
#include "launch/LaunchTask.h"
#include "ui/pages/BasePage.h"
namespace Ui {
class LauncherLogPage;
}
class QTextCharFormat;
class LogFormatProxyModel : public QIdentityProxyModel {
public:
LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) {}
QVariant data(const QModelIndex& index, int role) const override;
QFont getFont() const { return m_font; }
void setFont(QFont font) { m_font = font; }
QModelIndex find(const QModelIndex& start, const QString& value, bool reverse) const;
private:
QFont m_font;
};
class LauncherLogPage : public QWidget, public BasePage {
Q_OBJECT
public:
explicit LauncherLogPage(QWidget* parent = 0);
~LauncherLogPage();
QString displayName() const override { return tr("Logs"); }
QIcon icon() const override { return APPLICATION->getThemedIcon("log"); }
QString id() const override { return "launcher-console"; }
QString helpPage() const override { return "Launcher-Logs"; }
void retranslate() override;
private slots:
void on_btnPaste_clicked();
void on_btnCopy_clicked();
void on_btnClear_clicked();
void on_btnBottom_clicked();
void on_trackLogCheckbox_clicked(bool checked);
void on_wrapCheckbox_clicked(bool checked);
void on_colorCheckbox_clicked(bool checked);
void on_findButton_clicked();
void findActivated();
void findNextActivated();
void findPreviousActivated();
private:
void modelStateToUI();
void UIToModelState();
private:
Ui::LauncherLogPage* ui;
LogFormatProxyModel* m_proxy;
};

View file

@ -0,0 +1,193 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LauncherLogPage</class>
<widget class="QWidget" name="LauncherLogPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>825</width>
<height>782</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string notr="true">Tab 1</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0" colspan="5">
<widget class="LogView" name="text">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0" colspan="5">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="trackLogCheckbox">
<property name="text">
<string>Keep updating</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wrapCheckbox">
<property name="text">
<string>Wrap lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="colorCheckbox">
<property name="text">
<string>Color lines</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnCopy">
<property name="toolTip">
<string>Copy the whole log into the clipboard</string>
</property>
<property name="text">
<string>&amp;Copy</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnPaste">
<property name="toolTip">
<string>Upload the log to the paste service configured in preferences</string>
</property>
<property name="text">
<string>Upload</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClear">
<property name="toolTip">
<string>Clear the log</string>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Search:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="findButton">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="searchBar"/>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="btnBottom">
<property name="toolTip">
<string>Scroll all the way to bottom</string>
</property>
<property name="text">
<string>Bottom</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LogView</class>
<extends>QPlainTextEdit</extends>
<header>ui/widgets/LogView.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>trackLogCheckbox</tabstop>
<tabstop>wrapCheckbox</tabstop>
<tabstop>colorCheckbox</tabstop>
<tabstop>btnCopy</tabstop>
<tabstop>btnPaste</tabstop>
<tabstop>btnClear</tabstop>
<tabstop>text</tabstop>
<tabstop>searchBar</tabstop>
<tabstop>findButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View file

@ -52,82 +52,6 @@
#include <BuildConfig.h> #include <BuildConfig.h>
QVariant LogFormatProxyModel::data(const QModelIndex& index, int role) const
{
const LogColors& colors = APPLICATION->themeManager()->getLogColors();
switch (role) {
case Qt::FontRole:
return m_font;
case Qt::ForegroundRole: {
auto level = static_cast<MessageLevel::Enum>(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt());
QColor result = colors.foreground.value(level);
if (result.isValid())
return result;
break;
}
case Qt::BackgroundRole: {
auto level = static_cast<MessageLevel::Enum>(QIdentityProxyModel::data(index, LogModel::LevelRole).toInt());
QColor result = colors.background.value(level);
if (result.isValid())
return result;
break;
}
}
return QIdentityProxyModel::data(index, role);
}
QModelIndex LogFormatProxyModel::find(const QModelIndex& start, const QString& value, bool reverse) const
{
QModelIndex parentIndex = parent(start);
auto compare = [this, start, parentIndex, value](int r) -> QModelIndex {
QModelIndex idx = index(r, start.column(), parentIndex);
if (!idx.isValid() || idx == start) {
return QModelIndex();
}
QVariant v = data(idx, Qt::DisplayRole);
QString t = v.toString();
if (t.contains(value, Qt::CaseInsensitive))
return idx;
return QModelIndex();
};
if (reverse) {
int from = start.row();
int to = 0;
for (int i = 0; i < 2; ++i) {
for (int r = from; (r >= to); --r) {
auto idx = compare(r);
if (idx.isValid())
return idx;
}
// prepare for the next iteration
from = rowCount() - 1;
to = start.row();
}
} else {
int from = start.row();
int to = rowCount(parentIndex);
for (int i = 0; i < 2; ++i) {
for (int r = from; (r < to); ++r) {
auto idx = compare(r);
if (idx.isValid())
return idx;
}
// prepare for the next iteration
from = 0;
to = start.row();
}
}
return QModelIndex();
}
LogPage::LogPage(InstancePtr instance, QWidget* parent) : QWidget(parent), ui(new Ui::LogPage), m_instance(instance) LogPage::LogPage(InstancePtr instance, QWidget* parent) : QWidget(parent), ui(new Ui::LogPage), m_instance(instance)
{ {
ui->setupUi(this); ui->setupUi(this);

View file

@ -42,23 +42,11 @@
#include "BaseInstance.h" #include "BaseInstance.h"
#include "launch/LaunchTask.h" #include "launch/LaunchTask.h"
#include "ui/pages/BasePage.h" #include "ui/pages/BasePage.h"
#include "ui/pages/global/LauncherLogPage.h"
namespace Ui { namespace Ui {
class LogPage; class LogPage;
} }
class QTextCharFormat;
class LogFormatProxyModel : public QIdentityProxyModel {
public:
LogFormatProxyModel(QObject* parent = nullptr) : QIdentityProxyModel(parent) {}
QVariant data(const QModelIndex& index, int role) const override;
QFont getFont() const { return m_font; }
void setFont(QFont font) { m_font = font; }
QModelIndex find(const QModelIndex& start, const QString& value, bool reverse) const;
private:
QFont m_font;
};
class LogPage : public QWidget, public BasePage { class LogPage : public QWidget, public BasePage {
Q_OBJECT Q_OBJECT