mirror of https://gitee.com/cxasm/notepad--.git
cmake-plugin: 添加1个基于源代码构建的二级菜单支持系列高级UI模板
This commit is contained in:
parent
d0506e058d
commit
a5fab253e3
|
@ -16,6 +16,7 @@ if(USE_NOTEPAD_PLUGIN)
|
|||
add_subdirectory(template-plugins/base-widget-ui-plugin)
|
||||
add_subdirectory(template-plugins/base-secondary-menu-plugin)
|
||||
add_subdirectory(template-plugins/base-secondary-menu-plugin-v1)
|
||||
add_subdirectory(template-plugins/base-secondary-menu-ui-plugin-v1)
|
||||
endif(USE_NOTEPAD_PLUGIN_BASE)
|
||||
|
||||
# 一个简单的插件示例,但依赖于外部的 opencc 项目(基于 git)
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
# base-secondary-menu-ui-plugin-v1/CMakeLists.txt
|
||||
# 用于在源代码中构建一个插件的模板
|
||||
|
||||
# 如果不是在源代码中构建插件,请不要使用这个部分
|
||||
# 如果想在源代码中添加更多内置模板
|
||||
# 请替换 base-secondary-menu-ui-plugin-v1 为你的插件名称
|
||||
# base-secondary-menu-ui-plugin-v1 -> your plugin name
|
||||
|
||||
set(LOCAL_PLUGIN_NAME "base-secondary-menu-ui-plugin-v1")
|
||||
|
||||
# base-secondary-menu-ui-plugin-v1 核心构建
|
||||
# 在模块化构建中,这个部分代表着构建 base-secondary-menu-ui-plugin-v1 插件
|
||||
# 1. 默认构建时产出的目标为 base-secondary-menu-ui-plugin-v1
|
||||
# 2. 在此处可对 base-secondary-menu-ui-plugin-v1 目标进行详细的构建计划
|
||||
|
||||
if(TRUE)
|
||||
# 准备构建 base-secondary-menu-ui-plugin-v1 主程序扩展
|
||||
spark_file_glob(LocalSources
|
||||
./*.h ./*.cpp ./*.ui
|
||||
)
|
||||
spark_add_library(${LOCAL_PLUGIN_NAME} SHARED ${LocalSources})
|
||||
target_include_directories(${LOCAL_PLUGIN_NAME} PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
${PROJECT_SOURCE_DIR}/src/cceditor
|
||||
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/src
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/src/Qsci
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/scintilla/src
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/scintilla/include
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/scintilla/lexlib
|
||||
${PROJECT_SOURCE_DIR}/src/qscint/scintilla/boostregex
|
||||
)
|
||||
# target_link_libraries(${LOCAL_PLUGIN_NAME} QSci)
|
||||
target_link_QSci(${LOCAL_PLUGIN_NAME})
|
||||
if(USE_QT6)
|
||||
# target_link_qt6_Core5Compat(${LOCAL_PLUGIN_NAME}) # 兼容性: Qt6 可使用 Core5Compat 少量更改 Qt5 部分
|
||||
# target_link_qt6_PrintSupport(${LOCAL_PLUGIN_NAME})
|
||||
# target_link_qt6_XmlPatterns(${LOCAL_PLUGIN_NAME}) # Bug 初期配置时无此依赖要求
|
||||
else()
|
||||
# target_link_qt5_PrintSupport(${LOCAL_PLUGIN_NAME})
|
||||
# target_link_qt5_XmlPatterns(${LOCAL_PLUGIN_NAME})
|
||||
endif(USE_QT6)
|
||||
|
||||
# 确保生成到 Notepad-- 的相对 plugin 目录下
|
||||
set_target_properties(${LOCAL_PLUGIN_NAME}
|
||||
PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin
|
||||
LIBRARY_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin
|
||||
ARCHIVE_OUTPUT_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}>/plugin)
|
||||
|
||||
# 控制是否安装到 bin/plugin 而各种配方之下,每个位置或许都不一样(特别是 Linux)
|
||||
# install(TARGETS ${LOCAL_PLUGIN_NAME} DESTINATION bin/plugin)
|
||||
endif(TRUE)
|
||||
|
||||
|
||||
# ----------------- base-secondary-menu-ui-plugin-v1 构建宏支持相关 ----------------- #
|
||||
|
||||
if(WIN32 AND NOTEPAD_BUILD_BY_SHARED)
|
||||
# 在 Windows 中构建时,需要关注此库的构建形式,QScintilla 应该以何种方式编译
|
||||
target_compile_definitions(${LOCAL_PLUGIN_NAME}
|
||||
PRIVATE
|
||||
NOTEPAD_PLUGIN_MANAGER
|
||||
QSCINTILLA_DLL # 目前在 Windows 中使用 QSci 库时应该采用 Q_DECL_IMPORT
|
||||
# 控制 QSCINTILLA_EXPORT 符号应为 Q_DECL_IMPORT
|
||||
)
|
||||
else()
|
||||
# 在 Windows 中构建时,需要关注此库的构建形式,QScintilla 应该以何种方式编译
|
||||
target_compile_definitions(${LOCAL_PLUGIN_NAME}
|
||||
PRIVATE
|
||||
NOTEPAD_PLUGIN_MANAGER
|
||||
# QSCINTILLA_DLL # 目前在 Windows 中使用 QSci 库时应该采用 Q_DECL_IMPORT
|
||||
# 控制 QSCINTILLA_EXPORT 符号应为 Q_DECL_IMPORT
|
||||
)
|
||||
endif(WIN32 AND NOTEPAD_BUILD_BY_SHARED)
|
||||
|
||||
if(UNIX)
|
||||
# 默认在 Unix/Linux 中仅需要定义一个内部插件宏管理器
|
||||
target_compile_definitions(${LOCAL_PLUGIN_NAME}
|
||||
PRIVATE
|
||||
NOTEPAD_PLUGIN_MANAGER
|
||||
)
|
||||
endif(UNIX)
|
||||
|
||||
# ----------------- base-secondary-menu-ui-plugin-v1 构建的外部项目依赖 ----------------- #
|
|
@ -0,0 +1,59 @@
|
|||
#include "ndd_plugin_implement.h"
|
||||
#include "ui_ndd_plugin_implement.h"
|
||||
|
||||
#include <qsciscintilla.h>
|
||||
#include <QDebug>
|
||||
#include <QDockWidget>
|
||||
#include <QHostInfo>
|
||||
|
||||
NddPluginImplement::NddPluginImplement(QWidget *parent, QsciScintilla *pEdit) : QMainWindow(parent)
|
||||
, currentWidget(parent)
|
||||
, currentEdit(pEdit)
|
||||
, ui(new Ui::NddPluginImplement)
|
||||
, m_dockWidget(new QDockWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->computer->setText(QHostInfo::localHostName());
|
||||
ui->computer->setReadOnly(true);
|
||||
}
|
||||
|
||||
NddPluginImplement::~NddPluginImplement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NddPluginImplement::setMenuActions(QMenu *menu)
|
||||
{
|
||||
QAction *action1 = menu->addAction(u8"第一项打印");
|
||||
connect(action1, &QAction::triggered, this, [](){
|
||||
// 普通的菜单项
|
||||
qDebug() << "action1";
|
||||
});
|
||||
|
||||
connect(menu->addAction("Show Ui"), &QAction::triggered, this, [=](){
|
||||
on_pushButton_clicked();
|
||||
});
|
||||
|
||||
connect(menu->addAction("Show Sider"), &QAction::triggered, this, [=](){
|
||||
auto mainWindow = dynamic_cast<QMainWindow*>(currentWidget);
|
||||
if(!mainWindow) {
|
||||
qDebug() << "None";
|
||||
return;
|
||||
}
|
||||
|
||||
m_dockWidget->setMinimumSize(100, 200);
|
||||
mainWindow->addDockWidget(Qt::RightDockWidgetArea, m_dockWidget);
|
||||
|
||||
if (!m_dockWidget->isVisible())
|
||||
m_dockWidget->show();
|
||||
|
||||
m_dockWidget->setWidget(this);
|
||||
});
|
||||
}
|
||||
|
||||
void NddPluginImplement::on_pushButton_clicked()
|
||||
{
|
||||
this->setParent(nullptr);
|
||||
this->resize(QSize(480,340));
|
||||
this->show();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef NDD_PLUGIN_IMPLEMENT_H
|
||||
#define NDD_PLUGIN_IMPLEMENT_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QsciScintilla;
|
||||
namespace Ui {
|
||||
class NddPluginImplement;
|
||||
}
|
||||
class NddPluginImplement : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NddPluginImplement(QWidget *parent = nullptr, QsciScintilla *pEdit = nullptr);
|
||||
~NddPluginImplement();
|
||||
|
||||
void setMenuActions(QMenu *menu);
|
||||
void setCurrentEditFunc(std::function<QsciScintilla* ()> func) {
|
||||
getCurrentEditFunc = func;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
||||
private:
|
||||
// 目前看来需要准备一个完整内部状态
|
||||
QWidget *currentWidget;
|
||||
QsciScintilla *currentEdit;
|
||||
std::function<QsciScintilla* ()> getCurrentEditFunc;
|
||||
|
||||
private:
|
||||
Ui::NddPluginImplement *ui;
|
||||
QDockWidget *m_dockWidget;
|
||||
};
|
||||
|
||||
#endif // NDD_PLUGIN_IMPLEMENT_H
|
|
@ -0,0 +1,73 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NddPluginImplement</class>
|
||||
<widget class="QMainWindow" name="NddPluginImplement">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>340</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Sider Ui</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="computer"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Computer:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Eject</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>480</width>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,11 @@
|
|||
#include <qobject.h>
|
||||
#include <qstring.h>
|
||||
#include <include/pluginGl.h>
|
||||
#include <functional>
|
||||
#include <qsciscintilla.h>
|
||||
#include "ndd_plugin_implement.h"
|
||||
|
||||
|
||||
NOTEPAD_PLUGIN_METADATA_IDENTIFY_V1("base-secondary-menu-ui-plugin-v1", "0.1", "author", u8"二级菜单高级 UI 插件", "");
|
||||
|
||||
NOTEPAD_PLUGIN_METADATA_IMPLEMENT_V1(NddPluginImplement, false);
|
Loading…
Reference in New Issue