This commit is contained in:
寂静的羽夏 2022-08-25 23:48:57 +08:00
parent 332794369d
commit bd873f904d
5 changed files with 273 additions and 171 deletions

View File

@ -260,7 +260,9 @@ QByteArray QHexRenderer::getLine(quint64 line) const {
return m_document->read(qint64(line * quint64(hexLineWidth())), return m_document->read(qint64(line * quint64(hexLineWidth())),
hexLineWidth()); hexLineWidth());
} }
void QHexRenderer::blinkCursor() { m_cursorenabled = !m_cursorenabled; } void QHexRenderer::blinkCursor() { m_cursorenabled = !m_cursorenabled; }
qint64 QHexRenderer::rendererLength() const { return m_document->length() + 1; } qint64 QHexRenderer::rendererLength() const { return m_document->length() + 1; }
// modified by wingsummer // modified by wingsummer

View File

@ -19,7 +19,7 @@ SOURCES += \
$$PWD/class/logger.cpp \ $$PWD/class/logger.cpp \
$$PWD/dialog/settingwindow.cpp \ $$PWD/dialog/settingwindow.cpp \
$$PWD/mlicense/licensemanager.cpp \ $$PWD/mlicense/licensemanager.cpp \
$$PWD/mlicense/lincensedialog.cpp \ $$PWD/mlicense/lincensedialog.cpp
RESOURCES += resources.qrc RESOURCES += resources.qrc
@ -49,7 +49,7 @@ HEADERS += \
$$PWD/dialog/settingwindow.h \ $$PWD/dialog/settingwindow.h \
$$PWD/mlicense/licensemanager.h \ $$PWD/mlicense/licensemanager.h \
$$PWD/mlicense/lincensedialog.h \ $$PWD/mlicense/lincensedialog.h \
$$PWD/mlicense/qaesencryption.h \ $$PWD/mlicense/qaesencryption.h
LIBS += $$PWD/mlicense/libQtAES.a LIBS += $$PWD/mlicense/libQtAES.a

View File

@ -1589,9 +1589,10 @@ void MainWindow::connectBase(IWingPlugin *plugin) {
void MainWindow::connectControl(IWingPlugin *plugin) { void MainWindow::connectControl(IWingPlugin *plugin) {
auto pctl = &plugin->controller;
#define ConnectControlLamba(Signal, Function) connect(plugin, &Signal, Function) #define ConnectControlLamba(Signal, Function) connect(plugin, &Signal, Function)
#define ConnectControlLamba2(Signal, Function) \ #define ConnectControlLamba2(Signal, Function) connect(pctl, &Signal, Function)
connect(&plugin->controller, &Signal, Function)
ConnectControlLamba2( ConnectControlLamba2(
WingPlugin::Controller::switchDocument, [=](int index, bool gui) { WingPlugin::Controller::switchDocument, [=](int index, bool gui) {
@ -1657,39 +1658,124 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
hexeditor->document()->paste(hex), ) hexeditor->document()->paste(hex), )
}); });
#define ConnectControlLamba3(Signal, Function) \ connect(pctl, QOverload<qint64, uchar>::of(&WingPlugin::Controller::insert),
connect(&plugin->controller, Signal, Function) [=](qint64 offset, uchar b) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECKRETURN(hexfiles[_pcurfile].doc->insert(offset, b),
hexeditor->document()->insert(offset, b), false);
});
bool (WingPlugin::Controller::*insertchar)(qint64 offset, uchar b) = connect(pctl,
&WingPlugin::Controller::insert; QOverload<qint64, const QByteArray &>::of(
bool (WingPlugin::Controller::*insertarr)( &WingPlugin::Controller::insert),
qint64 offset, const QByteArray &data) = &WingPlugin::Controller::insert; [=](qint64 offset, const QByteArray &data) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
ConnectControlLamba3(insertchar, [=](qint64 offset, uchar b) { PCHECKRETURN(hexfiles[_pcurfile].doc->insert(offset, data),
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); hexeditor->document()->insert(offset, data), false);
PCHECKRETURN(hexfiles[_pcurfile].doc->insert(offset, b), });
hexeditor->document()->insert(offset, b), false); connect(pctl, QOverload<qint64, uchar>::of(&WingPlugin::Controller::write),
}); [=](qint64 offset, uchar b) {
ConnectControlLamba3(insertarr, [=](qint64 offset, const QByteArray &data) { plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); PCHECKRETURN(hexfiles[_pcurfile].doc->replace(offset, b),
PCHECKRETURN(hexfiles[_pcurfile].doc->insert(offset, data), hexeditor->document()->replace(offset, b), false);
hexeditor->document()->insert(offset, data), false); });
}); ConnectControlLamba2(
WingPlugin::Controller::insertInt8, [=](qint64 offset, qint8 value) {
bool (WingPlugin::Controller::*writechar)(qint64 offset, uchar b) = plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
&WingPlugin::Controller::write; PCHECK(
bool (WingPlugin::Controller::*writearr)( {
qint64 offset, const QByteArray &data) = &WingPlugin::Controller::write; auto doc = hexfiles[_pcurfile].doc;
ConnectControlLamba3(writechar, [=](qint64 offset, uchar b) { auto buffer = reinterpret_cast<char *>(&value);
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); return doc->insert(offset, QByteArray(buffer, sizeof(qint8)));
PCHECKRETURN(hexfiles[_pcurfile].doc->replace(offset, b), },
hexeditor->document()->replace(offset, b), false); {
}); auto doc = hexeditor->document();
ConnectControlLamba3(writearr, [=](qint64 offset, const QByteArray &data) { auto buffer = reinterpret_cast<char *>(&value);
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); return doc->insert(offset, QByteArray(buffer, sizeof(qint8)));
PCHECKRETURN(hexfiles[_pcurfile].doc->replace(offset, data), },
hexeditor->document()->replace(offset, data), false); return false;)
}); });
ConnectControlLamba2(
WingPlugin::Controller::insertInt16, [=](qint64 offset, qint16 value) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto doc = hexfiles[_pcurfile].doc;
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint16)));
},
{
auto doc = hexeditor->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint16)));
},
return false;)
});
ConnectControlLamba2(
WingPlugin::Controller::insertInt16, [=](qint64 offset, qint32 value) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto doc = hexfiles[_pcurfile].doc;
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint32)));
},
{
auto doc = hexeditor->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint32)));
},
return false;)
});
ConnectControlLamba2(
WingPlugin::Controller::insertInt16, [=](qint64 offset, qint64 value) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto doc = hexfiles[_pcurfile].doc;
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint64)));
},
{
auto doc = hexeditor->document();
auto buffer = reinterpret_cast<char *>(&value);
return doc->insert(offset, QByteArray(buffer, sizeof(qint64)));
},
return false;)
});
ConnectControlLamba2(
WingPlugin::Controller::insertString,
[=](qint64 offset, QString value, QString encoding) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto render = hexfiles[_pcurfile].render;
if (!encoding.length())
encoding = render->encoding();
auto enc = QTextCodec::codecForName(encoding.toUtf8());
auto e = enc->makeEncoder();
return hexfiles[_pcurfile].doc->insert(offset,
e->fromUnicode(value));
},
{
auto render = hexeditor->renderer();
if (!encoding.length())
encoding = render->encoding();
auto enc = QTextCodec::codecForName(encoding.toUtf8());
auto e = enc->makeEncoder();
return hexeditor->document()->insert(offset,
e->fromUnicode(value));
},
return false);
});
connect(
pctl,
QOverload<qint64, const QByteArray &>::of(&WingPlugin::Controller::write),
[=](qint64 offset, const QByteArray &data) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECKRETURN(hexfiles[_pcurfile].doc->replace(offset, data),
hexeditor->document()->replace(offset, data), false);
});
ConnectControlLamba2( ConnectControlLamba2(
WingPlugin::Controller::writeInt8, [=](qint64 offset, qint8 value) { WingPlugin::Controller::writeInt8, [=](qint64 offset, qint8 value) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
@ -1779,43 +1865,40 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
}, },
return false); return false);
}); });
connect(pctl, QOverload<uchar>::of(&WingPlugin::Controller::append),
[=](uchar b) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto doc = hexfiles[_pcurfile].doc;
auto offset = doc->length();
return doc->insert(offset, b);
},
{
auto doc = hexeditor->document();
auto offset = doc->length();
return doc->insert(offset, b);
},
return false;);
});
bool (WingPlugin::Controller::*appendchar)(uchar b) = connect(pctl,
&WingPlugin::Controller::append; QOverload<const QByteArray &>::of(&WingPlugin::Controller::append),
bool (WingPlugin::Controller::*appendarr)(const QByteArray &data) = [=](const QByteArray &data) {
&WingPlugin::Controller::append; plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
ConnectControlLamba3(appendchar, [=](uchar b) { {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); auto doc = hexfiles[_pcurfile].doc;
PCHECK( auto offset = doc->length();
{ return doc->insert(offset, data);
auto doc = hexfiles[_pcurfile].doc; },
auto offset = doc->length(); {
return doc->insert(offset, b); auto doc = hexeditor->document();
}, auto offset = doc->length();
{ return doc->insert(offset, data);
auto doc = hexeditor->document(); },
auto offset = doc->length(); return false;);
return doc->insert(offset, b); });
},
return false;);
});
ConnectControlLamba3(appendarr, [=](const QByteArray &data) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto doc = hexfiles[_pcurfile].doc;
auto offset = doc->length();
return doc->insert(offset, data);
},
{
auto doc = hexeditor->document();
auto offset = doc->length();
return doc->insert(offset, data);
},
return false;);
});
ConnectControlLamba2(WingPlugin::Controller::appendInt8, [=](qint8 value) { ConnectControlLamba2(WingPlugin::Controller::appendInt8, [=](qint8 value) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK( PCHECK(
@ -1892,6 +1975,33 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
}, },
return false;); return false;);
}); });
ConnectControlLamba2(
WingPlugin::Controller::appendString,
[=](QString value, QString encoding) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
{
auto render = hexfiles[_pcurfile].render;
if (!encoding.length())
encoding = render->encoding();
auto offset = hexfiles[_pcurfile].doc->length();
auto enc = QTextCodec::codecForName(encoding.toUtf8());
auto e = enc->makeEncoder();
return hexfiles[_pcurfile].doc->insert(offset,
e->fromUnicode(value));
},
{
auto render = hexeditor->renderer();
if (!encoding.length())
encoding = render->encoding();
auto offset = hexeditor->document()->length();
auto enc = QTextCodec::codecForName(encoding.toUtf8());
auto e = enc->makeEncoder();
return hexeditor->document()->replace(offset,
e->fromUnicode(value));
},
return false);
});
ConnectControlLamba2( ConnectControlLamba2(
WingPlugin::Controller::remove, [=](qint64 offset, int len) { WingPlugin::Controller::remove, [=](qint64 offset, int len) {
@ -1914,66 +2024,61 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
}, },
return false;); return false;);
}); });
connect(pctl,
void (WingPlugin::Controller::*moveToHP)(const HexPosition &pos) = QOverload<const HexPosition &>::of(&WingPlugin::Controller::moveTo),
&WingPlugin::Controller::moveTo; [=](const HexPosition &pos) {
void (WingPlugin::Controller::*moveTo)(quint64 line, int column, plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
int nibbleindex) = PCHECK(
&WingPlugin::Controller::moveTo; {
QHexPosition p;
void (WingPlugin::Controller::*moveToOff)(qint64 offset); p.line = pos.line;
ConnectControlLamba3(moveToHP, [=](const HexPosition &pos) { p.column = pos.column;
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); p.lineWidth = pos.lineWidth;
PCHECK( p.nibbleindex = pos.nibbleindex;
{ hexfiles[_pcurfile].doc->cursor()->moveTo(p);
QHexPosition p; },
p.line = pos.line; {
p.column = pos.column; QHexPosition p;
p.lineWidth = pos.lineWidth; p.line = pos.line;
p.nibbleindex = pos.nibbleindex; p.column = pos.column;
hexfiles[_pcurfile].doc->cursor()->moveTo(p); p.lineWidth = pos.lineWidth;
}, p.nibbleindex = pos.nibbleindex;
{ hexeditor->document()->cursor()->moveTo(p);
QHexPosition p; }, );
p.line = pos.line; });
p.column = pos.column; connect(pctl,
p.lineWidth = pos.lineWidth; QOverload<quint64, int, int>::of(&WingPlugin::Controller::moveTo),
p.nibbleindex = pos.nibbleindex; [=](quint64 line, int column, int nibbleindex) {
hexeditor->document()->cursor()->moveTo(p); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
}, ); PCHECK(hexfiles[_pcurfile].doc->cursor()->moveTo(line, column,
}); nibbleindex),
ConnectControlLamba3(moveTo, [=](quint64 line, int column, int nibbleindex) { hexeditor->document()->cursor()->moveTo(line, column,
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); nibbleindex), );
PCHECK( });
hexfiles[_pcurfile].doc->cursor()->moveTo(line, column, nibbleindex), connect(pctl, QOverload<qint64>::of(&WingPlugin::Controller::moveTo),
hexeditor->document()->cursor()->moveTo(line, column, nibbleindex), ); [=](qint64 offset) {
}); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
ConnectControlLamba3(moveToOff, [=](qint64 offset) { PCHECK(hexfiles[_pcurfile].doc->cursor()->moveTo(offset),
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); hexeditor->document()->cursor()->moveTo(offset), );
PCHECK(hexfiles[_pcurfile].doc->cursor()->moveTo(offset), });
hexeditor->document()->cursor()->moveTo(offset), ); connect(pctl, QOverload<qint64, int>::of(&WingPlugin::Controller::select),
}); [=](qint64 offset, int length) {
PCHECK(
void (WingPlugin::Controller::*select)(quint64 line, int column, hexfiles[_pcurfile].doc->cursor()->setSelection(offset, length),
int nibbleindex) = {
&WingPlugin::Controller::select; hexeditor->document()->cursor()->setSelection(offset, length);
hexeditor->viewport()->update();
void (WingPlugin::Controller::*selectN)(qint64 offset, int length) = }, )
&WingPlugin::Controller::select; });
connect(pctl,
ConnectControlLamba3(selectN, [=](qint64 offset, int length) { QOverload<quint64, int, int>::of(&WingPlugin::Controller::select),
PCHECK( [=](quint64 line, int column, int nibbleindex) {
hexfiles[_pcurfile].doc->cursor()->setSelection(offset, length), { plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
hexeditor->document()->cursor()->setSelection(offset, length); PCHECK(hexfiles[_pcurfile].doc->cursor()->select(line, column,
hexeditor->viewport()->update(); nibbleindex),
}, ) hexeditor->document()->cursor()->select(line, column,
}); nibbleindex), );
ConnectControlLamba3(select, [=](quint64 line, int column, int nibbleindex) { });
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(
hexfiles[_pcurfile].doc->cursor()->select(line, column, nibbleindex),
hexeditor->document()->cursor()->select(line, column, nibbleindex), );
});
ConnectControlLamba2(WingPlugin::Controller::enabledCursor, [=](bool b) { ConnectControlLamba2(WingPlugin::Controller::enabledCursor, [=](bool b) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK(hexfiles[_pcurfile].render->enableCursor(b), PCHECK(hexfiles[_pcurfile].render->enableCursor(b),
@ -1996,19 +2101,12 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
isinsert ? QHexCursor::InsertMode isinsert ? QHexCursor::InsertMode
: QHexCursor::OverwriteMode), ); : QHexCursor::OverwriteMode), );
}); });
connect(
bool (WingPlugin::Controller::*metadata)( pctl,
qint64 begin, qint64 end, const QColor &fgcolor, const QColor &bgcolor, QOverload<qint64, qint64, const QColor &, const QColor &,
const QString &comment) = &WingPlugin::Controller::metadata; const QString &>::of(&WingPlugin::Controller::metadata),
[=](qint64 begin, qint64 end, const QColor &fgcolor,
bool (WingPlugin::Controller::*metadataL)( const QColor &bgcolor, const QString &comment) {
quint64 line, int start, int length, const QColor &fgcolor,
const QColor &bgcolor, const QString &comment) =
&WingPlugin::Controller::metadata;
ConnectControlLamba3(
metadata, [=](qint64 begin, qint64 end, const QColor &fgcolor,
const QColor &bgcolor, const QString &comment) {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK( PCHECK(
{ {
@ -2029,31 +2127,33 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
}, },
return false); return false);
}); });
ConnectControlLamba3( connect(pctl,
metadataL, [=](quint64 line, int start, int length, const QColor &fgcolor, QOverload<quint64, int, int, const QColor &, const QColor &,
const QColor &bgcolor, const QString &comment) { const QString &>::of(&WingPlugin::Controller::metadata),
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); [=](quint64 line, int start, int length, const QColor &fgcolor,
PCHECK( const QColor &bgcolor, const QString &comment) {
{ plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
auto doc = hexfiles[_pcurfile].doc; PCHECK(
if (!doc->isKeepSize()) {
return false; auto doc = hexfiles[_pcurfile].doc;
doc->metadata()->metadata(line, start, length, fgcolor, bgcolor, if (!doc->isKeepSize())
comment); return false;
doc->metadata()->metadata(line, start, length, fgcolor,
bgcolor, comment);
return true; return true;
}, },
{ {
auto doc = hexeditor->document(); auto doc = hexeditor->document();
if (!doc->isKeepSize()) if (!doc->isKeepSize())
return false; return false;
doc->metadata()->metadata(line, start, length, fgcolor, bgcolor, doc->metadata()->metadata(line, start, length, fgcolor,
comment); bgcolor, comment);
return true; return true;
}, },
return false); return false);
}); });
ConnectControlLamba2( ConnectControlLamba2(
WingPlugin::Controller::removeMetadata, [=](qint64 offset) { WingPlugin::Controller::removeMetadata, [=](qint64 offset) {
@ -2071,8 +2171,7 @@ void MainWindow::connectControl(IWingPlugin *plugin) {
}, ); }, );
}); });
bool (WingPlugin::Controller::*clear)() = &WingPlugin::Controller::clearMeta; connect(pctl, QOverload<>::of(&WingPlugin::Controller::clearMeta), [=]() {
ConnectControlLamba3(clear, [=]() {
plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender())); plgsys->resetTimeout(qobject_cast<IWingPlugin *>(sender()));
PCHECK( PCHECK(
{ {

View File

@ -19,7 +19,7 @@
<message> <message>
<location filename="../class/appmanager.cpp" line="57"/> <location filename="../class/appmanager.cpp" line="57"/>
<source>ErrOpenFileBelow</source> <source>ErrOpenFileBelow</source>
<translation></translation> <translation></translation>
</message> </message>
</context> </context>
<context> <context>

View File

@ -9,6 +9,7 @@
6. 更新插件到最新版本 6. 更新插件到最新版本
7. 修复 root 下插件被禁用但仍尝试派发消息导致的段错误 7. 修复 root 下插件被禁用但仍尝试派发消息导致的段错误
8. 增加拷贝字节限制,防止程序卡死 8. 增加拷贝字节限制,防止程序卡死
9. 补充遗漏的拓展插件函数接口实现
1.4.8 1.4.8
1. 增加插件接口 1. 增加插件接口