Skip to content

Commit

Permalink
Big Upgrade:
Browse files Browse the repository at this point in the history
1. It's AxTrace4 now
2. Use QT as UI framework
3. Add 2D Map feature
  • Loading branch information
thejinchao committed Apr 11, 2019
1 parent 0b29a76 commit b8ec7d9
Show file tree
Hide file tree
Showing 343 changed files with 93,578 additions and 71,769 deletions.
17 changes: 17 additions & 0 deletions AT4.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>images/AxTrace.ico</file>
<file>images/capture.png</file>
<file>images/save.png</file>

<file>images/auto-scroll.png</file>
<file>images/copy.png</file>
<file>images/clean.png</file>
<file>images/clean-all.png</file>

<file>images/grid.png</file>
<file>images/setting.png</file>

<file>images/about.png</file>
</qresource>
</RCC>
115 changes: 115 additions & 0 deletions AT4_Camera2D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "stdafx.h"
#include "AT4_Camera2D.h"


//--------------------------------------------------------------------------------------------
Camera2D::Camera2D()
: m_scale(1.0)
, m_draging(false)
{

}

//--------------------------------------------------------------------------------------------
Camera2D::~Camera2D()
{

}

//--------------------------------------------------------------------------------------------
void Camera2D::_updateTransform(void)
{
qreal screenRatio = (qreal)m_viewSize.width() / (qreal)m_viewSize.height();
qreal sceneRatio = abs(m_sceneRect.width() / m_sceneRect.height());

if (screenRatio > sceneRatio)
{
m_scale = m_viewSize.height() / abs(m_sceneRect.height()*1.2);
}
else
{
m_scale = m_viewSize.width() / abs(m_sceneRect.width()*1.2);
}

int flipX = m_sceneRect.width() > 0 ? 1 : -1;
int flipY = m_sceneRect.height() > 0 ? 1 : -1;

m_transform = QTransform::fromTranslate(-m_sceneRect.left(), -m_sceneRect.top());
m_transform *= QTransform::fromScale(flipX*m_scale, flipY*m_scale);
m_transform *= QTransform::fromTranslate((m_viewSize.width() - abs(m_sceneRect.width()) * m_scale) / 2, (m_viewSize.height() - abs(m_sceneRect.height()) * m_scale) / 2);
}

//--------------------------------------------------------------------------------------------
void Camera2D::reset(const QSize& viewSize, const QRectF& sceneRect)
{
if (viewSize==m_viewSize && m_sceneRect == sceneRect) return;

m_viewSize = viewSize;
m_sceneRect = sceneRect;

_updateTransform();
}

//--------------------------------------------------------------------------------------------
void Camera2D::updateViewSize(const QSize& viewSize)
{
m_viewSize = viewSize;
}

//--------------------------------------------------------------------------------------------
QPointF Camera2D::screenToScene(const QPoint& pos)
{
bool invertAble;
QTransform inv = m_transform.inverted(&invertAble);
if (invertAble) {
QPointF scenePos = inv * QPointF(pos);
return scenePos;
}

return QPointF(pos);
}

//--------------------------------------------------------------------------------------------
void Camera2D::onMouseWheel(QWheelEvent *e)
{
qreal scale = 1.0;
if (e->delta() > 0) {
scale = 1.2;
}
else {
scale = 0.9;
}

QPoint mousePoint = e->pos();
m_transform *= QTransform::fromTranslate(-mousePoint.x(), -mousePoint.y());
m_transform *= QTransform::fromScale(scale, scale);
m_transform *= QTransform::fromTranslate(mousePoint.x(), mousePoint.y());

m_scale *= scale;
}

//--------------------------------------------------------------------------------------------
void Camera2D::beginDrag(QMouseEvent *e)
{
m_draging = true;
m_beginDragPoint = e->pos();
m_tragingTransform = m_transform;
}

//--------------------------------------------------------------------------------------------
void Camera2D::drag(QMouseEvent *e)
{
if (!m_draging) return;

QPoint move = e->pos() - m_beginDragPoint;
m_transform = m_tragingTransform * QTransform::fromTranslate(move.x(), move.y());
}

//--------------------------------------------------------------------------------------------
void Camera2D::endDrag(QMouseEvent *e)
{
m_draging = false;

QPoint move = e->pos() - m_beginDragPoint;
m_transform = m_tragingTransform * QTransform::fromTranslate(move.x(), move.y());
}
41 changes: 41 additions & 0 deletions AT4_Camera2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

class Camera2D
{
public:
void reset(const QSize& viewSize, const QRectF& sceneRect);

void updateViewSize(const QSize& viewSize);
const QSize& getViewSize(void) const { return m_viewSize; }

const QRectF& getSceneRect(void) const { return m_sceneRect; }

QPointF screenToScene(const QPoint& pos);

qreal getScale(void) const { return m_scale; }
const QTransform& getTransform(void) const { return m_transform; }

void onMouseWheel(QWheelEvent *e);
void beginDrag(QMouseEvent *e);
void drag(QMouseEvent *e);
void endDrag(QMouseEvent *e);
bool isDraging(void) const { return m_draging; }

private:
void _updateTransform(void);

private:
QSize m_viewSize;
QRectF m_sceneRect;

qreal m_scale;
QTransform m_transform;

bool m_draging;
QPoint m_beginDragPoint;
QTransform m_tragingTransform;

public:
Camera2D();
~Camera2D();
};
25 changes: 25 additions & 0 deletions AT4_ChildInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

class IChild : public QObjectUserData
{
public:
enum Type
{
CT_LOG,
CT_VALUE,
CT_2DMAP,
};

virtual Type getType(void) const = 0;
virtual QString getTitle(void) const = 0;

virtual bool copyAble(void) const = 0;
virtual void onCopy(void) const = 0;

virtual void clean(void) = 0;

virtual void saveAs(void) = 0;

virtual void update(void) = 0;
};

109 changes: 109 additions & 0 deletions AT4_Config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "stdafx.h"
#include "AT4_Config.h"

//--------------------------------------------------------------------------------------------
Config::Config()
{
// reset setting to default
_resetToDefaultSetting();
}

//--------------------------------------------------------------------------------------------
Config::Config(const Config& other)
{
// reset setting to default
_resetToDefaultSetting();
copyFrom(other);
}

//--------------------------------------------------------------------------------------------
Config::~Config()
{
saveSetting();
}

//--------------------------------------------------------------------------------------------
void Config::_resetToDefaultSetting(void)
{
m_bCapture = true;
m_bAutoScroll = true;
m_bShowGrid = true;
m_filterScript = m_defaultFilterScript = QString(
"function onLogMessage(msg)\r\n"
" local frontColor=COL_BLACK; \r\n"
" local backColor=COL_WHITE; \r\n"
" local logType=msg:get_log_type(); \r\n"
" if(logType==AXT_ERROR) then \r\n"
" frontColor=COL_RED; \r\n"
" end; \r\n"
" if(logType==AXT_FATAL) then \r\n"
" frontColor=COL_RED; \r\n"
" backColor=COL_YELLOW; \r\n"
" end; \r\n"
" return true, \"defult\", frontColor, backColor; \r\n"
"end\n\r\n"
"function onValueMessage(msg) \r\n"
" return true, \"defult\", COL_BLACK, COL_WHITE; \r\n"
"end; \r\n\r\n"
"function onActor2DMessage(msg)\r\n"
" return true, ACTOR_CIRCLE, 1, COL_WHITE, COL_GRAY; \r\n"
"end; \r\n"
);
m_maxLogCounts = 10000;
}

//--------------------------------------------------------------------------------------------
void Config::copyFrom(const Config& other)
{
m_bCapture = other.m_bCapture;
m_bAutoScroll = other.m_bAutoScroll;
m_filterScript = other.m_filterScript;
m_maxLogCounts = other.m_maxLogCounts;
}

//--------------------------------------------------------------------------------------------
void Config::setFilterScript(const QString& script)
{
m_filterScript = script;
saveSetting();
}

//--------------------------------------------------------------------------------------------
void Config::setMainGeometry(const QByteArray& geometry)
{
m_mainGeometry = geometry;
}

//--------------------------------------------------------------------------------------------
void Config::setMaxLogCounts(int maxLogCounts)
{
m_maxLogCounts = maxLogCounts;
}

//--------------------------------------------------------------------------------------------
void Config::loadSetting(void)
{
_resetToDefaultSetting();

//Load setting from disk
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());

m_bAutoScroll = settings.value("AutoScroll", m_bAutoScroll).toBool();
m_bShowGrid = settings.value("ShowGrid", m_bShowGrid).toBool();
m_mainGeometry = settings.value("MainGeometry", QByteArray()).toByteArray();
m_filterScript = settings.value("FilterScript", m_filterScript).toString();
m_maxLogCounts = settings.value("MaxLogCounts", m_maxLogCounts).toInt();
}

//--------------------------------------------------------------------------------------------
void Config::saveSetting(void) const
{
// Save setting to disk
QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());

settings.setValue("AutoScroll", m_bAutoScroll);
settings.setValue("ShowGrid", m_bShowGrid);
settings.setValue("MainGeometry", m_mainGeometry);
settings.setValue("FilterScript", m_filterScript);
settings.setValue("MaxLogCounts", m_maxLogCounts);
}
46 changes: 46 additions & 0 deletions AT4_Config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

class Config
{
public:
void loadSetting(void);
void saveSetting(void) const;
void copyFrom(const Config& other);

bool getCapture(void) const { return m_bCapture; }
void setCapture(bool c) { m_bCapture = c; }

bool getAutoScroll(void) const { return m_bAutoScroll; }
void setAutoScroll(bool a) { m_bAutoScroll = a; }

bool getShowGrid(void) const { return m_bShowGrid; }
void setShowGrid(bool s) { m_bShowGrid = s; }

const QString& getFilterScript(void) const { return m_filterScript; }
void setFilterScript(const QString& script);

const QByteArray& getMainGeometry(void) const { return m_mainGeometry; }
void setMainGeometry(const QByteArray& geometry);

const QString& getDefaultFilterScript(void) const { return m_defaultFilterScript; }

int getMaxLogCounts(void) const { return m_maxLogCounts; }
void setMaxLogCounts(int maxLogCounts);

private:
void _resetToDefaultSetting(void);

private:
bool m_bCapture;
bool m_bAutoScroll;
bool m_bShowGrid;
QString m_filterScript;
QString m_defaultFilterScript;
QByteArray m_mainGeometry;
int m_maxLogCounts;

public:
Config();
Config(const Config& other);
~Config();
};
Loading

0 comments on commit b8ec7d9

Please sign in to comment.