cmake-plugin: 添加基于源代码构建的 Linux 终端 插件示例,但依赖外部项目

1. lxqt-build-tool 提供构建配置
2. qtermwidget 依赖于 lxqt-build-tool 构建
This commit is contained in:
zinface 2023-03-30 17:43:36 +08:00
parent 794f6ad7bf
commit 496437bd49
5 changed files with 271 additions and 2 deletions

View File

@ -4,11 +4,12 @@ option(USE_NOTEPAD_PLUGIN_BASE "构建 Notepad-- 内部的插件基础模板" OF
if(USE_NOTEPAD_PLUGIN)
add_subdirectory(helloworld-next)
if(USE_NOTEPAD_PLUGIN_BASE)
#
add_subdirectory(test)
# cmake-plugins-dev helloworld
add_subdirectory(helloworld-next)
#
add_subdirectory(template-plugins/base-plugin)
add_subdirectory(template-plugins/base-widget-plugin)
@ -24,4 +25,9 @@ if(USE_NOTEPAD_PLUGIN)
#
add_subdirectory(external-plugin)
# Linux
if(UNIX AND NOT APPLE)
# Linux lxqt-qterminal
add_subdirectory(linux-terminal-plugin)
endif(UNIX AND NOT APPLE)
endif(USE_NOTEPAD_PLUGIN)

View File

@ -0,0 +1,129 @@
# linux-terminal-plugin/CMakeLists.txt
#
# 使
#
# linux-terminal-plugin
# linux-terminal-plugin -> your plugin name
set(LOCAL_PLUGIN_NAME "linux-terminal-plugin")
# linux-terminal-plugin
# linux-terminal-plugin
# 1. linux-terminal-plugin
# 2. linux-terminal-plugin
if(TRUE)
# linux-terminal-plugin
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)
# ----------------- linux-terminal-plugin ----------------- #
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)
# ----------------- linux-terminal-plugin ----------------- #
include(${CMAKE_SOURCE_DIR}/cmake/SparkExternalProject.cmake)
# 1. lxqt 使
spark_add_external_git_cmake_project(lxqt-build-tool
https://www.gitlink.org.cn/zinface/lxqt-build-tools.git
""
""
""
GIT_SHALLOW TRUE)
# 2. QTerminal lxqt-build-tool
spark_add_external_git_cmake_project(qtermwidget_git
https://www.gitlink.org.cn/zinface/qtermwidget.git
# 使 lxqt-build-tool ""
"-DCMAKE_PREFIX_PATH=${lxqt-build-tool-install};-DCMAKE_INSTALL_PREFIX=\${prj_install}"
"--;-j12"
""
GIT_SHALLOW TRUE)
# -------------------------------------------------------------------------------
# 3.
# qtermwidget5
# libqtermwidget5.a qtermwidget5.lib
include(${CMAKE_SOURCE_DIR}/cmake/platforms/utils.cmake)
get_current_platform_lib_name(libqtermwidget5_lib FALSE qtermwidget5)
add_library(qtermwidget SHARED IMPORTED)
set_target_properties(qtermwidget
PROPERTIES
IMPORTED_LOCATION ${qtermwidget_git-install}/lib/${libqtermwidget5_lib}
INCLUDE_DIRECTORIES ${qtermwidget_git-install}/include/qtermwidget5
INTERFACE_LINK_DIRECTORIES ${qtermwidget_git-install}/lib)
# ----------------- linux-terminal-plugin ----------------- #
# 1. qtermwidget_git lxqt-build-tool
add_dependencies(qtermwidget_git lxqt-build-tool)
# 2. qtermwidget qtermwidget_git
add_dependencies(qtermwidget qtermwidget_git)
# 3. qtermwidget qtermwidget_git
add_dependencies(${LOCAL_PLUGIN_NAME} qtermwidget qtermwidget_git lxqt-build-tool)
# 4. qtermwidget
target_link_libraries(${LOCAL_PLUGIN_NAME} qtermwidget)

View File

@ -0,0 +1,81 @@
#include "ndd_plugin_implement.h"
#include <qsciscintilla.h>
#include <QDebug>
#include <QMainWindow>
#include <QTabBar>
NddPluginImplement::NddPluginImplement(QWidget *parent, QsciScintilla *pEdit) : QWidget(parent)
, currentWidget(parent)
, currentEdit(pEdit)
, m_dockWidget(nullptr)
, m_dockTitleBarWidget(nullptr)
, m_dockEmptyTitleBarWidget(new QWidget())
, m_tabWidget(nullptr)
{
}
NddPluginImplement::~NddPluginImplement()
{
}
void NddPluginImplement::setMenuActions(QMenu *menu)
{
auto actionNewTerminal = menu->addAction("New Terminal");
connect(actionNewTerminal, &QAction::triggered, this, [&](){
auto mainWindow = dynamic_cast<QMainWindow*>(currentWidget);
if(!mainWindow) {
qDebug() << "None";
return;
}
qDebug() << "Yep";
if (!m_dockWidget) {
m_dockWidget = new QDockWidget(mainWindow);
m_dockTitleBarWidget = m_dockWidget->titleBarWidget();
m_dockWidget->setTitleBarWidget(m_dockEmptyTitleBarWidget);
m_dockWidget->setMinimumSize(100, 200);
connect(m_dockWidget, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(onDockLocationChanged(Qt::DockWidgetArea)));
mainWindow->addDockWidget(Qt::BottomDockWidgetArea, m_dockWidget);
}
if (!m_dockWidget->isVisible())
m_dockWidget->show();
if (!m_tabWidget) {
m_tabWidget = new QTabWidget(m_dockWidget);
m_tabWidget->setTabsClosable(true);
m_tabWidget->setMovable(true);
m_tabWidget->tabBar()->setStyleSheet("QTabBar::tab{padding-left:10px}");
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(onTabCloseRequested(int)));
m_dockWidget->setWidget(m_tabWidget);
}
int tabIndex = m_tabWidget->addTab(new QTermWidget(), "New Terminal");
m_tabWidget->setCurrentIndex(tabIndex);
});
}
void NddPluginImplement::onDockLocationChanged(Qt::DockWidgetArea area)
{
if (area == Qt::NoDockWidgetArea) {
m_dockWidget->setTitleBarWidget(m_dockTitleBarWidget);
}
else {
m_dockWidget->setTitleBarWidget(m_dockEmptyTitleBarWidget);
}
}
void NddPluginImplement::onTabCloseRequested(int index)
{
auto widget = m_tabWidget->widget(index);
if (widget)
delete widget;
if (m_tabWidget->count() == 0)
m_dockWidget->hide();
}

View File

@ -0,0 +1,42 @@
#ifndef NDD_PLUGIN_IMPLEMENT_H
#define NDD_PLUGIN_IMPLEMENT_H
#include <QWidget>
#include <QMenu>
#include <QDockWidget>
#include <QTabWidget>
#include <qtermwidget5/qtermwidget.h>
class QsciScintilla;
class NddPluginImplement : public QWidget
{
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:
// 目前看来需要准备一个完整内部状态
QWidget *currentWidget;
QsciScintilla *currentEdit;
std::function<QsciScintilla* ()> getCurrentEditFunc;
private slots:
void onDockLocationChanged(Qt::DockWidgetArea area);
void onTabCloseRequested(int index);
private:
QDockWidget* m_dockWidget;
QWidget* m_dockTitleBarWidget;
QWidget* m_dockEmptyTitleBarWidget;
QTabWidget* m_tabWidget;
};
#endif // NDD_PLUGIN_IMPLEMENT_H

View File

@ -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("Linux Terminal", "0.1", "author", u8"基于 LXQT QTerminal 的插件", "");
NOTEPAD_PLUGIN_METADATA_IMPLEMENT_V1(NddPluginImplement, false);