From b8a5843464329937cf8859bac626d607513af56c Mon Sep 17 00:00:00 2001 From: Syping Date: Sat, 25 Aug 2018 00:55:55 +0200 Subject: [PATCH] improvements --- src/luaengineapp/app.lua | 2 + src/luaengineapp/edit.lua | 49 +++++++++++++++++++ src/luaengineapp/luaengineapp.qrc | 1 + .../luaenginestyle/luaenginestyle.qss | 7 +++ src/luaengineapp/main.cpp | 2 +- src/luaenginegui/luaengine/LuaEngineGui.cpp | 34 +++++++++++++ src/luaenginegui/luaengine/LuaEngineGui.h | 2 + 7 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/luaengineapp/edit.lua diff --git a/src/luaengineapp/app.lua b/src/luaengineapp/app.lua index 6ecea8c..cd04832 100644 --- a/src/luaengineapp/app.lua +++ b/src/luaengineapp/app.lua @@ -46,6 +46,7 @@ function main() layoutAddWidget(mainLayout, pushButton1) connect(pushButton1, "clicked()", "showDialog") + setWidgetFixedSize(mainWindow) showWidget(mainWindow, ShowNormal) return GuiExecuted end @@ -70,6 +71,7 @@ function showDialog(pushButton) local dialogButton = createPushButton("Close", dialog) layoutAddWidget(buttonLayout, dialogButton) connect(dialogButton, "clicked()", "closeDialog") + setWidgetFixedSize(dialog) executeWidget(dialog) delete(dialog, DeleteInstant) end diff --git a/src/luaengineapp/edit.lua b/src/luaengineapp/edit.lua new file mode 100644 index 0000000..dd988cb --- /dev/null +++ b/src/luaengineapp/edit.lua @@ -0,0 +1,49 @@ +--[[ +****************************************************************************** +* luaEngine Lua Engine for Qt +* Copyright (C) 2018 Syping +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +****************************************************************************** +--]] + +local currentFile +local mainWindow +local textEditor + +function main() + mainWindow = createMainWindow() + local mainWidget = createCentralWidget(mainWindow) + local mainLayout = createLayout(VerticalLayout, mainWidget) + + local menuBar = createMenuBar(mainWindow) + local menuFile = createMenu("File", menuBar) + local menuEntryNew = createMenuEntry("New", menuFile) + local menuEntryOpen = createMenuEntry("Open...", menuFile) + connect(menuEntrySave, "triggered()", "editorOpen") + local menuEntrySave = createMenuEntry("Save...", menuFile) + connect(menuEntrySave, "triggered()", "editorSave") + local menuEntrySaveAs = createMenuEntry("Save as...", menuFile) + connect(menuEntrySaveAs, "triggered()", "editorSaveAs") + local menuEntryExit = createMenuEntry("Exit", menuFile) + connect(menuEntryExit, "triggered()", "editorClose") + local menuHelp = createMenu("Help", menuBar) + local menuEntryAbout = createMenuEntry("About LE Text Editor", menuHelp) + connect(menuEntryAbout, "triggered()", "editorAboutBox") + + textEditor = createTextEdit("", mainWidget) + layoutAddWidget(mainLayout, textEditor) + + showWidget(mainWindow, ShowNormal) + return GuiExecuted +end diff --git a/src/luaengineapp/luaengineapp.qrc b/src/luaengineapp/luaengineapp.qrc index d6634dd..bb17d2b 100644 --- a/src/luaengineapp/luaengineapp.qrc +++ b/src/luaengineapp/luaengineapp.qrc @@ -1,5 +1,6 @@ app.lua + edit.lua diff --git a/src/luaengineapp/luaenginestyle/luaenginestyle.qss b/src/luaengineapp/luaenginestyle/luaenginestyle.qss index f34dc75..7ac9f57 100644 --- a/src/luaengineapp/luaenginestyle/luaenginestyle.qss +++ b/src/luaengineapp/luaenginestyle/luaenginestyle.qss @@ -132,3 +132,10 @@ QPushButton:focus:pressed { color: rgb(215, 70, 25); border-style: inset; } +QTextEdit { + background-color: rgb(215, 120, 50); + color: rgb(255, 255, 255); + selection-background-color: rgb(255, 255, 255); + selection-color: rgb(215, 90, 0); + border: 1px solid white; +} diff --git a/src/luaengineapp/main.cpp b/src/luaengineapp/main.cpp index cc87444..f0864fe 100644 --- a/src/luaengineapp/main.cpp +++ b/src/luaengineapp/main.cpp @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) } delete luaEngineStyleFile; - QFile luaScript(":/lua/app.lua"); + QFile luaScript(":/lua/edit.lua"); LuaEngineGui luaEngineGui; luaEngineGui.executeLuaScript(&luaScript); diff --git a/src/luaenginegui/luaengine/LuaEngineGui.cpp b/src/luaenginegui/luaengine/LuaEngineGui.cpp index 8d41f70..8a6ce26 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.cpp +++ b/src/luaenginegui/luaengine/LuaEngineGui.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include LuaEngineGui::LuaEngineGui(QObject *parent, bool loadBaseLibraries) : LuaEngine(parent, loadBaseLibraries) { @@ -103,6 +105,9 @@ void LuaEngineGui::pushClass(lua_State *L_p) // Spacer Item pushFunction(L_p, "createSpacerItem", createSpacerItem); + // Line Edit + pushFunction(L_p, "createTextEdit", createTextEdit); + // Size Policy pushVariant(L_p, "SizePolicyFixed", (int)QSizePolicy::Fixed); pushVariant(L_p, "SizePolicyMinimum", (int)QSizePolicy::Minimum); @@ -302,6 +307,9 @@ int LuaEngineGui::setWidgetText(lua_State *L_p) else if (((QObject*)pointer)->inherits("QLineEdit")) { ((QLineEdit*)pointer)->setText(getVariant(L_p, 2).toString()); } + else if (((QObject*)pointer)->inherits("QTextEdit")) { + ((QTextEdit*)pointer)->setText(getVariant(L_p, 2).toString()); + } else if (((QObject*)pointer)->inherits("QWidget")) { ((QWidget*)pointer)->setWindowTitle(getVariant(L_p, 2).toString()); } @@ -609,6 +617,28 @@ int LuaEngineGui::createSpacerItem(lua_State *L_p) return 0; } +int LuaEngineGui::createTextEdit(lua_State *L_p) +{ + QVariantList args = getArguments(L_p); + QWidget *parent = nullptr; + QString editText = "LuaEngine"; + if (args.length() >= 1) { + editText = args.at(0).toString(); + if (args.length() >= 2) { + if ((QMetaType::Type)args.at(1).type() == QMetaType::Void || (QMetaType::Type)args.at(1).type() == QMetaType::VoidStar) { + if (((QObject*)qvariant_cast(args.at(1)))->inherits("QWidget")) { + parent = (QWidget*)qvariant_cast(args.at(1)); + } + } + } + } + QTextEdit *textEdit = new QTextEdit(parent); + textEdit->setObjectName(nameForPointer(textEdit)); + textEdit->setText(editText); + pushPointer(L_p, textEdit); + return 1; +} + int LuaEngineGui::getParent(lua_State *L_p) { if (getArgumentCount(L_p) >= 1) { @@ -638,6 +668,10 @@ int LuaEngineGui::getWidgetText(lua_State *L_p) pushVariant(L_p, ((QLineEdit*)pointer)->text()); return 1; } + else if (((QObject*)pointer)->inherits("QTextEdit")) { + pushVariant(L_p, ((QTextEdit*)pointer)->toPlainText()); + return 1; + } else if (((QObject*)pointer)->inherits("QWidget")) { pushVariant(L_p, ((QWidget*)pointer)->windowTitle()); return 1; diff --git a/src/luaenginegui/luaengine/LuaEngineGui.h b/src/luaenginegui/luaengine/LuaEngineGui.h index bb2b4a0..ecb6d78 100644 --- a/src/luaenginegui/luaengine/LuaEngineGui.h +++ b/src/luaenginegui/luaengine/LuaEngineGui.h @@ -36,6 +36,7 @@ public: static int showWidget(lua_State *L_p); static int setWidgetFixedSize(lua_State *L_p); static int setWidgetLayout(lua_State *L_p); + static int setWidgetMargins(lua_State *L_p); static int setWidgetText(lua_State *L_p); static int layoutAddLayout(lua_State *L_p); static int layoutAddWidget(lua_State *L_p); @@ -51,6 +52,7 @@ public: static int createMenuEntry(lua_State *L_p); static int createPushButton(lua_State *L_p); static int createSpacerItem(lua_State *L_p); + static int createTextEdit(lua_State *L_p); static int getParent(lua_State *L_p); static int getWidgetText(lua_State *L_p);