feat(editor): darcula theme for lua
This commit is contained in:
parent
590ecbe5ec
commit
deb72660da
4 changed files with 46 additions and 10 deletions
|
@ -13,7 +13,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||||
find_package(QScintilla)
|
find_package(QScintilla REQUIRED)
|
||||||
|
|
||||||
set(TS_FILES editor_en_US.ts)
|
set(TS_FILES editor_en_US.ts)
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,8 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "objects/datamodel.h"
|
#include "objects/datamodel.h"
|
||||||
#include "objects/jointsservice.h"
|
|
||||||
#include "objects/joint/snap.h"
|
|
||||||
#include "objects/script.h"
|
|
||||||
#include "placedocument.h"
|
#include "placedocument.h"
|
||||||
#include "script/scriptdocument.h"
|
#include "script/scriptdocument.h"
|
||||||
#include <map>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <qclipboard.h>
|
#include <qclipboard.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
|
@ -145,10 +141,6 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
placeDocument->init();
|
placeDocument->init();
|
||||||
|
|
||||||
ui->mdiArea->setTabsClosable(true);
|
ui->mdiArea->setTabsClosable(true);
|
||||||
|
|
||||||
// auto script = Script::New();
|
|
||||||
// gWorkspace()->AddChild(script);
|
|
||||||
// ui->mdiArea->addSubWindow(new ScriptDocument(script));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent* evt) {
|
void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#include "placedocument.h"
|
#include "placedocument.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "mainglwidget.h"
|
#include "mainglwidget.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "objects/joint/snap.h"
|
#include "objects/joint/snap.h"
|
||||||
|
#include "objects/script.h"
|
||||||
#include "rendering/surface.h"
|
#include "rendering/surface.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -125,4 +127,9 @@ void PlaceDocument::init() {
|
||||||
// part0->backSurface = SurfaceHinge;
|
// part0->backSurface = SurfaceHinge;
|
||||||
part0->backSurface = SurfaceMotor;
|
part0->backSurface = SurfaceMotor;
|
||||||
// part1->frontSurface = SurfaceHinge;
|
// part1->frontSurface = SurfaceHinge;
|
||||||
|
|
||||||
|
std::shared_ptr<Script> script = Script::New();
|
||||||
|
gWorkspace()->AddChild(script);
|
||||||
|
MainWindow* mainWnd = dynamic_cast<MainWindow*>(window());
|
||||||
|
mainWnd->openScriptDocument(script);
|
||||||
}
|
}
|
|
@ -1,14 +1,37 @@
|
||||||
#include "scriptdocument.h"
|
#include "scriptdocument.h"
|
||||||
|
|
||||||
#include <Qsci/qsciscintilla.h>
|
#include <Qsci/qsciscintilla.h>
|
||||||
#include <Qsci/qscilexer.h>
|
#include <Qsci/qscilexerlua.h>
|
||||||
|
#include <Qsci/qsciscintillabase.h>
|
||||||
|
#include <Qsci/qscistyle.h>
|
||||||
|
#include <map>
|
||||||
#include <qboxlayout.h>
|
#include <qboxlayout.h>
|
||||||
|
#include <qcolor.h>
|
||||||
#include <qfont.h>
|
#include <qfont.h>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <qlayout.h>
|
#include <qlayout.h>
|
||||||
#include "objects/script.h"
|
#include "objects/script.h"
|
||||||
|
|
||||||
|
std::map<int, const QColor> DARK_MODE_COLOR_SCHEME = {{
|
||||||
|
{QsciLexerLua::Comment, QColor("#808080")},
|
||||||
|
{QsciLexerLua::LineComment, QColor("#808080")},
|
||||||
|
{QsciLexerLua::Number, QColor("#6897BB")},
|
||||||
|
{QsciLexerLua::Keyword, QColor("#CC7832")},
|
||||||
|
{QsciLexerLua::String, QColor("#6A8759")},
|
||||||
|
{QsciLexerLua::Character, QColor("#6A8759")},
|
||||||
|
{QsciLexerLua::LiteralString, QColor("#6A8759")},
|
||||||
|
{QsciLexerLua::Preprocessor, QColor("#FF00FF")}, // Obsolete since Lua 4.0, but whatever
|
||||||
|
{QsciLexerLua::Operator, QColor("#FFFFFF")},
|
||||||
|
{QsciLexerLua::Identifier, QColor("#FFFFFF")},
|
||||||
|
{QsciLexerLua::UnclosedString, QColor("#6A8759")},
|
||||||
|
{QsciLexerLua::BasicFunctions, QColor("#CC7832")},
|
||||||
|
{QsciLexerLua::StringTableMathsFunctions, QColor("#CC7832")},
|
||||||
|
{QsciLexerLua::CoroutinesIOSystemFacilities, QColor("#CC7832")},
|
||||||
|
{QsciLexerLua::Label, QColor("#FFFFFF")},
|
||||||
|
|
||||||
|
}};
|
||||||
|
|
||||||
ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
||||||
script(script), QMdiSubWindow(parent) {
|
script(script), QMdiSubWindow(parent) {
|
||||||
|
|
||||||
|
@ -38,6 +61,20 @@ ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
||||||
|
|
||||||
scintilla->setText(QString::fromStdString(script->source));
|
scintilla->setText(QString::fromStdString(script->source));
|
||||||
|
|
||||||
|
QsciLexerLua* lexer = new QsciLexerLua;
|
||||||
|
lexer->setFont(font);
|
||||||
|
scintilla->setLexer(lexer);
|
||||||
|
|
||||||
|
// Set color scheme
|
||||||
|
// https://stackoverflow.com/a/26318796/16255372
|
||||||
|
for (auto& [style, color] : DARK_MODE_COLOR_SCHEME) {
|
||||||
|
lexer->setColor(color, style);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lexer->setAutoIndentStyle(QsciScintilla::AiOpening | QsciScintilla::AiMaintain | QsciScintilla::AiClosing);
|
||||||
|
// scintilla->setAutoIndent(true);
|
||||||
|
|
||||||
|
|
||||||
connect(scintilla, &QsciScintilla::textChanged, [this]() {
|
connect(scintilla, &QsciScintilla::textChanged, [this]() {
|
||||||
// this-> is important here, as otherwise it will refer to the
|
// this-> is important here, as otherwise it will refer to the
|
||||||
// parameter passed in, which will get gc'ed eventually
|
// parameter passed in, which will get gc'ed eventually
|
||||||
|
|
Loading…
Add table
Reference in a new issue