WingHexExplorer/TestPlugin/testplugin.cpp

72 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "testplugin.h"
#include <QLabel>
#include <QMessageBox>
#include <QStringList>
TestPlugin::TestPlugin(QObject *parent) { Q_UNUSED(parent) }
TestPlugin::~TestPlugin() {}
int TestPlugin::sdkVersion() { return SDKVERSION; }
bool TestPlugin::init(QList<WingPluginInfo> loadedplugin) {
if (loadedplugin.length() > 0) {
QString ps;
for (auto item : loadedplugin) {
ps.append(item.pluginName);
ps.append('\n');
}
QMessageBox::information(nullptr, "Test", ps);
}
PluginMenuInitBegin(testmenu, "TestPlugin") {
PluginMenuAddItemLamba(testmenu, "ClickMe!", [=] {
QMessageBox::information(nullptr, "戳我", "经典Hello World!");
});
}
PluginMenuInitEnd();
PluginDockWidgetInit(dw, new QLabel("Hello World!", dw), "testplg",
"testplg");
return true;
}
void TestPlugin::unload() {}
QString TestPlugin::pluginName() { return "TestPlugin"; }
QString TestPlugin::pluginAuthor() { return "Wingsummer"; }
QString TestPlugin::pluginComment() {
return "A Sample Plugin for WingHex Explorer by Wingsummer!";
}
uint TestPlugin::pluginVersion() { return 1; }
QString TestPlugin::signature() { return WINGSUMMER; }
void TestPlugin::plugin2MessagePipe(WingPluginMessage type,
QList<QVariant> msg) {
Q_UNUSED(msg)
if (type == WingPluginMessage::PluginLoaded) {
if (requestControl()) {
controller.newFile();
controller.switchDocument(0);
auto str = QString("HelloWorld!").toUtf8();
controller.insert(0, str);
controller.setKeepSize(true);
controller.metadata(0, 2, Qt::red, Qt::transparent, QString());
requestRelease();
controller.newFile(); //此语句在 requestRelease 释放成功无效
}
}
}
QMenu *TestPlugin::registerMenu() { return testmenu; }
void TestPlugin::registerDockWidget(
QMap<QDockWidget *, Qt::DockWidgetArea> &rdw) {
rdw.insert(dw, Qt::DockWidgetArea::BottomDockWidgetArea);
}