Permalink
Browse files

Separation of Lua Script widget

  • Loading branch information...
feragon committed Jun 10, 2016
1 parent 2a83b53 commit d92b88b08b533170569f5b09cd1c9dfb95d9d307
Showing with 114 additions and 66 deletions.
  1. +1 −1 lcUI/lua/qtbridge.cpp
  2. +43 −5 lcUI/widgets/luascript.cpp
  3. +8 −2 lcUI/widgets/luascript.h
  4. +39 −43 lcUI/widgets/luascript.ui
  5. +23 −15 lcUILua/ui/mainwindow.lua
View
@@ -178,7 +178,7 @@ void addLCBindings(lua_State *L) {
.endClass()
.beginExtendClass<LuaScript, QDockWidget>("LuaScript")
.addConstructor(LUA_ARGS(QMdiArea*))
.addConstructor(LUA_ARGS(QMdiArea*, CliCommand*))
.endClass()
.beginClass<LCViewer::DocumentCanvas>("DocumentCanvas")
View
@@ -1,12 +1,12 @@
#include "luascript.h"
#include "ui_luascript.h"
#include <string>
#include <lcadluascript.h>
LuaScript::LuaScript(QMdiArea* mdiArea) :
LuaScript::LuaScript(QMdiArea* mdiArea, CliCommand* cliCommand) :
ui(new Ui::LuaScript),
_mdiArea(mdiArea) {
_mdiArea(mdiArea),
_cliCommand(cliCommand) {
ui->setupUi(this);
}
@@ -22,8 +22,46 @@ void LuaScript::on_luaRun_clicked() {
LCadLuaScript lc(mdiChild->document());
std::string out = lc.run(ui->luaInput->toPlainText().toStdString());
ui->luaOutput->clear();
ui->luaOutput->textCursor().insertText(QString::fromStdString(out));
_cliCommand->write(QString::fromStdString(out));
}
}
void LuaScript::on_open_clicked() {
auto fileName = QFileDialog::getOpenFileName(
0,
tr("Open File"),
QString(),
tr("Lua (*.lua)")
);
if(!fileName.isEmpty()) {
QFile file(fileName);
file.open(QFile::ReadOnly | QFile::Text);
QTextStream stream(&file);
ui->luaInput->setPlainText(stream.readAll());
file.close();
}
}
void LuaScript::on_save_clicked() {
auto fileName = QFileDialog::getSaveFileName(
0,
tr("Save File"),
QString(),
tr("Lua (*.lua)")
);
if(!fileName.isEmpty()) {
QFile file(fileName);
file.open(QFile::WriteOnly | QFile::Text);
QTextStream stream(&file);
stream << ui->luaInput->toPlainText();
file.close();
}
}
View
@@ -3,25 +3,31 @@
#include <QDockWidget>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QFileDialog>
#include <QTextStream>
#include "cadmdichild.h"
#include "clicommand.h"
namespace Ui {
class LuaScript;
}
class LuaScript : public QDockWidget {
class LuaScript : public QWidget {
Q_OBJECT
public:
explicit LuaScript(QMdiArea* mdiArea = 0);
explicit LuaScript(QMdiArea* mdiArea, CliCommand* cliCommand);
virtual ~LuaScript();
private slots:
void on_luaRun_clicked();
void on_open_clicked();
void on_save_clicked();
private:
Ui::LuaScript* ui;
QMdiArea* _mdiArea;
CliCommand* _cliCommand;
};
// LUASCRIPT_H
View
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LuaScript</class>
<widget class="QDockWidget" name="LuaScript">
<widget class="QWidget" name="LuaScript">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>282</width>
<height>475</height>
<width>350</width>
<height>690</height>
</rect>
</property>
<property name="sizePolicy">
@@ -19,46 +19,42 @@
<property name="windowTitle">
<string>Lua Script</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1,1">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="luaRun">
<property name="text">
<string>run</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="luaInput"/>
</item>
<item>
<widget class="QPlainTextEdit" name="luaOutput">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="open">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="luaRun">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="luaInput"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
View
@@ -31,6 +31,29 @@ function open_file()
end
end
local function open_lua_script()
local luaScript = lc.LuaScript(mdiArea, cliCommand)
luaScript:show()
end
local function create_menu()
local menuBar = mainWindow:menuBar()
local drawMenu = menuBar:addMenuStr(qt.QString("Draw"))
local lineAction = drawMenu:addActionStr(qt.QString("Line"))
local luaMenu = menuBar:addMenuStr(qt.QString("Lua"))
local luaScriptAction = luaMenu:addActionStr(qt.QString("Run script"))
luaInterface:luaConnect(mainWindow:findChild("actionNew"), "triggered(bool)", new_file)
luaInterface:luaConnect(mainWindow:findChild("actionOpen"), "triggered(bool)", open_file)
luaInterface:luaConnect(mainWindow:findChild("actionUndo"), "triggered(bool)", undo)
luaInterface:luaConnect(mainWindow:findChild("actionRedo"), "triggered(bool)", redo)
luaInterface:luaConnect(lineAction, "triggered(bool)", create_line)
luaInterface:luaConnect(luaScriptAction, "triggered(bool)", open_lua_script)
end
function create_main_window()
mainWindow = qt.loadUi(ui_path .. "/mainwindow.ui")
mainWindow:setWindowTitle(qt.QObject.tr("LibreCAD"));
@@ -45,28 +68,13 @@ function create_main_window()
create_menu()
luaScript = lc.LuaScript(mdiArea)
mainWindow:addDockWidget(2, luaScript)
add_commandline()
mainWindow:show()
new_file()
end
function create_menu()
menuBar = mainWindow:menuBar()
drawMenu = menuBar:addMenuStr(qt.QString("Draw"))
lineAction = drawMenu:addActionStr(qt.QString("Line"))
luaInterface:luaConnect(mainWindow:findChild("actionNew"), "triggered(bool)", new_file)
luaInterface:luaConnect(mainWindow:findChild("actionOpen"), "triggered(bool)", open_file)
luaInterface:luaConnect(mainWindow:findChild("actionUndo"), "triggered(bool)", undo)
luaInterface:luaConnect(mainWindow:findChild("actionRedo"), "triggered(bool)", redo)
luaInterface:luaConnect(lineAction, "triggered(bool)", create_line)
end
function nextTableId(table)
count = 0
for id, v in pairs(table) do

0 comments on commit d92b88b

Please sign in to comment.