moved files, made Log.ui

This commit is contained in:
Geoffray Levasseur committed 2026-10-27 14:09:42 +01:00
1 parent 339e2c8a4b
commit ba8b69d771
8 files changed
+206 -80

No files matched your search

+6 -5
View File
@@ -87,11 +87,12 @@ if(CEVO_WITH_APP)
set(PROJECT_SOURCES set(PROJECT_SOURCES
main.cpp main.cpp
mainwindow.cpp game/mainwindow.cpp
mainwindow.h game/mainwindow.h
mainwindow.ui game/mainwindow.ui
Log.cpp game/Log.cpp
Log.h game/Log.h
game/Log.ui
${TS_FILES} ${TS_FILES}
) )
+39 -64
View File
@@ -27,101 +27,76 @@
// knowledge of the CeCILL license and that you accept its terms. // knowledge of the CeCILL license and that you accept its terms.
#include "Log.h" #include "Log.h"
#include "ui_Log.h"
#include <QActionGroup>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu>
#include <QScrollBar> #include <QScrollBar>
#include <QTextCursor> #include <QTextCursor>
#include <QVBoxLayout>
#include <array>
namespace Cevo { namespace Cevo {
LogDlg::LogDlg(QWidget *parent) : Dpi::Form(parent) LogDlg::LogDlg(QWidget *parent) : Dpi::Form(parent), ui(new Ui::LogDlg)
{ {
ui->setupUi(this);
setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint); setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint);
setWindowTitle(tr("Log")); ui->list->installEventFilter(this);
resize(339, 280); connect(ui->list, &QPlainTextEdit::customContextMenuRequested, this, [this](const QPoint &pos) {
logPopup->popup(ui->list->mapToGlobal(pos));
list = new Dpi::Memo(this);
list->setReadOnly(true);
list->setLineWrapMode(Dpi::Memo::NoWrap);
list->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
list->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
list->setContextMenuPolicy(Qt::CustomContextMenu);
list->installEventFilter(this);
connect(list, &QPlainTextEdit::customContextMenuRequested, this, [this](const QPoint &pos) {
logPopup->popup(list->mapToGlobal(pos));
}); });
auto *layout = new QVBoxLayout(this); logPopup = new QMenu(this);
layout->setContentsMargins(0, 0, 0, 0); logPopup->addAction(ui->actionInvalid);
layout->setSpacing(0); logPopup->addAction(ui->actionNegotiation);
layout->addWidget(list); logPopup->addAction(ui->actionTime);
logPopup->addSeparator();
logPopup = new Dpi::PopupMenu(this); auto *logLevelGroup = new QActionGroup(this);
logPopup->setAutoPopup(false); QAction *logLevelActions[4] = { ui->actionLog0, ui->actionLog1, ui->actionLog2, ui->actionLog3 };
mInvalid = logPopup->add(tr("Invalid Server Calls"));
mInvalid->action()->setCheckable(true);
mInvalid->onClick = [this] { mInvalid->setChecked(!mInvalid->checked()); };
mNegotiation = logPopup->add(tr("Negotiation"));
mNegotiation->action()->setCheckable(true);
mNegotiation->onClick = [this] { mNegotiation->setChecked(!mNegotiation->checked()); };
mTime = logPopup->add(tr("Client Handover"));
mTime->action()->setCheckable(true);
mTime->onClick = [this] { mTime->setChecked(!mTime->checked()); };
logPopup->add(QString())->action()->setSeparator(true);
const std::array<Dpi::MenuItem *, 4> logLevels = {
logPopup->add(tr("AI Messages Off")),
logPopup->add(tr("AI Messages Level 1")),
logPopup->add(tr("AI Messages Level 1+2")),
logPopup->add(tr("All AI Messages")),
};
static constexpr int logLevelValue[4] = { 0, 1, 2, 999 }; static constexpr int logLevelValue[4] = { 0, 1, 2, 999 };
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {
Dpi::MenuItem *item = logLevels[i]; logLevelGroup->addAction(logLevelActions[i]);
item->setRadioItem(true); logPopup->addAction(logLevelActions[i]);
item->onClick = [this, logLevels, i] { setMaxLevel(logLevelValue[i], logLevels, i); }; connect(logLevelActions[i], &QAction::triggered, this, [this, i] { setMaxLevel(logLevelValue[i], i); });
} }
logLevels[0]->setChecked(true); logPopup->addSeparator();
logPopup->addAction(ui->actionSlot);
logPopup->addAction(ui->actionClear);
logPopup->add(QString())->action()->setSeparator(true); connect(ui->actionSlot, &QAction::triggered, this, [] {
Dpi::MenuItem *mSlot = logPopup->add(tr("Nation <-> Slot"));
mSlot->onClick = [this] {
// TODO: needs G.Difficulty[]/Tribe[].TPhrase("SHORTNAME") (Global.pas/ // TODO: needs G.Difficulty[]/Tribe[].TPhrase("SHORTNAME") (Global.pas/
// Tribes.pas, not ported yet) - deferred until those units exist. // Tribes.pas, not ported yet) - deferred until those units exist.
}; });
connect(ui->actionClear, &QAction::triggered, ui->list, &QPlainTextEdit::clear);
Dpi::MenuItem *mClear = logPopup->add(tr("Clear"));
mClear->onClick = [this] { list->clear(); };
} }
void LogDlg::setMaxLevel(int value, const std::array<Dpi::MenuItem *, 4> &items, int checkedIndex) LogDlg::~LogDlg()
{
delete ui;
}
void LogDlg::setMaxLevel(int value, int checkedIndex)
{ {
maxLevel = value; maxLevel = value;
for (int i = 0; i < 4; ++i) Q_UNUSED(checkedIndex); // the QActionGroup already enforces mutual exclusivity
items[i]->setChecked(i == checkedIndex); // Dpi::MenuItem has no automatic radio grouping
} }
void LogDlg::add(int level, int turn, const QString &text) void LogDlg::add(int level, int turn, const QString &text)
{ {
if ((maxLevel > 0 && level <= maxLevel) || (level == (1 << 16) + 1 && mInvalid->checked()) || if ((maxLevel > 0 && level <= maxLevel) || (level == (1 << 16) + 1 && ui->actionInvalid->isChecked()) ||
(level == (1 << 16) + 2 && mTime->checked()) || (level == (1 << 16) + 3 && mNegotiation->checked())) { (level == (1 << 16) + 2 && ui->actionTime->isChecked()) ||
if (list->document()->blockCount() == MaxLines) { (level == (1 << 16) + 3 && ui->actionNegotiation->isChecked())) {
QTextCursor cursor(list->document()); if (ui->list->document()->blockCount() == MaxLines) {
QTextCursor cursor(ui->list->document());
cursor.movePosition(QTextCursor::Start); cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor); cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor);
cursor.removeSelectedText(); cursor.removeSelectedText();
} }
const QString prefix = const QString prefix =
QString("%1%2%3").arg((turn / 100) % 10).arg((turn / 10) % 10).arg(turn % 10); QString("%1%2%3").arg((turn / 100) % 10).arg((turn / 10) % 10).arg(turn % 10);
list->appendPlainText(prefix + ' ' + text); ui->list->appendPlainText(prefix + ' ' + text);
QScrollBar *vBar = list->verticalScrollBar(); QScrollBar *vBar = ui->list->verticalScrollBar();
vBar->setValue(vBar->maximum()); vBar->setValue(vBar->maximum());
repaint(); repaint();
} }
@@ -143,7 +118,7 @@ void LogDlg::keyReleaseEvent(QKeyEvent *event)
bool LogDlg::eventFilter(QObject *watched, QEvent *event) bool LogDlg::eventFilter(QObject *watched, QEvent *event)
{ {
if (watched == list && host) { if (watched == ui->list && host) {
if (event->type() == QEvent::KeyPress && host->onKeyDown) if (event->type() == QEvent::KeyPress && host->onKeyDown)
host->onKeyDown(static_cast<QKeyEvent *>(event)); host->onKeyDown(static_cast<QKeyEvent *>(event));
else if (event->type() == QEvent::KeyRelease && host->onKeyUp) else if (event->type() == QEvent::KeyRelease && host->onKeyUp)
+14 -10
View File
@@ -29,21 +29,28 @@
#pragma once #pragma once
#include "Dpi/DpiForms.h" #include "Dpi/DpiForms.h"
#include "Dpi/DpiMenus.h"
#include "Dpi/DpiStdCtrls.h"
#include <QString> #include <QString>
#include <array>
class QMenu;
QT_BEGIN_NAMESPACE
namespace Ui {
class LogDlg;
}
QT_END_NAMESPACE
namespace Cevo { namespace Cevo {
// TLogDlg equivalent: a floating, always-on-top debug/diagnostic log window // TLogDlg equivalent: a floating, always-on-top debug/diagnostic log window
// (AI messages, invalid server calls, client handover, negotiation), with a // (AI messages, invalid server calls, client handover, negotiation), with a
// right-click popup menu to filter what gets shown. // right-click popup menu to filter what gets shown. UI built from Log.ui
// (adapted from the original's Log.lfm).
class LogDlg : public Dpi::Form { class LogDlg : public Dpi::Form {
Q_OBJECT Q_OBJECT
public: public:
explicit LogDlg(QWidget *parent = nullptr); explicit LogDlg(QWidget *parent = nullptr);
~LogDlg() override;
// Forwards key events so the game's global hotkeys keep working while // Forwards key events so the game's global hotkeys keep working while
// the log window (KeyPreview in the original) has focus. // the log window (KeyPreview in the original) has focus.
@@ -61,13 +68,10 @@ private:
int maxLevel = 0; int maxLevel = 0;
Dpi::Memo *list; Ui::LogDlg *ui;
Dpi::PopupMenu *logPopup; QMenu *logPopup;
Dpi::MenuItem *mInvalid;
Dpi::MenuItem *mNegotiation;
Dpi::MenuItem *mTime;
void setMaxLevel(int value, const std::array<Dpi::MenuItem *, 4> &items, int checkedIndex); void setMaxLevel(int value, int checkedIndex);
}; };
} // namespace Cevo } // namespace Cevo
+146
View File
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
This file is part of cevo-evo.
This software is governed by the CeCILL license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/or redistribute the software under the terms of the CeCILL
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL license and that you accept its terms.
-->
<ui version="4.0">
<class>LogDlg</class>
<widget class="QWidget" name="LogDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>339</width>
<height>280</height>
</rect>
</property>
<property name="windowTitle">
<string>Log</string>
</property>
<layout class="QVBoxLayout" name="mainLayout">
<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>
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QPlainTextEdit" name="list">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="lineWrapMode">
<enum>QPlainTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
<action name="actionInvalid">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Invalid Server Calls</string>
</property>
</action>
<action name="actionNegotiation">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Negotiation</string>
</property>
</action>
<action name="actionTime">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Client Handover</string>
</property>
</action>
<action name="actionLog0">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>AI Messages Off</string>
</property>
</action>
<action name="actionLog1">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>AI Messages Level 1</string>
</property>
</action>
<action name="actionLog2">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>AI Messages Level 1+2</string>
</property>
</action>
<action name="actionLog3">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>All AI Messages</string>
</property>
</action>
<action name="actionSlot">
<property name="text">
<string>Nation &lt;-&gt; Slot</string>
</property>
</action>
<action name="actionClear">
<property name="text">
<string>Clear</string>
</property>
</action>
</widget>
<resources/>
</ui>
File renamed without changes.
View File
File renamed without changes.
File renamed without changes.
+1 -1
View File
@@ -26,7 +26,7 @@
// The fact that you are presently reading this means that you have had // The fact that you are presently reading this means that you have had
// knowledge of the CeCILL license and that you accept its terms. // knowledge of the CeCILL license and that you accept its terms.
#include "mainwindow.h" #include "game/mainwindow.h"
#include <QApplication> #include <QApplication>
#include <QLocale> #include <QLocale>