feat(editor): added script document
This commit is contained in:
parent
1ba9911036
commit
1858c703c7
10 changed files with 130 additions and 9 deletions
32
cmake/FindQScintilla.cmake
Normal file
32
cmake/FindQScintilla.cmake
Normal file
|
@ -0,0 +1,32 @@
|
|||
# Modified from QGIS' FindQScintilla.cmake by Thomas Moenicke, Larry Schaffer
|
||||
|
||||
FIND_PATH(QSCINTILLA_INCLUDE_DIR
|
||||
NAMES Qsci/qsciglobal.h
|
||||
PATHS
|
||||
${Qt${QT_VERSION_MAJOR}Core_INCLUDE_DIRS}
|
||||
$ENV{LIB_DIR}/include
|
||||
/usr/local/include
|
||||
/usr/include
|
||||
PATH_SUFFIXES ${QSCINTILLA_PATH_SUFFIXES}
|
||||
)
|
||||
|
||||
set(QSCINTILLA_LIBRARY_NAMES
|
||||
qscintilla2-qt${QT_VERSION_MAJOR}
|
||||
qscintilla2_qt${QT_VERSION_MAJOR}
|
||||
libqt${QT_VERSION_MAJOR}scintilla2
|
||||
libqscintilla2-qt${QT_VERSION_MAJOR}
|
||||
qt${QT_VERSION_MAJOR}scintilla2
|
||||
libqscintilla2-qt${QT_VERSION_MAJOR}.dylib
|
||||
qscintilla2
|
||||
)
|
||||
|
||||
|
||||
find_library(QSCINTILLA_LIBRARY
|
||||
NAMES ${QSCINTILLA_LIBRARY_NAMES}
|
||||
PATHS
|
||||
"${QT_LIBRARY_DIR}"
|
||||
$ENV{LIB_DIR}/lib
|
||||
/usr/local/lib
|
||||
/usr/local/lib/qt${QT_VERSION_MAJOR}
|
||||
/usr/lib
|
||||
)
|
|
@ -13,7 +13,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
|||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia LinguistTools)
|
||||
|
||||
find_package(QScintilla)
|
||||
|
||||
set(TS_FILES editor_en_US.ts)
|
||||
|
||||
|
@ -30,8 +30,10 @@ set(PROJECT_SOURCES
|
|||
panes/explorermodel.cpp
|
||||
panes/propertiesview.h
|
||||
panes/propertiesview.cpp
|
||||
placedocument.cpp
|
||||
placedocument.h
|
||||
placedocument.cpp
|
||||
script/scriptdocument.h
|
||||
script/scriptdocument.cpp
|
||||
${TS_FILES}
|
||||
)
|
||||
|
||||
|
@ -63,8 +65,8 @@ else()
|
|||
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
|
||||
endif()
|
||||
|
||||
target_include_directories(editor PUBLIC "../core/src" "../include")
|
||||
target_link_libraries(editor PRIVATE openblocks Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia)
|
||||
target_include_directories(editor PUBLIC "../core/src" "../include" ${QSCINTILLA_INCLUDE_DIR})
|
||||
target_link_libraries(editor PRIVATE openblocks Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia ${QSCINTILLA_LIBRARY})
|
||||
|
||||
# Qt6 does not include QOpenGLWidgets as part of Widgets base anymore, so
|
||||
# we have to include it manually
|
||||
|
|
|
@ -5,13 +5,16 @@
|
|||
#include "objects/datamodel.h"
|
||||
#include "objects/jointsservice.h"
|
||||
#include "objects/joint/snap.h"
|
||||
#include "objects/script.h"
|
||||
#include "placedocument.h"
|
||||
#include "script/scriptdocument.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <qclipboard.h>
|
||||
#include <qglobal.h>
|
||||
#include <qmessagebox.h>
|
||||
#include <qmimedata.h>
|
||||
#include <qnamespace.h>
|
||||
#include <qstylefactory.h>
|
||||
#include <qstylehints.h>
|
||||
#include <qmdisubwindow.h>
|
||||
|
@ -133,10 +136,17 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
// ui->explorerView->Init(ui);
|
||||
placeDocument = new PlaceDocument(this);
|
||||
placeDocument->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
ui->mdiArea->addSubWindow(placeDocument);
|
||||
ui->mdiArea->currentSubWindow()->showMaximized();
|
||||
ui->mdiArea->findChild<QTabBar*>()->setExpanding(false);
|
||||
placeDocument->init();
|
||||
|
||||
ui->mdiArea->setTabsClosable(true);
|
||||
|
||||
auto script = Script::New();
|
||||
gWorkspace()->AddChild(script);
|
||||
// ui->mdiArea->addSubWindow(new ScriptDocument(script));
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* evt) {
|
||||
|
@ -474,6 +484,14 @@ std::optional<std::string> MainWindow::openFileDialog(QString filter, QString de
|
|||
return dialog.selectedFiles().front().toStdString();
|
||||
}
|
||||
|
||||
void MainWindow::openScriptDocument(std::shared_ptr<Script> script) {
|
||||
ScriptDocument* doc = new ScriptDocument(script);
|
||||
doc->setAttribute(Qt::WA_DeleteOnClose, true);
|
||||
ui->mdiArea->addSubWindow(doc);
|
||||
ui->mdiArea->setActiveSubWindow(doc);
|
||||
doc->showMaximized();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "qcoreevent.h"
|
||||
#include <QMainWindow>
|
||||
#include <QLineEdit>
|
||||
#include <memory>
|
||||
#include <qfiledialog.h>
|
||||
|
||||
enum SelectedTool {
|
||||
|
@ -29,6 +30,8 @@ enum GridSnappingMode {
|
|||
SNAP_OFF,
|
||||
};
|
||||
|
||||
class Script;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -47,6 +50,8 @@ public:
|
|||
GridSnappingMode snappingMode;
|
||||
bool editSoundEffects = true;
|
||||
|
||||
void openScriptDocument(std::shared_ptr<Script>);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
private:
|
||||
PlaceDocument* placeDocument;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "mainwindow.h"
|
||||
#include "objects/base/instance.h"
|
||||
#include "objects/meta.h"
|
||||
#include "objects/script.h"
|
||||
#include <memory>
|
||||
#include <qaction.h>
|
||||
|
||||
|
@ -70,6 +71,15 @@ void ExplorerView::keyPressEvent(QKeyEvent* event) {
|
|||
}
|
||||
}
|
||||
|
||||
void ExplorerView::mouseDoubleClickEvent(QMouseEvent *event) {
|
||||
QModelIndex index = indexAt(event->pos());
|
||||
std::shared_ptr<Instance> inst = model.fromIndex(index);
|
||||
if (!inst->IsA<Script>()) return;
|
||||
|
||||
MainWindow* mainWnd = dynamic_cast<MainWindow*>(window());
|
||||
mainWnd->openScriptDocument(inst->CastTo<Script>().expect());
|
||||
}
|
||||
|
||||
void ExplorerView::buildContextMenu() {
|
||||
contextMenu.addAction(M_mainWindow->ui->actionDelete);
|
||||
contextMenu.addSeparator();
|
||||
|
|
|
@ -12,6 +12,7 @@ public:
|
|||
~ExplorerView() override;
|
||||
|
||||
void keyPressEvent(QKeyEvent*) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
// void dropEvent(QDropEvent*) override;
|
||||
|
||||
void buildContextMenu();
|
||||
|
|
|
@ -14,6 +14,7 @@ PlaceDocument::PlaceDocument(QWidget* parent):
|
|||
QMdiSubWindow(parent) {
|
||||
placeWidget = new MainGLWidget;
|
||||
setWidget(placeWidget);
|
||||
setWindowTitle("Place");
|
||||
|
||||
_runState = RUN_STOPPED;
|
||||
}
|
||||
|
@ -49,10 +50,6 @@ void PlaceDocument::closeEvent(QCloseEvent *closeEvent) {
|
|||
closeEvent->ignore();
|
||||
}
|
||||
|
||||
void PlaceDocument::keyPressEvent(QKeyEvent *keyEvent) {
|
||||
printf("Getting\n");
|
||||
}
|
||||
|
||||
static std::chrono::time_point lastTime = std::chrono::steady_clock::now();
|
||||
void PlaceDocument::timerEvent(QTimerEvent* evt) {
|
||||
if (evt->timerId() != timer.timerId()) {
|
||||
|
|
|
@ -24,6 +24,5 @@ public:
|
|||
void setRunState(RunState);
|
||||
|
||||
void closeEvent(QCloseEvent *closeEvent) override;
|
||||
void keyPressEvent(QKeyEvent *keyEvent) override;
|
||||
void init();
|
||||
};
|
41
editor/script/scriptdocument.cpp
Normal file
41
editor/script/scriptdocument.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "scriptdocument.h"
|
||||
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
#include <Qsci/qscilexer.h>
|
||||
#include <qboxlayout.h>
|
||||
#include <qfont.h>
|
||||
#include <qlayout.h>
|
||||
#include "objects/script.h"
|
||||
|
||||
ScriptDocument::ScriptDocument(std::shared_ptr<Script> script, QWidget* parent):
|
||||
script(script), QMdiSubWindow(parent) {
|
||||
|
||||
setWindowTitle(QString::fromStdString(script->name));
|
||||
|
||||
// QFrame* frame = new QFrame;
|
||||
// QVBoxLayout* frameLayout = new QVBoxLayout;
|
||||
// frame->setLayout(frameLayout);
|
||||
scintilla = new QsciScintilla;
|
||||
// frameLayout->addWidget(scintilla);
|
||||
// setWidget(frame);
|
||||
setWidget(scintilla);
|
||||
|
||||
QFont font;
|
||||
font.setFamily("Consolas");
|
||||
font.setStyleHint(QFont::Monospace);
|
||||
font.setPointSize(12);
|
||||
|
||||
// scintilla->setMargins(2);
|
||||
scintilla->setScrollWidth(1); // Hide scrollbars on empty document, it will grow automatically
|
||||
scintilla->setMarginType(1, QsciScintilla::NumberMargin);
|
||||
scintilla->setMarginWidth(1, "0000");
|
||||
scintilla->setMarginsForegroundColor(palette().windowText().color());
|
||||
scintilla->setMarginsBackgroundColor(palette().window().color());
|
||||
scintilla->setCaretForegroundColor(palette().text().color());
|
||||
scintilla->setFont(font);
|
||||
|
||||
scintilla->setLexer();
|
||||
}
|
||||
|
||||
ScriptDocument::~ScriptDocument() {
|
||||
}
|
16
editor/script/scriptdocument.h
Normal file
16
editor/script/scriptdocument.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
#include <memory>
|
||||
#include <qmdisubwindow.h>
|
||||
|
||||
class Script;
|
||||
|
||||
class ScriptDocument : public QMdiSubWindow {
|
||||
std::shared_ptr<Script> script;
|
||||
|
||||
QsciScintilla* scintilla;
|
||||
public:
|
||||
ScriptDocument(std::shared_ptr<Script> script, QWidget* parent = nullptr);
|
||||
~ScriptDocument() override;
|
||||
};
|
Loading…
Add table
Reference in a new issue